Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmake/nccl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ else()
BUILD_BYPRODUCTS ${CMAKE_BINARY_DIR}/deps/nccl/lib/libnccl${LIBEXT}
INSTALL_COMMAND ""
CONFIGURE_COMMAND ""
BUILD_COMMAND make src.build "${NCCL_BUILD_NVCC_GENCODE}" "CUDA_HOME=${CUDA_TOOLKIT_ROOT_DIR}" "BUILDDIR=${CMAKE_BINARY_DIR}/deps/nccl" "CXX=${CMAKE_CXX_COMPILER}" CC="${CMAKE_CC_COMPILER}"
BUILD_COMMAND make src.build "${NCCL_BUILD_NVCC_GENCODE}" "CUDA_HOME=${CUDA_TOOLKIT_ROOT_DIR}" "BUILDDIR=${CMAKE_BINARY_DIR}/deps/nccl" "CXX=${CMAKE_CXX_COMPILER}" CC="${CMAKE_CC_COMPILER}" CXXFLAGS="-w"
BUILD_IN_SOURCE 1
)

Expand Down
4 changes: 2 additions & 2 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
add_subdirectory(pcg)
add_subdirectory(compiler)
# add_subdirectory(runtime)
add_subdirectory(runtime)
add_subdirectory(op-attrs)
add_subdirectory(kernels)
add_subdirectory(utils)
# add_subdirectory(ffi)
add_subdirectory(ffi)
add_subdirectory(substitutions)
29 changes: 23 additions & 6 deletions lib/compiler/ffi/include/flexflow/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,35 @@

FLEXFLOW_FFI_BEGIN()

typedef enum {
FLEXFLOW_COMPILER_STATUS_OK,
FLEXFLOW_COMPILER_ERROR_UNKNOWN
} flexflow_compiler_error_t;

typedef enum {
FLEXFLOW_SEARCH_ALGORITHM_DATA_PARALLEL
} flexflow_search_algorithm_t;

FF_NEW_OPAQUE_TYPE(flexflow_search_algorithm_config_t);
FF_NEW_OPAQUE_TYPE(flexflow_search_result_t);
FF_NEW_OPAQUE_TYPE(fleflow_cost_estimator_t);
FF_NEW_OPAQUE_TYPE(flexflow_cost_estimator_t);

// Error functions
typedef enum {
FLEXFLOW_COMPILER_STATUS_OK,
FLEXFLOW_COMPILER_ERROR_UNKNOWN
} flexflow_compiler_error_code_t;

FF_NEW_OPAQUE_TYPE(flexflow_compiler_error_t);

flexflow_error_t flexflow_compiler_error_wrap(flexflow_compiler_error_t);
flexflow_error_t flexflow_compiler_error_unwrap(flexflow_error_t,
flexflow_compiler_error_t *);
flexflow_error_t flexflow_compiler_error_is_ok(flexflow_compiler_error_t,
bool *);
flexflow_error_t flexflow_compiler_error_get_string(flexflow_compiler_error_t,
char **message);
flexflow_error_t
flexflow_compiler_error_get_error_code(flexflow_compiler_error_t,
flexflow_compiler_error_code_t *out);
flexflow_error_t flexflow_compiler_error_destroy(flexflow_compiler_error_t);

//

