support generate ops.fbs
This commit is contained in:
parent
f2bf380b85
commit
0cb6117709
15
build.sh
15
build.sh
|
@ -536,20 +536,6 @@ write_commit_file() {
|
|||
echo ${COMMIT_STR} > "${BASEPATH}/mindspore/lite/build/.commit_id"
|
||||
}
|
||||
|
||||
gen_fbs() {
|
||||
if [[ "${ENABLE_TOOLS}" == "on" ]]; then
|
||||
if [[ -f ${BASEPATH}/mindspore/lite/build/tools/schema_gen/schema_gen ]]; then
|
||||
cd ${BASEPATH}/mindspore/lite/build/tools/schema_gen
|
||||
./schema_gen
|
||||
cd -
|
||||
diff_ops=$(diff ${BASEPATH}/mindspore/lite/build/tools/schema_gen/ops.fbs ${BASEPATH}/mindspore/lite/schema/ops.fbs || true)
|
||||
if [[ "X${diff_ops}" != "X" ]]; then
|
||||
cp ${BASEPATH}/mindspore/lite/build/tools/schema_gen/ops.fbs ${BASEPATH}/mindspore/lite/schema/
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
build_lite()
|
||||
{
|
||||
get_version
|
||||
|
@ -641,7 +627,6 @@ build_lite()
|
|||
-DENABLE_VERBOSE=${ENABLE_VERBOSE} -DX86_64_SIMD=${X86_64_SIMD} "${BASEPATH}/mindspore/lite"
|
||||
fi
|
||||
make -j$THREAD_NUM && make install && make package
|
||||
gen_fbs
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo "---------------- mindspore lite: build failed ----------------"
|
||||
exit 1
|
||||
|
|
|
@ -280,8 +280,10 @@ endif()
|
|||
if(NOT WIN32)
|
||||
if(ENABLE_TOOLS)
|
||||
if(NOT PLATFORM_ARM32 AND NOT PLATFORM_ARM64)
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/schema_gen)
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/cropper)
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/schema_gen)
|
||||
add_dependencies(fbs_src gen_ops)
|
||||
add_dependencies(fbs_inner_src gen_ops)
|
||||
endif()
|
||||
endif()
|
||||
if(BUILD_TESTCASES)
|
||||
|
|
|
@ -233,6 +233,8 @@ if(BUILD_MINDDATA STREQUAL "full")
|
|||
${MINDDATA_FULL_SRC}
|
||||
)
|
||||
|
||||
add_dependencies(minddata-lite fbs_src)
|
||||
|
||||
find_package(Threads REQUIRED)
|
||||
target_link_libraries(minddata-lite
|
||||
securec
|
||||
|
@ -316,6 +318,8 @@ elseif(BUILD_MINDDATA STREQUAL "wrapper")
|
|||
${MINDSPORE_LITE_CXXAPI_SRC}
|
||||
)
|
||||
|
||||
add_dependencies(minddata-lite fbs_src)
|
||||
|
||||
find_package(Threads REQUIRED)
|
||||
target_link_libraries(minddata-lite
|
||||
securec
|
||||
|
|
|
@ -1094,4 +1094,3 @@ table Splice {
|
|||
forward_indexes: [long];
|
||||
output_dim: long;
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
#define OP_TYPE(OP) prims_type.append(" ").append(#OP).append(",\n");
|
||||
|
||||
#define OP_TYPE_DEF_END(type) \
|
||||
prims_type.append("}\n\n"); \
|
||||
prims_type.append("}\n"); \
|
||||
return prims_type; \
|
||||
} \
|
||||
PrimitiveTypeRegister g_gen##type(Gen##type); \
|
||||
|
@ -50,11 +50,11 @@
|
|||
#endif
|
||||
|
||||
#ifdef GEN_SCHEMA_DEF
|
||||
#define OP_SCHEMA_DEF(OP) \
|
||||
namespace mindspore::lite::ops { \
|
||||
std::string Gen##OP##Def() { \
|
||||
std::string op_def = "table "; \
|
||||
op_def.append(#OP); \
|
||||
#define OP_SCHEMA_DEF(OP) \
|
||||
namespace mindspore::lite::ops { \
|
||||
std::string Gen##OP##Def() { \
|
||||
std::string op_def = "\ntable "; \
|
||||
op_def.append(#OP); \
|
||||
op_def.append(" {\n");
|
||||
|
||||
#elif PRIMITIVE_WRITEABLE
|
||||
|
@ -135,7 +135,7 @@
|
|||
|
||||
#ifdef GEN_SCHEMA_DEF
|
||||
#define OP_SCHEMA_DEF_END(OP) \
|
||||
op_def.append("}\n\n"); \
|
||||
op_def.append("}\n"); \
|
||||
return op_def; \
|
||||
} \
|
||||
SchemaOpRegister g_schema_op_##OP(Gen##OP##Def); \
|
||||
|
@ -156,11 +156,11 @@
|
|||
#endif
|
||||
|
||||
#ifdef GEN_SCHEMA_DEF
|
||||
#define OP_SCHEMA_DEF_ONLY(OP) \
|
||||
namespace mindspore::lite::ops { \
|
||||
std::string Gen##OP##Def() { \
|
||||
std::string op_def = "table "; \
|
||||
op_def.append(#OP); \
|
||||
#define OP_SCHEMA_DEF_ONLY(OP) \
|
||||
namespace mindspore::lite::ops { \
|
||||
std::string Gen##OP##Def() { \
|
||||
std::string op_def = "\ntable "; \
|
||||
op_def.append(#OP); \
|
||||
op_def.append(" {\n");
|
||||
#else
|
||||
#define OP_SCHEMA_DEF_ONLY(OP)
|
||||
|
@ -174,7 +174,7 @@
|
|||
|
||||
#ifdef GEN_SCHEMA_DEF
|
||||
#define OP_SCHEMA_DEF_ONLY_END(OP) \
|
||||
op_def.append("}\n\n"); \
|
||||
op_def.append("}\n"); \
|
||||
return op_def; \
|
||||
} \
|
||||
SchemaOpRegister g_schema_op_##OP(Gen##OP##Def); \
|
||||
|
|
|
@ -9,7 +9,15 @@ set(COMMON_SRC
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/../../src/ops/ops_def.cc
|
||||
)
|
||||
add_executable(schema_gen
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/main.cc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/schema_gen.cc
|
||||
${COMMON_SRC})
|
||||
target_link_libraries(schema_gen mindspore-lite pthread)
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/main.cc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/schema_gen.cc
|
||||
${COMMON_SRC})
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/../../schema/ops.fbs
|
||||
COMMAND ${CMAKE_BINARY_DIR}/tools/schema_gen/schema_gen --exportPath=${CMAKE_CURRENT_SOURCE_DIR}/../../schema/
|
||||
DEPENDS schema_gen
|
||||
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
|
||||
COMMENT "Running Generate ops.fbs" VERBATIM)
|
||||
|
||||
add_custom_target(gen_ops ALL DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../../schema/ops.fbs)
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "include/errorcode.h"
|
||||
#include "src/ops/schema_register.h"
|
||||
#include "src/common/log_adapter.h"
|
||||
#include "src/common/file_utils.h"
|
||||
|
||||
namespace mindspore::lite {
|
||||
using mindspore::lite::ops::SchemaRegisterImpl;
|
||||
|
@ -65,6 +66,7 @@ int SchemaGen::Init() {
|
|||
output.write(ns.c_str(), ns.length());
|
||||
std::string prim_type = instance->GetPrimTypeGenFunc()();
|
||||
output.write(prim_type.c_str(), prim_type.length());
|
||||
|
||||
for (auto &&func : instance->GetAllOpDefCreateFuncs()) {
|
||||
std::string &&str = func();
|
||||
output.write(str.c_str(), str.length());
|
||||
|
@ -72,6 +74,7 @@ int SchemaGen::Init() {
|
|||
|
||||
output.close();
|
||||
chmod(path.c_str(), S_IRUSR);
|
||||
std::cout << "Successfully generate ops.fbs in " << flags_->export_path_ + "/ops.fbs" << std::endl;
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
|
@ -88,7 +91,11 @@ int RunSchemaGen(int argc, const char **argv) {
|
|||
std::cerr << flags.Usage() << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
flags.export_path_ = RealPath(flags.export_path_.c_str());
|
||||
if (flags.export_path_.empty()) {
|
||||
std::cerr << flags.Usage() << std::endl;
|
||||
return RET_INPUT_PARAM_INVALID;
|
||||
}
|
||||
SchemaGen gen(&flags);
|
||||
int ret = gen.Init();
|
||||
if (ret != RET_OK) {
|
||||
|
|
Loading…
Reference in New Issue