diff --git a/mindspore/core/c_ops/conv2d.cc b/mindspore/core/c_ops/conv2d.cc index 92974731db..00bce06467 100644 --- a/mindspore/core/c_ops/conv2d.cc +++ b/mindspore/core/c_ops/conv2d.cc @@ -46,7 +46,7 @@ abstract::ShapePtr Conv2dInferShape(const PrimitivePtr &primitive, const std::ve CheckAndConvertUtils::CheckInteger("weight rank", w_shape.size(), kEqual, 4, prim_name); CheckAndConvertUtils::CheckInteger("x rank", x_shape.size(), kEqual, 4, prim_name); - CheckAndConvertUtils::Check("x_shape[1] / group", x_shape[1] / conv_prim->GetGroup(), kEqual, "w_shape[1]", + CheckAndConvertUtils::Check("x_shape[1] / group", x_shape[1] / conv_prim->get_group(), kEqual, "w_shape[1]", w_shape[1], conv_prim->name()); auto out_channel = conv_prim->GetOutputChannel(); CheckAndConvertUtils::Check("out_channel", out_channel, kEqual, "w_shape[0]", w_shape[0], conv_prim->name()); @@ -114,9 +114,9 @@ TypePtr Conv2dInferType(const PrimitivePtr &prim, const std::vector &kernel_size, int mode, const std::string &pad_mode, +void Conv2D::Init(int out_channel, const std::vector &kernel_size, int mode, const std::string &pad_mode, const std::vector &pad, const std::vector &stride, const std::vector &dilation, int group) { auto prim_name = this->name(); @@ -139,49 +139,49 @@ void Conv2d::Init(int out_channel, const std::vector &kernel_size, int mode this->SetOutChannel(CheckAndConvertUtils::CheckInteger("out_channel", out_channel, kGreaterThan, 0, prim_name)); this->SetGroup(CheckAndConvertUtils::CheckInteger("group", group, kGreaterThan, 0, prim_name)); } -std::vector Conv2d::GetKernelSize() const { +std::vector Conv2D::GetKernelSize() const { auto value_ptr = GetAttr(kKernelSize); return GetValue>(value_ptr); } -std::vector Conv2d::GetStride() const { +std::vector Conv2D::GetStride() const { auto value_ptr = GetAttr(kStride); return GetValue>(value_ptr); } -std::vector Conv2d::GetDilation() const { +std::vector Conv2D::GetDilation() const { auto value_ptr = GetAttr(kDilation); return GetValue>(value_ptr); } -std::string Conv2d::GetPadMode() const { +std::string Conv2D::GetPadMode() const { auto value_ptr = this->GetAttr(kPadMode); return GetValue(value_ptr); } -std::vector Conv2d::GetPad() const { +std::vector Conv2D::GetPad() const { auto value_ptr = this->GetAttr(kPad); return GetValue>(value_ptr); } -int Conv2d::GetMode() const { +int Conv2D::GetMode() const { auto value_ptr = this->GetAttr(kMode); return GetValue(value_ptr); } -int Conv2d::GetGroup() const { +int Conv2D::get_group() const { auto value_ptr = this->GetAttr(kGroup); return GetValue(value_ptr); } -int Conv2d::GetOutputChannel() const { +int Conv2D::GetOutputChannel() const { auto value_ptr = this->GetAttr(kOutputChannel); return GetValue(value_ptr); } -void Conv2d::SetKernelSize(const std::vector &kernel_size) { this->AddAttr(kKernelSize, MakeValue(kernel_size)); } -void Conv2d::SetStride(const std::vector &stride) { this->AddAttr(kStride, MakeValue(stride)); } -void Conv2d::SetDilation(const std::vector &dilation) { this->AddAttr(kDilation, MakeValue(dilation)); } -void Conv2d::SetPadMode(const std::string &pad_mode) { this->AddAttr(kPadMode, MakeValue(pad_mode)); } -void Conv2d::SetPad(const std::vector &pad) { this->AddAttr(kPad, MakeValue(pad)); } -void Conv2d::SetMode(int mode) { this->AddAttr(kMode, MakeValue(mode)); } -void Conv2d::SetGroup(int group) { this->AddAttr(kGroup, MakeValue(group)); } -void Conv2d::SetOutChannel(int output_channel) { this->AddAttr(kOutputChannel, MakeValue(output_channel)); } -void Conv2d::SetPadList(const std::vector &pad_list) { this->AddAttr(kPadList, MakeValue(pad_list)); } +void Conv2D::SetKernelSize(const std::vector &kernel_size) { this->AddAttr(kKernelSize, MakeValue(kernel_size)); } +void Conv2D::SetStride(const std::vector &stride) { this->AddAttr(kStride, MakeValue(stride)); } +void Conv2D::SetDilation(const std::vector &dilation) { this->AddAttr(kDilation, MakeValue(dilation)); } +void Conv2D::SetPadMode(const std::string &pad_mode) { this->AddAttr(kPadMode, MakeValue(pad_mode)); } +void Conv2D::SetPad(const std::vector &pad) { this->AddAttr(kPad, MakeValue(pad)); } +void Conv2D::SetMode(int mode) { this->AddAttr(kMode, MakeValue(mode)); } +void Conv2D::SetGroup(int group) { this->AddAttr(kGroup, MakeValue(group)); } +void Conv2D::SetOutChannel(int output_channel) { this->AddAttr(kOutputChannel, MakeValue(output_channel)); } +void Conv2D::SetPadList(const std::vector &pad_list) { this->AddAttr(kPadList, MakeValue(pad_list)); } AbstractBasePtr Conv2dInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, const std::vector &input_args) { diff --git a/mindspore/core/c_ops/conv2d.h b/mindspore/core/c_ops/conv2d.h index 7e8412e2f5..b00ada6db4 100644 --- a/mindspore/core/c_ops/conv2d.h +++ b/mindspore/core/c_ops/conv2d.h @@ -25,11 +25,11 @@ #include "abstract/abstract_value.h" #include "utils/check_convert_utils.h" namespace mindspore { -class Conv2d : public PrimitiveC { +class Conv2D : public PrimitiveC { public: - Conv2d(); - ~Conv2d() = default; - MS_DECLARE_PARENT(Conv2d, PrimitiveC); + Conv2D(); + ~Conv2D() = default; + MS_DECLARE_PARENT(Conv2D, PrimitiveC); void Init(int out_channel, const std::vector &kernel_size, int mode = 1, const std::string &pad_mode = "valid", const std::vector &pad = {0, 0, 0, 0}, const std::vector &stride = {1, 1, 1, 1}, const std::vector &dilation = {1, 1, 1, 1}, int group = 1); @@ -39,7 +39,7 @@ class Conv2d : public PrimitiveC { std::string GetPadMode() const; std::vector GetPad() const; int GetMode() const; - int GetGroup() const; + int get_group() const; int GetOutputChannel() const; void SetKernelSize(const std::vector &kernel_size); void SetStride(const std::vector &stride); @@ -53,6 +53,6 @@ class Conv2d : public PrimitiveC { }; AbstractBasePtr Conv2dInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, const std::vector &input_args); -using PrimConv2dPtr = std::shared_ptr; +using PrimConv2dPtr = std::shared_ptr; } // namespace mindspore #endif // MINDSPORE_CORE_C_OPS_CONV2D_H_ diff --git a/mindspore/lite/CMakeLists.txt b/mindspore/lite/CMakeLists.txt index 515c5d9a6b..73ec2c1269 100644 --- a/mindspore/lite/CMakeLists.txt +++ b/mindspore/lite/CMakeLists.txt @@ -228,6 +228,9 @@ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/nnacl) if (NOT WIN32) if (ENABLE_TOOLS) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/benchmark) + if (NOT PLATFORM_ARM32 AND NOT PLATFORM_ARM64) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/schema_gen) + endif () endif() if (BUILD_TESTCASES) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test) diff --git a/mindspore/lite/src/ops/ops_def.cc b/mindspore/lite/src/ops/ops_def.cc new file mode 100644 index 0000000000..ef9cc32d8b --- /dev/null +++ b/mindspore/lite/src/ops/ops_def.cc @@ -0,0 +1,23 @@ +/** + * Copyright 2019-2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "src/ops/schema_def.h" +#ifdef PRIMITIVE_WRITEABLE +#include "c_ops/conv2d.h" +#endif + +OP_SCHEMA_DEF(Conv2D) +OP_ATTR(group, int) +OP_SCHEMA_DEF_END(Conv2D) diff --git a/mindspore/lite/src/ops/schema_def.h b/mindspore/lite/src/ops/schema_def.h new file mode 100644 index 0000000000..322692290b --- /dev/null +++ b/mindspore/lite/src/ops/schema_def.h @@ -0,0 +1,73 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef MINDSPORE_LITE_SRC_OPS_SCHEMA_DEF_H_ +#define MINDSPORE_LITE_SRC_OPS_SCHEMA_DEF_H_ +#include +#include "src/ops/schema_register.h" +#ifdef PRIMITIVE_WRITEABLE +#include "c_ops/conv2d.h" +#include "schema/inner/model_generated.h" +#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); \ + op_def.append(" {\n"); +#elif PRIMITIVE_WRITEABLE +#define OP_SCHEMA_DEF(OP) \ + namespace mindspore::lite::ops { \ + mindspore::schema::OP##T *PrimitiveOp2SchemaOp(const mindspore::OP *op) { \ + mindspore::schema::OP##T *result_op = new (std::nothrow) mindspore::schema::OP##T(); +#else +#define OP_SCHEMA_DEF(OP) +#endif + +#ifdef GEN_SCHEMA_DEF +#define OP_ATTR(key, type) op_def.append(#key).append(": ").append(#type).append(";\n"); +#elif PRIMITIVE_WRITEABLE +#define OP_ATTR(key, type) result_op->key = op->get_##key(); +#else +#define OP_ATTR(key, type) +#endif + +#ifdef GEN_SCHEMA_DEF +#define OP_ATTR_WITH_VALUE(key, type, value) \ + op_def.append(#key).append(": ").append(#type).append(" = ").append(#value).append(";\n"); +#elif PRIMITIVE_WRITEABLE +#define OP_ATTR_WITH_VALUE(key, type, value) result_op->key = op->get_##key(); +#else +#define OP_ATTR_WITH_VALUE(key, type, value) +#endif + +#ifdef GEN_SCHEMA_DEF +#define OP_SCHEMA_DEF_END(OP) \ + op_def.append("}\n\n"); \ + return op_def; \ + } \ + SchemaOpRegister g_schema_op_##OP(Gen##OP##Def); \ + } // namespace mindspore::lite::ops +#elif PRIMITIVE_WRITEABLE +#define OP_SCHEMA_DEF_END(OP) \ + return result_op; \ + } \ + } // namespace mindspore::lite::ops +#else +#define OP_SCHEMA_DEF_END(OP) +#endif +#endif // MINDSPORE_LITE_SRC_OPS_SCHEMA_DEF_H_ diff --git a/mindspore/lite/src/ops/schema_register.h b/mindspore/lite/src/ops/schema_register.h new file mode 100644 index 0000000000..532dfa07f3 --- /dev/null +++ b/mindspore/lite/src/ops/schema_register.h @@ -0,0 +1,52 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef MINDSPORE_LITE_SRC_OPS_SCHEMA_REGISTER_H_ +#define MINDSPORE_LITE_SRC_OPS_SCHEMA_REGISTER_H_ +#include +#include +#include + +namespace mindspore::lite::ops { +using GetSchemaDef = std::function; + +class SchemaRegisterImpl { + public: + SchemaRegisterImpl() = default; + static SchemaRegisterImpl *Instance() { + static SchemaRegisterImpl instance; + return &instance; + } + + void OpPush(GetSchemaDef func) { op_def_funcs_.push_back(func); } + + void TypePush(GetSchemaDef func) { type_def_funcs_.push_back(func); } + + const std::vector &GetAllOpDefCreateFuncs() const { return op_def_funcs_; } + + const std::vector &GetAllTypeDefCreateFuncs() const { return type_def_funcs_; } + + private: + std::vector op_def_funcs_; + std::vector type_def_funcs_; +}; + +class SchemaOpRegister { + public: + explicit SchemaOpRegister(GetSchemaDef func) { SchemaRegisterImpl::Instance()->OpPush(func); } +}; +} // namespace mindspore::lite::ops + +#endif // MINDSPORE_LITE_SRC_OPS_SCHEMA_REGISTER_H_ diff --git a/mindspore/lite/tools/schema_gen/CMakeLists.txt b/mindspore/lite/tools/schema_gen/CMakeLists.txt new file mode 100644 index 0000000000..3587b8d496 --- /dev/null +++ b/mindspore/lite/tools/schema_gen/CMakeLists.txt @@ -0,0 +1,17 @@ +# add shared link library + +add_compile_definitions(GEN_SCHEMA_DEF) +set(COMMON_SRC + ${CMAKE_CURRENT_SOURCE_DIR}/../common/flag_parser.cc + ${CMAKE_CURRENT_SOURCE_DIR}/../../src/common/file_utils.cc + ${CMAKE_CURRENT_SOURCE_DIR}/../../src/common/utils.cc + ) +add_executable(schema_gen + ${CMAKE_CURRENT_SOURCE_DIR}/main.cc + ${CMAKE_CURRENT_SOURCE_DIR}/schema_gen.cc + ${CMAKE_CURRENT_SOURCE_DIR}/schema_type_def.cc + ${CMAKE_CURRENT_SOURCE_DIR}/../../src/ops/ops_def.cc + ${COMMON_SRC}) +target_link_libraries(schema_gen mindspore-lite pthread) +install(TARGETS schema_gen + RUNTIME DESTINATION ${MAIN_DIR}-${RUN_X86_COMPONENT_NAME}/schema_gen COMPONENT ${RUN_X86_COMPONENT_NAME}) diff --git a/mindspore/lite/tools/schema_gen/main.cc b/mindspore/lite/tools/schema_gen/main.cc new file mode 100644 index 0000000000..cd2f43f60e --- /dev/null +++ b/mindspore/lite/tools/schema_gen/main.cc @@ -0,0 +1,19 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "tools/schema_gen/schema_gen.h" + +int main(int argc, const char **argv) { return mindspore::lite::RunSchemaGen(argc, argv); } diff --git a/mindspore/lite/tools/schema_gen/schema_gen.cc b/mindspore/lite/tools/schema_gen/schema_gen.cc new file mode 100644 index 0000000000..6469935638 --- /dev/null +++ b/mindspore/lite/tools/schema_gen/schema_gen.cc @@ -0,0 +1,88 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "tools/schema_gen/schema_gen.h" +#include +#include +#include +#include +#include "include/errorcode.h" +#include "src/ops/schema_register.h" +#include "src/common/log_adapter.h" + +namespace mindspore::lite { +using mindspore::lite::ops::SchemaRegisterImpl; + +int SchemaGen::Init() { + if (this->flags_ == nullptr) { + return RET_ERROR; + } + MS_LOG(INFO) << "Export Path = " << flags_->export_path_; + + SchemaRegisterImpl *instance = SchemaRegisterImpl::Instance(); + if (instance == nullptr) { + MS_LOG(ERROR) << "get instance fail!"; + return RET_ERROR; + } + + std::string path = flags_->export_path_ + "/ops.fbs"; + if (access((path).c_str(), F_OK) == 0) { + chmod((path).c_str(), S_IWUSR); + } + std::ofstream output(path, std::ofstream::binary); + if (!output.is_open()) { + MS_LOG(ERROR) << "Can not open file: " << path; + return RET_ERROR; + } + std::string ns = "namespace mindspore.schema;\n\n"; + output.write(ns.c_str(), ns.length()); + for (auto &&func : instance->GetAllTypeDefCreateFuncs()) { + std::string &&str = func(); + output.write(str.c_str(), str.length()); + } + + for (auto &&func : instance->GetAllOpDefCreateFuncs()) { + std::string &&str = func(); + output.write(str.c_str(), str.length()); + } + + output.close(); + chmod(path.c_str(), S_IRUSR); + return RET_OK; +} + +int RunSchemaGen(int argc, const char **argv) { + SchemaGenFlags flags; + Option err = flags.ParseFlags(argc, argv); + if (err.IsSome()) { + std::cerr << err.Get() << std::endl; + std::cerr << flags.Usage() << std::endl; + return RET_ERROR; + } + + if (flags.help) { + std::cerr << flags.Usage() << std::endl; + return 0; + } + + SchemaGen gen(&flags); + int ret = gen.Init(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "schema gen fail!ret: " << ret; + } + return ret; +} +} // namespace mindspore::lite diff --git a/mindspore/lite/tools/schema_gen/schema_gen.h b/mindspore/lite/tools/schema_gen/schema_gen.h new file mode 100644 index 0000000000..0c50f23b76 --- /dev/null +++ b/mindspore/lite/tools/schema_gen/schema_gen.h @@ -0,0 +1,42 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef MINDSPORE_LITE_TOOLS_SCHEMA_GEN_SCHEMA_GEN_H_ +#define MINDSPORE_LITE_TOOLS_SCHEMA_GEN_SCHEMA_GEN_H_ +#include +#include "tools/common/flag_parser.h" + +namespace mindspore::lite { +class SchemaGenFlags : public virtual FlagParser { + public: + SchemaGenFlags() { AddFlag(&SchemaGenFlags::export_path_, "exportPath", "schema define export path", "."); } + + public: + std::string export_path_ = "."; +}; + +class SchemaGen { + public: + explicit SchemaGen(SchemaGenFlags *flags) : flags_(flags) {} + int Init(); + + private: + SchemaGenFlags *flags_; +}; + +int RunSchemaGen(int argc, const char **argv); +} // namespace mindspore::lite + +#endif // MINDSPORE_LITE_TOOLS_SCHEMA_GEN_SCHEMA_GEN_H_ diff --git a/mindspore/lite/tools/schema_gen/schema_type_def.cc b/mindspore/lite/tools/schema_gen/schema_type_def.cc new file mode 100644 index 0000000000..2c9007693e --- /dev/null +++ b/mindspore/lite/tools/schema_gen/schema_type_def.cc @@ -0,0 +1,62 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "tools/schema_gen/schema_type_def.h" + +SCHEMA_ENUM_DEF(ResizeMethod, byte) +SCHEMA_ENUM_ATTR_WITH_VALUE(UNKNOW, -1) +SCHEMA_ENUM_ATTR_WITH_VALUE(BILINEAR, 0) +SCHEMA_ENUM_ATTR_WITH_VALUE(NEAREST_NEIGHBOR, 1) +OP_SCHEMA_DEF_END(ResizeMethod) + +SCHEMA_ENUM_DEF(Format, int) +SCHEMA_ENUM_ATTR_WITH_VALUE(NCHW, 0) +SCHEMA_ENUM_ATTR(NHWC) +SCHEMA_ENUM_ATTR(NHWC4) +SCHEMA_ENUM_ATTR(HWKC) +SCHEMA_ENUM_ATTR(HWCK) +SCHEMA_ENUM_ATTR(KCHW) +SCHEMA_ENUM_ATTR(CKHW) +SCHEMA_ENUM_ATTR(KHWC) +SCHEMA_ENUM_ATTR(CHWK) +SCHEMA_ENUM_ATTR(HW) +SCHEMA_ENUM_ATTR(HW4) +SCHEMA_ENUM_ATTR(NC) +SCHEMA_ENUM_ATTR(NC4) +SCHEMA_ENUM_ATTR_WITH_VALUE(NC4HW4, 100) +SCHEMA_ENUM_ATTR(NUM_OF_FORMAT) +OP_SCHEMA_DEF_END(Format) + +SCHEMA_ENUM_DEF(ActivationType, byte) +SCHEMA_ENUM_ATTR_WITH_VALUE(NO_ACTIVATION, 0) +SCHEMA_ENUM_ATTR_WITH_VALUE(RELU, 1) +SCHEMA_ENUM_ATTR_WITH_VALUE(SIGMOID, 2) +SCHEMA_ENUM_ATTR_WITH_VALUE(RELU6, 3) +SCHEMA_ENUM_ATTR_WITH_VALUE(ELU, 4) +SCHEMA_ENUM_ATTR_WITH_VALUE(LEAKY_RELU, 5) +SCHEMA_ENUM_ATTR_WITH_VALUE(ABS, 6) +SCHEMA_ENUM_ATTR_WITH_VALUE(RELU1, 7) +SCHEMA_ENUM_ATTR_WITH_VALUE(SOFTSIGN, 8) +SCHEMA_ENUM_ATTR_WITH_VALUE(SOFTPLUS, 9) +SCHEMA_ENUM_ATTR_WITH_VALUE(TANH, 10) +SCHEMA_ENUM_ATTR_WITH_VALUE(SELU, 11) +SCHEMA_ENUM_ATTR_WITH_VALUE(HSWISH, 12) +SCHEMA_ENUM_ATTR_WITH_VALUE(HSIGMOID, 13) +SCHEMA_ENUM_ATTR_WITH_VALUE(THRESHOLDRELU, 14) +SCHEMA_ENUM_ATTR_WITH_VALUE(LINEAR, 15) +SCHEMA_ENUM_ATTR_WITH_VALUE(HARD_TANH, 16) +SCHEMA_ENUM_ATTR_WITH_VALUE(SIGN, 17) +SCHEMA_ENUM_ATTR_WITH_VALUE(UNKNOW, 18) +OP_SCHEMA_DEF_END(ActivationType) diff --git a/mindspore/lite/tools/schema_gen/schema_type_def.h b/mindspore/lite/tools/schema_gen/schema_type_def.h new file mode 100644 index 0000000000..73b82b52fe --- /dev/null +++ b/mindspore/lite/tools/schema_gen/schema_type_def.h @@ -0,0 +1,41 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef MINDSPORE_LITE_TOOLS_SCHEMA_GEN_SCHEMA_TYPE_DEF_H_ +#define MINDSPORE_LITE_TOOLS_SCHEMA_GEN_SCHEMA_TYPE_DEF_H_ +#include +#include "tools/schema_gen/schema_type_register.h" + +#define SCHEMA_ENUM_DEF(T, B) \ + namespace mindspore::lite::ops { \ + std::string GenEnumDef##T() { \ + std::string def = "enum "; \ + def.append(#T); \ + def.append(" : "); \ + def.append(#B); \ + def.append(" {\n"); + +#define SCHEMA_ENUM_ATTR_WITH_VALUE(key, value) def.append(#key).append(" = ").append(#value).append(",\n"); + +#define SCHEMA_ENUM_ATTR(key) def.append(#key).append(",\n"); + +#define OP_SCHEMA_DEF_END(T) \ + def.append("}\n\n"); \ + return def; \ + } \ + SchemaTypeRegister g_schema_enum_##T(GenEnumDef##T); \ + } // namespace mindspore::lite::ops + +#endif // MINDSPORE_LITE_TOOLS_SCHEMA_GEN_SCHEMA_TYPE_DEF_H_ diff --git a/mindspore/lite/tools/schema_gen/schema_type_register.h b/mindspore/lite/tools/schema_gen/schema_type_register.h new file mode 100644 index 0000000000..78f27ce56e --- /dev/null +++ b/mindspore/lite/tools/schema_gen/schema_type_register.h @@ -0,0 +1,27 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef MINDSPORE_LITE_TOOLS_SCHEMA_GEN_SCHEMA_TYPE_REGISTER_H_ +#define MINDSPORE_LITE_TOOLS_SCHEMA_GEN_SCHEMA_TYPE_REGISTER_H_ +#include "src/ops/schema_register.h" + +namespace mindspore::lite::ops { +class SchemaTypeRegister { + public: + explicit SchemaTypeRegister(GetSchemaDef func) { SchemaRegisterImpl::Instance()->TypePush(func); } +}; +} // namespace mindspore::lite::ops + +#endif // MINDSPORE_LITE_TOOLS_SCHEMA_GEN_SCHEMA_TYPE_REGISTER_H_