flexflow_error_t
flexflow_computation_graph_optimize(flexflow_computation_graph_t,
Expand Down
6 changes: 6 additions & 0 deletions lib/compiler/ffi/internal/internal/compiler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef _FLEXFLOW_COMPILER_FFI_INTERNAL_INTERNAL_COMPILER_H
#define _FLEXFLOW_COMPILER_FFI_INTERNAL_INTERNAL_COMPILER_H

#include "flexflow/compiler.h"

#endif
2 changes: 2 additions & 0 deletions lib/ffi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ target_link_libraries(
substitutions-ffi
pcg-ffi
op-attrs-ffi
PRIVATE
pcg-ffi-internal
)

ff_set_cxx_properties(${target})
22 changes: 17 additions & 5 deletions lib/ffi/include/flexflow/flexflow.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,34 @@
#include "flexflow/op-attrs.h"
#include "flexflow/pcg.h"
#include "flexflow/runtime.h"
#include "flexflow/utils.h"
#include <stdio.h>
#include <stdlib.h>

FLEXFLOW_FFI_BEGIN();

#define CHECK_FLEXFLOW(status) \
do { \
if (flexflow_status_is_ok(status)) { \
bool is_ok; \
flexflow_status_is_ok(status, &is_ok); \
if (is_ok) { \
char *error_msg; \
assert(flexflow_status_is_ok( \
flexflow_get_error_string(status, &err_msg), &is_ok)); \
fprintf(stderr, \
"FlexFlow encountered an errorat %s:%d : %s\n", \
"FlexFlow encountered an error at %s:%d : %s\n", \
__FILE__, \
__LINE__, \
flexflow_get_error_string(status)); \
exit(flexflow_get_error_return_code(status)); \
} \
} while (0)

bool flexflow_status_is_ok(flexflow_error_t);
char *flexflow_get_error_string(flexflow_error_t);
int flexflow_get_error_return_code(flexflow_error_t);
flexflow_error_t flexflow_status_is_ok(flexflow_error_t, bool *);
flexflow_error_t flexflow_get_error_string(flexflow_error_t, char *);

flexflow_error_t flexflow_error_destroy(flexflow_error_t);

FLEXFLOW_FFI_END();

#endif
68 changes: 68 additions & 0 deletions lib/ffi/src/ffi.cc
Original file line number Diff line number Diff line change
@@ -1 +1,69 @@
#include "flexflow/flexflow.h"
#include "flexflow/op-attrs.h"
#include "flexflow/runtime.h"
#include "flexflow/utils.h"
#include "internal/pcg.h"

flexflow_error_t flexflow_status_is_ok(flexflow_error_t e, bool *result) {
switch (e.error_source) {
case FLEXFLOW_ERROR_SOURCE_RUNTIME: {
flexflow_runtime_error_t err;
CHECK_FLEXFLOW(flexflow_runtime_error_unwrap(e, &err));
CHECK_FLEXFLOW(flexflow_runtime_error_is_ok(err, result));
}
case FLEXFLOW_ERROR_SOURCE_PCG: {
flexflow_pcg_error_t err;
CHECK_FLEXFLOW(flexflow_pcg_error_unwrap(e, &err));
CHECK_FLEXFLOW(flexflow_pcg_error_is_ok(err, result));
}
case FLEXFLOW_ERROR_SOURCE_COMPILER: {
flexflow_compiler_error_t err;
CHECK_FLEXFLOW(flexflow_compiler_error_unwrap(e, &err));
CHECK_FLEXFLOW(flexflow_compiler_error_is_ok(err, result));
}
case FLEXFLOW_ERROR_SOURCE_OPATTRS: {
flexflow_opattrs_error_t err;
CHECK_FLEXFLOW(flexflow_opattrs_error_unwrap(e, &err));
CHECK_FLEXFLOW(flexflow_opattrs_error_is_ok(err, result));
}
case FLEXFLOW_ERROR_SOURCE_UTILS: {
flexflow_utils_error_t err;
CHECK_FLEXFLOW(flexflow_utils_error_unwrap(e, &err));
CHECK_FLEXFLOW(flexflow_utils_error_is_ok(err, result));
}
default:
return flexflow_utils_error_create(FLEXFLOW_UTILS_INVALID_ERROR_SOURCE);
};

return flexflow_utils_error_create(FLEXFLOW_UTILS_STATUS_OK);
}

flexflow_error_t flexflow_error_destroy(flexflow_error_t e) {
switch (e.error_source) {
case FLEXFLOW_ERROR_SOURCE_RUNTIME: {
flexflow_runtime_error_t err;
CHECK_FLEXFLOW(flexflow_runtime_error_unwrap(e, &err));
return flexflow_runtime_error_destroy(err);
}
case FLEXFLOW_ERROR_SOURCE_PCG: {
flexflow_pcg_error_t err;
CHECK_FLEXFLOW(flexflow_pcg_error_unwrap(e, &err));
return flexflow_pcg_error_destroy(err);
}
case FLEXFLOW_ERROR_SOURCE_COMPILER: {
flexflow_compiler_error_t err;
CHECK_FLEXFLOW(flexflow_compiler_error_unwrap(e, &err));
return flexflow_compiler_error_destroy(err);
}
case FLEXFLOW_ERROR_SOURCE_OPATTRS: {
flexflow_opattrs_error_t err;
CHECK_FLEXFLOW(flexflow_opattrs_error_unwrap(e, &err));
return flexflow_opattrs_error_destroy(err);
}
case FLEXFLOW_ERROR_SOURCE_UTILS: {
return flexflow_utils_error_create(FLEXFLOW_UTILS_STATUS_OK);
}
default:
return flexflow_utils_error_create(FLEXFLOW_UTILS_INVALID_ERROR_SOURCE);
}
}
18 changes: 18 additions & 0 deletions lib/op-attrs/ffi/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
set(target op-attrs-ffi)
set(internal_target internal-${target})

project(${target})
file(GLOB_RECURSE SRC
Expand All @@ -16,13 +17,30 @@ target_include_directories(
include/
PRIVATE
src/
internal/
)
target_link_libraries(
${target}
PUBLIC
utils-ffi
PRIVATE
op-attrs
internal-utils-ffi
)

ff_set_cxx_properties(${target})

add_library(
${internal_target}
INTERFACE
)
target_link_libraries(
${internal_target}
INTERFACE
${target}
)
target_include_directories(
${internal_target}
INTERFACE
internal/
)
32 changes: 26 additions & 6 deletions lib/op-attrs/ffi/include/flexflow/op-attrs.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,30 @@

FLEXFLOW_FFI_BEGIN()

// Error handling

typedef enum {
FLEXFLOW_OPATTRS_ERROR_CODE_INVALID_PARAM_SYNC_VALUE,
FLEXFLOW_OPATTRS_ERROR_CODE_INVALID_DATATYPE_VALUE,
FLEXFLOW_OPATTRS_ERROR_CODE_INVALID_ACTIVATION_VALUE,
FLEXFLOW_OPATTRS_ERROR_CODE_INVALID_POOL_OP_VALUE,
FLEXFLOW_OPATTRS_ERROR_CODE_INVALID_AGGREGATE_OP_VALUE,
FLEXFLOW_OPATTRS_ERROR_CODE_INVALID_OP_TYPE_VALUE
} flexflow_opattrs_error_code_t;

FF_NEW_OPAQUE_TYPE(flexflow_opattrs_error_t);
flexflow_error_t flexflow_opattrs_error_wrap(flexflow_opattrs_error_t);
flexflow_error_t flexflow_opattrs_error_unwrap(flexflow_error_t,
flexflow_opattrs_error_t *);
flexflow_error_t flexflow_opattrs_error_is_ok(flexflow_opattrs_error_t, bool *);
flexflow_error_t flexflow_opattrs_error_get_string(flexflow_opattrs_error_t,
char **);
flexflow_error_t flexflow_opattrs_error_destroy(flexflow_opattrs_error_t);

//

FF_NEW_OPAQUE_TYPE(flexflow_regularizer_attrs_t);

typedef enum {
FLEXFLOW_DATATYPE_BOOL,
FLEXFLOW_DATATYPE_INT32,
Expand All @@ -29,19 +53,15 @@ typedef enum {

typedef enum {
FLEXFLOW_PARAM_SYNC_PARAMETER_SERVER,
FLEXFLOW_PARAM_SYNC_NCCL
FLEXFLOW_PARAM_SYNC_NCCL,
FLEXFLOW_PARAM_SYNC_NONE
} flexflow_param_sync_t;

typedef enum {
FLEXFLOW_AGGREGATE_OP_SUM,
FLEXFLOW_AGGREGATE_OP_AVG,
} flexflow_aggregate_op_t;

typedef enum {
FLEXFLOW_OPATTRS_STATUS_OK,
FLEXFLOW_OPATTRS_ERROR_UNKNOWN
} flexflow_opattrs_error_t;

typedef enum { // does _not_ have to stay synchronized with op-attrs/op.h
FLEXFLOW_OP_TYPE_NOOP,
FLEXFLOW_OP_TYPE_INPUT,
Expand Down
36 changes: 36 additions & 0 deletions lib/op-attrs/ffi/internal/internal/op-attrs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ifndef _FLEXFLOW_OPATTRS_FFI_INTERNAL_INTERNAL_OPATTRS_H
#define _FLEXFLOW_OPATTRS_FFI_INTERNAL_INTERNAL_OPATTRS_H

#include "flexflow/op-attrs.h"
#include "internal/opaque.h"
#include "op-attrs/activation.h"
#include "op-attrs/datatype.h"
#include "op-attrs/op.h"
#include "op-attrs/ops/embedding.h"
#include "op-attrs/ops/linear.h"
#include "op-attrs/ops/pool_2d.h"
#include "op-attrs/param_sync.h"

using namespace FlexFlow;

REGISTER_OPAQUE(flexflow_regularizer_attrs_t, optional<RegularizerAttrs>);

optional<ParamSync> to_internal(flexflow_param_sync_t);
flexflow_param_sync_t to_external(optional<ParamSync>);

DataType to_internal(flexflow_datatype_t);
flexflow_datatype_t to_external(DataType);

optional<Activation> to_internal(flexflow_activation_t);
flexflow_activation_t to_external(optional<Activation>);

PoolOp to_internal(flexflow_pool_op_t e);
flexflow_pool_op_t to_external(PoolOp i);

AggregateOp to_internal(flexflow_aggregate_op_t e);
flexflow_aggregate_op_t to_external(AggregateOp i);

OperatorType to_internal(flexflow_op_type_t e);
flexflow_op_type_t to_external(OperatorType i);

#endif
Loading