From: Андрей Тищенко/AI Tools Lab /SRR/Staff Engineer/삼성전자 Date: Fri, 2 Nov 2018 13:52:32 +0000 (+0300) Subject: Enable ONNX frontend compilation (#2082) X-Git-Tag: nncc_backup~1423 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6f527335a4644bd0696136954d893d8712e157ab;p=platform%2Fcore%2Fml%2Fnnfw.git Enable ONNX frontend compilation (#2082) Special --onnx option added. ONNX operator types aadded. CMake build system updated to add ONNX related stuff. Signed-off-by: Andrew V. Tischenko --- diff --git a/contrib/nnc/CMakeLists.txt b/contrib/nnc/CMakeLists.txt index 31f35b1..2ad48a2 100644 --- a/contrib/nnc/CMakeLists.txt +++ b/contrib/nnc/CMakeLists.txt @@ -51,6 +51,16 @@ else() set(NNC_FRONTEND_CAFFE_ENABLED OFF) endif() +# Try to get the compiled onnx proto and return if not successful. +# Note: this creates a target called "onnxproto" and after linking with it +# onnx.pb.h will be available as "onnx/onnx.pb.h" +nncc_find_package(ONNXProto QUIET) +if (ONNXProto_FOUND) + set(NNC_FRONTEND_ONNX_ENABLED ON) +else() + set(NNC_FRONTEND_ONNX_ENABLED OFF) +endif() + # We need flatbuffer for tflite frontend nncc_find_package(FlatBuffers QUIET) if (FlatBuffers_FOUND) diff --git a/contrib/nnc/driver/Driver.cpp b/contrib/nnc/driver/Driver.cpp index cd57065..7b168ea 100644 --- a/contrib/nnc/driver/Driver.cpp +++ b/contrib/nnc/driver/Driver.cpp @@ -21,7 +21,7 @@ #include "passes/interpreter/InterpreterPass.h" #include "passes/soft_backend/CPPGenerator.h" #include "passes/acl_soft_backend/AclCppGenerator.h" - +#include "passes/onnx_frontend/ONNXFrontend.h" #include "support/CommandLine.h" #include "Definitions.h" #include "option/Options.h" @@ -71,7 +71,15 @@ void Driver::registerFrontendPass() { #ifdef NNC_FRONTEND_CAFFE_ENABLED pass = std::move(std::unique_ptr(new CaffeImporter(cli::inputFile))); #endif // NNC_FRONTEND_CAFFE_ENABLED - } else if (cli::tflFrontend) { + } + else if ( cli::onnxFrontend ) + { +#ifdef NNC_FRONTEND_ONNX_ENABLED + pass = std::move(std::unique_ptr(new ONNXFrontend())); +#endif // NNC_FRONTEND_ONNX_ENABLED + } + else if ( cli::tflFrontend ) + { #ifdef NNC_FRONTEND_TFLITE_ENABLED pass = std::move(std::unique_ptr(new TfliteImporter(cli::inputFile))); #endif // NNC_FRONTEND_TFLITE_ENABLED diff --git a/contrib/nnc/driver/Options.cpp b/contrib/nnc/driver/Options.cpp index 4347135..d578e85 100644 --- a/contrib/nnc/driver/Options.cpp +++ b/contrib/nnc/driver/Options.cpp @@ -45,6 +45,19 @@ Option caffeFrontend(optname("--caffe"), showopt(false) #endif // NNC_FRONTEND_CAFFE_ENABLED ); +Option onnxFrontend(optname("--onnx"), + overview("treat input file as ONNX model"), + false, + optional(true), + optvalues(""), + nullptr, + separators(""), +#ifdef NNC_FRONTEND_ONNX_ENABLED + showopt(true) +#else + showopt(false) +#endif // NNC_FRONTEND_ONNX_ENABLED + ); Option tflFrontend(optname("--tflite"), overview("treat input file as Tensor Flow Lite model"), false, diff --git a/contrib/nnc/include/Definitions.h.in b/contrib/nnc/include/Definitions.h.in index 7299f23..84b5388 100644 --- a/contrib/nnc/include/Definitions.h.in +++ b/contrib/nnc/include/Definitions.h.in @@ -31,4 +31,9 @@ */ #cmakedefine NNC_FRONTEND_CAFFE_ENABLED +/** + * @brief define that ONNX frontend is enabled + */ +#cmakedefine NNC_FRONTEND_ONNX_ENABLED + #endif //NNCC_DEFINITIONS_H diff --git a/contrib/nnc/include/core/modelIR/Shape.h b/contrib/nnc/include/core/modelIR/Shape.h index fe40b3c..e3d5eab 100644 --- a/contrib/nnc/include/core/modelIR/Shape.h +++ b/contrib/nnc/include/core/modelIR/Shape.h @@ -34,6 +34,7 @@ public: Shape() = default; Shape(std::initializer_list &&l); + explicit Shape(std::vector d) : _dims(d) {} int32_t rank() const; diff --git a/contrib/nnc/include/option/Options.h b/contrib/nnc/include/option/Options.h index 5c023b2..8ca3452 100644 --- a/contrib/nnc/include/option/Options.h +++ b/contrib/nnc/include/option/Options.h @@ -30,6 +30,7 @@ namespace cli */ extern Option caffeFrontend; // frontend for CAFFE AI framework extern Option tflFrontend; // frontend for TensorFlow Lite AI framework +extern Option onnxFrontend; // frontend for ONNX AI framework // valid values for target option #define NNC_TARGET_X86_CPP "x86-c++" diff --git a/contrib/nnc/include/passes/onnx_frontend/ONNXFrontend.h b/contrib/nnc/include/passes/onnx_frontend/ONNXFrontend.h new file mode 100644 index 0000000..8b4d6a5 --- /dev/null +++ b/contrib/nnc/include/passes/onnx_frontend/ONNXFrontend.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved + * + * 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 NNCC_ONNXFRONTEND_H +#define NNCC_ONNXFRONTEND_H + +#include "pass/Pass.h" +#include "pass/PassData.h" + + +namespace nnc { +/** + * @brief class represent frontend of ONNX NN framework + */ +class ONNXFrontend : public Pass +{ +public: + ONNXFrontend &operator=(const ONNXFrontend &) = delete; + ONNXFrontend(const ONNXFrontend &) = delete; + + ONNXFrontend() = default; + ~ONNXFrontend() override = default; + + static Pass &getInstance(); + PassData run(PassData data) override; +}; +} // namespace nnc + +#endif //NNCC_ONNXFRONTEND_H diff --git a/contrib/nnc/passes/CMakeLists.txt b/contrib/nnc/passes/CMakeLists.txt index 8856ecd..8c4340c 100644 --- a/contrib/nnc/passes/CMakeLists.txt +++ b/contrib/nnc/passes/CMakeLists.txt @@ -10,6 +10,7 @@ add_executable(def2src ${DEF_CONV}) add_subdirectory(common_frontend) add_subdirectory(tflite_frontend) add_subdirectory(caffe_frontend) +add_subdirectory(onnx_frontend) # # BACKENDs diff --git a/contrib/nnc/passes/onnx_frontend/CMakeLists.txt b/contrib/nnc/passes/onnx_frontend/CMakeLists.txt new file mode 100644 index 0000000..da2e885 --- /dev/null +++ b/contrib/nnc/passes/onnx_frontend/CMakeLists.txt @@ -0,0 +1,32 @@ +if (NOT NNC_FRONTEND_ONNX_ENABLED) + return () +endif(NOT NNC_FRONTEND_ONNX_ENABLED) + +if(TARGET onnxproto) + + nncc_find_package(ONNXSource) + if (NOT ${ONNXSource_FOUND}) + return() + endif() + ################### + # ONNX importer # + ################### + + file(GLOB onnx_importer_headers *.h) + file(GLOB onnx_importer_sources *.cpp) + + add_nnc_library(onnx_importer SHARED ${onnx_importer_sources} + ${onnx_importer_headers}) + + target_link_libraries(onnx_importer PUBLIC onnxproto) + target_link_libraries(onnx_importer PUBLIC nn_import_common) + target_link_libraries(onnx_importer PRIVATE nnc_support) + target_link_libraries(onnx_importer PRIVATE nnc_core) + add_definitions (-DONNX_NAMESPACE=onnx) + + get_target_property(INCLUDE_DIRS onnxproto INCLUDE_DIRECTORIES) + include_directories(${INCLUDE_DIRS} ${ONNXSource_DIR}) + + # install onnx frontend library + install_nnc_library(onnx_importer) +endif(TARGET onnxproto) diff --git a/contrib/nnc/passes/onnx_frontend/ONNXOpType.h b/contrib/nnc/passes/onnx_frontend/ONNXOpType.h new file mode 100644 index 0000000..4ee5b07 --- /dev/null +++ b/contrib/nnc/passes/onnx_frontend/ONNXOpType.h @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved + * + * 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 NNCC_ONNX_OP_TYPES_H +#define NNCC_ONNX_OP_TYPES_H + +namespace nnc { +enum class ONNXOpSupportState { + Unsupported, + Fullysupported, + Partiallysupported +}; + +enum class ONNXOpCode { + opAbs, + opAcos, + opAdd, + opAnd, + opArgMax, + opArgMin, + opAsin, + opAtan, + opAveragePool, + opBatchNormalization, + opCast, + opCeil, + opClip, + opConcat, + opConstant, + opConstantLike, + opConv, + opConvTranspose, + opCos, + opDepthToSpace, + opDiv, + opDropout, + opElu, + opEqual, + opExp, + opExpand, + opEyeLike, + opFlatten, + opFloor, + opGRU, + opGather, + opGemm, + opGlobalAveragePool, + opGlobalLpPool, + opGlobalMaxPool, + opGreater, + opHardSigmoid, + opHardmax, + opIdentity, + opIf, + opInstanceNormalizati, + opLRN, + opLSTM, + opLeakyRelu, + opLess, + opLog, + opLogSoftmax, + opLoop, + opLpNormalization, + opLpPool, + opMatMul, + opMax, + opMaxPool, + opMaxRoiPool, + opMean, + opMin, + opMul, + opMultinomial, + opNeg, + opNot, + opOr, + opPRelu, + opPad, + opPow, + opRNN, + opRandomNormal, + opRandomNormalLike, + opRandomUniform, + opRandomUniformLike, + opReciprocal, + opReduceL1, + opReduceL2, + opReduceLogSum, + opReduceLogSumExp, + opReduceMax, + opReduceMean, + opReduceMin, + opReduceProd, + opReduceSum, + opReduceSumSquare, + opRelu, + opReshape, + opScan, + opSelu, + opShape, + opSigmoid, + opSin, + opSize, + opSlice, + opSoftmax, + opSoftplus, + opSoftsign, + opSpaceToDepth, + opSplit, + opSqrt, + opSqueeze, + opSub, + opSum, + opTan, + opTanh, + opTile, + opTopK, + opTranspose, + opUnsqueeze, + opUpsample, + opXor, + op// experimental + opATen, + opAffine, + opConstantFill, + opCrop, + opDynamicSlice, + opGRUUnit, + opGivenTensorFill, + opImageScaler, + opParametricSoftplus, + opScale, + opScaledTanh, + opThresholdedRelu +}; // ONNXOpCode + +struct ONNXOpType { + const char *name; + ONNXOpCode opCode; + ONNXOpSupportState state; +}; // ONNXOpType +} // namespace nnc +#endif //NNCC_ONNX_OP_TYPES_H diff --git a/contrib/nnc/passes/onnx_frontend/ONNXPerfect.gperf b/contrib/nnc/passes/onnx_frontend/ONNXPerfect.gperf new file mode 100644 index 0000000..2dc3e9a --- /dev/null +++ b/contrib/nnc/passes/onnx_frontend/ONNXPerfect.gperf @@ -0,0 +1,151 @@ +%{ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved + * + * 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 "ONNXOpType.h" + +using namespace nnc; + +%} + +%language=C++ +%define class-name ONNXPerfectHash +%struct-type +%define lookup-function-name getONNXOpType +%readonly-tables +%enum +%omit-struct-type + +struct ONNXOpType { char *name; ONNXOpType opCode; ONNXOpSupportState state}; +%% +Abs, ONNXOpCode::Abs, ONNXOpSupportState::Unsupported +Acos, ONNXOpCode::Acos, ONNXOpSupportState::Unsupported +Add, ONNXOpCode::Add, ONNXOpSupportState::Unsupported +And, ONNXOpCode::And, ONNXOpSupportState::Unsupported +ArgMax, ONNXOpCode::ArgMax, ONNXOpSupportState::Unsupported +ArgMin, ONNXOpCode::ArgMin, ONNXOpSupportState::Unsupported +Asin, ONNXOpCode::Asin, ONNXOpSupportState::Unsupported +Atan, ONNXOpCode::Atan, ONNXOpSupportState::Unsupported +AveragePool, ONNXOpCode::AveragePool, ONNXOpSupportState::Fullysupported +BatchNormalization, ONNXOpCode::BatchNormalization, ONNXOpSupportState::Fullysupported +Cast, ONNXOpCode::Cast, ONNXOpSupportState::Unsupported +Ceil, ONNXOpCode::Ceil, ONNXOpSupportState::Unsupported +Clip, ONNXOpCode::Clip, ONNXOpSupportState::Unsupported +Concat, ONNXOpCode::Concat, ONNXOpSupportState::Fullysupported +Constant, ONNXOpCode::Constant, ONNXOpSupportState::Unsupported +ConstantLike, ONNXOpCode::ConstantLike, ONNXOpSupportState::Unsupported +Conv, ONNXOpCode::Conv, ONNXOpSupportState::Fullysupported +ConvTranspose, ONNXOpCode::ConvTranspose, ONNXOpSupportState::Unsupported +Cos, ONNXOpCode::Cos, ONNXOpSupportState::Unsupported +DepthToSpace, ONNXOpCode::DepthToSpace, ONNXOpSupportState::Unsupported +Div, ONNXOpCode::Div, ONNXOpSupportState::Unsupported +Dropout, ONNXOpCode::Dropout, ONNXOpSupportState::Fullysupported +Elu, ONNXOpCode::Elu, ONNXOpSupportState::Unsupported +Equal, ONNXOpCode::Equal, ONNXOpSupportState::Unsupported +Exp, ONNXOpCode::Exp, ONNXOpSupportState::Unsupported +Expand, ONNXOpCode::Expand, ONNXOpSupportState::Unsupported +EyeLike, ONNXOpCode::EyeLike, ONNXOpSupportState::Unsupported +Flatten, ONNXOpCode::Flatten, ONNXOpSupportState::Unsupported +Floor, ONNXOpCode::Floor, ONNXOpSupportState::Unsupported +GRU, ONNXOpCode::GRU, ONNXOpSupportState::Unsupported +Gather, ONNXOpCode::Gather, ONNXOpSupportState::Unsupported +Gemm, ONNXOpCode::Gemm, ONNXOpSupportState::Unsupported +GlobalAveragePool, ONNXOpCode::GlobalAveragePool, ONNXOpSupportState::Unsupported +GlobalLpPool, ONNXOpCode::GlobalLpPool, ONNXOpSupportState::Unsupported +GlobalMaxPool, ONNXOpCode::GlobalMaxPool, ONNXOpSupportState::Unsupported +Greater, ONNXOpCode::Greater, ONNXOpSupportState::Unsupported +HardSigmoid, ONNXOpCode::HardSigmoid, ONNXOpSupportState::Unsupported +Hardmax, ONNXOpCode::Hardmax, ONNXOpSupportState::Unsupported +Identity, ONNXOpCode::Identity, ONNXOpSupportState::Supported +If, ONNXOpCode::If, ONNXOpSupportState::Unsupported +InstanceNormalizati, ONNXOpCode::InstanceNormalizati, ONNXOpSupportState::Unsupported +LRN, ONNXOpCode::LRN, ONNXOpSupportState::Unsupported +LSTM, ONNXOpCode::LSTM, ONNXOpSupportState::Unsupported +LeakyRelu, ONNXOpCode::LeakyRelu, ONNXOpSupportState::Unsupported +Less, ONNXOpCode::Less, ONNXOpSupportState::Unsupported +Log, ONNXOpCode::Log, ONNXOpSupportState::Unsupported +LogSoftmax, ONNXOpCode::LogSoftmax, ONNXOpSupportState::Unsupported +Loop, ONNXOpCode::Loop, ONNXOpSupportState::Unsupported +LpNormalization, ONNXOpCode::LpNormalization, ONNXOpSupportState::Unsupported +LpPool, ONNXOpCode::LpPool, ONNXOpSupportState::Unsupported +MatMul, ONNXOpCode::MatMul, ONNXOpSupportState::Unsupported +Max, ONNXOpCode::Max, ONNXOpSupportState::Unsupported +MaxPool, ONNXOpCode::MaxPool, ONNXOpSupportState::Supported +MaxRoiPool, ONNXOpCode::MaxRoiPool, ONNXOpSupportState::Unsupported +Mean, ONNXOpCode::Mean, ONNXOpSupportState::Unsupported +Min, ONNXOpCode::Min, ONNXOpSupportState::Unsupported +Mul, ONNXOpCode::Mul, ONNXOpSupportState::Unsupported +Multinomial, ONNXOpCode::Multinomial, ONNXOpSupportState::Unsupported +Neg, ONNXOpCode::Neg, ONNXOpSupportState::Unsupported +Not, ONNXOpCode::Not, ONNXOpSupportState::Unsupported +Or, ONNXOpCode::Or, ONNXOpSupportState::Unsupported +PRelu, ONNXOpCode::PRelu, ONNXOpSupportState::Unsupported +Pad, ONNXOpCode::Pad, ONNXOpSupportState::Unsupported +Pow, ONNXOpCode::Pow, ONNXOpSupportState::Unsupported +RNN, ONNXOpCode::RNN, ONNXOpSupportState::Unsupported +RandomNormal, ONNXOpCode::RandomNormal, ONNXOpSupportState::Unsupported +RandomNormalLike, ONNXOpCode::RandomNormalLike, ONNXOpSupportState::Unsupported +RandomUniform, ONNXOpCode::RandomUniform, ONNXOpSupportState::Unsupported +RandomUniformLike, ONNXOpCode::RandomUniformLike, ONNXOpSupportState::Unsupported +Reciprocal, ONNXOpCode::Reciprocal, ONNXOpSupportState::Unsupported +ReduceL1, ONNXOpCode::ReduceL1, ONNXOpSupportState::Unsupported +ReduceL2, ONNXOpCode::ReduceL2, ONNXOpSupportState::Unsupported +ReduceLogSum, ONNXOpCode::ReduceLogSum, ONNXOpSupportState::Unsupported +ReduceLogSumExp, ONNXOpCode::ReduceLogSumExp, ONNXOpSupportState::Unsupported +ReduceMax, ONNXOpCode::ReduceMax, ONNXOpSupportState::Unsupported +ReduceMean, ONNXOpCode::ReduceMean, ONNXOpSupportState::Unsupported +ReduceMin, ONNXOpCode::ReduceMin, ONNXOpSupportState::Unsupported +ReduceProd, ONNXOpCode::ReduceProd, ONNXOpSupportState::Unsupported +ReduceSum, ONNXOpCode::ReduceSum, ONNXOpSupportState::Unsupported +ReduceSumSquare, ONNXOpCode::ReduceSumSquare, ONNXOpSupportState::Unsupported +Relu, ONNXOpCode::Relu, ONNXOpSupportState::Fullysupported +Reshape, ONNXOpCode::Reshape, ONNXOpSupportState::Fullysupported +Scan, ONNXOpCode::Scan, ONNXOpSupportState::Unsupported +Selu, ONNXOpCode::Selu, ONNXOpSupportState::Unsupported +Shape, ONNXOpCode::Shape, ONNXOpSupportState::Unsupported +Sigmoid, ONNXOpCode::Sigmoid, ONNXOpSupportState::Unsupported +Sin, ONNXOpCode::Sin, ONNXOpSupportState::Unsupported +Size, ONNXOpCode::Size, ONNXOpSupportState::Unsupported +Slice, ONNXOpCode::Slice, ONNXOpSupportState::Unsupported +Softmax, ONNXOpCode::Softmax, ONNXOpSupportState::Fullysupported +Softplus, ONNXOpCode::Softplus, ONNXOpSupportState::Unsupported +Softsign, ONNXOpCode::Softsign, ONNXOpSupportState::Unsupported +SpaceToDepth, ONNXOpCode::SpaceToDepth, ONNXOpSupportState::Unsupported +Split, ONNXOpCode::Split, ONNXOpSupportState::Fullysupported +Sqrt, ONNXOpCode::Sqrt, ONNXOpSupportState::Unsupported +Squeeze, ONNXOpCode::Squeeze, ONNXOpSupportState::Unsupported +Sub, ONNXOpCode::Sub, ONNXOpSupportState::Unsupported +Sum, ONNXOpCode::Sum, ONNXOpSupportState::Unsupported +Tan, ONNXOpCode::Tan, ONNXOpSupportState::Unsupported +Tanh, ONNXOpCode::Tanh, ONNXOpSupportState::Unsupported +Tile, ONNXOpCode::Tile, ONNXOpSupportState::Unsupported +TopK, ONNXOpCode::TopK, ONNXOpSupportState::Unsupported +Transpose, ONNXOpCode::Transpose, ONNXOpSupportState::Unsupported +Unsqueeze, ONNXOpCode::Unsqueeze, ONNXOpSupportState::Unsupported +Upsample, ONNXOpCode::Upsample, ONNXOpSupportState::Unsupported +Xor, ONNXOpCode::Xor, ONNXOpSupportState::Unsupported +ATen, ONNXOpCode::ATen, ONNXOpSupportState::Unsupported +Affine, ONNXOpCode::Affine, ONNXOpSupportState::Unsupported +ConstantFill, ONNXOpCode::ConstantFill, ONNXOpSupportState::Unsupported +Crop, ONNXOpCode::Crop, ONNXOpSupportState::Unsupported +DynamicSlice, ONNXOpCode::DynamicSlice, ONNXOpSupportState::Unsupported +GRUUnit, ONNXOpCode::GRUUnit, ONNXOpSupportState::Unsupported +GivenTensorFill, ONNXOpCode::GivenTensorFill, ONNXOpSupportState::Unsupported +ImageScaler, ONNXOpCode::ImageScaler, ONNXOpSupportState::Unsupported +ParametricSoftplus, ONNXOpCode::ParametricSoftplus, ONNXOpSupportState::Unsupported +Scale, ONNXOpCode::Scale, ONNXOpSupportState::Partiallysupported +ScaledTanh, ONNXOpCode::ScaledTanh, ONNXOpSupportState::Unsupported +ThresholdedRelu, ONNXOpCode::ThresholdedRelu, ONNXOpSupportState::Unsupported diff --git a/contrib/nnc/passes/onnx_frontend/ONNXPerfectHash.h b/contrib/nnc/passes/onnx_frontend/ONNXPerfectHash.h new file mode 100644 index 0000000..13ea69d --- /dev/null +++ b/contrib/nnc/passes/onnx_frontend/ONNXPerfectHash.h @@ -0,0 +1,398 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved + * + * 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. + */ + +/* C++ code produced by gperf version 3.1 */ +/* Command-line: gperf --output-file=ONNXPerfectHash.h ONNXPerfect.gperf */ +/* Computed positions: -k'1-2,$' */ + +#if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \ + && ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \ + && (')' == 41) && ('*' == 42) && ('+' == 43) && (',' == 44) \ + && ('-' == 45) && ('.' == 46) && ('/' == 47) && ('0' == 48) \ + && ('1' == 49) && ('2' == 50) && ('3' == 51) && ('4' == 52) \ + && ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) \ + && ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) \ + && ('=' == 61) && ('>' == 62) && ('?' == 63) && ('A' == 65) \ + && ('B' == 66) && ('C' == 67) && ('D' == 68) && ('E' == 69) \ + && ('F' == 70) && ('G' == 71) && ('H' == 72) && ('I' == 73) \ + && ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) \ + && ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) \ + && ('R' == 82) && ('S' == 83) && ('T' == 84) && ('U' == 85) \ + && ('V' == 86) && ('W' == 87) && ('X' == 88) && ('Y' == 89) \ + && ('Z' == 90) && ('[' == 91) && ('\\' == 92) && (']' == 93) \ + && ('^' == 94) && ('_' == 95) && ('a' == 97) && ('b' == 98) \ + && ('c' == 99) && ('d' == 100) && ('e' == 101) && ('f' == 102) \ + && ('g' == 103) && ('h' == 104) && ('i' == 105) && ('j' == 106) \ + && ('k' == 107) && ('l' == 108) && ('m' == 109) && ('n' == 110) \ + && ('o' == 111) && ('p' == 112) && ('q' == 113) && ('r' == 114) \ + && ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \ + && ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \ + && ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126)) +/* The character set is not based on ISO-646. */ +#error "gperf generated tables don't work with this execution character set. Please report a bug to ." +#endif + +#line 1 "ONNXPerfect.gperf" + +#include "ONNXOpType.h" + +using namespace nnc; + +/* maximum key range = 193, duplicates = 0 */ + +class ONNXPerfectHash +{ +private: + static inline unsigned int hash (const char *str, size_t len); +public: + static const struct ONNXOpType *getONNXOpType (const char *str, size_t len); +}; + +inline unsigned int +ONNXPerfectHash::hash (const char *str, size_t len) +{ + static const unsigned char asso_values[] = + { + 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, + 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, + 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, + 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, + 199, 199, 199, 199, 199, 199, 199, 199, 199, 22, + 0, 199, 199, 199, 199, 199, 199, 199, 199, 199, + 199, 199, 199, 199, 199, 40, 75, 0, 25, 35, + 50, 25, 0, 65, 199, 0, 5, 0, 10, 65, + 90, 199, 0, 20, 110, 82, 199, 199, 0, 199, + 199, 199, 199, 199, 199, 199, 199, 0, 25, 60, + 35, 5, 25, 125, 30, 65, 199, 199, 0, 40, + 5, 15, 20, 60, 10, 90, 35, 40, 45, 45, + 65, 55, 199, 199, 199, 199, 199, 199, 199, 199, + 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, + 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, + 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, + 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, + 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, + 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, + 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, + 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, + 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, + 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, + 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, + 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, + 199, 199, 199, 199, 199, 199 + }; + return len + asso_values[static_cast(str[1])] + asso_values[static_cast(str[0])] + asso_values[static_cast(str[len - 1])]; +} + +const struct ONNXOpType * +ONNXPerfectHash::getONNXOpType (const char *str, size_t len) +{ + enum + { + TOTAL_KEYWORDS = 118, + MIN_WORD_LENGTH = 2, + MAX_WORD_LENGTH = 19, + MIN_HASH_VALUE = 6, + MAX_HASH_VALUE = 198 + }; + + static const struct ONNXOpType wordlist[] = + { + {""}, {""}, {""}, {""}, {""}, {""}, +#line 84 "ONNXPerfect.gperf" + {"MatMul", ONNXOpCode::MatMul, ONNXOpSupportState::Unsupported}, +#line 86 "ONNXPerfect.gperf" + {"MaxPool", ONNXOpCode::MaxPool, ONNXOpSupportState::Supported}, + {""}, +#line 45 "ONNXPerfect.gperf" + {"Ceil", ONNXOpCode::Ceil, ONNXOpSupportState::Unsupported}, +#line 87 "ONNXPerfect.gperf" + {"MaxRoiPool", ONNXOpCode::MaxRoiPool, ONNXOpSupportState::Unsupported}, + {""}, +#line 99 "ONNXPerfect.gperf" + {"RandomNormal", ONNXOpCode::RandomNormal, ONNXOpSupportState::Unsupported}, +#line 105 "ONNXPerfect.gperf" + {"ReduceL2", ONNXOpCode::ReduceL2, ONNXOpSupportState::Unsupported}, +#line 88 "ONNXPerfect.gperf" + {"Mean", ONNXOpCode::Mean, ONNXOpSupportState::Unsupported}, +#line 103 "ONNXPerfect.gperf" + {"Reciprocal", ONNXOpCode::Reciprocal, ONNXOpSupportState::Unsupported}, + {""}, +#line 115 "ONNXPerfect.gperf" + {"Reshape", ONNXOpCode::Reshape, ONNXOpSupportState::Fullysupported}, +#line 75 "ONNXPerfect.gperf" + {"LRN", ONNXOpCode::LRN, ONNXOpSupportState::Unsupported}, +#line 110 "ONNXPerfect.gperf" + {"ReduceMin", ONNXOpCode::ReduceMin, ONNXOpSupportState::Unsupported}, +#line 109 "ONNXPerfect.gperf" + {"ReduceMean", ONNXOpCode::ReduceMean, ONNXOpSupportState::Unsupported}, +#line 100 "ONNXPerfect.gperf" + {"RandomNormalLike", ONNXOpCode::RandomNormalLike, ONNXOpSupportState::Unsupported}, +#line 102 "ONNXPerfect.gperf" + {"RandomUniformLike", ONNXOpCode::RandomUniformLike, ONNXOpSupportState::Unsupported}, +#line 98 "ONNXPerfect.gperf" + {"RNN", ONNXOpCode::RNN, ONNXOpSupportState::Unsupported}, +#line 46 "ONNXPerfect.gperf" + {"Clip", ONNXOpCode::Clip, ONNXOpSupportState::Unsupported}, +#line 113 "ONNXPerfect.gperf" + {"ReduceSumSquare", ONNXOpCode::ReduceSumSquare, ONNXOpSupportState::Unsupported}, + {""}, +#line 142 "ONNXPerfect.gperf" + {"ConstantFill", ONNXOpCode::ConstantFill, ONNXOpSupportState::Unsupported}, +#line 139 "ONNXPerfect.gperf" + {"Xor", ONNXOpCode::Xor, ONNXOpSupportState::Unsupported}, +#line 76 "ONNXPerfect.gperf" + {"LSTM", ONNXOpCode::LSTM, ONNXOpSupportState::Unsupported}, +#line 122 "ONNXPerfect.gperf" + {"Slice", ONNXOpCode::Slice, ONNXOpSupportState::Unsupported}, +#line 83 "ONNXPerfect.gperf" + {"LpPool", ONNXOpCode::LpPool, ONNXOpSupportState::Unsupported}, +#line 49 "ONNXPerfect.gperf" + {"ConstantLike", ONNXOpCode::ConstantLike, ONNXOpSupportState::Unsupported}, +#line 51 "ONNXPerfect.gperf" + {"ConvTranspose", ONNXOpCode::ConvTranspose, ONNXOpSupportState::Unsupported}, +#line 143 "ONNXPerfect.gperf" + {"Crop", ONNXOpCode::Crop, ONNXOpSupportState::Unsupported}, +#line 104 "ONNXPerfect.gperf" + {"ReduceL1", ONNXOpCode::ReduceL1, ONNXOpSupportState::Unsupported}, + {""}, +#line 67 "ONNXPerfect.gperf" + {"GlobalLpPool", ONNXOpCode::GlobalLpPool, ONNXOpSupportState::Unsupported}, +#line 68 "ONNXPerfect.gperf" + {"GlobalMaxPool", ONNXOpCode::GlobalMaxPool, ONNXOpSupportState::Unsupported}, +#line 44 "ONNXPerfect.gperf" + {"Cast", ONNXOpCode::Cast, ONNXOpSupportState::Unsupported}, +#line 107 "ONNXPerfect.gperf" + {"ReduceLogSumExp", ONNXOpCode::ReduceLogSumExp, ONNXOpSupportState::Unsupported}, +#line 64 "ONNXPerfect.gperf" + {"Gather", ONNXOpCode::Gather, ONNXOpSupportState::Unsupported}, +#line 66 "ONNXPerfect.gperf" + {"GlobalAveragePool", ONNXOpCode::GlobalAveragePool, ONNXOpSupportState::Unsupported}, +#line 90 "ONNXPerfect.gperf" + {"Mul", ONNXOpCode::Mul, ONNXOpSupportState::Unsupported}, +#line 81 "ONNXPerfect.gperf" + {"Loop", ONNXOpCode::Loop, ONNXOpSupportState::Unsupported}, +#line 82 "ONNXPerfect.gperf" + {"LpNormalization", ONNXOpCode::LpNormalization, ONNXOpSupportState::Unsupported}, +#line 70 "ONNXPerfect.gperf" + {"HardSigmoid", ONNXOpCode::HardSigmoid, ONNXOpSupportState::Unsupported}, +#line 53 "ONNXPerfect.gperf" + {"DepthToSpace", ONNXOpCode::DepthToSpace, ONNXOpSupportState::Unsupported}, +#line 125 "ONNXPerfect.gperf" + {"Softsign", ONNXOpCode::Softsign, ONNXOpSupportState::Unsupported}, +#line 114 "ONNXPerfect.gperf" + {"Relu", ONNXOpCode::Relu, ONNXOpSupportState::Fullysupported}, +#line 111 "ONNXPerfect.gperf" + {"ReduceProd", ONNXOpCode::ReduceProd, ONNXOpSupportState::Unsupported}, +#line 91 "ONNXPerfect.gperf" + {"Multinomial", ONNXOpCode::Multinomial, ONNXOpSupportState::Unsupported}, +#line 69 "ONNXPerfect.gperf" + {"Greater", ONNXOpCode::Greater, ONNXOpSupportState::Unsupported}, +#line 101 "ONNXPerfect.gperf" + {"RandomUniform", ONNXOpCode::RandomUniform, ONNXOpSupportState::Unsupported}, +#line 112 "ONNXPerfect.gperf" + {"ReduceSum", ONNXOpCode::ReduceSum, ONNXOpSupportState::Unsupported}, + {""}, +#line 47 "ONNXPerfect.gperf" + {"Concat", ONNXOpCode::Concat, ONNXOpSupportState::Fullysupported}, +#line 106 "ONNXPerfect.gperf" + {"ReduceLogSum", ONNXOpCode::ReduceLogSum, ONNXOpSupportState::Unsupported}, +#line 48 "ONNXPerfect.gperf" + {"Constant", ONNXOpCode::Constant, ONNXOpSupportState::Unsupported}, +#line 77 "ONNXPerfect.gperf" + {"LeakyRelu", ONNXOpCode::LeakyRelu, ONNXOpSupportState::Unsupported}, +#line 118 "ONNXPerfect.gperf" + {"Shape", ONNXOpCode::Shape, ONNXOpSupportState::Unsupported}, +#line 39 "ONNXPerfect.gperf" + {"ArgMin", ONNXOpCode::ArgMin, ONNXOpSupportState::Unsupported}, +#line 61 "ONNXPerfect.gperf" + {"Flatten", ONNXOpCode::Flatten, ONNXOpSupportState::Unsupported}, +#line 93 "ONNXPerfect.gperf" + {"Not", ONNXOpCode::Not, ONNXOpSupportState::Unsupported}, +#line 50 "ONNXPerfect.gperf" + {"Conv", ONNXOpCode::Conv, ONNXOpSupportState::Fullysupported}, +#line 62 "ONNXPerfect.gperf" + {"Floor", ONNXOpCode::Floor, ONNXOpSupportState::Unsupported}, + {""}, +#line 145 "ONNXPerfect.gperf" + {"GRUUnit", ONNXOpCode::GRUUnit, ONNXOpSupportState::Unsupported}, +#line 85 "ONNXPerfect.gperf" + {"Max", ONNXOpCode::Max, ONNXOpSupportState::Unsupported}, +#line 117 "ONNXPerfect.gperf" + {"Selu", ONNXOpCode::Selu, ONNXOpSupportState::Unsupported}, + {""}, {""}, +#line 71 "ONNXPerfect.gperf" + {"Hardmax", ONNXOpCode::Hardmax, ONNXOpSupportState::Unsupported}, +#line 89 "ONNXPerfect.gperf" + {"Min", ONNXOpCode::Min, ONNXOpSupportState::Unsupported}, +#line 65 "ONNXPerfect.gperf" + {"Gemm", ONNXOpCode::Gemm, ONNXOpSupportState::Unsupported}, + {""}, +#line 141 "ONNXPerfect.gperf" + {"Affine", ONNXOpCode::Affine, ONNXOpSupportState::Unsupported}, +#line 55 "ONNXPerfect.gperf" + {"Dropout", ONNXOpCode::Dropout, ONNXOpSupportState::Fullysupported}, +#line 56 "ONNXPerfect.gperf" + {"Elu", ONNXOpCode::Elu, ONNXOpSupportState::Unsupported}, +#line 108 "ONNXPerfect.gperf" + {"ReduceMax", ONNXOpCode::ReduceMax, ONNXOpSupportState::Unsupported}, +#line 127 "ONNXPerfect.gperf" + {"Split", ONNXOpCode::Split, ONNXOpSupportState::Fullysupported}, + {""}, +#line 126 "ONNXPerfect.gperf" + {"SpaceToDepth", ONNXOpCode::SpaceToDepth, ONNXOpSupportState::Unsupported}, +#line 37 "ONNXPerfect.gperf" + {"And", ONNXOpCode::And, ONNXOpSupportState::Unsupported}, +#line 41 "ONNXPerfect.gperf" + {"Atan", ONNXOpCode::Atan, ONNXOpSupportState::Unsupported}, + {""}, {""}, +#line 94 "ONNXPerfect.gperf" + {"Or", ONNXOpCode::Or, ONNXOpSupportState::Unsupported}, +#line 130 "ONNXPerfect.gperf" + {"Sub", ONNXOpCode::Sub, ONNXOpSupportState::Unsupported}, +#line 116 "ONNXPerfect.gperf" + {"Scan", ONNXOpCode::Scan, ONNXOpSupportState::Unsupported}, +#line 149 "ONNXPerfect.gperf" + {"Scale", ONNXOpCode::Scale, ONNXOpSupportState::Partiallysupported}, + {""}, +#line 129 "ONNXPerfect.gperf" + {"Squeeze", ONNXOpCode::Squeeze, ONNXOpSupportState::Unsupported}, +#line 120 "ONNXPerfect.gperf" + {"Sin", ONNXOpCode::Sin, ONNXOpSupportState::Unsupported}, +#line 121 "ONNXPerfect.gperf" + {"Size", ONNXOpCode::Size, ONNXOpSupportState::Unsupported}, +#line 80 "ONNXPerfect.gperf" + {"LogSoftmax", ONNXOpCode::LogSoftmax, ONNXOpSupportState::Unsupported}, +#line 42 "ONNXPerfect.gperf" + {"AveragePool", ONNXOpCode::AveragePool, ONNXOpSupportState::Fullysupported}, +#line 144 "ONNXPerfect.gperf" + {"DynamicSlice", ONNXOpCode::DynamicSlice, ONNXOpSupportState::Unsupported}, +#line 43 "ONNXPerfect.gperf" + {"BatchNormalization", ONNXOpCode::BatchNormalization, ONNXOpSupportState::Fullysupported}, + {""}, +#line 57 "ONNXPerfect.gperf" + {"Equal", ONNXOpCode::Equal, ONNXOpSupportState::Unsupported}, +#line 137 "ONNXPerfect.gperf" + {"Unsqueeze", ONNXOpCode::Unsqueeze, ONNXOpSupportState::Unsupported}, +#line 60 "ONNXPerfect.gperf" + {"EyeLike", ONNXOpCode::EyeLike, ONNXOpSupportState::Unsupported}, +#line 131 "ONNXPerfect.gperf" + {"Sum", ONNXOpCode::Sum, ONNXOpSupportState::Unsupported}, +#line 78 "ONNXPerfect.gperf" + {"Less", ONNXOpCode::Less, ONNXOpSupportState::Unsupported}, +#line 146 "ONNXPerfect.gperf" + {"GivenTensorFill", ONNXOpCode::GivenTensorFill, ONNXOpSupportState::Unsupported}, + {""}, +#line 123 "ONNXPerfect.gperf" + {"Softmax", ONNXOpCode::Softmax, ONNXOpSupportState::Fullysupported}, +#line 52 "ONNXPerfect.gperf" + {"Cos", ONNXOpCode::Cos, ONNXOpSupportState::Unsupported}, + {""}, +#line 63 "ONNXPerfect.gperf" + {"GRU", ONNXOpCode::GRU, ONNXOpSupportState::Unsupported}, + {""}, {""}, +#line 36 "ONNXPerfect.gperf" + {"Add", ONNXOpCode::Add, ONNXOpSupportState::Unsupported}, + {""}, +#line 138 "ONNXPerfect.gperf" + {"Upsample", ONNXOpCode::Upsample, ONNXOpSupportState::Unsupported}, + {""}, +#line 73 "ONNXPerfect.gperf" + {"If", ONNXOpCode::If, ONNXOpSupportState::Unsupported}, +#line 132 "ONNXPerfect.gperf" + {"Tan", ONNXOpCode::Tan, ONNXOpSupportState::Unsupported}, +#line 128 "ONNXPerfect.gperf" + {"Sqrt", ONNXOpCode::Sqrt, ONNXOpSupportState::Unsupported}, +#line 150 "ONNXPerfect.gperf" + {"ScaledTanh", ONNXOpCode::ScaledTanh, ONNXOpSupportState::Unsupported}, +#line 38 "ONNXPerfect.gperf" + {"ArgMax", ONNXOpCode::ArgMax, ONNXOpSupportState::Unsupported}, + {""}, +#line 58 "ONNXPerfect.gperf" + {"Exp", ONNXOpCode::Exp, ONNXOpSupportState::Unsupported}, + {""}, {""}, +#line 147 "ONNXPerfect.gperf" + {"ImageScaler", ONNXOpCode::ImageScaler, ONNXOpSupportState::Unsupported}, +#line 119 "ONNXPerfect.gperf" + {"Sigmoid", ONNXOpCode::Sigmoid, ONNXOpSupportState::Unsupported}, +#line 96 "ONNXPerfect.gperf" + {"Pad", ONNXOpCode::Pad, ONNXOpSupportState::Unsupported}, +#line 135 "ONNXPerfect.gperf" + {"TopK", ONNXOpCode::TopK, ONNXOpSupportState::Unsupported}, + {""}, {""}, {""}, +#line 124 "ONNXPerfect.gperf" + {"Softplus", ONNXOpCode::Softplus, ONNXOpSupportState::Unsupported}, +#line 136 "ONNXPerfect.gperf" + {"Transpose", ONNXOpCode::Transpose, ONNXOpSupportState::Unsupported}, +#line 95 "ONNXPerfect.gperf" + {"PRelu", ONNXOpCode::PRelu, ONNXOpSupportState::Unsupported}, + {""}, {""}, +#line 54 "ONNXPerfect.gperf" + {"Div", ONNXOpCode::Div, ONNXOpSupportState::Unsupported}, +#line 40 "ONNXPerfect.gperf" + {"Asin", ONNXOpCode::Asin, ONNXOpSupportState::Unsupported}, + {""}, +#line 59 "ONNXPerfect.gperf" + {"Expand", ONNXOpCode::Expand, ONNXOpSupportState::Unsupported}, + {""}, +#line 92 "ONNXPerfect.gperf" + {"Neg", ONNXOpCode::Neg, ONNXOpSupportState::Unsupported}, +#line 133 "ONNXPerfect.gperf" + {"Tanh", ONNXOpCode::Tanh, ONNXOpSupportState::Unsupported}, + {""}, {""}, {""}, +#line 79 "ONNXPerfect.gperf" + {"Log", ONNXOpCode::Log, ONNXOpSupportState::Unsupported}, + {""}, {""}, {""}, {""}, +#line 97 "ONNXPerfect.gperf" + {"Pow", ONNXOpCode::Pow, ONNXOpSupportState::Unsupported}, +#line 74 "ONNXPerfect.gperf" + {"InstanceNormalizati", ONNXOpCode::InstanceNormalizati, ONNXOpSupportState::Unsupported}, + {""}, {""}, {""}, +#line 34 "ONNXPerfect.gperf" + {"Abs", ONNXOpCode::Abs, ONNXOpSupportState::Unsupported}, +#line 140 "ONNXPerfect.gperf" + {"ATen", ONNXOpCode::ATen, ONNXOpSupportState::Unsupported}, + {""}, {""}, {""}, +#line 72 "ONNXPerfect.gperf" + {"Identity", ONNXOpCode::Identity, ONNXOpSupportState::Supported}, + {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, + {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, + {""}, {""}, +#line 134 "ONNXPerfect.gperf" + {"Tile", ONNXOpCode::Tile, ONNXOpSupportState::Unsupported}, + {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, +#line 35 "ONNXPerfect.gperf" + {"Acos", ONNXOpCode::Acos, ONNXOpSupportState::Unsupported}, +#line 151 "ONNXPerfect.gperf" + {"ThresholdedRelu", ONNXOpCode::ThresholdedRelu, ONNXOpSupportState::Unsupported}, + {""}, {""}, +#line 148 "ONNXPerfect.gperf" + {"ParametricSoftplus", ONNXOpCode::ParametricSoftplus, ONNXOpSupportState::Unsupported} + }; + + if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) + { + unsigned int key = hash (str, len); + + if (key <= MAX_HASH_VALUE) + { + const char *s = wordlist[key].name; + + if (*str == *s && !strcmp (str + 1, s + 1)) + return &wordlist[key]; + } + } + return 0; +}