diff --git a/README.md b/README.md index 8772bb12073..f50c7cff440 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![Inner Source](https://img.shields.io/badge/innersource-incubating-orange)](http://mosaic.sec.samsung.net/kms/comty.do?comtyId=279217135&menuId=324419756&postId=373704030&page=view&type=LIST) + # nnfw A high-performance, on-device neural network inference framework @@ -45,7 +47,7 @@ Sooner or later, the maintainer will tag the `FEATURE_REQUEST` label and appear We expect one of the most frequent feature requests would be the operator kernel implementation. It is good to make a request, but it is better if you contribute by yourself. See the following guide, -[How to Implement Operator Kernel](docs/nnfw/HowToImplementOperatorKernel.md), for help. +[How to Implement Operator Kernel](docs/nnfw/howto/HowToAddNewOperation.md), for help. We are looking forward to your participation. Thank you in advance! diff --git a/compiler/circle-inspect/src/Model.cpp b/compiler/circle-inspect/src/Model.cpp index fec1eb99e03..1924bfafcbd 100644 --- a/compiler/circle-inspect/src/Model.cpp +++ b/compiler/circle-inspect/src/Model.cpp @@ -129,7 +129,7 @@ std::unique_ptr load_circle(const std::string &path) // Check if file is a valid Flatbuffer file const uint8_t *u8data = reinterpret_cast(data); - flatbuffers::Verifier verifier{u8data, size}; + flatbuffers::Verifier verifier{u8data, static_cast(size)}; if (!circle::VerifyModelBuffer(verifier)) { munmap(data, size); diff --git a/compiler/circle2circle/CMakeLists.txt b/compiler/circle2circle/CMakeLists.txt new file mode 100644 index 00000000000..6441799414d --- /dev/null +++ b/compiler/circle2circle/CMakeLists.txt @@ -0,0 +1,42 @@ +file(GLOB_RECURSE SOURCES "src/*.cpp") +file(GLOB_RECURSE TESTS "src/*.test.cpp") +list(REMOVE_ITEM SOURCES ${TESTS}) + +add_executable(circle2circle "${SOURCES}") +target_include_directories(circle2circle PRIVATE include) +target_include_directories(circle2circle PRIVATE src) +target_link_libraries(circle2circle nncc_common) +target_link_libraries(circle2circle safemain) +target_link_libraries(circle2circle stdex) +target_link_libraries(circle2circle oops) +target_link_libraries(circle2circle hermes) +target_link_libraries(circle2circle hermes_std) +target_link_libraries(circle2circle loco) +target_link_libraries(circle2circle mio_circle) +target_link_libraries(circle2circle luci_import) +target_link_libraries(circle2circle luci_service) +target_link_libraries(circle2circle luci_pass) +target_link_libraries(circle2circle luci_export) + +install(TARGETS circle2circle DESTINATION bin) + +if(NOT ENABLE_TEST) + return() +endif(NOT ENABLE_TEST) + +nnas_find_package(GTest REQUIRED) + +GTest_AddTest(circle2circle_test ${TESTS} ${SOURCES}) +target_include_directories(circle2circle_test PRIVATE include) +target_include_directories(circle2circle_test PRIVATE src) +target_link_libraries(circle2circle_test nncc_common) +target_link_libraries(circle2circle_test stdex) +target_link_libraries(circle2circle_test oops) +target_link_libraries(circle2circle_test hermes) +target_link_libraries(circle2circle_test hermes_std) +target_link_libraries(circle2circle_test loco) +target_link_libraries(circle2circle_test mio_circle) +target_link_libraries(circle2circle_test luci_import) +target_link_libraries(circle2circle_test luci_service) +target_link_libraries(circle2circle_test luci_pass) +target_link_libraries(circle2circle_test luci_export) diff --git a/compiler/circle2circle/README.md b/compiler/circle2circle/README.md new file mode 100644 index 00000000000..7bc1b7f594b --- /dev/null +++ b/compiler/circle2circle/README.md @@ -0,0 +1,3 @@ +# circle2circle + +_circle2circle_ provides Circle optimizations and quantizations as executable tool diff --git a/compiler/circle2circle/include/CircleExpContract.h b/compiler/circle2circle/include/CircleExpContract.h new file mode 100644 index 00000000000..edb12d45361 --- /dev/null +++ b/compiler/circle2circle/include/CircleExpContract.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2020 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 __CIRCLE2CIRCLE_CIRCLEXPCONTRACT_H__ +#define __CIRCLE2CIRCLE_CIRCLEXPCONTRACT_H__ + +#include +#include +#include + +#include +#include + +struct CircleExpContract : public luci::CircleExporter::Contract +{ +public: + CircleExpContract(loco::Graph *graph, const std::string &filename) + : _graph(graph), _filepath(filename) + { + // NOTHING TO DO + } + virtual ~CircleExpContract() = default; + +public: + loco::Graph *graph(void) const final { return _graph; } + +public: + bool store(const char *ptr, const size_t size) const final; + +private: + loco::Graph *_graph; + const std::string _filepath; +}; + +#endif // __CIRCLE2CIRCLE_CIRCLEXPCONTRACT_H__ diff --git a/compiler/circle2circle/include/Model.h b/compiler/circle2circle/include/Model.h new file mode 100644 index 00000000000..35b7e3239fd --- /dev/null +++ b/compiler/circle2circle/include/Model.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2020 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 __CIRCLE2CIRCLE_MODEL_H__ +#define __CIRCLE2CIRCLE_MODEL_H__ + +#include + +#include + +namespace luci +{ + +struct Model +{ + virtual ~Model() = default; + + virtual const ::circle::Model *model(void) = 0; +}; + +/** + * @brief Load Circle model (as a raw Model) from a given path + * + * @note May return a nullptr + */ +std::unique_ptr load_model(const std::string &path); + +} // namespace luci + +#endif // __CIRCLE2CIRCLE_MODEL_H__ diff --git a/compiler/circle2circle/requires.cmake b/compiler/circle2circle/requires.cmake new file mode 100644 index 00000000000..5b1e657caad --- /dev/null +++ b/compiler/circle2circle/requires.cmake @@ -0,0 +1,10 @@ +require("loco") +require("locop") +require("logo-core") +require("stdex") +require("safemain") +require("mio-circle") +require("oops") +require("hermes") +require("hermes-std") +require("luci") diff --git a/compiler/circle2circle/src/Circle2Circle.cpp b/compiler/circle2circle/src/Circle2Circle.cpp new file mode 100644 index 00000000000..600369e7d38 --- /dev/null +++ b/compiler/circle2circle/src/Circle2Circle.cpp @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2020 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 "Model.h" +#include "CircleExpContract.h" + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + +using OptionHook = std::function; + +using Algorithms = luci::CircleOptimizer::Options::Algorithm; + +void print_help(const char *progname) +{ + std::cerr << "USAGE: " << progname << " [options] input output" << std::endl; + std::cerr << " --fuse_instnorm : Enable FuseInstanceNormalization Pass" << std::endl; + std::cerr << std::endl; +} + +int entry(int argc, char **argv) +{ + if (argc < 3) + { + std::cerr << "ERROR: Failed to parse arguments" << std::endl; + std::cerr << std::endl; + print_help(argv[0]); + return 255; + } + + // Simple argument parser (based on map) + std::map argparse; + luci::CircleOptimizer optimizer; + + auto options = optimizer.options(); + + // TODO merge this with help message + argparse["--fuse_instnorm"] = [&options](const char **) { + options->enable(Algorithms::FuseInstanceNorm); + return 0; + }; + + for (int n = 1; n < argc - 2; ++n) + { + const std::string tag{argv[n]}; + auto it = argparse.find(tag); + if (it == argparse.end()) + { + std::cerr << "Option '" << tag << "' is not supported" << std::endl; + std::cerr << std::endl; + print_help(argv[0]); + return 255; + } + + n += it->second((const char **)&argv[n + 1]); + } + + std::string input_path = argv[argc - 2]; + std::string output_path = argv[argc - 1]; + + // Load model from the file + std::unique_ptr model = luci::load_model(input_path); + if (model == nullptr) + { + std::cerr << "ERROR: Failed to load '" << input_path << "'" << std::endl; + return 255; + } + + const circle::Model *input_model = model->model(); + if (input_model == nullptr) + { + std::cerr << "ERROR: Failed to read '" << input_path << "'" << std::endl; + return 255; + } + + // Import from input Circle file + luci::Importer importer; + auto graph = importer.import(input_model); + + // call luci optimizations + optimizer.optimize(graph.get()); + + if (!luci::validate(graph.get())) + return 255; + + // Export to output Circle file + luci::CircleExporter exporter; + + CircleExpContract contract(graph.get(), output_path); + + return exporter.invoke(&contract) ? 0 : 255; +} diff --git a/compiler/circle2circle/src/Circle2Circle.test.cpp b/compiler/circle2circle/src/Circle2Circle.test.cpp new file mode 100644 index 00000000000..015358ae7cd --- /dev/null +++ b/compiler/circle2circle/src/Circle2Circle.test.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2020 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 "TestHelper.h" + +#include + +TEST(Circle2CircleTest, NoArg_NEG) +{ + Argv<1> argv; + argv.add("circle2circle"); + + ::testing::internal::CaptureStdout(); + int result = entry(1, argv.argv()); + ASSERT_EQ(result, 255); +} diff --git a/compiler/circle2circle/src/CircleExpContract.cpp b/compiler/circle2circle/src/CircleExpContract.cpp new file mode 100644 index 00000000000..b56b7eedc4d --- /dev/null +++ b/compiler/circle2circle/src/CircleExpContract.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2020 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 "CircleExpContract.h" + +#include + +#include +#include + +bool CircleExpContract::store(const char *ptr, const size_t size) const +{ + if (!ptr) + INTERNAL_EXN("Graph was not serialized by FlatBuffer for some reason"); + + std::ofstream fs(_filepath.c_str(), std::ofstream::binary); + fs.write(ptr, size); + + return fs.good(); +} diff --git a/compiler/circle2circle/src/Model.cpp b/compiler/circle2circle/src/Model.cpp new file mode 100644 index 00000000000..20d55a131d8 --- /dev/null +++ b/compiler/circle2circle/src/Model.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2020 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 "Model.h" + +#include +#include + +#include +#include +#include + +namespace +{ + +class FileModel final : public luci::Model +{ +public: + explicit FileModel(const std::string &filename) : _filename(filename) {} + +public: + FileModel(const FileModel &) = delete; + FileModel(FileModel &&) = delete; + +public: + const ::circle::Model *model(void) override + { + std::ifstream file(_filename, std::ios::binary | std::ios::in); + if (!file.good()) + return nullptr; + + file.unsetf(std::ios::skipws); + + std::streampos fileSize; + file.seekg(0, std::ios::end); + fileSize = file.tellg(); + file.seekg(0, std::ios::beg); + + // reserve capacity + _data.reserve(fileSize); + + // read the data + file.read(_data.data(), fileSize); + if (file.fail()) + return nullptr; + + return ::circle::GetModel(_data.data()); + } + +private: + const std::string _filename; + std::vector _data; +}; + +} // namespace + +namespace luci +{ + +std::unique_ptr load_model(const std::string &path) +{ + return std::unique_ptr{new FileModel(path)}; +} + +} // namespace luci diff --git a/compiler/circle2circle/src/TestHelper.h b/compiler/circle2circle/src/TestHelper.h new file mode 100644 index 00000000000..f4dbe23a9bc --- /dev/null +++ b/compiler/circle2circle/src/TestHelper.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2020 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 __CIRCLE2CIRCLE_TEST_HELPER_H__ +#define __CIRCLE2CIRCLE_TEST_HELPER_H__ + +#include +#include +#include + +int entry(int argc, char **argv); + +template class Argv +{ +public: + typedef char *pchar_t; + +public: + ~Argv() + { + for (size_t n = 0; n < _ptr; ++n) + delete _argv[n]; + } + + void add(const char *in) + { + assert(_ptr < N); + _argv[_ptr] = new char[strlen(in) + 1]; + strcpy(_argv[_ptr], in); + _ptr++; + } + + pchar_t *argv(void) { return _argv; } + +private: + pchar_t _argv[N] = { + nullptr, + }; + size_t _ptr = 0; +}; + +#endif // __CIRCLE2CIRCLE_TEST_HELPER_H__ diff --git a/compiler/circledump/src/Dump.cpp b/compiler/circledump/src/Dump.cpp index 3b7a249be78..3d99189f9a4 100644 --- a/compiler/circledump/src/Dump.cpp +++ b/compiler/circledump/src/Dump.cpp @@ -104,15 +104,8 @@ std::ostream &operator<<(std::ostream &os, const flatbuffers::Vector *fbvect) return os; } -void dump_model(std::ostream &os, const circle::Model *model) +void dump_sub_graph(std::ostream &os, circleread::Reader &reader) { - circleread::Reader reader(model); - - assert(reader.num_subgraph() == 1); - reader.select_subgraph(0); - - auto opcodes = reader.opcodes(); - auto buffers = reader.buffers(); auto tensors = reader.tensors(); auto operators = reader.operators(); auto data_format = reader.data_format(); @@ -129,38 +122,9 @@ void dump_model(std::ostream &os, const circle::Model *model) } os << std::endl; - // dump operator_codes - os << "Operator Codes: [order] OpCodeName (OpCode Enum)" << std::endl; - int32_t opcode_index = 0; - for (auto opcode : opcodes) - { - circle::BuiltinOperator op_code = opcode->builtin_code(); - auto op_name = circleread::opcode_name(opcode); - - os << "[" << opcode_index << "] " << op_name << " (code: " << op_code << ")" << std::endl; - - opcode_index++; - } - os << std::endl; - - // dump buffer - os << "Buffers: B(index) (length) values, if any" << std::endl; - for (uint32_t i = 0; i < buffers->Length(); ++i) - { - const uint8_t *buff_data; - size_t size = reader.buffer_info(i, &buff_data); - - os << "B(" << i << ") (" << size << ") "; - if (buff_data != nullptr) - { - dump_buffer(os, buff_data, size, 16); - } - os << std::endl; - } - os << std::endl; - // dump operands(tensors) - os << "Operands: T(tensor index) TYPE (shape) B(buffer index) OperandName" << std::endl; + os << "Operands: T(subgraph index : tensor index) TYPE (shape) B(buffer index) OperandName" + << std::endl; for (uint32_t i = 0; i < tensors->Length(); ++i) { // TODO refactor to some better structure @@ -170,7 +134,8 @@ void dump_model(std::ostream &os, const circle::Model *model) if (tensor->shape()) dims = circleread::as_index_vector(tensor->shape()); - os << "T(" << i << ") " << circleread::tensor_type(tensor) << " "; + os << "T(" << reader.subgraph_index() << ":" << i << ") " << circleread::tensor_type(tensor) + << " "; os << "(" << dims << ") "; os << "B(" << tensor->buffer() << ") "; os << circleread::tensor_name(tensor) << std::endl; @@ -211,7 +176,7 @@ void dump_model(std::ostream &os, const circle::Model *model) os << std::endl; // dump operators - os << "Operators: O(operator index) OpCodeName " << std::endl; + os << "Operators: O(subgraph index : operator index) OpCodeName " << std::endl; os << " Option(values) ... <-- depending on OpCode" << std::endl; os << " I T(tensor index) OperandName <-- as input" << std::endl; os << " O T(tensor index) OperandName <-- as output" << std::endl; @@ -224,7 +189,7 @@ void dump_model(std::ostream &os, const circle::Model *model) const std::vector &outputs = circleread::as_index_vector(op->outputs()); auto op_name = reader.opcode_name(op); - os << "O(" << i << ") " << op_name << " "; + os << "O(" << reader.subgraph_index() << ":" << i << ") " << op_name << " "; os << std::endl; if (auto op_prn = OpPrinterRegistry::get().lookup(builtincode)) @@ -271,6 +236,69 @@ void dump_model(std::ostream &os, const circle::Model *model) std::string name = circleread::tensor_name(tensor); os << "O T(" << output << ") " << name << std::endl; } + + os << std::endl; +} + +void dump_model(std::ostream &os, const circle::Model *model) +{ + circleread::Reader reader(model); + + uint32_t num_subgraph = reader.num_subgraph(); + + // dump model version + os << "===================================================================" << std::endl; + os << "Model version: " << reader.version() << std::endl; + os << " # sub graphs: " << num_subgraph << std::endl; + os << std::endl; + + auto opcodes = reader.opcodes(); + auto buffers = reader.buffers(); + + // dump operator_codes + os << "Operator Codes: [order] OpCodeName (OpCode Enum)" << std::endl; + int32_t opcode_index = 0; + for (auto opcode : opcodes) + { + circle::BuiltinOperator op_code = opcode->builtin_code(); + auto op_name = circleread::opcode_name(opcode); + auto op_version = opcode->version(); + + os << "[" << opcode_index << "] " << op_name << " (code: " << op_code + << ", version: " << op_version << ")" << std::endl; + + opcode_index++; + } + os << std::endl; + + // dump buffer + os << "Buffers: B(index) (length) values, if any" << std::endl; + for (uint32_t i = 0; i < buffers->Length(); ++i) + { + const uint8_t *buff_data; + size_t size = reader.buffer_info(i, &buff_data); + + os << "B(" << i << ") (" << size << ") "; + if (buff_data != nullptr) + { + dump_buffer(os, buff_data, size, 16); + } + os << std::endl; + } + os << std::endl; + + for (uint32_t sg = 0; sg < num_subgraph; ++sg) + { + reader.select_subgraph(sg); + + os << "-------------------------------------------------------------------" << std::endl; + os << "Sub-Graph: #" << sg << " " << reader.subgraph_name() << std::endl; + os << std::endl; + + dump_sub_graph(os, reader); + } + + os << "===================================================================" << std::endl; } } // namespace circledump diff --git a/compiler/circledump/src/OpPrinter.cpp b/compiler/circledump/src/OpPrinter.cpp index 903678a9af3..f9daab49478 100644 --- a/compiler/circledump/src/OpPrinter.cpp +++ b/compiler/circledump/src/OpPrinter.cpp @@ -39,7 +39,22 @@ class AddPrinter : public OpPrinter if (auto *params = op->builtin_options_as_AddOptions()) { os << " "; - os << "Activation(" << params->fused_activation_function() << ") "; + os << "Activation(" << EnumNameActivationFunctionType(params->fused_activation_function()) + << ") "; + os << std::endl; + } + } +}; + +class ArgMaxPrinter : public OpPrinter +{ +public: + void options(const circle::Operator *op, std::ostream &os) const override + { + if (auto *params = op->builtin_options_as_ArgMaxOptions()) + { + os << " "; + os << "OutputType(" << EnumNameTensorType(params->output_type()) << ") "; os << std::endl; } } @@ -56,7 +71,8 @@ class Conv2DPrinter : public OpPrinter os << "Padding(" << conv_params->padding() << ") "; os << "Stride.W(" << conv_params->stride_w() << ") "; os << "Stride.H(" << conv_params->stride_h() << ") "; - os << "Activation(" << conv_params->fused_activation_function() << ")"; + os << "Activation(" + << EnumNameActivationFunctionType(conv_params->fused_activation_function()) << ")"; os << std::endl; } } @@ -70,7 +86,8 @@ class DivPrinter : public OpPrinter if (auto *params = op->builtin_options_as_DivOptions()) { os << " "; - os << "Activation(" << params->fused_activation_function() << ") "; + os << "Activation(" << EnumNameActivationFunctionType(params->fused_activation_function()) + << ") "; os << std::endl; } } @@ -89,7 +106,8 @@ class Pool2DPrinter : public OpPrinter os << "Stride.H(" << pool_params->stride_h() << ") "; os << "Filter.W(" << pool_params->filter_width() << ") "; os << "Filter.H(" << pool_params->filter_height() << ") "; - os << "Activation(" << pool_params->fused_activation_function() << ")"; + os << "Activation(" + << EnumNameActivationFunctionType(pool_params->fused_activation_function()) << ")"; os << std::endl; } } @@ -103,7 +121,9 @@ class ConcatenationPrinter : public OpPrinter if (auto *concatenation_params = op->builtin_options_as_ConcatenationOptions()) { os << " "; - os << "Activation(" << concatenation_params->fused_activation_function() << ") "; + os << "Activation(" + << EnumNameActivationFunctionType(concatenation_params->fused_activation_function()) + << ") "; os << "Axis(" << concatenation_params->axis() << ")"; os << std::endl; } @@ -139,7 +159,8 @@ class DepthwiseConv2DPrinter : public OpPrinter os << "DepthMultiplier(" << conv_params->depth_multiplier() << ") "; os << "Dilation.W(" << conv_params->dilation_w_factor() << ") "; os << "Dilation.H(" << conv_params->dilation_h_factor() << ")"; - os << "Activation(" << conv_params->fused_activation_function() << ") "; + os << "Activation(" + << EnumNameActivationFunctionType(conv_params->fused_activation_function()) << ") "; os << std::endl; } } @@ -153,10 +174,11 @@ class FullyConnectedPrinter : public OpPrinter if (auto *params = op->builtin_options_as_FullyConnectedOptions()) { os << " "; - os << "WeightFormat(" - << "..." - << ") "; // TODO implement this - os << "Activation(" << params->fused_activation_function() << ") "; + os << "WeightFormat(" << EnumNameFullyConnectedOptionsWeightsFormat(params->weights_format()) + << ") "; + os << "Activation(" << EnumNameActivationFunctionType(params->fused_activation_function()) + << ") "; + os << std::endl; } } @@ -170,7 +192,23 @@ class MulPrinter : public OpPrinter if (auto *params = op->builtin_options_as_MulOptions()) { os << " "; - os << "Activation(" << params->fused_activation_function() << ") "; + os << "Activation(" << EnumNameActivationFunctionType(params->fused_activation_function()) + << ") "; + os << std::endl; + } + } +}; + +class PackPrinter : public OpPrinter +{ +public: + void options(const circle::Operator *op, std::ostream &os) const override + { + if (auto *params = op->builtin_options_as_PackOptions()) + { + os << " "; + os << "ValuesCount(" << params->values_count() << ") "; + os << "Axis(" << params->axis() << ") "; os << std::endl; } } @@ -198,7 +236,8 @@ class SubPrinter : public OpPrinter if (auto *params = op->builtin_options_as_SubOptions()) { os << " "; - os << "Activation(" << params->fused_activation_function() << ") "; + os << "Activation(" << EnumNameActivationFunctionType(params->fused_activation_function()) + << ") "; os << std::endl; } } @@ -247,6 +286,7 @@ class CustomOpPrinter : public OpPrinter OpPrinterRegistry::OpPrinterRegistry() { _op_map[circle::BuiltinOperator_ADD] = make_unique(); + _op_map[circle::BuiltinOperator_ARG_MAX] = make_unique(); _op_map[circle::BuiltinOperator_AVERAGE_POOL_2D] = make_unique(); _op_map[circle::BuiltinOperator_CONCATENATION] = make_unique(); _op_map[circle::BuiltinOperator_CONV_2D] = make_unique(); @@ -255,6 +295,7 @@ OpPrinterRegistry::OpPrinterRegistry() _op_map[circle::BuiltinOperator_FULLY_CONNECTED] = make_unique(); _op_map[circle::BuiltinOperator_MAX_POOL_2D] = make_unique(); _op_map[circle::BuiltinOperator_MUL] = make_unique(); + _op_map[circle::BuiltinOperator_PACK] = make_unique(); // There is no Option for Pad // There is no Option for ReLU and ReLU6 _op_map[circle::BuiltinOperator_RESHAPE] = make_unique(); diff --git a/compiler/circledump/src/Read.cpp b/compiler/circledump/src/Read.cpp index a0ba86778d0..0532255364a 100644 --- a/compiler/circledump/src/Read.cpp +++ b/compiler/circledump/src/Read.cpp @@ -78,6 +78,7 @@ const char *tensor_name(const circle::Tensor *tensor) Reader::Reader(const circle::Model *model) { + _version = model->version(); _subgraphs = model->subgraphs(); _buffers = model->buffers(); @@ -137,6 +138,7 @@ std::string Reader::opcode_name(const circle::Operator *op) const bool Reader::select_subgraph(uint32_t sgindex) { + _subgraph_index = sgindex; _tensors = nullptr; _operators = nullptr; @@ -151,6 +153,9 @@ bool Reader::select_subgraph(uint32_t sgindex) const circle::SubGraph *subgraph = (*_subgraphs)[sgindex]; + auto name = subgraph->name(); + _subgraph_name = name ? name->c_str() : "(noname)"; + _tensors = subgraph->tensors(); _operators = subgraph->operators(); _data_format = subgraph->data_format(); diff --git a/compiler/circledump/src/Read.h b/compiler/circledump/src/Read.h index b80e77e6279..dd1ef20b60d 100644 --- a/compiler/circledump/src/Read.h +++ b/compiler/circledump/src/Read.h @@ -59,6 +59,8 @@ class Reader Reader() = delete; public: + uint32_t version() const { return _version; } + const std::vector &opcodes() { return _op_codes; } const CircleBuffers_t *buffers() { return _buffers; } const CircleTensors_t *tensors() { return _tensors; } @@ -75,13 +77,19 @@ class Reader public: bool select_subgraph(uint32_t subgraph); + const std::string &subgraph_name(void) const { return _subgraph_name; } + uint32_t subgraph_index(void) const { return _subgraph_index; } private: + uint32_t _version; + const CircleSubGraphs_t *_subgraphs{nullptr}; const CircleBuffers_t *_buffers{nullptr}; const CircleTensors_t *_tensors{nullptr}; const CircleOperators_t *_operators{nullptr}; + uint32_t _subgraph_index; + std::string _subgraph_name; std::vector _op_codes; std::vector _inputs; std::vector _outputs; diff --git a/compiler/loco/include/loco/IR/DataType.h b/compiler/loco/include/loco/IR/DataType.h index 1c3abd1514b..b07022bf52e 100644 --- a/compiler/loco/include/loco/IR/DataType.h +++ b/compiler/loco/include/loco/IR/DataType.h @@ -40,6 +40,10 @@ enum class DataType FLOAT16, // IEEE 16-bit floating-point FLOAT32, // IEEE 32-bit floating-point FLOAT64, // IEEE 64-bit floating-point + + // WARNING the size of Bool may vary for NN frameworks + // TODO we need to find a way to resolve this issue + BOOL, // Boolean }; } // namespace loco diff --git a/compiler/loco/include/loco/IR/DataTypeTraits.h b/compiler/loco/include/loco/IR/DataTypeTraits.h index e8270b93522..c4479e545f7 100644 --- a/compiler/loco/include/loco/IR/DataTypeTraits.h +++ b/compiler/loco/include/loco/IR/DataTypeTraits.h @@ -19,6 +19,7 @@ #include "loco/IR/DataType.h" +#include #include namespace loco @@ -57,6 +58,29 @@ template <> struct DataTypeImpl using Type = float; }; +/** + * @brief Returns the size of the data type. + * @note If you need the size at compile time, use `sizeof(typename DataTypeImpl
::Type)`. + */ +inline uint32_t size(DataType data_type) +{ + switch (data_type) + { + case DataType::S8: + return sizeof(DataTypeImpl::Type); + case DataType::U8: + return sizeof(DataTypeImpl::Type); + case DataType::S32: + return sizeof(DataTypeImpl::Type); + case DataType::FLOAT32: + return sizeof(DataTypeImpl::Type); + default: + // TODO Support remaining data types. + assert(false); + return UINT32_MAX; // Avoid compiler warning. + } +} + } // namespace loco #endif // __LOCO_IR_DATA_TYPE_TRAITS_H__ diff --git a/compiler/loco/include/loco/IR/Graph.h b/compiler/loco/include/loco/IR/Graph.h index 46b08e5f571..34b3ea0d638 100644 --- a/compiler/loco/include/loco/IR/Graph.h +++ b/compiler/loco/include/loco/IR/Graph.h @@ -238,7 +238,9 @@ struct GraphInputIndexQueryService : public DialectService virtual bool associated(const Node *node) const = 0; /** - * WARNING! CALLER SHOULD GUARANTEE that associated(node) is true before invoking this API. + * Exceptions + * - index SHOULD throw std::invalid_argument exception if a given node is not associated with + * any input (i.e. assocaited above returns false). */ virtual GraphInputIndex index(const Node *node) const = 0; }; @@ -255,7 +257,9 @@ struct GraphOutputIndexQueryService : public DialectService virtual bool associated(const Node *node) const = 0; /** - * WARNING! CALLER SHOULD GUARANTEE that associated(node) is true before invoking this API. + * Exceptions + * - index SHOULD throw std::invalid_argument exception if a given node is not associated with + * any output (i.e. assocaited above returns false). */ virtual GraphOutputIndex index(const Node *node) const = 0; }; diff --git a/compiler/loco/include/loco/IR/TensorShape.h b/compiler/loco/include/loco/IR/TensorShape.h index 76f803b2b83..af1066d528d 100644 --- a/compiler/loco/include/loco/IR/TensorShape.h +++ b/compiler/loco/include/loco/IR/TensorShape.h @@ -19,6 +19,7 @@ #include "loco/IR/Dimension.h" +#include #include namespace loco @@ -28,6 +29,7 @@ class TensorShape { public: TensorShape() = default; + TensorShape(std::initializer_list dims) : _dims(dims.begin(), dims.end()) {} public: uint32_t rank(void) const { return _dims.size(); } diff --git a/compiler/loco/src/IR/CanonicalDialect.cpp b/compiler/loco/src/IR/CanonicalDialect.cpp index f89ea447bf6..ea956b80e8c 100644 --- a/compiler/loco/src/IR/CanonicalDialect.cpp +++ b/compiler/loco/src/IR/CanonicalDialect.cpp @@ -21,6 +21,7 @@ #include #include +#include namespace { @@ -39,9 +40,11 @@ struct GraphOutputIndexQueryServiceImpl final : public loco::GraphOutputIndexQue loco::GraphOutputIndex index(const loco::Node *node) const final { assert(associated(node)); - auto push = dynamic_cast(node); - assert(push != nullptr); - return push->index(); + if (auto push = dynamic_cast(node)) + { + return push->index(); + } + throw std::invalid_argument("node"); } }; diff --git a/compiler/loco/src/IR/TensorShape.test.cpp b/compiler/loco/src/IR/TensorShape.test.cpp index 448d2aa9db3..ce03ccbd44c 100644 --- a/compiler/loco/src/IR/TensorShape.test.cpp +++ b/compiler/loco/src/IR/TensorShape.test.cpp @@ -25,6 +25,19 @@ TEST(TensorShapeTest, default_constructor) ASSERT_EQ(tensor_shape.rank(), 0); } +TEST(TensorShapeTest, initializer_list_constructor) +{ + loco::TensorShape tensor_shape{3, 5}; + + ASSERT_EQ(tensor_shape.rank(), 2); + + ASSERT_TRUE(tensor_shape.dim(0).known()); + ASSERT_TRUE(tensor_shape.dim(1).known()); + + ASSERT_EQ(tensor_shape.dim(0).value(), 3); + ASSERT_EQ(tensor_shape.dim(1).value(), 5); +} + TEST(TensorShapeTest, rank) { loco::TensorShape tensor_shape; diff --git a/compiler/locoex-customop/README.md b/compiler/locoex-customop/README.md index c2b22e3db1d..3f71140f964 100644 --- a/compiler/locoex-customop/README.md +++ b/compiler/locoex-customop/README.md @@ -3,7 +3,7 @@ _locoex_ is an extention of loco. Classes with `COp` prefix enables *Custom Operation*. In this version, a *custom operation* means one of the following: -1. an op that is supported by Tensorflow but not supported both by the moco and the neurun -1. an op that is not supported by Tensorflow, moco, and the neurun +1. an op that is supported by Tensorflow but not supported both by the moco and the onert +1. an op that is not supported by Tensorflow, moco, and the onert `COpCall` node will represent IR entity that calls custom operations and kernels. diff --git a/compiler/luci/export/CMakeLists.txt b/compiler/luci/export/CMakeLists.txt index cc76ec65809..e32eca3665f 100644 --- a/compiler/luci/export/CMakeLists.txt +++ b/compiler/luci/export/CMakeLists.txt @@ -10,7 +10,6 @@ target_link_libraries(luci_export PRIVATE luci_lang) target_link_libraries(luci_export PRIVATE luci_service) target_link_libraries(luci_export PRIVATE luci_pass) target_link_libraries(luci_export PRIVATE mio_circle) -target_link_libraries(luci_export PRIVATE stdex) target_link_libraries(luci_export PRIVATE luci_log) target_link_libraries(luci_export PRIVATE luci_logex) target_link_libraries(luci_export PRIVATE nncc_common) diff --git a/compiler/luci/export/src/CircleExporter.cpp b/compiler/luci/export/src/CircleExporter.cpp index f137885f76d..9e95c698982 100644 --- a/compiler/luci/export/src/CircleExporter.cpp +++ b/compiler/luci/export/src/CircleExporter.cpp @@ -17,10 +17,10 @@ #include "luci/CircleExporter.h" #include "CircleExporterImpl.h" -#include #include #include +#include namespace luci { diff --git a/compiler/luci/export/src/CircleExporterUtils.cpp b/compiler/luci/export/src/CircleExporterUtils.cpp index 3ab4dc29d58..1af2c17e9f0 100644 --- a/compiler/luci/export/src/CircleExporterUtils.cpp +++ b/compiler/luci/export/src/CircleExporterUtils.cpp @@ -18,6 +18,9 @@ #include +#include +#include + namespace luci { @@ -29,6 +32,8 @@ circle::ActivationFunctionType to_circle_actfunc(luci::FusedActFunc func) return circle::ActivationFunctionType_NONE; case luci::FusedActFunc::RELU: return circle::ActivationFunctionType_RELU; + case luci::FusedActFunc::RELU_N1_TO_1: + return circle::ActivationFunctionType_RELU_N1_TO_1; case luci::FusedActFunc::RELU6: return circle::ActivationFunctionType_RELU6; default: @@ -57,6 +62,9 @@ circle::TensorType to_circle_tensortype(loco::DataType type) case loco::DataType::FLOAT32: return circle::TensorType_FLOAT32; + case loco::DataType::BOOL: + return circle::TensorType_BOOL; + default: INTERNAL_EXN_V("failed to convert unsupported loco::DataType", oops::to_uint32(type)); } @@ -147,10 +155,6 @@ void registerGraphIOName(loco::Graph *graph, SerializedModelData &gd) gd._data_format = circle::DataFormat::DataFormat_CHANNELS_LAST; } -#include - -#include - namespace { @@ -174,7 +178,7 @@ class CircleTensorIndexAnnotation final : public loco::NodeAnnotation void set_tensor_index(loco::Node *node, const CircleTensorIndex &tensor_id) { assert(node->annot() == nullptr); - node->annot(stdex::make_unique(tensor_id)); + node->annot(std::make_unique(tensor_id)); } CircleTensorIndex get_tensor_index(loco::Node *node) diff --git a/compiler/luci/export/src/CircleOperationExporter.cpp b/compiler/luci/export/src/CircleOperationExporter.cpp index 48b17659408..5bbd99d43dc 100644 --- a/compiler/luci/export/src/CircleOperationExporter.cpp +++ b/compiler/luci/export/src/CircleOperationExporter.cpp @@ -46,25 +46,31 @@ class OperationExporter final : public luci::CircleNodeMutableVisitor, } public: + void visit(luci::CircleAbs *) final; void visit(luci::CircleAdd *) final; void visit(luci::CircleArgMax *) final; void visit(luci::CircleAveragePool2D *) final; void visit(luci::CircleConcatenation *) final; void visit(luci::CircleConst *) final{/* skip, everything is done in exportOpDefinedTensors */}; void visit(luci::CircleConv2D *) final; + void visit(luci::CircleCos *) final; void visit(luci::CircleDepthwiseConv2D *) final; void visit(luci::CircleDiv *) final; + void visit(luci::CircleEqual *) final; void visit(luci::CircleFullyConnected *) final; + void visit(luci::CircleLogicalNot *) final; + void visit(luci::CircleLogicalOr *) final; void visit(luci::CircleMaximum *) final; void visit(luci::CircleMaxPool2D *) final; void visit(luci::CircleMean *) final; void visit(luci::CircleMul *) final; + void visit(luci::CirclePack *) final; void visit(luci::CirclePad *) final; void visit(luci::CircleRelu *) final; void visit(luci::CircleRelu6 *) final; - // TODO CircleReshape + void visit(luci::CircleReshape *) final; void visit(luci::CircleRsqrt *) final; - // TODO CircleSoftmax + void visit(luci::CircleSoftmax *) final; void visit(luci::CircleSqrt *) final; void visit(luci::CircleSquaredDifference *) final; void visit(luci::CircleSub *) final; @@ -115,6 +121,19 @@ void OperationExporter::export_pool_2d(CirclePool2D *node, circle::BuiltinOperat gd._operators.push_back(op_offset); } +void OperationExporter::visit(luci::CircleAbs *node) +{ + uint32_t op_idx = gd.registerBuiltinOpcode(circle::BuiltinOperator_ABS); + std::vector inputs_vec{get_tensor_index(node->x())}; + std::vector outputs_vec{get_tensor_index(static_cast(node))}; + auto inputs = builder.CreateVector(inputs_vec); + auto outputs = builder.CreateVector(outputs_vec); + auto options = CreateAbsOptions(builder); + auto op_offset = CreateOperator(builder, op_idx, inputs, outputs, + circle::BuiltinOptions_AbsOptions, options.Union()); + gd._operators.push_back(op_offset); +} + void OperationExporter::visit(luci::CircleAdd *node) { uint32_t op_idx = gd.registerBuiltinOpcode(circle::BuiltinOperator_ADD); @@ -185,6 +204,23 @@ void OperationExporter::visit(luci::CircleConv2D *node) gd._operators.push_back(op_offset); } +void OperationExporter::visit(luci::CircleCos *node) +{ + uint32_t op_idx = gd.registerBuiltinOpcode(circle::BuiltinOperator_COS); + + // Make input, output and options for operator + std::vector inputs_vec{get_tensor_index(node->x())}; + std::vector outputs_vec{get_tensor_index(static_cast(node))}; + auto inputs = builder.CreateVector(inputs_vec); + auto outputs = builder.CreateVector(outputs_vec); + auto options = CreateCosOptions(builder); + + // Make COS operator + auto op_offset = CreateOperator(builder, op_idx, inputs, outputs, + circle::BuiltinOptions_CosOptions, options.Union()); + gd._operators.push_back(op_offset); +} + void OperationExporter::visit(luci::CircleDepthwiseConv2D *node) { uint32_t op_idx = gd.registerBuiltinOpcode(circle::BuiltinOperator_DEPTHWISE_CONV_2D); @@ -239,6 +275,40 @@ void OperationExporter::visit(luci::CircleFullyConnected *node) gd._operators.push_back(op_offset); } +void OperationExporter::visit(luci::CircleLogicalNot *node) +{ + uint32_t op_idx = gd.registerBuiltinOpcode(circle::BuiltinOperator_LOGICAL_NOT); + + // Make input, output and options for operator + std::vector inputs_vec{get_tensor_index(node->x())}; + std::vector outputs_vec{get_tensor_index(static_cast(node))}; + auto inputs = builder.CreateVector(inputs_vec); + auto outputs = builder.CreateVector(outputs_vec); + auto options = CreateLogicalNotOptions(builder); + + // Make LOGICAL_NOT operator + auto op_offset = CreateOperator(builder, op_idx, inputs, outputs, + circle::BuiltinOptions_LogicalNotOptions, options.Union()); + gd._operators.push_back(op_offset); +} + +void OperationExporter::visit(luci::CircleLogicalOr *node) +{ + uint32_t op_idx = gd.registerBuiltinOpcode(circle::BuiltinOperator_LOGICAL_OR); + + // Make input, output and options for operator + std::vector inputs_vec{get_tensor_index(node->x()), get_tensor_index(node->y())}; + std::vector outputs_vec{get_tensor_index(static_cast(node))}; + auto inputs = builder.CreateVector(inputs_vec); + auto outputs = builder.CreateVector(outputs_vec); + auto options = CreateLogicalOrOptions(builder); + + // Make LOGICAL_OR operator + auto op_offset = CreateOperator(builder, op_idx, inputs, outputs, + circle::BuiltinOptions_LogicalOrOptions, options.Union()); + gd._operators.push_back(op_offset); +} + void OperationExporter::visit(luci::CircleMaximum *node) { uint32_t op_idx = gd.registerBuiltinOpcode(circle::BuiltinOperator_MAXIMUM); @@ -284,6 +354,23 @@ void OperationExporter::visit(luci::CircleMul *node) gd._operators.push_back(op_offset); } +void OperationExporter::visit(luci::CirclePack *node) +{ + uint32_t op_idx = gd.registerBuiltinOpcode(circle::BuiltinOperator_PACK); + std::vector inputs_vec; + std::vector outputs_vec{get_tensor_index(static_cast(node))}; + + for (uint32_t i = 0; i < node->values_count(); ++i) + inputs_vec.push_back(get_tensor_index(node->values(i))); + + auto inputs = builder.CreateVector(inputs_vec); + auto outputs = builder.CreateVector(outputs_vec); + auto options = CreatePackOptions(builder, node->values_count(), node->axis()); + auto op_offset = CreateOperator(builder, op_idx, inputs, outputs, + circle::BuiltinOptions_PackOptions, options.Union()); + gd._operators.push_back(op_offset); +} + void OperationExporter::visit(luci::CirclePad *node) { uint32_t op_idx = gd.registerBuiltinOpcode(circle::BuiltinOperator_PAD); @@ -320,7 +407,27 @@ void OperationExporter::visit(luci::CircleRelu6 *node) gd._operators.push_back(op_offset); } -// TODO CircleReshape +void OperationExporter::visit(luci::CircleReshape *node) +{ + uint32_t op_idx = gd.registerBuiltinOpcode(circle::BuiltinOperator_RESHAPE); + + // Create inputs and outputs. + std::vector inputs_vec{get_tensor_index(node->tensor()), + get_tensor_index(node->shape())}; + std::vector outputs_vec{get_tensor_index(node)}; + auto inputs = builder.CreateVector(inputs_vec); + auto outputs = builder.CreateVector(outputs_vec); + + // Create options. + auto new_shape = builder.CreateVector( + node->newShape()->rank(), [node](size_t i) { return node->newShape()->dim(i); }); + auto options = CreateReshapeOptions(builder, new_shape); + + // Create the operator. + auto op_offset = CreateOperator(builder, op_idx, inputs, outputs, + circle::BuiltinOptions_ReshapeOptions, options.Union()); + gd._operators.push_back(op_offset); +} void OperationExporter::visit(luci::CircleRsqrt *node) { @@ -333,7 +440,18 @@ void OperationExporter::visit(luci::CircleRsqrt *node) gd._operators.push_back(op_offset); } -// TODO CircleSoftmax +void OperationExporter::visit(luci::CircleSoftmax *node) +{ + uint32_t op_idx = gd.registerBuiltinOpcode(circle::BuiltinOperator_SOFTMAX); + std::vector inputs_vec{get_tensor_index(node->logits())}; + std::vector outputs_vec{get_tensor_index(static_cast(node))}; + auto inputs = builder.CreateVector(inputs_vec); + auto outputs = builder.CreateVector(outputs_vec); + auto options = CreateSoftmaxOptions(builder, node->beta()); + auto op_offset = CreateOperator(builder, op_idx, inputs, outputs, + circle::BuiltinOptions_SoftmaxOptions, options.Union()); + gd._operators.push_back(op_offset); +} void OperationExporter::visit(luci::CircleSqrt *node) { @@ -426,6 +544,23 @@ void OperationExporter::visit(luci::CircleInstanceNorm *node) gd._operators.push_back(op_offset); } +void OperationExporter::visit(luci::CircleEqual *node) +{ + uint32_t opcode_idx = gd.registerBuiltinOpcode(circle::BuiltinOperator_EQUAL); + std::vector inputs{get_tensor_index(node->x()), get_tensor_index(node->y())}; + std::vector outputs{get_tensor_index(node)}; + + auto fb_inputs = builder.CreateVector(inputs); + auto fb_outputs = builder.CreateVector(outputs); + + auto options = CreateEqualOptions(builder); + + auto op_offset = CreateOperator(builder, opcode_idx, fb_inputs, fb_outputs, + circle::BuiltinOptions_EqualOptions, options.Union()); + + gd._operators.push_back(op_offset); +} + void exportNode(loco::Node *node, flatbuffers::FlatBufferBuilder &builder, SerializedModelData &data) { diff --git a/compiler/luci/export/src/Optimize.cpp b/compiler/luci/export/src/Optimize.cpp index 57af61246fd..6fa50b5646d 100644 --- a/compiler/luci/export/src/Optimize.cpp +++ b/compiler/luci/export/src/Optimize.cpp @@ -21,7 +21,8 @@ #include #include -#include + +#include namespace luci { @@ -31,8 +32,8 @@ void optimize(loco::Graph *g) logo::Phase phase; { // prepare type and shape before optimization - phase.emplace_back(stdex::make_unique()); - phase.emplace_back(stdex::make_unique()); + phase.emplace_back(std::make_unique()); + phase.emplace_back(std::make_unique()); // TODO add more optimization passes (with a knob) } diff --git a/compiler/luci/import/CMakeLists.txt b/compiler/luci/import/CMakeLists.txt index 4faee016bb7..bc9a9152a99 100644 --- a/compiler/luci/import/CMakeLists.txt +++ b/compiler/luci/import/CMakeLists.txt @@ -7,7 +7,6 @@ target_include_directories(luci_import PRIVATE src) target_include_directories(luci_import PUBLIC include) target_link_libraries(luci_import PUBLIC luci_lang) target_link_libraries(luci_import PUBLIC mio_circle) -target_link_libraries(luci_import PUBLIC stdex) target_link_libraries(luci_import PRIVATE luci_log) target_link_libraries(luci_import PRIVATE luci_logex) target_link_libraries(luci_import PRIVATE nncc_common) diff --git a/compiler/luci/import/include/luci/Import/CircleReader.h b/compiler/luci/import/include/luci/Import/CircleReader.h index fdf02b8ca29..54737ee0deb 100644 --- a/compiler/luci/import/include/luci/Import/CircleReader.h +++ b/compiler/luci/import/include/luci/Import/CircleReader.h @@ -33,29 +33,17 @@ namespace luci { -template std::vector as_index_vector(const flatbuffers::Vector *flat_array) -{ - std::vector ret(flat_array->Length()); - for (uint32_t i = 0; i < flat_array->Length(); i++) - { - ret[i] = flat_array->Get(i); - } - return ret; -} - -bool is_valid(const circle::OperatorCode *opcode); -bool is_custom(const circle::OperatorCode *opcode); -std::string opcode_name(const circle::OperatorCode *opcode); -const char *tensor_type(const circle::Tensor *tensor); -const char *tensor_name(const circle::Tensor *tensor); -const circle::QuantizationParameters *tensor_quantization(const circle::Tensor *tensor); +bool is_valid(const circle::OperatorCodeT &opcode); +bool is_custom(const circle::OperatorCodeT &opcode); +std::string opcode_name(const circle::OperatorCodeT &opcode); +const char *tensor_name(const circle::TensorT &tensor); +const circle::QuantizationParametersT *tensor_quantization(const circle::TensorT &tensor); loco::DataType luci_datatype(circle::TensorType type); -loco::DataType luci_datatype(const circle::Tensor *tensor); FusedActFunc luci_actfunc(const circle::ActivationFunctionType type); Padding luci_padding(const circle::Padding padding); std::unique_ptr -luci_quantparam(const circle::QuantizationParameters *quantization); +luci_quantparam(const circle::QuantizationParametersT *quantization); /** * @brief Loads Circle file and provides helpers to access attributes @@ -63,43 +51,34 @@ luci_quantparam(const circle::QuantizationParameters *quantization); class CircleReader { private: - using CircleSubGraphs_t = flatbuffers::Vector>; - using CircleBuffers_t = flatbuffers::Vector>; - using CircleTensors_t = flatbuffers::Vector>; - using CircleOperators_t = flatbuffers::Vector>; + using CircleBuffers_t = std::vector>; + using CircleTensors_t = std::vector>; + using CircleOperators_t = std::vector>; + using CircleOperatorCodes_t = std::vector>; public: CircleReader() = default; public: - const std::vector &opcodes() const { return _op_codes; } - const CircleBuffers_t *buffers() const { return _buffers; } - const CircleTensors_t *tensors() const { return _tensors; } - const CircleOperators_t *operators() const { return _operators; } - const std::vector &inputs() const { return _inputs; } - const std::vector &outputs() const { return _outputs; } + const CircleOperatorCodes_t &opcodes() const { return _model->operator_codes; } + const CircleBuffers_t &buffers() const { return _model->buffers; } + const CircleTensors_t &tensors() const { return _current_subgraph->tensors; } + const CircleOperators_t &operators() const { return _current_subgraph->operators; } + const std::vector &inputs() const { return _current_subgraph->inputs; } + const std::vector &outputs() const { return _current_subgraph->outputs; } - uint32_t num_subgraph() const { return _subgraphs->Length(); } + uint32_t num_subgraph() const { return _model->subgraphs.size(); } - size_t buffer_info(uint32_t buf_idx, const uint8_t **buff_data); - circle::BuiltinOperator builtin_code(const circle::Operator *op) const; - std::string opcode_name(const circle::Operator *op) const; + circle::BuiltinOperator builtin_code(const circle::OperatorT &op) const; + std::string opcode_name(const circle::OperatorT &op) const; public: bool parse(const circle::Model *model); bool select_subgraph(uint32_t subgraph); private: - const circle::Model *_model{nullptr}; - - const CircleSubGraphs_t *_subgraphs{nullptr}; - const CircleBuffers_t *_buffers{nullptr}; - const CircleTensors_t *_tensors{nullptr}; - const CircleOperators_t *_operators{nullptr}; - - std::vector _op_codes; - std::vector _inputs; - std::vector _outputs; + std::unique_ptr _model; + const circle::SubGraphT *_current_subgraph{nullptr}; }; } // namespace luci diff --git a/compiler/luci/import/include/luci/Import/GraphBuilder.h b/compiler/luci/import/include/luci/Import/GraphBuilder.h index 434ef0885e7..61f673fb603 100644 --- a/compiler/luci/import/include/luci/Import/GraphBuilder.h +++ b/compiler/luci/import/include/luci/Import/GraphBuilder.h @@ -30,10 +30,25 @@ namespace luci class GraphBuilder { public: - virtual bool validate(const circle::Operator *) const = 0; - virtual void build(const circle::Operator *, GraphBuilderContext *) const = 0; + struct ValidateArgs + { + ValidateArgs(const circle::OperatorT &o, const CircleReader &r) : op(o), reader(r) {} - virtual ~GraphBuilder() {} + const circle::OperatorT &op; + const CircleReader &reader; + }; + +public: + virtual ~GraphBuilder() = default; + + virtual bool validate(const ValidateArgs &) const = 0; + + void build(const circle::OperatorT &op, GraphBuilderContext *context) const; + +private: + virtual CircleNode *build_node(const circle::OperatorT &op, + const std::vector &inputs, + loco::Graph *graph) const = 0; }; } // namespace luci diff --git a/compiler/luci/import/include/luci/Import/GraphBuilderContext.h b/compiler/luci/import/include/luci/Import/GraphBuilderContext.h index 6e7fb3f6f33..8d464181d00 100644 --- a/compiler/luci/import/include/luci/Import/GraphBuilderContext.h +++ b/compiler/luci/import/include/luci/Import/GraphBuilderContext.h @@ -28,40 +28,6 @@ namespace luci { -/* - * @brief CircleNode to circle::Operator - * To find circle::Operator from CircleNode - */ -class NodeOpFinder -{ -public: - void enroll(CircleNode *node, const circle::Operator *op); - - const circle::Operator *op(CircleNode *node) const; - -private: - using MapNodeOperator_t = std::map; - - MapNodeOperator_t _table; -}; - -/* - * @brief CircleNode to circle::Tensor - * To find circle::Tensor from CircleNode - */ -class NodeTensorFinder -{ -public: - void enroll(CircleNode *node, const circle::Tensor *tensor); - - const circle::Tensor *tensor(CircleNode *node) const; - -private: - using MapNodeTensor_t = std::map; - - MapNodeTensor_t _table; -}; - using TensorIndex = int32_t; /* @@ -81,53 +47,14 @@ class IndexNodeFinder MapIndexNode_t _table; }; -class GraphBuilderContext; - -/** - * @brief Interface to connect the graph - */ -class GraphUpdate -{ -public: - virtual ~GraphUpdate() = default; - -public: - /** - * @brief Do the graph input connections using the SymbolTable - */ - virtual void update(GraphBuilderContext *) = 0; -}; - -/** - * @brief Class to store GraphUpdate objects - */ -class UpdateQueue final -{ -public: - /** - * @brief Registers GraphUpdate objects - */ - void enroll(std::unique_ptr &&update); - -public: - using Queue = std::vector>; - - const Queue &queue() const { return _queue; } - -private: - Queue _queue; -}; - /** * @brief Class to store context to build loco graph IR from TensorFlow */ class GraphBuilderContext { public: - GraphBuilderContext(loco::Graph *g, CircleReader *reader, NodeOpFinder *nofinder, - NodeTensorFinder *ntfinder, IndexNodeFinder *infinder, UpdateQueue *updates) - : _g(g), _reader(reader), _nodeopfinder(nofinder), _nodetensorfinder(ntfinder), - _indexnodefinder(infinder), _updates(updates) + GraphBuilderContext(loco::Graph *g, CircleReader *reader, IndexNodeFinder *nodefinder) + : _g(g), _reader(reader), _indexnodefinder(nodefinder) { // DO NOTHING } @@ -139,18 +66,12 @@ class GraphBuilderContext loco::Graph *graph() { return _g; } CircleReader *reader() { return _reader; } - NodeOpFinder *opfinder(void) { return _nodeopfinder; } - NodeTensorFinder *tensorfinder(void) { return _nodetensorfinder; } - IndexNodeFinder *nodefinder(void) { return _indexnodefinder; } - UpdateQueue *updates() { return _updates; } + IndexNodeFinder *nodefinder() { return _indexnodefinder; } private: loco::Graph *_g; CircleReader *_reader; - NodeOpFinder *_nodeopfinder; - NodeTensorFinder *_nodetensorfinder; IndexNodeFinder *_indexnodefinder; - UpdateQueue *_updates; }; } // namespace luci diff --git a/compiler/luci/import/include/luci/Import/Nodes.h b/compiler/luci/import/include/luci/Import/Nodes.h index 8cfefbd9836..dce364e6eb0 100644 --- a/compiler/luci/import/include/luci/Import/Nodes.h +++ b/compiler/luci/import/include/luci/Import/Nodes.h @@ -17,13 +17,30 @@ #ifndef __LUCI_IMPORT_NODES_H__ #define __LUCI_IMPORT_NODES_H__ +#include "Nodes/CircleAbs.h" #include "Nodes/CircleAdd.h" #include "Nodes/CircleArgMax.h" +#include "Nodes/CircleAveragePool2D.h" +#include "Nodes/CircleConcatenation.h" #include "Nodes/CircleConst.h" #include "Nodes/CircleConv2D.h" +#include "Nodes/CircleCos.h" +#include "Nodes/CircleDepthwiseConv2D.h" +#include "Nodes/CircleDiv.h" +#include "Nodes/CircleEqual.h" +#include "Nodes/CircleFullyConnected.h" +#include "Nodes/CircleLogicalNot.h" +#include "Nodes/CircleLogicalOr.h" #include "Nodes/CircleMaxPool2D.h" #include "Nodes/CircleMean.h" +#include "Nodes/CircleMul.h" +#include "Nodes/CirclePack.h" #include "Nodes/CirclePad.h" +#include "Nodes/CircleRelu.h" #include "Nodes/CircleReshape.h" +#include "Nodes/CircleRsqrt.h" +#include "Nodes/CircleSoftmax.h" +#include "Nodes/CircleSub.h" +#include "Nodes/CircleTranspose.h" #endif // __LUCI_IMPORT_NODES_H__ diff --git a/compiler/luci/import/include/luci/Import/Nodes/CircleAbs.h b/compiler/luci/import/include/luci/Import/Nodes/CircleAbs.h new file mode 100644 index 00000000000..e0cec26d9e6 --- /dev/null +++ b/compiler/luci/import/include/luci/Import/Nodes/CircleAbs.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2020 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 __LUCI_IMPORT_OP_CIRCLE_ABS_H__ +#define __LUCI_IMPORT_OP_CIRCLE_ABS_H__ + +#include "luci/Import/GraphBuilder.h" + +namespace luci +{ + +class CircleAbsGraphBuilder : public GraphBuilder +{ +public: + bool validate(const ValidateArgs &args) const final; + +private: + CircleNode *build_node(const circle::OperatorT &op, const std::vector &inputs, + loco::Graph *graph) const final; +}; + +} // namespace luci + +#endif // __LUCI_IMPORT_OP_CIRCLE_ABS_H__ diff --git a/compiler/luci/import/include/luci/Import/Nodes/CircleAdd.h b/compiler/luci/import/include/luci/Import/Nodes/CircleAdd.h index c9683fdab89..d852ee8b3c2 100644 --- a/compiler/luci/import/include/luci/Import/Nodes/CircleAdd.h +++ b/compiler/luci/import/include/luci/Import/Nodes/CircleAdd.h @@ -25,8 +25,11 @@ namespace luci class CircleAddGraphBuilder : public GraphBuilder { public: - bool validate(const circle::Operator *) const final; - void build(const circle::Operator *, GraphBuilderContext *) const final; + bool validate(const ValidateArgs &args) const final; + +private: + CircleNode *build_node(const circle::OperatorT &op, const std::vector &inputs, + loco::Graph *graph) const final; }; } // namespace luci diff --git a/compiler/luci/import/include/luci/Import/Nodes/CircleArgMax.h b/compiler/luci/import/include/luci/Import/Nodes/CircleArgMax.h index a012db49d11..dae4691dc8b 100644 --- a/compiler/luci/import/include/luci/Import/Nodes/CircleArgMax.h +++ b/compiler/luci/import/include/luci/Import/Nodes/CircleArgMax.h @@ -25,8 +25,11 @@ namespace luci class CircleArgMaxGraphBuilder : public GraphBuilder { public: - bool validate(const circle::Operator *) const final; - void build(const circle::Operator *, GraphBuilderContext *) const final; + bool validate(const ValidateArgs &args) const final; + +private: + CircleNode *build_node(const circle::OperatorT &op, const std::vector &inputs, + loco::Graph *graph) const final; }; } // namespace luci diff --git a/compiler/luci/import/include/luci/Import/Nodes/CircleAveragePool2D.h b/compiler/luci/import/include/luci/Import/Nodes/CircleAveragePool2D.h new file mode 100644 index 00000000000..07f6565bcbf --- /dev/null +++ b/compiler/luci/import/include/luci/Import/Nodes/CircleAveragePool2D.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2020 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 __LUCI_IMPORT_OP_CIRCLE_AVERAGEPOOL2D_H__ +#define __LUCI_IMPORT_OP_CIRCLE_AVERAGEPOOL2D_H__ + +#include "luci/Import/GraphBuilder.h" + +namespace luci +{ + +class CircleAveragePool2DGraphBuilder : public GraphBuilder +{ +public: + bool validate(const ValidateArgs &args) const final; + +private: + CircleNode *build_node(const circle::OperatorT &op, const std::vector &inputs, + loco::Graph *graph) const final; +}; + +} // namespace luci + +#endif // __LUCI_IMPORT_OP_CIRCLE_AVERAGEPOOL2D_H__ diff --git a/compiler/luci/import/include/luci/Import/Nodes/CircleConcatenation.h b/compiler/luci/import/include/luci/Import/Nodes/CircleConcatenation.h new file mode 100644 index 00000000000..9b4c9ffd118 --- /dev/null +++ b/compiler/luci/import/include/luci/Import/Nodes/CircleConcatenation.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2020 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 __LUCI_IMPORT_OP_CIRCLE_CONCATENATION_H__ +#define __LUCI_IMPORT_OP_CIRCLE_CONCATENATION_H__ + +#include "luci/Import/GraphBuilder.h" + +namespace luci +{ + +class CircleConcatenationGraphBuilder : public GraphBuilder +{ +public: + bool validate(const ValidateArgs &args) const final; + +private: + CircleNode *build_node(const circle::OperatorT &op, const std::vector &inputs, + loco::Graph *graph) const final; +}; + +} // namespace luci + +#endif // __LUCI_IMPORT_OP_CIRCLE_CONCATENATION_H__ diff --git a/compiler/luci/import/include/luci/Import/Nodes/CircleConv2D.h b/compiler/luci/import/include/luci/Import/Nodes/CircleConv2D.h index 0fa1de914d7..4529a4f1133 100644 --- a/compiler/luci/import/include/luci/Import/Nodes/CircleConv2D.h +++ b/compiler/luci/import/include/luci/Import/Nodes/CircleConv2D.h @@ -25,8 +25,11 @@ namespace luci class CircleConv2DGraphBuilder : public GraphBuilder { public: - bool validate(const circle::Operator *) const final; - void build(const circle::Operator *, GraphBuilderContext *) const final; + bool validate(const ValidateArgs &args) const final; + +private: + CircleNode *build_node(const circle::OperatorT &op, const std::vector &inputs, + loco::Graph *graph) const final; }; } // namespace luci diff --git a/compiler/luci/import/include/luci/Import/Nodes/CircleCos.h b/compiler/luci/import/include/luci/Import/Nodes/CircleCos.h new file mode 100644 index 00000000000..fb472977e8d --- /dev/null +++ b/compiler/luci/import/include/luci/Import/Nodes/CircleCos.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2020 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 __LUCI_IMPORT_OP_CIRCLE_COS_H__ +#define __LUCI_IMPORT_OP_CIRCLE_COS_H__ + +#include "luci/Import/GraphBuilder.h" + +namespace luci +{ + +class CircleCosGraphBuilder : public GraphBuilder +{ +public: + bool validate(const ValidateArgs &args) const final; + +private: + CircleNode *build_node(const circle::OperatorT &op, const std::vector &inputs, + loco::Graph *graph) const final; +}; + +} // namespace luci + +#endif // __LUCI_IMPORT_OP_CIRCLE_COS_H__ diff --git a/compiler/luci/import/include/luci/Import/Nodes/CircleDepthwiseConv2D.h b/compiler/luci/import/include/luci/Import/Nodes/CircleDepthwiseConv2D.h new file mode 100644 index 00000000000..1953cb76cad --- /dev/null +++ b/compiler/luci/import/include/luci/Import/Nodes/CircleDepthwiseConv2D.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2020 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 __LUCI_IMPORT_OP_CIRCLE_DEPTHWISECONV_2D_H__ +#define __LUCI_IMPORT_OP_CIRCLE_DEPTHWISECONV_2D_H__ + +#include "luci/Import/GraphBuilder.h" + +namespace luci +{ + +class CircleDepthwiseConv2DGraphBuilder : public GraphBuilder +{ +public: + bool validate(const ValidateArgs &args) const final; + +private: + CircleNode *build_node(const circle::OperatorT &op, const std::vector &inputs, + loco::Graph *graph) const final; +}; + +} // namespace luci + +#endif // __LUCI_IMPORT_OP_CIRCLE_DEPTHWISECONV_2D_H__ diff --git a/compiler/luci/import/include/luci/Import/Nodes/CircleDiv.h b/compiler/luci/import/include/luci/Import/Nodes/CircleDiv.h new file mode 100644 index 00000000000..6a38118fe12 --- /dev/null +++ b/compiler/luci/import/include/luci/Import/Nodes/CircleDiv.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2020 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 __LUCI_IMPORT_OP_CIRCLE_DIV_H__ +#define __LUCI_IMPORT_OP_CIRCLE_DIV_H__ + +#include "luci/Import/GraphBuilder.h" + +namespace luci +{ + +class CircleDivGraphBuilder : public GraphBuilder +{ + bool validate(const ValidateArgs &args) const final; + +private: + CircleNode *build_node(const circle::OperatorT &op, const std::vector &inputs, + loco::Graph *graph) const override; +}; + +} // namespace luci + +#endif // __LUCI_IMPORT_OP_CIRCLE_DIV_H__ diff --git a/compiler/luci/import/include/luci/Import/Nodes/CircleEqual.h b/compiler/luci/import/include/luci/Import/Nodes/CircleEqual.h new file mode 100644 index 00000000000..a98adcd0898 --- /dev/null +++ b/compiler/luci/import/include/luci/Import/Nodes/CircleEqual.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2020 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 __LUCI_IMPORT_OP_CIRCLE_EQUAL_H__ +#define __LUCI_IMPORT_OP_CIRCLE_EQUAL_H__ + +#include "luci/Import/GraphBuilder.h" + +namespace luci +{ + +class CircleEqualGraphBuilder : public GraphBuilder +{ +public: + bool validate(const ValidateArgs &args) const final; + +private: + CircleNode *build_node(const circle::OperatorT &op, const std::vector &inputs, + loco::Graph *graph) const final; +}; + +} // namespace luci + +#endif // __LUCI_IMPORT_OP_CIRCLE_EQUAL_H__ diff --git a/compiler/luci/import/include/luci/Import/Nodes/CircleFullyConnected.h b/compiler/luci/import/include/luci/Import/Nodes/CircleFullyConnected.h new file mode 100644 index 00000000000..b7798c68826 --- /dev/null +++ b/compiler/luci/import/include/luci/Import/Nodes/CircleFullyConnected.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2020 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 __LUCI_IMPORT_OP_CIRCLE_FULLYCONNECTED_H__ +#define __LUCI_IMPORT_OP_CIRCLE_FULLYCONNECTED_H__ + +#include "luci/Import/GraphBuilder.h" + +namespace luci +{ + +class CircleFullyConnectedGraphBuilder : public GraphBuilder +{ +public: + bool validate(const ValidateArgs &args) const final; + +private: + CircleNode *build_node(const circle::OperatorT &op, const std::vector &inputs, + loco::Graph *graph) const final; +}; + +} // namespace luci + +#endif // __LUCI_IMPORT_OP_CIRCLE_FULLYCONNECTED_H__ diff --git a/compiler/luci/import/include/luci/Import/Nodes/CircleLogicalNot.h b/compiler/luci/import/include/luci/Import/Nodes/CircleLogicalNot.h new file mode 100644 index 00000000000..ec890ecf732 --- /dev/null +++ b/compiler/luci/import/include/luci/Import/Nodes/CircleLogicalNot.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2020 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 __LUCI_IMPORT_OP_CIRCLE_LOGICALNOT_H__ +#define __LUCI_IMPORT_OP_CIRCLE_LOGICALNOT_H__ + +#include "luci/Import/GraphBuilder.h" + +namespace luci +{ + +class CircleLogicalNotGraphBuilder : public GraphBuilder +{ +public: + bool validate(const ValidateArgs &args) const final; + +private: + CircleNode *build_node(const circle::OperatorT &op, const std::vector &inputs, + loco::Graph *graph) const final; +}; + +} // namespace luci + +#endif // __LUCI_IMPORT_OP_CIRCLE_LOGICALNOT_H__ diff --git a/compiler/luci/import/include/luci/Import/Nodes/CircleLogicalOr.h b/compiler/luci/import/include/luci/Import/Nodes/CircleLogicalOr.h new file mode 100644 index 00000000000..9fb0086c1ab --- /dev/null +++ b/compiler/luci/import/include/luci/Import/Nodes/CircleLogicalOr.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2020 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 __LUCI_IMPORT_OP_CIRCLE_LOGICALOR_H__ +#define __LUCI_IMPORT_OP_CIRCLE_LOGICALOR_H__ + +#include "luci/Import/GraphBuilder.h" + +namespace luci +{ + +class CircleLogicalOrGraphBuilder : public GraphBuilder +{ +public: + bool validate(const ValidateArgs &args) const final; + +private: + CircleNode *build_node(const circle::OperatorT &op, const std::vector &inputs, + loco::Graph *graph) const final; +}; + +} // namespace luci + +#endif // __LUCI_IMPORT_OP_CIRCLE_LOGICALOR_H__ diff --git a/compiler/luci/import/include/luci/Import/Nodes/CircleMaxPool2D.h b/compiler/luci/import/include/luci/Import/Nodes/CircleMaxPool2D.h index 91ec99b4620..bcd2acb30f9 100644 --- a/compiler/luci/import/include/luci/Import/Nodes/CircleMaxPool2D.h +++ b/compiler/luci/import/include/luci/Import/Nodes/CircleMaxPool2D.h @@ -25,8 +25,11 @@ namespace luci class CircleMaxPool2DGraphBuilder : public GraphBuilder { public: - bool validate(const circle::Operator *) const final; - void build(const circle::Operator *, GraphBuilderContext *) const final; + bool validate(const ValidateArgs &args) const final; + +private: + CircleNode *build_node(const circle::OperatorT &op, const std::vector &inputs, + loco::Graph *graph) const final; }; } // namespace luci diff --git a/compiler/luci/import/include/luci/Import/Nodes/CircleMean.h b/compiler/luci/import/include/luci/Import/Nodes/CircleMean.h index 271962d44aa..a7919a57cee 100644 --- a/compiler/luci/import/include/luci/Import/Nodes/CircleMean.h +++ b/compiler/luci/import/include/luci/Import/Nodes/CircleMean.h @@ -25,8 +25,11 @@ namespace luci class CircleMeanGraphBuilder : public GraphBuilder { public: - bool validate(const circle::Operator *) const final; - void build(const circle::Operator *, GraphBuilderContext *) const final; + bool validate(const ValidateArgs &args) const final; + +private: + CircleNode *build_node(const circle::OperatorT &op, const std::vector &inputs, + loco::Graph *graph) const final; }; } // namespace luci diff --git a/compiler/luci/import/include/luci/Import/Nodes/CircleMul.h b/compiler/luci/import/include/luci/Import/Nodes/CircleMul.h new file mode 100644 index 00000000000..13027a15567 --- /dev/null +++ b/compiler/luci/import/include/luci/Import/Nodes/CircleMul.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2020 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 __LUCI_IMPORT_OP_CIRCLE_MUL_H__ +#define __LUCI_IMPORT_OP_CIRCLE_MUL_H__ + +#include "luci/Import/GraphBuilder.h" + +namespace luci +{ + +class CircleMulGraphBuilder : public GraphBuilder +{ +public: + bool validate(const ValidateArgs &args) const final; + +private: + CircleNode *build_node(const circle::OperatorT &op, const std::vector &inputs, + loco::Graph *graph) const override; +}; + +} // namespace luci + +#endif // __LUCI_IMPORT_OP_CIRCLE_MUL_H__ diff --git a/compiler/luci/import/include/luci/Import/Nodes/CirclePack.h b/compiler/luci/import/include/luci/Import/Nodes/CirclePack.h new file mode 100644 index 00000000000..8e4b7199569 --- /dev/null +++ b/compiler/luci/import/include/luci/Import/Nodes/CirclePack.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2020 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 __LUCI_IMPORT_OP_CIRCLE_PACK_H__ +#define __LUCI_IMPORT_OP_CIRCLE_PACK_H__ + +#include "luci/Import/GraphBuilder.h" + +namespace luci +{ + +class CirclePackGraphBuilder : public GraphBuilder +{ +public: + bool validate(const ValidateArgs &args) const final; + +private: + CircleNode *build_node(const circle::OperatorT &op, const std::vector &inputs, + loco::Graph *graph) const override; +}; + +} // namespace luci + +#endif // __LUCI_IMPORT_OP_CIRCLE_PACK_H__ diff --git a/compiler/luci/import/include/luci/Import/Nodes/CirclePad.h b/compiler/luci/import/include/luci/Import/Nodes/CirclePad.h index 146046bb786..e333ee912c6 100644 --- a/compiler/luci/import/include/luci/Import/Nodes/CirclePad.h +++ b/compiler/luci/import/include/luci/Import/Nodes/CirclePad.h @@ -25,8 +25,11 @@ namespace luci class CirclePadGraphBuilder : public GraphBuilder { public: - bool validate(const circle::Operator *) const final; - void build(const circle::Operator *, GraphBuilderContext *) const final; + bool validate(const ValidateArgs &args) const final; + +private: + CircleNode *build_node(const circle::OperatorT &op, const std::vector &inputs, + loco::Graph *graph) const final; }; } // namespace luci diff --git a/compiler/luci/import/include/luci/Import/Nodes/CircleRelu.h b/compiler/luci/import/include/luci/Import/Nodes/CircleRelu.h new file mode 100644 index 00000000000..deb91324398 --- /dev/null +++ b/compiler/luci/import/include/luci/Import/Nodes/CircleRelu.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2020 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 __LUCI_IMPORT_OP_CIRCLE_RELU_H__ +#define __LUCI_IMPORT_OP_CIRCLE_RELU_H__ + +#include "luci/Import/GraphBuilder.h" + +namespace luci +{ + +class CircleReluGraphBuilder : public GraphBuilder +{ +public: + bool validate(const ValidateArgs &args) const final; + +private: + CircleNode *build_node(const circle::OperatorT &op, const std::vector &inputs, + loco::Graph *graph) const final; +}; + +} // namespace luci + +#endif // __LUCI_IMPORT_OP_CIRCLE_RELU_H__ diff --git a/compiler/luci/import/include/luci/Import/Nodes/CircleReshape.h b/compiler/luci/import/include/luci/Import/Nodes/CircleReshape.h index 60d36b75791..eb4fb13bae0 100644 --- a/compiler/luci/import/include/luci/Import/Nodes/CircleReshape.h +++ b/compiler/luci/import/include/luci/Import/Nodes/CircleReshape.h @@ -25,8 +25,11 @@ namespace luci class CircleReshapeGraphBuilder : public GraphBuilder { public: - bool validate(const circle::Operator *) const final; - void build(const circle::Operator *, GraphBuilderContext *) const final; + bool validate(const ValidateArgs &args) const final; + +private: + CircleNode *build_node(const circle::OperatorT &op, const std::vector &inputs, + loco::Graph *graph) const final; }; } // namespace luci diff --git a/compiler/luci/import/include/luci/Import/Nodes/CircleRsqrt.h b/compiler/luci/import/include/luci/Import/Nodes/CircleRsqrt.h new file mode 100644 index 00000000000..90d568f1fdc --- /dev/null +++ b/compiler/luci/import/include/luci/Import/Nodes/CircleRsqrt.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2020 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 __LUCI_IMPORT_OP_CIRCLE_RSQRT_H__ +#define __LUCI_IMPORT_OP_CIRCLE_RSQRT_H__ + +#include "luci/Import/GraphBuilder.h" + +namespace luci +{ + +class CircleRsqrtGraphBuilder : public GraphBuilder +{ +public: + bool validate(const ValidateArgs &args) const final; + +private: + CircleNode *build_node(const circle::OperatorT &op, const std::vector &inputs, + loco::Graph *graph) const final; +}; + +} // namespace luci + +#endif // __LUCI_IMPORT_OP_CIRCLE_RSQRT_H__ diff --git a/compiler/luci/import/include/luci/Import/Nodes/CircleSoftmax.h b/compiler/luci/import/include/luci/Import/Nodes/CircleSoftmax.h new file mode 100644 index 00000000000..b93846d67e7 --- /dev/null +++ b/compiler/luci/import/include/luci/Import/Nodes/CircleSoftmax.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2020 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 __LUCI_IMPORT_OP_CIRCLE_SOFTMAX_H__ +#define __LUCI_IMPORT_OP_CIRCLE_SOFTMAX_H__ + +#include "luci/Import/GraphBuilder.h" + +namespace luci +{ + +class CircleSoftmaxGraphBuilder : public GraphBuilder +{ +public: + bool validate(const ValidateArgs &args) const final; + +private: + CircleNode *build_node(const circle::OperatorT &op, const std::vector &inputs, + loco::Graph *graph) const final; +}; + +} // namespace luci + +#endif // __LUCI_IMPORT_OP_CIRCLE_SOFTMAX_H__ diff --git a/compiler/luci/import/include/luci/Import/Nodes/CircleSub.h b/compiler/luci/import/include/luci/Import/Nodes/CircleSub.h new file mode 100644 index 00000000000..315d1c2f918 --- /dev/null +++ b/compiler/luci/import/include/luci/Import/Nodes/CircleSub.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2020 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 __LUCI_IMPORT_OP_CIRCLE_SUB_H__ +#define __LUCI_IMPORT_OP_CIRCLE_SUB_H__ + +#include "luci/Import/GraphBuilder.h" + +namespace luci +{ + +class CircleSubGraphBuilder : public GraphBuilder +{ +public: + bool validate(const ValidateArgs &args) const final; + +private: + CircleNode *build_node(const circle::OperatorT &op, const std::vector &inputs, + loco::Graph *graph) const final; +}; + +} // namespace luci + +#endif // __LUCI_IMPORT_OP_CIRCLE_SUB_H__ diff --git a/compiler/luci/import/include/luci/Import/Nodes/CircleTranspose.h b/compiler/luci/import/include/luci/Import/Nodes/CircleTranspose.h new file mode 100644 index 00000000000..ac0f1fb417f --- /dev/null +++ b/compiler/luci/import/include/luci/Import/Nodes/CircleTranspose.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2020 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 __LUCI_IMPORT_OP_CIRCLE_TRANSPOSE_H__ +#define __LUCI_IMPORT_OP_CIRCLE_TRANSPOSE_H__ + +#include "luci/Import/GraphBuilder.h" + +namespace luci +{ + +class CircleTransposeGraphBuilder : public GraphBuilder +{ +public: + bool validate(const ValidateArgs &args) const final; + +private: + CircleNode *build_node(const circle::OperatorT &op, const std::vector &inputs, + loco::Graph *graph) const override; +}; + +} // namespace luci + +#endif // __LUCI_IMPORT_OP_CIRCLE_TRANSPOSE_H__ diff --git a/compiler/luci/import/src/CircleReader.cpp b/compiler/luci/import/src/CircleReader.cpp index a78fe090b99..ead0093b86d 100644 --- a/compiler/luci/import/src/CircleReader.cpp +++ b/compiler/luci/import/src/CircleReader.cpp @@ -16,30 +16,27 @@ #include "luci/Import/CircleReader.h" -#include - +#include #include #include namespace luci { -bool is_valid(const circle::OperatorCode *opcode) +bool is_valid(const circle::OperatorCodeT &opcode) { - circle::BuiltinOperator code = opcode->builtin_code(); + circle::BuiltinOperator code = opcode.builtin_code; return (circle::BuiltinOperator_MIN <= code && code <= circle::BuiltinOperator_MAX); } -bool is_custom(const circle::OperatorCode *opcode) +bool is_custom(const circle::OperatorCodeT &opcode) { - circle::BuiltinOperator code = opcode->builtin_code(); + circle::BuiltinOperator code = opcode.builtin_code; return (code == circle::BuiltinOperator_CUSTOM); } -std::string opcode_name(const circle::OperatorCode *opcode) +std::string opcode_name(const circle::OperatorCodeT &opcode) { - assert(opcode); - if (!is_valid(opcode)) { std::ostringstream oss; @@ -49,35 +46,29 @@ std::string opcode_name(const circle::OperatorCode *opcode) if (is_custom(opcode)) { - if (!opcode->custom_code()) + if (opcode.custom_code.empty()) return "(invalid custom)"; - return opcode->custom_code()->c_str(); + return opcode.custom_code; } - circle::BuiltinOperator code = opcode->builtin_code(); + circle::BuiltinOperator code = opcode.builtin_code; return circle::EnumNameBuiltinOperator(code); } -const char *tensor_type(const circle::Tensor *tensor) -{ - return circle::EnumNameTensorType(tensor->type()); -} - -const char *tensor_name(const circle::Tensor *tensor) +const char *tensor_name(const circle::TensorT &tensor) { static const char *kEmptyTensorName = "(noname)"; - auto name = tensor->name(); - if (name) - return name->c_str(); + if (!tensor.name.empty()) + return tensor.name.c_str(); return kEmptyTensorName; } -const circle::QuantizationParameters *tensor_quantization(const circle::Tensor *tensor) +const circle::QuantizationParametersT *tensor_quantization(const circle::TensorT &tensor) { - return tensor->quantization(); + return tensor.quantization.get(); } loco::DataType luci_datatype(const circle::TensorType type) @@ -97,43 +88,15 @@ loco::DataType luci_datatype(const circle::TensorType type) case circle::TensorType_STRING: break; case circle::TensorType_BOOL: - break; + return loco::DataType::BOOL; case circle::TensorType_INT16: return loco::DataType::S16; case circle::TensorType_COMPLEX64: break; case circle::TensorType_INT8: return loco::DataType::S8; - } - assert(false); - return loco::DataType::Unknown; -} - -loco::DataType luci_datatype(const circle::Tensor *tensor) -{ - // TODO use luci_datatype(circle::TensorType type) - switch (tensor->type()) - { - case circle::TensorType_FLOAT32: - return loco::DataType::FLOAT32; - case circle::TensorType_FLOAT16: - return loco::DataType::FLOAT16; - case circle::TensorType_INT32: - return loco::DataType::S32; - case circle::TensorType_UINT8: - return loco::DataType::U8; - case circle::TensorType_INT64: - return loco::DataType::S64; - case circle::TensorType_STRING: - break; - case circle::TensorType_BOOL: - break; - case circle::TensorType_INT16: - return loco::DataType::S16; - case circle::TensorType_COMPLEX64: + default: break; - case circle::TensorType_INT8: - return loco::DataType::S8; } assert(false); return loco::DataType::Unknown; @@ -148,7 +111,7 @@ FusedActFunc luci_actfunc(const circle::ActivationFunctionType type) case circle::ActivationFunctionType::ActivationFunctionType_RELU: return luci::FusedActFunc::RELU; case circle::ActivationFunctionType::ActivationFunctionType_RELU_N1_TO_1: - break; + return luci::FusedActFunc::RELU_N1_TO_1; case circle::ActivationFunctionType::ActivationFunctionType_RELU6: return luci::FusedActFunc::RELU6; case circle::ActivationFunctionType::ActivationFunctionType_TANH: @@ -174,65 +137,44 @@ Padding luci_padding(const circle::Padding padding) } std::unique_ptr -luci_quantparam(const circle::QuantizationParameters *quantization) +luci_quantparam(const circle::QuantizationParametersT *quantization) { - if ((quantization->min() && quantization->max()) || - (quantization->scale() && quantization->zero_point())) - { - auto quantparam = stdex::make_unique(); + const auto &min = quantization->min; + const auto &max = quantization->max; + const auto &scale = quantization->scale; + const auto &zero_point = quantization->zero_point; - if (quantization->min()) - quantparam->min = as_index_vector(quantization->min()); - if (quantization->max()) - quantparam->max = as_index_vector(quantization->max()); + if ((!min.empty() && !max.empty()) || (!scale.empty() && !zero_point.empty())) + { + auto quantparam = std::make_unique(); - if (quantization->scale()) - quantparam->scale = as_index_vector(quantization->scale()); - if (quantization->zero_point()) - quantparam->zerop = as_index_vector(quantization->zero_point()); + quantparam->min = min; + quantparam->max = max; + quantparam->scale = scale; + quantparam->zerop = zero_point; - return std::move(quantparam); + return quantparam; } return nullptr; } -size_t CircleReader::buffer_info(uint32_t buf_idx, const uint8_t **buff_data) -{ - *buff_data = nullptr; - - if (buf_idx == 0) - return 0; - - if (auto *buffer = (*_buffers)[buf_idx]) - { - if (auto *array = buffer->data()) - { - if (size_t size = array->size()) - { - *buff_data = reinterpret_cast(array->data()); - return size; - } - } - } - - return 0; -} - -circle::BuiltinOperator CircleReader::builtin_code(const circle::Operator *op) const +circle::BuiltinOperator CircleReader::builtin_code(const circle::OperatorT &op) const { - uint32_t index = op->opcode_index(); - assert(index < _op_codes.size()); - const circle::OperatorCode *opcode = _op_codes.at(index); + const auto &op_codes = opcodes(); + uint32_t index = op.opcode_index; + assert(index < op_codes.size()); + const circle::OperatorCodeT &opcode = *op_codes[index]; - return opcode->builtin_code(); + return opcode.builtin_code; } -std::string CircleReader::opcode_name(const circle::Operator *op) const +std::string CircleReader::opcode_name(const circle::OperatorT &op) const { - uint32_t index = op->opcode_index(); - assert(index < _op_codes.size()); - const circle::OperatorCode *opcode = _op_codes.at(index); + const auto &op_codes = opcodes(); + uint32_t index = op.opcode_index; + assert(index < op_codes.size()); + const circle::OperatorCodeT &opcode = *op_codes[index]; if (!is_valid(opcode)) { @@ -248,41 +190,20 @@ bool CircleReader::parse(const circle::Model *model) { assert(model != nullptr); - _model = model; - - _subgraphs = _model->subgraphs(); - _buffers = _model->buffers(); - - auto opcodes = _model->operator_codes(); - for (const ::circle::OperatorCode *opcode : *opcodes) - { - _op_codes.push_back(opcode); - } + _model.reset(model->UnPack()); return true; } bool CircleReader::select_subgraph(uint32_t sgindex) { - _tensors = nullptr; - _operators = nullptr; - - _inputs.clear(); - _outputs.clear(); - - if (_subgraphs->Length() <= sgindex) + if (_model->subgraphs.size() <= sgindex) { assert(false); return false; } - const circle::SubGraph *subgraph = (*_subgraphs)[sgindex]; - - _tensors = subgraph->tensors(); - _operators = subgraph->operators(); - - _inputs = as_index_vector(subgraph->inputs()); - _outputs = as_index_vector(subgraph->outputs()); + _current_subgraph = _model->subgraphs[sgindex].get(); return true; } diff --git a/compiler/luci/import/src/GraphBuilder.cpp b/compiler/luci/import/src/GraphBuilder.cpp new file mode 100644 index 00000000000..e0ec9ded50f --- /dev/null +++ b/compiler/luci/import/src/GraphBuilder.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2020 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 "luci/Import/GraphBuilder.h" + +namespace luci +{ + +void GraphBuilder::build(const circle::OperatorT &op, GraphBuilderContext *context) const +{ + assert(context != nullptr); + + const std::vector &inputs = op.inputs; + const std::vector &outputs = op.outputs; + const auto &tensors = context->reader()->tensors(); + + std::vector input_nodes; + for (const int32_t input_tensor_index : inputs) + { + input_nodes.push_back(context->nodefinder()->node(input_tensor_index)); + } + + CircleNode *node = build_node(op, input_nodes, context->graph()); + + // Set up node parameters. + assert(outputs.size() == 1); + { + const circle::TensorT &output_tensor = *tensors[outputs[0]]; + + node->name(tensor_name(output_tensor)); + + auto quantization = tensor_quantization(output_tensor); + if (quantization) + { + auto quantparam = luci_quantparam(quantization); + if (quantparam) + node->quantparam(std::move(quantparam)); + } + } + + // Register node's only output. + assert(outputs.size() == 1); + { + context->nodefinder()->enroll(outputs[0], node); + } +} + +} // namespace luci diff --git a/compiler/luci/import/src/GraphBuilderContext.cpp b/compiler/luci/import/src/GraphBuilderContext.cpp index d9520aad6f8..a5162ce8353 100644 --- a/compiler/luci/import/src/GraphBuilderContext.cpp +++ b/compiler/luci/import/src/GraphBuilderContext.cpp @@ -23,38 +23,6 @@ namespace luci { -void NodeOpFinder::enroll(CircleNode *node, const circle::Operator *op) -{ - assert(_table.find(node) == _table.end()); - - _table[node] = op; -} - -const circle::Operator *NodeOpFinder::op(CircleNode *node) const -{ - MapNodeOperator_t::const_iterator iter = _table.find(node); - - assert(iter != _table.end()); - - return iter->second; -} - -void NodeTensorFinder::enroll(CircleNode *node, const circle::Tensor *tensor) -{ - assert(_table.find(node) == _table.end()); - - _table[node] = tensor; -} - -const circle::Tensor *NodeTensorFinder::tensor(CircleNode *node) const -{ - MapNodeTensor_t::const_iterator iter = _table.find(node); - - assert(iter != _table.end()); - - return iter->second; -} - void IndexNodeFinder::enroll(TensorIndex idx, CircleNode *node) { if (_table.find(idx) != _table.end()) @@ -71,14 +39,9 @@ CircleNode *IndexNodeFinder::node(TensorIndex idx) const { MapIndexNode_t::const_iterator iter = _table.find(idx); - assert(iter != _table.end()); + assert(iter != _table.end() && iter->second != nullptr); return iter->second; } -void UpdateQueue::enroll(std::unique_ptr &&update) -{ - _queue.push_back(std::move(update)); -} - } // namespace luci diff --git a/compiler/luci/import/src/GraphBuilderRegistry.cpp b/compiler/luci/import/src/GraphBuilderRegistry.cpp index fc6de6209d4..45d40b839c9 100644 --- a/compiler/luci/import/src/GraphBuilderRegistry.cpp +++ b/compiler/luci/import/src/GraphBuilderRegistry.cpp @@ -18,28 +18,45 @@ #include "luci/Import/Nodes.h" -#include +#include namespace luci { GraphBuilderRegistry::GraphBuilderRegistry() { - add(circle::BuiltinOperator_ADD, stdex::make_unique()); // 0 - add(circle::BuiltinOperator_ARG_MAX, stdex::make_unique()); // 56 - add(circle::BuiltinOperator_CONV_2D, stdex::make_unique()); // 3 - add(circle::BuiltinOperator_MAX_POOL_2D, stdex::make_unique()); // 17 - add(circle::BuiltinOperator_MEAN, stdex::make_unique()); // 40 - add(circle::BuiltinOperator_PAD, stdex::make_unique()); // 34 - add(circle::BuiltinOperator_RESHAPE, stdex::make_unique()); // 22 +#define CIRCLE_NODE(OPCODE, CLASS) add(circle::BuiltinOperator_##OPCODE, std::make_unique()); + + CIRCLE_NODE(ABS, CircleAbsGraphBuilder); // 101 + CIRCLE_NODE(ADD, CircleAddGraphBuilder); // 0 + CIRCLE_NODE(ARG_MAX, CircleArgMaxGraphBuilder); // 56 + CIRCLE_NODE(AVERAGE_POOL_2D, CircleAveragePool2DGraphBuilder); // 1 + CIRCLE_NODE(CONCATENATION, CircleConcatenationGraphBuilder); // 2 + CIRCLE_NODE(CONV_2D, CircleConv2DGraphBuilder); // 3 + CIRCLE_NODE(COS, CircleCosGraphBuilder); // 108 + CIRCLE_NODE(DEPTHWISE_CONV_2D, CircleDepthwiseConv2DGraphBuilder); // 4 + CIRCLE_NODE(DIV, CircleDivGraphBuilder); // 42 + CIRCLE_NODE(EQUAL, CircleEqualGraphBuilder); // 71 + CIRCLE_NODE(FULLY_CONNECTED, CircleFullyConnectedGraphBuilder); // 9 + CIRCLE_NODE(LOGICAL_NOT, CircleLogicalNotGraphBuilder); // 87 + CIRCLE_NODE(LOGICAL_OR, CircleLogicalOrGraphBuilder); // 84 + CIRCLE_NODE(MAX_POOL_2D, CircleMaxPool2DGraphBuilder); // 17 + CIRCLE_NODE(MEAN, CircleMeanGraphBuilder); // 40 + CIRCLE_NODE(MUL, CircleMulGraphBuilder); // 18 + CIRCLE_NODE(PACK, CirclePackGraphBuilder); // 83 + CIRCLE_NODE(PAD, CirclePadGraphBuilder); // 34 + CIRCLE_NODE(RELU, CircleReluGraphBuilder); // 19 + CIRCLE_NODE(RESHAPE, CircleReshapeGraphBuilder); // 22 + CIRCLE_NODE(RSQRT, CircleRsqrtGraphBuilder); // 76 + CIRCLE_NODE(SOFTMAX, CircleSoftmaxGraphBuilder); // 25 + CIRCLE_NODE(SUB, CircleSubGraphBuilder); // 41 + CIRCLE_NODE(TRANSPOSE, CircleTransposeGraphBuilder); // 39 + +#undef CIRCLE_NODE - // BuiltinOperator_AVERAGE_POOL_2D = 1, - // BuiltinOperator_CONCATENATION = 2, - // BuiltinOperator_DEPTHWISE_CONV_2D = 4, // BuiltinOperator_DEQUANTIZE = 6, // BuiltinOperator_EMBEDDING_LOOKUP = 7, // BuiltinOperator_FLOOR = 8, - // BuiltinOperator_FULLY_CONNECTED = 9, // BuiltinOperator_HASHTABLE_LOOKUP = 10, // BuiltinOperator_L2_NORMALIZATION = 11, // BuiltinOperator_L2_POOL_2D = 12, @@ -47,13 +64,10 @@ GraphBuilderRegistry::GraphBuilderRegistry() // BuiltinOperator_LOGISTIC = 14, // BuiltinOperator_LSH_PROJECTION = 15, // BuiltinOperator_LSTM = 16, - // BuiltinOperator_MUL = 18, - // BuiltinOperator_RELU = 19, // BuiltinOperator_RELU_N1_TO_1 = 20, // BuiltinOperator_RELU6 = 21, // BuiltinOperator_RESIZE_BILINEAR = 23, // BuiltinOperator_RNN = 24, - // BuiltinOperator_SOFTMAX = 25, // BuiltinOperator_SPACE_TO_DEPTH = 26, // BuiltinOperator_SVDF = 27, // BuiltinOperator_TANH = 28, @@ -66,9 +80,6 @@ GraphBuilderRegistry::GraphBuilderRegistry() // BuiltinOperator_GATHER = 36, // BuiltinOperator_BATCH_TO_SPACE_ND = 37, // BuiltinOperator_SPACE_TO_BATCH_ND = 38, - // BuiltinOperator_TRANSPOSE = 39, - // BuiltinOperator_SUB = 41, - // BuiltinOperator_DIV = 42, // BuiltinOperator_SQUEEZE = 43, // BuiltinOperator_UNIDIRECTIONAL_SEQUENCE_LSTM = 44, // BuiltinOperator_STRIDED_SLICE = 45, @@ -97,23 +108,18 @@ GraphBuilderRegistry::GraphBuilderRegistry() // BuiltinOperator_SPARSE_TO_DENSE = 68, // BuiltinOperator_TILE = 69, // BuiltinOperator_EXPAND_DIMS = 70, - // BuiltinOperator_EQUAL = 71, // BuiltinOperator_NOT_EQUAL = 72, // BuiltinOperator_LOG = 73, // BuiltinOperator_SUM = 74, // BuiltinOperator_SQRT = 75, - // BuiltinOperator_RSQRT = 76, // BuiltinOperator_SHAPE = 77, // BuiltinOperator_POW = 78, // BuiltinOperator_ARG_MIN = 79, // BuiltinOperator_FAKE_QUANT = 80, // BuiltinOperator_REDUCE_PROD = 81, // BuiltinOperator_REDUCE_MAX = 82, - // BuiltinOperator_PACK = 83, - // BuiltinOperator_LOGICAL_OR = 84, // BuiltinOperator_ONE_HOT = 85, // BuiltinOperator_LOGICAL_AND = 86, - // BuiltinOperator_LOGICAL_NOT = 87, // BuiltinOperator_UNPACK = 88, // BuiltinOperator_REDUCE_MIN = 89, // BuiltinOperator_FLOOR_DIV = 90, @@ -127,8 +133,30 @@ GraphBuilderRegistry::GraphBuilderRegistry() // BuiltinOperator_LEAKY_RELU = 98, // BuiltinOperator_SQUARED_DIFFERENCE = 99, // BuiltinOperator_MIRROR_PAD = 100, - // BuiltinOperator_ABS = 101, // BuiltinOperator_SPLIT_V = 102, + // BuiltinOperator_UNIQUE = 103, + // BuiltinOperator_CEIL = 104, + // BuiltinOperator_REVERSE_V2 = 105, + // BuiltinOperator_ADD_N = 106, + // BuiltinOperator_GATHER_ND = 107, + // BuiltinOperator_WHERE = 109, + // BuiltinOperator_RANK = 110, + // BuiltinOperator_ELU = 111, + // BuiltinOperator_REVERSE_SEQUENCE = 112, + // BuiltinOperator_MATRIX_DIAG = 113, + // BuiltinOperator_QUANTIZE = 114, + // BuiltinOperator_MATRIX_SET_DIAG = 115, + // BuiltinOperator_ROUND = 116, + // BuiltinOperator_HARD_SWISH = 117, + // BuiltinOperator_IF = 118, + // BuiltinOperator_WHILE = 119, + // BuiltinOperator_NON_MAX_SUPPRESSION_V4 = 120, + // BuiltinOperator_NON_MAX_SUPPRESSION_V5 = 121, + // BuiltinOperator_SCATTER_ND = 122, + // BuiltinOperator_SELECT_V2 = 123, + // BuiltinOperator_DENSIFY = 124, + // BuiltinOperator_SEGMENT_SUM = 125, + // BuiltinOperator_BATCH_MATMUL = 126, // BuiltinOperator_INSTANCE_NORM = 254, } diff --git a/compiler/luci/import/src/Importer.cpp b/compiler/luci/import/src/Importer.cpp index ee88bd2e443..607799ef65b 100644 --- a/compiler/luci/import/src/Importer.cpp +++ b/compiler/luci/import/src/Importer.cpp @@ -20,13 +20,15 @@ #include "luci/Import/GraphBuilderContext.h" #include "luci/Import/GraphBuilderRegistry.h" #include "luci/Import/CircleReader.h" +#include "luci/Import/Nodes/CircleConst.h" #include #include #include #include -#include + +#include namespace { @@ -36,16 +38,12 @@ void convert_graph(const luci::GraphBuilderSource &source, luci::CircleReader &r { LOGGER(l); - auto opfinder = stdex::make_unique(); - auto tensorfinder = stdex::make_unique(); - auto nodefinder = stdex::make_unique(); - auto updates = stdex::make_unique(); + auto nodefinder = std::make_unique(); - luci::GraphBuilderContext gb_context(graph, &reader, opfinder.get(), tensorfinder.get(), - nodefinder.get(), updates.get()); + luci::GraphBuilderContext gb_context(graph, &reader, nodefinder.get()); - auto operators = reader.operators(); - auto tensors = reader.tensors(); + const auto &operators = reader.operators(); + const auto &tensors = reader.tensors(); // graph inputs; there are no input nodes in TFlite but just Tensors // creating virtual input nodes will make possible to connect nodes that uses them @@ -54,9 +52,7 @@ void convert_graph(const luci::GraphBuilderSource &source, luci::CircleReader &r { auto input_node = graph->nodes()->create(); assert(input_node != nullptr); - opfinder->enroll(input_node, nullptr); // there is no Op for graph output - auto tensor = tensors->Get(input); - tensorfinder->enroll(input_node, tensor); + const circle::TensorT &tensor = *tensors[input]; auto tname = luci::tensor_name(tensor); input_node->name(tname); @@ -72,14 +68,13 @@ void convert_graph(const luci::GraphBuilderSource &source, luci::CircleReader &r nodefinder->enroll(input, input_node); // Shape of Input - assert(tensor->shape()); - std::vector input_dims = luci::as_index_vector(tensor->shape()); // in NHWC + const std::vector &input_dims = tensor.shape; // in NHWC input_node->rank(input_dims.size()); for (uint32_t r = 0; r < input_dims.size(); ++r) input_node->dim(r) = loco::Dimension(input_dims[r]); // Data type of Input - auto dtype = luci::luci_datatype(tensor); + auto dtype = luci::luci_datatype(tensor.type); input_node->dtype(dtype); // Name @@ -93,14 +88,32 @@ void convert_graph(const luci::GraphBuilderSource &source, luci::CircleReader &r graph_input->dtype(dtype); } - for (uint32_t i = 0; i < operators->Length(); ++i) + // Create CircleConst nodes for constant tensors. + const auto &buffers = reader.buffers(); + for (uint32_t i = 0; i < tensors.size(); ++i) { - const auto op = operators->Get(i); + const circle::TensorT &tensor = *tensors[i]; + const std::vector &buffer = buffers[tensor.buffer]->data; + if (!buffer.empty()) + { + luci::CircleConst *const_node = luci::create_circleconst(&gb_context, i); + nodefinder->enroll(i, const_node); + } + } + + // Import the operators. + // Note that operators in model are stored in execution order. This means that when importing + // an operator, its input operators have already been imported. We exploit this fact to set up + // node's inputs right after creating the node. + for (uint32_t i = 0; i < operators.size(); ++i) + { + const circle::OperatorT &op = *operators[i]; circle::BuiltinOperator builtincode = reader.builtin_code(op); if (const auto *builder = source.lookup(builtincode)) { - if (!builder->validate(op)) + luci::GraphBuilder::ValidateArgs args(op, reader); + if (!builder->validate(args)) { throw oops::UserExn("Invalid operator", reader.opcode_name(op)); } @@ -113,25 +126,17 @@ void convert_graph(const luci::GraphBuilderSource &source, luci::CircleReader &r } } - // connect nodes - for (auto &update : updates->queue()) - { - update->update(&gb_context); - } - // graph outputs for (auto output : reader.outputs()) { auto output_node = graph->nodes()->create(); assert(output_node != nullptr); - auto node = nodefinder->node(output); - assert(node != nullptr); - output_node->from(node); + output_node->from(nodefinder->node(output)); INFO(l) << "[luci] NodeFinder OUTPUT(" << output << ") = " << output_node << std::endl; // set the graph output name and node object - auto tensor = tensors->Get(output); + const circle::TensorT &tensor = *tensors[output]; auto graph_output = graph->outputs()->create(); std::string tname = luci::tensor_name(tensor); graph_output->name("output_" + tname); @@ -140,16 +145,15 @@ void convert_graph(const luci::GraphBuilderSource &source, luci::CircleReader &r output_node->index(graph_output->index()); // Shape of Output - assert(tensor->shape()); - auto output_shape = stdex::make_unique(); - std::vector output_dims = luci::as_index_vector(tensor->shape()); // in NHWC + auto output_shape = std::make_unique(); + const std::vector &output_dims = tensor.shape; // in NHWC output_shape->rank(output_dims.size()); for (uint32_t r = 0; r < output_dims.size(); ++r) output_shape->dim(r) = loco::Dimension(output_dims[r]); graph_output->shape(std::move(output_shape)); // Data type - auto dtype = luci::luci_datatype(tensor); + auto dtype = luci::luci_datatype(tensor.type); graph_output->dtype(dtype); } } @@ -201,7 +205,7 @@ std::unique_ptr Importer::import(const circle::Model *model) const LOGGER(l); INFO(l) << fmt(graph.get()); - assert(loco::valid(graph.get(), stdex::make_unique())); + assert(loco::valid(graph.get(), std::make_unique())); return std::move(graph); } diff --git a/compiler/luci/import/src/Nodes/CircleAbs.cpp b/compiler/luci/import/src/Nodes/CircleAbs.cpp new file mode 100644 index 00000000000..9054986bd39 --- /dev/null +++ b/compiler/luci/import/src/Nodes/CircleAbs.cpp @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2020 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 "luci/Import/Nodes/CircleAbs.h" + +#include + +#include + +namespace luci +{ +bool CircleAbsGraphBuilder::validate(const ValidateArgs &args) const +{ + if (args.op.inputs.size() != 1) + return false; + + // TODO Support type check + return true; +} + +CircleNode *CircleAbsGraphBuilder::build_node(const circle::OperatorT &, + const std::vector &inputs, + loco::Graph *graph) const +{ + auto *node = graph->nodes()->create(); + node->x(inputs[0]); + + return node; +} + +} // namespace luci diff --git a/compiler/luci/import/src/Nodes/CircleAdd.cpp b/compiler/luci/import/src/Nodes/CircleAdd.cpp index dc4b91f19f3..3b1bb734f16 100644 --- a/compiler/luci/import/src/Nodes/CircleAdd.cpp +++ b/compiler/luci/import/src/Nodes/CircleAdd.cpp @@ -15,118 +15,34 @@ */ #include "luci/Import/Nodes/CircleAdd.h" -#include "luci/Import/GraphBuilderContext.h" #include -#include #include -#include - -#include - -namespace -{ - -using namespace luci; - -class CircleAddGraphUpdate final : public GraphUpdate -{ -public: - CircleAddGraphUpdate(CircleAdd *node) : _node(node) {} - - void update(GraphBuilderContext *) override; - -private: - CircleAdd *_node; -}; - -} // namespace namespace luci { -bool CircleAddGraphBuilder::validate(const circle::Operator *op) const +bool CircleAddGraphBuilder::validate(const ValidateArgs &args) const { - const std::vector &inputs = as_index_vector(op->inputs()); - if (inputs.size() != 2) + if (args.op.inputs.size() != 2) return false; return true; } -void CircleAddGraphBuilder::build(const circle::Operator *op, GraphBuilderContext *context) const +CircleNode *CircleAddGraphBuilder::build_node(const circle::OperatorT &op, + const std::vector &inputs, + loco::Graph *graph) const { - LOGGER(l); - - assert(context != nullptr); - - auto graph = context->graph(); - auto reader = context->reader(); - auto opfinder = context->opfinder(); - auto tensorfinder = context->tensorfinder(); - auto nodefinder = context->nodefinder(); - auto updates = context->updates(); + auto *node = graph->nodes()->create(); + node->x(inputs[0]); + node->y(inputs[1]); - // FlatBuffer contents - auto tensors = reader->tensors(); + const auto *options = op.builtin_options.AsAddOptions(); + node->fusedActivationFunction(luci_actfunc(options->fused_activation_function)); - const std::vector &inputs = as_index_vector(op->inputs()); - const std::vector &outputs = as_index_vector(op->outputs()); - - // Add node itself - auto add_node = graph->nodes()->create(); - assert(outputs.size() > 0); - uint32_t output_ti = static_cast(outputs[0]); - auto output_tensor = tensors->Get(output_ti); - auto tname = tensor_name(output_tensor); - add_node->name(tname); - auto quantization = tensor_quantization(output_tensor); - if (quantization) - { - auto quantparam = luci_quantparam(quantization); - if (quantparam.get()) - add_node->quantparam(std::move(quantparam)); - } - opfinder->enroll(add_node, op); - tensorfinder->enroll(add_node, output_tensor); - for (auto output : outputs) - { - INFO(l) << "[luci] NodeFinder add_node(" << output << ") -> " << add_node << std::endl; - nodefinder->enroll(output, add_node); - } - const auto *options = op->builtin_options_as_AddOptions(); - - // Activation - auto actfunctype = luci_actfunc(options->fused_activation_function()); - add_node->fusedActivationFunction(actfunctype); - - // Create GraphUpdate for graph connection for Add node - auto update = stdex::make_unique(add_node); - updates->enroll(std::move(update)); + return node; } } // namespace luci - -namespace -{ - -void CircleAddGraphUpdate::update(GraphBuilderContext *context) -{ - auto opfinder = context->opfinder(); - auto nodefinder = context->nodefinder(); - - auto op = opfinder->op(_node); - - // set input 'x, y' - const std::vector &inputs = luci::as_index_vector(op->inputs()); - uint32_t idx_x = static_cast(inputs[0]); - uint32_t idx_y = static_cast(inputs[1]); - auto node_x = nodefinder->node(idx_x); - assert(node_x != nullptr); - auto node_y = nodefinder->node(idx_y); - _node->x(node_x); - _node->y(node_y); -} - -} // namespace diff --git a/compiler/luci/import/src/Nodes/CircleArgMax.cpp b/compiler/luci/import/src/Nodes/CircleArgMax.cpp index 054a5918c44..2679827e2be 100644 --- a/compiler/luci/import/src/Nodes/CircleArgMax.cpp +++ b/compiler/luci/import/src/Nodes/CircleArgMax.cpp @@ -15,124 +15,34 @@ */ #include "luci/Import/Nodes/CircleArgMax.h" -#include "luci/Import/Nodes/CircleConst.h" -#include "luci/Import/GraphBuilderContext.h" #include -#include #include -#include - -#include - -namespace -{ - -using namespace luci; - -class CircleArgMaxGraphUpdate final : public GraphUpdate -{ -public: - CircleArgMaxGraphUpdate(CircleArgMax *node) : _node(node) {} - - void update(GraphBuilderContext *) override; - -private: - CircleArgMax *_node; -}; - -} // namespace namespace luci { -bool CircleArgMaxGraphBuilder::validate(const circle::Operator *op) const +bool CircleArgMaxGraphBuilder::validate(const ValidateArgs &args) const { - const std::vector &inputs = as_index_vector(op->inputs()); - if (inputs.size() != 2) + if (args.op.inputs.size() != 2) return false; return true; } -void CircleArgMaxGraphBuilder::build(const circle::Operator *op, GraphBuilderContext *context) const +CircleNode *CircleArgMaxGraphBuilder::build_node(const circle::OperatorT &op, + const std::vector &inputs, + loco::Graph *graph) const { - LOGGER(l); - - assert(context != nullptr); - - auto graph = context->graph(); - auto reader = context->reader(); - auto opfinder = context->opfinder(); - auto tensorfinder = context->tensorfinder(); - auto nodefinder = context->nodefinder(); - auto updates = context->updates(); - - // FlatBuffer contents - auto tensors = reader->tensors(); + auto *node = graph->nodes()->create(); + node->input(inputs[0]); + node->dimension(inputs[1]); - const std::vector &inputs = as_index_vector(op->inputs()); - const std::vector &outputs = as_index_vector(op->outputs()); - assert(outputs.size() > 0); + const auto *options = op.builtin_options.AsArgMaxOptions(); + node->output_type(luci_datatype(options->output_type)); - // ArgMax node itself - auto argmax_node = graph->nodes()->create(); - uint32_t output_ti = static_cast(outputs[0]); - auto output_tensor = tensors->Get(output_ti); - auto tname = tensor_name(output_tensor); - argmax_node->name(tname); - opfinder->enroll(argmax_node, op); - tensorfinder->enroll(argmax_node, output_tensor); - for (auto output : outputs) - { - INFO(l) << "[luci] NodeFinder argmax_node(" << output << ") -> " << argmax_node << std::endl; - nodefinder->enroll(output, argmax_node); - } - const auto *options = op->builtin_options_as_ArgMaxOptions(); - if (options != nullptr) - { - // output_type - auto output_type = luci_datatype(options->output_type()); - argmax_node->output_type(output_type); - } - - // ArgMax dimension tensor + buffer to CircleConst node - uint32_t dimension_ti = static_cast(inputs[1]); - auto dimension_const = create_circleconst(context, dimension_ti); - argmax_node->dimension(dimension_const); - - // Create GraphUpdate for graph connection for Add node - auto update = stdex::make_unique(argmax_node); - updates->enroll(std::move(update)); + return node; } } // namespace luci - -namespace -{ - -void CircleArgMaxGraphUpdate::update(GraphBuilderContext *context) -{ - LOGGER(l); - - auto opfinder = context->opfinder(); - auto nodefinder = context->nodefinder(); - - auto op = opfinder->op(_node); - - // set input - const std::vector &inputs = luci::as_index_vector(op->inputs()); - uint32_t idx_0 = static_cast(inputs[0]); - uint32_t idx_1 = static_cast(inputs[1]); - INFO(l) << "[luci] ArgMax update " << idx_0 << ", " << idx_1 << std::endl; - auto node_0 = nodefinder->node(idx_0); - assert(node_0 != nullptr); - auto node_1 = nodefinder->node(idx_1); - (void)node_1; // unused error for release build - assert(node_1 != nullptr); - _node->input(node_0); - assert(_node->dimension() == node_1); -} - -} // namespace diff --git a/compiler/luci/import/src/Nodes/CircleAveragePool2D.cpp b/compiler/luci/import/src/Nodes/CircleAveragePool2D.cpp new file mode 100644 index 00000000000..cfc3cf1262e --- /dev/null +++ b/compiler/luci/import/src/Nodes/CircleAveragePool2D.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2020 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 "luci/Import/Nodes/CircleAveragePool2D.h" + +#include + +namespace luci +{ + +bool CircleAveragePool2DGraphBuilder::validate(const ValidateArgs &args) const +{ + if (args.op.inputs.size() != 1) + return false; + + return true; +} + +CircleNode *CircleAveragePool2DGraphBuilder::build_node(const circle::OperatorT &op, + const std::vector &inputs, + loco::Graph *graph) const +{ + auto *node = graph->nodes()->create(); + node->value(inputs[0]); + + const auto *options = op.builtin_options.AsPool2DOptions(); + node->padding(luci_padding(options->padding)); + node->stride()->w(options->stride_w); + node->stride()->h(options->stride_h); + node->filter()->w(options->filter_width); + node->filter()->h(options->filter_height); + node->fusedActivationFunction(luci_actfunc(options->fused_activation_function)); + + return node; +} + +} // namespace luci diff --git a/compiler/luci/import/src/Nodes/CircleConcatenation.cpp b/compiler/luci/import/src/Nodes/CircleConcatenation.cpp new file mode 100644 index 00000000000..7fc616aa0ba --- /dev/null +++ b/compiler/luci/import/src/Nodes/CircleConcatenation.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2020 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 "luci/Import/Nodes/CircleConcatenation.h" + +#include + +namespace luci +{ + +bool CircleConcatenationGraphBuilder::validate(const ValidateArgs &args) const +{ + if (args.op.inputs.size() < 1) + return false; + + if (args.op.outputs.size() != 1) + return false; + + return true; +} + +CircleNode *CircleConcatenationGraphBuilder::build_node(const circle::OperatorT &op, + const std::vector &inputs, + loco::Graph *graph) const +{ + auto *node = graph->nodes()->create(inputs.size()); + for (uint32_t i = 0; i < inputs.size(); ++i) + { + node->values(i, inputs[i]); + } + + const auto *options = op.builtin_options.AsConcatenationOptions(); + node->axis(options->axis); + node->fusedActivationFunction(luci_actfunc(options->fused_activation_function)); + + return node; +} + +} // namespace luci diff --git a/compiler/luci/import/src/Nodes/CircleConst.cpp b/compiler/luci/import/src/Nodes/CircleConst.cpp index 6718e89befe..1d798983bc5 100644 --- a/compiler/luci/import/src/Nodes/CircleConst.cpp +++ b/compiler/luci/import/src/Nodes/CircleConst.cpp @@ -20,7 +20,6 @@ #include #include -#include #include #include @@ -28,6 +27,22 @@ namespace luci { +template +static void copy_data(const std::vector &raw_data, uint32_t num_elements, + CircleConst *const_node) +{ + using T = typename loco::DataTypeImpl
::Type; + + assert(raw_data.size() == num_elements * sizeof(T)); + const auto *data = reinterpret_cast(raw_data.data()); + + const_node->size
(num_elements); + for (uint32_t i = 0; i < num_elements; ++i) + { + const_node->at
(i) = data[i]; + } +} + // // circleconst_from_tensor() ? // @@ -37,26 +52,27 @@ CircleConst *create_circleconst(GraphBuilderContext *context, int32_t tensor_ind auto graph = context->graph(); auto reader = context->reader(); - auto opfinder = context->opfinder(); - auto tensorfinder = context->tensorfinder(); - auto nodefinder = context->nodefinder(); - auto tensors = reader->tensors(); + const auto &tensors = reader->tensors(); // (1) create CircleConst auto const_node = graph->nodes()->create(); - auto const_tensor = tensors->Get(tensor_index); - opfinder->enroll(const_node, nullptr); - tensorfinder->enroll(const_node, const_tensor); - nodefinder->enroll(tensor_index, const_node); + const circle::TensorT &const_tensor = *tensors[tensor_index]; + const_node->name(tensor_name(const_tensor)); + auto quantization = luci::tensor_quantization(const_tensor); + if (quantization) + { + auto quantparam = luci::luci_quantparam(quantization); + if (quantparam.get()) + const_node->quantparam(std::move(quantparam)); + } INFO(l) << "[luci] NodeFinder const_node(" << tensor_index << ") -> " << const_node << std::endl; // (2) set data_type to CircleConst - const_node->dtype(luci_datatype(const_tensor)); + const_node->dtype(luci_datatype(const_tensor.type)); // (3) set shape to CicleConst - assert(const_tensor->shape()); - std::vector const_dims = as_index_vector(const_tensor->shape()); // in NHWC + std::vector const_dims = const_tensor.shape; // in NHWC const_node->rank(const_dims.size()); uint32_t num_elements = 1; for (uint32_t r = 0; r < const_dims.size(); ++r) @@ -66,48 +82,26 @@ CircleConst *create_circleconst(GraphBuilderContext *context, int32_t tensor_ind } // (4) constant values from circle buffer - uint32_t const_buff_idx = const_tensor->buffer(); - const uint8_t *const_buff_data = nullptr; - size_t const_buff_size = reader->buffer_info(const_buff_idx, &const_buff_data); - switch (luci_datatype(const_tensor)) + const std::vector &buffer = reader->buffers()[const_tensor.buffer]->data; + if (buffer.empty()) + throw oops::UserExn("Empty buffer"); + + switch (luci_datatype(const_tensor.type)) { case loco::DataType::FLOAT32: - { - // NOTE assert(const_buff_size == num_elements * sizeof(float)) will drop - // unused variables compilation error in release build. - if (const_buff_size != num_elements * sizeof(float)) - throw oops::UserExn("Invalid Buffer size", "FLOAT32"); - const float *float_cb = reinterpret_cast(const_buff_data); - const_node->size(num_elements); - for (uint32_t ele = 0; ele < num_elements; ++ele) - const_node->at(ele) = float_cb[ele]; + copy_data(buffer, num_elements, const_node); break; - } case loco::DataType::U8: - { - if (const_buff_size != num_elements * sizeof(uint8_t)) - throw oops::UserExn("Invalid Buffer size", "UINT8"); - const uint8_t *uint8_cb = reinterpret_cast(const_buff_data); - const_node->size(num_elements); - for (uint32_t ele = 0; ele < num_elements; ++ele) - const_node->at(ele) = uint8_cb[ele]; + copy_data(buffer, num_elements, const_node); break; - } case loco::DataType::S32: - { - if (const_buff_size != num_elements * sizeof(int32_t)) - throw oops::UserExn("Invalid Buffer size", "INT32"); - const int32_t *int32_cb = reinterpret_cast(const_buff_data); - const_node->size(num_elements); - for (uint32_t ele = 0; ele < num_elements; ++ele) - const_node->at(ele) = int32_cb[ele]; + copy_data(buffer, num_elements, const_node); break; - } default: - assert(false); + throw oops::UserExn("Unsupported tensor type", circle::EnumNameTensorType(const_tensor.type)); } return const_node; diff --git a/compiler/luci/import/src/Nodes/CircleConv2D.cpp b/compiler/luci/import/src/Nodes/CircleConv2D.cpp index 05c7f7fa502..ec9dce0d288 100644 --- a/compiler/luci/import/src/Nodes/CircleConv2D.cpp +++ b/compiler/luci/import/src/Nodes/CircleConv2D.cpp @@ -15,146 +15,44 @@ */ #include "luci/Import/Nodes/CircleConv2D.h" -#include "luci/Import/Nodes/CircleConst.h" -#include "luci/Import/GraphBuilderContext.h" #include -#include -#include #include -#include #include -namespace -{ - -using namespace luci; - -class CircleConv2DGraphUpdate final : public GraphUpdate -{ -public: - CircleConv2DGraphUpdate(CircleConv2D *node) : _node(node) {} - - void update(GraphBuilderContext *) override; - -private: - CircleConv2D *_node; -}; - -} // namespace - namespace luci { -bool CircleConv2DGraphBuilder::validate(const circle::Operator *op) const +bool CircleConv2DGraphBuilder::validate(const ValidateArgs &args) const { // Circle Conv2D may not have a bias but we won't support this - const std::vector &inputs = as_index_vector(op->inputs()); - if (inputs.size() != 3) + if (args.op.inputs.size() != 3) return false; return true; } -void CircleConv2DGraphBuilder::build(const circle::Operator *op, GraphBuilderContext *context) const +CircleNode *CircleConv2DGraphBuilder::build_node(const circle::OperatorT &op, + const std::vector &inputs, + loco::Graph *graph) const { - LOGGER(l); - - assert(context != nullptr); - - auto graph = context->graph(); - auto reader = context->reader(); - auto opfinder = context->opfinder(); - auto tensorfinder = context->tensorfinder(); - auto nodefinder = context->nodefinder(); - auto updates = context->updates(); - - // FlatBuffer contents - auto tensors = reader->tensors(); - - const std::vector &inputs = as_index_vector(op->inputs()); - const std::vector &outputs = as_index_vector(op->outputs()); - - // Conv2D node itself - auto conv2d_node = graph->nodes()->create(); - assert(outputs.size() > 0); - uint32_t output_ti = static_cast(outputs[0]); - auto output_tensor = tensors->Get(output_ti); - auto tname = tensor_name(output_tensor); - conv2d_node->name(tname); - auto quantization = tensor_quantization(output_tensor); - if (quantization) - { - auto quantparam = luci_quantparam(quantization); - if (quantparam.get()) - conv2d_node->quantparam(std::move(quantparam)); - } - opfinder->enroll(conv2d_node, op); - tensorfinder->enroll(conv2d_node, output_tensor); - for (auto output : outputs) - { - INFO(l) << "[luci] NodeFinder conv2d_node(" << output << ") -> " << conv2d_node << std::endl; - nodefinder->enroll(output, conv2d_node); - } - // TODO Output Shape ? - - const auto *options = op->builtin_options_as_Conv2DOptions(); - - // Padding - auto padding = luci_padding(options->padding()); - conv2d_node->padding(padding); - - // Stride - conv2d_node->stride()->w(options->stride_w()); - conv2d_node->stride()->h(options->stride_h()); - - // Activation - auto actfunctype = luci_actfunc(options->fused_activation_function()); - conv2d_node->fusedActivationFunction(actfunctype); - - // TODO extract function that returns CircleConst from tensor_index - // Conv2D kernel tensor + buffer to CircleConst node - uint32_t kernel_ti = static_cast(inputs[1]); - auto kernel_const = create_circleconst(context, kernel_ti); - conv2d_node->filter(kernel_const); - - // Conv2D bias tensor + buffer to CircleConst node, if exist - if (inputs.size() == 3) - { - uint32_t bias_ti = static_cast(inputs[2]); - auto bias_const = create_circleconst(context, bias_ti); - conv2d_node->bias(bias_const); - } - else - { - // TODO if we should support without bias, let's implement here - } - - // Create GraphUpdate for graph connection for Conv2D node - auto update = stdex::make_unique(conv2d_node); - updates->enroll(std::move(update)); + auto *node = graph->nodes()->create(); + node->input(inputs[0]); + node->filter(inputs[1]); + // For now, bias is required (checked in `verify` method). + assert(inputs.size() == 3); + node->bias(inputs[2]); + + const auto *options = op.builtin_options.AsConv2DOptions(); + node->padding(luci_padding(options->padding)); + node->stride()->w(options->stride_w); + node->stride()->h(options->stride_h); + node->fusedActivationFunction(luci_actfunc(options->fused_activation_function)); + // FIXME Check dilation_w_factor, dilation_h_factor. + + return node; } } // namespace luci - -namespace -{ - -void CircleConv2DGraphUpdate::update(GraphBuilderContext *context) -{ - auto opfinder = context->opfinder(); - auto nodefinder = context->nodefinder(); - - auto op = opfinder->op(_node); - - // set input 'input' - const std::vector &inputs = luci::as_index_vector(op->inputs()); - uint32_t idx_input = static_cast(inputs[0]); - auto node_input = nodefinder->node(idx_input); - assert(node_input != nullptr); - _node->input(node_input); -} - -} // namespace diff --git a/compiler/luci/import/src/Nodes/CircleCos.cpp b/compiler/luci/import/src/Nodes/CircleCos.cpp new file mode 100644 index 00000000000..5f61cc7f6f9 --- /dev/null +++ b/compiler/luci/import/src/Nodes/CircleCos.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2020 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 "luci/Import/Nodes/CircleCos.h" + +#include + +#include + +namespace luci +{ + +bool CircleCosGraphBuilder::validate(const ValidateArgs &args) const +{ + if (args.op.inputs.size() != 1) + return false; + + return true; +} + +CircleNode *CircleCosGraphBuilder::build_node(const circle::OperatorT &, + const std::vector &inputs, + loco::Graph *graph) const +{ + auto *node = graph->nodes()->create(); + node->x(inputs[0]); + + // No options for Cos + + return node; +} + +} // namespace luci diff --git a/compiler/luci/import/src/Nodes/CircleDepthwiseConv2D.cpp b/compiler/luci/import/src/Nodes/CircleDepthwiseConv2D.cpp new file mode 100644 index 00000000000..c6d3b1f1e24 --- /dev/null +++ b/compiler/luci/import/src/Nodes/CircleDepthwiseConv2D.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2020 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 "luci/Import/Nodes/CircleDepthwiseConv2D.h" + +#include + +#include + +namespace luci +{ + +bool CircleDepthwiseConv2DGraphBuilder::validate(const ValidateArgs &args) const +{ + // Circle DepthwiseConv2D may not have a bias but we won't support this + if (args.op.inputs.size() != 3 && args.op.inputs.size() != 2) + return false; + + if (args.op.outputs.size() != 1) + return false; + + return true; +} + +CircleNode *CircleDepthwiseConv2DGraphBuilder::build_node(const circle::OperatorT &op, + const std::vector &inputs, + loco::Graph *graph) const +{ + auto *node = graph->nodes()->create(); + node->input(inputs[0]); + node->filter(inputs[1]); + if (inputs.size() != 3) + throw oops::UserExn("DepthwiseConv2d without bias is unsupported"); + node->bias(inputs[2]); + + const auto *options = op.builtin_options.AsDepthwiseConv2DOptions(); + node->padding(luci_padding(options->padding)); + node->stride()->w(options->stride_w); + node->stride()->h(options->stride_h); + node->depthMultiplier(options->depth_multiplier); + node->fusedActivationFunction(luci_actfunc(options->fused_activation_function)); + // FIXME Check dilation_w_factor, dilation_h_factor. + + return node; +} + +} // namespace luci diff --git a/compiler/luci/import/src/Nodes/CircleDiv.cpp b/compiler/luci/import/src/Nodes/CircleDiv.cpp new file mode 100644 index 00000000000..d09cfb815d5 --- /dev/null +++ b/compiler/luci/import/src/Nodes/CircleDiv.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2020 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 "luci/Import/Nodes/CircleDiv.h" + +#include + +namespace luci +{ + +bool CircleDivGraphBuilder::validate(const ValidateArgs &args) const +{ + if (args.op.inputs.size() != 2) + return false; + + if (args.op.outputs.size() != 1) + return false; + + return true; +} + +CircleNode *CircleDivGraphBuilder::build_node(const circle::OperatorT &op, + const std::vector &inputs, + loco::Graph *graph) const +{ + auto node = graph->nodes()->create(); + node->x(inputs[0]); + node->y(inputs[1]); + + const auto *options = op.builtin_options.AsDivOptions(); + node->fusedActivationFunction(luci_actfunc(options->fused_activation_function)); + + return node; +} + +} // namespace luci diff --git a/compiler/luci/import/src/Nodes/CircleEqual.cpp b/compiler/luci/import/src/Nodes/CircleEqual.cpp new file mode 100644 index 00000000000..a53f6e94b08 --- /dev/null +++ b/compiler/luci/import/src/Nodes/CircleEqual.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2020 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 "luci/Import/Nodes/CircleEqual.h" + +#include + +#include + +namespace luci +{ + +bool CircleEqualGraphBuilder::validate(const ValidateArgs &args) const +{ + const auto &inputs = args.op.inputs; + + if (inputs.size() != 2) + { + return false; + } + + const auto &tensors = args.reader.tensors(); + + return tensors[inputs[0]]->type == tensors[inputs[1]]->type; +} + +CircleNode *CircleEqualGraphBuilder::build_node(const circle::OperatorT &, + const std::vector &inputs, + loco::Graph *graph) const +{ + auto *node = graph->nodes()->create(); + node->x(inputs[0]); + node->y(inputs[1]); + + return node; +} + +} // namespace luci diff --git a/compiler/luci/import/src/Nodes/CircleFullyConnected.cpp b/compiler/luci/import/src/Nodes/CircleFullyConnected.cpp new file mode 100644 index 00000000000..8f74fe9cedd --- /dev/null +++ b/compiler/luci/import/src/Nodes/CircleFullyConnected.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2020 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 "luci/Import/Nodes/CircleFullyConnected.h" + +#include + +#include +#include + +namespace luci +{ + +bool CircleFullyConnectedGraphBuilder::validate(const ValidateArgs &args) const +{ + if (args.op.inputs.size() != 3) + return false; + + return true; +} + +CircleNode *CircleFullyConnectedGraphBuilder::build_node(const circle::OperatorT &op, + const std::vector &inputs, + loco::Graph *graph) const +{ + auto *node = graph->nodes()->create(); + node->input(inputs[0]); + node->weights(inputs[1]); + node->bias(inputs[2]); + + const auto *options = op.builtin_options.AsFullyConnectedOptions(); + node->fusedActivationFunction(luci_actfunc(options->fused_activation_function)); + if (options->weights_format != circle::FullyConnectedOptionsWeightsFormat_DEFAULT) + { + throw oops::UserExn( + "Unsupported weights format", + circle::EnumNameFullyConnectedOptionsWeightsFormat(options->weights_format)); + } + + return node; +} + +} // namespace luci diff --git a/compiler/luci/import/src/Nodes/CircleLogicalNot.cpp b/compiler/luci/import/src/Nodes/CircleLogicalNot.cpp new file mode 100644 index 00000000000..b1ed3ea37fe --- /dev/null +++ b/compiler/luci/import/src/Nodes/CircleLogicalNot.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2020 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 "luci/Import/Nodes/CircleLogicalNot.h" + +#include + +#include + +namespace luci +{ + +bool CircleLogicalNotGraphBuilder::validate(const ValidateArgs &args) const +{ + if (args.op.inputs.size() != 1) + return false; + + // Only BOOL type is allowed for the input + const auto &inputs = args.op.inputs; + const auto &tensors = args.reader.tensors(); + const auto &tensor = tensors.at(inputs[0]); + if (tensor->type != circle::TensorType::TensorType_BOOL) + return false; + + return true; +} + +CircleNode *CircleLogicalNotGraphBuilder::build_node(const circle::OperatorT &, + const std::vector &inputs, + loco::Graph *graph) const +{ + auto *node = graph->nodes()->create(); + node->x(inputs[0]); + + return node; +} + +} // namespace luci diff --git a/compiler/luci/import/src/Nodes/CircleLogicalOr.cpp b/compiler/luci/import/src/Nodes/CircleLogicalOr.cpp new file mode 100644 index 00000000000..00eb9c5df43 --- /dev/null +++ b/compiler/luci/import/src/Nodes/CircleLogicalOr.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2020 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 "luci/Import/Nodes/CircleLogicalOr.h" + +#include + +#include + +namespace luci +{ + +bool CircleLogicalOrGraphBuilder::validate(const ValidateArgs &args) const +{ + if (args.op.inputs.size() != 2) + return false; + + // Only BOOL type is allowed for inputs + const auto &inputs = args.op.inputs; + const auto &tensors = args.reader.tensors(); + for (auto input : inputs) + { + const auto &tensor = tensors.at(input); + if (tensor->type != circle::TensorType::TensorType_BOOL) + return false; + } + + return true; +} + +CircleNode *CircleLogicalOrGraphBuilder::build_node(const circle::OperatorT &, + const std::vector &inputs, + loco::Graph *graph) const +{ + auto *node = graph->nodes()->create(); + node->x(inputs[0]); + node->y(inputs[1]); + + return node; +} + +} // namespace luci diff --git a/compiler/luci/import/src/Nodes/CircleMaxPool2D.cpp b/compiler/luci/import/src/Nodes/CircleMaxPool2D.cpp index 1d361eeb465..1798819cf32 100644 --- a/compiler/luci/import/src/Nodes/CircleMaxPool2D.cpp +++ b/compiler/luci/import/src/Nodes/CircleMaxPool2D.cpp @@ -15,131 +15,38 @@ */ #include "luci/Import/Nodes/CircleMaxPool2D.h" -#include "luci/Import/GraphBuilderContext.h" -#include -#include +#include #include -#include - -#include - -namespace -{ - -using namespace luci; - -class CircleMaxPool2DGraphUpdate final : public GraphUpdate -{ -public: - CircleMaxPool2DGraphUpdate(CircleMaxPool2D *node) : _node(node) {} - - void update(GraphBuilderContext *) override; - -private: - CircleMaxPool2D *_node; -}; - -} // namespace namespace luci { -bool CircleMaxPool2DGraphBuilder::validate(const circle::Operator *op) const +bool CircleMaxPool2DGraphBuilder::validate(const ValidateArgs &args) const { - const std::vector &inputs = as_index_vector(op->inputs()); - if (inputs.size() != 1) + if (args.op.inputs.size() != 1) return false; return true; } -void CircleMaxPool2DGraphBuilder::build(const circle::Operator *op, - GraphBuilderContext *context) const +CircleNode *CircleMaxPool2DGraphBuilder::build_node(const circle::OperatorT &op, + const std::vector &inputs, + loco::Graph *graph) const { - LOGGER(l); - - assert(context != nullptr); - - auto graph = context->graph(); - auto reader = context->reader(); - auto opfinder = context->opfinder(); - auto tensorfinder = context->tensorfinder(); - auto nodefinder = context->nodefinder(); - auto updates = context->updates(); - - // FlatBuffer contents - auto tensors = reader->tensors(); - - const std::vector &inputs = as_index_vector(op->inputs()); - const std::vector &outputs = as_index_vector(op->outputs()); - - // MaxPool2D node itself - auto maxpool2d_node = graph->nodes()->create(); - assert(outputs.size() > 0); - uint32_t output_ti = static_cast(outputs[0]); - auto output_tensor = tensors->Get(output_ti); - - auto tname = tensor_name(output_tensor); - maxpool2d_node->name(tname); - auto quantization = tensor_quantization(output_tensor); - if (quantization) - { - auto quantparam = luci_quantparam(quantization); - if (quantparam.get()) - maxpool2d_node->quantparam(std::move(quantparam)); - } - - opfinder->enroll(maxpool2d_node, op); - tensorfinder->enroll(maxpool2d_node, output_tensor); - for (auto output : outputs) - { - INFO(l) << "[luci] NodeFinder maxpool2d_node(" << output << ") -> " << maxpool2d_node - << std::endl; - nodefinder->enroll(output, maxpool2d_node); - } - const auto *options = op->builtin_options_as_Pool2DOptions(); - - // Filter - maxpool2d_node->filter()->w(options->filter_width()); - maxpool2d_node->filter()->h(options->filter_height()); - - // Padding - auto padding = luci_padding(options->padding()); - maxpool2d_node->padding(padding); - - // Stride - maxpool2d_node->stride()->w(options->stride_w()); - maxpool2d_node->stride()->h(options->stride_h()); - - // Activation - auto actfunctype = luci_actfunc(options->fused_activation_function()); - maxpool2d_node->fusedActivationFunction(actfunctype); - - // Create GraphUpdate for graph connection for MaxPool2D node - auto update = stdex::make_unique(maxpool2d_node); - updates->enroll(std::move(update)); + auto *node = graph->nodes()->create(); + node->value(inputs[0]); + + const auto *options = op.builtin_options.AsPool2DOptions(); + node->padding(luci_padding(options->padding)); + node->stride()->w(options->stride_w); + node->stride()->h(options->stride_h); + node->filter()->w(options->filter_width); + node->filter()->h(options->filter_height); + node->fusedActivationFunction(luci_actfunc(options->fused_activation_function)); + + return node; } } // namespace luci - -namespace -{ - -void CircleMaxPool2DGraphUpdate::update(GraphBuilderContext *context) -{ - auto opfinder = context->opfinder(); - auto nodefinder = context->nodefinder(); - - auto op = opfinder->op(_node); - - // set input 'value' - const std::vector &inputs = luci::as_index_vector(op->inputs()); - uint32_t idx_value = static_cast(inputs[0]); - auto node_value = nodefinder->node(idx_value); - assert(node_value != nullptr); - _node->value(node_value); -} - -} // namespace diff --git a/compiler/luci/import/src/Nodes/CircleMean.cpp b/compiler/luci/import/src/Nodes/CircleMean.cpp index 6749e0f162a..8261c7b3813 100644 --- a/compiler/luci/import/src/Nodes/CircleMean.cpp +++ b/compiler/luci/import/src/Nodes/CircleMean.cpp @@ -15,70 +15,32 @@ */ #include "luci/Import/Nodes/CircleMean.h" -#include "luci/Import/GraphBuilderContext.h" #include -#include -#include - -#include - namespace luci { -bool CircleMeanGraphBuilder::validate(const circle::Operator *op) const +bool CircleMeanGraphBuilder::validate(const ValidateArgs &args) const { - const auto &inputs = *op->inputs(); - - if (inputs.size() != 2) + if (args.op.inputs.size() != 2) return false; return true; } -void CircleMeanGraphBuilder::build(const circle::Operator *op, GraphBuilderContext *context) const +CircleNode *CircleMeanGraphBuilder::build_node(const circle::OperatorT &op, + const std::vector &inputs, + loco::Graph *graph) const { - auto graph = context->graph(); - auto reader = context->reader(); - auto nodefinder = context->nodefinder(); - - auto tensors = reader->tensors(); - const auto &inputs = *op->inputs(); - const auto &outputs = *op->outputs(); - - assert(outputs.size() == 1); - const circle::Tensor *output_tensor = tensors->Get(outputs[0]); - - // Create the node. - auto mean_node = graph->nodes()->create(); - mean_node->name(tensor_name(output_tensor)); - - // Set node's quantization parameters, if any. - auto quantization = tensor_quantization(output_tensor); - if (quantization) - { - auto quantparam = luci_quantparam(quantization); - if (quantparam) - mean_node->quantparam(std::move(quantparam)); - } - - // input - CircleNode *input_node = nodefinder->node(inputs[0]); - assert(input_node != nullptr); - mean_node->input(input_node); - - // reduction indices - CircleNode *reduction_insices_node = nodefinder->node(inputs[1]); - assert(reduction_insices_node != nullptr); - mean_node->reduction_indices(reduction_insices_node); + auto *node = graph->nodes()->create(); + node->input(inputs[0]); + node->reduction_indices(inputs[1]); - // Configure options. - const auto *options = op->builtin_options_as_ReducerOptions(); - mean_node->keep_dims(options->keep_dims()); + const auto *options = op.builtin_options.AsReducerOptions(); + node->keep_dims(options->keep_dims); - // Register node's only output. - nodefinder->enroll(outputs[0], mean_node); + return node; } } // namespace luci diff --git a/compiler/luci/import/src/Nodes/CircleMul.cpp b/compiler/luci/import/src/Nodes/CircleMul.cpp new file mode 100644 index 00000000000..d4412b96b4d --- /dev/null +++ b/compiler/luci/import/src/Nodes/CircleMul.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2020 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 "luci/Import/Nodes/CircleMul.h" + +#include + +namespace luci +{ + +bool CircleMulGraphBuilder::validate(const ValidateArgs &args) const +{ + if (args.op.inputs.size() != 2) + return false; + + if (args.op.outputs.size() != 1) + return false; + + return true; +} + +CircleNode *CircleMulGraphBuilder::build_node(const circle::OperatorT &op, + const std::vector &inputs, + loco::Graph *graph) const +{ + auto *node = graph->nodes()->create(); + node->x(inputs[0]); + node->y(inputs[1]); + + const auto *options = op.builtin_options.AsMulOptions(); + node->fusedActivationFunction(luci_actfunc(options->fused_activation_function)); + + return node; +} + +} // namespace luci diff --git a/compiler/luci/import/src/Nodes/CirclePack.cpp b/compiler/luci/import/src/Nodes/CirclePack.cpp new file mode 100644 index 00000000000..6ba6fae1125 --- /dev/null +++ b/compiler/luci/import/src/Nodes/CirclePack.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2020 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 "luci/Import/Nodes/CirclePack.h" + +#include + +#include +#include + +namespace luci +{ + +bool CirclePackGraphBuilder::validate(const ValidateArgs &args) const +{ + const auto &inputs = args.op.inputs; + const auto &outputs = args.op.outputs; + const auto *options = args.op.builtin_options.AsPackOptions(); + + if (options->values_count < 1) + return false; + + if (inputs.size() != static_cast(options->values_count)) + return false; + + if (outputs.size() != 1) + return false; + + return true; +} + +CircleNode *CirclePackGraphBuilder::build_node(const circle::OperatorT &op, + const std::vector &inputs, + loco::Graph *graph) const +{ + auto *node = graph->nodes()->create(inputs.size()); + for (uint32_t i = 0; i < inputs.size(); ++i) + { + node->values(i, inputs[i]); + } + + const auto *options = op.builtin_options.AsPackOptions(); + node->axis(options->axis); + + return node; +} + +} // namespace luci diff --git a/compiler/luci/import/src/Nodes/CirclePad.cpp b/compiler/luci/import/src/Nodes/CirclePad.cpp index eb6baf9bb3a..6abcf2d6cfc 100644 --- a/compiler/luci/import/src/Nodes/CirclePad.cpp +++ b/compiler/luci/import/src/Nodes/CirclePad.cpp @@ -15,42 +15,17 @@ */ #include "luci/Import/Nodes/CirclePad.h" -#include "luci/Import/Nodes/CircleConst.h" -#include "luci/Import/GraphBuilderContext.h" #include -#include #include -#include - -#include - -namespace -{ - -using namespace luci; - -class CirclePadGraphUpdate final : public GraphUpdate -{ -public: - CirclePadGraphUpdate(CirclePad *node) : _node(node) {} - - void update(GraphBuilderContext *) override; - -private: - CirclePad *_node; -}; - -} // namespace namespace luci { -bool CirclePadGraphBuilder::validate(const circle::Operator *op) const +bool CirclePadGraphBuilder::validate(const ValidateArgs &args) const { - const std::vector &inputs = as_index_vector(op->inputs()); - if (inputs.size() != 2) + if (args.op.inputs.size() != 2) return false; // TODO do attribute checks @@ -58,84 +33,18 @@ bool CirclePadGraphBuilder::validate(const circle::Operator *op) const return true; } -void CirclePadGraphBuilder::build(const circle::Operator *op, GraphBuilderContext *context) const +CircleNode *CirclePadGraphBuilder::build_node(const circle::OperatorT &op, + const std::vector &inputs, + loco::Graph *graph) const { - LOGGER(l); - - assert(context != nullptr); - - auto graph = context->graph(); - auto reader = context->reader(); - auto opfinder = context->opfinder(); - auto tensorfinder = context->tensorfinder(); - auto nodefinder = context->nodefinder(); - auto updates = context->updates(); - - // FlatBuffer contents - auto tensors = reader->tensors(); - - const std::vector &inputs = as_index_vector(op->inputs()); - const std::vector &outputs = as_index_vector(op->outputs()); + auto *node = graph->nodes()->create(); + node->input(inputs[0]); + node->paddings(inputs[1]); - // Pad node itself - auto pad_node = graph->nodes()->create(); - assert(outputs.size() > 0); - uint32_t output_ti = static_cast(outputs[0]); - auto output_tensor = tensors->Get(output_ti); + const auto *options = op.builtin_options.AsPadOptions(); + (void)options; // There are no options. - // name - auto tname = tensor_name(output_tensor); - pad_node->name(tname); - - // quantization - auto quantization = tensor_quantization(output_tensor); - if (quantization) - { - auto quantparam = luci_quantparam(quantization); - if (quantparam.get()) - pad_node->quantparam(std::move(quantparam)); - } - - opfinder->enroll(pad_node, op); - tensorfinder->enroll(pad_node, output_tensor); - for (auto output : outputs) - { - INFO(l) << "[luci] NodeFinder pad_node(" << output << ") -> " << pad_node << std::endl; - nodefinder->enroll(output, pad_node); - } - - // There's no options to read for Pad - - // paddings Const - uint32_t paddings_ti = static_cast(inputs[1]); - auto paddings_const = create_circleconst(context, paddings_ti); - pad_node->paddings(paddings_const); - - // Create GraphUpdate for graph connection for Pad node - auto update = stdex::make_unique(pad_node); - updates->enroll(std::move(update)); + return node; } } // namespace luci - -namespace -{ - -void CirclePadGraphUpdate::update(GraphBuilderContext *context) -{ - auto opfinder = context->opfinder(); - auto nodefinder = context->nodefinder(); - - auto op = opfinder->op(_node); - - // set input 'input, paddings' - const std::vector &inputs = luci::as_index_vector(op->inputs()); - uint32_t idx_input = static_cast(inputs[0]); - auto node_input = nodefinder->node(idx_input); - assert(node_input != nullptr); - _node->input(node_input); - // paddings CircleConst is created in build() and should not be null - assert(_node->paddings() != nullptr); -} - -} // namespace diff --git a/compiler/luci/import/src/Nodes/CircleRelu.cpp b/compiler/luci/import/src/Nodes/CircleRelu.cpp new file mode 100644 index 00000000000..056268a5b53 --- /dev/null +++ b/compiler/luci/import/src/Nodes/CircleRelu.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2020 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 "luci/Import/Nodes/CircleRelu.h" + +#include + +#include + +namespace luci +{ + +bool CircleReluGraphBuilder::validate(const ValidateArgs &args) const +{ + if (args.op.inputs.size() != 1) + return false; + + if (args.op.outputs.size() != 1) + return false; + + return true; +} + +CircleNode *CircleReluGraphBuilder::build_node(const circle::OperatorT &, + const std::vector &inputs, + loco::Graph *graph) const +{ + auto *node = graph->nodes()->create(); + node->features(inputs[0]); + + return node; +} + +} // namespace luci diff --git a/compiler/luci/import/src/Nodes/CircleReshape.cpp b/compiler/luci/import/src/Nodes/CircleReshape.cpp index e7e05f81399..c83f143a6a1 100644 --- a/compiler/luci/import/src/Nodes/CircleReshape.cpp +++ b/compiler/luci/import/src/Nodes/CircleReshape.cpp @@ -15,81 +15,68 @@ */ #include "luci/Import/Nodes/CircleReshape.h" -#include "luci/Import/GraphBuilderContext.h" +#include #include -#include -#include - -#include - namespace luci { -bool CircleReshapeGraphBuilder::validate(const circle::Operator *op) const +bool CircleReshapeGraphBuilder::validate(const ValidateArgs &args) const { - const auto &inputs = *op->inputs(); - const auto &outputs = *op->outputs(); - - if (inputs.size() != 1 && inputs.size() != 2) + if (args.op.inputs.size() != 1 && args.op.inputs.size() != 2) return false; - if (outputs.size() != 1) + if (args.op.outputs.size() != 1) return false; return true; } -void CircleReshapeGraphBuilder::build(const circle::Operator *op, - GraphBuilderContext *context) const +static void setup_shape_attribute(const std::vector &shape, CircleReshape *node) { - auto graph = context->graph(); - auto reader = context->reader(); - auto nodefinder = context->nodefinder(); - - auto tensors = reader->tensors(); - const auto &inputs = *op->inputs(); - const auto &outputs = *op->outputs(); - - assert(outputs.size() == 1); - const circle::Tensor *output_tensor = tensors->Get(outputs[0]); - - // Create the node. - auto reshape_node = graph->nodes()->create(); - reshape_node->name(tensor_name(output_tensor)); - - // Set node's quantization parameters, if any. - auto quantization = tensor_quantization(output_tensor); - if (quantization) + node->newShape()->rank(shape.size()); + for (uint32_t i = 0; i < shape.size(); ++i) { - auto quantparam = luci_quantparam(quantization); - if (quantparam) - reshape_node->quantparam(std::move(quantparam)); + node->newShape()->dim(i) = shape[i]; } +} - // Set node's inputs. There may be one or two, but the IR requires 2 atm. - assert(inputs.size() == 1 || inputs.size() == 2); - if (inputs.size() != 2) - throw oops::UserExn("Unsupported number of inputs", inputs.size()); +static CircleNode *create_shape_node(const std::vector &shape, loco::Graph *graph) +{ + auto *shape_node = graph->nodes()->create(); + shape_node->dtype(loco::DataType::S32); + shape_node->rank(1); + shape_node->dim(0) = shape.size(); + shape_node->size(shape.size()); + for (uint32_t i = 0; i < shape.size(); ++i) + { + shape_node->at(i) = shape[i]; + } + return shape_node; +} - CircleNode *tensor_node = nodefinder->node(inputs[0]); - assert(tensor_node != nullptr); - reshape_node->tensor(tensor_node); +CircleNode *CircleReshapeGraphBuilder::build_node(const circle::OperatorT &op, + const std::vector &inputs, + loco::Graph *graph) const +{ + // If the second input is not provided, generate it based on the value of the attribute. + // TODO Presence of the second input is the current requirement of the IR. + auto *shape_node = (inputs.size() == 2) ? inputs[1] : nullptr; + if (shape_node == nullptr) + { + const auto *options = op.builtin_options.AsReshapeOptions(); + shape_node = create_shape_node(options->new_shape, graph); + } - CircleNode *shape_node = nodefinder->node(inputs[1]); - assert(shape_node != nullptr); - reshape_node->shape(shape_node); + auto *node = graph->nodes()->create(); + node->tensor(inputs[0]); + node->shape(shape_node); - // Configure options. - const circle::ReshapeOptions *options = op->builtin_options_as_ReshapeOptions(); - const auto &new_shape = *options->new_shape(); - reshape_node->newShape()->rank(new_shape.size()); - for (uint32_t i = 0; i < new_shape.size(); ++i) - reshape_node->newShape()->dim(i) = new_shape[i]; + const auto *options = op.builtin_options.AsReshapeOptions(); + setup_shape_attribute(options->new_shape, node); - // Register node's only output. - nodefinder->enroll(outputs[0], reshape_node); + return node; } } // namespace luci diff --git a/compiler/luci/import/src/Nodes/CircleRsqrt.cpp b/compiler/luci/import/src/Nodes/CircleRsqrt.cpp new file mode 100644 index 00000000000..b5de0b5754a --- /dev/null +++ b/compiler/luci/import/src/Nodes/CircleRsqrt.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2020 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 "luci/Import/Nodes/CircleRsqrt.h" + +#include + +#include + +namespace luci +{ + +bool CircleRsqrtGraphBuilder::validate(const ValidateArgs &args) const +{ + const auto &inputs = args.op.inputs; + if (inputs.size() != 1) + return false; + + // Must be one of the following types + // bfloat16, half (float16), float32, float64, complex64, complex128 + // Currently, circle supports float16, float32, complex64 + const auto &tensors = args.reader.tensors(); + const auto &tensor = tensors.at(inputs[0]); + switch (tensor->type) + { + case circle::TensorType_FLOAT16: + case circle::TensorType_FLOAT32: + case circle::TensorType_COMPLEX64: + break; + default: + return false; + } + + return true; +} + +CircleNode *CircleRsqrtGraphBuilder::build_node(const circle::OperatorT &, + const std::vector &inputs, + loco::Graph *graph) const +{ + auto *node = graph->nodes()->create(); + node->x(inputs[0]); + + return node; +} + +} // namespace luci diff --git a/compiler/luci/import/src/Nodes/CircleSoftmax.cpp b/compiler/luci/import/src/Nodes/CircleSoftmax.cpp new file mode 100644 index 00000000000..0d316e18cbb --- /dev/null +++ b/compiler/luci/import/src/Nodes/CircleSoftmax.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2020 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 "luci/Import/Nodes/CircleSoftmax.h" + +#include + +#include + +namespace luci +{ + +bool CircleSoftmaxGraphBuilder::validate(const ValidateArgs &args) const +{ + if (args.op.inputs.size() != 1) + return false; + + // TODO do attribute checks + + return true; +} + +CircleNode *CircleSoftmaxGraphBuilder::build_node(const circle::OperatorT &op, + const std::vector &inputs, + loco::Graph *graph) const +{ + auto *node = graph->nodes()->create(); + node->logits(inputs[0]); + + const auto *options = op.builtin_options.AsSoftmaxOptions(); + node->beta(options->beta); + + return node; +} + +} // namespace luci diff --git a/compiler/luci/import/src/Nodes/CircleSub.cpp b/compiler/luci/import/src/Nodes/CircleSub.cpp new file mode 100644 index 00000000000..968e9f51f09 --- /dev/null +++ b/compiler/luci/import/src/Nodes/CircleSub.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2020 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 "luci/Import/Nodes/CircleSub.h" + +#include + +#include + +namespace luci +{ + +bool CircleSubGraphBuilder::validate(const ValidateArgs &args) const +{ + if (args.op.inputs.size() != 2) + return false; + + if (args.op.outputs.size() != 1) + return false; + + return true; +} + +CircleNode *CircleSubGraphBuilder::build_node(const circle::OperatorT &op, + const std::vector &inputs, + loco::Graph *graph) const +{ + auto *node = graph->nodes()->create(); + node->x(inputs[0]); + node->y(inputs[1]); + + const auto *options = op.builtin_options.AsSubOptions(); + node->fusedActivationFunction(luci_actfunc(options->fused_activation_function)); + + return node; +} + +} // namespace luci diff --git a/compiler/luci/import/src/Nodes/CircleTranspose.cpp b/compiler/luci/import/src/Nodes/CircleTranspose.cpp new file mode 100644 index 00000000000..8622c8b80aa --- /dev/null +++ b/compiler/luci/import/src/Nodes/CircleTranspose.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2020 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 "luci/Import/Nodes/CircleTranspose.h" + +#include + +#include + +namespace luci +{ + +bool CircleTransposeGraphBuilder::validate(const ValidateArgs &args) const +{ + if (args.op.inputs.size() != 2) + return false; + + if (args.op.outputs.size() != 1) + return false; + + return true; +} + +CircleNode *CircleTransposeGraphBuilder::build_node(const circle::OperatorT &op, + const std::vector &inputs, + loco::Graph *graph) const +{ + auto *node = graph->nodes()->create(); + node->a(inputs[0]); + node->perm(inputs[1]); + + const auto *options = op.builtin_options.AsTransposeOptions(); + (void)options; + + return node; +} + +} // namespace luci diff --git a/compiler/luci/lang/CMakeLists.txt b/compiler/luci/lang/CMakeLists.txt index 3c96a40bc10..564e777fbfc 100644 --- a/compiler/luci/lang/CMakeLists.txt +++ b/compiler/luci/lang/CMakeLists.txt @@ -6,9 +6,8 @@ add_library(luci_lang SHARED ${SOURCES}) target_include_directories(luci_lang PRIVATE src) target_include_directories(luci_lang PUBLIC include) target_link_libraries(luci_lang PUBLIC loco) +target_link_libraries(luci_lang PUBLIC oops) target_link_libraries(luci_lang PRIVATE nncc_common) -target_link_libraries(luci_lang PRIVATE stdex) -target_link_libraries(luci_lang PRIVATE oops) install(TARGETS luci_lang DESTINATION lib) diff --git a/compiler/luci/lang/include/luci/IR/AttrFusedActFunc.h b/compiler/luci/lang/include/luci/IR/AttrFusedActFunc.h index ab93b7fc527..2abae604be7 100644 --- a/compiler/luci/lang/include/luci/IR/AttrFusedActFunc.h +++ b/compiler/luci/lang/include/luci/IR/AttrFusedActFunc.h @@ -27,6 +27,7 @@ enum class FusedActFunc // prevent programming error. NONE, RELU, + RELU_N1_TO_1, RELU6 }; diff --git a/compiler/luci/lang/include/luci/IR/CircleNodeDecl.h b/compiler/luci/lang/include/luci/IR/CircleNodeDecl.h index 305c888d760..b87bdf9d0fc 100644 --- a/compiler/luci/lang/include/luci/IR/CircleNodeDecl.h +++ b/compiler/luci/lang/include/luci/IR/CircleNodeDecl.h @@ -44,7 +44,7 @@ struct CircleNode : public loco::Node NodeName name(void) const { return _name; } void name(const NodeName &name) { _name = name; } - CircleQuantParam *quantparam(void) { return _quantparam.get(); } + CircleQuantParam *quantparam(void) const { return _quantparam.get(); } void quantparam(std::unique_ptr &&quantparam) { _quantparam = std::move(quantparam); diff --git a/compiler/luci/lang/include/luci/IR/CircleNodes.h b/compiler/luci/lang/include/luci/IR/CircleNodes.h index b0996a37d2a..1118f899985 100644 --- a/compiler/luci/lang/include/luci/IR/CircleNodes.h +++ b/compiler/luci/lang/include/luci/IR/CircleNodes.h @@ -17,24 +17,31 @@ #ifndef __LUCI_IR_CIRCLENODES_H__ #define __LUCI_IR_CIRCLENODES_H__ +#include "Nodes/CircleAbs.h" #include "Nodes/CircleAdd.h" #include "Nodes/CircleArgMax.h" #include "Nodes/CircleAveragePool2D.h" #include "Nodes/CircleConcatenation.h" #include "Nodes/CircleConst.h" #include "Nodes/CircleConv2D.h" +#include "Nodes/CircleCos.h" #include "Nodes/CircleDepthwiseConv2D.h" #include "Nodes/CircleDiv.h" +#include "Nodes/CircleEqual.h" #include "Nodes/CircleFullyConnected.h" +#include "Nodes/CircleLogicalNot.h" +#include "Nodes/CircleLogicalOr.h" #include "Nodes/CircleMaximum.h" #include "Nodes/CircleMaxPool2D.h" #include "Nodes/CircleMean.h" #include "Nodes/CircleMul.h" +#include "Nodes/CirclePack.h" #include "Nodes/CirclePad.h" #include "Nodes/CircleRelu6.h" #include "Nodes/CircleRelu.h" #include "Nodes/CircleReshape.h" #include "Nodes/CircleRsqrt.h" +#include "Nodes/CircleSoftmax.h" #include "Nodes/CircleSqrt.h" #include "Nodes/CircleSquaredDifference.h" #include "Nodes/CircleSub.h" diff --git a/compiler/luci/lang/include/luci/IR/CircleNodes.lst b/compiler/luci/lang/include/luci/IR/CircleNodes.lst index 6ccf0890ce6..5fa766f822a 100644 --- a/compiler/luci/lang/include/luci/IR/CircleNodes.lst +++ b/compiler/luci/lang/include/luci/IR/CircleNodes.lst @@ -5,25 +5,37 @@ // // PLEASE SORT NODE DECLS IN ALPHABETICAL ORDER // +// Naming rule: Follow names in TensorFlow C++ source; same as TFDialect +// ex) for AvgPool, tensorflow/core/ops/nn_ops.cc +// REGISTER_OP("AvgPool") <-- OPCODE: AvgPool. Prefix `Circle` for CLASS name +// .Input("value: T") <-- Input name is 'value' +// + +CIRCLE_NODE(ABS, luci::CircleAbs) CIRCLE_NODE(ADD, luci::CircleAdd) CIRCLE_NODE(ARG_MAX, luci::CircleArgMax) CIRCLE_NODE(AVERAGE_POOL_2D, luci::CircleAveragePool2D) CIRCLE_NODE(CONCATENATION, luci::CircleConcatenation) CIRCLE_NODE(CONST, luci::CircleConst) CIRCLE_NODE(CONV_2D, luci::CircleConv2D) +CIRCLE_NODE(COS, luci::CircleCos) CIRCLE_NODE(DEPTHWISE_CONV_2D, luci::CircleDepthwiseConv2D) CIRCLE_NODE(DIV, luci::CircleDiv) +CIRCLE_NODE(EQUAL, luci::CircleEqual) CIRCLE_NODE(FULLY_CONNECTED, luci::CircleFullyConnected) +CIRCLE_NODE(LOGICAL_NOT, luci::CircleLogicalNot) +CIRCLE_NODE(LOGICAL_OR, luci::CircleLogicalOr) CIRCLE_NODE(MAXIMUM, luci::CircleMaximum) CIRCLE_NODE(MAX_POOL_2D, luci::CircleMaxPool2D) CIRCLE_NODE(MEAN, luci::CircleMean) CIRCLE_NODE(MUL, luci::CircleMul) +CIRCLE_NODE(PACK, luci::CirclePack) CIRCLE_NODE(PAD, luci::CirclePad) CIRCLE_NODE(RELU, luci::CircleRelu) CIRCLE_NODE(RELU6, luci::CircleRelu6) CIRCLE_NODE(RESHAPE, luci::CircleReshape) CIRCLE_NODE(RSQRT, luci::CircleRsqrt) -// TODO TFLSoftmax +CIRCLE_NODE(SOFTMAX, luci::CircleSoftmax) CIRCLE_NODE(SQRT, luci::CircleSqrt) CIRCLE_NODE(SQUARED_DIFFERENCE, luci::CircleSquaredDifference) CIRCLE_NODE(SUB, luci::CircleSub) diff --git a/compiler/luci/lang/include/luci/IR/CircleQuantParam.h b/compiler/luci/lang/include/luci/IR/CircleQuantParam.h index be688e42e3f..7253e657b75 100644 --- a/compiler/luci/lang/include/luci/IR/CircleQuantParam.h +++ b/compiler/luci/lang/include/luci/IR/CircleQuantParam.h @@ -17,6 +17,7 @@ #ifndef __LUCI_IR_CIRCLEQUANTPARAM_H__ #define __LUCI_IR_CIRCLEQUANTPARAM_H__ +#include #include namespace luci diff --git a/compiler/luci/lang/include/luci/IR/LuciNodeMixins.h b/compiler/luci/lang/include/luci/IR/LuciNodeMixins.h index 656bba8e30a..b18ac5dc4be 100644 --- a/compiler/luci/lang/include/luci/IR/LuciNodeMixins.h +++ b/compiler/luci/lang/include/luci/IR/LuciNodeMixins.h @@ -72,7 +72,7 @@ template class FixedArityNode : public Base { for (uint32_t n = 0; n < N; ++n) { - _args[n] = std::unique_ptr(new loco::Use{this}); + _args[n] = std::make_unique(this); } } diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleAbs.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleAbs.h new file mode 100644 index 00000000000..45dba15bf45 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleAbs.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2020 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 __LUCI_IR_CIRCELABS_H__ +#define __LUCI_IR_CIRCELABS_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief ABS in Circle + */ +class CircleAbs final : public FixedArityNode<1, CircleNodeImpl> +{ +public: + loco::Node *x(void) const { return at(0)->node(); } + void x(loco::Node *node) { at(0)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCELABS_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleConcatenation.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleConcatenation.h index 55beaf67ce9..8a6778a2f15 100644 --- a/compiler/luci/lang/include/luci/IR/Nodes/CircleConcatenation.h +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleConcatenation.h @@ -60,11 +60,11 @@ class CircleConcatenation final } public: - uint32_t axis(void) const { return _axis; } - void axis(uint32_t axis) { _axis = axis; } + int32_t axis(void) const { return _axis; } + void axis(int32_t axis) { _axis = axis; } private: - uint32_t _axis; + int32_t _axis; }; } // namespace luci diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleCos.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleCos.h new file mode 100644 index 00000000000..07ced620a0b --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleCos.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2020 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 __LUCI_IR_CIRCLE_COS_H__ +#define __LUCI_IR_CIRCLE_COS_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief COS in Circle + */ +class CircleCos final : public FixedArityNode<1, CircleNodeImpl> +{ +public: + loco::Node *x(void) const { return at(0)->node(); } + void x(loco::Node *node) { at(0)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_COS_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleEqual.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleEqual.h new file mode 100644 index 00000000000..2087d097ade --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleEqual.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2020 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 __LUCI_IR_CIRCLE_EQUAL_H__ +#define __LUCI_IR_CIRCLE_EQUAL_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief EQUAL in Circle + */ +class CircleEqual final : public FixedArityNode<2, CircleNodeImpl> +{ +public: + loco::Node *x(void) const { return at(0)->node(); } + void x(loco::Node *node) { at(0)->node(node); } + + loco::Node *y(void) const { return at(1)->node(); } + void y(loco::Node *node) { at(1)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_EQUAL_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleInput.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleInput.h index c5ae0fc4991..2c4d602533e 100644 --- a/compiler/luci/lang/include/luci/IR/Nodes/CircleInput.h +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleInput.h @@ -46,10 +46,6 @@ class CircleInput final : public FixedArityNode<0, CircleNodeImpl uint32_t size(void) const; - template void size(uint32_t size); - private: int64_t _index = -1; // Uninitialized }; diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleLogicalNot.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleLogicalNot.h new file mode 100644 index 00000000000..749dbe51835 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleLogicalNot.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2020 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 __LUCI_IR_CIRCLE_LOGICALNOT_H__ +#define __LUCI_IR_CIRCLE_LOGICALNOT_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief LOGICAL_NOT in Circle + */ +class CircleLogicalNot final : public FixedArityNode<1, CircleNodeImpl> +{ +public: + loco::Node *x(void) const { return at(0)->node(); } + void x(loco::Node *node) { at(0)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_LOGICALNOT_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleLogicalOr.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleLogicalOr.h new file mode 100644 index 00000000000..570be57afdf --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleLogicalOr.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2020 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 __LUCI_IR_CIRCLE_LOGICALOR_H__ +#define __LUCI_IR_CIRCLE_LOGICALOR_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief LOGICAL_OR in Circle + */ +class CircleLogicalOr final : public FixedArityNode<2, CircleNodeImpl> +{ +public: + loco::Node *x(void) const { return at(0)->node(); } + void x(loco::Node *node) { at(0)->node(node); } + + loco::Node *y(void) const { return at(1)->node(); } + void y(loco::Node *node) { at(1)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_LOGICALOR_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CirclePack.h b/compiler/luci/lang/include/luci/IR/Nodes/CirclePack.h new file mode 100644 index 00000000000..1c18c1333cf --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CirclePack.h @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2020 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 __LUCI_IR_CIRCLEPACK_H__ +#define __LUCI_IR_CIRCLEPACK_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/VariadicArityNode.h" + +#include + +namespace luci +{ + +/** + * @brief PACK in Circle + */ +class CirclePack final : public VariadicArityNode> +{ +public: + CirclePack(uint32_t arity) : VariadicArityNode>(arity) + { + // TODO Support when arity is 0 + assert(arity >= 1); + } + +public: + uint32_t values_count(void) const { return arity(); } + +public: + Node *values(uint32_t index) const + { + assert(index < values_count()); + return at(index)->node(); + } + void values(uint32_t index, Node *node) + { + assert(index < values_count()); + at(index)->node(node); + } + +public: + int32_t axis(void) const { return _axis; } + void axis(int32_t axis) { _axis = axis; } + +private: + int32_t _axis; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLEPACK_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleSoftmax.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleSoftmax.h new file mode 100644 index 00000000000..4ea3c4b0ec2 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleSoftmax.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2020 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 __LUCI_IR_CIRCLESOFTMAX_H__ +#define __LUCI_IR_CIRCLESOFTMAX_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief SOFTMAX in Circle + */ +class CircleSoftmax final : public FixedArityNode<1, CircleNodeImpl> +{ +public: + loco::Node *logits(void) const { return at(0)->node(); } + void logits(loco::Node *node) { at(0)->node(node); } + +public: + float beta(void) const { return _beta; } + void beta(float beta) { _beta = beta; } + +private: + float _beta; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLESOFTMAX_H__ diff --git a/compiler/luci/lang/include/luci/IR/VariadicArityNode.h b/compiler/luci/lang/include/luci/IR/VariadicArityNode.h index 474c188ad6b..a4814ee489d 100644 --- a/compiler/luci/lang/include/luci/IR/VariadicArityNode.h +++ b/compiler/luci/lang/include/luci/IR/VariadicArityNode.h @@ -37,7 +37,7 @@ template class VariadicArityNode : public Base { for (uint32_t n = 0; n < arity; ++n) { - _args.emplace_back(std::move(std::unique_ptr{new loco::Use{this}})); + _args.push_back(std::make_unique(this)); } }; diff --git a/compiler/luci/lang/src/CircleDialect.cpp b/compiler/luci/lang/src/CircleDialect.cpp index a90a48689a2..e1c925de4e2 100644 --- a/compiler/luci/lang/src/CircleDialect.cpp +++ b/compiler/luci/lang/src/CircleDialect.cpp @@ -22,9 +22,8 @@ #include #include -#include - #include +#include namespace { @@ -76,8 +75,8 @@ namespace luci CircleDialect::CircleDialect() { - service(stdex::make_unique()); - service(stdex::make_unique()); + service(std::make_unique()); + service(std::make_unique()); } loco::Dialect *CircleDialect::get(void) diff --git a/compiler/luci/lang/src/Nodes/CircleAbs.test.cpp b/compiler/luci/lang/src/Nodes/CircleAbs.test.cpp new file mode 100644 index 00000000000..847f1500b5d --- /dev/null +++ b/compiler/luci/lang/src/Nodes/CircleAbs.test.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 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 "luci/IR/Nodes/CircleAbs.h" + +#include "luci/IR/CircleDialect.h" + +#include + +TEST(CircleAbsTest, constructor) +{ + luci::CircleAbs abs_node; + + ASSERT_EQ(abs_node.dialect(), luci::CircleDialect::get()); + ASSERT_EQ(abs_node.opcode(), luci::CircleOpcode::ABS); + + ASSERT_EQ(abs_node.x(), nullptr); +} diff --git a/compiler/luci/lang/src/Nodes/CircleCos.test.cpp b/compiler/luci/lang/src/Nodes/CircleCos.test.cpp new file mode 100644 index 00000000000..34c2cfdf0f7 --- /dev/null +++ b/compiler/luci/lang/src/Nodes/CircleCos.test.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 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 "luci/IR/Nodes/CircleCos.h" + +#include "luci/IR/CircleDialect.h" + +#include + +TEST(CircleCosTest, constructor_P) +{ + luci::CircleCos cos_node; + + ASSERT_EQ(cos_node.dialect(), luci::CircleDialect::get()); + ASSERT_EQ(cos_node.opcode(), luci::CircleOpcode::COS); + + ASSERT_EQ(cos_node.x(), nullptr); +} diff --git a/compiler/luci/lang/src/Nodes/CircleEqual.test.cpp b/compiler/luci/lang/src/Nodes/CircleEqual.test.cpp new file mode 100644 index 00000000000..e2757f09495 --- /dev/null +++ b/compiler/luci/lang/src/Nodes/CircleEqual.test.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2020 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 "luci/IR/Nodes/CircleEqual.h" + +#include "luci/IR/CircleDialect.h" + +#include + +TEST(CircleEqualTest, constructor_P) +{ + luci::CircleEqual or_node; + + ASSERT_EQ(or_node.dialect(), luci::CircleDialect::get()); + ASSERT_EQ(or_node.opcode(), luci::CircleOpcode::EQUAL); + + ASSERT_EQ(or_node.x(), nullptr); + ASSERT_EQ(or_node.y(), nullptr); +} diff --git a/compiler/luci/lang/src/Nodes/CircleFullyConnected.test.cpp b/compiler/luci/lang/src/Nodes/CircleFullyConnected.test.cpp new file mode 100644 index 00000000000..994dcd2391c --- /dev/null +++ b/compiler/luci/lang/src/Nodes/CircleFullyConnected.test.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2020 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 "luci/IR/Nodes/CircleFullyConnected.h" + +#include "luci/IR/CircleDialect.h" + +#include + +TEST(CircleFullyConnectedTest, constructor) +{ + luci::CircleFullyConnected fc_node; + + ASSERT_EQ(fc_node.dialect(), luci::CircleDialect::get()); + ASSERT_EQ(fc_node.opcode(), luci::CircleOpcode::FULLY_CONNECTED); + + ASSERT_EQ(fc_node.input(), nullptr); + ASSERT_EQ(fc_node.weights(), nullptr); + ASSERT_EQ(fc_node.bias(), nullptr); + ASSERT_EQ(fc_node.fusedActivationFunction(), luci::FusedActFunc::UNDEFINED); +} diff --git a/compiler/luci/lang/src/Nodes/CircleLogicalNot.test.cpp b/compiler/luci/lang/src/Nodes/CircleLogicalNot.test.cpp new file mode 100644 index 00000000000..360dd471193 --- /dev/null +++ b/compiler/luci/lang/src/Nodes/CircleLogicalNot.test.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 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 "luci/IR/Nodes/CircleLogicalNot.h" + +#include "luci/IR/CircleDialect.h" + +#include + +TEST(CircleLogicalNotTest, constructor_P) +{ + luci::CircleLogicalNot not_node; + + ASSERT_EQ(not_node.dialect(), luci::CircleDialect::get()); + ASSERT_EQ(not_node.opcode(), luci::CircleOpcode::LOGICAL_NOT); + + ASSERT_EQ(not_node.x(), nullptr); +} diff --git a/compiler/luci/lang/src/Nodes/CircleLogicalOr.test.cpp b/compiler/luci/lang/src/Nodes/CircleLogicalOr.test.cpp new file mode 100644 index 00000000000..039db4afc93 --- /dev/null +++ b/compiler/luci/lang/src/Nodes/CircleLogicalOr.test.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2020 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 "luci/IR/Nodes/CircleLogicalOr.h" + +#include "luci/IR/CircleDialect.h" + +#include + +TEST(CircleLogicalOrTest, constructor_P) +{ + luci::CircleLogicalOr or_node; + + ASSERT_EQ(or_node.dialect(), luci::CircleDialect::get()); + ASSERT_EQ(or_node.opcode(), luci::CircleOpcode::LOGICAL_OR); + + ASSERT_EQ(or_node.x(), nullptr); + ASSERT_EQ(or_node.y(), nullptr); +} diff --git a/compiler/luci/lang/src/Nodes/CirclePack.test.cpp b/compiler/luci/lang/src/Nodes/CirclePack.test.cpp new file mode 100644 index 00000000000..b38eebfcea4 --- /dev/null +++ b/compiler/luci/lang/src/Nodes/CirclePack.test.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2020 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 "luci/IR/Nodes/CirclePack.h" + +#include "luci/IR/CircleDialect.h" + +#include + +TEST(CirclePackTest, constructor) +{ + luci::CirclePack pack_node(3); + + ASSERT_EQ(pack_node.dialect(), luci::CircleDialect::get()); + ASSERT_EQ(pack_node.opcode(), luci::CircleOpcode::PACK); + + ASSERT_EQ(pack_node.values_count(), 3); + ASSERT_EQ(pack_node.values(0), nullptr); + ASSERT_EQ(pack_node.values(1), nullptr); + ASSERT_EQ(pack_node.values(2), nullptr); +} diff --git a/compiler/luci/lang/src/Nodes/CircleSoftmax.test.cpp b/compiler/luci/lang/src/Nodes/CircleSoftmax.test.cpp new file mode 100644 index 00000000000..7e994490c5b --- /dev/null +++ b/compiler/luci/lang/src/Nodes/CircleSoftmax.test.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 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 "luci/IR/Nodes/CircleSoftmax.h" + +#include "luci/IR/CircleDialect.h" + +#include + +TEST(CircleSoftmaxTest, constructor_P) +{ + luci::CircleSoftmax softmax_node; + + ASSERT_EQ(softmax_node.dialect(), luci::CircleDialect::get()); + ASSERT_EQ(softmax_node.opcode(), luci::CircleOpcode::SOFTMAX); + + ASSERT_EQ(softmax_node.logits(), nullptr); +} diff --git a/compiler/luci/log/CMakeLists.txt b/compiler/luci/log/CMakeLists.txt index 23fed1cf198..af2e7a76822 100644 --- a/compiler/luci/log/CMakeLists.txt +++ b/compiler/luci/log/CMakeLists.txt @@ -5,6 +5,5 @@ add_library(luci_log SHARED ${SOURCES}) target_include_directories(luci_log PUBLIC include) target_link_libraries(luci_log PUBLIC hermes) target_link_libraries(luci_log PRIVATE hermes_std) -target_link_libraries(luci_log PRIVATE stdex) target_link_libraries(luci_log PRIVATE nncc_common) install(TARGETS luci_log DESTINATION lib) diff --git a/compiler/luci/log/src/LoggingContext.cpp b/compiler/luci/log/src/LoggingContext.cpp index ed091195d19..8d7997869b8 100644 --- a/compiler/luci/log/src/LoggingContext.cpp +++ b/compiler/luci/log/src/LoggingContext.cpp @@ -18,7 +18,8 @@ #include "luci/Log.h" #include -#include + +#include namespace luci { @@ -30,8 +31,8 @@ hermes::Context *LoggingContext::get(void) if (ctx == nullptr) { ctx = new hermes::Context; - ctx->sinks()->append(stdex::make_unique()); - ctx->config(stdex::make_unique()); + ctx->sinks()->append(std::make_unique()); + ctx->config(std::make_unique()); } return ctx; diff --git a/compiler/luci/logex/CMakeLists.txt b/compiler/luci/logex/CMakeLists.txt index a5f7e771f34..fa2ea123c86 100644 --- a/compiler/luci/logex/CMakeLists.txt +++ b/compiler/luci/logex/CMakeLists.txt @@ -8,7 +8,6 @@ target_link_libraries(luci_logex PUBLIC locop) target_link_libraries(luci_logex PRIVATE luci_log) target_link_libraries(luci_logex PRIVATE luci_lang) target_link_libraries(luci_logex PRIVATE hermes_std) -target_link_libraries(luci_logex PRIVATE stdex) target_link_libraries(luci_logex PRIVATE nncc_common) target_link_libraries(luci_logex PRIVATE pepper_str) install(TARGETS luci_logex DESTINATION lib) diff --git a/compiler/luci/logex/src/FormattedGraph.h b/compiler/luci/logex/include/luci/FormattedGraph.h similarity index 94% rename from compiler/luci/logex/src/FormattedGraph.h rename to compiler/luci/logex/include/luci/FormattedGraph.h index c340f86403a..da4af3bfaa4 100644 --- a/compiler/luci/logex/src/FormattedGraph.h +++ b/compiler/luci/logex/include/luci/FormattedGraph.h @@ -19,7 +19,7 @@ #include -#include +#include namespace luci { @@ -47,7 +47,7 @@ class NodeSummaryBuilderFactory final : public locop::NodeSummaryBuilderFactory public: std::unique_ptr create(const locop::SymbolTable *tlb) const final { - return stdex::make_unique(tlb); + return std::make_unique(tlb); } }; diff --git a/compiler/luci/logex/src/FormattedGraph.cpp b/compiler/luci/logex/src/FormattedGraph.cpp index d954438e4de..63e0129a42b 100644 --- a/compiler/luci/logex/src/FormattedGraph.cpp +++ b/compiler/luci/logex/src/FormattedGraph.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "FormattedGraph.h" +#include "luci/FormattedGraph.h" #include #include @@ -70,6 +70,9 @@ const char *to_str(loco::DataType type) case loco::DataType::FLOAT64: return "FLOAT64"; + case loco::DataType::BOOL: + return "BOOL"; + default: return "Error"; } @@ -83,6 +86,8 @@ const char *to_str(luci::FusedActFunc fused) return "NONE"; case luci::FusedActFunc::RELU: return "RELU"; + case luci::FusedActFunc::RELU_N1_TO_1: + return "RELU_N1_TO_1"; case luci::FusedActFunc::RELU6: return "RELU6"; default: @@ -173,23 +178,30 @@ class CircleNodeSummaryBuilder final : public CircleNodeSummaryBuilderBase private: #define IMPLEMENT(CLASS) bool summary(const CLASS *, locop::NodeSummary &) const final; + IMPLEMENT(luci::CircleAbs) IMPLEMENT(luci::CircleAdd) IMPLEMENT(luci::CircleArgMax) IMPLEMENT(luci::CircleAveragePool2D) IMPLEMENT(luci::CircleConcatenation) IMPLEMENT(luci::CircleConst) IMPLEMENT(luci::CircleConv2D) + IMPLEMENT(luci::CircleCos) IMPLEMENT(luci::CircleDepthwiseConv2D) IMPLEMENT(luci::CircleDiv) + IMPLEMENT(luci::CircleFullyConnected) + IMPLEMENT(luci::CircleLogicalNot) + IMPLEMENT(luci::CircleLogicalOr) IMPLEMENT(luci::CircleMaximum) IMPLEMENT(luci::CircleMaxPool2D) IMPLEMENT(luci::CircleMean) IMPLEMENT(luci::CircleMul) + IMPLEMENT(luci::CirclePack) IMPLEMENT(luci::CirclePad) IMPLEMENT(luci::CircleRelu) IMPLEMENT(luci::CircleRelu6) IMPLEMENT(luci::CircleReshape) IMPLEMENT(luci::CircleRsqrt) + IMPLEMENT(luci::CircleSoftmax) IMPLEMENT(luci::CircleSqrt) IMPLEMENT(luci::CircleSquaredDifference) IMPLEMENT(luci::CircleSub) @@ -220,6 +232,13 @@ bool CircleNodeSummaryBuilderBase::build(const loco::Node *node, locop::NodeSumm return false; } +bool CircleNodeSummaryBuilder::summary(const luci::CircleAbs *node, locop::NodeSummary &s) const +{ + s.args().append("x", tbl()->lookup(node->x())); + s.state(locop::NodeSummary::State::Complete); + return true; +} + bool CircleNodeSummaryBuilder::summary(const luci::CircleAdd *node, locop::NodeSummary &s) const { assert(node->fusedActivationFunction() != luci::FusedActFunc::UNDEFINED); @@ -293,6 +312,13 @@ bool CircleNodeSummaryBuilder::summary(const luci::CircleConv2D *node, locop::No return true; } +bool CircleNodeSummaryBuilder::summary(const luci::CircleCos *node, locop::NodeSummary &s) const +{ + s.args().append("x", tbl()->lookup(node->x())); + s.state(locop::NodeSummary::State::Complete); + return true; +} + bool CircleNodeSummaryBuilder::summary(const luci::CircleDepthwiseConv2D *node, locop::NodeSummary &s) const { @@ -321,6 +347,38 @@ bool CircleNodeSummaryBuilder::summary(const luci::CircleDiv *node, locop::NodeS return true; } +bool CircleNodeSummaryBuilder::summary(const luci::CircleFullyConnected *node, + locop::NodeSummary &s) const +{ + assert(node->fusedActivationFunction() != luci::FusedActFunc::UNDEFINED); + + s.args().append("input", tbl()->lookup(node->input())); + s.args().append("weights", tbl()->lookup(node->weights())); + s.args().append("bias", tbl()->lookup(node->bias())); + s.args().append("fused", to_str(node->fusedActivationFunction())); + + s.state(locop::NodeSummary::State::Complete); + + return true; +} + +bool CircleNodeSummaryBuilder::summary(const luci::CircleLogicalNot *node, + locop::NodeSummary &s) const +{ + s.args().append("x", tbl()->lookup(node->x())); + s.state(locop::NodeSummary::State::Complete); + return true; +} + +bool CircleNodeSummaryBuilder::summary(const luci::CircleLogicalOr *node, + locop::NodeSummary &s) const +{ + s.args().append("x", tbl()->lookup(node->x())); + s.args().append("y", tbl()->lookup(node->y())); + s.state(locop::NodeSummary::State::Complete); + return true; +} + bool CircleNodeSummaryBuilder::summary(const luci::CircleMaximum *node, locop::NodeSummary &s) const { s.args().append("x", tbl()->lookup(node->x())); @@ -365,6 +423,16 @@ bool CircleNodeSummaryBuilder::summary(const luci::CircleMul *node, locop::NodeS return true; } +bool CircleNodeSummaryBuilder::summary(const luci::CirclePack *node, locop::NodeSummary &s) const +{ + for (uint32_t i = 0; i < node->values_count(); ++i) + s.args().append("values", tbl()->lookup(node->values(i))); + s.args().append("values_count", pepper::str(node->values_count())); + s.args().append("axis", pepper::str(node->axis())); + s.state(locop::NodeSummary::State::Complete); + return true; +} + bool CircleNodeSummaryBuilder::summary(const luci::CirclePad *node, locop::NodeSummary &s) const { s.args().append("input", tbl()->lookup(node->input())); @@ -403,7 +471,13 @@ bool CircleNodeSummaryBuilder::summary(const luci::CircleRsqrt *node, locop::Nod return true; } -// TODO TFLSoftmax +bool CircleNodeSummaryBuilder::summary(const luci::CircleSoftmax *node, locop::NodeSummary &s) const +{ + s.args().append("logits", tbl()->lookup(node->logits())); + s.args().append("beta", pepper::str(node->beta())); + s.state(locop::NodeSummary::State::Complete); + return true; +} bool CircleNodeSummaryBuilder::summary(const luci::CircleSqrt *node, locop::NodeSummary &s) const { diff --git a/compiler/luci/logex/src/LogHelper.cpp b/compiler/luci/logex/src/LogHelper.cpp index fe7970a1d4d..caf6599062b 100644 --- a/compiler/luci/logex/src/LogHelper.cpp +++ b/compiler/luci/logex/src/LogHelper.cpp @@ -15,14 +15,14 @@ */ #include "luci/LogHelper.h" -#include "FormattedGraph.h" +#include "luci/FormattedGraph.h" namespace luci { FormattedGraph fmt(loco::Graph *g) { - auto node_summary_builder = stdex::make_unique(); + auto node_summary_builder = std::make_unique(); return std::move(locop::fmt(g).with(std::move(node_summary_builder))); } diff --git a/compiler/luci/pass/CMakeLists.txt b/compiler/luci/pass/CMakeLists.txt index c349a17839c..93130ce60cd 100644 --- a/compiler/luci/pass/CMakeLists.txt +++ b/compiler/luci/pass/CMakeLists.txt @@ -5,12 +5,13 @@ file(GLOB_RECURSE SOURCES "src/*.cpp") add_library(luci_pass SHARED ${SOURCES}) target_include_directories(luci_pass PRIVATE src) target_include_directories(luci_pass PUBLIC include) -target_link_libraries(luci_pass PUBLIC luci_lang) -target_link_libraries(luci_pass PUBLIC luci_service) -target_link_libraries(luci_pass PUBLIC mio_tflite) -target_link_libraries(luci_pass PUBLIC stdex) +target_link_libraries(luci_pass PUBLIC loco) target_link_libraries(luci_pass PUBLIC logo_core) +target_link_libraries(luci_pass PRIVATE logo) +target_link_libraries(luci_pass PRIVATE luci_lang) target_link_libraries(luci_pass PRIVATE luci_log) +target_link_libraries(luci_pass PRIVATE luci_service) +target_link_libraries(luci_pass PRIVATE luci_logex) target_link_libraries(luci_pass PRIVATE nncc_common) target_link_libraries(luci_pass PRIVATE oops) install(TARGETS luci_pass DESTINATION lib) diff --git a/compiler/luci/pass/include/luci/CircleOptimizer.h b/compiler/luci/pass/include/luci/CircleOptimizer.h new file mode 100644 index 00000000000..a969cca8547 --- /dev/null +++ b/compiler/luci/pass/include/luci/CircleOptimizer.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2020 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 __LUCI_CIRCLE_OPTIMIZER_H__ +#define __LUCI_CIRCLE_OPTIMIZER_H__ + +#include + +#include +#include + +namespace luci +{ + +class CircleOptimizer final +{ +public: + struct Options + { + enum Algorithm + { + FuseInstanceNorm, + }; + + virtual void enable(Algorithm) = 0; + virtual bool query(Algorithm) = 0; + }; + +public: + // TODO maybe caller can provide Options as ctor parameters + Options *options(void); + +public: + void optimize(loco::Graph *) const; + +private: + std::unique_ptr _options; +}; + +} // namespace luci + +#endif // __LUCI_CIRCLE_OPTIMIZER_H__ diff --git a/compiler/luci/pass/src/CircleOptimizer.cpp b/compiler/luci/pass/src/CircleOptimizer.cpp new file mode 100644 index 00000000000..dcb05a0b5d5 --- /dev/null +++ b/compiler/luci/pass/src/CircleOptimizer.cpp @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2020 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 "luci/CircleOptimizer.h" + +#include "luci/Pass/FuseInstanceNormPass.h" +// TODO add more passes + +#include "luci/Pass/ShapeInferencePass.h" +#include "luci/Pass/TypeInferencePass.h" + +// logo passes +#include + +#include "ProgressReporter.h" + +#include + +#include + +namespace +{ + +using namespace luci; + +class OptimizeOptionsImpl : public luci::CircleOptimizer::Options +{ +public: + void enable(Algorithm) final; + bool query(Algorithm) final; + +private: + std::vector _algorithms; +}; + +void OptimizeOptionsImpl::enable(Algorithm algo) { _algorithms.push_back(algo); } + +bool OptimizeOptionsImpl::query(Algorithm algo) +{ + std::vector::iterator it = std::find(_algorithms.begin(), _algorithms.end(), algo); + if (it == _algorithms.end()) + return false; + + return true; +} + +} // namespace + +namespace luci +{ + +CircleOptimizer::Options *CircleOptimizer::options(void) +{ + if (_options == nullptr) + { + _options = std::make_unique(); + } + + return _options.get(); +} + +void CircleOptimizer::optimize(loco::Graph *g) const +{ + logo::Phase phase; + + /* TRANSFORM DECLARATION BEGIN */ + if (_options->query(Options::Algorithm::FuseInstanceNorm)) + { + phase.emplace_back(std::make_unique()); + } + // Shape inference is needed for added nodes doing above transformations + phase.emplace_back(std::make_unique()); + phase.emplace_back(std::make_unique()); + phase.emplace_back(std::make_unique()); + /* TRANSFORM DECLARATION END */ + + ProgressReporter prog(g, logo::PhaseStrategy::Saturate); + logo::PhaseRunner phase_runner{g}; + phase_runner.attach(&prog); + phase_runner.run(phase); +} + +} // namespace luci diff --git a/compiler/luci/pass/src/ProgressReporter.cpp b/compiler/luci/pass/src/ProgressReporter.cpp new file mode 100644 index 00000000000..dcf47aba69c --- /dev/null +++ b/compiler/luci/pass/src/ProgressReporter.cpp @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2020 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 "ProgressReporter.h" + +#include +#include + +#include +#include + +#include + +namespace +{ + +char to_char(bool b) { return b ? 'Y' : 'N'; } + +const char *to_str(logo::PhaseStrategy s) +{ + switch (s) + { + case logo::PhaseStrategy::Saturate: + return "Saturate"; + case logo::PhaseStrategy::Restart: + return "Restart"; + } + assert(false); + return ""; +} + +} // namespace + +namespace luci +{ + +void ProgressReporter::notify(const logo::PhaseEventInfo *) +{ + LOGGER(prime); + + INFO(prime) << "=============================================================="; + INFO(prime) << "PhaseRunner<" << to_str(strategy()) << ">"; + INFO(prime) << "Initial graph"; + INFO(prime) << luci::fmt(graph()); +} + +void ProgressReporter::notify(const logo::PhaseEventInfo *) +{ + LOGGER(prime); + + INFO(prime) << "PhaseRunner<" << to_str(strategy()) << "> - done"; +} + +void ProgressReporter::notify(const logo::PhaseEventInfo *info) +{ + LOGGER(prime); + + INFO(prime) << "--------------------------------------------------------------"; + INFO(prime) << "Before " << logo::pass_name(info->pass()); +} + +void ProgressReporter::notify(const logo::PhaseEventInfo *info) +{ + LOGGER(prime); + + INFO(prime) << "After " << logo::pass_name(info->pass()) + << " (changed: " << to_char(info->changed()) << ")"; + INFO(prime) << luci::fmt(graph()); +} + +} // namespace luci diff --git a/compiler/luci/pass/src/ProgressReporter.h b/compiler/luci/pass/src/ProgressReporter.h new file mode 100644 index 00000000000..bd2ba984958 --- /dev/null +++ b/compiler/luci/pass/src/ProgressReporter.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2020 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 __LUCI_PROGRESSREPORTER_H__ +#define __LUCI_PROGRESSREPORTER_H__ + +#include + +#include + +namespace luci +{ + +class ProgressReporter : public logo::PhaseEventListener +{ +public: + ProgressReporter(loco::Graph *graph, logo::PhaseStrategy strategy) + : _graph{graph}, _strategy{strategy} + { + // DO NOTHING + } + +public: + void notify(const logo::PhaseEventInfo *) override; + void notify(const logo::PhaseEventInfo *) override; + void notify(const logo::PhaseEventInfo *) override; + void notify(const logo::PhaseEventInfo *) override; + +public: + loco::Graph *graph(void) const { return _graph; } + logo::PhaseStrategy strategy(void) const { return _strategy; } + +private: + loco::Graph *_graph; + logo::PhaseStrategy _strategy; +}; + +} // namespace luci + +#endif // __LUCI_PROGRESSREPORTER_H__ diff --git a/compiler/luci/requires.cmake b/compiler/luci/requires.cmake index e878c8036a8..e88dabd24bd 100644 --- a/compiler/luci/requires.cmake +++ b/compiler/luci/requires.cmake @@ -1,7 +1,6 @@ require("loco") require("locop") require("logo-core") -require("stdex") require("mio-circle") require("oops") require("hermes") diff --git a/compiler/luci/service/CMakeLists.txt b/compiler/luci/service/CMakeLists.txt index 2c7b9f358d9..9f50c9c4f5d 100644 --- a/compiler/luci/service/CMakeLists.txt +++ b/compiler/luci/service/CMakeLists.txt @@ -7,7 +7,6 @@ target_include_directories(luci_service PRIVATE src) target_include_directories(luci_service PUBLIC include) target_link_libraries(luci_service PUBLIC luci_lang) target_link_libraries(luci_service PUBLIC mio_circle) -target_link_libraries(luci_service PUBLIC stdex) target_link_libraries(luci_service PUBLIC logo_core) target_link_libraries(luci_service PRIVATE luci_log) target_link_libraries(luci_service PRIVATE nncc_common) diff --git a/compiler/luci/service/src/CircleShapeInferenceRule.cpp b/compiler/luci/service/src/CircleShapeInferenceRule.cpp index 4742771e3ed..096e76c12de 100644 --- a/compiler/luci/service/src/CircleShapeInferenceRule.cpp +++ b/compiler/luci/service/src/CircleShapeInferenceRule.cpp @@ -184,6 +184,12 @@ loco::TensorShape broadcast_shape(const loco::TensorShape &x, const loco::Tensor class ShapeInferenceAlgorithm final : public luci::CircleNodeVisitor { public: + loco::NodeShape visit(const luci::CircleAbs *node) final + { + auto x_shape = loco::shape_get(node->x()).as(); + return loco::NodeShape{x_shape}; + } + loco::NodeShape visit(const luci::CircleAdd *node) final { auto x_shape = loco::shape_get(node->x()).as(); @@ -244,8 +250,13 @@ class ShapeInferenceAlgorithm final : public luci::CircleNodeVisitornumValues() > 0); - auto axis = node->axis(); auto first_shape = loco::shape_get(node->values(0)).as(); + auto axis = node->axis(); + if (axis < 0) + axis += first_shape.rank(); + + assert(0 <= axis); + assert(first_shape.rank() > static_cast(axis)); loco::TensorShape output_shape; @@ -259,7 +270,7 @@ class ShapeInferenceAlgorithm final : public luci::CircleNodeVisitor(axis)) output_shape.dim(j) = output_shape.dim(j).value() + input_shape.dim(j).value(); else assert(output_shape.dim(j) == input_shape.dim(j)); @@ -331,6 +342,13 @@ class ShapeInferenceAlgorithm final : public luci::CircleNodeVisitorx()).as(); + + return loco::NodeShape{x_shape}; + } + loco::NodeShape visit(const luci::CircleDepthwiseConv2D *node) final { auto ifm_shape = loco::shape_get(node->input()).as(); // in NHWC @@ -387,26 +405,52 @@ class ShapeInferenceAlgorithm final : public luci::CircleNodeVisitorx()).as(); + const auto y_shape = loco::shape_get(node->y()).as(); + loco::TensorShape output_shape = broadcast_shape(x_shape, y_shape); + return loco::NodeShape{output_shape}; + } + loco::NodeShape visit(const luci::CircleFullyConnected *node) final { auto input_shape = loco::shape_get(node->input()).as(); auto weights_shape = loco::shape_get(node->weights()).as(); - // Checking shape capability for multiplication - LUCI_ASSERT(input_shape.rank() == 2, "NYI for input shape rank > 2"); + // Checking shape capability for fully connected layer + // Input: a tensor of at least rank 2 [D1, D2, ... Dn] + // Weight: [# of units, K] + // Output: [D1 * D2 * ... * Dn / K, # of units] + LUCI_ASSERT(input_shape.rank() >= 2, "Input rank should be at least 2"); LUCI_ASSERT(weights_shape.rank() == 2, "Incompatible weights rank for fully connected"); - LUCI_ASSERT(input_shape.dim(1) == weights_shape.dim(1), - "Incompatible shapes for fully connected"); + uint32_t input_size = 1; + for (uint32_t i = 0; i < input_shape.rank(); i++) + { + input_size = input_size * input_shape.dim(i).value(); + } + const uint32_t batch_size = input_size / weights_shape.dim(1).value(); loco::TensorShape out_shape; out_shape.rank(2); - - out_shape.dim(0) = input_shape.dim(0); + out_shape.dim(0) = batch_size; out_shape.dim(1) = weights_shape.dim(0); return loco::NodeShape{out_shape}; } + loco::NodeShape visit(const luci::CircleLogicalNot *node) final + { + const auto input_shape = loco::shape_get(node->x()).as(); + return loco::NodeShape{input_shape}; + } + + loco::NodeShape visit(const luci::CircleLogicalOr *node) final + { + const auto input_shape = loco::shape_get(node->x()).as(); + return loco::NodeShape{input_shape}; + } + loco::NodeShape visit(const luci::CircleMaximum *node) final { auto x_shape = loco::shape_get(node->x()).as(); @@ -488,6 +532,49 @@ class ShapeInferenceAlgorithm final : public luci::CircleNodeVisitorvalues_count() > 0, "Only support one or more inputs"); + + auto first_shape = loco::shape_get(node->values(0)).as(); + // Make sure all inputs have the same shape. + for (uint32_t i = 1; i < node->values_count(); ++i) + { + auto in_shape = loco::shape_get(node->values(i)).as(); + LUCI_ASSERT(loco::NodeShape{first_shape} == loco::NodeShape{in_shape}, + "All inputs must have the same shape"); + } + + // Checking shape capability for pack layer + // Input: tensors [D1, D2, ... Dn] + // Axis: K + // Output: [D1, D2, ... , D_K-1, n, D_K+1, ... Dn] + auto axis = node->axis(); + if (axis < 0) + axis += first_shape.rank() + 1; + + LUCI_ASSERT(0 <= axis, "Axis is out of range"); + LUCI_ASSERT(static_cast(axis) <= first_shape.rank(), "Axis is out of range"); + + loco::TensorShape output_shape; + output_shape.rank(first_shape.rank() + 1); + + uint32_t j = 0; + for (uint32_t i = 0; i < output_shape.rank(); ++i) + { + if (i == static_cast(axis)) + { + output_shape.dim(i) = node->values_count(); + } + else + { + output_shape.dim(i) = first_shape.dim(j++); + } + } + + return loco::NodeShape{output_shape}; + } + loco::NodeShape visit(const luci::CirclePad *node) final { const loco::DataType S32 = loco::DataType::S32; @@ -566,7 +653,6 @@ class ShapeInferenceAlgorithm final : public luci::CircleNodeVisitorat(axis) > 0, "Dimension should be > 0") shape_by_input.dim(axis) = const_shape_node->at(axis); } } @@ -577,7 +663,6 @@ class ShapeInferenceAlgorithm final : public luci::CircleNodeVisitornewShape()->dim(axis) > 0, "Dimension should be > 0") shape_by_attr.dim(axis) = node->newShape()->dim(axis); } } @@ -585,7 +670,32 @@ class ShapeInferenceAlgorithm final : public luci::CircleNodeVisitortensor()).as(); + const uint32_t input_element_count = loco::element_count(&input_shape); + uint32_t output_element_count = 1; + uint32_t unknown_dim_index = UINT32_MAX; + for (uint32_t dim_index = 0; dim_index < output_shape.rank(); ++dim_index) + { + const uint32_t dim_value = output_shape.dim(dim_index).value(); + if (static_cast(dim_value) == -1) + { + LUCI_ASSERT(unknown_dim_index == UINT32_MAX, "More than one unknown dimension"); + unknown_dim_index = dim_index; + } + else + { + output_element_count *= dim_value; + } + } + if (unknown_dim_index != UINT32_MAX) + { + output_shape.dim(unknown_dim_index) = input_element_count / output_element_count; + } + + return loco::NodeShape{output_shape}; } loco::NodeShape visit(const luci::CircleRsqrt *node) final @@ -595,7 +705,12 @@ class ShapeInferenceAlgorithm final : public luci::CircleNodeVisitorlogits()).as(); + + return loco::NodeShape{input_shape}; + } loco::NodeShape visit(const luci::CircleSqrt *node) final { @@ -639,8 +754,8 @@ class ShapeInferenceAlgorithm final : public luci::CircleNodeVisitortemplate at(out_axis); - output_shape.dim(new_dim) = input_shape.dim(out_axis); + auto in_axis = perm_node->template at(out_axis); + output_shape.dim(out_axis) = input_shape.dim(in_axis); } return output_shape; @@ -651,15 +766,15 @@ class ShapeInferenceAlgorithm final : public luci::CircleNodeVisitora()).as(); auto canon_perm = dynamic_cast(node->perm()); - auto tfl_perm = dynamic_cast(node->perm()); + auto circle_perm = dynamic_cast(node->perm()); if (canon_perm) { return loco::NodeShape{output_shape_of_transpose(input_shape, canon_perm)}; } - else if (tfl_perm) + else if (circle_perm) { - return loco::NodeShape{output_shape_of_transpose(input_shape, tfl_perm)}; + return loco::NodeShape{output_shape_of_transpose(input_shape, circle_perm)}; } else INTERNAL_EXN("perm of CircleTranspose should be either ConstGen or CircleConst"); diff --git a/compiler/luci/service/src/CircleShapeInferenceRule.test.cpp b/compiler/luci/service/src/CircleShapeInferenceRule.test.cpp index dcef9f19884..0374251a0b8 100644 --- a/compiler/luci/service/src/CircleShapeInferenceRule.test.cpp +++ b/compiler/luci/service/src/CircleShapeInferenceRule.test.cpp @@ -26,10 +26,10 @@ #include #include -#include - #include +#include + namespace { @@ -249,20 +249,18 @@ TEST(CircleShapeInferenceRuleTest, CircleTranspose_simple) { luci::test::ExampleGraph g; - g.pull->rank(4); - g.pull->dim(0) = 10; - g.pull->dim(1) = 20; - g.pull->dim(2) = 30; - g.pull->dim(3) = 40; + g.pull->rank(3); + g.pull->dim(0) = 3; + g.pull->dim(1) = 8; + g.pull->dim(2) = 1; g.const_perm->dtype(loco::DataType::S32); g.const_perm->rank(1); - g.const_perm->dim(0) = 4; - g.const_perm->size(4); - g.const_perm->at(0) = 2; - g.const_perm->at(1) = 3; + g.const_perm->dim(0) = 3; + g.const_perm->size(3); + g.const_perm->at(0) = 1; + g.const_perm->at(1) = 2; g.const_perm->at(2) = 0; - g.const_perm->at(3) = 1; // pre-check ASSERT_FALSE(loco::shape_known(g.transpose_node)); @@ -276,10 +274,9 @@ TEST(CircleShapeInferenceRuleTest, CircleTranspose_simple) ASSERT_TRUE(loco::shape_known(g.transpose_node)); auto shape = loco::shape_get(g.transpose_node).as(); - ASSERT_EQ(shape.rank(), 4); - ASSERT_EQ(shape.dim(0), 30); - ASSERT_EQ(shape.dim(1), 40); - ASSERT_EQ(shape.dim(2), 10); - ASSERT_EQ(shape.dim(3), 20); + ASSERT_EQ(shape.rank(), 3); + ASSERT_EQ(shape.dim(0), 8); + ASSERT_EQ(shape.dim(1), 1); + ASSERT_EQ(shape.dim(2), 3); } } diff --git a/compiler/luci/service/src/CircleTypeInference.cpp b/compiler/luci/service/src/CircleTypeInference.cpp index f6a4e8aa3b3..66990615962 100644 --- a/compiler/luci/service/src/CircleTypeInference.cpp +++ b/compiler/luci/service/src/CircleTypeInference.cpp @@ -25,8 +25,8 @@ #include #include #include -#include +#include #include #include @@ -55,6 +55,8 @@ circle::TensorType translateLocoTypeToCircle(loco::DataType dtype) case loco::DataType::FLOAT32: return circle::TensorType_FLOAT32; // case loco::DataType::FLOAT64: unsupported + case loco::DataType::BOOL: + return circle::TensorType_BOOL; default: break; } diff --git a/compiler/luci/service/src/CircleTypeInferenceRule.cpp b/compiler/luci/service/src/CircleTypeInferenceRule.cpp index 37ab9b52524..61b5c327ed3 100644 --- a/compiler/luci/service/src/CircleTypeInferenceRule.cpp +++ b/compiler/luci/service/src/CircleTypeInferenceRule.cpp @@ -27,6 +27,10 @@ namespace struct TypeInferenceAlgorithm final : public luci::CircleNodeVisitor { + // TODO Given a tensor x of complex numbers, Abs operation returns a tensor of type float32 or + // float64. + loco::DataType visit(const luci::CircleAbs *node) final { return loco::dtype_get(node->x()); } + loco::DataType visit(const luci::CircleAdd *node) final { return loco::dtype_get(node->x()); } loco::DataType visit(const luci::CircleArgMax *node) final { return node->output_type(); } @@ -54,6 +58,8 @@ struct TypeInferenceAlgorithm final : public luci::CircleNodeVisitorinput()); } + loco::DataType visit(const luci::CircleCos *node) final { return loco::dtype_get(node->x()); } + loco::DataType visit(const luci::CircleDepthwiseConv2D *node) final { return loco::dtype_get(node->input()); @@ -61,11 +67,23 @@ struct TypeInferenceAlgorithm final : public luci::CircleNodeVisitorx()); } + loco::DataType visit(const luci::CircleEqual *) final { return loco::DataType::BOOL; } + loco::DataType visit(const luci::CircleFullyConnected *node) final { return loco::dtype_get(node->input()); } + loco::DataType visit(const luci::CircleLogicalNot *node) final + { + return loco::dtype_get(node->x()); + } + + loco::DataType visit(const luci::CircleLogicalOr *node) final + { + return loco::dtype_get(node->x()); + } + loco::DataType visit(const luci::CircleMaximum *node) final { return loco::dtype_get(node->x()); } loco::DataType visit(const luci::CircleMaxPool2D *node) final @@ -78,6 +96,18 @@ struct TypeInferenceAlgorithm final : public luci::CircleNodeVisitorinput()); } + loco::DataType visit(const luci::CirclePack *node) final + { + // Only support CirclePack with one or more inputs + assert(node->values_count() > 0); + + auto first_value_type = loco::dtype_get(node->values(0)); + for (uint32_t i = 1; i < node->values_count(); ++i) + assert(first_value_type == loco::dtype_get(node->values(i))); + + return first_value_type; + } + loco::DataType visit(const luci::CirclePad *node) final { return loco::dtype_get(node->input()); } loco::DataType visit(const luci::CircleMul *node) final { return loco::dtype_get(node->x()); } @@ -99,7 +129,10 @@ struct TypeInferenceAlgorithm final : public luci::CircleNodeVisitorx()); } - // TODO CircleSoftmax + loco::DataType visit(const luci::CircleSoftmax *node) final + { + return loco::dtype_get(node->logits()); + } loco::DataType visit(const luci::CircleSqrt *node) final { return loco::dtype_get(node->x()); } diff --git a/compiler/luci/service/src/CircleTypeInferenceRule.test.cpp b/compiler/luci/service/src/CircleTypeInferenceRule.test.cpp index 67960df5059..29f45173ee3 100644 --- a/compiler/luci/service/src/CircleTypeInferenceRule.test.cpp +++ b/compiler/luci/service/src/CircleTypeInferenceRule.test.cpp @@ -24,10 +24,10 @@ #include #include -#include - #include +#include + TEST(CircleTypeInferenceRuleTest, minimal_with_CircleRelu) { // Create a simple network diff --git a/compiler/luci/service/src/GraphBlock.test.cpp b/compiler/luci/service/src/GraphBlock.test.cpp index 361c35f3ea8..1da8c18fa83 100644 --- a/compiler/luci/service/src/GraphBlock.test.cpp +++ b/compiler/luci/service/src/GraphBlock.test.cpp @@ -19,7 +19,8 @@ #include "Check.h" #include -#include + +#include // TODO Change all Canonical nodes to Circle nodes @@ -116,7 +117,7 @@ template loco::FeatureEncode *make_feature_encode(loco::Node * LUCI_ASSERT(input_for_encode != nullptr, "input should not be nullptr"); loco::Graph *g = input_for_encode->graph(); - auto encoder = stdex::make_unique>(); + auto encoder = std::make_unique>(); encoder->perm(perm()); @@ -132,7 +133,7 @@ template loco::FeatureDecode *make_feature_decode(loco::Node * LUCI_ASSERT(input_for_decode != nullptr, "input should not be nullptr"); loco::Graph *g = input_for_decode->graph(); - auto decoder = stdex::make_unique>(); + auto decoder = std::make_unique>(); decoder->perm(perm()); @@ -148,7 +149,7 @@ template loco::FilterEncode *make_filter_encode(loco::Node *inp LUCI_ASSERT(input_for_encode != nullptr, "filter should not be nullptr"); loco::Graph *g = input_for_encode->graph(); - auto encoder = stdex::make_unique>(); + auto encoder = std::make_unique>(); encoder->perm(perm()); @@ -164,7 +165,7 @@ template loco::FilterDecode *make_filter_decode(loco::Node *inp LUCI_ASSERT(input_for_decode != nullptr, "filter should not be nullptr"); loco::Graph *g = input_for_decode->graph(); - auto decoder = stdex::make_unique>(); + auto decoder = std::make_unique>(); decoder->perm(perm()); @@ -181,7 +182,7 @@ loco::DepthwiseFilterDecode *make_dw_filter_decode(loco::Node *input_for_decode) LUCI_ASSERT(input_for_decode != nullptr, "filter should not be nullptr"); loco::Graph *g = input_for_decode->graph(); - auto decoder = stdex::make_unique>(); + auto decoder = std::make_unique>(); decoder->perm(perm()); @@ -197,7 +198,7 @@ template loco::MatrixEncode *make_matrix_encode(loco::Node *inp LUCI_ASSERT(input_for_encode != nullptr, "input should not be nullptr"); loco::Graph *g = input_for_encode->graph(); - auto encoder = stdex::make_unique>(); + auto encoder = std::make_unique>(); encoder->perm(perm()); @@ -213,7 +214,7 @@ template loco::MatrixDecode *make_matrix_decode(loco::Node *inp LUCI_ASSERT(input_for_decode != nullptr, "input should not be nullptr"); loco::Graph *g = input_for_decode->graph(); - auto decoder = stdex::make_unique>(); + auto decoder = std::make_unique>(); decoder->perm(perm()); diff --git a/compiler/luci/service/src/TestGraph.h b/compiler/luci/service/src/TestGraph.h index 9068fa7109b..73562040f91 100644 --- a/compiler/luci/service/src/TestGraph.h +++ b/compiler/luci/service/src/TestGraph.h @@ -21,9 +21,9 @@ #include "GraphBlock.h" #include -#include #include +#include // TODO Change all Canonical nodes to Circle nodes diff --git a/compiler/luci/tester/CMakeLists.txt b/compiler/luci/tester/CMakeLists.txt index 0f6d1f0ae41..bcb47183e0b 100644 --- a/compiler/luci/tester/CMakeLists.txt +++ b/compiler/luci/tester/CMakeLists.txt @@ -16,7 +16,7 @@ set(SRCS_WRITE_TESTER add_executable(luci_writetester "${SRCS_WRITE_TESTER}") target_link_libraries(luci_writetester PRIVATE luci_import) -target_link_libraries(luci_readtester PRIVATE luci_service) +target_link_libraries(luci_writetester PRIVATE luci_service) target_link_libraries(luci_writetester PRIVATE luci_pass) target_link_libraries(luci_writetester PRIVATE luci_export) target_link_libraries(luci_writetester PRIVATE oops) diff --git a/compiler/luci/tester/src/Model.cpp b/compiler/luci/tester/src/Model.cpp index 453be74f77b..b02c19161c0 100644 --- a/compiler/luci/tester/src/Model.cpp +++ b/compiler/luci/tester/src/Model.cpp @@ -56,7 +56,7 @@ namespace luci std::unique_ptr load_model(const std::string &path) { - return std::unique_ptr{new FileModel(path)}; + return std::make_unique(path); } } // namespace luci diff --git a/compiler/luci/tests/CMakeLists.txt b/compiler/luci/tests/CMakeLists.txt index e6bfaf950f4..4e56390473c 100644 --- a/compiler/luci/tests/CMakeLists.txt +++ b/compiler/luci/tests/CMakeLists.txt @@ -5,33 +5,29 @@ foreach(RECIPE IN ITEMS ${RECIPES}) get_filename_component(RECIPE_PREFIX ${RECIPE} DIRECTORY) set(RECIPE_SOURCE_FILE "${RECIPE_PREFIX}.recipe") - set(RECIPE_SOURCE_TARGET lucitests_${RECIPE_PREFIX}_recipe) - set(RECIPE_OUTPUT_FILE "${RECIPE_PREFIX}.tflite") - set(RECIPE_OUTPUT_TARGET lucitests_${RECIPE_PREFIX}_tflite) - set(CIRCLE_OUTPUT_FILE "${RECIPE_PREFIX}.circle") - set(CIRCLE_OUTPUT_TARGET lucitests_${RECIPE_PREFIX}_circle) # Copy .recipe - add_custom_target(${RECIPE_SOURCE_TARGET} - ALL ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/${RECIPE}" - "${CMAKE_CURRENT_BINARY_DIR}/${RECIPE_SOURCE_FILE}" - COMMENT "Generate ${RECIPE_PREFIX}.recipe") + add_custom_command(OUTPUT "${RECIPE_SOURCE_FILE}" + COMMAND ${CMAKE_COMMAND} -E copy_if_different + "${CMAKE_CURRENT_SOURCE_DIR}/${RECIPE}" "${RECIPE_SOURCE_FILE}" + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${RECIPE}" + COMMENT "Generating ${RECIPE_SOURCE_FILE}") # Generate .tflite - add_custom_target(${RECIPE_OUTPUT_TARGET} - ALL $ ${RECIPE_SOURCE_FILE} ${RECIPE_OUTPUT_FILE} - DEPENDS ${RECIPE_SOURCE_TARGET} - COMMENT "Generate ${RECIPE_PREFIX}.tflite") + add_custom_command(OUTPUT "${RECIPE_OUTPUT_FILE}" + COMMAND tflchef-file "${RECIPE_SOURCE_FILE}" "${RECIPE_OUTPUT_FILE}" + DEPENDS tflchef-file "${RECIPE_SOURCE_FILE}" + COMMENT "Generating ${RECIPE_OUTPUT_FILE}") # Generate .circle - add_custom_target(${CIRCLE_OUTPUT_TARGET} - ALL $ ${RECIPE_OUTPUT_FILE} ${CIRCLE_OUTPUT_FILE} - DEPENDS ${RECIPE_OUTPUT_TARGET} - COMMENT "Generate ${RECIPE_PREFIX}.circle") + add_custom_command(OUTPUT "${CIRCLE_OUTPUT_FILE}" + COMMAND tflite2circle "${RECIPE_OUTPUT_FILE}" "${CIRCLE_OUTPUT_FILE}" + DEPENDS tflite2circle "${RECIPE_OUTPUT_FILE}" + COMMENT "Generating ${CIRCLE_OUTPUT_FILE}") - list(APPEND TESTS ${RECIPE_PREFIX}) + list(APPEND TESTFILES "${CIRCLE_OUTPUT_FILE}") endforeach(RECIPE) # Generate from res/TensorFlowLiteRecipes @@ -44,35 +40,35 @@ foreach(RECIPE IN ITEMS ${RECIPES}) get_filename_component(RECIPE_PREFIX ${RECIPE} DIRECTORY) set(RECIPE_SOURCE_FILE "${RECIPE_PREFIX}.recipe") - set(RECIPE_SOURCE_TARGET lucitests_res_${RECIPE_PREFIX}_recipe) - set(RECIPE_OUTPUT_FILE "${RECIPE_PREFIX}.tflite") - set(RECIPE_OUTPUT_TARGET lucitests_res_${RECIPE_PREFIX}_tflite) - set(CIRCLE_OUTPUT_FILE "${RECIPE_PREFIX}.circle") - set(CIRCLE_OUTPUT_TARGET lucitests_res_${RECIPE_PREFIX}_circle) # Copy .recipe - add_custom_target(${RECIPE_SOURCE_TARGET} - ALL ${CMAKE_COMMAND} -E copy "${TENSORFLOWLITERECIPES_DIR}/${RECIPE}" - "${CMAKE_CURRENT_BINARY_DIR}/${RECIPE_SOURCE_FILE}" - COMMENT "Generate ${RECIPE_PREFIX}.recipe") + add_custom_command(OUTPUT "${RECIPE_SOURCE_FILE}" + COMMAND ${CMAKE_COMMAND} -E copy_if_different + "${TENSORFLOWLITERECIPES_DIR}/${RECIPE}" "${RECIPE_SOURCE_FILE}" + DEPENDS "${TENSORFLOWLITERECIPES_DIR}/${RECIPE}" + COMMENT "Generating ${RECIPE_SOURCE_FILE}") # Generate .tflite - add_custom_target(${RECIPE_OUTPUT_TARGET} - ALL $ ${RECIPE_SOURCE_FILE} ${RECIPE_OUTPUT_FILE} - DEPENDS ${RECIPE_SOURCE_TARGET} - COMMENT "Generate ${RECIPE_PREFIX}.tflite") + add_custom_command(OUTPUT "${RECIPE_OUTPUT_FILE}" + COMMAND tflchef-file "${RECIPE_SOURCE_FILE}" "${RECIPE_OUTPUT_FILE}" + DEPENDS tflchef-file "${RECIPE_SOURCE_FILE}" + COMMENT "Generating ${RECIPE_OUTPUT_FILE}") # Generate .circle - add_custom_target(${CIRCLE_OUTPUT_TARGET} - ALL $ ${RECIPE_OUTPUT_FILE} ${CIRCLE_OUTPUT_FILE} - DEPENDS ${RECIPE_OUTPUT_TARGET} - COMMENT "Generate ${RECIPE_PREFIX}.circle") + add_custom_command(OUTPUT "${CIRCLE_OUTPUT_FILE}" + COMMAND tflite2circle "${RECIPE_OUTPUT_FILE}" "${CIRCLE_OUTPUT_FILE}" + DEPENDS tflite2circle "${RECIPE_OUTPUT_FILE}" + COMMENT "Generating ${CIRCLE_OUTPUT_FILE}") - list(APPEND TESTS ${RECIPE_PREFIX}) + list(APPEND TESTFILES "${CIRCLE_OUTPUT_FILE}") endforeach(RECIPE) +# Add a dummy target to create a target-level dependency. +# TODO Find a way to create dependency between CTest tests (added below) and generated testfiles. +add_custom_target(luci_testfiles ALL DEPENDS ${TESTFILES}) + macro(addread NAME) list(APPEND DAILY_READ_TESTS ${NAME}) endmacro(addread) diff --git a/compiler/luci/tests/test.lst b/compiler/luci/tests/test.lst index fa3d10fba62..972c167876a 100644 --- a/compiler/luci/tests/test.lst +++ b/compiler/luci/tests/test.lst @@ -1,15 +1,85 @@ addread(Add_000) addread(Add_U8_000) +addread(ArgMax_000) +addread(ArgMax_001) +addread(ArgMax_002) +addread(ArgMax_003) +addread(ArgMax_U8_000) +addread(ArgMax_U8_001) +addread(ArgMax_U8_002) +addread(ArgMax_U8_003) +addread(Concatenation_000) +addread(Concatenation_U8_000) addread(Conv2D_000) addread(Conv2D_U8_000) addread(Conv2D_002) +addread(Cos_000) +addread(DepthwiseConv2D_000) +addread(DepthwiseConv2D_U8_000) +addread(Div_000) +addread(Equal_000) +addread(FullyConnected_000) +addread(FullyConnected_001) +addread(FullyConnected_U8_000) +addread(LogicalNot_000) +addread(LogicalOr_000) addread(MaxPool2D_000) addread(MaxPool2D_U8_000) +addread(Mean_000) +addread(Mul_000) +addread(Mul_U8_000) +addread(Pack_000) +addread(Pack_U8_000) +addread(Pad_000) +addread(ReLU_000) +addread(Reshape_000) +addread(Reshape_001) +addread(Reshape_U8_000) +addread(Softmax_000) +addread(Softmax_U8_000) +addread(Sub_000) +addread(Sub_U8_000) +addread(Transpose_000) addwrite(Add_000) addwrite(Add_U8_000) +addwrite(ArgMax_000) +addwrite(ArgMax_001) +addwrite(ArgMax_002) +addwrite(ArgMax_003) +addwrite(ArgMax_U8_000) +addwrite(ArgMax_U8_001) +addwrite(ArgMax_U8_002) +addwrite(ArgMax_U8_003) +addwrite(Concatenation_000) +addwrite(Concatenation_U8_000) addwrite(Conv2D_000) addwrite(Conv2D_U8_000) addwrite(Conv2D_002) +addwrite(Cos_000) +addwrite(DepthwiseConv2D_000) +addwrite(DepthwiseConv2D_U8_000) +addwrite(Div_000) +addwrite(Equal_000) +addwrite(FullyConnected_000) +addwrite(FullyConnected_001) +addwrite(FullyConnected_U8_000) +addwrite(LogicalNot_000) +addwrite(LogicalOr_000) addwrite(MaxPool2D_000) addwrite(MaxPool2D_U8_000) +addwrite(Mean_000) +addwrite(Mul_000) +addwrite(Mul_U8_000) +addwrite(Pack_000) +addwrite(Pack_U8_000) +addwrite(Pad_000) +addwrite(ReLU_000) +addwrite(Reshape_000) +addwrite(Reshape_001) +addwrite(Reshape_U8_000) +addwrite(Softmax_000) +addwrite(Softmax_U8_000) +addwrite(Sub_000) +addwrite(Sub_U8_000) +addwrite(Transpose_000) diff --git a/compiler/mio-tflite/CMakeLists.txt b/compiler/mio-tflite/CMakeLists.txt index bc2bdf395e3..cb0795a08e0 100644 --- a/compiler/mio-tflite/CMakeLists.txt +++ b/compiler/mio-tflite/CMakeLists.txt @@ -4,7 +4,7 @@ if(NOT FlatBuffers_FOUND) return() endif(NOT FlatBuffers_FOUND) -nnas_find_package(TensorFlowSource EXACT 1.13.1 QUIET) +nnas_find_package(TensorFlowSource EXACT 2.1.0 QUIET) if(NOT TensorFlowSource_FOUND) return() @@ -30,3 +30,8 @@ FlatBuffers_Target(mio_tflite add_executable(mio_tflite_example example.cpp) target_link_libraries(mio_tflite_example mio_tflite) + +# Temporay tflite validation tool to replace nnkit-tflite +# TODO provide full tflite validation with runtime/interpreter +add_executable(mio_tflite_validate example.cpp) +target_link_libraries(mio_tflite_validate mio_tflite) diff --git a/compiler/mir-interpreter/include/MirInterpreter.h b/compiler/mir-interpreter/include/MirInterpreter.h index 2f4f52dcbb2..c3d9717163b 100644 --- a/compiler/mir-interpreter/include/MirInterpreter.h +++ b/compiler/mir-interpreter/include/MirInterpreter.h @@ -33,12 +33,6 @@ class MIRInterpreter : public mir::Visitor ~MIRInterpreter() override = default; - /// @deprecated Use `setTensor` instead. - void setOutputTensors(const mir::Operation &op, std::vector &&outputs); - - /// @deprecated Use `getTensor` instead. - mir::TensorVariant getResult(const mir::Operation::Output *tensor); - /// @brief Set tensor to the interpreter environment. void setTensor(const mir::Operation::Output *output, mir::TensorVariant tensor); @@ -89,12 +83,14 @@ class MIRInterpreter : public mir::Visitor void visit_fallback(mir::Operation &op) override; private: + mir::TensorVariant &allocateTensor(const mir::Operation::Output *output); + /// @brief Gets the computed inputs for the operation. std::vector> getInputTensors(const mir::Operation &op); std::vector> - getOutputTensors(const mir::Operation &op); + allocateOutputTensors(const mir::Operation &op); /// @brief Mapping of operation outputs to corresponding tensors. std::unordered_map _tensors; diff --git a/compiler/mir-interpreter/src/MirInterpreter.cpp b/compiler/mir-interpreter/src/MirInterpreter.cpp index 474a451c90b..245f7ddabe3 100644 --- a/compiler/mir-interpreter/src/MirInterpreter.cpp +++ b/compiler/mir-interpreter/src/MirInterpreter.cpp @@ -74,6 +74,17 @@ void MIRInterpreter::setTensor(const Operation::Output *output, TensorVariant te } } +TensorVariant &MIRInterpreter::allocateTensor(const Operation::Output *output) +{ + const auto result = _tensors.emplace(output, output->getType()); + if (!result.second) + { + const std::string &name = output->getName(); + throw std::runtime_error("Attempt to overwrite data for tensor \"" + name + "\"."); + } + return result.first->second; +} + const TensorVariant &MIRInterpreter::getTensor(const Operation::Output *output) const { const auto it = _tensors.find(output); @@ -97,40 +108,16 @@ MIRInterpreter::getInputTensors(const Operation &op) } std::vector> -MIRInterpreter::getOutputTensors(const Operation &op) +MIRInterpreter::allocateOutputTensors(const Operation &op) { - // Create and register output tensors. - for (const Operation::Output &res : op.getOutputs()) - { - assert(res.getElementType() != mir::DataType::UNKNOWN); - _tensors.emplace(&res, res.getType()); - } - - // Gather references to output tensors. std::vector> tensors; for (const Operation::Output &output : op.getOutputs()) { - tensors.emplace_back(_tensors.at(&output)); + tensors.emplace_back(allocateTensor(&output)); } return tensors; } -// Deprecated, will be removed. -void MIRInterpreter::setOutputTensors(const Operation &op, std::vector &&outputs) -{ - assert(outputs.size() == op.getNumOutputs()); - for (std::size_t i = 0; i < op.getNumOutputs(); ++i) - { - setTensor(op.getOutput(i), std::move(outputs[i])); - } -} - -// Deprecated, will be removed. -TensorVariant MIRInterpreter::getResult(const Operation::Output *tensor) -{ - return getTensor(tensor); -} - void MIRInterpreter::visit(ops::InputOp &op) { assert(_tensors.find(op.getOutput(0)) != _tensors.end()); @@ -139,23 +126,23 @@ void MIRInterpreter::visit(ops::InputOp &op) void MIRInterpreter::visit(ops::AvgPool2DOp &op) { auto inputs = getInputTensors(op); - auto outputs = getOutputTensors(op); + auto outputs = allocateOutputTensors(op); AvgPool2D(op, inputs[0], outputs[0]); } -void MIRInterpreter::visit(ops::ConstantOp &op) { setOutputTensors(op, {op.getValue()}); } +void MIRInterpreter::visit(ops::ConstantOp &op) { setTensor(op.getOutput(0), op.getValue()); } void MIRInterpreter::visit(ops::ConcatOp &op) { auto inputs = getInputTensors(op); - auto outputs = getOutputTensors(op); + auto outputs = allocateOutputTensors(op); Concat(inputs, op.getAxis(), outputs[0]); } void MIRInterpreter::visit(ops::Conv2DOp &op) { auto inputs = getInputTensors(op); - auto outputs = getOutputTensors(op); + auto outputs = allocateOutputTensors(op); const mir::TensorVariant *bias = nullptr; if (inputs.size() > 2) { @@ -167,28 +154,28 @@ void MIRInterpreter::visit(ops::Conv2DOp &op) void MIRInterpreter::visit(ops::MaxPool2DOp &op) { auto inputs = getInputTensors(op); - auto outputs = getOutputTensors(op); + auto outputs = allocateOutputTensors(op); MaxPool2D(inputs[0], op, outputs[0]); } void MIRInterpreter::visit(ops::ReshapeOp &op) { auto inputs = getInputTensors(op); - auto outputs = Reshape(inputs[0], op.getOutputShape(0)); - setOutputTensors(op, std::move(outputs)); + auto outputs = allocateOutputTensors(op); + Reshape(inputs[0], outputs[0]); } void MIRInterpreter::visit(ops::ReluOp &op) { auto args = getInputTensors(op); - auto results = getOutputTensors(op); + auto results = allocateOutputTensors(op); ReLU(args[0], results[0]); } void MIRInterpreter::visit(ops::SigmoidOp &op) { auto args = getInputTensors(op); - auto results = getOutputTensors(op); + auto results = allocateOutputTensors(op); Sigmoid(args[0], results[0]); } @@ -196,14 +183,14 @@ void MIRInterpreter::visit(ops::SoftmaxOp &op) { auto inputs = getInputTensors(op); assert(inputs.size() == 1); - auto outputs = getOutputTensors(op); + auto outputs = allocateOutputTensors(op); Softmax(inputs[0], op.getAxis(), outputs[0]); } void MIRInterpreter::visit(ops::FullyConnectedOp &op) { auto inputs = getInputTensors(op); - auto outputs = getOutputTensors(op); + auto outputs = allocateOutputTensors(op); const mir::TensorVariant *bias = nullptr; if (inputs.size() > 2) { @@ -215,14 +202,14 @@ void MIRInterpreter::visit(ops::FullyConnectedOp &op) void MIRInterpreter::visit(ops::CappedReluOp &op) { auto args = getInputTensors(op); - auto results = getOutputTensors(op); + auto results = allocateOutputTensors(op); CappedReLU(args[0], op.getCap(), results[0]); } void MIRInterpreter::visit(ops::DepthwiseConv2DOp &op) { auto inputs = getInputTensors(op); - auto outputs = getOutputTensors(op); + auto outputs = allocateOutputTensors(op); const mir::TensorVariant *bias = nullptr; if (inputs.size() > 2) { @@ -235,50 +222,50 @@ void MIRInterpreter::visit(ops::SliceOp &op) { auto inputs = getInputTensors(op); auto input = inputs[0]; - auto outputs = getOutputTensors(op); + auto outputs = allocateOutputTensors(op); Slice(input, op.getStarts(), outputs[0]); } void MIRInterpreter::visit(ops::TanhOp &op) { auto args = getInputTensors(op); - auto results = getOutputTensors(op); + auto results = allocateOutputTensors(op); Tanh(args[0], results[0]); } void MIRInterpreter::visit(ops::DeConv2DOp &op) { auto inputs = getInputTensors(op); - auto outputs = getOutputTensors(op); - DeConv2D(inputs[0], inputs[1], op, outputs[0]); + auto outputs = allocateOutputTensors(op); + DeConv2D(inputs[0], inputs[1], op.getAttributes(), outputs[0]); } void MIRInterpreter::visit(ops::EluOp &op) { auto args = getInputTensors(op); - auto results = getOutputTensors(op); + auto results = allocateOutputTensors(op); ELU(args[0], op.getAlpha(), results[0]); } void MIRInterpreter::visit(ops::SqueezeOp &op) { auto inputs = getInputTensors(op); + auto outputs = allocateOutputTensors(op); // Squeeze is just a special case of reshape. - auto outputs = Reshape(inputs[0], op.getOutputShape(0)); - setOutputTensors(op, std::move(outputs)); + Reshape(inputs[0], outputs[0]); } void MIRInterpreter::visit(ops::PadOp &op) { auto inputs = getInputTensors(op); - auto outputs = getOutputTensors(op); + auto outputs = allocateOutputTensors(op); Pad(inputs[0], op, outputs[0]); } void MIRInterpreter::visit(ops::SqrtOp &op) { auto args = getInputTensors(op); - auto results = getOutputTensors(op); + auto results = allocateOutputTensors(op); Sqrt(args[0], results[0]); } @@ -287,7 +274,7 @@ void MIRInterpreter::visit(ops::ResizeOp &op) // TODO support types other than float32 auto inputs = getInputTensors(op); assert(inputs[0].get().getElementType() == mir::DataType::FLOAT32); - auto outputs = getOutputTensors(op); + auto outputs = allocateOutputTensors(op); Tensor input(inputs[0]); assert(op.getMode() == ops::ResizeOp::ResizeMethod::nearestNeighbor); @@ -307,28 +294,28 @@ void MIRInterpreter::visit(ops::ResizeOp &op) void MIRInterpreter::visit(ops::ReduceMeanOp &op) { auto inputs = getInputTensors(op); - auto outputs = getOutputTensors(op); + auto outputs = allocateOutputTensors(op); ReduceMean(inputs[0], op, outputs[0]); } void MIRInterpreter::visit(ops::TransposeOp &op) { auto inputs = getInputTensors(op); - auto outputs = getOutputTensors(op); + auto outputs = allocateOutputTensors(op); Transpose(inputs[0], op, outputs[0]); } void MIRInterpreter::visit(ops::GatherOp &op) { auto inputs = getInputTensors(op); - auto outputs = getOutputTensors(op); + auto outputs = allocateOutputTensors(op); Gather(inputs[0], inputs[1], op, outputs[0]); } void MIRInterpreter::visit(ops::LeakyReluOp &op) { auto args = getInputTensors(op); - auto results = getOutputTensors(op); + auto results = allocateOutputTensors(op); LeakyReLU(args[0], op.getAlpha(), results[0]); } @@ -340,92 +327,92 @@ void MIRInterpreter::visit(ops::OutputOp &op) void MIRInterpreter::visit(ops::AddOp &op) { auto inputs = getInputTensors(op); - auto outputs = getOutputTensors(op); + auto outputs = allocateOutputTensors(op); Add(inputs[0], inputs[1], outputs[0]); } void MIRInterpreter::visit(mir::ops::DivOp &op) { auto inputs = getInputTensors(op); - auto outputs = getOutputTensors(op); + auto outputs = allocateOutputTensors(op); Div(inputs[0], inputs[1], outputs[0]); } void MIRInterpreter::visit(mir::ops::MaxOp &op) { auto inputs = getInputTensors(op); - auto outputs = getOutputTensors(op); + auto outputs = allocateOutputTensors(op); Max(inputs[0], inputs[1], outputs[0]); } void MIRInterpreter::visit(mir::ops::MulOp &op) { auto inputs = getInputTensors(op); - auto outputs = getOutputTensors(op); + auto outputs = allocateOutputTensors(op); Mul(inputs[0], inputs[1], outputs[0]); } void MIRInterpreter::visit(mir::ops::SubOp &op) { auto inputs = getInputTensors(op); - auto outputs = getOutputTensors(op); + auto outputs = allocateOutputTensors(op); Sub(inputs[0], inputs[1], outputs[0]); } void MIRInterpreter::visit(mir::ops::DequantizeOp &op) { auto inputs = getInputTensors(op); - auto outputs = getOutputTensors(op); + auto outputs = allocateOutputTensors(op); Dequantize(inputs[0], outputs[0]); } void MIRInterpreter::visit(mir::ops::QuantizeOp &op) { auto inputs = getInputTensors(op); - auto outputs = getOutputTensors(op); + auto outputs = allocateOutputTensors(op); Quantize(inputs[0], outputs[0]); } void MIRInterpreter::visit(mir::ops::HardSwishOp &op) { auto inputs = getInputTensors(op); - auto outputs = getOutputTensors(op); + auto outputs = allocateOutputTensors(op); HardSwish(inputs[0], outputs[0]); } void MIRInterpreter::visit(mir::ops::GreaterOp &op) { auto inputs = getInputTensors(op); - auto outputs = getOutputTensors(op); + auto outputs = allocateOutputTensors(op); Greater(inputs[0], inputs[1], outputs[0]); } void MIRInterpreter::visit(mir::ops::LessOp &op) { auto inputs = getInputTensors(op); - auto outputs = getOutputTensors(op); + auto outputs = allocateOutputTensors(op); Less(inputs[0], inputs[1], outputs[0]); } void MIRInterpreter::visit(mir::ops::EqualOp &op) { auto inputs = getInputTensors(op); - auto outputs = getOutputTensors(op); + auto outputs = allocateOutputTensors(op); Equal(inputs[0], inputs[1], outputs[0]); } void MIRInterpreter::visit(mir::ops::AbsOp &op) { auto inputs = getInputTensors(op); - auto outputs = getOutputTensors(op); + auto outputs = allocateOutputTensors(op); Abs(inputs[0], outputs[0]); } void MIRInterpreter::visit(mir::ops::BroadcastOp &op) { auto inputs = getInputTensors(op); - TensorVariant tv{inputs[0], op.getOutputShape(0)}; - setOutputTensors(op, {tv}); + auto outputs = allocateOutputTensors(op); + outputs[0].get() = TensorVariant{inputs[0], op.getOutputShape(0)}; } void MIRInterpreter::visit_fallback(mir::Operation &) { throw std::runtime_error("NYI operation"); } diff --git a/compiler/mir-interpreter/src/ops/DeConv2D.cpp b/compiler/mir-interpreter/src/ops/DeConv2D.cpp index 9c25702c89f..746d8c87c97 100644 --- a/compiler/mir-interpreter/src/ops/DeConv2D.cpp +++ b/compiler/mir-interpreter/src/ops/DeConv2D.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved + * Copyright 2017 The TensorFlow Authors. 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. @@ -14,120 +15,97 @@ * limitations under the License. */ -#include +#include "DeConv2D.h" +#include "Common.h" #include "mir/TensorUtil.h" -#include "mir/ShapeRange.h" -#include "mir/Tensor.h" -#include "DeConv2D.h" -#include "Common.h" +#include namespace mir_interpreter { using namespace mir; -using namespace mir::ops; +using std::int32_t; + +static int32_t calcOffset(const Shape &shape, int32_t i0, int32_t i1, int32_t i2, int32_t i3) +{ + return ((i0 * shape.dim(1) + i1) * shape.dim(2) + i2) * shape.dim(3) + i3; +} template struct DeConv2DImpl { - static void run(const mir::TensorVariant &input_var, const mir::TensorVariant &kernel_var, - const mir::ops::DeConv2DOp &op, mir::TensorVariant &output); + static void run(const TensorVariant &input, const TensorVariant &kernel, + const Deconv2DOpAttributes &attributes, TensorVariant &output); }; template -void DeConv2DImpl::run(const TensorVariant &input_var, const TensorVariant &kernel_var, - const DeConv2DOp &op, TensorVariant &output) +void DeConv2DImpl::run(const TensorVariant &input, const TensorVariant &kernel, + const Deconv2DOpAttributes &attributes, TensorVariant &output) { - Tensor input(input_var); - - // Input shape: [N, Hi, Wi, Ci] - // Kernel shape: [Hk, Wk, Co, Ci] - assert(op.getInputShape(0).rank() == 4); - const auto &input_shape = input.getShape(); - const auto &kernel_shape = kernel_var.getShape(); - (void)input_shape; - (void)kernel_shape; - assert(input_shape.rank() == 4); - assert(kernel_shape.rank() == 4); - assert(kernel_shape.dim(3) == input_shape.dim(3)); - assert(op.getPaddingBefore().size() == 2); - assert(op.getPaddingAfter().size() == 2); - - const auto &strides = op.getStrides(); - Shape out_shape = op.getOutputShape(0); - Tensor res_accesor(output); - Index pads({op.getPaddingBefore().at(0), op.getPaddingBefore().at(1), 0}); - - out_shape.dim(3) = 1; - ShapeRange out_range(out_shape); - - Shape in_shape = input.getShape(); - ShapeRange in_range(in_shape); - - auto tr_kernel = transposeTensor<0, 1, 3, 2>(kernel_var); - Tensor kernel(tr_kernel); - - Shape k_shape = kernel.getShape(); - int32_t num_kernels = k_shape.dim(3); - k_shape.dim(3) = 1; - ShapeRange kernel_range(k_shape); - - Index input_idx; - input_idx.resize(in_shape.rank()); - - Index kernel_idx; - kernel_idx.resize(k_shape.rank()); + // [H, W, Co, Ci] -> [Ci, H, W, Co] + TensorVariant transposed_kernel = transposeTensor<3, 0, 1, 2>(kernel); + + const auto *input_data = reinterpret_cast(input.atOffset(0)); + const auto *kernel_data = reinterpret_cast(transposed_kernel.atOffset(0)); + auto *output_data = reinterpret_cast(output.atOffset(0)); + + const Shape &input_shape = input.getShape(); + const Shape &output_shape = output.getShape(); + const Shape &kernel_shape = transposed_kernel.getShape(); + + const std::vector &strides = attributes.strides; + const std::vector &padding_before = attributes.padding_before; + assert(attributes.data_format == DataFormat::NHWC); + + const int32_t batch_size = output_shape.dim(0); + const int32_t output_height = output_shape.dim(1); + const int32_t output_width = output_shape.dim(2); + const int32_t kernel_height = kernel_shape.dim(1); + const int32_t kernel_width = kernel_shape.dim(2); + const int32_t input_height = input_shape.dim(1); + const int32_t input_width = input_shape.dim(2); + + const int32_t num_in_channels = input_shape.dim(3); + const int32_t num_out_channels = output_shape.dim(3); + + assert(kernel_shape.dim(0) == num_in_channels); + assert(kernel_shape.dim(3) == num_out_channels); erase(output); - for (auto &out_idx : out_range) + for (int32_t batch = 0; batch < batch_size; ++batch) { - auto out_region = res_accesor.getRegion(out_idx); - assert(out_region.size() == num_kernels); - - for (auto &kernel_idx_r : kernel_range) + for (int32_t in_y = 0; in_y < input_height; ++in_y) { - // rotate kernel 180 deg around last axis - // by index transform - for (int32_t d = 0; d < 2; ++d) - { - kernel_idx.at(d) = kernel.getShape().dim(d) - kernel_idx_r.at(d) - 1; - } - kernel_idx.at(2) = kernel_idx_r.at(2); - kernel_idx.at(3) = kernel_idx_r.at(3); - - // flag that keeps info on whether the current input element is from input - // or is from dilation by stride - bool is_from_input = true; - for (int32_t d = 1; d < input_idx.rank() - 1; ++d) - { - const auto num = (out_idx.at(d) + pads.at(d - 1) - kernel_idx.at(d - 1)); - auto stride = strides[d - 1]; - const auto div_res = num / stride; - const auto rem = num - div_res * stride; - is_from_input = is_from_input && rem == 0; - if (rem != 0) - break; - input_idx.at(d) = div_res; - } - if (is_from_input) + for (int32_t in_x = 0; in_x < input_width; ++in_x) { - // batch is same as output's - input_idx.at(0) = out_idx.at(0); - // channel index - same as kernel's - input_idx.at(3) = kernel_idx.at(2); - - if (in_range.contains(input_idx)) + for (int32_t in_c = 0; in_c < num_in_channels; ++in_c) { - auto kernel_region = kernel.getRegion(kernel_idx); - assert(kernel_region.size() == num_kernels); - - auto in = input.at(input_idx); + const T input_val = input_data[calcOffset(input_shape, batch, in_y, in_x, in_c)]; + const int32_t out_y_origin = in_y * strides[0] - padding_before[0]; + const int32_t out_x_origin = in_x * strides[1] - padding_before[1]; - for (int32_t kernel_index = 0; kernel_index < num_kernels; kernel_index++) + for (int32_t kernel_y = 0; kernel_y < kernel_height; ++kernel_y) { - out_region.base()[kernel_index] += in * kernel_region.base()[kernel_index]; + for (int32_t kernel_x = 0; kernel_x < kernel_width; ++kernel_x) + { + const int32_t out_y = out_y_origin + kernel_y; + const int32_t out_x = out_x_origin + kernel_x; + + if ((out_y >= 0 && out_y < output_height) && (out_x >= 0 && out_x < output_width)) + { + for (int32_t out_c = 0; out_c < num_out_channels; ++out_c) + { + const int32_t kernel_offset = + calcOffset(kernel_shape, in_c, kernel_y, kernel_x, out_c); + const int32_t output_offset = + calcOffset(output_shape, batch, out_y, out_x, out_c); + const T kernel_val = kernel_data[kernel_offset]; + output_data[output_offset] += input_val * kernel_val; + } + } + } } } } @@ -135,10 +113,10 @@ void DeConv2DImpl::run(const TensorVariant &input_var, const TensorVariant &k } } -void DeConv2D(const mir::TensorVariant &input, const mir::TensorVariant &kernel, - const mir::ops::DeConv2DOp &op, mir::TensorVariant &output) +void DeConv2D(const TensorVariant &input, const TensorVariant &kernel, + const Deconv2DOpAttributes &attributes, TensorVariant &output) { - dispatch(output.getElementType(), input, kernel, op, output); + dispatch(output.getElementType(), input, kernel, attributes, output); } } // namespace mir_interpreter diff --git a/compiler/mir-interpreter/src/ops/DeConv2D.h b/compiler/mir-interpreter/src/ops/DeConv2D.h index 04af17376b4..be797fcef08 100644 --- a/compiler/mir-interpreter/src/ops/DeConv2D.h +++ b/compiler/mir-interpreter/src/ops/DeConv2D.h @@ -17,7 +17,8 @@ #ifndef _NNC_CORE_BACKEND_INTERPRETER_DECONV2D_IMPL_ #define _NNC_CORE_BACKEND_INTERPRETER_DECONV2D_IMPL_ -#include "mir/ops/Deconv2DOp.h" +#include "mir/Attributes.h" +#include "mir/TensorVariant.h" namespace mir_interpreter { @@ -33,7 +34,7 @@ namespace mir_interpreter */ void DeConv2D(const mir::TensorVariant &input, const mir::TensorVariant &kernel, - const mir::ops::DeConv2DOp &op, mir::TensorVariant &output); + const mir::Deconv2DOpAttributes &attributes, mir::TensorVariant &output); } // namespace mir_interpreter diff --git a/compiler/mir-interpreter/src/ops/Reshape.cpp b/compiler/mir-interpreter/src/ops/Reshape.cpp new file mode 100644 index 00000000000..f29b261ced8 --- /dev/null +++ b/compiler/mir-interpreter/src/ops/Reshape.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2020 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 "Reshape.h" + +#include "mir/ShapeRange.h" + +#include + +namespace mir_interpreter +{ + +void Reshape(const mir::TensorVariant &input, mir::TensorVariant &output) +{ + assert(input.getShape().numElements() == output.getShape().numElements()); + + mir::ShapeRange input_range(input.getShape()); + auto in_iter = input_range.begin(); + const size_t elem_size = input.getElementSize(); + + for (const auto &out_index : mir::ShapeRange(output.getShape())) + std::memcpy(output.at(out_index), input.at(*in_iter++), elem_size); +} + +} // namespace mir_interpreter diff --git a/compiler/mir-interpreter/src/ops/Reshape.h b/compiler/mir-interpreter/src/ops/Reshape.h index 1e0009005b7..2da6411f67e 100644 --- a/compiler/mir-interpreter/src/ops/Reshape.h +++ b/compiler/mir-interpreter/src/ops/Reshape.h @@ -17,32 +17,12 @@ #ifndef _NNC_CORE_BACKEND_INTERPRETER_RESHAPE_IMPL_ #define _NNC_CORE_BACKEND_INTERPRETER_RESHAPE_IMPL_ -#include "mir/ShapeRange.h" #include "mir/TensorVariant.h" -#include - namespace mir_interpreter { -std::vector Reshape(const mir::TensorVariant &input, - const mir::Shape &output_shape) -{ - assert(input.getShape().numElements() == output_shape.numElements()); - mir::TensorType type(input.getElementType(), output_shape); - if (input.getType().isQuantized()) - type.setQuantization(input.getType().getQuantization()); - - mir::TensorVariant result(type); - mir::ShapeRange input_range(input.getShape()); - auto in_iter = input_range.begin(); - const size_t elem_size = input.getElementSize(); - - for (const auto &out_index : mir::ShapeRange(output_shape)) - std::memcpy(result.at(out_index), input.at(*in_iter++), elem_size); - - return {result}; -} +void Reshape(const mir::TensorVariant &input, mir::TensorVariant &output); } // namespace mir_interpreter diff --git a/compiler/mir-onnx-importer/ONNXHelpers.cpp b/compiler/mir-onnx-importer/ONNXHelpers.cpp index 768f9437fd2..f3a9d182dab 100644 --- a/compiler/mir-onnx-importer/ONNXHelpers.cpp +++ b/compiler/mir-onnx-importer/ONNXHelpers.cpp @@ -177,10 +177,10 @@ mir::Operation *foldConstants(mir::Graph *graph, mir::Operation *op) for (mir::Operation::Output *out : op->getInputs()) { auto *constant = static_cast(out->getNode()); - interpreter.setOutputTensors(*constant, {constant->getValue()}); + interpreter.setTensor(out, constant->getValue()); } op->accept(&interpreter); - mir::TensorVariant output = interpreter.getResult(op->getOutput(0)); + const mir::TensorVariant &output = interpreter.getTensor(op->getOutput(0)); return graph->create(output); } diff --git a/compiler/mir-onnx-importer/ONNXNodeConverterRegistry.test.cpp b/compiler/mir-onnx-importer/ONNXNodeConverterRegistry.test.cpp index a416a8d71a6..dfc3e4216dd 100644 --- a/compiler/mir-onnx-importer/ONNXNodeConverterRegistry.test.cpp +++ b/compiler/mir-onnx-importer/ONNXNodeConverterRegistry.test.cpp @@ -42,13 +42,13 @@ class NodeConverterRegsitryTest : public ::testing::Test TEST_F(NodeConverterRegsitryTest, existing_lookup_works) { auto res = registry.lookup("dummy", 1); - ASSERT_EQ(res, converterV1); + ASSERT_EQ(res, &converterV1); } TEST_F(NodeConverterRegsitryTest, skipped_lookup_works) { auto res = registry.lookup("dummy", 2); - ASSERT_EQ(res, converterV1); + ASSERT_EQ(res, &converterV1); } TEST_F(NodeConverterRegsitryTest, first_unknown_version_works) diff --git a/compiler/nnc/backends/interpreter/InterpreterBackend.cpp b/compiler/nnc/backends/interpreter/InterpreterBackend.cpp index 983b9e4b2b1..923a7cfc74e 100644 --- a/compiler/nnc/backends/interpreter/InterpreterBackend.cpp +++ b/compiler/nnc/backends/interpreter/InterpreterBackend.cpp @@ -142,29 +142,25 @@ void InterpreterBackend::run(mir::Graph *graph) for (const auto *input_op : graph->getInputs()) { - std::string tensor_name = input_op->getOutput(0)->getName(); + const Operation::Output *input = input_op->getOutput(0); + + std::string tensor_name = input->getName(); assert(!tensor_name.empty()); std::replace(tensor_name.begin(), tensor_name.end(), '/', '_'); std::string filename = _input_dir + "/" + tensor_name + ".dat"; - auto type = input_op->getOutput(0)->getType(); - // TODO Fix frontends to set input type - if (input_op->getOutput(0)->getElementType() == DataType::UNKNOWN) - { - type = TensorType(DataType::FLOAT32, type.getShape(), type.getQuantization()); - } - auto tensor = readTensorFromFile(filename, type); - interpreter.setOutputTensors(*input_op, {tensor}); + TensorVariant tensor = readTensorFromFile(filename, input->getType()); + interpreter.setTensor(input, std::move(tensor)); } graph->accept(&interpreter); for (const auto *output_op : graph->getOutputs()) { - const auto &tensor = interpreter.getResult(output_op->getInput(0)); const auto &output_name = output_op->getInput(0)->getName(); #ifdef NNC_HDF5_SUPPORTED + const auto &tensor = interpreter.getTensor(output_op->getInput(0)); writeTensorToHDF5File(tensor, output_name, _output_dir); #else std::cout << "Result <" << output_name << "> wasn't saved, due to lack of HDF5" << std::endl; diff --git a/compiler/nnc/backends/soft_backend/CPPGenerator.cpp b/compiler/nnc/backends/soft_backend/CPPGenerator.cpp index 815d9f3c4db..236881b807b 100644 --- a/compiler/nnc/backends/soft_backend/CPPGenerator.cpp +++ b/compiler/nnc/backends/soft_backend/CPPGenerator.cpp @@ -48,6 +48,7 @@ #include "cpp_pad.generated.h" #include "cpp_transpose.generated.h" #include "cpp_gather.generated.h" +#include "cpp_broadcast.generated.h" #include @@ -423,6 +424,7 @@ void CPPCodeGenerator::materializeCode(ostream &out, const ModelAnalyzer &ma, co out.write(cpp_conv_transpose, sizeof(cpp_conv_transpose)); out.write(cpp_transpose, sizeof(cpp_transpose)); out.write(cpp_gather, sizeof(cpp_gather)); + out.write(cpp_broadcast, sizeof(cpp_broadcast)); // Operations calls into all of the above out.write(cpp_operations, sizeof(cpp_operations)); // Below call into operations diff --git a/compiler/nnc/backends/soft_backend/ModelAnalyzer.cpp b/compiler/nnc/backends/soft_backend/ModelAnalyzer.cpp index 5c1c1d5559e..82e62b5310d 100644 --- a/compiler/nnc/backends/soft_backend/ModelAnalyzer.cpp +++ b/compiler/nnc/backends/soft_backend/ModelAnalyzer.cpp @@ -326,6 +326,8 @@ void ModelAnalyzer::visit(ops::FullyConnectedOp &op) appendOperationToInference(&op, "fullConnect"); } +void ModelAnalyzer::visit(ops::BroadcastOp &op) { appendOperationToInference(&op, "broadcast"); } + void ModelAnalyzer::visit(ops::CappedReluOp &op) { appendOperationToInference(&op, "cappedRelu"); } void ModelAnalyzer::visit(ops::InputOp &op) diff --git a/compiler/nnc/backends/soft_backend/ModelAnalyzer.h b/compiler/nnc/backends/soft_backend/ModelAnalyzer.h index c3ff17513ad..471c310116a 100644 --- a/compiler/nnc/backends/soft_backend/ModelAnalyzer.h +++ b/compiler/nnc/backends/soft_backend/ModelAnalyzer.h @@ -50,6 +50,7 @@ class ModelAnalyzer : public mir::Visitor void visit(mir::ops::AbsOp &) override; void visit(mir::ops::AddOp &op) override; void visit(mir::ops::AvgPool2DOp &op) override; + void visit(mir::ops::BroadcastOp &op) override; void visit(mir::ops::CappedReluOp &op) override; void visit(mir::ops::ConcatOp &op) override; void visit(mir::ops::ConstantOp &op) override; diff --git a/compiler/nnc/backends/soft_backend/SBSerializer.cpp b/compiler/nnc/backends/soft_backend/SBSerializer.cpp index b2d33d75155..96fa5158011 100644 --- a/compiler/nnc/backends/soft_backend/SBSerializer.cpp +++ b/compiler/nnc/backends/soft_backend/SBSerializer.cpp @@ -31,8 +31,8 @@ static_assert(std::numeric_limits::is_iec559, "Unsupported float type"); using namespace std; -using mir::Shape; using mir::Index; +using mir::Shape; using mir::ShapeRange; using mir::TensorVariant; @@ -202,6 +202,12 @@ void Serializer::visit(ops::FullyConnectedOp &op) serializeShape(op.getOutputShape(0)); } +void Serializer::visit(ops::BroadcastOp &op) +{ + _curOp->paramStartOffset = _buffer.size(); + serializeShape(op.getOutputShape(0)); +} + void Serializer::visit(ops::CappedReluOp &op) { _curOp->paramStartOffset = _buffer.size(); diff --git a/compiler/nnc/backends/soft_backend/SBSerializer.h b/compiler/nnc/backends/soft_backend/SBSerializer.h index 3048eb53309..98b9ce605fb 100644 --- a/compiler/nnc/backends/soft_backend/SBSerializer.h +++ b/compiler/nnc/backends/soft_backend/SBSerializer.h @@ -44,6 +44,7 @@ class Serializer : public mir::Visitor void visit(mir::ops::AbsOp &op) override; void visit(mir::ops::AddOp &op) override; void visit(mir::ops::AvgPool2DOp &op) override; + void visit(mir::ops::BroadcastOp &op) override; void visit(mir::ops::CappedReluOp &op) override; void visit(mir::ops::ConcatOp &op) override; void visit(mir::ops::ConstantOp &op) override; diff --git a/compiler/nnc/backends/soft_backend/code_snippets/cpp_broadcast.def b/compiler/nnc/backends/soft_backend/code_snippets/cpp_broadcast.def new file mode 100644 index 00000000000..1d170eb486b --- /dev/null +++ b/compiler/nnc/backends/soft_backend/code_snippets/cpp_broadcast.def @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved + * Copyright 2018 The TensorFlow Authors. 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. + */ + +template +inline void NdArrayDescForBroadcast(const RuntimeShape &input_shape, + const RuntimeShape &output_shape, NdArrayDesc *desc_out) +{ + TFLITE_DCHECK(desc_out != nullptr); + + auto extended_input_shape = RuntimeShape::ExtendedShape(N, input_shape); + auto extended_output_shape = RuntimeShape::ExtendedShape(N, output_shape); + + int desc_stride = 1; + for (int i = N - 1; i >= 0; --i) + { + desc_out->extents[i] = extended_input_shape.Dims(i); + desc_out->strides[i] = desc_stride; + desc_stride *= extended_input_shape.Dims(i); + } + + for (int i = 0; i < N; ++i) + { + const int extent0 = extended_input_shape.Dims(i); + const int extent1 = extended_output_shape.Dims(i); + if (extent0 != extent1) + { + TFLITE_DCHECK_EQ(extent0, 1); + desc_out->strides[i] = 0; + desc_out->extents[i] = extent1; + } + } +} + +void Broadcast4DSlow(const RuntimeShape &input_shape, const float *input_data, + const RuntimeShape &output_shape, float *output_data) +{ + TFLITE_DCHECK_LE(input_shape.DimensionsCount(), 4); + TFLITE_DCHECK_LE(output_shape.DimensionsCount(), 4); + const RuntimeShape extended_output_shape = RuntimeShape::ExtendedShape(4, output_shape); + + NdArrayDesc<4> desc; + NdArrayDescForBroadcast(input_shape, output_shape, &desc); + + for (int b = 0; b < extended_output_shape.Dims(0); ++b) + { + for (int y = 0; y < extended_output_shape.Dims(1); ++y) + { + for (int x = 0; x < extended_output_shape.Dims(2); ++x) + { + for (int c = 0; c < extended_output_shape.Dims(3); ++c) + { + auto out_idx = Offset(extended_output_shape, b, y, x, c); + auto in_idx = SubscriptToIndex(desc, b, y, x, c); + output_data[out_idx] = input_data[in_idx]; + } + } + } + } +} diff --git a/compiler/nnc/backends/soft_backend/code_snippets/cpp_operations.def b/compiler/nnc/backends/soft_backend/code_snippets/cpp_operations.def index ae5eb626a43..f78274e5cea 100644 --- a/compiler/nnc/backends/soft_backend/code_snippets/cpp_operations.def +++ b/compiler/nnc/backends/soft_backend/code_snippets/cpp_operations.def @@ -639,6 +639,15 @@ void gather(Tensor &out, const char *params, const Tensor &data, const Tensor &i shapeToRuntimeShape(out.getShape()), out.getData()); } +void broadcast(Tensor &out, const char *params, const Tensor &in) +{ + Shape out_shape = deserializeShape(params); + out.reshape(out_shape); + + Broadcast4DSlow(shapeToRuntimeShape(in.getShape()), in.getData(), + shapeToRuntimeShape(out_shape), out.getData()); +} + void constant(Tensor& out, const char* params) { out = deserializeTensor(params); } diff --git a/compiler/nnc/include/backends/interpreter/Interpreter.h b/compiler/nnc/include/backends/interpreter/Interpreter.h deleted file mode 100644 index 8e3758cd4f5..00000000000 --- a/compiler/nnc/include/backends/interpreter/Interpreter.h +++ /dev/null @@ -1,102 +0,0 @@ -/* - * 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 _NNC_BACKEND_INTERPRETER_CORE_INTERPRETER_ -#define _NNC_BACKEND_INTERPRETER_CORE_INTERPRETER_ - -#include "mir/Visitor.h" -#include "mir/Operation.h" -#include "mir/TensorVariant.h" -#include -#include -#include - -namespace nnc -{ - -class NNInterpreter : public mir::Visitor -{ -public: - explicit NNInterpreter() = default; - - ~NNInterpreter() override = default; - - void setInput(const std::string &name, const mir::TensorVariant &data); - - mir::TensorVariant getResult(const mir::Operation::Output *tensor); - - void visit(mir::ops::AddOp &op) override; - void visit(mir::ops::AvgPool2DOp &op) override; - void visit(mir::ops::CappedReluOp &op) override; - void visit(mir::ops::ConcatOp &op) override; - void visit(mir::ops::ConstantOp &op) override; - void visit(mir::ops::Conv2DOp &op) override; - void visit(mir::ops::DeConv2DOp &op) override; - void visit(mir::ops::DepthwiseConv2DOp &op) override; - void visit(mir::ops::DequantizeOp &op) override; - void visit(mir::ops::DivOp &op) override; - void visit(mir::ops::EluOp &op) override; - void visit(mir::ops::EqualOp &op) override; - void visit(mir::ops::FullyConnectedOp &op) override; - void visit(mir::ops::GatherOp &op) override; - void visit(mir::ops::GreaterOp &op) override; - void visit(mir::ops::HardSwishOp &op) override; - void visit(mir::ops::InputOp &op) override; - void visit(mir::ops::LeakyReluOp &op) override; - void visit(mir::ops::LessOp &op) override; - void visit(mir::ops::MaxOp &op) override; - void visit(mir::ops::MaxPool2DOp &op) override; - void visit(mir::ops::MulOp &op) override; - void visit(mir::ops::OutputOp &op) override; - void visit(mir::ops::PadOp &op) override; - void visit(mir::ops::QuantizeOp &op) override; - void visit(mir::ops::ReduceMeanOp &op) override; - void visit(mir::ops::ReluOp &op) override; - void visit(mir::ops::ReshapeOp &op) override; - void visit(mir::ops::ResizeOp &op) override; - void visit(mir::ops::SigmoidOp &op) override; - void visit(mir::ops::SliceOp &op) override; - void visit(mir::ops::SoftmaxOp &op) override; - void visit(mir::ops::SqrtOp &op) override; - void visit(mir::ops::SqueezeOp &op) override; - void visit(mir::ops::SubOp &op) override; - void visit(mir::ops::TanhOp &op) override; - void visit(mir::ops::TransposeOp &op) override; - -protected: - void visit_fallback(mir::Operation &op) override; - -private: - /// @brief Gets the computed inputs for the operation. - std::vector> - getInputTensors(const mir::Operation &op); - - std::vector> - getOutputTensors(const mir::Operation &op); - - /// @brief Saves the computed outputs for the operation. - void setOutputTensors(const mir::Operation &op, std::vector &&outputs); - - /// @brief Mapping of graph named inputs to their values. - std::unordered_map _inputTensors; - - /// @brief Mapping of operations to their computed results. - std::unordered_map> _opResults; -}; - -} // namespace nnc - -#endif //_NNC_BACKEND_INTERPRETER_CORE_INTERPRETER_ diff --git a/compiler/nnc/unittests/CMakeLists.txt b/compiler/nnc/unittests/CMakeLists.txt index 87b3de3b581..bbb6c7e67df 100644 --- a/compiler/nnc/unittests/CMakeLists.txt +++ b/compiler/nnc/unittests/CMakeLists.txt @@ -8,12 +8,3 @@ add_subdirectory(acl_backend) add_subdirectory(support) add_subdirectory(optimizations) add_subdirectory(transformations) -if(NNC_FRONTEND_CAFFE_ENABLED) - add_subdirectory(caffe_frontend) -endif() -if(NNC_FRONTEND_CAFFE2_ENABLED) - add_subdirectory(caffe2_frontend) -endif() -if(NNC_FRONTEND_TFLITE_ENABLED) - add_subdirectory(tflite_frontend) -endif() diff --git a/compiler/nnc/unittests/caffe2_frontend/CMakeLists.txt b/compiler/nnc/unittests/caffe2_frontend/CMakeLists.txt deleted file mode 100644 index 64d50282972..00000000000 --- a/compiler/nnc/unittests/caffe2_frontend/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -file(GLOB_RECURSE TESTS "*.cpp") - -execute_process( - COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test_data/gen_model.py ${CMAKE_CURRENT_BINARY_DIR} - OUTPUT_VARIABLE outp - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - RESULT_VARIABLE test_create_failed -) - -if (NOT ${test_create_failed}) - add_definitions(-DTEST_DIR="${CMAKE_CURRENT_BINARY_DIR}") - nnc_add_unit_test(nnc_caffe2_frontend_test ${TESTS}) - optional_target_link_libraries(nnc_caffe2_frontend_test mir_caffe2_importer mir) -endif() diff --git a/compiler/nnc/unittests/caffe2_frontend/test_data/gen_model.py b/compiler/nnc/unittests/caffe2_frontend/test_data/gen_model.py deleted file mode 100755 index 52f799731d8..00000000000 --- a/compiler/nnc/unittests/caffe2_frontend/test_data/gen_model.py +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/python3 - -import os -import sys - -try: - from caffe2.python import workspace, model_helper - from caffe2.python.predictor import mobile_exporter -except ImportError: - print("!! Caffe2 not installed, caffe2 frontend test not generated", file=sys.stderr) - exit(1) - - -def save_net(init_net_pb, predict_net_pb, model): - init_net, predict_net = mobile_exporter.Export(workspace, model.net, m.params) - with open(predict_net_pb, 'wb') as f: - f.write(model.net._net.SerializeToString()) - with open(init_net_pb, 'wb') as f: - f.write(init_net.SerializeToString()) - - -resDir = sys.argv[1] - -m = model_helper.ModelHelper(name='unsupported_net') -m.net.GivenTensorFill([], 'input_data', values=(1., ), shape=(1, )) -m.net.Sin(['input_data'], 'result') -save_net(os.path.join(resDir, 'init_net.pb'), os.path.join(resDir, 'predict_net.pb'), m) diff --git a/compiler/nnc/unittests/caffe2_frontend/unsupported_caffe2_model.cpp b/compiler/nnc/unittests/caffe2_frontend/unsupported_caffe2_model.cpp deleted file mode 100644 index 56e109b8a4b..00000000000 --- a/compiler/nnc/unittests/caffe2_frontend/unsupported_caffe2_model.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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 -#include - -#include -#include - -const char *ErrorMsg = "NNC can't load model. Detected problems:\n" - " * Sin: unknown layer"; - -// When adding support for new layers, change the model, not the test -TEST(CAFFE_IMPORT_UNSUPPORTED, ImportAModelWithUnsupportedLayers) -{ - - std::string predict_net = std::string(TEST_DIR) + "/predict_net.pb"; - std::string init_net = std::string(TEST_DIR) + "/init_net.pb"; - - try - { - mir_caffe2::loadModel(predict_net, init_net, {{1}}); - } - catch (std::exception &e) - { - ASSERT_EQ(std::string(ErrorMsg), e.what()); - return; - } - - FAIL(); -} diff --git a/compiler/nnc/unittests/caffe_frontend/CMakeLists.txt b/compiler/nnc/unittests/caffe_frontend/CMakeLists.txt deleted file mode 100644 index 74ed8f70bc8..00000000000 --- a/compiler/nnc/unittests/caffe_frontend/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -file(GLOB_RECURSE TESTS "*.cpp") - -add_definitions(-DTEST_DIR="${CMAKE_CURRENT_SOURCE_DIR}/test_data/") -nnc_add_unit_test(nnc_caffe_frontend_test ${TESTS}) -optional_target_link_libraries(nnc_caffe_frontend_test mir_caffe_importer mir) diff --git a/compiler/nnc/unittests/caffe_frontend/unsupported_caffe_model.cpp b/compiler/nnc/unittests/caffe_frontend/unsupported_caffe_model.cpp deleted file mode 100644 index 88d427fa978..00000000000 --- a/compiler/nnc/unittests/caffe_frontend/unsupported_caffe_model.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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 -#include - -#include -#include - -const char *ErrorMsg = "NNC can't load model. Detected problems:\n" - " * DummyData: unsupported layer\n" - " * LSTM: parameter 'expose_hidden' has unsupported value: 1\n" - " * UnexcitingLayerType: unknown layer"; - -// When adding support for new layers, change the model, not the test -TEST(CAFFE_IMPORT_UNSUPPORTED, ImportAModelWithUnsupportedLayers) -{ - std::string filename = std::string(TEST_DIR) + "unsupported.caffemodel"; - - try - { - mir_caffe::loadModel(filename); - } - catch (std::exception &e) - { - ASSERT_EQ(std::string(ErrorMsg), e.what()); - return; - } - - FAIL(); -} diff --git a/compiler/nnc/unittests/soft_backend/CPPOperations.cpp b/compiler/nnc/unittests/soft_backend/CPPOperations.cpp index 048ea2513d1..508ee954d97 100644 --- a/compiler/nnc/unittests/soft_backend/CPPOperations.cpp +++ b/compiler/nnc/unittests/soft_backend/CPPOperations.cpp @@ -26,6 +26,7 @@ #include "code_snippets/cpp_header_types.def" #include "code_snippets/cpp_common_funcs.def" +#include "code_snippets/cpp_broadcast.def" #include "code_snippets/cpp_capped_relu.def" #include "code_snippets/cpp_concat.def" #include "code_snippets/cpp_conv.def" @@ -59,6 +60,7 @@ #include "mir/ops/AbsOp.h" #include "mir/ops/AddOp.h" #include "mir/ops/AvgPool2DOp.h" +#include "mir/ops/BroadcastOp.h" #include "mir/ops/CappedReluOp.h" #include "mir/ops/ConcatOp.h" #include "mir/ops/ConstantOp.h" @@ -220,7 +222,7 @@ mir::TensorVariant getReferenceTensor(mir::Graph &g, mir::Operation *op) mir_interpreter::MIRInterpreter interpreter; g.accept(&interpreter); assert(op->getNumOutputs() == 1); - return interpreter.getResult(op->getOutput(0)); + return interpreter.getTensor(op->getOutput(0)); } /** @@ -986,3 +988,20 @@ TEST(cpp_operations_test, transpose) createAndRunTestGraph(op_generator, transpose, input_ntensor_3d, input_atensor_3d); } } + +TEST(cpp_operation_test, broadcast) +{ + const mir::Shape target_shapes[] = {{6}, {2, 3}, {2, 3, 1}, {1, 2, 1, 3}}; + for (const mir::Shape &target_shape : target_shapes) + { + vector input_shape_data{}; + vector> input_ntensors(1); + Tensor input_atensor; + fillTensors(input_ntensors[0], input_atensor, input_shape_data, 1.0f); + auto op_generator = [&target_shape](mir::Graph &g, + const std::vector &inputs) { + return g.create(inputs[0], target_shape); + }; + createAndRunTestGraph(op_generator, broadcast, input_ntensors, input_atensor); + } +} diff --git a/compiler/nnc/unittests/tflite_frontend/CMakeLists.txt b/compiler/nnc/unittests/tflite_frontend/CMakeLists.txt deleted file mode 100644 index 2613d21f3a1..00000000000 --- a/compiler/nnc/unittests/tflite_frontend/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -file(GLOB_RECURSE TESTS "*.cpp") - -#Feature detect: -execute_process( - COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test_data/gen_test.py ${CMAKE_CURRENT_BINARY_DIR} - OUTPUT_VARIABLE outp - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - RESULT_VARIABLE test_create_failed -) - -if (NOT ${test_create_failed}) - add_definitions(-DTFLITE_TEST_DIR="${CMAKE_CURRENT_BINARY_DIR}/") - nnc_add_unit_test(nnc_tflite_frontend_test ${TESTS}) - optional_target_link_libraries(nnc_tflite_frontend_test mir_tflite_importer mir) -endif() diff --git a/compiler/nnc/unittests/tflite_frontend/test_data/gen_test.py b/compiler/nnc/unittests/tflite_frontend/test_data/gen_test.py deleted file mode 100755 index 74a566d9b87..00000000000 --- a/compiler/nnc/unittests/tflite_frontend/test_data/gen_test.py +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/python3 -import sys -from distutils.version import LooseVersion, StrictVersion -try: - import numpy as np -except ImportError: - print( - "!! NumPy is not installed, tflite frontend test not generated", file=sys.stderr) - exit(1) -try: - import tensorflow as tf - if (LooseVersion(tf.VERSION) < LooseVersion("1.11.0")): - raise (Exception("Wrong Version")) -except: - print( - "!! Tensorflow v 1.11 not installed, tflite frontend test not generated", - file=sys.stderr) - exit(1) - -resDir = sys.argv[1] -if resDir[-1] != "/": resDir += "/" - -output_shape = [1, 28, 28, 1] -strides = [1, 1, 1, 1] -W = tf.constant(np.ones([7, 7, 1, 1]).astype(np.float32), name="ker_d") - -# Create the graph. -X = tf.placeholder(shape=[1, 28, 28, 1], name='input', dtype=tf.float32) -Y = tf.sin(X) - -out0 = tf.identity(Y, name="out") -# Filter the input image. -with tf.Session() as sess: - out = sess.run( - out0, feed_dict={"input:0": np.ones((1, 28, 28, 1)).astype(np.float32)}) - frozen_graphdef = tf.graph_util.convert_variables_to_constants( - sess, sess.graph_def, ["out"]) - converter = tf.contrib.lite.TocoConverter.from_session(sess, [X], [out0]) - tflite_model = converter.convert() - - open(resDir + "unsupported.tflite", "wb").write(tflite_model) diff --git a/compiler/nnc/unittests/tflite_frontend/unsupported_tflite_model.cpp b/compiler/nnc/unittests/tflite_frontend/unsupported_tflite_model.cpp deleted file mode 100644 index 4ba3a1e7a3b..00000000000 --- a/compiler/nnc/unittests/tflite_frontend/unsupported_tflite_model.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 -#include - -#include -#include - -const char *ErrorMsg = "NNC can't load model. Detected problems:\n" - " * SIN: unsupported operator"; - -// When adding support for new layers, change the model, not the test -TEST(TFLITE_IMPORT_UNSUPPORTED, ImportModelWithUnsupportedLayers) -{ - std::string filename = std::string(TFLITE_TEST_DIR) + "unsupported.tflite"; - std::cout << filename << "\n"; - - try - { - mir_tflite::loadModel(filename); - } - catch (std::exception &e) - { - ASSERT_EQ(std::string(ErrorMsg), e.what()); - return; - } - - FAIL(); -} diff --git a/compiler/nnc/utils/CMakeLists.txt b/compiler/nnc/utils/CMakeLists.txt index 32988669f7d..e5d96d00544 100644 --- a/compiler/nnc/utils/CMakeLists.txt +++ b/compiler/nnc/utils/CMakeLists.txt @@ -1,9 +1,3 @@ - -# -# "tflite_model_generator" is a generator random TFLite models. -# -add_subdirectory(tflite_model_generator) - # dumpers of NN models add_subdirectory(tflite_dot_dumper) add_subdirectory(caffe_dot_dumper) diff --git a/compiler/nnc/utils/caffe_model_maker/GenerateCaffeModels.py b/compiler/nnc/utils/caffe_model_maker/GenerateCaffeModels.py old mode 100644 new mode 100755 diff --git a/compiler/nnc/utils/caffe_model_maker/Pyloss.py b/compiler/nnc/utils/caffe_model_maker/Pyloss.py old mode 100644 new mode 100755 diff --git a/compiler/nnc/utils/infer_tests/infer_testcases.py b/compiler/nnc/utils/infer_tests/infer_testcases.py old mode 100644 new mode 100755 diff --git a/compiler/nnc/utils/infer_tests/res2bin.py b/compiler/nnc/utils/infer_tests/res2bin.py old mode 100644 new mode 100755 diff --git a/compiler/nnc/utils/model_runner/common_place.py b/compiler/nnc/utils/model_runner/common_place.py old mode 100644 new mode 100755 diff --git a/compiler/nnc/utils/model_runner/model_runner_caffe.py b/compiler/nnc/utils/model_runner/model_runner_caffe.py old mode 100644 new mode 100755 diff --git a/compiler/nnc/utils/model_runner/model_runner_caffe2.py b/compiler/nnc/utils/model_runner/model_runner_caffe2.py old mode 100644 new mode 100755 diff --git a/compiler/nnc/utils/model_runner/model_runner_onnx.py b/compiler/nnc/utils/model_runner/model_runner_onnx.py old mode 100644 new mode 100755 diff --git a/compiler/nnc/utils/model_runner/model_runner_tflite.py b/compiler/nnc/utils/model_runner/model_runner_tflite.py old mode 100644 new mode 100755 diff --git a/compiler/nnc/utils/prepare_inputs/jpeg2hdf5.py b/compiler/nnc/utils/prepare_inputs/jpeg2hdf5.py old mode 100644 new mode 100755 diff --git a/compiler/nnc/utils/tflite_model_generator/CMakeLists.txt b/compiler/nnc/utils/tflite_model_generator/CMakeLists.txt deleted file mode 100644 index a8eb460a351..00000000000 --- a/compiler/nnc/utils/tflite_model_generator/CMakeLists.txt +++ /dev/null @@ -1,26 +0,0 @@ -find_package(HDF5 COMPONENTS CXX QUIET) -if(NOT HDF5_FOUND) - message(WARNING "HDF5 not found, tflite_model_generator not available") - return() -endif(NOT HDF5_FOUND) - -nnas_find_package(FlatBuffers QUIET) -if(NOT FlatBuffers_FOUND) - message(WARNING "FlatBuffers not found, tflite_model_generator not available") - return() -endif(NOT FlatBuffers_FOUND) - -if (NOT TARGET tflite_schema) - message(WARNING "tflite_schema not found, tflite_model_generator not available") - return() -endif (NOT TARGET tflite_schema) - -set(TFLITE_MODEL_GENERATOR_SOURCES "ModelGenerator.cpp" "TFLiteRandomModelBuilder.cpp" "Tree.cpp") - -add_executable(tflite_model_generator ${TFLITE_MODEL_GENERATOR_SOURCES}) - -target_link_libraries(tflite_model_generator PRIVATE flatbuffers) -target_link_libraries(tflite_model_generator PRIVATE tflite_schema) -target_link_libraries(tflite_model_generator PRIVATE ${HDF5_CXX_LIBRARIES}) - -target_include_directories(tflite_model_generator PRIVATE ${HDF5_INCLUDE_DIRS}) diff --git a/compiler/nnc/utils/tflite_model_generator/Operator.def b/compiler/nnc/utils/tflite_model_generator/Operator.def deleted file mode 100644 index 4a3c373e953..00000000000 --- a/compiler/nnc/utils/tflite_model_generator/Operator.def +++ /dev/null @@ -1,128 +0,0 @@ -/* - * 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. - */ - -/* - * @Name -- 'char *' string with name of operator. - * @OpCode -- operator ID form enum. - * @CreatorFunc -- method of the RandomModelBuilder class for creation this operator. - * DEF_OPERATOR(Name, OpCode, CreatorFunc) - * - * Comments in this file is operations which are recommended for implementation. - * @todo: support not supported among the following set. - * - */ - -#ifndef DEF_OPERATOR -#define DEF_OPERATOR(Name, OpCode, TFLiteOpCode, CreatorFunc) -#endif -/* -DEF_OPERATOR("ADD", Op_ADD, tflite::BuiltinOperator::BuiltinOperator_ADD, createLayerADD ) -*/ -DEF_OPERATOR("CONV_2D", OpConv2d, tflite::BuiltinOperator::BuiltinOperator_CONV_2D, createLayerCONV_2D ) -DEF_OPERATOR("CONCATENATION", OpConcatenation, tflite::BuiltinOperator::BuiltinOperator_CONCATENATION, createLayerCONCATENATION ) -DEF_OPERATOR("DEPTHWISE_CONV_2D", OpDepthwiseConv2d, tflite::BuiltinOperator::BuiltinOperator_DEPTHWISE_CONV_2D, createLayerDEPTHWISE_CONV_2D ) -DEF_OPERATOR("MAX_POOL_2D", OpMaxPool2d, tflite::BuiltinOperator::BuiltinOperator_MAX_POOL_2D, createLayerX_POOL_2D ) -DEF_OPERATOR("AVERAGE_POOL_2D", OpAveragePool2d, tflite::BuiltinOperator::BuiltinOperator_AVERAGE_POOL_2D, createLayerX_POOL_2D ) -DEF_OPERATOR("SOFTMAX", OpSoftmax, tflite::BuiltinOperator::BuiltinOperator_SOFTMAX, createLayerSOFTMAX ) -DEF_OPERATOR("FULLY_CONNECTED", OpFullyConnected, tflite::BuiltinOperator::BuiltinOperator_FULLY_CONNECTED, createLayerFULLY_CONNECTED ) -/* -DEF_OPERATOR("DEQUANTIZE", Op_DEQUANTIZE, tflite::BuiltinOperator::BuiltinOperator_DEQUANTIZE, createLayerDEQUANTIZE ) -DEF_OPERATOR("EMBEDDING_LOOKUP", Op_EMBEDDING_LOOKUP, tflite::BuiltinOperator::BuiltinOperator_EMBEDDING_LOOKUP, createLayerEMBEDDING_LOOKUP ) -DEF_OPERATOR("FLOOR", Op_FLOOR, tflite::BuiltinOperator::BuiltinOperator_FLOOR, createLayerFLOOR ) -DEF_OPERATOR("HASHTABLE_LOOKUP", Op_HASHTABLE_LOOKUP, tflite::BuiltinOperator::BuiltinOperator_HASHTABLE_LOOKUP, createLayerHASHTABLE_LOOKUP ) -DEF_OPERATOR("L2_NORMALIZATION", Op_L2_NORMALIZATION, tflite::BuiltinOperator::BuiltinOperator_L2_NORMALIZATION, createLayerL2_NORMALIZATION ) -DEF_OPERATOR("L2_POOL_2D", Op_L2_POOL_2D, tflite::BuiltinOperator::BuiltinOperator_L2_POOL_2D, createLayerL2_POOL_2D ) -DEF_OPERATOR("LOCAL_RESPONSE_NORMALIZATION", Op_LOCAL_RESPONSE_NORMALIZATION,tflite::BuiltinOperator::BuiltinOperator_LOCAL_RESPONSE_NORMALIZATION, createLayerLOCAL_RESPONSE_NORMALIZATION) -DEF_OPERATOR("LOGISTIC", Op_LOGISTIC, tflite::BuiltinOperator::BuiltinOperator_LOGISTIC, createLayerLOGISTIC ) -DEF_OPERATOR("LSH_PROJECTION", Op_LSH_PROJECTION, tflite::BuiltinOperator::BuiltinOperator_LSH_PROJECTION, createLayerLSH_PROJECTION ) -DEF_OPERATOR("LSTM", Op_LSTM, tflite::BuiltinOperator::BuiltinOperator_LSTM, createLayerLSTM ) -DEF_OPERATOR("MUL", Op_MUL, tflite::BuiltinOperator::BuiltinOperator_MUL, createLayerMUL ) -DEF_OPERATOR("RELU", Op_RELU, tflite::BuiltinOperator::BuiltinOperator_RELU, createLayerRELU ) -DEF_OPERATOR("RELU_N1_TO_1", Op_RELU_N1_TO_1, tflite::BuiltinOperator::BuiltinOperator_RELU_N1_TO_1, createLayerRELU_N1_TO_1 ) -DEF_OPERATOR("RELU6", Op_RELU6, tflite::BuiltinOperator::BuiltinOperator_RELU6, createLayerRELU6 ) -DEF_OPERATOR("RESHAPE", Op_RESHAPE, tflite::BuiltinOperator::BuiltinOperator_RESHAPE, createLayerRESHAPE ) -DEF_OPERATOR("RESIZE_BILINEAR", Op_RESIZE_BILINEAR, tflite::BuiltinOperator::BuiltinOperator_RESIZE_BILINEAR, createLayerRESIZE_BILINEAR ) -DEF_OPERATOR("RNN", Op_RNN, tflite::BuiltinOperator::BuiltinOperator_RNN, createLayerRNN ) -DEF_OPERATOR("SPACE_TO_DEPTH", Op_SPACE_TO_DEPTH, tflite::BuiltinOperator::BuiltinOperator_SPACE_TO_DEPTH, createLayerSPACE_TO_DEPTH ) -DEF_OPERATOR("SVDF", Op_SVDF, tflite::BuiltinOperator::BuiltinOperator_SVDF, createLayerSVDF ) -DEF_OPERATOR("TANH", Op_TANH, tflite::BuiltinOperator::BuiltinOperator_TANH, createLayerTANH ) -DEF_OPERATOR("CONCAT_EMBEDDINGS", Op_CONCAT_EMBEDDINGS, tflite::BuiltinOperator::BuiltinOperator_CONCAT_EMBEDDINGS, createLayerCONCAT_EMBEDDINGS ) -DEF_OPERATOR("SKIP_GRAM", Op_SKIP_GRAM, tflite::BuiltinOperator::BuiltinOperator_SKIP_GRAM, createLayerSKIP_GRAM ) -DEF_OPERATOR("CALL", Op_CALL, tflite::BuiltinOperator::BuiltinOperator_CALL, createLayerCALL ) -DEF_OPERATOR("CUSTOM", Op_CUSTOM, tflite::BuiltinOperator::BuiltinOperator_CUSTOM, createLayerCUSTOM ) -DEF_OPERATOR("EMBEDDING_LOOKUP_SPARSE", Op_EMBEDDING_LOOKUP_SPARSE, tflite::BuiltinOperator::BuiltinOperator_EMBEDDING_LOOKUP_SPARSE, createLayerEMBEDDING_LOOKUP_SPARSE ) -DEF_OPERATOR("PAD", Op_PAD, tflite::BuiltinOperator::BuiltinOperator_PAD, createLayerPAD ) -DEF_OPERATOR("UNIDIRECTIONAL_SEQUENCE_RNN", Op_UNIDIRECTIONAL_SEQUENCE_RNN, tflite::BuiltinOperator::BuiltinOperator_UNIDIRECTIONAL_SEQUENCE_RNN, createLayerUNIDIRECTIONAL_SEQUENCE_RNN ) -DEF_OPERATOR("GATHER", Op_GATHER, tflite::BuiltinOperator::BuiltinOperator_GATHER, createLayerGATHER ) -DEF_OPERATOR("BATCH_TO_SPACE_ND", Op_BATCH_TO_SPACE_ND, tflite::BuiltinOperator::BuiltinOperator_BATCH_TO_SPACE_ND, createLayerBATCH_TO_SPACE_ND ) -DEF_OPERATOR("SPACE_TO_BATCH_ND", Op_SPACE_TO_BATCH_ND, tflite::BuiltinOperator::BuiltinOperator_SPACE_TO_BATCH_ND, createLayerSPACE_TO_BATCH_ND ) -DEF_OPERATOR("TRANSPOSE", Op_TRANSPOSE, tflite::BuiltinOperator::BuiltinOperator_TRANSPOSE, createLayerTRANSPOSE ) -DEF_OPERATOR("MEAN", Op_MEAN, tflite::BuiltinOperator::BuiltinOperator_MEAN, createLayerMEAN ) -DEF_OPERATOR("SUB", Op_SUB, tflite::BuiltinOperator::BuiltinOperator_SUB, createLayerSUB ) -DEF_OPERATOR("DIV", Op_DIV, tflite::BuiltinOperator::BuiltinOperator_DIV, createLayerDIV ) -DEF_OPERATOR("SQUEEZE", Op_SQUEEZE, tflite::BuiltinOperator::BuiltinOperator_SQUEEZE, createLayerSQUEEZE ) -DEF_OPERATOR("UNIDIRECTIONAL_SEQUENCE_LSTM", Op_UNIDIRECTIONAL_SEQUENCE_LSTM,tflite::BuiltinOperator::BuiltinOperator_UNIDIRECTIONAL_SEQUENCE_LSTM, createLayerUNIDIRECTIONAL_SEQUENCE_LSTM) -DEF_OPERATOR("STRIDED_SLICE", Op_STRIDED_SLICE, tflite::BuiltinOperator::BuiltinOperator_STRIDED_SLICE, createLayerSTRIDED_SLICE ) -DEF_OPERATOR("BIDIRECTIONAL_SEQUENCE_RNN", Op_BIDIRECTIONAL_SEQUENCE_RNN, tflite::BuiltinOperator::BuiltinOperator_BIDIRECTIONAL_SEQUENCE_RNN, createLayerBIDIRECTIONAL_SEQUENCE_RNN ) -DEF_OPERATOR("EXP", Op_EXP, tflite::BuiltinOperator::BuiltinOperator_EXP, createLayerEXP ) -DEF_OPERATOR("TOPK_V2", Op_TOPK_V2, tflite::BuiltinOperator::BuiltinOperator_TOPK_V2, createLayerTOPK_V2 ) -DEF_OPERATOR("SPLIT", Op_SPLIT, tflite::BuiltinOperator::BuiltinOperator_SPLIT, createLayerSPLIT ) -DEF_OPERATOR("LOG_SOFTMAX", Op_LOG_SOFTMAX, tflite::BuiltinOperator::BuiltinOperator_LOG_SOFTMAX, createLayerLOG_SOFTMAX ) -DEF_OPERATOR("DELEGATE", Op_DELEGATE, tflite::BuiltinOperator::BuiltinOperator_DELEGATE, createLayerDELEGATE ) -DEF_OPERATOR("BIDIRECTIONAL_SEQUENCE_LSTM", Op_BIDIRECTIONAL_SEQUENCE_LSTM, tflite::BuiltinOperator::BuiltinOperator_BIDIRECTIONAL_SEQUENCE_LSTM, createLayerBIDIRECTIONAL_SEQUENCE_LSTM ) -DEF_OPERATOR("CAST", Op_CAST, tflite::BuiltinOperator::BuiltinOperator_CAST, createLayerCAST ) -DEF_OPERATOR("PRELU", Op_PRELU, tflite::BuiltinOperator::BuiltinOperator_PRELU, createLayerPRELU ) -DEF_OPERATOR("MAXIMUM", Op_MAXIMUM, tflite::BuiltinOperator::BuiltinOperator_MAXIMUM, createLayerMAXIMUM ) -DEF_OPERATOR("ARG_MAX", Op_ARG_MAX, tflite::BuiltinOperator::BuiltinOperator_ARG_MAX, createLayerARG_MAX ) -DEF_OPERATOR("MINIMUM", Op_MINIMUM, tflite::BuiltinOperator::BuiltinOperator_MINIMUM, createLayerMINIMUM ) -DEF_OPERATOR("LESS", Op_LESS, tflite::BuiltinOperator::BuiltinOperator_LESS, createLayerLESS ) -DEF_OPERATOR("NEG", Op_NEG, tflite::BuiltinOperator::BuiltinOperator_NEG, createLayerNEG ) -DEF_OPERATOR("PADV2", Op_PADV2, tflite::BuiltinOperator::BuiltinOperator_PADV2, createLayerPADV2 ) -DEF_OPERATOR("GREATER", Op_GREATER, tflite::BuiltinOperator::BuiltinOperator_GREATER, createLayerGREATER ) -DEF_OPERATOR("GREATER_EQUAL", Op_GREATER_EQUAL, tflite::BuiltinOperator::BuiltinOperator_GREATER_EQUAL, createLayerGREATER_EQUAL ) -DEF_OPERATOR("LESS_EQUAL", Op_LESS_EQUAL, tflite::BuiltinOperator::BuiltinOperator_LESS_EQUAL, createLayerLESS_EQUAL ) -DEF_OPERATOR("SELECT", Op_SELECT, tflite::BuiltinOperator::BuiltinOperator_SELECT, createLayerSELECT ) -DEF_OPERATOR("SLICE", Op_SLICE, tflite::BuiltinOperator::BuiltinOperator_SLICE, createLayerSLICE ) -DEF_OPERATOR("SIN", Op_SIN, tflite::BuiltinOperator::BuiltinOperator_SIN, createLayerSIN ) -DEF_OPERATOR("TRANSPOSE_CONV", Op_TRANSPOSE_CONV, tflite::BuiltinOperator::BuiltinOperator_TRANSPOSE_CONV, createLayerTRANSPOSE_CONV ) -DEF_OPERATOR("SPARSE_TO_DENSE", Op_SPARSE_TO_DENSE, tflite::BuiltinOperator::BuiltinOperator_SPARSE_TO_DENSE, createLayerSPARSE_TO_DENSE ) -DEF_OPERATOR("TILE", Op_TILE, tflite::BuiltinOperator::BuiltinOperator_TILE, createLayerTILE ) -DEF_OPERATOR("EXPAND_DIMS", Op_EXPAND_DIMS, tflite::BuiltinOperator::BuiltinOperator_EXPAND_DIMS, createLayerEXPAND_DIMS ) -DEF_OPERATOR("EQUAL", Op_EQUAL, tflite::BuiltinOperator::BuiltinOperator_EQUAL, createLayerEQUAL ) -DEF_OPERATOR("NOT_EQUAL", Op_NOT_EQUAL, tflite::BuiltinOperator::BuiltinOperator_NOT_EQUAL, createLayerNOT_EQUAL ) -DEF_OPERATOR("LOG", Op_LOG, tflite::BuiltinOperator::BuiltinOperator_LOG, createLayerLOG ) -DEF_OPERATOR("SUM", Op_SUM, tflite::BuiltinOperator::BuiltinOperator_SUM, createLayerSUM ) -DEF_OPERATOR("SQRT", Op_SQRT, tflite::BuiltinOperator::BuiltinOperator_SQRT, createLayerSQRT ) -DEF_OPERATOR("RSQRT", Op_RSQRT, tflite::BuiltinOperator::BuiltinOperator_RSQRT, createLayerRSQRT ) -DEF_OPERATOR("SHAPE", Op_SHAPE, tflite::BuiltinOperator::BuiltinOperator_SHAPE, createLayerSHAPE ) -DEF_OPERATOR("POW", Op_POW, tflite::BuiltinOperator::BuiltinOperator_POW, createLayerPOW ) -DEF_OPERATOR("ARG_MIN", Op_ARG_MIN, tflite::BuiltinOperator::BuiltinOperator_ARG_MIN, createLayerARG_MIN ) -DEF_OPERATOR("FAKE_QUANT", Op_FAKE_QUANT, tflite::BuiltinOperator::BuiltinOperator_FAKE_QUANT, createLayerFAKE_QUANT ) -DEF_OPERATOR("REDUCE_PROD", Op_REDUCE_PROD, tflite::BuiltinOperator::BuiltinOperator_REDUCE_PROD, createLayerREDUCE_PROD ) -DEF_OPERATOR("REDUCE_MAX", Op_REDUCE_MAX, tflite::BuiltinOperator::BuiltinOperator_REDUCE_MAX, createLayerREDUCE_MAX ) -DEF_OPERATOR("PACK", Op_PACK, tflite::BuiltinOperator::BuiltinOperator_PACK, createLayerPACK ) -DEF_OPERATOR("LOGICAL_OR", Op_LOGICAL_OR, tflite::BuiltinOperator::BuiltinOperator_LOGICAL_OR, createLayerLOGICAL_OR ) -DEF_OPERATOR("ONE_HOT", Op_ONE_HOT, tflite::BuiltinOperator::BuiltinOperator_ONE_HOT, createLayerONE_HOT ) -DEF_OPERATOR("LOGICAL_AND", Op_LOGICAL_AND, tflite::BuiltinOperator::BuiltinOperator_LOGICAL_AND, createLayerLOGICAL_AND ) -DEF_OPERATOR("LOGICAL_NOT", Op_LOGICAL_NOT, tflite::BuiltinOperator::BuiltinOperator_LOGICAL_NOT, createLayerLOGICAL_NOT ) -DEF_OPERATOR("UNPACK", Op_UNPACK, tflite::BuiltinOperator::BuiltinOperator_UNPACK, createLayerUNPACK ) -DEF_OPERATOR("REDUCE_MIN", Op_REDUCE_MIN, tflite::BuiltinOperator::BuiltinOperator_REDUCE_MIN, createLayerREDUCE_MIN ) -DEF_OPERATOR("FLOOR_DIV", Op_FLOOR_DIV, tflite::BuiltinOperator::BuiltinOperator_FLOOR_DIV, createLayerFLOOR_DIV ) -DEF_OPERATOR("REDUCE_ANY", Op_REDUCE_ANY, tflite::BuiltinOperator::BuiltinOperator_REDUCE_ANY, createLayerREDUCE_ANY ) -DEF_OPERATOR("SQUARE", Op_SQUARE, tflite::BuiltinOperator::BuiltinOperator_SQUARE, createLayerSQUARE ) -DEF_OPERATOR("ZEROS_LIKE", Op_ZEROS_LIKE, tflite::BuiltinOperator::BuiltinOperator_ZEROS_LIKE, createLayerZEROS_LIKE ) -DEF_OPERATOR("FILL", Op_FILL, tflite::BuiltinOperator::BuiltinOperator_FILL, createLayerFILL ) -*/ diff --git a/compiler/nnc/utils/tflite_model_generator/RandomModelBuilder.h b/compiler/nnc/utils/tflite_model_generator/RandomModelBuilder.h deleted file mode 100644 index b6659a01ca4..00000000000 --- a/compiler/nnc/utils/tflite_model_generator/RandomModelBuilder.h +++ /dev/null @@ -1,135 +0,0 @@ -/* - * 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 RANDOM_MODELBUILDER_H -#define RANDOM_MODELBUILDER_H - -#include -#include -#include -#include - -#include "Tree.h" - -namespace modelgen -{ -/** - * @brief ModelSaver this class describes a common interface for saving model. - */ -class ModelSaver -{ -public: - ModelSaver() = default; - virtual ~ModelSaver() = default; - - /** - * @brief saveModel does export a owned model. - */ - virtual void saveModel() = 0; -}; - -/** - * @brief RandomModelBuilder this class describe a common interface for building - * random neural network models. - */ -class RandomModelBuilder -{ -public: - /** - * @brief constructor for RandomModelBuilder. - * @details Be careful, opCreators's initializer list should save the order - * from the OpCode enum. - */ - RandomModelBuilder() - : _operatorCounts{0}, _gen(_rd()), - _floatRand(std::numeric_limits::min(), std::numeric_limits::max()), - _intRand(static_cast(OpCodes::opFirst), static_cast(OpCodes::opLast)) - { - _opCreators[static_cast(OpCodes::opConv2d)] = - [this](treebuilder::Tree *t, treebuilder::Operation *op) { createLayerCONV_2D(t, op); }; - _opCreators[static_cast(OpCodes::opConcatenation)] = [this]( - treebuilder::Tree *t, treebuilder::Operation *op) { createLayerCONCATENATION(t, op); }; - _opCreators[static_cast(OpCodes::opDepthwiseConv2d)] = [this]( - treebuilder::Tree *t, treebuilder::Operation *op) { createLayerDEPTHWISE_CONV_2D(t, op); }; - _opCreators[static_cast(OpCodes::opOpMaxPool2d)] = [this](treebuilder::Tree *t, - treebuilder::Operation *op) { - createLayerX_POOL_2D(t, op, OpCodes::opOpMaxPool2d); - }; - _opCreators[static_cast(OpCodes::opAveragePool2d)] = [this](treebuilder::Tree *t, - treebuilder::Operation *op) { - createLayerX_POOL_2D(t, op, OpCodes::opAveragePool2d); - }; - _opCreators[static_cast(OpCodes::opSoftmax)] = - [this](treebuilder::Tree *t, treebuilder::Operation *op) { createLayerSOFTMAX(t, op); }; - _opCreators[static_cast(OpCodes::opFullyConnected)] = [this]( - treebuilder::Tree *t, treebuilder::Operation *op) { createLayerFULLY_CONNECTED(t, op); }; - }; - - virtual ~RandomModelBuilder() = default; - - virtual void convertTreeToModel(treebuilder::Tree *t) = 0; - - /** - * @brief getModelSaver does create unique_ptr to ModelSaver. - * @return unique_ptr to ModelSaver. - */ - virtual std::unique_ptr createModelSaver() = 0; - -protected: - /** - * @Brief createInput does add input tensor to model. - */ - virtual void createInput(treebuilder::Tree *t) = 0; - /** - * @brief addOperator does add a new layer to model. - */ - virtual void addOperator(treebuilder::Tree *t, treebuilder::Operation *op) = 0; - - /** - * @brief createLayerXXX are creator for operators. - * @param input_tensor_id is id of input tensor. - */ - virtual void createLayerCONV_2D(treebuilder::Tree *, treebuilder::Operation *) = 0; - virtual void createLayerCONCATENATION(treebuilder::Tree *t, treebuilder::Operation *op) = 0; - virtual void createLayerDEPTHWISE_CONV_2D(treebuilder::Tree *t, treebuilder::Operation *op) = 0; - virtual void createLayerX_POOL_2D(treebuilder::Tree *t, treebuilder::Operation *op, - OpCodes opcode) = 0; - virtual void createLayerSOFTMAX(treebuilder::Tree *t, treebuilder::Operation *op) = 0; - virtual void createLayerFULLY_CONNECTED(treebuilder::Tree *t, treebuilder::Operation *op) = 0; - - /** - * @brief opCreators this array contains a lambda with call of method - * for building specified operator. - * @details This array is used for convenient creation random operators, - * like follow: opCreators[OpCodes::opCount] - * For example: opCreators[OpCodes::opConv2d](0) -- will lead to call createLayerCONV_2D method. - */ - std::function - _opCreators[static_cast(OpCodes::opCount)]; - /** - * @brief operatorCounts this array contains amount of used operators in generated model. - * @details For example: operatorCounts[Op_CONV_2D] -- amount of used 2D convolution operators. - */ - int _operatorCounts[static_cast(OpCodes::opCount)]; - - std::random_device _rd; - std::mt19937 _gen; - std::uniform_real_distribution _floatRand; - std::uniform_int_distribution _intRand; -}; -} // namespace modelgen - -#endif // RANDOM_MODELBUILDER_H diff --git a/compiler/nnc/utils/tflite_model_generator/TFLiteRandomModelBuilder.cpp b/compiler/nnc/utils/tflite_model_generator/TFLiteRandomModelBuilder.cpp deleted file mode 100644 index 4347d2cfa05..00000000000 --- a/compiler/nnc/utils/tflite_model_generator/TFLiteRandomModelBuilder.cpp +++ /dev/null @@ -1,359 +0,0 @@ -/* - * 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 -#include - -#include "TFLiteRandomModelBuilder.h" - -namespace modelgen -{ -static const char *modelFileOut = "model.tflite"; -static const int notInitialized = -1; - -static const char *const opNames[] = { -#define DEF_OPERATOR(Name, OpCode, TFLiteOpCode, CreatorFunc) Name, -#include "Operator.def" -#undef DEF_OPERATOR -}; - -static const tflite::BuiltinOperator internalOpCode2TFLiteOpCode[]{ -#define DEF_OPERATOR(Name, OpCode, TFLiteOpCode, CreatorFunc) TFLiteOpCode, -#include "Operator.def" -#undef DEF_OPERATOR -}; - -void TFLiteModelSaver::saveModel() -{ - auto m = tflite::Model::Pack(_flatBufferBuilder, _model.get()); - tflite::FinishModelBuffer(_flatBufferBuilder, m); - - auto model_data = _flatBufferBuilder.GetBufferPointer(); - auto size = _flatBufferBuilder.GetSize(); - - std::string fileName(modelFileOut); - auto f = fopen(fileName.c_str(), "wb"); - assert(f != nullptr); - auto rlen = fwrite(model_data, size, 1, f); - assert(rlen == 1); - fclose(f); -} - -TFLiteRandomModelBuilder::TFLiteRandomModelBuilder() : RandomModelBuilder(), _model(new ModelT()) -{ - std::fill_n(_mapOperatorCode, static_cast(OpCodes::opCount), notInitialized); -} - -void TFLiteRandomModelBuilder::convertTreeToModel(treebuilder::Tree *t) -{ - createInput(t); - - for (auto &op : t->opList) - { - addOperator(t, op.get()); - } -} - -std::unique_ptr TFLiteRandomModelBuilder::createModelSaver() -{ - return std::unique_ptr(new TFLiteModelSaver(std::move(_model))); -} - -/** - * @todo Add support several inputs. - */ -void TFLiteRandomModelBuilder::createInput(treebuilder::Tree *t) -{ - assert(_model->subgraphs.empty() && "Subgraph is already created"); - - std::unique_ptr subgraph(new SubGraphT); - subgraph->inputs.push_back(0); - subgraph->outputs.push_back(0); - - subgraph->tensors.push_back(createEmptyTensor(t->inputShapeTree, "input")); - _operandTree2tensor.push_back(0); // it is same as: push_pack(subgraph->tensors.size() - 1); - - _model->subgraphs.push_back(std::move(subgraph)); - _model->description = "Random tflite model"; - _model->version = 3; -} - -void TFLiteRandomModelBuilder::addOperator(treebuilder::Tree *t, treebuilder::Operation *op) -{ - assert(!_model->subgraphs.empty() && "Subgraph is not created"); - - std::cout << "Add operator [" << opNames[static_cast(op->opcode)] << "] on the level [ " - << op->levelOwner << " ]" << std::endl; - _opCreators[static_cast(op->opcode)](t, op); - _model->subgraphs[0]->outputs[0] = (*_model->subgraphs[0]->operators.rbegin())->outputs[0]; -} - -void TFLiteRandomModelBuilder::createLayerCONV_2D(treebuilder::Tree *t, treebuilder::Operation *op) -{ - std::string output_name(opNames[static_cast(OpCodes::opConv2d)]); - output_name += "_" + std::to_string(_operatorCounts[static_cast(OpCodes::opConv2d)]); - auto operator_ptr = createEmptyOperator(op); - - auto out_tensor_ptr = createEmptyTensor(op->outputShape, output_name.c_str()); - auto kernel_ptr = createTensorWthBuffer(op->kernelShape, "Kernel"); - auto bias_ptr = createTensorWthBuffer({op->outputShape[3]}, "bias"); - - auto input_tensor_id = op->levelOwner == 0 ? _operandTree2tensor[0] - : _operandTree2tensor[t->inputCnt + op->inputs[0]]; - - operator_ptr->inputs.push_back(input_tensor_id); - operator_ptr->inputs.push_back(static_cast(_model->subgraphs[0]->tensors.size())); - _model->subgraphs[0]->tensors.push_back(std::move(kernel_ptr)); - operator_ptr->inputs.push_back(static_cast(_model->subgraphs[0]->tensors.size())); - _model->subgraphs[0]->tensors.push_back(std::move(bias_ptr)); - - auto output_tensor_id = static_cast(_model->subgraphs[0]->tensors.size()); - _operandTree2tensor.push_back(output_tensor_id); - operator_ptr->outputs.push_back(output_tensor_id); - _model->subgraphs[0]->tensors.push_back(std::move(out_tensor_ptr)); - - operator_ptr->builtin_options.Set(tflite::Conv2DOptionsT()); - auto conv2D_opt = operator_ptr->builtin_options.AsConv2DOptions(); - conv2D_opt->stride_w = conv2D_opt->stride_h = 1; - conv2D_opt->fused_activation_function = - tflite::ActivationFunctionType::ActivationFunctionType_RELU6; - - _model->subgraphs[0]->operators.push_back(std::move(operator_ptr)); -} - -void TFLiteRandomModelBuilder::createLayerCONCATENATION(treebuilder::Tree *t, - treebuilder::Operation *op) -{ - std::string output_name(opNames[static_cast(OpCodes::opConcatenation)]); - output_name += - "_" + std::to_string(_operatorCounts[static_cast(OpCodes::opConcatenation)]); - auto operator_ptr = createEmptyOperator(op); - - auto out_tensor_ptr = createEmptyTensor(op->outputShape, output_name.c_str()); - - std::cout << "Concatination inputs [ "; - for (auto it : op->inputs) - { - std::cout << it << "/"; - auto input_tensor_id = - op->levelOwner == 0 ? _operandTree2tensor[0] : _operandTree2tensor[t->inputCnt + it]; - std::cout << input_tensor_id << " "; - operator_ptr->inputs.push_back(input_tensor_id); - } - std::cout << "]" << std::endl; - - auto output_tensor_id = static_cast(_model->subgraphs[0]->tensors.size()); - _operandTree2tensor.push_back(output_tensor_id); - operator_ptr->outputs.push_back(output_tensor_id); - _model->subgraphs[0]->tensors.push_back(std::move(out_tensor_ptr)); - - operator_ptr->builtin_options.Set(tflite::ConcatenationOptionsT()); - auto concat_opt = operator_ptr->builtin_options.AsConcatenationOptions(); - concat_opt->fused_activation_function = - tflite::ActivationFunctionType::ActivationFunctionType_RELU6; - concat_opt->axis = 0; - - for (auto it : op->inputShape) - { - if (it == -1) - break; - concat_opt->axis++; - } - - _model->subgraphs[0]->operators.push_back(std::move(operator_ptr)); -} - -void TFLiteRandomModelBuilder::createLayerDEPTHWISE_CONV_2D(treebuilder::Tree *t, - treebuilder::Operation *op) -{ - std::string output_name(opNames[static_cast(OpCodes::opDepthwiseConv2d)]); - output_name += - "_" + std::to_string(_operatorCounts[static_cast(OpCodes::opDepthwiseConv2d)]); - auto operator_ptr = createEmptyOperator(op); - - auto out_tensor_ptr = createEmptyTensor(op->outputShape, output_name.c_str()); - auto kernel_ptr = createTensorWthBuffer(op->kernelShape, "Kernel"); - auto bias_ptr = createTensorWthBuffer({op->outputShape[3]}, "bias"); - - auto input_tensor_id = op->levelOwner == 0 ? _operandTree2tensor[0] - : _operandTree2tensor[t->inputCnt + op->inputs[0]]; - - operator_ptr->inputs.push_back(input_tensor_id); - operator_ptr->inputs.push_back(static_cast(_model->subgraphs[0]->tensors.size())); - _model->subgraphs[0]->tensors.push_back(std::move(kernel_ptr)); - operator_ptr->inputs.push_back(static_cast(_model->subgraphs[0]->tensors.size())); - _model->subgraphs[0]->tensors.push_back(std::move(bias_ptr)); - - auto output_tensor_id = static_cast(_model->subgraphs[0]->tensors.size()); - _operandTree2tensor.push_back(output_tensor_id); - operator_ptr->outputs.push_back(output_tensor_id); - _model->subgraphs[0]->tensors.push_back(std::move(out_tensor_ptr)); - - operator_ptr->builtin_options.Set(tflite::DepthwiseConv2DOptionsT()); - auto depthwise_conv2d_opt = operator_ptr->builtin_options.AsDepthwiseConv2DOptions(); - depthwise_conv2d_opt->stride_w = depthwise_conv2d_opt->stride_h = 1; - depthwise_conv2d_opt->depth_multiplier = 1; - depthwise_conv2d_opt->fused_activation_function = - tflite::ActivationFunctionType::ActivationFunctionType_RELU6; - - _model->subgraphs[0]->operators.push_back(std::move(operator_ptr)); -} - -void TFLiteRandomModelBuilder::createLayerX_POOL_2D(treebuilder::Tree *t, - treebuilder::Operation *op, OpCodes opcode) -{ - std::string output_name(opNames[static_cast(opcode)]); - output_name += "_" + std::to_string(_operatorCounts[static_cast(opcode)]); - auto operator_ptr = createEmptyOperator(op); - - auto out_tensor_ptr = createEmptyTensor(op->outputShape, output_name.c_str()); - - auto input_tensor_id = op->levelOwner == 0 ? _operandTree2tensor[0] - : _operandTree2tensor[t->inputCnt + op->inputs[0]]; - operator_ptr->inputs.push_back(input_tensor_id); - - auto output_tensor_id = static_cast(_model->subgraphs[0]->tensors.size()); - _operandTree2tensor.push_back(output_tensor_id); - operator_ptr->outputs.push_back(output_tensor_id); - _model->subgraphs[0]->tensors.push_back(std::move(out_tensor_ptr)); - - /** - * @todo generate random filter width/height. - */ - operator_ptr->builtin_options.Set(tflite::Pool2DOptionsT()); - auto pool2d_opt = operator_ptr->builtin_options.AsPool2DOptions(); - pool2d_opt->stride_w = pool2d_opt->stride_h = 1; - pool2d_opt->filter_width = pool2d_opt->filter_height = 3; - - _model->subgraphs[0]->operators.push_back(std::move(operator_ptr)); -} - -void TFLiteRandomModelBuilder::createLayerSOFTMAX(treebuilder::Tree *t, treebuilder::Operation *op) -{ - std::string output_name(opNames[static_cast(OpCodes::opSoftmax)]); - output_name += "_" + std::to_string(_operatorCounts[static_cast(OpCodes::opSoftmax)]); - auto operator_ptr = createEmptyOperator(op); - - auto out_tensor_ptr = createEmptyTensor(op->outputShape, output_name.c_str()); - - auto input_tensor_id = op->levelOwner == 0 ? _operandTree2tensor[0] - : _operandTree2tensor[t->inputCnt + op->inputs[0]]; - operator_ptr->inputs.push_back(input_tensor_id); - - auto output_tensor_id = static_cast(_model->subgraphs[0]->tensors.size()); - _operandTree2tensor.push_back(output_tensor_id); - operator_ptr->outputs.push_back(output_tensor_id); - _model->subgraphs[0]->tensors.push_back(std::move(out_tensor_ptr)); - - operator_ptr->builtin_options.Set(tflite::SoftmaxOptionsT()); - auto softmax_opt = operator_ptr->builtin_options.AsSoftmaxOptions(); - softmax_opt->beta = _floatRand(_gen); - - _model->subgraphs[0]->operators.push_back(std::move(operator_ptr)); -} - -void TFLiteRandomModelBuilder::createLayerFULLY_CONNECTED(treebuilder::Tree *t, - treebuilder::Operation *op) -{ - std::string output_name(opNames[static_cast(OpCodes::opFullyConnected)]); - output_name += - "_" + std::to_string(_operatorCounts[static_cast(OpCodes::opFullyConnected)]); - auto operator_ptr = createEmptyOperator(op); - - auto out_tensor_ptr = createEmptyTensor(op->outputShape, output_name.c_str()); - auto kernel_ptr = createTensorWthBuffer(op->kernelShape, "Kernel"); - auto bias_ptr = createTensorWthBuffer({op->outputShape[3]}, "bias"); - - auto input_tensor_id = op->levelOwner == 0 ? _operandTree2tensor[0] - : _operandTree2tensor[t->inputCnt + op->inputs[0]]; - - operator_ptr->inputs.push_back(input_tensor_id); - operator_ptr->inputs.push_back(static_cast(_model->subgraphs[0]->tensors.size())); - _model->subgraphs[0]->tensors.push_back(std::move(kernel_ptr)); - operator_ptr->inputs.push_back(static_cast(_model->subgraphs[0]->tensors.size())); - _model->subgraphs[0]->tensors.push_back(std::move(bias_ptr)); - - auto output_tensor_id = static_cast(_model->subgraphs[0]->tensors.size()); - _operandTree2tensor.push_back(output_tensor_id); - operator_ptr->outputs.push_back(output_tensor_id); - _model->subgraphs[0]->tensors.push_back(std::move(out_tensor_ptr)); - - operator_ptr->builtin_options.Set(tflite::FullyConnectedOptionsT()); - auto fullcon_opt = operator_ptr->builtin_options.AsFullyConnectedOptions(); - fullcon_opt->fused_activation_function = - tflite::ActivationFunctionType::ActivationFunctionType_RELU6; - - _model->subgraphs[0]->operators.push_back(std::move(operator_ptr)); -} - -std::unique_ptr -TFLiteRandomModelBuilder::createEmptyTensor(const std::vector &shape, const char *name) -{ - auto tensor_ptr = std::unique_ptr(new TensorT); - - tensor_ptr->type = tflite::TensorType_FLOAT32; - tensor_ptr->name = name; - tensor_ptr->shape = shape; - tensor_ptr->buffer = static_cast(_model->buffers.size()); - _model->buffers.push_back(std::unique_ptr(new BufferT)); - - return tensor_ptr; -} - -std::unique_ptr -TFLiteRandomModelBuilder::createTensorWthBuffer(const std::vector &shape, const char *name) -{ - auto tensor_ptr = createEmptyTensor(shape, name); - - size_t buffer_size = 1; - for (auto s : shape) - { - buffer_size *= s; - } - buffer_size *= sizeof(float); - - _model->buffers[tensor_ptr->buffer]->data.resize(buffer_size); - - for (size_t i = 0; i < buffer_size; i += sizeof(float)) - { - float val = _floatRand(_gen); - memcpy(_model->buffers[tensor_ptr->buffer]->data.data() + i, &val, sizeof(float)); - } - return tensor_ptr; -} - -std::unique_ptr TFLiteRandomModelBuilder::createEmptyOperator(treebuilder::Operation *op) -{ - auto operator_ptr = std::unique_ptr(new OperatorT); - auto opcode_id = _mapOperatorCode[static_cast(op->opcode)]; - auto tflite_opcode = internalOpCode2TFLiteOpCode[static_cast(op->opcode)]; - - if (opcode_id == notInitialized) - { - auto opcode_ptr = std::unique_ptr(new OperatorCodeT); - opcode_ptr->builtin_code = tflite_opcode; - opcode_ptr->custom_code = tflite::EnumNamesBuiltinOperator()[tflite_opcode]; - opcode_id = static_cast(_model->operator_codes.size()); - _model->operator_codes.push_back(std::move(opcode_ptr)); - _mapOperatorCode[static_cast(op->opcode)] = opcode_id; - } - operator_ptr->opcode_index = static_cast(opcode_id); - _operatorCounts[static_cast(op->opcode)]++; - - return operator_ptr; -} - -} // namespace modelgen diff --git a/compiler/nnc/utils/tflite_model_generator/TFLiteRandomModelBuilder.h b/compiler/nnc/utils/tflite_model_generator/TFLiteRandomModelBuilder.h deleted file mode 100644 index 38ff7bdb3f1..00000000000 --- a/compiler/nnc/utils/tflite_model_generator/TFLiteRandomModelBuilder.h +++ /dev/null @@ -1,118 +0,0 @@ -/* - * 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 TFLITEBUILDER_H -#define TFLITEBUILDER_H - -#include -#include - -#include "Tree.h" -#include "RandomModelBuilder.h" -#include "schema_generated.h" - -namespace modelgen -{ -using namespace tflite; - -/** - * @brief TFLiteModelSaver contains the unique_ptr to model and does convertation of model - * to FlatBuffer format and it's saving. - */ -class TFLiteModelSaver : public ModelSaver -{ -public: - TFLiteModelSaver() = default; - ~TFLiteModelSaver() override = default; - - TFLiteModelSaver(std::unique_ptr &&m) : ModelSaver(), _model(std::move(m)) {} - - void saveModel() override; - -private: - flatbuffers::FlatBufferBuilder _flatBufferBuilder; - std::unique_ptr _model; -}; - -/** - * @brief TFLiteRandomModelBuilder does build random TFLiteModel - * and gives unique_ptr to ModelSaver for export it to file. - */ -class TFLiteRandomModelBuilder : public RandomModelBuilder -{ -public: - TFLiteRandomModelBuilder(); - ~TFLiteRandomModelBuilder() override = default; - - void convertTreeToModel(treebuilder::Tree *t) override; - - std::unique_ptr createModelSaver() override; - -protected: - void createInput(treebuilder::Tree *t) override; - void addOperator(treebuilder::Tree *t, treebuilder::Operation *op) override; - /** - * Operations: - */ - void createLayerCONV_2D(treebuilder::Tree *t, treebuilder::Operation *op) override; - void createLayerCONCATENATION(treebuilder::Tree *t, treebuilder::Operation *op) override; - void createLayerDEPTHWISE_CONV_2D(treebuilder::Tree *t, treebuilder::Operation *op) override; - void createLayerX_POOL_2D(treebuilder::Tree *t, treebuilder::Operation *op, - OpCodes opcode) override; - void createLayerSOFTMAX(treebuilder::Tree *t, treebuilder::Operation *op) override; - void createLayerFULLY_CONNECTED(treebuilder::Tree *t, treebuilder::Operation *op) override; - -private: - /** - * @brief createEmptyTensor does create tensor without buffer - * and add it to tensors array of SubGraphT. - * @param shape is a shape of tensor. - * @param name is a name of tensor. - * @return unique_ptr to created tensor. - */ - std::unique_ptr createEmptyTensor(const std::vector &shape, const char *name); - /** - * @brief createTensorWthBuffer does create tensor with buffer - * and add it to tensors array of SubGraphT. - * @param shape is a shape of tensor. - * @param name is a name of tensor. - * @return unique_ptr to created tensor. - */ - std::unique_ptr createTensorWthBuffer(const std::vector &shape, - const char *name); - /** - * @brief createEmptyOperator does create operator without tensors and - * add operator to operators array of SubGraphT - * @param opcode is operator's code. - * @return unique_ptr to created operator. - */ - std::unique_ptr createEmptyOperator(treebuilder::Operation *op); - - std::unique_ptr _model; - /** - * @details This vector contains a index of tensor (in subgraph tflite vector) - * for output operand of tree's node `i`. - */ - std::vector _operandTree2tensor; - - /** - * @brief mapOperatorCode contains indexes to operator_codes array in ModelT. - */ - int32_t _mapOperatorCode[static_cast(OpCodes::opCount)]; -}; -} // namespace modelgen - -#endif // TFLITEBUILDER_H diff --git a/compiler/nnc/utils/tflite_model_generator/Tree.cpp b/compiler/nnc/utils/tflite_model_generator/Tree.cpp deleted file mode 100644 index 79620baa7c4..00000000000 --- a/compiler/nnc/utils/tflite_model_generator/Tree.cpp +++ /dev/null @@ -1,389 +0,0 @@ -/* - * 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 -#include - -#include "Tree.h" - -namespace modelgen -{ -namespace treebuilder -{ - -static constexpr int levelsMin = 1; -static constexpr int levelsMax = 15; -static constexpr int widthMin = 1; -static constexpr int widthMax = 10; -static constexpr int shapeMin = 1; -static constexpr int shapeMax = 64; -static constexpr int concatCntInputsMin = 4; -static constexpr int concatCntInputsMax = 8; -static constexpr int depthwiseConv2dMultiply = 4; -static constexpr int fullyConnectedMaxWeight = 8; -static constexpr int fullyConnectedKernelDim = 2; - -TreeBuilder::TreeBuilder() : _gen(_rd()) {} - -std::unique_ptr TreeBuilder::buildTree() -{ - std::uniform_int_distribution int_rand(levelsMin, levelsMax); - auto t = std::unique_ptr(new Tree); - t->inputCnt = 1; - t->hTree = int_rand(_gen); - initTree(t.get()); - - std::cout << "Build " << t->hTree << " levels in tree" << std::endl; - for (int i = 1; i < t->hTree; i++) - { - buildLevel(t.get()); - } - - std::cout << "operations count " << t->opList.end() - t->opList.begin() << std::endl; - std::cout << "levels count " << t->widthLevel.end() - t->widthLevel.begin() << std::endl; - - return t; -} - -void TreeBuilder::buildLevel(Tree *t) -{ - std::uniform_int_distribution int_rand(widthMin, widthMax); - auto levelId = t->widthLevel.size(); - auto levelWidth = int_rand(_gen); - t->widthLevel.push_back(static_cast(levelWidth)); - t->beginLevel.push_back(static_cast(t->opList.size())); - t->endLevel.push_back(static_cast(t->opList.size() + levelWidth - 1)); - - for (int32_t i = 0; i < levelWidth; i++) - { - auto op = std::unique_ptr(new Operation); - op->levelOwner = levelId; - /** - * If the operation was not created, then repeat the creation. - */ - if (!buildSketchOperation(t, op.get())) - { - i--; - continue; - } - t->opList.push_back(std::move(op)); - } -} - -void TreeBuilder::initTree(Tree *t) -{ - std::uniform_int_distribution int_rand(shapeMin, shapeMax); - - std::cout << "Build first level in tree" << std::endl; - - t->widthLevel.push_back(int_rand(_gen)); - t->beginLevel.push_back(0); - t->endLevel.push_back(0); - int32_t x = int_rand(_gen) * 2, y = int_rand(_gen) * 2, z = int_rand(_gen) % 8 + 1; - t->inputShapeTree = {1, x, y, z}; - - std::cout << "Initialize first level with width = [ " << t->widthLevel[0] << " ]" - << " and shape [ 1" - << " " << x << " " << y << " " << z << " ]" << std::endl; - for (int32_t i = 0; i < t->widthLevel[0]; i++) - { - auto op = std::unique_ptr(new Operation); - op->levelOwner = 0; - /** - * If the operation was not created, then repeat the creation. - */ - if (!buildSketchOperation(t, op.get())) - { - i--; - continue; - } - t->opList.push_back(std::move(op)); - } -} - -bool TreeBuilder::buildSketchOperation(Tree *t, Operation *op) -{ - std::uniform_int_distribution opcode_rand(static_cast(OpCodes::opFirst), - static_cast(OpCodes::opLast)); - - op->opcode = static_cast(opcode_rand(_gen)); - switch (op->opcode) - { - case OpCodes::opConv2d: - buildSketchConv2D(t, op); - break; - case OpCodes::opConcatenation: - buildSketchConcat(t, op); - break; - case OpCodes::opDepthwiseConv2d: - buildSketchDepthwiseConv2D(t, op); - break; - case OpCodes::opOpMaxPool2d: - case OpCodes::opAveragePool2d: - buildSketchPooling(t, op); - break; - case OpCodes::opSoftmax: - buildSketchSoftmax(t, op); - break; - case OpCodes::opFullyConnected: - /** - * Currently, we can create fullyconnected operation only on last level. - * @todo fix it. - */ - if (t->beginLevel.size() != static_cast(t->hTree)) - { - return false; - } - - buildSketchFullyConnected(t, op); - break; - default: - assert(false && "TreeBuilder: Unsupported operation"); - } - - return true; -} - -void TreeBuilder::buildSketchConv2D(Tree *t, Operation *op) -{ - std::uniform_int_distribution int_rand(0, INT32_MAX); - - if (t->beginLevel.size() == 1) - { - op->inputShape = t->inputShapeTree; - buildSketchConv2DForShape(op->inputShape, op); - return; - } - - auto levelId = int_rand(_gen) % (t->beginLevel.size() - 1); - auto opId = t->beginLevel[levelId] + (int_rand(_gen) % t->widthLevel[levelId]); - - std::cout << "input level [ " << levelId << " ] operation id [ " << opId << " ]" << std::endl; - - op->inputs.push_back(opId); - op->levelOwner = t->beginLevel.size() - 1; - op->inputShape = t->opList[opId]->outputShape; - buildSketchConv2DForShape(op->inputShape, op); -} - -void TreeBuilder::buildSketchConcat(Tree *t, Operation *op) -{ - std::uniform_int_distribution int_rand(2, INT32_MAX); - auto axis = 1 + (int_rand(_gen) + 3) % 3; - auto input_cnt = concatCntInputsMin + int_rand(_gen) % concatCntInputsMax; - - /* Special case if there are only one level (input to neural network) */ - if (t->beginLevel.size() == 1) - { - op->inputShape = t->inputShapeTree; - op->outputShape = op->inputShape; - for (int i = 0; i < input_cnt; i++) - { - op->inputs.push_back(-1); /* -1 means that it is needed to specify amount inputs - * on the first level where input tensor for operation - * is a input tensor for neural network. */ - addConcatInput(op->inputShape, axis, op); - } - op->inputShape[axis] = -1; /* specify a dimension for concatenation. */ - return; - } - - /* Select the first operand */ - auto levelId = int_rand(_gen) % (t->beginLevel.size() - 1); - auto opId = t->beginLevel[levelId] + (int_rand(_gen) % t->widthLevel[levelId]); - std::cout << "input level [ " << levelId << " ] operation id [ " << opId << " ]" << std::endl; - - op->inputs.push_back(opId); - op->levelOwner = t->beginLevel.size() - 1; - op->inputShape = t->opList[opId]->outputShape; - op->outputShape = op->inputShape; - std::vector shape = op->inputShape; - shape[axis] = -1; - for (int i = 0; i < input_cnt; i++) - { - opId = lookupConsistentOutput(t, op, shape, t->beginLevel.size() - 1); - op->inputs.push_back(opId); - addConcatInput(t->opList[opId]->outputShape, axis, op); - } - - op->inputShape[axis] = -1; /* specify a dimension for concatenation. */ -} - -void TreeBuilder::buildSketchDepthwiseConv2D(Tree *t, Operation *op) -{ - std::uniform_int_distribution int_rand(1, INT32_MAX); - /** - * Currently, on the stage of building arbitrary tree it is enough - * build DepthwiseConv2D node as Conv2D. - * @todo: maby there is sense to specifically create OpDepthwiseConv2d. - */ - buildSketchConv2D(t, op); - - /** - * Then change the kernel's shape. - */ - op->kernelShape[0] = int_rand(_gen) % depthwiseConv2dMultiply + 1; /* channel multiplier */ - op->kernelShape[1] = op->inputShape[3]; /* filter height */ - op->kernelShape[2] = op->inputShape[2]; /* filter width */ - op->kernelShape[3] = op->inputShape[3]; /* input channels */ - op->outputShape[3] = op->kernelShape[0] * op->kernelShape[3]; -} - -void TreeBuilder::buildSketchPooling(Tree *t, Operation *op) -{ - std::uniform_int_distribution int_rand(2, INT32_MAX); - - if (t->beginLevel.size() == 1) - { - op->inputShape = t->inputShapeTree; - op->outputShape = op->inputShape; - return; - } - - auto levelId = int_rand(_gen) % (t->beginLevel.size() - 1); - auto opId = t->beginLevel[levelId] + (int_rand(_gen) % t->widthLevel[levelId]); - - std::cout << "input level [ " << levelId << " ] operation id [ " << opId << " ]" << std::endl; - - op->inputs.push_back(opId); - op->levelOwner = t->beginLevel.size() - 1; - op->inputShape = t->opList[opId]->outputShape; - op->outputShape = op->inputShape; -} - -void TreeBuilder::buildSketchSoftmax(Tree *t, Operation *op) -{ - /** - * We need only select input node, the output shape will be same as input. - * That is why we use pooling's builder. - */ - buildSketchPooling(t, op); -} - -void TreeBuilder::buildSketchFullyConnected(Tree *t, Operation *op) -{ - std::uniform_int_distribution int_rand(2, fullyConnectedMaxWeight); - /** - * 1. Select a input form previous nodes by means of buildSketchPooling - */ - buildSketchPooling(t, op); - - /** - * 2. Create a weights for fully connected layer. - */ - op->kernelShape.resize(fullyConnectedKernelDim); - op->kernelShape[0] = int_rand(_gen); - op->kernelShape[1] = - op->inputShape[0] * op->inputShape[1] * op->inputShape[2] * op->inputShape[3]; - - op->outputShape.resize(2); - op->outputShape[0] = op->kernelShape[0]; - op->outputShape[1] = op->kernelShape[1]; -} - -// =========== private =========== - -int32_t TreeBuilder::lookupConsistentOutput(Tree *t, Operation *op, std::vector &shape, - int32_t until_level) -{ - for (int i = 0, j = 0; i < t->beginLevel[until_level]; i++) - { - for (j = 0; j < 4; j++) - { - if (shape[j] != t->opList[i]->outputShape[j] && shape[j] != -1) - { - j = 0; - break; - } - } - if (j == 3 && std::find(op->inputs.begin(), op->inputs.end(), i) == op->inputs.end()) - return i; - } - - /* - * Help to code below (initialization new_op): - * Z = y->inputs - * / \ - * Y new_op - * \ / - * op - */ - const Operation *y = t->opList[op->inputs[0]].get(); - std::unique_ptr new_op = std::unique_ptr(new Operation(*y)); - - /* - * reindex operations - */ - auto inser_pos = t->beginLevel[y->levelOwner]; - for (auto &in : op->inputs) - { - if (in >= inser_pos) - in++; - } - for (int i = inser_pos; i < static_cast(t->opList.size()); i++) - { - for (auto &in : t->opList[i]->inputs) - { - if (in >= inser_pos) - { - in++; - } - } - } - - t->endLevel[y->levelOwner]++; - t->widthLevel[y->levelOwner]++; - for (int i = y->levelOwner + 1; i < static_cast(t->beginLevel.size()); i++) - { - t->beginLevel[i]++; - t->endLevel[i]++; - } - t->opList.insert(t->opList.begin() + inser_pos, std::move(new_op)); - - return inser_pos; -} - -void TreeBuilder::buildSketchConv2DForShape(std::vector &input_shape, Operation *op) -{ - std::uniform_int_distribution int_rand(shapeMin, shapeMax); - - /* out channels */ - op->kernelShape.push_back(input_shape[3]); - /* filter height */ - op->kernelShape.push_back(int_rand(_gen)); - /* filter width */ - op->kernelShape.push_back(int_rand(_gen)); - /* in channels */ - op->kernelShape.push_back(input_shape[3]); - op->outputShape = input_shape; - std::cout << "\t with kernel [ "; - for (auto i : op->kernelShape) - std::cout << " " << i; - std::cout << " ]" << std::endl; -} - -void TreeBuilder::addConcatInput(std::vector &input_shape, int32_t axis, Operation *op) -{ - for (int i = 0; i < 4; i++) - { - if (input_shape[i] != op->inputShape[i] && i != axis) - assert(false && "Not consistency input shapes\n"); - } - op->outputShape[axis] += input_shape[axis]; -} - -} // namespace treebuilder -} // namespace modelgen diff --git a/compiler/nnc/utils/tflite_model_generator/Tree.h b/compiler/nnc/utils/tflite_model_generator/Tree.h deleted file mode 100644 index 1d4f00db691..00000000000 --- a/compiler/nnc/utils/tflite_model_generator/Tree.h +++ /dev/null @@ -1,145 +0,0 @@ -/* - * 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_TREE_H -#define NNCC_TREE_H - -#include -#include -#include -#include - -#include - -namespace modelgen -{ - -enum class OpCodes -{ - opConv2d, - opConcatenation, - opDepthwiseConv2d, - opOpMaxPool2d, - opAveragePool2d, - opSoftmax, - opFullyConnected, - opCount, - opFirst = 0, - opLast = opCount - 1, -}; - -namespace treebuilder -{ - -/** - * opcode is a code of operation. - * inputs is a index of parent operations. - * inputShape is a shape of left parent. - * levelOwner is a index of level having the operation. - * - * @details In some cases the kernelShape will keep - * not the kernel but specific data for operation. - * - */ -struct Operation -{ - OpCodes opcode; - std::vector inputs; - std::vector kernelShape; - std::vector inputShape; - std::vector outputShape; - size_t levelOwner; -}; - -/** - * @param inputCnt is a number of tensors to tree's input. - * @param hTree is a number of levels in tree. - * @param inputShapeTree is a shape for input tree's tensor. - * @param widthLevel is a number of operations on the level [i]. - * @param beginLevel keeps the vector of operations id which are beginners for level [i]. - * @param endLevel keeps the vector of operations id which are end for level [i]. - * @param opList keeps the vector of all used operations. - * - * @details beginLevel is array of indexes to opList. - * for example: beginLevel[4] contains the id of first operation on the level 4. - * id is index for opList array. - */ -struct Tree -{ - int inputCnt; - int hTree; - std::vector inputShapeTree; - std::vector widthLevel; - std::vector beginLevel; - std::vector endLevel; - std::vector> opList; -}; - -class TreeBuilder -{ -public: - TreeBuilder(); - - std::unique_ptr buildTree(); - /** - * @details initTree creates first level and specific operations on its using inputShapeTree - * inside every operation as size of input. This method are used when there aren't - * operations on upper levels. - */ - void initTree(Tree *t); - void buildLevel(Tree *t); - - bool buildSketchOperation(Tree *t, Operation *op); - - /** - * @details Currently Conv2D are build with stride = 1. - * @param input_shape is the shape of input tensor. - * @param op is the pointer to created operation. - */ - void buildSketchConv2D(Tree *t, Operation *op); - void buildSketchConcat(Tree *t, Operation *op); - void buildSketchDepthwiseConv2D(Tree *t, Operation *op); - void buildSketchPooling(Tree *t, Operation *op); - void buildSketchSoftmax(Tree *t, Operation *op); - void buildSketchFullyConnected(Tree *t, Operation *op); - -private: - /** - * @lookupConsistentOutput It Looks up operation with conststent output's shape. - * @param t is a tree where doing search. - * @param op is a operation for which looking a operation. - * @param shape is a template of shape. -1 in this vector is ignorid axis. - * For example in case of <1, 64, 64, -1> the lookupConsistentOutput looks up - * operation with output <1, 64, 64, X>. - * @param until_level is a level starting from which the searching doesn't perform. - * - * @details If the operation doesn't found then this method create such operation - * and return its id. - * - */ - int32_t lookupConsistentOutput(Tree *t, Operation *op, std::vector &shape, - int32_t until_level); - - void buildSketchConv2DForShape(std::vector &input_shape, Operation *op); - void addConcatInput(std::vector &input_shape, int32_t axis, Operation *op); - - std::random_device _rd; - std::mt19937 _gen; -}; - -} // namespace treebuilder -} // namespace modelgen -#endif // NNCC_TREE_H diff --git a/compiler/tf2tfliteV2-value-pbtxt-test/CMakeLists.txt b/compiler/tf2tfliteV2-value-pbtxt-test/CMakeLists.txt new file mode 100644 index 00000000000..ed394ae9c5b --- /dev/null +++ b/compiler/tf2tfliteV2-value-pbtxt-test/CMakeLists.txt @@ -0,0 +1,183 @@ +find_package(PythonInterp 3 QUIET) +find_package(PythonLibs 3 QUIET) + +if(NOT ${PYTHONINTERP_FOUND}) + message("Build tf2tfliteV2-value-pbtxt-test: FALSE (Python3 is missing)") + return() +endif() + +if(${PYTHON_VERSION_MINOR} LESS 3) + message("Build tf2tfliteV2-value-pbtxt-test: FALSE (You need to install Python version higher than 3.3)") + return() +endif() + +nnas_include(TargetRequire) + +unset(REQUIRED_TARGETS) +list(APPEND REQUIRED_TARGETS tfkit) +list(APPEND REQUIRED_TARGETS tf2tfliteV2) +list(APPEND REQUIRED_TARGETS nnkit-run) +list(APPEND REQUIRED_TARGETS nnkit_tf_backend) +list(APPEND REQUIRED_TARGETS nnkit_tflite_backend) +list(APPEND REQUIRED_TARGETS nnkit_randomize_action) +list(APPEND REQUIRED_TARGETS nnkit_HDF5_export_action) +list(APPEND REQUIRED_TARGETS nnkit_HDF5_import_action) +list(APPEND REQUIRED_TARGETS i5diff) +TargetRequire_Return(${REQUIRED_TARGETS}) + +message(STATUS "tf2tfliteV2-value-pbtxt-test: run tests") + +# Create python virtual environment +set(VIRTUALENV "${CMAKE_CURRENT_BINARY_DIR}/venv") + +add_custom_command( + OUTPUT ${VIRTUALENV} + COMMAND ${PYTHON_EXECUTABLE} -m venv ${VIRTUALENV} +) + +# Copy requirements.txt and install required pip packages +set(REQUIREMENTS_FILE "requirements.txt") +set(REQUIREMENTS_SRC_PATH "${CMAKE_CURRENT_SOURCE_DIR}/${REQUIREMENTS_FILE}") +set(REQUIREMENTS_BIN_PATH "${CMAKE_CURRENT_BINARY_DIR}/${REQUIREMENTS_FILE}") + +add_custom_command( + OUTPUT ${REQUIREMENTS_BIN_PATH} + COMMAND ${CMAKE_COMMAND} -E copy ${REQUIREMENTS_SRC_PATH} ${REQUIREMENTS_BIN_PATH} + COMMAND ${VIRTUALENV}/bin/pip install --upgrade pip setuptools --timeout 100 + COMMAND ${VIRTUALENV}/bin/pip install -r requirements.txt --upgrade --timeout 100 + DEPENDS ${VIRTUALENV} ${REQUIREMENTS_SRC_PATH} +) + +add_custom_target(tf2tfliteV2_value_pbtxt_python_deps ALL + DEPENDS ${VIRTUALENV} ${REQUIREMENTS_BIN_PATH} #${TF2TFLITEV2_BIN_PATH} +) + +nncc_find_resource(TensorFlowTests) + +# +# Copy [PREFIX]/test.pbtxt to PREFIX.pbtxt in binary folder +# Copy [PREFIX]/test.info to PREFIX.info in binary folder +# Encode PREFIX.pbtxt to PREFIX.pb +# +set(TEST_REPO "${TensorFlowTests_DIR}") +set(TEST_PBTXT_FILENAME "test.pbtxt") +set(TEST_INFO_FILENAME "test.info") + +unset(TESTCASES) + +macro(add NAME) + list(APPEND TESTCASES ${NAME}) +endmacro(add) + +# Read "test.lst" +include("test.lst") +# Read "test.local.lst" if exists +include("test.local.lst" OPTIONAL) + +unset(TEST_DEPS) +unset(TEST_NAMES) + +foreach(PREFIX IN ITEMS ${TESTCASES}) + if(NOT IS_DIRECTORY "${TEST_REPO}/${PREFIX}") + message(FATAL_ERROR "Missing '${PREFIX}' test") + endif() + + set(PBTXT_SOURCE_PATH "${TEST_REPO}/${PREFIX}/${TEST_PBTXT_FILENAME}") + set(INFO_SOURCE_PATH "${TEST_REPO}/${PREFIX}/${TEST_INFO_FILENAME}") + + set(PBTXT_FILE "${PREFIX}.pbtxt") + set(PBTXT_PATH "${CMAKE_CURRENT_BINARY_DIR}/${PBTXT_FILE}") + + set(INFO_FILE "${PREFIX}.info") + set(INFO_PATH "${CMAKE_CURRENT_BINARY_DIR}/${INFO_FILE}") + + set(PB_FILE "${PREFIX}.pb") + set(PB_PATH "${CMAKE_CURRENT_BINARY_DIR}/${PB_FILE}") + + # Copy .pbtxt + add_custom_command(OUTPUT ${PBTXT_PATH} + COMMAND ${CMAKE_COMMAND} -E copy "${PBTXT_SOURCE_PATH}" "${PBTXT_PATH}" + DEPENDS ${PBTXT_SOURCE_PATH} + COMMENT "Generate ${PBTXT_FILE}" + ) + + # Copy .info + add_custom_command(OUTPUT ${INFO_PATH} + COMMAND ${CMAKE_COMMAND} -E copy "${INFO_SOURCE_PATH}" "${INFO_PATH}" + DEPENDS ${INFO_SOURCE_PATH} + COMMENT "Generate ${INFO_FILE}" + ) + + # Generate .pb from .pbtxt + add_custom_command(OUTPUT ${PB_PATH} + COMMAND $ encode ${PBTXT_PATH} ${PB_PATH} + DEPENDS ${PBTXT_PATH} + COMMENT "Generate ${PB_FILE}" + ) + + list(APPEND TEST_DEPS ${INFO_PATH} ${PB_PATH}) + list(APPEND TEST_NAMES ${PREFIX}) +endforeach(PREFIX) + +## +## Copy testall +## +set(TEST_RUNNER "${CMAKE_CURRENT_BINARY_DIR}/testall.sh") +set(TEST_RUNNER_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/testall.sh") + +add_custom_command( + OUTPUT ${TEST_RUNNER} + COMMAND ${CMAKE_COMMAND} -E copy "${TEST_RUNNER_SOURCE}" "${TEST_RUNNER}" + DEPENDS ${TEST_RUNNER_SOURCE} + COMMENT "Generate test runner" +) + +list(APPEND TEST_DEPS "${TEST_RUNNER}") + +### +### Generate test.config +### +set(TEST_CONFIG "${CMAKE_CURRENT_BINARY_DIR}/test.config") + +# Get tf2tfliteV2 binary path +get_target_property(TF2TFLITEV2_BIN_DIR tf2tfliteV2 BINARY_DIR) +set(TF2TFLITEV2_PATH "${TF2TFLITEV2_BIN_DIR}/tf2tfliteV2.py") + +add_custom_command( + OUTPUT ${TEST_CONFIG} + COMMAND ${CMAKE_COMMAND} -E remove -f ${TEST_CONFIG} + COMMAND ${CMAKE_COMMAND} -E echo 'NNKIT_RUN_PATH=\"$\"' >> ${TEST_CONFIG} + COMMAND ${CMAKE_COMMAND} -E echo 'TF_BACKEND_PATH=\"$\"' >> ${TEST_CONFIG} + COMMAND ${CMAKE_COMMAND} -E echo 'TFLITE_BACKEND_PATH=\"$\"' >> ${TEST_CONFIG} + COMMAND ${CMAKE_COMMAND} -E echo 'RANDOMIZE_ACTION_PATH=\"$\"' >> ${TEST_CONFIG} + COMMAND ${CMAKE_COMMAND} -E echo 'HDF5_EXPORT_ACTION_PATH=\"$\"' >> ${TEST_CONFIG} + COMMAND ${CMAKE_COMMAND} -E echo 'HDF5_IMPORT_ACTION_PATH=\"$\"' >> ${TEST_CONFIG} + COMMAND ${CMAKE_COMMAND} -E echo 'I5DIFF_PATH=\"$\"' >> ${TEST_CONFIG} + COMMAND ${CMAKE_COMMAND} -E echo 'TF2TFLITEV2_PATH=\"${TF2TFLITEV2_PATH}\"' >> ${TEST_CONFIG} + COMMAND ${CMAKE_COMMAND} -E echo 'VIRTUALENV=\"${VIRTUALENV}\"' >> ${TEST_CONFIG} + DEPENDS + i5diff + nnkit-run + nnkit_tf_backend + nnkit_tflite_backend + nnkit_randomize_action + nnkit_HDF5_export_action + nnkit_HDF5_import_action + tf2tfliteV2 + tf2tfliteV2_value_pbtxt_python_deps + COMMENT "Generate test configuration" +) + +list(APPEND TEST_DEPS "${TEST_CONFIG}") + +# This "tf2tfliteV2_value_pbtxt_test_deps" target enforces CMake to generate all the dependencies during "build" phase +add_custom_target(tf2tfliteV2_value_pbtxt_test_deps ALL DEPENDS ${TEST_DEPS}) + +# Run tests +add_test( + NAME tf2tfliteV2_value_pbtxt_test + COMMAND "${TEST_RUNNER}" + "${TEST_CONFIG}" + "${CMAKE_CURRENT_BINARY_DIR}" + ${TEST_NAMES} +) diff --git a/compiler/tf2tfliteV2-value-pbtxt-test/requirements.txt b/compiler/tf2tfliteV2-value-pbtxt-test/requirements.txt new file mode 100644 index 00000000000..2eef5dbb4ef --- /dev/null +++ b/compiler/tf2tfliteV2-value-pbtxt-test/requirements.txt @@ -0,0 +1,2 @@ +# TODO : Handling TF v2 +tensorflow==1.13.1 diff --git a/compiler/tf2tfliteV2-value-pbtxt-test/requires.cmake b/compiler/tf2tfliteV2-value-pbtxt-test/requires.cmake new file mode 100644 index 00000000000..a51236119df --- /dev/null +++ b/compiler/tf2tfliteV2-value-pbtxt-test/requires.cmake @@ -0,0 +1,4 @@ +require("nnkit") +require("tfkit") +require("i5diff") +require("tf2tfliteV2") diff --git a/compiler/tf2tfliteV2-value-pbtxt-test/test.lst b/compiler/tf2tfliteV2-value-pbtxt-test/test.lst new file mode 100644 index 00000000000..328366b169f --- /dev/null +++ b/compiler/tf2tfliteV2-value-pbtxt-test/test.lst @@ -0,0 +1,101 @@ +# TODO Enable skipped tests + +add(NET_0000) +add(NET_0001) +add(NET_0002) +add(NET_0003) +add(NET_0004) +add(NET_0005) +add(NET_0006) +add(NET_0007) +add(NET_0008) +add(NET_0009) +add(NET_0010) +add(NET_0011) +add(NET_0012) +add(NET_0013) +add(NET_0014) +add(NET_0015) +add(NET_0016) +add(NET_0017) +add(NET_0018) +add(NET_0019) +add(NET_0020) +add(NET_0021) +add(NET_0022) +#add(NET_0023) +add(NET_0024) +add(NET_0025) +#add(NET_0028) +add(NET_0029) +add(NET_0030) +add(NET_0031) +add(NET_0032) +add(NET_0033) +add(NET_0034) +add(NET_0035) +add(NET_0036) +add(NET_0037) +add(NET_0038) +add(NET_0039) +add(NET_0040) +add(NET_0041) +add(REGRESSION_0000) +add(REGRESSION_0001) +add(REGRESSION_0002) +add(UNIT_Add_000) +add(UNIT_Add_001) +add(UNIT_Add_002) +add(UNIT_Add_004) +add(UNIT_Add_005) +add(UNIT_AvgPool_000) +add(UNIT_AvgPool_001) +#add(UNIT_BiasAdd_000) +#add(UNIT_BiasAdd_001) +add(UNIT_BiasAdd_002) +#add(UNIT_ConcatV2_000) +#add(UNIT_ConcatV2_001) +add(UNIT_ConcatV2_002) +#add(UNIT_Const_000) +#add(UNIT_Const_001) +add(UNIT_Conv2D_000) +add(UNIT_Conv2DBackpropInput_000) +add(UNIT_Conv2DBackpropInput_001) +add(UNIT_DepthwiseConv2dNative_000) +add(UNIT_DepthwiseConv2dNative_001) +add(UNIT_Maximum_000) +add(UNIT_Maximum_001) +add(UNIT_Maximum_002) +add(UNIT_MaxPool_000) +add(UNIT_MaxPool_001) +add(UNIT_Mean_000) +add(UNIT_Mean_001) +add(UNIT_Mean_002) +add(UNIT_Mean_003) +add(UNIT_Mul_000) +add(UNIT_Mul_001) +add(UNIT_Mul_002) +add(UNIT_Pad_000) +#add(UNIT_Placeholder_000) +#add(UNIT_Placeholder_001) +#add(UNIT_Placeholder_002) +#add(UNIT_Placeholder_003) +add(UNIT_RealDiv_000) +add(UNIT_RealDiv_001) +add(UNIT_Relu_000) +add(UNIT_Relu6_000) +add(UNIT_Reshape_000) +add(UNIT_Rsqrt_000) +add(UNIT_Softmax_001) +add(UNIT_Sqrt_000) +#add(UNIT_SquaredDifference_000) +#add(UNIT_SquaredDifference_001) +add(UNIT_Squeeze_000) +add(UNIT_Squeeze_001) +#add(UNIT_Squeeze_002) +#add(UNIT_Squeeze_003) +#add(UNIT_StopGradient_000) +#add(UNIT_StopGradient_001) +add(UNIT_Sub_000) +add(UNIT_Sub_001) +add(UNIT_Tanh_000) diff --git a/compiler/tf2tfliteV2-value-pbtxt-test/testall.sh b/compiler/tf2tfliteV2-value-pbtxt-test/testall.sh new file mode 100755 index 00000000000..9dde41bfe7d --- /dev/null +++ b/compiler/tf2tfliteV2-value-pbtxt-test/testall.sh @@ -0,0 +1,110 @@ +#!/bin/bash + +# Need at least 2 arguments +if [[ $# -lt 2 ]]; then + echo "USAGE: $0 ..." + echo + echo "ARGUMENTS:" + echo " [test.config path]" + echo " [WORKDIR]" + echo " [Prefix1]" + echo " [Prefix2]" + echo " ..." + exit 255 +fi + +CONFIG_PATH="$1"; shift +WORKDIR="$1"; shift + +source "${CONFIG_PATH}" + +echo "-- Found nnkit-run: ${NNKIT_RUN_PATH}" +echo "-- Found TF backend: ${TF_BACKEND_PATH}" +echo "-- Found TFLITE backend: ${TFLITE_BACKEND_PATH}" +echo "-- Found TF2TFLITEV2: ${TF2TFLITEV2_PATH}" +echo "-- Found randomize action: ${RANDOMIZE_ACTION_PATH}" +echo "-- Found HDF5 export action: ${HDF5_EXPORT_ACTION_PATH}" +echo "-- Found HDF5 import action: ${HDF5_IMPORT_ACTION_PATH}" +echo "-- Found i5diff: ${I5DIFF_PATH}" +echo "-- Found workdir: ${WORKDIR}" + +TESTED=() +PASSED=() +FAILED=() + +pushd "${WORKDIR}" +while [[ $# -ne 0 ]]; do + PREFIX="$1"; shift + + TESTED+=("${PREFIX}") + + PASSED_TAG="${PREFIX}.passed" + + rm -f "${PASSED_TAG}" + + cat > "${PREFIX}.log" <( + exec 2>&1 + + echo "-- Found pb: ${PREFIX}.pb" + + # Exit immediately if any command fails + set -e + # Show commands + set -x + + # Generate tflite + source "${VIRTUALENV}/bin/activate" + "${VIRTUALENV}/bin/python" "${TF2TFLITEV2_PATH}" \ + --v1 \ + --input_path "${WORKDIR}/${PREFIX}.pb" \ + --input_arrays "$(awk -F, '/^input/ { print $2 }' ${PREFIX}.info | cut -d: -f1 | tr -d ' ' | paste -d, -s)" \ + --input_shapes "$(cat ${PREFIX}.info | grep '^input' | cut -d '[' -f2 | cut -d ']' -f1 | tr -d ' ' | xargs | tr ' ' ':')" \ + --output_path "${WORKDIR}/${PREFIX}.tflite" \ + --output_arrays "$(awk -F, '/^output/ { print $2 }' ${PREFIX}.info | cut -d: -f1 | tr -d ' ' | paste -d, -s)" + + # Run TensorFlow + "${NNKIT_RUN_PATH}" \ + --backend "${TF_BACKEND_PATH}" \ + --backend-arg "${WORKDIR}/${PREFIX}.pb" \ + --backend-arg "${WORKDIR}/${PREFIX}.info" \ + --pre "${RANDOMIZE_ACTION_PATH}" \ + --pre "${HDF5_EXPORT_ACTION_PATH}" \ + --pre-arg "${WORKDIR}/${PREFIX}.input.h5" \ + --post "${HDF5_EXPORT_ACTION_PATH}" \ + --post-arg "${WORKDIR}/${PREFIX}.expected.h5" + + # Run TensorFlow Lite + "${NNKIT_RUN_PATH}" \ + --backend "${TFLITE_BACKEND_PATH}" \ + --backend-arg "${WORKDIR}/${PREFIX}.tflite" \ + --pre "${HDF5_IMPORT_ACTION_PATH}" \ + --pre-arg "${WORKDIR}/${PREFIX}.input.h5" \ + --post "${HDF5_EXPORT_ACTION_PATH}" \ + --post-arg "${WORKDIR}/${PREFIX}.obtained.h5" + + "${I5DIFF_PATH}" -d 0.001 "${PREFIX}.expected.h5" "${PREFIX}.obtained.h5" + + if [[ $? -eq 0 ]]; then + touch "${PASSED_TAG}" + fi + ) + + if [[ -f "${PASSED_TAG}" ]]; then + PASSED+=("$PREFIX") + else + FAILED+=("$PREFIX") + fi +done +popd + +if [[ ${#TESTED[@]} -ne ${#PASSED[@]} ]]; then + echo "FAILED" + for TEST in "${FAILED[@]}" + do + echo "- ${TEST}" + done + exit 255 +fi + +echo "PASSED" +exit 0 diff --git a/compiler/tf2tfliteV2/CMakeLists.txt b/compiler/tf2tfliteV2/CMakeLists.txt new file mode 100644 index 00000000000..8a5c2dcd8b6 --- /dev/null +++ b/compiler/tf2tfliteV2/CMakeLists.txt @@ -0,0 +1,11 @@ +set(tf2tfliteV2_FILE "tf2tfliteV2.py") +set(tf2tfliteV2_SRC "${CMAKE_CURRENT_SOURCE_DIR}/${tf2tfliteV2_FILE}") +set(tf2tfliteV2_BIN "${CMAKE_CURRENT_BINARY_DIR}/${tf2tfliteV2_FILE}") + +add_custom_command(OUTPUT ${tf2tfliteV2_BIN} + COMMAND ${CMAKE_COMMAND} -E copy "${tf2tfliteV2_SRC}" "${tf2tfliteV2_BIN}" + DEPENDS ${tf2tfliteV2_SRC} + COMMENT "Generate ${tf2tfliteV2_BIN}" + ) + +add_custom_target(tf2tfliteV2 ALL DEPENDS ${tf2tfliteV2_BIN}) diff --git a/compiler/tf2tfliteV2/README.md b/compiler/tf2tfliteV2/README.md new file mode 100644 index 00000000000..836740a5c51 --- /dev/null +++ b/compiler/tf2tfliteV2/README.md @@ -0,0 +1,47 @@ +# tf2tfliteV2 + +_tf2tfliteV2_ is a TensorFlow to TensorFlow Lite model Converter. + +## Where does V2 come from? +Even though we alreay have _tf2tflite_, we cannot cover all opeartors in TensorFlow. To expand coverage, we introduce _tf2tfliteV2_ which uses `TensorFlow Lite Converter`(by Google) internally. + +## Prerequisite +- Frozen graph from TensorFlow 1.13.1 +- Desired version of TensorFlow(You can use python virtualenv, docker, etc.) + +## Example +``` +python tf2tfliteV2.py \ +> --v1 \ +> --input_path=frozen_graph.pb \ +> --output_path=converted.tflite \ +> --input_arrays=model_inputs \ +> --output_arrays=model_outputs + +``` +``` +python tf2tfliteV2.py \ +> --v2 \ +> --input_path=frozen_graph.pb \ +> --output_path=converted.tflite \ +> --input_arrays=model_inputs \ +> --output_arrays=model_outputs +``` + +## optional argument +``` + -h, --help show this help message and exit + --v1 Use TensorFlow Lite Converter 1.x + --v2 Use TensorFlow Lite Converter 2.x + --input_path INPUT_PATH + Full filepath of the input file. + --output_path OUTPUT_PATH + Full filepath of the output file. + --input_arrays INPUT_ARRAYS + Names of the input arrays, comma-separated. + --input_shapes INPUT_SHAPES + Shapes corresponding to --input_arrays, colon- + separated. + --output_arrays OUTPUT_ARRAYS + Names of the output arrays, comma-separated. +``` diff --git a/compiler/tf2tfliteV2/tf2tfliteV2.py b/compiler/tf2tfliteV2/tf2tfliteV2.py new file mode 100755 index 00000000000..8b6ba0dc454 --- /dev/null +++ b/compiler/tf2tfliteV2/tf2tfliteV2.py @@ -0,0 +1,183 @@ +# Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved +# Copyright (C) 2018 The TensorFlow Authors +# +# 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. + +import tensorflow as tf +import argparse +import sys + +from google.protobuf.message import DecodeError +from google.protobuf import text_format as _text_format + + +def wrap_frozen_graph(graph_def, inputs, outputs): + def _imports_graph_def(): + tf.compat.v1.import_graph_def(graph_def, name="") + + wrapped_import = tf.compat.v1.wrap_function(_imports_graph_def, []) + import_graph = wrapped_import.graph + return wrapped_import.prune( + tf.nest.map_structure(import_graph.as_graph_element, inputs), + tf.nest.map_structure(import_graph.as_graph_element, outputs)) + + +def _get_parser(): + """ + Returns an ArgumentParser for TensorFlow Lite Converter. + """ + parser = argparse.ArgumentParser( + description=("Command line tool to run TensorFlow Lite Converter.")) + + # Converter version. + converter_version = parser.add_mutually_exclusive_group(required=True) + converter_version.add_argument( + "--v1", action="store_true", help="Use TensorFlow Lite Converter 1.x") + converter_version.add_argument( + "--v2", action="store_true", help="Use TensorFlow Lite Converter 2.x") + + # Input and output path. + parser.add_argument( + "--input_path", type=str, help="Full filepath of the input file.", required=True) + parser.add_argument( + "--output_path", + type=str, + help="Full filepath of the output file.", + required=True) + + # Input and output arrays. + parser.add_argument( + "--input_arrays", + type=str, + help="Names of the input arrays, comma-separated.", + required=True) + parser.add_argument( + "--input_shapes", + type=str, + help="Shapes corresponding to --input_arrays, colon-separated.") + parser.add_argument( + "--output_arrays", + type=str, + help="Names of the output arrays, comma-separated.", + required=True) + + return parser + + +def _check_flags(flags): + """ + Checks the parsed flags to ensure they are valid. + """ + if flags.v1: + invalid = "" + # To be filled + + if invalid: + raise ValueError(invalid + " options must be used with v2") + + if flags.v2: + if tf.__version__.find("2.") != 0: + raise ValueError( + "Imported TensorFlow should have version >= 2.0 but you have " + + tf.__version__) + + invalid = "" + # To be filled + + if invalid: + raise ValueError(invalid + " options must be used with v1") + + if flags.input_shapes: + if not flags.input_arrays: + raise ValueError("--input_shapes must be used with --input_arrays") + if flags.input_shapes.count(":") != flags.input_arrays.count(","): + raise ValueError("--input_shapes and --input_arrays must have the same " + "number of items") + + +def _parse_array(arrays, type_fn=str): + return list(map(type_fn, arrays.split(","))) + + +def _v1_convert(flags): + input_shapes = None + if flags.input_shapes: + input_arrays = _parse_array(flags.input_arrays) + input_shapes_list = [ + _parse_array(shape, type_fn=int) for shape in flags.input_shapes.split(":") + ] + input_shapes = dict(list(zip(input_arrays, input_shapes_list))) + + converter = tf.compat.v1.lite.TFLiteConverter.from_frozen_graph( + flags.input_path, _parse_array(flags.input_arrays), + _parse_array(flags.output_arrays), input_shapes) + + converter.allow_custom_ops = True + + tflite_model = converter.convert() + open(flags.output_path, "wb").write(tflite_model) + + +def _v2_convert(flags): + file_content = open(flags.input_path, 'rb').read() + try: + graph_def = tf.compat.v1.GraphDef() + graph_def.ParseFromString(file_content) + except (_text_format.ParseError, DecodeError): + try: + _text_format.Merge(file_content, graph_def) + except (_text_format.ParseError, DecodeError): + raise IOError("Unable to parse input file '{}'.".format(flags.input_path)) + + wrap_func = wrap_frozen_graph( + graph_def, + inputs=[_str + ":0" for _str in _parse_array(flags.input_arrays)], + # TODO What if multiple outputs come in? + outputs=[_str + ":0" for _str in _parse_array(flags.output_arrays)]) + converter = tf.lite.TFLiteConverter.from_concrete_functions([wrap_func]) + + converter.allow_custom_ops = True + converter.experimental_new_converter = True + + converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS] + + tflite_model = converter.convert() + open(flags.output_path, "wb").write(tflite_model) + + +def _convert(flags): + if (flags.v1): + _v1_convert(flags) + else: + _v2_convert(flags) + + +""" +Input frozen graph must be from TensorFlow 1.13.1 +""" + + +def main(): + # Parse argument. + parser = _get_parser() + + # Check if the flags are valid. + flags = parser.parse_known_args(args=sys.argv[1:]) + _check_flags(flags[0]) + + # Convert + _convert(flags[0]) + + +if __name__ == "__main__": + main() diff --git a/compiler/tfl-inspect/src/Model.cpp b/compiler/tfl-inspect/src/Model.cpp index 3a45dffaa13..8c3bf379ab1 100644 --- a/compiler/tfl-inspect/src/Model.cpp +++ b/compiler/tfl-inspect/src/Model.cpp @@ -129,7 +129,7 @@ std::unique_ptr load_tflite(const std::string &path) // Check if file is a valid Flatbuffer file const uint8_t *u8data = reinterpret_cast(data); - flatbuffers::Verifier verifier{u8data, size}; + flatbuffers::Verifier verifier{u8data, static_cast(size)}; if (!tflite::VerifyModelBuffer(verifier)) { munmap(data, size); diff --git a/compiler/tflchef/core/src/Convert.cpp b/compiler/tflchef/core/src/Convert.cpp index 63c0732e8f2..86a31d9b730 100644 --- a/compiler/tflchef/core/src/Convert.cpp +++ b/compiler/tflchef/core/src/Convert.cpp @@ -62,6 +62,8 @@ tflite::TensorType as_tflite_tensortype(const tflchef::TensorType &value) return tflite::TensorType_UINT8; case tflchef::INT64: return tflite::TensorType_INT64; + case tflchef::BOOL: + return tflite::TensorType_BOOL; default: break; } diff --git a/compiler/tflchef/core/src/Data/Explicit.h b/compiler/tflchef/core/src/Data/Explicit.h index 69b759fba0a..088e791b94d 100644 --- a/compiler/tflchef/core/src/Data/Explicit.h +++ b/compiler/tflchef/core/src/Data/Explicit.h @@ -22,14 +22,6 @@ #include -/** - * @brief Return the identity of arithmetic addition - */ -template T zero(void); - -template <> int zero(void) { return 0; } -template <> uint8_t zero(void) { return 0; } - template class ExplicitDataChef final : public DataChef { public: @@ -45,7 +37,7 @@ template class ExplicitDataChef final : public DataChef for (uint32_t n = 0; n < count; ++n) { - T const value = (n < _values.size()) ? _values.at(n) : zero(); + T const value = (n < _values.size()) ? _values.at(n) : T{}; const uint8_t *arr = reinterpret_cast(&value); for (uint32_t b = 0; b < sizeof(T); ++b) diff --git a/compiler/tflchef/core/src/DataChef.def b/compiler/tflchef/core/src/DataChef.def index dc0e510ac7b..89d34a20212 100644 --- a/compiler/tflchef/core/src/DataChef.def +++ b/compiler/tflchef/core/src/DataChef.def @@ -5,8 +5,11 @@ // DATA_CHEF(TYPE, NAME, FACTORY_CLASS) // "TYPE" SHOULD BE an enum tag of tflchef::TensorType DATA_CHEF(FLOAT32, constant, ConstantDataChefFactory) +DATA_CHEF(BOOL, constant, ConstantDataChefFactory) DATA_CHEF(INT32, explicit, ExplicitDataChefFactory) DATA_CHEF(UINT8, explicit, ExplicitDataChefFactory) +DATA_CHEF(BOOL, explicit, ExplicitDataChefFactory) +DATA_CHEF(FLOAT32, explicit, ExplicitDataChefFactory) DATA_CHEF(FLOAT32, gaussian, GaussianFloat32DataChefFactory) DATA_CHEF(INT32, gaussian, GaussianInt32DataChefFactory) DATA_CHEF(UINT8, gaussian, GaussianUint8DataChefFactory) diff --git a/compiler/tflchef/core/src/LexicalCast.cpp b/compiler/tflchef/core/src/LexicalCast.cpp index 5132f72161b..38a5f929010 100644 --- a/compiler/tflchef/core/src/LexicalCast.cpp +++ b/compiler/tflchef/core/src/LexicalCast.cpp @@ -28,3 +28,9 @@ template <> uint8_t to_number(const std::string &s) assert(temp <= std::numeric_limits::max()); return static_cast(temp); } +template <> bool to_number(const std::string &s) +{ + if (std::stoi(s) || s == "T" || s == "t" || s == "TRUE" || s == "true") + return true; + return false; +} diff --git a/compiler/tflchef/core/src/ModelChef.cpp b/compiler/tflchef/core/src/ModelChef.cpp index f48a0317834..2c69efd4bec 100644 --- a/compiler/tflchef/core/src/ModelChef.cpp +++ b/compiler/tflchef/core/src/ModelChef.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include namespace @@ -169,6 +170,7 @@ DataChefRegistry &data_chef_registry(const tflchef::TensorType &type) static DataChefRegistry s32; static DataChefRegistry fp32; static DataChefRegistry u8; + static DataChefRegistry boolean; switch (type) { @@ -178,6 +180,8 @@ DataChefRegistry &data_chef_registry(const tflchef::TensorType &type) return fp32; case tflchef::UINT8: return u8; + case tflchef::BOOL: + return boolean; default: break; } @@ -204,6 +208,18 @@ std::set gather_opcode_set(const ::tflchef::ModelRecipe auto op_chef = op_chef_registry().lookup(operation.type()).create(&operation); opcode_set.insert(op_chef->code()); } + + // Add ops used in Graphs(subgraphs) + for (int g = 0; g < model_recipe.graph_size(); ++g) + { + const auto &graph = model_recipe.graph(g); + for (const auto &operation : graph.operation()) + { + auto op_chef = op_chef_registry().lookup(operation.type()).create(&operation); + opcode_set.insert(op_chef->code()); + } + } + return opcode_set; } @@ -230,11 +246,6 @@ GeneratedModel cook(const ::tflchef::ModelRecipe &model_recipe) #include "DataChef.def" #undef DATA_CHEF - // Tensor Name -> Tensor ID mapping - std::map symbol_table; - - auto lookup = [&symbol_table](const std::string &name) { return symbol_table.at(name); }; - // // Create FlatBufferBuilder // @@ -243,11 +254,12 @@ GeneratedModel cook(const ::tflchef::ModelRecipe &model_recipe) // Operand-related std::vector> buffer_vec; - std::vector> tensor_vec; // Operation-related std::vector> code_vec; - std::vector> operator_vec; + + // Graphs-related + std::vector> subgraph_vec; // Create OperatorCode std::set opcode_set = gather_opcode_set(model_recipe); @@ -269,210 +281,461 @@ GeneratedModel cook(const ::tflchef::ModelRecipe &model_recipe) buffer_vec.emplace_back(buffer_builder.Finish()); } - // Create buffer(s) 1~n(I) for input(s) - const auto size_input = model_recipe.input_size(); - for (int ci = 0; ci < size_input; ++ci) + // + // Create Main graph + // { + // Operand-related + std::vector> tensor_vec; + + // Operation-related + std::vector> operator_vec; + + // Tensor Name -> Tensor ID mapping (per Graph) + std::map symbol_table; + + auto lookup = [&symbol_table](const std::string &name) { return symbol_table.at(name); }; + + int32_t buffer_start = buffer_vec.size(); + int32_t buffer_index = 0; + + // Create buffer(s) 1~n(I) for input(s) + const auto size_input = model_recipe.input_size(); + for (int ci = 0; ci < size_input; ++ci) { tflite::BufferBuilder buffer_builder{*flatbuffer_builder}; buffer_vec.emplace_back(buffer_builder.Finish()); } - } - // Create buffer(s) n(I)+1~n(I)+n(O) for output(s) - const auto size_output = model_recipe.output_size(); - for (int co = 0; co < size_output; ++co) - { + // Create buffer(s) n(I)+1~n(I)+n(O) for output(s) + const auto size_output = model_recipe.output_size(); + for (int co = 0; co < size_output; ++co) { tflite::BufferBuilder buffer_builder{*flatbuffer_builder}; buffer_vec.emplace_back(buffer_builder.Finish()); } - } - auto input_names = as_dataset(model_recipe.input()).vectorize(); - auto output_names = as_dataset(model_recipe.output()).vectorize(); + // default name for main graph + std::string graph_name = "main"; + if (model_recipe.has_name()) + graph_name = model_recipe.name(); - for (const auto &operand : model_recipe.operand()) - { - assert(operand.has_name()); + auto input_names = as_dataset(model_recipe.input()).vectorize(); + auto output_names = as_dataset(model_recipe.output()).vectorize(); - assert(operand.has_type()); - assert(operand.has_shape()); + for (const auto &operand : model_recipe.operand()) + { + assert(operand.has_name()); - std::vector dims = as_dims(operand.shape()); + assert(operand.has_type()); + assert(operand.has_shape()); - auto shape = flatbuffer_builder->CreateVector(dims); - auto name = flatbuffer_builder->CreateString(operand.name()); + std::vector dims = as_dims(operand.shape()); - int32_t buffer_index = 0; + auto shape = flatbuffer_builder->CreateVector(dims); + auto name = flatbuffer_builder->CreateString(operand.name()); - // Create Buffer if filler is specified - if (operand.has_filler()) - { - const auto &filler = operand.filler(); + buffer_index = 0; - assert(filler.has_tag()); + // Create Buffer if filler is specified + if (operand.has_filler()) + { + const auto &filler = operand.filler(); - auto args = ranged_arguments(filler.arg().begin(), filler.arg().end()); - auto chef = data_chef_registry(operand.type()).lookup(filler.tag()).create(args); + assert(filler.has_tag()); - assert(chef != nullptr); + auto args = ranged_arguments(filler.arg().begin(), filler.arg().end()); + auto chef = data_chef_registry(operand.type()).lookup(filler.tag()).create(args); - // Create Data - auto data_vec = chef->generate(element_count(dims)); - auto data = flatbuffer_builder->CreateVector(data_vec); + assert(chef != nullptr); - // Create Buffer - tflite::BufferBuilder buffer_builder{*flatbuffer_builder}; - buffer_builder.add_data(data); - auto buffer = buffer_builder.Finish(); + // Create Data + auto data_vec = chef->generate(element_count(dims)); + auto data = flatbuffer_builder->CreateVector(data_vec); - // Update Buffer Index & Vector - buffer_index = buffer_vec.size(); - buffer_vec.emplace_back(buffer); - } - else - { - // if this is input or output, assign to that buffer_index - int idx = 0; - for (auto it = input_names.begin(); it != input_names.end(); ++it, ++idx) - { - if (*it == operand.name()) - { - buffer_index = 1 + idx; // input is from 1 - break; - } + // Create Buffer + tflite::BufferBuilder buffer_builder{*flatbuffer_builder}; + buffer_builder.add_data(data); + auto buffer = buffer_builder.Finish(); + + // Update Buffer Index & Vector + buffer_index = buffer_vec.size(); + buffer_vec.emplace_back(buffer); } - if (buffer_index == 0) + else { - idx = 0; - for (auto it = output_names.begin(); it != output_names.end(); ++it, ++idx) + // if this is input or output, assign to that buffer_index + int idx = 0; + for (auto it = input_names.begin(); it != input_names.end(); ++it, ++idx) { if (*it == operand.name()) { - buffer_index = 1 + size_input + idx; // output is from 1 + size_input + buffer_index = buffer_start + idx; break; } } + if (buffer_index == 0) + { + idx = 0; + for (auto it = output_names.begin(); it != output_names.end(); ++it, ++idx) + { + if (*it == operand.name()) + { + buffer_index = buffer_start + size_input + idx; + break; + } + } + } } - } - flatbuffers::Offset quant_index; + flatbuffers::Offset quant_index; + + // Create QuantizationParameters if quant is specified + if (operand.has_quant()) + { + const auto &quant = operand.quant(); + + // Create each parameters + // NOTE if some parameters are not given, those will be set to default value + std::vector quant_max_vec(quant.max_size()); + std::vector quant_min_vec(quant.min_size()); + std::vector quant_scale_vec(quant.scale_size()); + std::vector quant_zero_point_vec(quant.zero_point_size()); + + for (uint32_t i = 0; i < quant.max_size(); ++i) + quant_max_vec.at(i) = quant.max(i); + for (uint32_t i = 0; i < quant.min_size(); ++i) + quant_min_vec.at(i) = quant.min(i); + for (uint32_t i = 0; i < quant.scale_size(); ++i) + quant_scale_vec.at(i) = quant.scale(i); + for (uint32_t i = 0; i < quant.zero_point_size(); ++i) + quant_zero_point_vec.at(i) = quant.zero_point(i); + + auto quant_max = flatbuffer_builder->CreateVector(quant_max_vec); + auto quant_min = flatbuffer_builder->CreateVector(quant_min_vec); + auto quant_scale = flatbuffer_builder->CreateVector(quant_scale_vec); + auto quant_zero_point = flatbuffer_builder->CreateVector(quant_zero_point_vec); + + // Create QuantizationParameters + tflite::QuantizationParametersBuilder quant_builder{*flatbuffer_builder}; + quant_builder.add_max(quant_max); + quant_builder.add_min(quant_min); + quant_builder.add_scale(quant_scale); + quant_builder.add_zero_point(quant_zero_point); + + // Update QuantizationParameters Index + quant_index = quant_builder.Finish(); + } + + // Create Tensor + tflite::TensorBuilder tensor_builder{*flatbuffer_builder}; + + tensor_builder.add_shape(shape); + tensor_builder.add_type(as_tflite_tensortype(operand.type())); + tensor_builder.add_buffer(buffer_index); + tensor_builder.add_name(name); + if (operand.has_quant()) + tensor_builder.add_quantization(quant_index); + + // Append! + tensor_vec.emplace_back(tensor_builder.Finish()); - // Create QuantizationParameters if quant is specified - if (operand.has_quant()) + // Update Tensor Name -> Tensor Index Map + int32_t tensor_index = symbol_table.size(); + const auto &tensor_name = operand.name(); + + symbol_table[tensor_name] = tensor_index; + } + + // Create Operator + for (const auto &operation : model_recipe.operation()) { - const auto &quant = operand.quant(); - - // Create each parameters - // NOTE if some parameters are not given, those will be set to default value - std::vector quant_max_vec(quant.max_size()); - std::vector quant_min_vec(quant.min_size()); - std::vector quant_scale_vec(quant.scale_size()); - std::vector quant_zero_point_vec(quant.zero_point_size()); - - for (uint32_t i = 0; i < quant.max_size(); ++i) - quant_max_vec.at(i) = quant.max(i); - for (uint32_t i = 0; i < quant.min_size(); ++i) - quant_min_vec.at(i) = quant.min(i); - for (uint32_t i = 0; i < quant.scale_size(); ++i) - quant_scale_vec.at(i) = quant.scale(i); - for (uint32_t i = 0; i < quant.zero_point_size(); ++i) - quant_zero_point_vec.at(i) = quant.zero_point(i); - - auto quant_max = flatbuffer_builder->CreateVector(quant_max_vec); - auto quant_min = flatbuffer_builder->CreateVector(quant_min_vec); - auto quant_scale = flatbuffer_builder->CreateVector(quant_scale_vec); - auto quant_zero_point = flatbuffer_builder->CreateVector(quant_zero_point_vec); - - // Create QuantizationParameters - tflite::QuantizationParametersBuilder quant_builder{*flatbuffer_builder}; - quant_builder.add_max(quant_max); - quant_builder.add_min(quant_min); - quant_builder.add_scale(quant_scale); - quant_builder.add_zero_point(quant_zero_point); - - // Update QuantizationParameters Index - quant_index = quant_builder.Finish(); + assert(operation.has_type()); + + auto op_chef = op_chef_registry().lookup(operation.type()).create(&operation); + + // Create 'inputs' + std::vector input_vec = as_dataset(operation.input()).map(lookup).vectorize(); + auto inputs = flatbuffer_builder->CreateVector(input_vec); + + // Create 'outputs' + std::vector output_vec = as_dataset(operation.output()).map(lookup).vectorize(); + auto outputs = flatbuffer_builder->CreateVector(output_vec); + + // Create Option + auto options = op_chef->value(*flatbuffer_builder); + + // Create Operator + tflite::OperatorBuilder op_builder{*flatbuffer_builder}; + + // Get operator code index from opcode_set with assumption, order of + // opcode_set is same as that of code_vec + auto op_it = opcode_set.find(op_chef->code()); + assert(op_it != opcode_set.end()); + uint32_t opcode_index = std::distance(opcode_set.begin(), op_it); + + op_builder.add_opcode_index(opcode_index); + op_builder.add_inputs(inputs); + op_builder.add_outputs(outputs); + op_builder.add_builtin_options_type(op_chef->type()); + op_builder.add_builtin_options(options); + + // Append Operator + operator_vec.emplace_back(op_builder.Finish()); } - // Create Tensor - tflite::TensorBuilder tensor_builder{*flatbuffer_builder}; + // Create network input/output vector + std::vector input_vec = as_dataset(model_recipe.input()).map(lookup).vectorize(); + std::vector output_vec = as_dataset(model_recipe.output()).map(lookup).vectorize(); - tensor_builder.add_shape(shape); - tensor_builder.add_type(as_tflite_tensortype(operand.type())); - tensor_builder.add_buffer(buffer_index); - tensor_builder.add_name(name); - if (operand.has_quant()) - tensor_builder.add_quantization(quant_index); + // Create "SubGraph" arguments + auto tensors = flatbuffer_builder->CreateVector(tensor_vec); + auto inputs = flatbuffer_builder->CreateVector(input_vec); + auto outputs = flatbuffer_builder->CreateVector(output_vec); + auto operators = flatbuffer_builder->CreateVector(operator_vec); + auto name = flatbuffer_builder->CreateString(graph_name); - // Append! - tensor_vec.emplace_back(tensor_builder.Finish()); + tflite::SubGraphBuilder subgraph_builder{*flatbuffer_builder}; - // Update Tensor Name -> Tensor Index Map - int32_t tensor_index = symbol_table.size(); - const auto &tensor_name = operand.name(); + subgraph_builder.add_tensors(tensors); + subgraph_builder.add_inputs(inputs); + subgraph_builder.add_outputs(outputs); + subgraph_builder.add_operators(operators); + subgraph_builder.add_name(name); - symbol_table[tensor_name] = tensor_index; + subgraph_vec.emplace_back(subgraph_builder.Finish()); } - // Create Operator - for (const auto &operation : model_recipe.operation()) + // + // Create subgraphs if exist + // TODO refactor main graph and subgraphs generation to reduce duplicate codes + // + for (int g = 0; g < model_recipe.graph_size(); ++g) { - assert(operation.has_type()); + // Operand-related + std::vector> tensor_vec; - auto op_chef = op_chef_registry().lookup(operation.type()).create(&operation); + // Operation-related + std::vector> operator_vec; - // Create 'inputs' - std::vector input_vec = as_dataset(operation.input()).map(lookup).vectorize(); - auto inputs = flatbuffer_builder->CreateVector(input_vec); + // Tensor Name -> Tensor ID mapping (per Graph) + std::map symbol_table; - // Create 'outputs' - std::vector output_vec = as_dataset(operation.output()).map(lookup).vectorize(); - auto outputs = flatbuffer_builder->CreateVector(output_vec); + auto lookup = [&symbol_table](const std::string &name) { return symbol_table.at(name); }; - // Create Option - auto options = op_chef->value(*flatbuffer_builder); + const auto &graph = model_recipe.graph(g); + + int32_t buffer_start = buffer_vec.size(); + int32_t buffer_index = 0; + + // Create buffer(s) for input(s) + const auto size_input = graph.input_size(); + for (int ci = 0; ci < size_input; ++ci) + { + tflite::BufferBuilder buffer_builder{*flatbuffer_builder}; + buffer_vec.emplace_back(buffer_builder.Finish()); + } + // Create buffer(s) for output(s) + const auto size_output = graph.output_size(); + for (int co = 0; co < size_output; ++co) + { + tflite::BufferBuilder buffer_builder{*flatbuffer_builder}; + buffer_vec.emplace_back(buffer_builder.Finish()); + } + + // default name for sub graph + // TODO naming rule here may have conflit if recipe file provides it. + // fix this when this happens. + std::ostringstream stringStream; + stringStream << "sub_" << (g + 1); + std::string graph_name = stringStream.str(); + if (graph.has_name()) + graph_name = graph.name(); + + auto input_names = as_dataset(graph.input()).vectorize(); + auto output_names = as_dataset(graph.output()).vectorize(); + + for (const auto &operand : graph.operand()) + { + assert(operand.has_name()); + + assert(operand.has_type()); + assert(operand.has_shape()); + + std::vector dims = as_dims(operand.shape()); + + auto shape = flatbuffer_builder->CreateVector(dims); + auto name = flatbuffer_builder->CreateString(operand.name()); + + // Create Buffer if filler is specified + if (operand.has_filler()) + { + const auto &filler = operand.filler(); + + assert(filler.has_tag()); + + auto args = ranged_arguments(filler.arg().begin(), filler.arg().end()); + auto chef = data_chef_registry(operand.type()).lookup(filler.tag()).create(args); + + assert(chef != nullptr); + + // Create Data + auto data_vec = chef->generate(element_count(dims)); + auto data = flatbuffer_builder->CreateVector(data_vec); + + // Create Buffer + tflite::BufferBuilder buffer_builder{*flatbuffer_builder}; + buffer_builder.add_data(data); + auto buffer = buffer_builder.Finish(); + + // Update Buffer Index & Vector + buffer_index = buffer_vec.size(); + buffer_vec.emplace_back(buffer); + } + else + { + // if this is input or output, assign to that buffer_index + int idx = 0; + buffer_index = 0; + for (auto it = input_names.begin(); it != input_names.end(); ++it, ++idx) + { + if (*it == operand.name()) + { + buffer_index = buffer_start + idx; + break; + } + } + if (buffer_index == 0) + { + idx = 0; + for (auto it = output_names.begin(); it != output_names.end(); ++it, ++idx) + { + if (*it == operand.name()) + { + buffer_index = buffer_start + size_input + idx; + break; + } + } + } + } + // NOTE buffer_index can be 0 when this operand does not have a filler or not I/O + + flatbuffers::Offset quant_index; + + // Create QuantizationParameters if quant is specified + if (operand.has_quant()) + { + const auto &quant = operand.quant(); + + // Create each parameters + // NOTE if some parameters are not given, those will be set to default value + std::vector quant_max_vec(quant.max_size()); + std::vector quant_min_vec(quant.min_size()); + std::vector quant_scale_vec(quant.scale_size()); + std::vector quant_zero_point_vec(quant.zero_point_size()); + + for (uint32_t i = 0; i < quant.max_size(); ++i) + quant_max_vec.at(i) = quant.max(i); + for (uint32_t i = 0; i < quant.min_size(); ++i) + quant_min_vec.at(i) = quant.min(i); + for (uint32_t i = 0; i < quant.scale_size(); ++i) + quant_scale_vec.at(i) = quant.scale(i); + for (uint32_t i = 0; i < quant.zero_point_size(); ++i) + quant_zero_point_vec.at(i) = quant.zero_point(i); + + auto quant_max = flatbuffer_builder->CreateVector(quant_max_vec); + auto quant_min = flatbuffer_builder->CreateVector(quant_min_vec); + auto quant_scale = flatbuffer_builder->CreateVector(quant_scale_vec); + auto quant_zero_point = flatbuffer_builder->CreateVector(quant_zero_point_vec); + + // Create QuantizationParameters + tflite::QuantizationParametersBuilder quant_builder{*flatbuffer_builder}; + quant_builder.add_max(quant_max); + quant_builder.add_min(quant_min); + quant_builder.add_scale(quant_scale); + quant_builder.add_zero_point(quant_zero_point); + + // Update QuantizationParameters Index + quant_index = quant_builder.Finish(); + } + + // Create Tensor + tflite::TensorBuilder tensor_builder{*flatbuffer_builder}; + + tensor_builder.add_shape(shape); + tensor_builder.add_type(as_tflite_tensortype(operand.type())); + tensor_builder.add_buffer(buffer_index); + tensor_builder.add_name(name); + if (operand.has_quant()) + tensor_builder.add_quantization(quant_index); + + // Append! + tensor_vec.emplace_back(tensor_builder.Finish()); + + // Update Tensor Name -> Tensor Index Map + int32_t tensor_index = symbol_table.size(); + const auto &tensor_name = operand.name(); + + symbol_table[tensor_name] = tensor_index; + } // Create Operator - tflite::OperatorBuilder op_builder{*flatbuffer_builder}; - - // Get operator code index from opcode_set with assumption, order of - // opcode_set is same as that of code_vec - auto op_it = opcode_set.find(op_chef->code()); - assert(op_it != opcode_set.end()); - uint32_t opcode_index = std::distance(opcode_set.begin(), op_it); - - op_builder.add_opcode_index(opcode_index); - op_builder.add_inputs(inputs); - op_builder.add_outputs(outputs); - op_builder.add_builtin_options_type(op_chef->type()); - op_builder.add_builtin_options(options); - - // Append Operator - operator_vec.emplace_back(op_builder.Finish()); - } + for (const auto &operation : graph.operation()) + { + assert(operation.has_type()); - // Create network input/output vector - std::vector input_vec = as_dataset(model_recipe.input()).map(lookup).vectorize(); - std::vector output_vec = as_dataset(model_recipe.output()).map(lookup).vectorize(); + auto op_chef = op_chef_registry().lookup(operation.type()).create(&operation); - // Create "SubGraph" arguments - auto tensors = flatbuffer_builder->CreateVector(tensor_vec); - auto inputs = flatbuffer_builder->CreateVector(input_vec); - auto outputs = flatbuffer_builder->CreateVector(output_vec); - auto operators = flatbuffer_builder->CreateVector(operator_vec); + // Create 'inputs' + std::vector input_vec = as_dataset(operation.input()).map(lookup).vectorize(); + auto inputs = flatbuffer_builder->CreateVector(input_vec); - // Create "SubGraph" - std::vector> subgraph_vec; + // Create 'outputs' + std::vector output_vec = as_dataset(operation.output()).map(lookup).vectorize(); + auto outputs = flatbuffer_builder->CreateVector(output_vec); - tflite::SubGraphBuilder subgraph_builder{*flatbuffer_builder}; + // Create Option + auto options = op_chef->value(*flatbuffer_builder); - subgraph_builder.add_tensors(tensors); - subgraph_builder.add_inputs(inputs); - subgraph_builder.add_outputs(outputs); - subgraph_builder.add_operators(operators); + // Create Operator + tflite::OperatorBuilder op_builder{*flatbuffer_builder}; + + // Get operator code index from opcode_set with assumption, order of + // opcode_set is same as that of code_vec + auto op_it = opcode_set.find(op_chef->code()); + assert(op_it != opcode_set.end()); + uint32_t opcode_index = std::distance(opcode_set.begin(), op_it); + + op_builder.add_opcode_index(opcode_index); + op_builder.add_inputs(inputs); + op_builder.add_outputs(outputs); + op_builder.add_builtin_options_type(op_chef->type()); + op_builder.add_builtin_options(options); + + // Append Operator + operator_vec.emplace_back(op_builder.Finish()); + } - subgraph_vec.emplace_back(subgraph_builder.Finish()); + // Create network input/output vector + std::vector input_vec = as_dataset(graph.input()).map(lookup).vectorize(); + std::vector output_vec = as_dataset(graph.output()).map(lookup).vectorize(); + + // Create "SubGraph" arguments + auto tensors = flatbuffer_builder->CreateVector(tensor_vec); + auto inputs = flatbuffer_builder->CreateVector(input_vec); + auto outputs = flatbuffer_builder->CreateVector(output_vec); + auto operators = flatbuffer_builder->CreateVector(operator_vec); + auto name = flatbuffer_builder->CreateString(graph_name); + + tflite::SubGraphBuilder subgraph_builder{*flatbuffer_builder}; + + subgraph_builder.add_tensors(tensors); + subgraph_builder.add_inputs(inputs); + subgraph_builder.add_outputs(outputs); + subgraph_builder.add_operators(operators); + subgraph_builder.add_name(name); + + subgraph_vec.emplace_back(subgraph_builder.Finish()); + } // Create "Model" arguments auto buffers = flatbuffer_builder->CreateVector(buffer_vec); diff --git a/compiler/tflchef/core/src/Op/Abs.cpp b/compiler/tflchef/core/src/Op/Abs.cpp new file mode 100644 index 00000000000..dcb27784caf --- /dev/null +++ b/compiler/tflchef/core/src/Op/Abs.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2020 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 "Abs.h" +#include "Convert.h" + +flatbuffers::Offset AbsChef::value(flatbuffers::FlatBufferBuilder &fbb) const +{ + tflite::AbsOptionsBuilder abs_options_builder{fbb}; + + return abs_options_builder.Finish().Union(); +} + +std::unique_ptr AbsChefFactory::create(const tflchef::Operation *operation) const +{ + return std::unique_ptr{new AbsChef{operation}}; +} diff --git a/compiler/tflchef/core/src/Op/Abs.h b/compiler/tflchef/core/src/Op/Abs.h new file mode 100644 index 00000000000..5b694c6b666 --- /dev/null +++ b/compiler/tflchef/core/src/Op/Abs.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2020 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 __OP_ABS_H__ +#define __OP_ABS_H__ + +#include "OpChef.h" + +class AbsChef final : public OpChef +{ +public: + explicit AbsChef(const tflchef::Operation *operation) : _operation{operation} + { + // DO NOTHING + } + +public: + tflite::BuiltinOperator code(void) const override { return tflite::BuiltinOperator_ABS; } + + tflite::BuiltinOptions type(void) const override { return tflite::BuiltinOptions_AbsOptions; } + + flatbuffers::Offset value(flatbuffers::FlatBufferBuilder &fbb) const override; + +private: + const tflchef::Operation *_operation; +}; + +struct AbsChefFactory final : public OpChefFactory +{ + std::unique_ptr create(const tflchef::Operation *operation) const override; +}; + +#endif // __OP_ABS_H__ diff --git a/compiler/tflchef/core/src/Op/Cos.cpp b/compiler/tflchef/core/src/Op/Cos.cpp new file mode 100644 index 00000000000..547bee1a956 --- /dev/null +++ b/compiler/tflchef/core/src/Op/Cos.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2020 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 "Cos.h" + +flatbuffers::Offset CosChef::value(flatbuffers::FlatBufferBuilder &fbb) const +{ + tflite::CosOptionsBuilder options_builder{fbb}; + + return options_builder.Finish().Union(); +} + +std::unique_ptr CosChefFactory::create(const tflchef::Operation *operation) const +{ + return std::unique_ptr{new CosChef{operation}}; +} diff --git a/compiler/tflchef/core/src/Op/Cos.h b/compiler/tflchef/core/src/Op/Cos.h new file mode 100644 index 00000000000..9bf8cbeabda --- /dev/null +++ b/compiler/tflchef/core/src/Op/Cos.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2020 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 __OP_COS_H__ +#define __OP_COS_H__ + +#include "OpChef.h" + +class CosChef final : public OpChef +{ +public: + explicit CosChef(const tflchef::Operation *operation) : _operation{operation} + { + // DO NOTHING + } + +public: + tflite::BuiltinOperator code(void) const override { return tflite::BuiltinOperator_COS; } + + tflite::BuiltinOptions type(void) const override { return tflite::BuiltinOptions_CosOptions; } + + flatbuffers::Offset value(flatbuffers::FlatBufferBuilder &fbb) const override; + +private: + const tflchef::Operation *_operation; +}; + +struct CosChefFactory final : public OpChefFactory +{ + std::unique_ptr create(const tflchef::Operation *operation) const override; +}; + +#endif // __OP_COS_H__ diff --git a/compiler/tflchef/core/src/Op/Equal.cpp b/compiler/tflchef/core/src/Op/Equal.cpp new file mode 100644 index 00000000000..f7a39f03d68 --- /dev/null +++ b/compiler/tflchef/core/src/Op/Equal.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2020 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 "Equal.h" + +flatbuffers::Offset EqualChef::value(flatbuffers::FlatBufferBuilder &fbb) const +{ + tflite::EqualOptionsBuilder options_builder{fbb}; + + return options_builder.Finish().Union(); +} + +std::unique_ptr EqualChefFactory::create(const tflchef::Operation *operation) const +{ + return std::unique_ptr{new EqualChef{operation}}; +} diff --git a/compiler/tflchef/core/src/Op/Equal.h b/compiler/tflchef/core/src/Op/Equal.h new file mode 100644 index 00000000000..6e097991d03 --- /dev/null +++ b/compiler/tflchef/core/src/Op/Equal.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2020 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 __OP_EQUAL_H__ +#define __OP_EQUAL_H__ + +#include "OpChef.h" + +class EqualChef final : public OpChef +{ +public: + explicit EqualChef(const tflchef::Operation *operation) : _operation{operation} + { + // DO NOTHING + } + +public: + tflite::BuiltinOperator code(void) const override { return tflite::BuiltinOperator_EQUAL; } + + tflite::BuiltinOptions type(void) const override { return tflite::BuiltinOptions_EqualOptions; } + + flatbuffers::Offset value(flatbuffers::FlatBufferBuilder &fbb) const override; + +private: + const tflchef::Operation *_operation; +}; + +struct EqualChefFactory final : public OpChefFactory +{ + std::unique_ptr create(const tflchef::Operation *operation) const override; +}; + +#endif // __OP_EQUAL_H__ diff --git a/compiler/tflchef/core/src/Op/FloorDiv.cpp b/compiler/tflchef/core/src/Op/FloorDiv.cpp new file mode 100644 index 00000000000..0d531bede3d --- /dev/null +++ b/compiler/tflchef/core/src/Op/FloorDiv.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2020 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 "FloorDiv.h" + +#include + +flatbuffers::Offset FloorDivChef::value(flatbuffers::FlatBufferBuilder &fbb) const +{ + tflite::FloorDivOptionsBuilder floor_div_options_builder{fbb}; + return floor_div_options_builder.Finish().Union(); +} + +std::unique_ptr FloorDivChefFactory::create(const tflchef::Operation *operation) const +{ + return std::unique_ptr{new FloorDivChef{operation}}; +} diff --git a/compiler/tflchef/core/src/Op/FloorDiv.h b/compiler/tflchef/core/src/Op/FloorDiv.h new file mode 100644 index 00000000000..151f243142d --- /dev/null +++ b/compiler/tflchef/core/src/Op/FloorDiv.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2020 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 __OP_FLOORDIV_H__ +#define __OP_FLOORDIV_H__ + +#include "OpChef.h" + +class FloorDivChef final : public OpChef +{ +public: + explicit FloorDivChef(const tflchef::Operation *operation) : _operation{operation} + { + // DO NOTHING + } + +public: + tflite::BuiltinOperator code(void) const override { return tflite::BuiltinOperator_FLOOR_DIV; } + + tflite::BuiltinOptions type(void) const override + { + return tflite::BuiltinOptions_FloorDivOptions; + } + + flatbuffers::Offset value(flatbuffers::FlatBufferBuilder &fbb) const override; + +private: + const tflchef::Operation *_operation; +}; + +struct FloorDivChefFactory final : public OpChefFactory +{ + std::unique_ptr create(const tflchef::Operation *operation) const override; +}; + +#endif // __OP_FLOORDIV_H__ diff --git a/compiler/tflchef/core/src/Op/LogicalNot.cpp b/compiler/tflchef/core/src/Op/LogicalNot.cpp new file mode 100644 index 00000000000..26cdef30800 --- /dev/null +++ b/compiler/tflchef/core/src/Op/LogicalNot.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2020 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 "LogicalNot.h" + +flatbuffers::Offset LogicalNotChef::value(flatbuffers::FlatBufferBuilder &fbb) const +{ + tflite::LogicalNotOptionsBuilder options_builder{fbb}; + + return options_builder.Finish().Union(); +} + +std::unique_ptr LogicalNotChefFactory::create(const tflchef::Operation *operation) const +{ + return std::unique_ptr{new LogicalNotChef{operation}}; +} diff --git a/compiler/tflchef/core/src/Op/LogicalNot.h b/compiler/tflchef/core/src/Op/LogicalNot.h new file mode 100644 index 00000000000..d2ca21b9333 --- /dev/null +++ b/compiler/tflchef/core/src/Op/LogicalNot.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2020 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 __OP_LOGICALNOT_H__ +#define __OP_LOGICALNOT_H__ + +#include "OpChef.h" + +class LogicalNotChef final : public OpChef +{ +public: + explicit LogicalNotChef(const tflchef::Operation *operation) : _operation{operation} + { + // DO NOTHING + } + +public: + tflite::BuiltinOperator code(void) const override { return tflite::BuiltinOperator_LOGICAL_NOT; } + + tflite::BuiltinOptions type(void) const override + { + return tflite::BuiltinOptions_LogicalNotOptions; + } + + flatbuffers::Offset value(flatbuffers::FlatBufferBuilder &fbb) const override; + +private: + const tflchef::Operation *_operation; +}; + +struct LogicalNotChefFactory final : public OpChefFactory +{ + std::unique_ptr create(const tflchef::Operation *operation) const override; +}; + +#endif // __OP_LOGICALNOT_H__ diff --git a/compiler/tflchef/core/src/Op/LogicalOr.cpp b/compiler/tflchef/core/src/Op/LogicalOr.cpp new file mode 100644 index 00000000000..483373a81c0 --- /dev/null +++ b/compiler/tflchef/core/src/Op/LogicalOr.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2020 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 "LogicalOr.h" + +flatbuffers::Offset LogicalOrChef::value(flatbuffers::FlatBufferBuilder &fbb) const +{ + tflite::LogicalOrOptionsBuilder options_builder{fbb}; + + return options_builder.Finish().Union(); +} + +std::unique_ptr LogicalOrChefFactory::create(const tflchef::Operation *operation) const +{ + return std::unique_ptr{new LogicalOrChef{operation}}; +} diff --git a/compiler/tflchef/core/src/Op/LogicalOr.h b/compiler/tflchef/core/src/Op/LogicalOr.h new file mode 100644 index 00000000000..b84c9a6ab9b --- /dev/null +++ b/compiler/tflchef/core/src/Op/LogicalOr.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2020 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 __OP_LOGICALOR_H__ +#define __OP_LOGICALOR_H__ + +#include "OpChef.h" + +class LogicalOrChef final : public OpChef +{ +public: + explicit LogicalOrChef(const tflchef::Operation *operation) : _operation{operation} + { + // DO NOTHING + } + +public: + tflite::BuiltinOperator code(void) const override { return tflite::BuiltinOperator_LOGICAL_OR; } + + tflite::BuiltinOptions type(void) const override + { + return tflite::BuiltinOptions_LogicalOrOptions; + } + + flatbuffers::Offset value(flatbuffers::FlatBufferBuilder &fbb) const override; + +private: + const tflchef::Operation *_operation; +}; + +struct LogicalOrChefFactory final : public OpChefFactory +{ + std::unique_ptr create(const tflchef::Operation *operation) const override; +}; + +#endif // __OP_LOGICALOR_H__ diff --git a/compiler/tflchef/core/src/Op/Mean.cpp b/compiler/tflchef/core/src/Op/Mean.cpp new file mode 100644 index 00000000000..def8f7b3b84 --- /dev/null +++ b/compiler/tflchef/core/src/Op/Mean.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2020 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 "Mean.h" +#include "Convert.h" + +#include + +flatbuffers::Offset MeanChef::value(flatbuffers::FlatBufferBuilder &fbb) const +{ + auto &operation = (*_operation); + + assert(operation.has_mean_options()); + + auto keep_dims = operation.mean_options().keep_dims(); + + tflite::ReducerOptionsBuilder mean_options_builder{fbb}; + mean_options_builder.add_keep_dims(keep_dims); + + return mean_options_builder.Finish().Union(); +} + +std::unique_ptr MeanChefFactory::create(const tflchef::Operation *operation) const +{ + return std::unique_ptr{new MeanChef{operation}}; +} diff --git a/compiler/tflchef/core/src/Op/Mean.h b/compiler/tflchef/core/src/Op/Mean.h new file mode 100644 index 00000000000..9032aef3f95 --- /dev/null +++ b/compiler/tflchef/core/src/Op/Mean.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2020 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 __OP_MEAN_H__ +#define __OP_MEAN_H__ + +#include "OpChef.h" + +class MeanChef final : public OpChef +{ +public: + explicit MeanChef(const tflchef::Operation *operation) : _operation{operation} + { + // DO NOTHING + } + +public: + tflite::BuiltinOperator code(void) const override { return tflite::BuiltinOperator_MEAN; } + + tflite::BuiltinOptions type(void) const override { return tflite::BuiltinOptions_ReducerOptions; } + + flatbuffers::Offset value(flatbuffers::FlatBufferBuilder &fbb) const override; + +private: + const tflchef::Operation *_operation; +}; + +struct MeanChefFactory final : public OpChefFactory +{ + std::unique_ptr create(const tflchef::Operation *operation) const override; +}; + +#endif // __OP_MEAN_H__ diff --git a/compiler/tflchef/core/src/Op/Mul.cpp b/compiler/tflchef/core/src/Op/Mul.cpp new file mode 100644 index 00000000000..10ec918c29c --- /dev/null +++ b/compiler/tflchef/core/src/Op/Mul.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2020 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 "Mul.h" +#include "Convert.h" + +#include + +flatbuffers::Offset MulChef::value(flatbuffers::FlatBufferBuilder &fbb) const +{ + auto &operation = (*_operation); + + assert(operation.has_mul_options()); + + auto tflite_activation = as_tflite_activation(operation.mul_options().activation()); + + tflite::MulOptionsBuilder mul_options_builder{fbb}; + mul_options_builder.add_fused_activation_function(tflite_activation); + + return mul_options_builder.Finish().Union(); +} + +std::unique_ptr MulChefFactory::create(const tflchef::Operation *operation) const +{ + return std::unique_ptr{new MulChef{operation}}; +} diff --git a/compiler/tflchef/core/src/Op/Mul.h b/compiler/tflchef/core/src/Op/Mul.h new file mode 100644 index 00000000000..7f1d07ac9ea --- /dev/null +++ b/compiler/tflchef/core/src/Op/Mul.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2020 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 __OP_MUL_H__ +#define __OP_MUL_H__ + +#include "OpChef.h" + +class MulChef final : public OpChef +{ +public: + explicit MulChef(const tflchef::Operation *operation) : _operation{operation} + { + // DO NOTHING + } + +public: + tflite::BuiltinOperator code(void) const override { return tflite::BuiltinOperator_MUL; } + + tflite::BuiltinOptions type(void) const override { return tflite::BuiltinOptions_MulOptions; } + + flatbuffers::Offset value(flatbuffers::FlatBufferBuilder &fbb) const override; + +private: + const tflchef::Operation *_operation; +}; + +struct MulChefFactory final : public OpChefFactory +{ + std::unique_ptr create(const tflchef::Operation *operation) const override; +}; + +#endif // __OP_MUL_H__ diff --git a/compiler/tflchef/core/src/Op/Pack.cpp b/compiler/tflchef/core/src/Op/Pack.cpp new file mode 100644 index 00000000000..2532ac7440d --- /dev/null +++ b/compiler/tflchef/core/src/Op/Pack.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2020 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 "Pack.h" +#include "Convert.h" + +#include + +flatbuffers::Offset PackChef::value(flatbuffers::FlatBufferBuilder &fbb) const +{ + auto &operation = (*_operation); + + assert(operation.has_pack_options()); + + tflite::PackOptionsBuilder pack_options_builder{fbb}; + pack_options_builder.add_values_count(operation.pack_options().values_count()); + pack_options_builder.add_axis(operation.pack_options().axis()); + + return pack_options_builder.Finish().Union(); +} + +std::unique_ptr PackChefFactory::create(const tflchef::Operation *operation) const +{ + return std::unique_ptr{new PackChef{operation}}; +} diff --git a/compiler/tflchef/core/src/Op/Pack.h b/compiler/tflchef/core/src/Op/Pack.h new file mode 100644 index 00000000000..54bdc9338cd --- /dev/null +++ b/compiler/tflchef/core/src/Op/Pack.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2020 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 __OP_PACK_H__ +#define __OP_PACK_H__ + +#include "OpChef.h" + +class PackChef final : public OpChef +{ +public: + explicit PackChef(const tflchef::Operation *operation) : _operation{operation} + { + // DO NOTHING + } + +public: + tflite::BuiltinOperator code(void) const override { return tflite::BuiltinOperator_PACK; } + + tflite::BuiltinOptions type(void) const override { return tflite::BuiltinOptions_PackOptions; } + + flatbuffers::Offset value(flatbuffers::FlatBufferBuilder &fbb) const override; + +private: + const tflchef::Operation *_operation; +}; + +struct PackChefFactory final : public OpChefFactory +{ + std::unique_ptr create(const tflchef::Operation *operation) const override; +}; + +#endif // __OP_PACK_H__ diff --git a/compiler/tflchef/core/src/Op/Pad.cpp b/compiler/tflchef/core/src/Op/Pad.cpp index 21fb60589b4..d0c4719810e 100644 --- a/compiler/tflchef/core/src/Op/Pad.cpp +++ b/compiler/tflchef/core/src/Op/Pad.cpp @@ -18,7 +18,8 @@ flatbuffers::Offset PadChef::value(flatbuffers::FlatBufferBuilder &fbb) const { - return flatbuffers::Offset(); + tflite::PadOptionsBuilder pad_options_builder{fbb}; + return pad_options_builder.Finish().Union(); } std::unique_ptr PadChefFactory::create(const tflchef::Operation *operation) const diff --git a/compiler/tflchef/core/src/Op/Pad.h b/compiler/tflchef/core/src/Op/Pad.h index bf9c0d758b0..9da9c9b8ae2 100644 --- a/compiler/tflchef/core/src/Op/Pad.h +++ b/compiler/tflchef/core/src/Op/Pad.h @@ -30,7 +30,7 @@ class PadChef final : public OpChef public: tflite::BuiltinOperator code(void) const override { return tflite::BuiltinOperator_PAD; } - tflite::BuiltinOptions type(void) const override { return tflite::BuiltinOptions_NONE; } + tflite::BuiltinOptions type(void) const override { return tflite::BuiltinOptions_PadOptions; } flatbuffers::Offset value(flatbuffers::FlatBufferBuilder &fbb) const override; diff --git a/compiler/tflchef/core/src/Op/Shape.cpp b/compiler/tflchef/core/src/Op/Shape.cpp new file mode 100644 index 00000000000..74b1894da06 --- /dev/null +++ b/compiler/tflchef/core/src/Op/Shape.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2020 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 "Shape.h" +#include "Convert.h" + +#include + +flatbuffers::Offset ShapeChef::value(flatbuffers::FlatBufferBuilder &fbb) const +{ + auto &operation = (*_operation); + + assert(operation.has_shape_options()); + + auto tflite_out_type = as_tflite_tensortype(operation.shape_options().out_type()); + + tflite::ShapeOptionsBuilder shape_options_builder{fbb}; + shape_options_builder.add_out_type(tflite_out_type); + + return shape_options_builder.Finish().Union(); +} + +std::unique_ptr ShapeChefFactory::create(const tflchef::Operation *operation) const +{ + return std::unique_ptr{new ShapeChef{operation}}; +} diff --git a/compiler/tflchef/core/src/Op/Shape.h b/compiler/tflchef/core/src/Op/Shape.h new file mode 100644 index 00000000000..ddaeb1d95ce --- /dev/null +++ b/compiler/tflchef/core/src/Op/Shape.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2020 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 __OP_SHAPE_H__ +#define __OP_SHAPE_H__ + +#include "OpChef.h" + +class ShapeChef final : public OpChef +{ +public: + explicit ShapeChef(const tflchef::Operation *operation) : _operation{operation} + { + // DO NOTHING + } + +public: + tflite::BuiltinOperator code(void) const override { return tflite::BuiltinOperator_SHAPE; } + + tflite::BuiltinOptions type(void) const override { return tflite::BuiltinOptions_ShapeOptions; } + + flatbuffers::Offset value(flatbuffers::FlatBufferBuilder &fbb) const override; + +private: + const tflchef::Operation *_operation; +}; + +struct ShapeChefFactory final : public OpChefFactory +{ + std::unique_ptr create(const tflchef::Operation *operation) const override; +}; + +#endif // __OP_SHAPE_H__ diff --git a/compiler/tflchef/core/src/Op/Softmax.cpp b/compiler/tflchef/core/src/Op/Softmax.cpp new file mode 100644 index 00000000000..a554e0d814a --- /dev/null +++ b/compiler/tflchef/core/src/Op/Softmax.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2020 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 "Softmax.h" +#include "Convert.h" + +#include + +flatbuffers::Offset SoftmaxChef::value(flatbuffers::FlatBufferBuilder &fbb) const +{ + auto &operation = (*_operation); + + assert(operation.has_softmax_options()); + + auto tflite_beta = operation.softmax_options().beta(); + + tflite::SoftmaxOptionsBuilder soft_options_builder{fbb}; + soft_options_builder.add_beta(tflite_beta); + + return soft_options_builder.Finish().Union(); +} + +std::unique_ptr SoftmaxChefFactory::create(const tflchef::Operation *operation) const +{ + return std::unique_ptr{new SoftmaxChef{operation}}; +} diff --git a/compiler/tflchef/core/src/Op/Softmax.h b/compiler/tflchef/core/src/Op/Softmax.h new file mode 100644 index 00000000000..8b3f0ebf616 --- /dev/null +++ b/compiler/tflchef/core/src/Op/Softmax.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2020 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 __OP_SOFTMAX_H__ +#define __OP_SOFTMAX_H__ + +#include "OpChef.h" + +class SoftmaxChef final : public OpChef +{ +public: + explicit SoftmaxChef(const tflchef::Operation *operation) : _operation{operation} + { + // DO NOTHING + } + +public: + tflite::BuiltinOperator code(void) const override { return tflite::BuiltinOperator_SOFTMAX; } + + tflite::BuiltinOptions type(void) const override { return tflite::BuiltinOptions_SoftmaxOptions; } + + flatbuffers::Offset value(flatbuffers::FlatBufferBuilder &fbb) const override; + +private: + const tflchef::Operation *_operation; +}; + +struct SoftmaxChefFactory final : public OpChefFactory +{ + std::unique_ptr create(const tflchef::Operation *operation) const override; +}; + +#endif // __OP_SOFTMAX_H__ diff --git a/compiler/tflchef/core/src/Op/Transpose.cpp b/compiler/tflchef/core/src/Op/Transpose.cpp new file mode 100644 index 00000000000..caae6cfa89f --- /dev/null +++ b/compiler/tflchef/core/src/Op/Transpose.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2020 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 "Transpose.h" +#include "Convert.h" + +#include +#include + +flatbuffers::Offset TransposeChef::value(flatbuffers::FlatBufferBuilder &fbb) const +{ + tflite::TransposeOptionsBuilder options_builder{fbb}; + return options_builder.Finish().Union(); +} + +std::unique_ptr TransposeChefFactory::create(const tflchef::Operation *operation) const +{ + return std::unique_ptr{new TransposeChef{operation}}; +} diff --git a/compiler/tflchef/core/src/Op/Transpose.h b/compiler/tflchef/core/src/Op/Transpose.h new file mode 100644 index 00000000000..bb30f7bc94d --- /dev/null +++ b/compiler/tflchef/core/src/Op/Transpose.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2020 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 __OP_TRANSPOSE_H__ +#define __OP_TRANSPOSE_H__ + +#include "OpChef.h" + +class TransposeChef final : public OpChef +{ +public: + explicit TransposeChef(const tflchef::Operation *operation) : _operation{operation} + { + // DO NOTHING + } + +public: + tflite::BuiltinOperator code(void) const override { return tflite::BuiltinOperator_TRANSPOSE; } + + tflite::BuiltinOptions type(void) const override + { + return tflite::BuiltinOptions_TransposeOptions; + } + + flatbuffers::Offset value(flatbuffers::FlatBufferBuilder &fbb) const override; + +private: + const tflchef::Operation *_operation; +}; + +struct TransposeChefFactory final : public OpChefFactory +{ + std::unique_ptr create(const tflchef::Operation *operation) const override; +}; + +#endif // __OP_TRANSPOSE_H__ diff --git a/compiler/tflchef/core/src/OpChef.def b/compiler/tflchef/core/src/OpChef.def index 17f13d43939..923a182098b 100644 --- a/compiler/tflchef/core/src/OpChef.def +++ b/compiler/tflchef/core/src/OpChef.def @@ -4,18 +4,30 @@ // Please keep the list in alphabetical order // OP_CHEF(NAME, FACTORY_CLASS) +OP_CHEF(Abs, AbsChefFactory) OP_CHEF(Add, AddChefFactory) OP_CHEF(ArgMax, ArgMaxChefFactory) OP_CHEF(AveragePool2D, AveragePool2DChefFactory) OP_CHEF(Concatenation, ConcatenationChefFactory) OP_CHEF(Conv2D, Conv2DChefFactory) +OP_CHEF(Cos, CosChefFactory) OP_CHEF(DepthwiseConv2D, DepthwiseConv2DChefFactory) OP_CHEF(Div, DivChefFactory) +OP_CHEF(Equal, EqualChefFactory) +OP_CHEF(FloorDiv, FloorDivChefFactory) OP_CHEF(FullyConnected, FullyConnectedChefFactory) +OP_CHEF(LogicalNot, LogicalNotChefFactory) +OP_CHEF(LogicalOr, LogicalOrChefFactory) OP_CHEF(MaxPool2D, MaxPool2DChefFactory) +OP_CHEF(Mean, MeanChefFactory) +OP_CHEF(Mul, MulChefFactory) +OP_CHEF(Pack, PackChefFactory) OP_CHEF(Pad, PadChefFactory) OP_CHEF(ReLU, ReLUChefFactory) OP_CHEF(ReLU6, ReLU6ChefFactory) OP_CHEF(Reshape, ReshapeChefFactory) +OP_CHEF(Shape, ShapeChefFactory) +OP_CHEF(Softmax, SoftmaxChefFactory) OP_CHEF(Sqrt, SqrtChefFactory) OP_CHEF(Sub, SubChefFactory) +OP_CHEF(Transpose, TransposeChefFactory) diff --git a/compiler/tflchef/core/src/OpChefs.h b/compiler/tflchef/core/src/OpChefs.h index d76d0c09e53..33eaca09d02 100644 --- a/compiler/tflchef/core/src/OpChefs.h +++ b/compiler/tflchef/core/src/OpChefs.h @@ -17,20 +17,32 @@ #ifndef __OP_CHEFS_H__ #define __OP_CHEFS_H__ +#include "Op/Abs.h" #include "Op/Add.h" #include "Op/ArgMax.h" #include "Op/AveragePool2D.h" #include "Op/Concatenation.h" #include "Op/Conv2D.h" +#include "Op/Cos.h" #include "Op/DepthwiseConv2D.h" #include "Op/Div.h" +#include "Op/Equal.h" +#include "Op/FloorDiv.h" #include "Op/FullyConnected.h" +#include "Op/LogicalOr.h" +#include "Op/LogicalNot.h" #include "Op/MaxPool2D.h" +#include "Op/Mean.h" +#include "Op/Mul.h" +#include "Op/Pack.h" #include "Op/Pad.h" #include "Op/ReLU.h" #include "Op/ReLU6.h" #include "Op/Reshape.h" +#include "Op/Shape.h" +#include "Op/Softmax.h" #include "Op/Sqrt.h" #include "Op/Sub.h" +#include "Op/Transpose.h" #endif // __OP_CHEFS_H__ diff --git a/compiler/tflchef/proto/tflchef.proto b/compiler/tflchef/proto/tflchef.proto index 982b615013f..b6c01d40d23 100644 --- a/compiler/tflchef/proto/tflchef.proto +++ b/compiler/tflchef/proto/tflchef.proto @@ -2,12 +2,23 @@ syntax = "proto2"; package tflchef; +// +// Initial version +// - Our initial version +// +// Version 1 +// - Backward compatible with Initial version +// - Added Graph to represent sub graphs +// - Added name, version(default as 1), graph in ModelRecipe +// + // This enum value corresponds to TensorType in TensorFlow Lite schema enum TensorType { FLOAT32 = 0; INT32 = 2; UINT8 = 3; INT64 = 4; + BOOL = 6; } message TensorShape { @@ -90,6 +101,10 @@ message DivOptions { optional Activation activation = 1 [default = NONE]; } +message FloorDivOptions { + // None +} + message FullyConnectedOptions { optional Activation activation = 1 [default = NONE]; } @@ -102,10 +117,59 @@ message ArgMaxOptions { optional TensorType output_type = 1 [default = INT64]; } +message PackOptions { + optional int32 values_count = 1; + optional int32 axis = 2 [default = 0]; +} + message PadOptions { // None } +message SoftmaxOptions { + optional float beta = 1 [default = 0.0]; +} + +message MulOptions { + optional Activation activation = 1 [default = NONE]; +} + +message ReducerOptions { + optional bool keep_dims = 1 [ default = false ]; +} + +message LogicalOrOptions { + // None +} + +message LogicalNotOptions { + // None +} + +message LogicalAndOptions { + // None +} + +message TransposeOptions { + // None +} + +message AbsOptions { + // None +} + +message CosOptions { + // None +} + +message EqualOptions { + // None +} + +message ShapeOptions { + optional TensorType out_type = 1 [default = INT32]; +} + message Operation { optional string type = 1; repeated string input = 2; @@ -123,6 +187,28 @@ message Operation { optional AddOptions add_options = 109; optional ArgMaxOptions argmax_options = 110; optional PadOptions pad_options = 111; + optional SoftmaxOptions softmax_options = 112; + optional MulOptions mul_options = 113; + optional ReducerOptions mean_options = 114; + optional TransposeOptions transpose_options = 115; + optional PackOptions pack_options = 116; + optional LogicalOrOptions logical_or_options = 117; + optional LogicalNotOptions logical_not_options = 118; + optional LogicalAndOptions logical_and_options = 119; + optional AbsOptions abs_options = 120; + optional CosOptions cos_options = 121; + optional EqualOptions equal_options = 122; + optional ShapeOptions shape_options = 123; + optional FloorDivOptions floordiv_options = 124; +} + +// For additional subgraphs +message Graph { + repeated Operand operand = 1; + repeated Operation operation = 2; + repeated string input = 3; + repeated string output = 4; + optional string name = 5; } message ModelRecipe { @@ -130,4 +216,7 @@ message ModelRecipe { repeated Operation operation = 2; repeated string input = 3; repeated string output = 4; + optional string name = 5; + optional uint32 version = 6 [default = 1]; + repeated Graph graph = 7; } diff --git a/compiler/tflchef/tests/CMakeLists.txt b/compiler/tflchef/tests/CMakeLists.txt index 1f11f7e3fa0..5c4dff012a4 100644 --- a/compiler/tflchef/tests/CMakeLists.txt +++ b/compiler/tflchef/tests/CMakeLists.txt @@ -15,24 +15,23 @@ foreach(RECIPE IN ITEMS ${RECIPES}) get_filename_component(RECIPE_PREFIX ${RECIPE} DIRECTORY) set(RECIPE_SOURCE_FILE "${RECIPE_PREFIX}.recipe") - set(RECIPE_SOURCE_TARGET tflchef_${RECIPE_PREFIX}_recipe) - set(RECIPE_OUTPUT_FILE "${RECIPE_PREFIX}.tflite") - set(RECIPE_OUTPUT_TARGET tflchef_${RECIPE_PREFIX}_tflite) # Copy .recipe - add_custom_target(${RECIPE_SOURCE_TARGET} - ALL ${CMAKE_COMMAND} -E copy "${TENSORFLOWLITERECIPES_DIR}/${RECIPE}" - "${CMAKE_CURRENT_BINARY_DIR}/${RECIPE_SOURCE_FILE}" - COMMENT "Generate ${RECIPE_PREFIX}.recipe") + add_custom_command(OUTPUT ${RECIPE_SOURCE_FILE} + COMMAND ${CMAKE_COMMAND} -E copy_if_different + "${TENSORFLOWLITERECIPES_DIR}/${RECIPE}" ${RECIPE_SOURCE_FILE} + DEPENDS "${TENSORFLOWLITERECIPES_DIR}/${RECIPE}" + COMMENT "Generating ${RECIPE_SOURCE_FILE}") # Generate .tflite - add_custom_target(${RECIPE_OUTPUT_TARGET} - ALL $ ${RECIPE_SOURCE_FILE} ${RECIPE_OUTPUT_FILE} - DEPENDS ${RECIPE_SOURCE_TARGET} - COMMENT "Generate ${RECIPE_PREFIX}.tflite") + add_custom_command(OUTPUT ${RECIPE_OUTPUT_FILE} + COMMAND tflchef-file ${RECIPE_SOURCE_FILE} ${RECIPE_OUTPUT_FILE} + DEPENDS tflchef-file ${RECIPE_SOURCE_FILE} + COMMENT "Generating ${RECIPE_OUTPUT_FILE}") list(APPEND TESTS ${RECIPE_PREFIX}) + list(APPEND TESTFILES ${RECIPE_OUTPUT_FILE}) endforeach(RECIPE) # Add local files @@ -42,24 +41,23 @@ foreach(RECIPE IN ITEMS ${RECIPES}) get_filename_component(RECIPE_PREFIX ${RECIPE} DIRECTORY) set(RECIPE_SOURCE_FILE "${RECIPE_PREFIX}.recipe") - set(RECIPE_SOURCE_TARGET tflchef_${RECIPE_PREFIX}_recipe) - set(RECIPE_OUTPUT_FILE "${RECIPE_PREFIX}.tflite") - set(RECIPE_OUTPUT_TARGET tflchef_${RECIPE_PREFIX}_tflite) # Copy .recipe - add_custom_target(${RECIPE_SOURCE_TARGET} - ALL ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/${RECIPE}" - "${CMAKE_CURRENT_BINARY_DIR}/${RECIPE_SOURCE_FILE}" - COMMENT "Generate ${RECIPE_PREFIX}.recipe") + add_custom_command(OUTPUT ${RECIPE_SOURCE_FILE} + COMMAND ${CMAKE_COMMAND} -E copy_if_different + "${CMAKE_CURRENT_SOURCE_DIR}/${RECIPE}" ${RECIPE_SOURCE_FILE} + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${RECIPE}" + COMMENT "Generating ${RECIPE_SOURCE_FILE}") # Generate .tflite - add_custom_target(${RECIPE_OUTPUT_TARGET} - ALL $ ${RECIPE_SOURCE_FILE} ${RECIPE_OUTPUT_FILE} - DEPENDS ${RECIPE_SOURCE_TARGET} - COMMENT "Generate ${RECIPE_PREFIX}.tflite") + add_custom_command(OUTPUT ${RECIPE_OUTPUT_FILE} + COMMAND tflchef-file ${RECIPE_SOURCE_FILE} ${RECIPE_OUTPUT_FILE} + DEPENDS tflchef-file ${RECIPE_SOURCE_FILE} + COMMENT "Generating ${RECIPE_OUTPUT_FILE}") list(APPEND TESTS ${RECIPE_PREFIX}) + list(APPEND TESTFILES ${RECIPE_OUTPUT_FILE}) endforeach(RECIPE) # Test tflchef-reverse @@ -73,29 +71,25 @@ foreach(TFLITEFILE IN ITEMS ${GEN_TFLITEFILES}) # file from above tflchef-file block # use tflite file as input of tflchef-reverse generated from tflchef-file set(RECIPE_OUTPUT_FILE "${TFLITE_PREFIX}.tflite") - set(RECIPE_OUTPUT_TARGET tflchef_${TFLITE_PREFIX}_tflite) - set(RECIPE_GEN_OUTPUT_FILE "${TFLITE_PREFIX}.gen.recipe") - set(RECIPE_GEN_OUTPUT_TARGET tflchef_${TFLITE_PREFIX}_gen_recipe) + set(RECIPE_GEN_OUTPUT_FILE2 "${TFLITE_PREFIX}.gen.tflite") # Generate .gen.recipe from generated .tflite - add_custom_target(${RECIPE_GEN_OUTPUT_TARGET} - ALL $ ${RECIPE_OUTPUT_FILE} ${RECIPE_GEN_OUTPUT_FILE} - DEPENDS ${RECIPE_OUTPUT_TARGET} - COMMENT "Generate ${TFLITE_PREFIX}.gen.recipe") + add_custom_command(OUTPUT ${RECIPE_GEN_OUTPUT_FILE} + COMMAND tflchef-reverse ${RECIPE_OUTPUT_FILE} ${RECIPE_GEN_OUTPUT_FILE} + DEPENDS tflchef-reverse ${RECIPE_OUTPUT_FILE} + COMMENT "Generating ${RECIPE_GEN_OUTPUT_FILE}") # now we are going to generate .gen.tflite from .gen.recipe # to check generated .gen.recipe file is correct by using it. # as weight values may be different, binary comparision is not acceptable. - set(RECIPE_GEN_OUTPUT_FILE2 "${TFLITE_PREFIX}.gen.tflite") - set(RECIPE_GEN_OUTPUT_TARGET2 tflchef_${TFLITE_PREFIX}_gen_tflite) - - add_custom_target(${RECIPE_GEN_OUTPUT_TARGET2} - ALL $ ${RECIPE_GEN_OUTPUT_FILE} ${RECIPE_GEN_OUTPUT_FILE2} - DEPENDS ${RECIPE_GEN_OUTPUT_TARGET} - COMMENT "Generate ${TFLITE_PREFIX}.gen.tflite") + add_custom_command(OUTPUT ${RECIPE_GEN_OUTPUT_FILE2} + COMMAND tflchef-file ${RECIPE_GEN_OUTPUT_FILE} ${RECIPE_GEN_OUTPUT_FILE2} + DEPENDS tflchef-file ${RECIPE_GEN_OUTPUT_FILE} + COMMENT "Generating ${RECIPE_GEN_OUTPUT_FILE2}") list(APPEND TESTS ${TFLITE_PREFIX}.gen) + list(APPEND TESTFILES ${RECIPE_GEN_OUTPUT_FILE2}) endforeach(TFLITEFILE) # Test local tflchef-reverse @@ -105,31 +99,31 @@ foreach(TFLITEFILE IN ITEMS ${GEN_TFLITEFILES}) get_filename_component(TFLITE_PREFIX ${TFLITEFILE} DIRECTORY) set(RECIPE_OUTPUT_FILE "${TFLITE_PREFIX}.tflite") - set(RECIPE_OUTPUT_TARGET tflchef_${TFLITE_PREFIX}_tflite) - set(RECIPE_GEN_OUTPUT_FILE "${TFLITE_PREFIX}.gen.recipe") - set(RECIPE_GEN_OUTPUT_TARGET tflchef_${TFLITE_PREFIX}_gen_recipe) + set(RECIPE_GEN_OUTPUT_FILE2 "${TFLITE_PREFIX}.gen.tflite") # Generate .gen.recipe from generated .tflite - add_custom_target(${RECIPE_GEN_OUTPUT_TARGET} - ALL $ ${RECIPE_OUTPUT_FILE} ${RECIPE_GEN_OUTPUT_FILE} - DEPENDS ${RECIPE_OUTPUT_TARGET} - COMMENT "Generate ${TFLITE_PREFIX}.gen.recipe") + add_custom_command(OUTPUT ${RECIPE_GEN_OUTPUT_FILE} + COMMAND tflchef-reverse ${RECIPE_OUTPUT_FILE} ${RECIPE_GEN_OUTPUT_FILE} + DEPENDS tflchef-reverse ${RECIPE_OUTPUT_FILE} + COMMENT "Generating ${RECIPE_GEN_OUTPUT_FILE}") - set(RECIPE_GEN_OUTPUT_FILE2 "${TFLITE_PREFIX}.gen.tflite") - set(RECIPE_GEN_OUTPUT_TARGET2 tflchef_${TFLITE_PREFIX}_gen_tflite) - - add_custom_target(${RECIPE_GEN_OUTPUT_TARGET2} - ALL $ ${RECIPE_GEN_OUTPUT_FILE} ${RECIPE_GEN_OUTPUT_FILE2} - DEPENDS ${RECIPE_GEN_OUTPUT_TARGET} - COMMENT "Generate ${TFLITE_PREFIX}.gen.tflite") + add_custom_command(OUTPUT ${RECIPE_GEN_OUTPUT_FILE2} + COMMAND tflchef-file ${RECIPE_GEN_OUTPUT_FILE} ${RECIPE_GEN_OUTPUT_FILE2} + DEPENDS tflchef-file ${RECIPE_GEN_OUTPUT_FILE} + COMMENT "Generating ${RECIPE_GEN_OUTPUT_FILE2}") list(APPEND TESTS ${TFLITE_PREFIX}.gen) + list(APPEND TESTFILES ${RECIPE_GEN_OUTPUT_FILE2}) endforeach(TFLITEFILE) +# Add a dummy target to create a target-level dependency. +# TODO Find a way to create a dependency between tflchef_test and generated testfiles. +add_custom_target(tflchef_testfiles ALL DEPENDS ${TESTFILES}) + +# Using mio_tflite_validate for temporary as it only calls flatbuffer validate +# TODO do testing with running the model with runtime/interpreter add_test(NAME tflchef_test - COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/runall.sh" - $ - $ - "${CMAKE_CURRENT_BINARY_DIR}" + COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/runvalidate.sh" + $ ${TESTS}) diff --git a/compiler/tflchef/tests/multisubgraph/test.recipe b/compiler/tflchef/tests/multisubgraph/test.recipe new file mode 100644 index 00000000000..b55af133780 --- /dev/null +++ b/compiler/tflchef/tests/multisubgraph/test.recipe @@ -0,0 +1,72 @@ +version: 1 + +graph { + operand { + name: "ifm" + type: FLOAT32 + shape { dim: 1 dim: 3 dim: 3 dim: 2 } + } + operand { + name: "ofm" + type: FLOAT32 + shape { dim: 1 dim: 3 dim: 3 dim: 2 } + } + operation { + type: "ReLU" + input: "ifm" + output: "ofm" + } + input: "ifm" + output: "ofm" + name: "Sub_01" +} + +graph { + operand { + name: "ifm" + type: FLOAT32 + shape { dim: 1 dim: 3 dim: 3 dim: 2 } + } + operand { + name: "ofm" + type: FLOAT32 + shape { dim: 1 dim: 3 dim: 3 dim: 2 } + } + operation { + type: "ReLU6" + input: "ifm" + output: "ofm" + } + input: "ifm" + output: "ofm" + name: "Sub_01" +} + +operand { + name: "ifm1" + type: FLOAT32 + shape { dim: 1 dim: 3 dim: 3 dim: 2 } +} +operand { + name: "ifm2" + type: FLOAT32 + shape { dim: 1 dim: 3 dim: 3 dim: 2 } +} +operand { + name: "ofm" + type: FLOAT32 + shape { dim: 1 dim: 3 dim: 3 dim: 2 } +} +operation { + type: "Add" + input: "ifm1" + input: "ifm2" + output: "ofm" + add_options { + activation: NONE + } +} +input: "ifm1" +input: "ifm2" +output: "ofm" +name: "Main" diff --git a/compiler/tflchef/tests/runvalidate.sh b/compiler/tflchef/tests/runvalidate.sh new file mode 100755 index 00000000000..a1453b39918 --- /dev/null +++ b/compiler/tflchef/tests/runvalidate.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +if [[ $# -le 3 ]]; then + echo "USAGE: $0 [mio_tflite_validate path] [prefix 0] " + exit 255 +fi + +MIO_TFLITE_VALIDATE_PATH="$1"; shift + +echo "-- Found mio_tflite_validate: ${NNKIT_RUN_PATH}" + +TESTED=() +PASSED=() +FAILED=() + +pushd "${WORKDIR}" +while [[ $# -ne 0 ]]; do + PREFIX="$1"; shift + + TESTED+=("${PREFIX}") + + PASSED_TAG="${PREFIX}.passed" + + rm -f "${PASSED_TAG}" + + cat > "${PREFIX}.log" <( + exec 2>&1 + + echo "'${MIO_TFLITE_VALIDATE_PATH}' '${PREFIX}.tflite'" + "${MIO_TFLITE_VALIDATE_PATH}" "${PREFIX}.tflite" + + if [[ $? -eq 0 ]]; then + touch "${PASSED_TAG}" + fi + ) + + if [[ -f "${PASSED_TAG}" ]]; then + PASSED+=("$PREFIX") + else + FAILED+=("$PREFIX") + fi +done +popd + +echo "SUMMARY: ${#PASSED[@]} PASS AND ${#FAILED[@]} FAIL AMONG ${#TESTED[@]} TESTS" + +if [[ ${#TESTED[@]} -ne ${#PASSED[@]} ]]; then + echo "FAILED" + for TEST in "${FAILED[@]}" + do + echo "- ${TEST}" + done + exit 255 +fi + +exit 0 diff --git a/compiler/tflchef/tflite/src/Convert.cpp b/compiler/tflchef/tflite/src/Convert.cpp index 111510560f2..dc60e00870d 100644 --- a/compiler/tflchef/tflite/src/Convert.cpp +++ b/compiler/tflchef/tflite/src/Convert.cpp @@ -27,13 +27,15 @@ tflchef::TensorType as_tflchef_type(const tflite::TensorType type) return tflchef::FLOAT32; case tflite::TensorType_INT32: return tflchef::INT32; + case tflite::TensorType_INT64: + return tflchef::INT64; case tflite::TensorType_UINT8: return tflchef::UINT8; + case tflite::TensorType_BOOL: + return tflchef::BOOL; // TODO handle other types // TensorType_FLOAT16 - // TensorType_INT64 // TensorType_STRING - // TensorType_BOOL // TensorType_INT16 // TensorType_COMPLEX64 default: diff --git a/compiler/tflchef/tflite/src/Convert.h b/compiler/tflchef/tflite/src/Convert.h index f3020cf4353..8623e7b78b4 100644 --- a/compiler/tflchef/tflite/src/Convert.h +++ b/compiler/tflchef/tflite/src/Convert.h @@ -28,6 +28,18 @@ tflchef::TensorType as_tflchef_type(const tflite::TensorType type); tflchef::Activation as_tflchef_activation(const tflite::ActivationFunctionType type); tflchef::Padding as_tflchef_padding(const tflite::Padding padding); +/** + * @brief extract buffer data to std::vector
+ */ +template std::vector
extract_buffer(const tflite::Buffer *buffer) +{ + auto buffer_length = buffer->data()->size(); + auto num_elements = buffer_length / sizeof(DT); + std::vector
result(num_elements); + std::memcpy(result.data(), buffer->data()->data(), buffer_length); + return result; +} + template std::vector as_index_vector(const flatbuffers::Vector *flat_array) { std::vector ret(flat_array->Length()); diff --git a/compiler/tflchef/tflite/src/Op/Abs.cpp b/compiler/tflchef/tflite/src/Op/Abs.cpp new file mode 100644 index 00000000000..7d769e3441d --- /dev/null +++ b/compiler/tflchef/tflite/src/Op/Abs.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2020 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 "Abs.h" + +#include "Convert.h" + +namespace tflchef +{ + +void TFliteOpAbs::filler(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const +{ + // Nothing to do with filler +} + +tflchef::Operation *TFliteOpAbs::build(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const +{ + auto operation = model_recipe->add_operation(); + + operation->set_type("Abs"); + + return operation; +} + +} // namespace tflchef diff --git a/compiler/tflchef/tflite/src/Op/Abs.h b/compiler/tflchef/tflite/src/Op/Abs.h new file mode 100644 index 00000000000..d99b0d593f6 --- /dev/null +++ b/compiler/tflchef/tflite/src/Op/Abs.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2020 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 __TFLITE_OP_ABS_H__ +#define __TFLITE_OP_ABS_H__ + +#include "TFliteOpChef.h" + +namespace tflchef +{ + +/** + * @brief tflchef operator builder for abs + */ +class TFliteOpAbs : public TFliteOpChef +{ +public: + void filler(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const override; + tflchef::Operation *build(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const override; +}; + +} // namespace tflchef + +#endif // __TFLITE_OP_ABS_H__ diff --git a/compiler/tflchef/tflite/src/Op/ArgMax.cpp b/compiler/tflchef/tflite/src/Op/ArgMax.cpp new file mode 100644 index 00000000000..f4d1c5e667a --- /dev/null +++ b/compiler/tflchef/tflite/src/Op/ArgMax.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2020 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 "ArgMax.h" + +#include "Convert.h" + +namespace tflchef +{ + +void TFliteOpArgMax::filler(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const +{ + // filler for second input, argmax/dim + const auto &inputs = *op->inputs(); + + const tflite::Tensor *dim_tensor = import->tensors()->Get(inputs[1]); + assert(dim_tensor->type() == tflite::TensorType::TensorType_INT32); + const tflite::Buffer *buffer = import->buffers()->Get(dim_tensor->buffer()); + auto vec = extract_buffer(buffer); + import->set_tensor_filler(inputs[1], vec); +} + +tflchef::Operation *TFliteOpArgMax::build(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const +{ + auto op_params = op->builtin_options_as_ArgMaxOptions(); + assert(op_params != nullptr); + + auto operation = model_recipe->add_operation(); + + operation->set_type("ArgMax"); + + auto op_options = operation->mutable_argmax_options(); + + op_options->set_output_type(as_tflchef_type(op_params->output_type())); + + return operation; +} + +} // namespace tflchef diff --git a/compiler/tflchef/tflite/src/Op/ArgMax.h b/compiler/tflchef/tflite/src/Op/ArgMax.h new file mode 100644 index 00000000000..30068ecf2ec --- /dev/null +++ b/compiler/tflchef/tflite/src/Op/ArgMax.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2020 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 __TFLITE_OP_ARGMAX_H__ +#define __TFLITE_OP_ARGMAX_H__ + +#include "TFliteOpChef.h" + +namespace tflchef +{ + +/** + * @brief tflchef operator builder for ArgMax + */ +class TFliteOpArgMax : public TFliteOpChef +{ +public: + void filler(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const override; + tflchef::Operation *build(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const override; +}; + +} // namespace tflchef + +#endif // __TFLITE_OP_ARGMAX_H__ diff --git a/compiler/tflchef/tflite/src/Op/Cos.cpp b/compiler/tflchef/tflite/src/Op/Cos.cpp new file mode 100644 index 00000000000..9f2c49d49f5 --- /dev/null +++ b/compiler/tflchef/tflite/src/Op/Cos.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2020 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 "Cos.h" + +#include "Convert.h" + +namespace tflchef +{ + +void TFliteOpCos::filler(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const +{ + // Nothing to do with filler +} + +tflchef::Operation *TFliteOpCos::build(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const +{ + auto operation = model_recipe->add_operation(); + + operation->set_type("Cos"); + + return operation; +} + +} // namespace tflchef diff --git a/compiler/tflchef/tflite/src/Op/Cos.h b/compiler/tflchef/tflite/src/Op/Cos.h new file mode 100644 index 00000000000..8f3dbe3a64e --- /dev/null +++ b/compiler/tflchef/tflite/src/Op/Cos.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2020 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 __TFLITE_OP_COS_H__ +#define __TFLITE_OP_COS_H__ + +#include "TFliteOpChef.h" + +namespace tflchef +{ + +/** + * @brief tflchef operator builder for Cos + */ +class TFliteOpCos : public TFliteOpChef +{ +public: + void filler(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const override; + tflchef::Operation *build(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const override; +}; + +} // namespace tflchef + +#endif // __TFLITE_OP_COS_H__ diff --git a/compiler/tflchef/tflite/src/Op/Equal.cpp b/compiler/tflchef/tflite/src/Op/Equal.cpp new file mode 100644 index 00000000000..a515862287d --- /dev/null +++ b/compiler/tflchef/tflite/src/Op/Equal.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2020 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 "Equal.h" + +#include "Convert.h" + +namespace tflchef +{ + +void TFliteOpEqual::filler(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const +{ + // Nothing to do with filler +} + +tflchef::Operation *TFliteOpEqual::build(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const +{ + auto operation = model_recipe->add_operation(); + + operation->set_type("Equal"); + + return operation; +} + +} // namespace tflchef diff --git a/compiler/tflchef/tflite/src/Op/Equal.h b/compiler/tflchef/tflite/src/Op/Equal.h new file mode 100644 index 00000000000..fd4b400015c --- /dev/null +++ b/compiler/tflchef/tflite/src/Op/Equal.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2020 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 __TFLITE_OP_EQUAL_H__ +#define __TFLITE_OP_EQUAL_H__ + +#include "TFliteOpChef.h" + +namespace tflchef +{ + +/** + * @brief tflchef operator builder for Equal + */ +class TFliteOpEqual : public TFliteOpChef +{ +public: + void filler(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const override; + tflchef::Operation *build(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const override; +}; + +} // namespace tflchef + +#endif // __TFLITE_OP_EQUAL_H__ diff --git a/compiler/tflchef/tflite/src/Op/FloorDiv.cpp b/compiler/tflchef/tflite/src/Op/FloorDiv.cpp new file mode 100644 index 00000000000..492c6941f17 --- /dev/null +++ b/compiler/tflchef/tflite/src/Op/FloorDiv.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2020 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 "FloorDiv.h" + +#include "Convert.h" + +namespace tflchef +{ + +void TFliteOpFloorDiv::filler(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const +{ + // Nothing to do with filler +} + +tflchef::Operation *TFliteOpFloorDiv::build(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const +{ + auto operation = model_recipe->add_operation(); + + operation->set_type("FloorDiv"); + + return operation; +} + +} // namespace tflchef diff --git a/compiler/tflchef/tflite/src/Op/FloorDiv.h b/compiler/tflchef/tflite/src/Op/FloorDiv.h new file mode 100644 index 00000000000..5d049a668f2 --- /dev/null +++ b/compiler/tflchef/tflite/src/Op/FloorDiv.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2020 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 __TFLITE_OP_FLOORDIV_H__ +#define __TFLITE_OP_FLOORDIV_H__ + +#include "TFliteOpChef.h" + +namespace tflchef +{ + +/** + * @brief tflchef operator builder for floor division + */ +class TFliteOpFloorDiv : public TFliteOpChef +{ +public: + void filler(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const override; + tflchef::Operation *build(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const override; +}; + +} // namespace tflchef + +#endif // __TFLITE_OP_FLOORDIV_H__ diff --git a/compiler/tflchef/tflite/src/Op/LogicalNot.cpp b/compiler/tflchef/tflite/src/Op/LogicalNot.cpp new file mode 100644 index 00000000000..ecd5b903c44 --- /dev/null +++ b/compiler/tflchef/tflite/src/Op/LogicalNot.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2020 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 "LogicalNot.h" + +#include "Convert.h" + +namespace tflchef +{ + +void TFliteOpLogicalNot::filler(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const +{ + // Nothing to do with filler +} + +tflchef::Operation *TFliteOpLogicalNot::build(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const +{ + auto operation = model_recipe->add_operation(); + + operation->set_type("LogicalNot"); + + return operation; +} + +} // namespace tflchef diff --git a/compiler/tflchef/tflite/src/Op/LogicalNot.h b/compiler/tflchef/tflite/src/Op/LogicalNot.h new file mode 100644 index 00000000000..b75d3355499 --- /dev/null +++ b/compiler/tflchef/tflite/src/Op/LogicalNot.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2020 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 __TFLITE_OP_LOGICALNOT_H__ +#define __TFLITE_OP_LOGICALNOT_H__ + +#include "TFliteOpChef.h" + +namespace tflchef +{ + +/** + * @brief tflchef operator builder for LogicalNot + */ +class TFliteOpLogicalNot : public TFliteOpChef +{ +public: + void filler(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const override; + tflchef::Operation *build(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const override; +}; + +} // namespace tflchef + +#endif // __TFLITE_OP_LOGICALNOT_H__ diff --git a/compiler/tflchef/tflite/src/Op/LogicalOr.cpp b/compiler/tflchef/tflite/src/Op/LogicalOr.cpp new file mode 100644 index 00000000000..b91f4cfca71 --- /dev/null +++ b/compiler/tflchef/tflite/src/Op/LogicalOr.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2020 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 "LogicalOr.h" + +#include "Convert.h" + +namespace tflchef +{ + +void TFliteOpLogicalOr::filler(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const +{ + // Nothing to do with filler +} + +tflchef::Operation *TFliteOpLogicalOr::build(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const +{ + auto operation = model_recipe->add_operation(); + + operation->set_type("LogicalOr"); + + return operation; +} + +} // namespace tflchef diff --git a/compiler/tflchef/tflite/src/Op/LogicalOr.h b/compiler/tflchef/tflite/src/Op/LogicalOr.h new file mode 100644 index 00000000000..5331a0d655c --- /dev/null +++ b/compiler/tflchef/tflite/src/Op/LogicalOr.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2020 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 __TFLITE_OP_LOGICALOR_H__ +#define __TFLITE_OP_LOGICALOR_H__ + +#include "TFliteOpChef.h" + +namespace tflchef +{ + +/** + * @brief tflchef operator builder for LogicalOr + */ +class TFliteOpLogicalOr : public TFliteOpChef +{ +public: + void filler(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const override; + tflchef::Operation *build(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const override; +}; + +} // namespace tflchef + +#endif // __TFLITE_OP_LOGICALOR_H__ diff --git a/compiler/tflchef/tflite/src/Op/Mean.cpp b/compiler/tflchef/tflite/src/Op/Mean.cpp new file mode 100644 index 00000000000..1c297578154 --- /dev/null +++ b/compiler/tflchef/tflite/src/Op/Mean.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2020 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 "Mean.h" + +#include "Convert.h" + +namespace tflchef +{ + +void TFliteOpMean::filler(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const +{ + // filler for second input + const auto &inputs = *op->inputs(); + + const tflite::Tensor *tensor = import->tensors()->Get(inputs[1]); + assert(tensor->type() == tflite::TensorType::TensorType_INT32); + const tflite::Buffer *buffer = import->buffers()->Get(tensor->buffer()); + auto vec = extract_buffer(buffer); + import->set_tensor_filler(inputs[1], vec); +} + +tflchef::Operation *TFliteOpMean::build(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const +{ + auto op_params = op->builtin_options_as_ReducerOptions(); + assert(op_params != nullptr); + + auto operation = model_recipe->add_operation(); + + operation->set_type("Mean"); + + auto op_options = operation->mutable_mean_options(); + + op_options->set_keep_dims(op_params->keep_dims()); + + return operation; +} + +} // namespace tflchef diff --git a/compiler/tflchef/tflite/src/Op/Mean.h b/compiler/tflchef/tflite/src/Op/Mean.h new file mode 100644 index 00000000000..532c40c6622 --- /dev/null +++ b/compiler/tflchef/tflite/src/Op/Mean.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2020 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 __TFLITE_OP_MEAN_H__ +#define __TFLITE_OP_MEAN_H__ + +#include "TFliteOpChef.h" + +namespace tflchef +{ + +/** + * @brief tflchef operator builder for mean + */ +class TFliteOpMean : public TFliteOpChef +{ +public: + void filler(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const override; + tflchef::Operation *build(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const override; +}; + +} // namespace tflchef + +#endif // __TFLITE_OP_MEAN_H__ diff --git a/compiler/tflchef/tflite/src/Op/Pack.cpp b/compiler/tflchef/tflite/src/Op/Pack.cpp new file mode 100644 index 00000000000..ddf8c7d5d6e --- /dev/null +++ b/compiler/tflchef/tflite/src/Op/Pack.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2020 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 "Pack.h" + +#include "Convert.h" + +namespace tflchef +{ + +void TFliteOpPack::filler(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const +{ + // Nothing to do with filler +} + +tflchef::Operation *TFliteOpPack::build(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const +{ + auto op_params = op->builtin_options_as_PackOptions(); + assert(op_params != nullptr); + + auto operation = model_recipe->add_operation(); + + operation->set_type("Pack"); + + auto op_options = operation->mutable_pack_options(); + + op_options->set_axis(op_params->axis()); + op_options->set_values_count(op_params->values_count()); + + return operation; +} + +} // namespace tflchef diff --git a/compiler/tflchef/tflite/src/Op/Pack.h b/compiler/tflchef/tflite/src/Op/Pack.h new file mode 100644 index 00000000000..7779f64ed48 --- /dev/null +++ b/compiler/tflchef/tflite/src/Op/Pack.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2020 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 __TFLITE_OP_PACK_H__ +#define __TFLITE_OP_PACK_H__ + +#include "TFliteOpChef.h" + +namespace tflchef +{ + +/** + * @brief tflchef operator builder for pack + */ +class TFliteOpPack : public TFliteOpChef +{ +public: + void filler(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const override; + tflchef::Operation *build(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const override; +}; + +} // namespace tflchef + +#endif // __TFLITE_OP_PACK_H__ diff --git a/compiler/tflchef/tflite/src/Op/Pad.cpp b/compiler/tflchef/tflite/src/Op/Pad.cpp new file mode 100644 index 00000000000..2978e4422ef --- /dev/null +++ b/compiler/tflchef/tflite/src/Op/Pad.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2020 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 "Pad.h" + +#include "Convert.h" + +namespace tflchef +{ + +void TFliteOpPad::filler(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const +{ + // filler for second input + const auto &inputs = *op->inputs(); + + const tflite::Tensor *tensor = import->tensors()->Get(inputs[1]); + assert(tensor->type() == tflite::TensorType::TensorType_INT32); + const tflite::Buffer *buffer = import->buffers()->Get(tensor->buffer()); + auto vec = extract_buffer(buffer); + import->set_tensor_filler(inputs[1], vec); +} + +tflchef::Operation *TFliteOpPad::build(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const +{ + auto operation = model_recipe->add_operation(); + + operation->set_type("Pad"); + + return operation; +} + +} // namespace tflchef diff --git a/compiler/tflchef/tflite/src/Op/Pad.h b/compiler/tflchef/tflite/src/Op/Pad.h new file mode 100644 index 00000000000..99998d4188b --- /dev/null +++ b/compiler/tflchef/tflite/src/Op/Pad.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2020 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 __TFLITE_OP_PAD_H__ +#define __TFLITE_OP_PAD_H__ + +#include "TFliteOpChef.h" + +namespace tflchef +{ + +/** + * @brief tflchef operator builder for PAD + */ +class TFliteOpPad : public TFliteOpChef +{ +public: + void filler(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const override; + tflchef::Operation *build(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const override; +}; + +} // namespace tflchef + +#endif // __TFLITE_OP_PAD_H__ diff --git a/compiler/tflchef/tflite/src/Op/Softmax.cpp b/compiler/tflchef/tflite/src/Op/Softmax.cpp new file mode 100644 index 00000000000..5b5c94f7ed0 --- /dev/null +++ b/compiler/tflchef/tflite/src/Op/Softmax.cpp @@ -0,0 +1,47 @@ +/* + * 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 "Softmax.h" + +#include "Convert.h" + +namespace tflchef +{ + +void TFliteOpSoftmax::filler(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const +{ + // Nothing to do with filler +} + +tflchef::Operation *TFliteOpSoftmax::build(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const +{ + auto op_params = op->builtin_options_as_SoftmaxOptions(); + assert(op_params != nullptr); + + auto operation = model_recipe->add_operation(); + + operation->set_type("Softmax"); + + auto op_options = operation->mutable_softmax_options(); + + op_options->set_beta(op_params->beta()); + + return operation; +} + +} // namespace tflchef diff --git a/compiler/nnc/utils/tflite_model_generator/ModelGenerator.cpp b/compiler/tflchef/tflite/src/Op/Softmax.h similarity index 53% rename from compiler/nnc/utils/tflite_model_generator/ModelGenerator.cpp rename to compiler/tflchef/tflite/src/Op/Softmax.h index fc42d793fb9..cf168bdd9c4 100644 --- a/compiler/nnc/utils/tflite_model_generator/ModelGenerator.cpp +++ b/compiler/tflchef/tflite/src/Op/Softmax.h @@ -14,28 +14,26 @@ * limitations under the License. */ -#include -#include -#include +#ifndef __TFLITE_OP_SOFTMAX_H__ +#define __TFLITE_OP_SOFTMAX_H__ -#include "Tree.h" +#include "TFliteOpChef.h" -#include "RandomModelBuilder.h" -#include "TFLiteRandomModelBuilder.h" - -using namespace modelgen; -using namespace treebuilder; - -int main(int argc, const char *argv[]) +namespace tflchef { - std::unique_ptr tree_builder(new TreeBuilder); - auto tree = tree_builder->buildTree(); - std::unique_ptr builder(new TFLiteRandomModelBuilder); - builder->convertTreeToModel(tree.get()); +/** + * @brief tflchef operator builder for Softmax + */ +class TFliteOpSoftmax : public TFliteOpChef +{ +public: + void filler(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const override; + tflchef::Operation *build(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const override; +}; - std::unique_ptr saver = builder->createModelSaver(); - saver->saveModel(); +} // namespace tflchef - return 0; -} +#endif // __TFLITE_OP_SOFTMAX_H__ diff --git a/compiler/tflchef/tflite/src/Op/Sqrt.cpp b/compiler/tflchef/tflite/src/Op/Sqrt.cpp index 5d967d66f23..dd6bfcab070 100644 --- a/compiler/tflchef/tflite/src/Op/Sqrt.cpp +++ b/compiler/tflchef/tflite/src/Op/Sqrt.cpp @@ -25,6 +25,19 @@ void TFliteOpSqrt::filler(const tflite::Operator *op, TFliteImport *import, tflchef::ModelRecipe *model_recipe) const { // Nothing to do with filler + // But input has filler for constant inputs + const auto &inputs = *op->inputs(); + + const tflite::Tensor *tensor = import->tensors()->Get(inputs[0]); + if (tensor->type() == tflite::TensorType::TensorType_FLOAT32) + { + const tflite::Buffer *buffer = import->buffers()->Get(tensor->buffer()); + if (buffer && buffer->data()) + { + auto vec = extract_buffer(buffer); + import->set_tensor_filler(inputs[0], vec); + } + } } tflchef::Operation *TFliteOpSqrt::build(const tflite::Operator *op, TFliteImport *import, diff --git a/compiler/tflchef/tflite/src/Op/Transpose.cpp b/compiler/tflchef/tflite/src/Op/Transpose.cpp new file mode 100644 index 00000000000..ae97a19e213 --- /dev/null +++ b/compiler/tflchef/tflite/src/Op/Transpose.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2020 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 "Transpose.h" + +#include "Convert.h" + +namespace tflchef +{ + +void TFliteOpTranspose::filler(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const +{ + const auto &inputs = *op->inputs(); + + const tflite::Tensor *perm_tensor = import->tensors()->Get(inputs[1]); + assert(perm_tensor->type() == tflite::TensorType::TensorType_INT32); + const tflite::Buffer *buffer = import->buffers()->Get(perm_tensor->buffer()); + auto vec = extract_buffer(buffer); + import->set_tensor_filler(inputs[1], vec); +} + +tflchef::Operation *TFliteOpTranspose::build(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const +{ + auto op_params = op->builtin_options_as(); + assert(op_params != nullptr); + (void)op_params; + + auto operation = model_recipe->add_operation(); + + operation->set_type("Transpose"); + + auto op_options = operation->mutable_transpose_options(); + (void)op_options; + + return operation; +} + +} // namespace tflchef diff --git a/compiler/tflchef/tflite/src/Op/Transpose.h b/compiler/tflchef/tflite/src/Op/Transpose.h new file mode 100644 index 00000000000..f0d944b6be2 --- /dev/null +++ b/compiler/tflchef/tflite/src/Op/Transpose.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2020 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 __TFLITE_OP_TRANSPOSE_H__ +#define __TFLITE_OP_TRANSPOSE_H__ + +#include "TFliteOpChef.h" + +namespace tflchef +{ + +/** + * @brief tflchef operator builder for Transpose + */ +class TFliteOpTranspose : public TFliteOpChef +{ +public: + void filler(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const override; + tflchef::Operation *build(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const override; +}; + +} // namespace tflchef + +#endif // __TFLITE_OP_TRANSPOSE_H__ diff --git a/compiler/tflchef/tflite/src/RecipeChef.cpp b/compiler/tflchef/tflite/src/RecipeChef.cpp index 0a26ae06655..407006b2655 100644 --- a/compiler/tflchef/tflite/src/RecipeChef.cpp +++ b/compiler/tflchef/tflite/src/RecipeChef.cpp @@ -113,6 +113,7 @@ std::unique_ptr generate_recipe(const tflite::Model *model) // filler for weights, bias and so on std::vector expvalues; + std::vector expfvalues; if (tflite_import.get_tensor_filler(i)) { tflchef::TensorFiller *filler = operand->mutable_filler(); @@ -132,6 +133,17 @@ std::unique_ptr generate_recipe(const tflite::Model *model) filler->add_arg(ss.str()); } } + else if (tflite_import.get_tensor_filler(i, expfvalues)) + { + tflchef::TensorFiller *filler = operand->mutable_filler(); + filler->set_tag("explicit"); + for (auto value : expfvalues) + { + std::ostringstream ss; + ss << value; + filler->add_arg(ss.str()); + } + } auto quant = tensor->quantization(); if (quant != nullptr) diff --git a/compiler/tflchef/tflite/src/TFliteImport.h b/compiler/tflchef/tflite/src/TFliteImport.h index 0ae7832d8af..fa819640554 100644 --- a/compiler/tflchef/tflite/src/TFliteImport.h +++ b/compiler/tflchef/tflite/src/TFliteImport.h @@ -77,6 +77,11 @@ class TFliteImport _tensor_filler_vint32[tensor_index] = expvalues; } + void set_tensor_filler(uint32_t tensor_index, std::vector &expvalues) + { + _tensor_filler_vfloat[tensor_index] = expvalues; + } + /** * @brief This will return true if the tensor by index, needs a filler option. */ @@ -104,6 +109,17 @@ class TFliteImport return false; } + bool get_tensor_filler(uint32_t tensor_index, std::vector &expvalues) + { + auto it = _tensor_filler_vfloat.find(tensor_index); + if (it != _tensor_filler_vfloat.end()) + { + expvalues = it->second; + return true; + } + return false; + } + private: const TFliteSubGraphs_t *_subgraphs; const TFliteBuffers_t *_buffers; @@ -116,6 +132,7 @@ class TFliteImport std::map _tensor_filler; std::map> _tensor_filler_vint32; + std::map> _tensor_filler_vfloat; }; } // namespace tflchef diff --git a/compiler/tflchef/tflite/src/TFliteOpChefs.h b/compiler/tflchef/tflite/src/TFliteOpChefs.h index 4971cd2dcaa..01bbb27a4bc 100644 --- a/compiler/tflchef/tflite/src/TFliteOpChefs.h +++ b/compiler/tflchef/tflite/src/TFliteOpChefs.h @@ -18,18 +18,30 @@ #define __TFLITE_OP_CHEFS_H__ // In alphabet order +#include "Op/Abs.h" #include "Op/Add.h" +#include "Op/ArgMax.h" #include "Op/AveragePool2D.h" #include "Op/Concatenation.h" #include "Op/Conv2D.h" +#include "Op/Cos.h" #include "Op/DepthwiseConv2D.h" #include "Op/Div.h" +#include "Op/Equal.h" +#include "Op/FloorDiv.h" #include "Op/FullyConnected.h" +#include "Op/LogicalNot.h" +#include "Op/LogicalOr.h" #include "Op/MaxPool2D.h" +#include "Op/Mean.h" +#include "Op/Pack.h" +#include "Op/Pad.h" #include "Op/ReLU.h" #include "Op/ReLU6.h" #include "Op/Reshape.h" +#include "Op/Softmax.h" #include "Op/Sqrt.h" #include "Op/Sub.h" +#include "Op/Transpose.h" #endif // __TFLITE_OP_CHEFS_H__ diff --git a/compiler/tflchef/tflite/src/TFliteOpRegistry.h b/compiler/tflchef/tflite/src/TFliteOpRegistry.h index d41c4dc153d..8bea16eb773 100644 --- a/compiler/tflchef/tflite/src/TFliteOpRegistry.h +++ b/compiler/tflchef/tflite/src/TFliteOpRegistry.h @@ -54,20 +54,32 @@ class TFliteOpRegistry private: TFliteOpRegistry() { + _tfliteop_map[tflite::BuiltinOperator_ABS] = make_unique(); _tfliteop_map[tflite::BuiltinOperator_ADD] = make_unique(); + _tfliteop_map[tflite::BuiltinOperator_ARG_MAX] = make_unique(); _tfliteop_map[tflite::BuiltinOperator_AVERAGE_POOL_2D] = make_unique(); _tfliteop_map[tflite::BuiltinOperator_CONCATENATION] = make_unique(); _tfliteop_map[tflite::BuiltinOperator_CONV_2D] = make_unique(); + _tfliteop_map[tflite::BuiltinOperator_COS] = make_unique(); _tfliteop_map[tflite::BuiltinOperator_DEPTHWISE_CONV_2D] = make_unique(); _tfliteop_map[tflite::BuiltinOperator_DIV] = make_unique(); + _tfliteop_map[tflite::BuiltinOperator_EQUAL] = make_unique(); + _tfliteop_map[tflite::BuiltinOperator_FLOOR_DIV] = make_unique(); _tfliteop_map[tflite::BuiltinOperator_FULLY_CONNECTED] = make_unique(); + _tfliteop_map[tflite::BuiltinOperator_LOGICAL_NOT] = make_unique(); + _tfliteop_map[tflite::BuiltinOperator_LOGICAL_OR] = make_unique(); _tfliteop_map[tflite::BuiltinOperator_MAX_POOL_2D] = make_unique(); + _tfliteop_map[tflite::BuiltinOperator_MEAN] = make_unique(); + _tfliteop_map[tflite::BuiltinOperator_PACK] = make_unique(); + _tfliteop_map[tflite::BuiltinOperator_PAD] = make_unique(); _tfliteop_map[tflite::BuiltinOperator_RELU] = make_unique(); _tfliteop_map[tflite::BuiltinOperator_RELU6] = make_unique(); _tfliteop_map[tflite::BuiltinOperator_RESHAPE] = make_unique(); + _tfliteop_map[tflite::BuiltinOperator_SOFTMAX] = make_unique(); _tfliteop_map[tflite::BuiltinOperator_SQRT] = make_unique(); _tfliteop_map[tflite::BuiltinOperator_SUB] = make_unique(); + _tfliteop_map[tflite::BuiltinOperator_TRANSPOSE] = make_unique(); } private: diff --git a/compiler/tflchef/tools/console/Driver.cpp b/compiler/tflchef/tools/console/Driver.cpp index 0f319c0cdc6..d6f7ba1aef7 100644 --- a/compiler/tflchef/tools/console/Driver.cpp +++ b/compiler/tflchef/tools/console/Driver.cpp @@ -24,6 +24,8 @@ int entry(int argc, char **argv) { + int32_t model_version = 1; + ::tflchef::ModelRecipe model_recipe; // Read a model recipe from standard input @@ -31,9 +33,20 @@ int entry(int argc, char **argv) google::protobuf::io::IstreamInputStream iis{&std::cin}; if (!google::protobuf::TextFormat::Parse(&iis, &model_recipe)) { - std::cerr << "ERROR: Failed to parse recipe '" << argv[1] << "'" << std::endl; + std::cerr << "ERROR: Failed to parse recipe" << std::endl; return 255; } + + if (model_recipe.has_version()) + { + model_version = model_recipe.version(); + } + } + + if (model_version > 1) + { + std::cerr << "ERROR: Unsupported recipe version: " << model_version << std::endl; + return 255; } auto generated_model = tflchef::cook(model_recipe); diff --git a/compiler/tflchef/tools/file/Driver.cpp b/compiler/tflchef/tools/file/Driver.cpp index 1287b0104de..3ef7019106f 100644 --- a/compiler/tflchef/tools/file/Driver.cpp +++ b/compiler/tflchef/tools/file/Driver.cpp @@ -33,6 +33,8 @@ int entry(int argc, char **argv) return 255; } + int32_t model_version = 1; + ::tflchef::ModelRecipe model_recipe; // Load model recipe from a file @@ -44,6 +46,18 @@ int entry(int argc, char **argv) std::cerr << "ERROR: Failed to parse recipe '" << argv[1] << "'" << std::endl; return 255; } + + if (model_recipe.has_version()) + { + model_version = model_recipe.version(); + } + } + + if (model_version > 1) + { + std::cerr << "ERROR: Unsupported recipe version: " << model_version << ", '" << argv[1] << "'" + << std::endl; + return 255; } auto generated_model = tflchef::cook(model_recipe); diff --git a/compiler/tfldump/src/Dump.cpp b/compiler/tfldump/src/Dump.cpp index e3618f227fe..e6b84251a5a 100644 --- a/compiler/tfldump/src/Dump.cpp +++ b/compiler/tfldump/src/Dump.cpp @@ -104,50 +104,14 @@ std::ostream &operator<<(std::ostream &os, const flatbuffers::Vector *fbvect) return os; } -void dump_model(std::ostream &os, const tflite::Model *model) +void dump_sub_graph(std::ostream &os, tflread::Reader &reader) { - tflread::Reader reader(model); - - assert(reader.num_subgraph() == 1); - reader.select_subgraph(0); - - auto opcodes = reader.opcodes(); - auto buffers = reader.buffers(); auto tensors = reader.tensors(); auto operators = reader.operators(); - // dump operator_codes - os << "Operator Codes: [order] OpCodeName (OpCode Enum)" << std::endl; - int32_t opcode_index = 0; - for (auto opcode : opcodes) - { - tflite::BuiltinOperator op_code = opcode->builtin_code(); - auto op_name = tflread::opcode_name(opcode); - - os << "[" << opcode_index << "] " << op_name << " (code: " << op_code << ")" << std::endl; - - opcode_index++; - } - os << std::endl; - - // dump buffer - os << "Buffers: B(index) (length) values, if any" << std::endl; - for (uint32_t i = 0; i < buffers->Length(); ++i) - { - const uint8_t *buff_data; - size_t size = reader.buffer_info(i, &buff_data); - - os << "B(" << i << ") (" << size << ") "; - if (buff_data != nullptr) - { - dump_buffer(os, buff_data, size, 16); - } - os << std::endl; - } - os << std::endl; - // dump operands(tensors) - os << "Operands: T(tensor index) TYPE (shape) B(buffer index) OperandName" << std::endl; + os << "Operands: T(subgraph index : tensor index) TYPE (shape) B(buffer index) OperandName" + << std::endl; for (uint32_t i = 0; i < tensors->Length(); ++i) { // TODO refactor to some better structure @@ -157,7 +121,8 @@ void dump_model(std::ostream &os, const tflite::Model *model) if (tensor->shape()) dims = tflread::as_index_vector(tensor->shape()); - os << "T(" << i << ") " << tflread::tensor_type(tensor) << " "; + os << "T(" << reader.subgraph_index() << ":" << i << ") " << tflread::tensor_type(tensor) + << " "; os << "(" << dims << ") "; os << "B(" << tensor->buffer() << ") "; os << tflread::tensor_name(tensor) << std::endl; @@ -198,7 +163,7 @@ void dump_model(std::ostream &os, const tflite::Model *model) os << std::endl; // dump operators - os << "Operators: O(operator index) OpCodeName " << std::endl; + os << "Operators: O(subgraph index : operator index) OpCodeName " << std::endl; os << " Option(values) ... <-- depending on OpCode" << std::endl; os << " I T(tensor index) OperandName <-- as input" << std::endl; os << " O T(tensor index) OperandName <-- as output" << std::endl; @@ -211,7 +176,7 @@ void dump_model(std::ostream &os, const tflite::Model *model) const std::vector &outputs = tflread::as_index_vector(op->outputs()); auto op_name = reader.opcode_name(op); - os << "O(" << i << ") " << op_name << " "; + os << "O(" << reader.subgraph_index() << ":" << i << ") " << op_name << " "; os << std::endl; if (auto op_prn = OpPrinterRegistry::get().lookup(builtincode)) @@ -258,6 +223,69 @@ void dump_model(std::ostream &os, const tflite::Model *model) std::string name = tflread::tensor_name(tensor); os << "O T(" << output << ") " << name << std::endl; } + + os << std::endl; +} + +void dump_model(std::ostream &os, const tflite::Model *model) +{ + tflread::Reader reader(model); + + uint32_t num_subgraph = reader.num_subgraph(); + + // dump model version + os << "===================================================================" << std::endl; + os << "Model version: " << reader.version() << std::endl; + os << " # sub graphs: " << num_subgraph << std::endl; + os << std::endl; + + auto opcodes = reader.opcodes(); + auto buffers = reader.buffers(); + + // dump operator_codes + os << "Operator Codes: [order] OpCodeName (OpCode Enum)" << std::endl; + int32_t opcode_index = 0; + for (auto opcode : opcodes) + { + tflite::BuiltinOperator op_code = opcode->builtin_code(); + auto op_name = tflread::opcode_name(opcode); + auto op_version = opcode->version(); + + os << "[" << opcode_index << "] " << op_name << " (code: " << op_code + << ", version: " << op_version << ")" << std::endl; + + opcode_index++; + } + os << std::endl; + + // dump buffer + os << "Buffers: B(index) (length) values, if any" << std::endl; + for (uint32_t i = 0; i < buffers->Length(); ++i) + { + const uint8_t *buff_data; + size_t size = reader.buffer_info(i, &buff_data); + + os << "B(" << i << ") (" << size << ") "; + if (buff_data != nullptr) + { + dump_buffer(os, buff_data, size, 16); + } + os << std::endl; + } + os << std::endl; + + for (uint32_t sg = 0; sg < num_subgraph; ++sg) + { + reader.select_subgraph(sg); + + os << "-------------------------------------------------------------------" << std::endl; + os << "Sub-Graph: #" << sg << " " << reader.subgraph_name() << std::endl; + os << std::endl; + + dump_sub_graph(os, reader); + } + + os << "===================================================================" << std::endl; } } // namespace tfldump diff --git a/compiler/tfldump/src/OpPrinter.cpp b/compiler/tfldump/src/OpPrinter.cpp index 1ade802a814..5120f42b1d5 100644 --- a/compiler/tfldump/src/OpPrinter.cpp +++ b/compiler/tfldump/src/OpPrinter.cpp @@ -39,7 +39,8 @@ class AddPrinter : public OpPrinter if (auto *params = op->builtin_options_as_AddOptions()) { os << " "; - os << "Activation(" << params->fused_activation_function() << ") "; + os << "Activation(" << EnumNameActivationFunctionType(params->fused_activation_function()) + << ") "; os << std::endl; } } @@ -70,7 +71,8 @@ class Conv2DPrinter : public OpPrinter os << "Padding(" << conv_params->padding() << ") "; os << "Stride.W(" << conv_params->stride_w() << ") "; os << "Stride.H(" << conv_params->stride_h() << ") "; - os << "Activation(" << conv_params->fused_activation_function() << ")"; + os << "Activation(" + << EnumNameActivationFunctionType(conv_params->fused_activation_function()) << ")"; os << std::endl; } } @@ -84,7 +86,8 @@ class DivPrinter : public OpPrinter if (auto *params = op->builtin_options_as_DivOptions()) { os << " "; - os << "Activation(" << params->fused_activation_function() << ") "; + os << "Activation(" << EnumNameActivationFunctionType(params->fused_activation_function()) + << ") "; os << std::endl; } } @@ -103,7 +106,8 @@ class Pool2DPrinter : public OpPrinter os << "Stride.H(" << pool_params->stride_h() << ") "; os << "Filter.W(" << pool_params->filter_width() << ") "; os << "Filter.H(" << pool_params->filter_height() << ") "; - os << "Activation(" << pool_params->fused_activation_function() << ")"; + os << "Activation(" + << EnumNameActivationFunctionType(pool_params->fused_activation_function()) << ")"; os << std::endl; } } @@ -117,7 +121,9 @@ class ConcatenationPrinter : public OpPrinter if (auto *concatenation_params = op->builtin_options_as_ConcatenationOptions()) { os << " "; - os << "Activation(" << concatenation_params->fused_activation_function() << ") "; + os << "Activation(" + << EnumNameActivationFunctionType(concatenation_params->fused_activation_function()) + << ") "; os << "Axis(" << concatenation_params->axis() << ")"; os << std::endl; } @@ -153,7 +159,8 @@ class DepthwiseConv2DPrinter : public OpPrinter os << "DepthMultiplier(" << conv_params->depth_multiplier() << ") "; os << "Dilation.W(" << conv_params->dilation_w_factor() << ") "; os << "Dilation.H(" << conv_params->dilation_h_factor() << ")"; - os << "Activation(" << conv_params->fused_activation_function() << ") "; + os << "Activation(" + << EnumNameActivationFunctionType(conv_params->fused_activation_function()) << ") "; os << std::endl; } } @@ -167,10 +174,11 @@ class FullyConnectedPrinter : public OpPrinter if (auto *params = op->builtin_options_as_FullyConnectedOptions()) { os << " "; - os << "WeightFormat(" - << "..." - << ") "; // TODO implement this - os << "Activation(" << params->fused_activation_function() << ") "; + os << "WeightFormat(" << EnumNameFullyConnectedOptionsWeightsFormat(params->weights_format()) + << ") "; + os << "Activation(" << EnumNameActivationFunctionType(params->fused_activation_function()) + << ") "; + os << std::endl; } } @@ -184,7 +192,23 @@ class MulPrinter : public OpPrinter if (auto *params = op->builtin_options_as_MulOptions()) { os << " "; - os << "Activation(" << params->fused_activation_function() << ") "; + os << "Activation(" << EnumNameActivationFunctionType(params->fused_activation_function()) + << ") "; + os << std::endl; + } + } +}; + +class PackPrinter : public OpPrinter +{ +public: + void options(const tflite::Operator *op, std::ostream &os) const override + { + if (auto *params = op->builtin_options_as_PackOptions()) + { + os << " "; + os << "ValuesCount(" << params->values_count() << ") "; + os << "Axis(" << params->axis() << ") "; os << std::endl; } } @@ -212,7 +236,8 @@ class SubPrinter : public OpPrinter if (auto *params = op->builtin_options_as_SubOptions()) { os << " "; - os << "Activation(" << params->fused_activation_function() << ") "; + os << "Activation(" << EnumNameActivationFunctionType(params->fused_activation_function()) + << ") "; os << std::endl; } } @@ -270,6 +295,7 @@ OpPrinterRegistry::OpPrinterRegistry() _op_map[tflite::BuiltinOperator_FULLY_CONNECTED] = make_unique(); _op_map[tflite::BuiltinOperator_MAX_POOL_2D] = make_unique(); _op_map[tflite::BuiltinOperator_MUL] = make_unique(); + _op_map[tflite::BuiltinOperator_PACK] = make_unique(); // There is no Option for ReLU and ReLU6 _op_map[tflite::BuiltinOperator_RESHAPE] = make_unique(); _op_map[tflite::BuiltinOperator_SOFTMAX] = make_unique(); diff --git a/compiler/tfldump/src/Read.cpp b/compiler/tfldump/src/Read.cpp index 7dfce270171..f9782d9effb 100644 --- a/compiler/tfldump/src/Read.cpp +++ b/compiler/tfldump/src/Read.cpp @@ -78,6 +78,7 @@ const char *tensor_name(const tflite::Tensor *tensor) Reader::Reader(const tflite::Model *model) { + _version = model->version(); _subgraphs = model->subgraphs(); _buffers = model->buffers(); @@ -137,6 +138,7 @@ std::string Reader::opcode_name(const tflite::Operator *op) const bool Reader::select_subgraph(uint32_t sgindex) { + _subgraph_index = sgindex; _tensors = nullptr; _operators = nullptr; @@ -151,6 +153,9 @@ bool Reader::select_subgraph(uint32_t sgindex) const tflite::SubGraph *subgraph = (*_subgraphs)[sgindex]; + auto name = subgraph->name(); + _subgraph_name = name ? name->c_str() : "(noname)"; + _tensors = subgraph->tensors(); _operators = subgraph->operators(); diff --git a/compiler/tfldump/src/Read.h b/compiler/tfldump/src/Read.h index 3c344e3d03d..7af2fa59b2b 100644 --- a/compiler/tfldump/src/Read.h +++ b/compiler/tfldump/src/Read.h @@ -59,6 +59,8 @@ class Reader Reader() = delete; public: + uint32_t version() const { return _version; } + const std::vector &opcodes() { return _op_codes; } const TFliteBuffers_t *buffers() { return _buffers; } const TFliteTensors_t *tensors() { return _tensors; } @@ -74,13 +76,19 @@ class Reader public: bool select_subgraph(uint32_t subgraph); + const std::string &subgraph_name(void) const { return _subgraph_name; } + uint32_t subgraph_index(void) const { return _subgraph_index; } private: + uint32_t _version; + const TFliteSubGraphs_t *_subgraphs{nullptr}; const TFliteBuffers_t *_buffers{nullptr}; const TFliteTensors_t *_tensors{nullptr}; const TFliteOperators_t *_operators{nullptr}; + uint32_t _subgraph_index; + std::string _subgraph_name; std::vector _op_codes; std::vector _inputs; std::vector _outputs; diff --git a/compiler/tflite2circle/CMakeLists.txt b/compiler/tflite2circle/CMakeLists.txt index 7cf6475ec98..f846a2bc524 100644 --- a/compiler/tflite2circle/CMakeLists.txt +++ b/compiler/tflite2circle/CMakeLists.txt @@ -9,6 +9,7 @@ set(DRIVER "driver/Driver.cpp") file(GLOB_RECURSE SOURCES "src/*.cpp") add_executable(tflite2circle ${DRIVER} ${SOURCES}) target_include_directories(tflite2circle PRIVATE include) +target_include_directories(tflite2circle PRIVATE src) target_link_libraries(tflite2circle safemain) target_link_libraries(tflite2circle stdex) target_link_libraries(tflite2circle mio_tflite) diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions.cpp b/compiler/tflite2circle/src/BuildBuiltinOptions.cpp deleted file mode 100644 index 2af4d574841..00000000000 --- a/compiler/tflite2circle/src/BuildBuiltinOptions.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright (c) 2020 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 - -#include "DataLookup.h" - -namespace tflite2circle -{ - -flatbuffers::Offset -build_circle_Conv2DOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op) -{ - auto tflite_builtin_options = op->builtin_options_as_Conv2DOptions(); - assert(tflite_builtin_options); - circle::Conv2DOptionsBuilder builtin_options_builder{fb}; - builtin_options_builder.add_padding(get_circle_padding(tflite_builtin_options->padding())); - builtin_options_builder.add_stride_w(tflite_builtin_options->stride_w()); - builtin_options_builder.add_stride_h(tflite_builtin_options->stride_h()); - builtin_options_builder.add_fused_activation_function( - get_circle_activation_function_type(tflite_builtin_options->fused_activation_function())); - builtin_options_builder.add_dilation_w_factor(tflite_builtin_options->dilation_w_factor()); - builtin_options_builder.add_dilation_h_factor(tflite_builtin_options->dilation_h_factor()); - return builtin_options_builder.Finish(); -} - -flatbuffers::Offset -build_circle_DepthwiseConv2DOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op) -{ - auto tflite_builtin_options = op->builtin_options_as_DepthwiseConv2DOptions(); - assert(tflite_builtin_options); - circle::DepthwiseConv2DOptionsBuilder builtin_options_builder{fb}; - builtin_options_builder.add_padding(get_circle_padding(tflite_builtin_options->padding())); - builtin_options_builder.add_stride_w(tflite_builtin_options->stride_w()); - builtin_options_builder.add_stride_h(tflite_builtin_options->stride_h()); - builtin_options_builder.add_depth_multiplier(tflite_builtin_options->depth_multiplier()); - builtin_options_builder.add_fused_activation_function( - get_circle_activation_function_type(tflite_builtin_options->fused_activation_function())); - builtin_options_builder.add_dilation_w_factor(tflite_builtin_options->dilation_w_factor()); - builtin_options_builder.add_dilation_h_factor(tflite_builtin_options->dilation_h_factor()); - return builtin_options_builder.Finish(); -} - -flatbuffers::Offset -build_circle_Pool2DOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op) -{ - auto tflite_builtin_options = op->builtin_options_as_Pool2DOptions(); - assert(tflite_builtin_options); - circle::Pool2DOptionsBuilder builtin_options_builder{fb}; - builtin_options_builder.add_padding(get_circle_padding(tflite_builtin_options->padding())); - builtin_options_builder.add_stride_w(tflite_builtin_options->stride_w()); - builtin_options_builder.add_stride_h(tflite_builtin_options->stride_h()); - builtin_options_builder.add_filter_width(tflite_builtin_options->filter_width()); - builtin_options_builder.add_filter_height(tflite_builtin_options->filter_height()); - builtin_options_builder.add_fused_activation_function( - get_circle_activation_function_type(tflite_builtin_options->fused_activation_function())); - return builtin_options_builder.Finish(); -} - -flatbuffers::Offset -build_circle_ConcatenationOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op) -{ - auto tflite_builtin_options = op->builtin_options_as_ConcatenationOptions(); - assert(tflite_builtin_options); - circle::ConcatenationOptionsBuilder builtin_options_builder{fb}; - builtin_options_builder.add_axis(tflite_builtin_options->axis()); - builtin_options_builder.add_fused_activation_function( - get_circle_activation_function_type(tflite_builtin_options->fused_activation_function())); - return builtin_options_builder.Finish(); -} - -flatbuffers::Offset build_circle_AddOptions(flatbuffers::FlatBufferBuilder &fb, - const tflite::Operator *op) -{ - auto tflite_builtin_options = op->builtin_options_as_AddOptions(); - assert(tflite_builtin_options); - circle::AddOptionsBuilder builtin_options_builder{fb}; - builtin_options_builder.add_fused_activation_function( - get_circle_activation_function_type(tflite_builtin_options->fused_activation_function())); - return builtin_options_builder.Finish(); -} - -flatbuffers::Offset -build_circle_ReshapeOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op) -{ - auto tflite_builtin_options = op->builtin_options_as_ReshapeOptions(); - assert(tflite_builtin_options); - std::vector new_shape_vec{tflite_builtin_options->new_shape()->begin(), - tflite_builtin_options->new_shape()->end()}; - auto new_shape = fb.CreateVector(new_shape_vec); - circle::ReshapeOptionsBuilder builtin_options_builder{fb}; - builtin_options_builder.add_new_shape(new_shape); - return builtin_options_builder.Finish(); -} - -flatbuffers::Offset build_circle_PadOptions(flatbuffers::FlatBufferBuilder &fb, - const tflite::Operator *op) -{ - circle::PadOptionsBuilder builtin_options_builder{fb}; - return builtin_options_builder.Finish(); -} - -flatbuffers::Offset build_circle_SubOptions(flatbuffers::FlatBufferBuilder &fb, - const tflite::Operator *op) -{ - auto tflite_builtin_options = op->builtin_options_as_SubOptions(); - assert(tflite_builtin_options); - circle::SubOptionsBuilder builtin_options_builder{fb}; - builtin_options_builder.add_fused_activation_function( - get_circle_activation_function_type(tflite_builtin_options->fused_activation_function())); - return builtin_options_builder.Finish(); -} - -flatbuffers::Offset build_circle_DivOptions(flatbuffers::FlatBufferBuilder &fb, - const tflite::Operator *op) -{ - auto tflite_builtin_options = op->builtin_options_as_DivOptions(); - assert(tflite_builtin_options); - circle::DivOptionsBuilder builtin_options_builder{fb}; - builtin_options_builder.add_fused_activation_function( - get_circle_activation_function_type(tflite_builtin_options->fused_activation_function())); - return builtin_options_builder.Finish(); -} - -flatbuffers::Offset -build_circle_SoftmaxOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op) -{ - auto tflite_builtin_options = op->builtin_options_as_SoftmaxOptions(); - assert(tflite_builtin_options); - circle::SoftmaxOptionsBuilder builtin_options_builder{fb}; - builtin_options_builder.add_beta(tflite_builtin_options->beta()); - return builtin_options_builder.Finish(); -} - -flatbuffers::Offset -build_circle_FullyConnectedOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op) -{ - auto tflite_builtin_options = op->builtin_options_as_FullyConnectedOptions(); - assert(tflite_builtin_options); - circle::FullyConnectedOptionsBuilder builtin_options_builder{fb}; - builtin_options_builder.add_fused_activation_function( - get_circle_activation_function_type(tflite_builtin_options->fused_activation_function())); - // Get FullyConnectedOptionsWeightsFormat - auto tflite_weight_format = tflite_builtin_options->weights_format(); - if (tflite_weight_format == tflite::FullyConnectedOptionsWeightsFormat_DEFAULT) - builtin_options_builder.add_weights_format(circle::FullyConnectedOptionsWeightsFormat_DEFAULT); - else if (tflite_weight_format == tflite::FullyConnectedOptionsWeightsFormat_SHUFFLED4x16INT8) - builtin_options_builder.add_weights_format( - circle::FullyConnectedOptionsWeightsFormat_SHUFFLED4x16INT8); - return builtin_options_builder.Finish(); -} - -flatbuffers::Offset -build_circle_ArgMaxOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op) -{ - auto tflite_builtin_options = op->builtin_options_as_ArgMaxOptions(); - assert(tflite_builtin_options); - circle::ArgMaxOptionsBuilder builtin_options_builder{fb}; - builtin_options_builder.add_output_type( - get_circle_tensortype(tflite_builtin_options->output_type())); - return builtin_options_builder.Finish(); -} - -} // namespace tflite2circle diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions.h b/compiler/tflite2circle/src/BuildBuiltinOptions.h index de4ed0f8389..4cdb4dca6e0 100644 --- a/compiler/tflite2circle/src/BuildBuiltinOptions.h +++ b/compiler/tflite2circle/src/BuildBuiltinOptions.h @@ -17,47 +17,36 @@ #ifndef __BUILD_BUITIN_OPTIONS_H__ #define __BUILD_BUITIN_OPTIONS_H__ -#include "DataLookup.h" - -namespace tflite2circle -{ - -flatbuffers::Offset -build_circle_Conv2DOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op); - -flatbuffers::Offset -build_circle_DepthwiseConv2DOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op); - -flatbuffers::Offset -build_circle_Pool2DOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op); - -flatbuffers::Offset -build_circle_ConcatenationOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op); - -flatbuffers::Offset build_circle_AddOptions(flatbuffers::FlatBufferBuilder &fb, - const tflite::Operator *op); - -flatbuffers::Offset -build_circle_ReshapeOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op); - -flatbuffers::Offset build_circle_PadOptions(flatbuffers::FlatBufferBuilder &fb, - const tflite::Operator *op); - -flatbuffers::Offset build_circle_SubOptions(flatbuffers::FlatBufferBuilder &fb, - const tflite::Operator *op); - -flatbuffers::Offset build_circle_DivOptions(flatbuffers::FlatBufferBuilder &fb, - const tflite::Operator *op); - -flatbuffers::Offset -build_circle_SoftmaxOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op); - -flatbuffers::Offset -build_circle_FullyConnectedOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op); - -flatbuffers::Offset -build_circle_ArgMaxOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op); - -} // namespace tflite2circle +// NOTE please add new option headers in alphabetical order + +#include "BuildBuiltinOptions/AbsOptions.h" +#include "BuildBuiltinOptions/AddOptions.h" +#include "BuildBuiltinOptions/ArgMaxOptions.h" +#include "BuildBuiltinOptions/CastOptions.h" +#include "BuildBuiltinOptions/ConcatenationOptions.h" +#include "BuildBuiltinOptions/Conv2DOptions.h" +#include "BuildBuiltinOptions/CosOptions.h" +#include "BuildBuiltinOptions/DepthwiseConv2DOptions.h" +#include "BuildBuiltinOptions/DivOptions.h" +#include "BuildBuiltinOptions/EqualOptions.h" +#include "BuildBuiltinOptions/ExpandDimsOptions.h" +#include "BuildBuiltinOptions/FillOptions.h" +#include "BuildBuiltinOptions/FullyConnectedOptions.h" +#include "BuildBuiltinOptions/GreaterEqualOptions.h" +#include "BuildBuiltinOptions/LogicalNotOptions.h" +#include "BuildBuiltinOptions/LogicalOrOptions.h" +#include "BuildBuiltinOptions/MulOptions.h" +#include "BuildBuiltinOptions/NotEqualOptions.h" +#include "BuildBuiltinOptions/PackOptions.h" +#include "BuildBuiltinOptions/PadOptions.h" +#include "BuildBuiltinOptions/Pool2DOptions.h" +#include "BuildBuiltinOptions/ReducerOptions.h" +#include "BuildBuiltinOptions/ReshapeOptions.h" +#include "BuildBuiltinOptions/ShapeOptions.h" +#include "BuildBuiltinOptions/SoftmaxOptions.h" +#include "BuildBuiltinOptions/SplitOptions.h" +#include "BuildBuiltinOptions/SqueezeOptions.h" +#include "BuildBuiltinOptions/SubOptions.h" +#include "BuildBuiltinOptions/TransposeOptions.h" #endif // __BUILD_BUITIN_OPTIONS_H__ diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/AbsOptions.cpp b/compiler/tflite2circle/src/BuildBuiltinOptions/AbsOptions.cpp new file mode 100644 index 00000000000..70aa06d3ebd --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/AbsOptions.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2020 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 "AbsOptions.h" +#include "DataLookup.h" + +#include + +namespace tflite2circle +{ + +flatbuffers::Offset build_circle_AbsOptions(flatbuffers::FlatBufferBuilder &fb, + const tflite::Operator *) +{ + circle::AbsOptionsBuilder builtin_options_builder{fb}; + return builtin_options_builder.Finish(); +} + +} // namespace tflite2circle diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/AbsOptions.h b/compiler/tflite2circle/src/BuildBuiltinOptions/AbsOptions.h new file mode 100644 index 00000000000..a118eb52b26 --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/AbsOptions.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 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 __BBO_ABS_OPTIONS_H__ +#define __BBO_ABS_OPTIONS_H__ + +#include +#include + +namespace tflite2circle +{ + +flatbuffers::Offset build_circle_AbsOptions(flatbuffers::FlatBufferBuilder &fb, + const tflite::Operator *op); + +} // namespace tflite2circle + +#endif // __BBO_ABS_OPTIONS_H__ diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/AddOptions.cpp b/compiler/tflite2circle/src/BuildBuiltinOptions/AddOptions.cpp new file mode 100644 index 00000000000..f93a0f21fcb --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/AddOptions.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2020 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 "AddOptions.h" +#include "DataLookup.h" + +#include + +namespace tflite2circle +{ + +flatbuffers::Offset build_circle_AddOptions(flatbuffers::FlatBufferBuilder &fb, + const tflite::Operator *op) +{ + auto tflite_builtin_options = op->builtin_options_as_AddOptions(); + assert(tflite_builtin_options); + circle::AddOptionsBuilder builtin_options_builder{fb}; + builtin_options_builder.add_fused_activation_function( + get_circle_activation_function_type(tflite_builtin_options->fused_activation_function())); + return builtin_options_builder.Finish(); +} + +} // namespace tflite2circle diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/AddOptions.h b/compiler/tflite2circle/src/BuildBuiltinOptions/AddOptions.h new file mode 100644 index 00000000000..bbfa03f0d57 --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/AddOptions.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 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 __BBO_ADD_OPTIONS_H__ +#define __BBO_ADD_OPTIONS_H__ + +#include +#include + +namespace tflite2circle +{ + +flatbuffers::Offset build_circle_AddOptions(flatbuffers::FlatBufferBuilder &fb, + const tflite::Operator *op); + +} // namespace tflite2circle + +#endif // __BBO_ADD_OPTIONS_H__ diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/ArgMaxOptions.cpp b/compiler/tflite2circle/src/BuildBuiltinOptions/ArgMaxOptions.cpp new file mode 100644 index 00000000000..0ccdde4cb20 --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/ArgMaxOptions.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2020 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 "ArgMaxOptions.h" +#include "DataLookup.h" + +#include + +namespace tflite2circle +{ + +flatbuffers::Offset +build_circle_ArgMaxOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op) +{ + auto tflite_builtin_options = op->builtin_options_as_ArgMaxOptions(); + assert(tflite_builtin_options); + circle::ArgMaxOptionsBuilder builtin_options_builder{fb}; + builtin_options_builder.add_output_type( + get_circle_tensortype(tflite_builtin_options->output_type())); + return builtin_options_builder.Finish(); +} + +} // namespace tflite2circle diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/ArgMaxOptions.h b/compiler/tflite2circle/src/BuildBuiltinOptions/ArgMaxOptions.h new file mode 100644 index 00000000000..2c84762528f --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/ArgMaxOptions.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 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 __BBO_ARGMAX_OPTIONS_H__ +#define __BBO_ARGMAX_OPTIONS_H__ + +#include +#include + +namespace tflite2circle +{ + +flatbuffers::Offset +build_circle_ArgMaxOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op); + +} // namespace tflite2circle + +#endif // __BBO_ARGMAX_OPTIONS_H__ diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/CastOptions.cpp b/compiler/tflite2circle/src/BuildBuiltinOptions/CastOptions.cpp new file mode 100644 index 00000000000..f07fb3b1f53 --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/CastOptions.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2020 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 "CastOptions.h" +#include "DataLookup.h" + +#include + +namespace tflite2circle +{ + +flatbuffers::Offset +build_circle_CastOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op) +{ + auto tflite_builtin_options = op->builtin_options_as_CastOptions(); + assert(tflite_builtin_options); + circle::CastOptionsBuilder builtin_options_builder{fb}; + builtin_options_builder.add_in_data_type( + get_circle_tensortype(tflite_builtin_options->in_data_type())); + builtin_options_builder.add_out_data_type( + get_circle_tensortype(tflite_builtin_options->out_data_type())); + return builtin_options_builder.Finish(); +} + +} // namespace tflite2circle diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/CastOptions.h b/compiler/tflite2circle/src/BuildBuiltinOptions/CastOptions.h new file mode 100644 index 00000000000..a8cc5441b33 --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/CastOptions.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 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 __BBO_CAST_OPTIONS_H__ +#define __BBO_CAST_OPTIONS_H__ + +#include +#include + +namespace tflite2circle +{ + +flatbuffers::Offset +build_circle_CastOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op); + +} // namespace tflite2circle + +#endif // __BBO_CAST_OPTIONS_H__ diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/ConcatenationOptions.cpp b/compiler/tflite2circle/src/BuildBuiltinOptions/ConcatenationOptions.cpp new file mode 100644 index 00000000000..933e7cf66c3 --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/ConcatenationOptions.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2020 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 "ConcatenationOptions.h" +#include "DataLookup.h" + +#include + +namespace tflite2circle +{ + +flatbuffers::Offset +build_circle_ConcatenationOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op) +{ + auto tflite_builtin_options = op->builtin_options_as_ConcatenationOptions(); + assert(tflite_builtin_options); + circle::ConcatenationOptionsBuilder builtin_options_builder{fb}; + builtin_options_builder.add_axis(tflite_builtin_options->axis()); + builtin_options_builder.add_fused_activation_function( + get_circle_activation_function_type(tflite_builtin_options->fused_activation_function())); + return builtin_options_builder.Finish(); +} + +} // namespace tflite2circle diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/ConcatenationOptions.h b/compiler/tflite2circle/src/BuildBuiltinOptions/ConcatenationOptions.h new file mode 100644 index 00000000000..004e6433cf2 --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/ConcatenationOptions.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 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 __BBO_CONCATENATION_OPTIONS_H__ +#define __BBO_CONCATENATION_OPTIONS_H__ + +#include +#include + +namespace tflite2circle +{ + +flatbuffers::Offset +build_circle_ConcatenationOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op); + +} // namespace tflite2circle + +#endif // __BBO_CONCATENATION_OPTIONS_H__ diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/Conv2DOptions.cpp b/compiler/tflite2circle/src/BuildBuiltinOptions/Conv2DOptions.cpp new file mode 100644 index 00000000000..ace63dd26a5 --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/Conv2DOptions.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2020 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 "Conv2DOptions.h" +#include "DataLookup.h" + +#include + +namespace tflite2circle +{ + +flatbuffers::Offset +build_circle_Conv2DOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op) +{ + auto tflite_builtin_options = op->builtin_options_as_Conv2DOptions(); + assert(tflite_builtin_options); + circle::Conv2DOptionsBuilder builtin_options_builder{fb}; + builtin_options_builder.add_padding(get_circle_padding(tflite_builtin_options->padding())); + builtin_options_builder.add_stride_w(tflite_builtin_options->stride_w()); + builtin_options_builder.add_stride_h(tflite_builtin_options->stride_h()); + builtin_options_builder.add_fused_activation_function( + get_circle_activation_function_type(tflite_builtin_options->fused_activation_function())); + builtin_options_builder.add_dilation_w_factor(tflite_builtin_options->dilation_w_factor()); + builtin_options_builder.add_dilation_h_factor(tflite_builtin_options->dilation_h_factor()); + return builtin_options_builder.Finish(); +} + +} // namespace tflite2circle diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/Conv2DOptions.h b/compiler/tflite2circle/src/BuildBuiltinOptions/Conv2DOptions.h new file mode 100644 index 00000000000..1f2bdc16916 --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/Conv2DOptions.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 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 __BBO_CONV2D_OPTIONS_H__ +#define __BBO_CONV2D_OPTIONS_H__ + +#include +#include + +namespace tflite2circle +{ + +flatbuffers::Offset +build_circle_Conv2DOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op); + +} // namespace tflite2circle + +#endif // __BBO_CONV2D_OPTIONS_H__ diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/CosOptions.cpp b/compiler/tflite2circle/src/BuildBuiltinOptions/CosOptions.cpp new file mode 100644 index 00000000000..9f6ebf16b8f --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/CosOptions.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2020 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 "CosOptions.h" +#include "DataLookup.h" + +#include + +namespace tflite2circle +{ + +flatbuffers::Offset build_circle_CosOptions(flatbuffers::FlatBufferBuilder &fb, + const tflite::Operator *op) +{ + circle::CosOptionsBuilder builtin_options_builder{fb}; + return builtin_options_builder.Finish(); +} + +} // namespace tflite2circle diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/CosOptions.h b/compiler/tflite2circle/src/BuildBuiltinOptions/CosOptions.h new file mode 100644 index 00000000000..bc15573b92b --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/CosOptions.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 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 __BBO_COS_OPTIONS_H__ +#define __BBO_COS_OPTIONS_H__ + +#include +#include + +namespace tflite2circle +{ + +flatbuffers::Offset build_circle_CosOptions(flatbuffers::FlatBufferBuilder &fb, + const tflite::Operator *op); + +} // namespace tflite2circle + +#endif // __BBO_COS_OPTIONS_H__ diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/DepthwiseConv2DOptions.cpp b/compiler/tflite2circle/src/BuildBuiltinOptions/DepthwiseConv2DOptions.cpp new file mode 100644 index 00000000000..2aa35abc691 --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/DepthwiseConv2DOptions.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2020 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 "DepthwiseConv2DOptions.h" +#include "DataLookup.h" + +#include + +namespace tflite2circle +{ + +flatbuffers::Offset +build_circle_DepthwiseConv2DOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op) +{ + auto tflite_builtin_options = op->builtin_options_as_DepthwiseConv2DOptions(); + assert(tflite_builtin_options); + circle::DepthwiseConv2DOptionsBuilder builtin_options_builder{fb}; + builtin_options_builder.add_padding(get_circle_padding(tflite_builtin_options->padding())); + builtin_options_builder.add_stride_w(tflite_builtin_options->stride_w()); + builtin_options_builder.add_stride_h(tflite_builtin_options->stride_h()); + builtin_options_builder.add_depth_multiplier(tflite_builtin_options->depth_multiplier()); + builtin_options_builder.add_fused_activation_function( + get_circle_activation_function_type(tflite_builtin_options->fused_activation_function())); + builtin_options_builder.add_dilation_w_factor(tflite_builtin_options->dilation_w_factor()); + builtin_options_builder.add_dilation_h_factor(tflite_builtin_options->dilation_h_factor()); + return builtin_options_builder.Finish(); +} + +} // namespace tflite2circle diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/DepthwiseConv2DOptions.h b/compiler/tflite2circle/src/BuildBuiltinOptions/DepthwiseConv2DOptions.h new file mode 100644 index 00000000000..2d92993dfcb --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/DepthwiseConv2DOptions.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 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 __BBO_DEPTHWISECONV2D_OPTIONS_H__ +#define __BBO_DEPTHWISECONV2D_OPTIONS_H__ + +#include +#include + +namespace tflite2circle +{ + +flatbuffers::Offset +build_circle_DepthwiseConv2DOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op); + +} // namespace tflite2circle + +#endif // __BBO_DEPTHWISECONV2D_OPTIONS_H__ diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/DivOptions.cpp b/compiler/tflite2circle/src/BuildBuiltinOptions/DivOptions.cpp new file mode 100644 index 00000000000..4272fe1443b --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/DivOptions.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2020 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 "DivOptions.h" +#include "DataLookup.h" + +#include + +namespace tflite2circle +{ + +flatbuffers::Offset build_circle_DivOptions(flatbuffers::FlatBufferBuilder &fb, + const tflite::Operator *op) +{ + auto tflite_builtin_options = op->builtin_options_as_DivOptions(); + assert(tflite_builtin_options); + circle::DivOptionsBuilder builtin_options_builder{fb}; + builtin_options_builder.add_fused_activation_function( + get_circle_activation_function_type(tflite_builtin_options->fused_activation_function())); + return builtin_options_builder.Finish(); +} + +} // namespace tflite2circle diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/DivOptions.h b/compiler/tflite2circle/src/BuildBuiltinOptions/DivOptions.h new file mode 100644 index 00000000000..2b2bc57dcba --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/DivOptions.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 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 __BBO_DIV_OPTIONS_H__ +#define __BBO_DIV_OPTIONS_H__ + +#include +#include + +namespace tflite2circle +{ + +flatbuffers::Offset build_circle_DivOptions(flatbuffers::FlatBufferBuilder &fb, + const tflite::Operator *op); + +} // namespace tflite2circle + +#endif // __BBO_DIV_OPTIONS_H__ diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/EqualOptions.cpp b/compiler/tflite2circle/src/BuildBuiltinOptions/EqualOptions.cpp new file mode 100644 index 00000000000..cc2efa4fa08 --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/EqualOptions.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2020 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 "EqualOptions.h" + +namespace tflite2circle +{ + +flatbuffers::Offset +build_circle_EqualOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op) +{ + circle::EqualOptionsBuilder builtin_options_builder{fb}; + return builtin_options_builder.Finish(); +} + +} // namespace tflite2circle diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/EqualOptions.h b/compiler/tflite2circle/src/BuildBuiltinOptions/EqualOptions.h new file mode 100644 index 00000000000..8572157f2d4 --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/EqualOptions.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 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 __BBO_EQUAL_OPTIONS_H__ +#define __BBO_EQUAL_OPTIONS_H__ + +#include +#include + +namespace tflite2circle +{ + +flatbuffers::Offset +build_circle_EqualOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op); + +} // namespace tflite2circle + +#endif // __BBO_EQUAL_OPTIONS_H__ diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/ExpandDimsOptions.cpp b/compiler/tflite2circle/src/BuildBuiltinOptions/ExpandDimsOptions.cpp new file mode 100644 index 00000000000..ee2af2c096f --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/ExpandDimsOptions.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2020 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 "ExpandDimsOptions.h" + +namespace tflite2circle +{ + +flatbuffers::Offset +build_circle_ExpandDimsOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op) +{ + circle::ExpandDimsOptionsBuilder builtin_options_builder{fb}; + return builtin_options_builder.Finish(); +} + +} // namespace tflite2circle diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/ExpandDimsOptions.h b/compiler/tflite2circle/src/BuildBuiltinOptions/ExpandDimsOptions.h new file mode 100644 index 00000000000..814e5037456 --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/ExpandDimsOptions.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 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 __BBO_EXPANDDIMS_OPTIONS_H__ +#define __BBO_EXPANDDIMS_OPTIONS_H__ + +#include +#include + +namespace tflite2circle +{ + +flatbuffers::Offset +build_circle_ExpandDimsOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op); + +} // namespace tflite2circle + +#endif // __BBO_EXPANDDIMS_OPTIONS_H__ diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/FillOptions.cpp b/compiler/tflite2circle/src/BuildBuiltinOptions/FillOptions.cpp new file mode 100644 index 00000000000..919c57cdccc --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/FillOptions.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2020 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 "FillOptions.h" + +namespace tflite2circle +{ + +flatbuffers::Offset +build_circle_FillOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op) +{ + circle::FillOptionsBuilder builtin_options_builder{fb}; + return builtin_options_builder.Finish(); +} + +} // namespace tflite2circle diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/FillOptions.h b/compiler/tflite2circle/src/BuildBuiltinOptions/FillOptions.h new file mode 100644 index 00000000000..81eb5e3a21d --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/FillOptions.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 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 __BBO_FILL_OPTIONS_H__ +#define __BBO_FILL_OPTIONS_H__ + +#include +#include + +namespace tflite2circle +{ + +flatbuffers::Offset +build_circle_FillOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op); + +} // namespace tflite2circle + +#endif // __BBO_FILL_OPTIONS_H__ diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/FullyConnectedOptions.cpp b/compiler/tflite2circle/src/BuildBuiltinOptions/FullyConnectedOptions.cpp new file mode 100644 index 00000000000..098a96a40cb --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/FullyConnectedOptions.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2020 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 "FullyConnectedOptions.h" +#include "DataLookup.h" + +#include + +namespace tflite2circle +{ + +flatbuffers::Offset +build_circle_FullyConnectedOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op) +{ + auto tflite_builtin_options = op->builtin_options_as_FullyConnectedOptions(); + assert(tflite_builtin_options); + circle::FullyConnectedOptionsBuilder builtin_options_builder{fb}; + builtin_options_builder.add_fused_activation_function( + get_circle_activation_function_type(tflite_builtin_options->fused_activation_function())); + // Get FullyConnectedOptionsWeightsFormat + auto tflite_weight_format = tflite_builtin_options->weights_format(); + if (tflite_weight_format == tflite::FullyConnectedOptionsWeightsFormat_DEFAULT) + builtin_options_builder.add_weights_format(circle::FullyConnectedOptionsWeightsFormat_DEFAULT); + else if (tflite_weight_format == tflite::FullyConnectedOptionsWeightsFormat_SHUFFLED4x16INT8) + builtin_options_builder.add_weights_format( + circle::FullyConnectedOptionsWeightsFormat_SHUFFLED4x16INT8); + return builtin_options_builder.Finish(); +} + +} // namespace tflite2circle diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/FullyConnectedOptions.h b/compiler/tflite2circle/src/BuildBuiltinOptions/FullyConnectedOptions.h new file mode 100644 index 00000000000..8f4ac43cf77 --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/FullyConnectedOptions.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 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 __BBO_FULLYCONNECTED_OPTIONS_H__ +#define __BBO_FULLYCONNECTED_OPTIONS_H__ + +#include +#include + +namespace tflite2circle +{ + +flatbuffers::Offset +build_circle_FullyConnectedOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op); + +} // namespace tflite2circle + +#endif // __BBO_FULLYCONNECTED_OPTIONS_H__ diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/GreaterEqualOptions.cpp b/compiler/tflite2circle/src/BuildBuiltinOptions/GreaterEqualOptions.cpp new file mode 100644 index 00000000000..6c890e5798e --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/GreaterEqualOptions.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2020 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 "GreaterEqualOptions.h" + +namespace tflite2circle +{ + +flatbuffers::Offset +build_circle_GreaterEqualOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op) +{ + circle::GreaterEqualOptionsBuilder builtin_options_builder{fb}; + return builtin_options_builder.Finish(); +} + +} // namespace tflite2circle diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/GreaterEqualOptions.h b/compiler/tflite2circle/src/BuildBuiltinOptions/GreaterEqualOptions.h new file mode 100644 index 00000000000..bddb553710c --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/GreaterEqualOptions.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 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 __BBO_GREATEREQUAL_OPTIONS_H__ +#define __BBO_GREATEREQUAL_OPTIONS_H__ + +#include +#include + +namespace tflite2circle +{ + +flatbuffers::Offset +build_circle_GreaterEqualOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op); + +} // namespace tflite2circle + +#endif // __BBO_GREATEREQUAL_OPTIONS_H__ diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/LogicalNotOptions.cpp b/compiler/tflite2circle/src/BuildBuiltinOptions/LogicalNotOptions.cpp new file mode 100644 index 00000000000..fc17fd5b18c --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/LogicalNotOptions.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2020 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 "LogicalNotOptions.h" +#include "DataLookup.h" + +#include + +namespace tflite2circle +{ + +flatbuffers::Offset +build_circle_LogicalNotOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op) +{ + circle::LogicalNotOptionsBuilder builtin_options_builder{fb}; + return builtin_options_builder.Finish(); +} + +} // namespace tflite2circle diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/LogicalNotOptions.h b/compiler/tflite2circle/src/BuildBuiltinOptions/LogicalNotOptions.h new file mode 100644 index 00000000000..da830b78190 --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/LogicalNotOptions.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 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 __BBO_LOGICALNOT_OPTIONS_H__ +#define __BBO_LOGICALNOT_OPTIONS_H__ + +#include +#include + +namespace tflite2circle +{ + +flatbuffers::Offset +build_circle_LogicalNotOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op); + +} // namespace tflite2circle + +#endif // __BBO_LOGICALNOT_OPTIONS_H__ diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/LogicalOrOptions.cpp b/compiler/tflite2circle/src/BuildBuiltinOptions/LogicalOrOptions.cpp new file mode 100644 index 00000000000..6c3a6b3a667 --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/LogicalOrOptions.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2020 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 "LogicalOrOptions.h" +#include "DataLookup.h" + +#include + +namespace tflite2circle +{ + +flatbuffers::Offset +build_circle_LogicalOrOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op) +{ + circle::LogicalOrOptionsBuilder builtin_options_builder{fb}; + return builtin_options_builder.Finish(); +} + +} // namespace tflite2circle diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/LogicalOrOptions.h b/compiler/tflite2circle/src/BuildBuiltinOptions/LogicalOrOptions.h new file mode 100644 index 00000000000..59ba914c2a9 --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/LogicalOrOptions.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 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 __BBO_LOGICALOR_OPTIONS_H__ +#define __BBO_LOGICALOR_OPTIONS_H__ + +#include +#include + +namespace tflite2circle +{ + +flatbuffers::Offset +build_circle_LogicalOrOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op); + +} // namespace tflite2circle + +#endif // __BBO_LOGICALOR_OPTIONS_H__ diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/MulOptions.cpp b/compiler/tflite2circle/src/BuildBuiltinOptions/MulOptions.cpp new file mode 100644 index 00000000000..009daea8bda --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/MulOptions.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2020 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 "AddOptions.h" +#include "DataLookup.h" + +#include + +namespace tflite2circle +{ + +flatbuffers::Offset build_circle_MulOptions(flatbuffers::FlatBufferBuilder &fb, + const tflite::Operator *op) +{ + auto tflite_builtin_options = op->builtin_options_as_MulOptions(); + assert(tflite_builtin_options); + circle::MulOptionsBuilder builtin_options_builder{fb}; + builtin_options_builder.add_fused_activation_function( + get_circle_activation_function_type(tflite_builtin_options->fused_activation_function())); + return builtin_options_builder.Finish(); +} + +} // namespace tflite2circle diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/MulOptions.h b/compiler/tflite2circle/src/BuildBuiltinOptions/MulOptions.h new file mode 100644 index 00000000000..18f1e496746 --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/MulOptions.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 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 __BBO_MUL_OPTIONS_H__ +#define __BBO_MUL_OPTIONS_H__ + +#include +#include + +namespace tflite2circle +{ + +flatbuffers::Offset build_circle_MulOptions(flatbuffers::FlatBufferBuilder &fb, + const tflite::Operator *op); + +} // namespace tflite2circle + +#endif // __BBO_MUL_OPTIONS_H__ diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/NotEqualOptions.cpp b/compiler/tflite2circle/src/BuildBuiltinOptions/NotEqualOptions.cpp new file mode 100644 index 00000000000..8ed3bb0bb73 --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/NotEqualOptions.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2020 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 "NotEqualOptions.h" + +namespace tflite2circle +{ + +flatbuffers::Offset +build_circle_NotEqualOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op) +{ + circle::NotEqualOptionsBuilder builtin_options_builder{fb}; + return builtin_options_builder.Finish(); +} + +} // namespace tflite2circle diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/NotEqualOptions.h b/compiler/tflite2circle/src/BuildBuiltinOptions/NotEqualOptions.h new file mode 100644 index 00000000000..f7533ec06e7 --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/NotEqualOptions.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 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 __BBO_NOTEQUAL_OPTIONS_H__ +#define __BBO_NOTEQUAL_OPTIONS_H__ + +#include +#include + +namespace tflite2circle +{ + +flatbuffers::Offset +build_circle_NotEqualOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op); + +} // namespace tflite2circle + +#endif // __BBO_NOTEQUAL_OPTIONS_H__ diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/PackOptions.cpp b/compiler/tflite2circle/src/BuildBuiltinOptions/PackOptions.cpp new file mode 100644 index 00000000000..7950f62e98d --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/PackOptions.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2020 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 "PackOptions.h" + +#include + +namespace tflite2circle +{ + +flatbuffers::Offset +build_circle_PackOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op) +{ + auto tflite_builtin_options = op->builtin_options_as_PackOptions(); + assert(tflite_builtin_options); + circle::PackOptionsBuilder builtin_options_builder{fb}; + builtin_options_builder.add_values_count(tflite_builtin_options->values_count()); + builtin_options_builder.add_axis(tflite_builtin_options->axis()); + return builtin_options_builder.Finish(); +} + +} // namespace tflite2circle diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/PackOptions.h b/compiler/tflite2circle/src/BuildBuiltinOptions/PackOptions.h new file mode 100644 index 00000000000..7bf7643eff1 --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/PackOptions.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 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 __BBO_PACK_OPTIONS_H__ +#define __BBO_PACK_OPTIONS_H__ + +#include +#include + +namespace tflite2circle +{ + +flatbuffers::Offset +build_circle_PackOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op); + +} // namespace tflite2circle + +#endif // __BBO_PACK_OPTIONS_H__ diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/PadOptions.cpp b/compiler/tflite2circle/src/BuildBuiltinOptions/PadOptions.cpp new file mode 100644 index 00000000000..1214390c133 --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/PadOptions.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 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 "PadOptions.h" + +#include + +namespace tflite2circle +{ + +flatbuffers::Offset build_circle_PadOptions(flatbuffers::FlatBufferBuilder &fb, + const tflite::Operator *op) +{ + circle::PadOptionsBuilder builtin_options_builder{fb}; + return builtin_options_builder.Finish(); +} + +} // namespace tflite2circle diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/PadOptions.h b/compiler/tflite2circle/src/BuildBuiltinOptions/PadOptions.h new file mode 100644 index 00000000000..a22b0a1267f --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/PadOptions.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 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 __BBO_PAD_OPTIONS_H__ +#define __BBO_PAD_OPTIONS_H__ + +#include +#include + +namespace tflite2circle +{ + +flatbuffers::Offset build_circle_PadOptions(flatbuffers::FlatBufferBuilder &fb, + const tflite::Operator *op); + +} // namespace tflite2circle + +#endif // __BBO_PAD_OPTIONS_H__ diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/Pool2DOptions.cpp b/compiler/tflite2circle/src/BuildBuiltinOptions/Pool2DOptions.cpp new file mode 100644 index 00000000000..6b0bd128869 --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/Pool2DOptions.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2020 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 "Pool2DOptions.h" +#include "DataLookup.h" + +#include + +namespace tflite2circle +{ + +flatbuffers::Offset +build_circle_Pool2DOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op) +{ + auto tflite_builtin_options = op->builtin_options_as_Pool2DOptions(); + assert(tflite_builtin_options); + circle::Pool2DOptionsBuilder builtin_options_builder{fb}; + builtin_options_builder.add_padding(get_circle_padding(tflite_builtin_options->padding())); + builtin_options_builder.add_stride_w(tflite_builtin_options->stride_w()); + builtin_options_builder.add_stride_h(tflite_builtin_options->stride_h()); + builtin_options_builder.add_filter_width(tflite_builtin_options->filter_width()); + builtin_options_builder.add_filter_height(tflite_builtin_options->filter_height()); + builtin_options_builder.add_fused_activation_function( + get_circle_activation_function_type(tflite_builtin_options->fused_activation_function())); + return builtin_options_builder.Finish(); +} + +} // namespace tflite2circle diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/Pool2DOptions.h b/compiler/tflite2circle/src/BuildBuiltinOptions/Pool2DOptions.h new file mode 100644 index 00000000000..69119f377b8 --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/Pool2DOptions.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 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 __BBO_POOL2D_OPTIONS_H__ +#define __BBO_POOL2D_OPTIONS_H__ + +#include +#include + +namespace tflite2circle +{ + +flatbuffers::Offset +build_circle_Pool2DOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op); + +} // namespace tflite2circle + +#endif // __BBO_POOL2D_OPTIONS_H__ diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/ReducerOptions.cpp b/compiler/tflite2circle/src/BuildBuiltinOptions/ReducerOptions.cpp new file mode 100644 index 00000000000..4bcb04e5b6a --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/ReducerOptions.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2020 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 "ReducerOptions.h" + +#include + +namespace tflite2circle +{ + +flatbuffers::Offset +build_circle_ReducerOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op) +{ + auto tflite_builtin_options = op->builtin_options_as_ReducerOptions(); + assert(tflite_builtin_options); + circle::ReducerOptionsBuilder reducer_options_builder{fb}; + reducer_options_builder.add_keep_dims(tflite_builtin_options->keep_dims()); + return reducer_options_builder.Finish(); +} + +} // namespace tflite2circle diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/ReducerOptions.h b/compiler/tflite2circle/src/BuildBuiltinOptions/ReducerOptions.h new file mode 100644 index 00000000000..b9b39fcb66f --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/ReducerOptions.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 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 __BBO_REDUCER_OPTIONS_H__ +#define __BBO_REDUCER_OPTIONS_H__ + +#include +#include + +namespace tflite2circle +{ + +flatbuffers::Offset +build_circle_ReducerOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op); + +} // namespace tflite2circle + +#endif // __BBO_REDUCER_OPTIONS_H__ diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/ReshapeOptions.cpp b/compiler/tflite2circle/src/BuildBuiltinOptions/ReshapeOptions.cpp new file mode 100644 index 00000000000..dc8e73633b4 --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/ReshapeOptions.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2020 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 "ReshapeOptions.h" + +#include + +namespace tflite2circle +{ + +flatbuffers::Offset +build_circle_ReshapeOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op) +{ + auto tflite_builtin_options = op->builtin_options_as_ReshapeOptions(); + assert(tflite_builtin_options); + std::vector new_shape_vec{tflite_builtin_options->new_shape()->begin(), + tflite_builtin_options->new_shape()->end()}; + auto new_shape = fb.CreateVector(new_shape_vec); + circle::ReshapeOptionsBuilder builtin_options_builder{fb}; + builtin_options_builder.add_new_shape(new_shape); + return builtin_options_builder.Finish(); +} + +} // namespace tflite2circle diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/ReshapeOptions.h b/compiler/tflite2circle/src/BuildBuiltinOptions/ReshapeOptions.h new file mode 100644 index 00000000000..55546ba3e61 --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/ReshapeOptions.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 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 __BBO_RESHAPE_OPTIONS_H__ +#define __BBO_RESHAPE_OPTIONS_H__ + +#include +#include + +namespace tflite2circle +{ + +flatbuffers::Offset +build_circle_ReshapeOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op); + +} // namespace tflite2circle + +#endif // __BBO_RESHAPE_OPTIONS_H__ diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/ShapeOptions.cpp b/compiler/tflite2circle/src/BuildBuiltinOptions/ShapeOptions.cpp new file mode 100644 index 00000000000..b1cbaba0531 --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/ShapeOptions.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2020 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 "ShapeOptions.h" +#include "DataLookup.h" + +#include + +namespace tflite2circle +{ + +flatbuffers::Offset +build_circle_ShapeOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op) +{ + auto tflite_builtin_options = op->builtin_options_as_ShapeOptions(); + assert(tflite_builtin_options); + circle::ShapeOptionsBuilder builtin_options_builder{fb}; + builtin_options_builder.add_out_type(get_circle_tensortype(tflite_builtin_options->out_type())); + return builtin_options_builder.Finish(); +} + +} // namespace tflite2circle diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/ShapeOptions.h b/compiler/tflite2circle/src/BuildBuiltinOptions/ShapeOptions.h new file mode 100644 index 00000000000..2c6e720742b --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/ShapeOptions.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 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 __BBO_SHAPE_OPTIONS_H__ +#define __BBO_SHAPE_OPTIONS_H__ + +#include +#include + +namespace tflite2circle +{ + +flatbuffers::Offset +build_circle_ShapeOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op); + +} // namespace tflite2circle + +#endif // __BBO_SHAPE_OPTIONS_H__ diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/SoftmaxOptions.cpp b/compiler/tflite2circle/src/BuildBuiltinOptions/SoftmaxOptions.cpp new file mode 100644 index 00000000000..a1cf9abe7b8 --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/SoftmaxOptions.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2020 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 "SoftmaxOptions.h" +#include "DataLookup.h" + +#include + +namespace tflite2circle +{ + +flatbuffers::Offset +build_circle_SoftmaxOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op) +{ + auto tflite_builtin_options = op->builtin_options_as_SoftmaxOptions(); + assert(tflite_builtin_options); + circle::SoftmaxOptionsBuilder builtin_options_builder{fb}; + builtin_options_builder.add_beta(tflite_builtin_options->beta()); + return builtin_options_builder.Finish(); +} + +} // namespace tflite2circle diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/SoftmaxOptions.h b/compiler/tflite2circle/src/BuildBuiltinOptions/SoftmaxOptions.h new file mode 100644 index 00000000000..f4a876aaabd --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/SoftmaxOptions.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 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 __BBO_SOFTMAX_OPTIONS_H__ +#define __BBO_SOFTMAX_OPTIONS_H__ + +#include +#include + +namespace tflite2circle +{ + +flatbuffers::Offset +build_circle_SoftmaxOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op); + +} // namespace tflite2circle + +#endif // __BBO_SOFTMAX_OPTIONS_H__ diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/SplitOptions.cpp b/compiler/tflite2circle/src/BuildBuiltinOptions/SplitOptions.cpp new file mode 100644 index 00000000000..fc6c036bfa4 --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/SplitOptions.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2020 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 "SplitOptions.h" + +#include + +namespace tflite2circle +{ + +flatbuffers::Offset +build_circle_SplitOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op) +{ + auto tflite_builtin_options = op->builtin_options_as_SplitOptions(); + assert(tflite_builtin_options); + circle::SplitOptionsBuilder builtin_options_builder{fb}; + builtin_options_builder.add_num_splits(tflite_builtin_options->num_splits()); + return builtin_options_builder.Finish(); +} + +} // namespace tflite2circle diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/SplitOptions.h b/compiler/tflite2circle/src/BuildBuiltinOptions/SplitOptions.h new file mode 100644 index 00000000000..1bbcc397ec1 --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/SplitOptions.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 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 __BBO_SPLIT_OPTIONS_H__ +#define __BBO_SPLIT_OPTIONS_H__ + +#include +#include + +namespace tflite2circle +{ + +flatbuffers::Offset +build_circle_SplitOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op); + +} // namespace tflite2circle + +#endif // __BBO_SPLIT_OPTIONS_H__ diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/SqueezeOptions.cpp b/compiler/tflite2circle/src/BuildBuiltinOptions/SqueezeOptions.cpp new file mode 100644 index 00000000000..ec29b9bf553 --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/SqueezeOptions.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2020 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 "SqueezeOptions.h" + +#include + +namespace tflite2circle +{ + +flatbuffers::Offset +build_circle_SqueezeOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op) +{ + auto tflite_builtin_options = op->builtin_options_as_SqueezeOptions(); + assert(tflite_builtin_options); + std::vector squeeze_dims_vec{tflite_builtin_options->squeeze_dims()->begin(), + tflite_builtin_options->squeeze_dims()->end()}; + auto squeeze_dims = fb.CreateVector(squeeze_dims_vec); + circle::SqueezeOptionsBuilder builtin_options_builder{fb}; + builtin_options_builder.add_squeeze_dims(squeeze_dims); + return builtin_options_builder.Finish(); +} + +} // namespace tflite2circle diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/SqueezeOptions.h b/compiler/tflite2circle/src/BuildBuiltinOptions/SqueezeOptions.h new file mode 100644 index 00000000000..f6237c97792 --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/SqueezeOptions.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 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 __BBO_SQUEEZE_OPTIONS_H__ +#define __BBO_SQUEEZE_OPTIONS_H__ + +#include +#include + +namespace tflite2circle +{ + +flatbuffers::Offset +build_circle_SqueezeOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op); + +} // namespace tflite2circle + +#endif // __BBO_SQUEEZE_OPTIONS_H__ diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/SubOptions.cpp b/compiler/tflite2circle/src/BuildBuiltinOptions/SubOptions.cpp new file mode 100644 index 00000000000..2e55f4dabf3 --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/SubOptions.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2020 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 "SubOptions.h" +#include "DataLookup.h" + +#include + +namespace tflite2circle +{ + +flatbuffers::Offset build_circle_SubOptions(flatbuffers::FlatBufferBuilder &fb, + const tflite::Operator *op) +{ + auto tflite_builtin_options = op->builtin_options_as_SubOptions(); + assert(tflite_builtin_options); + circle::SubOptionsBuilder builtin_options_builder{fb}; + builtin_options_builder.add_fused_activation_function( + get_circle_activation_function_type(tflite_builtin_options->fused_activation_function())); + return builtin_options_builder.Finish(); +} + +} // namespace tflite2circle diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/SubOptions.h b/compiler/tflite2circle/src/BuildBuiltinOptions/SubOptions.h new file mode 100644 index 00000000000..a655548d10f --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/SubOptions.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 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 __BBO_SUB_OPTIONS_H__ +#define __BBO_SUB_OPTIONS_H__ + +#include +#include + +namespace tflite2circle +{ + +flatbuffers::Offset build_circle_SubOptions(flatbuffers::FlatBufferBuilder &fb, + const tflite::Operator *op); + +} // namespace tflite2circle + +#endif // __BBO_SUB_OPTIONS_H__ diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/TransposeOptions.cpp b/compiler/tflite2circle/src/BuildBuiltinOptions/TransposeOptions.cpp new file mode 100644 index 00000000000..427322949c3 --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/TransposeOptions.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 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 "TransposeOptions.h" + +#include + +namespace tflite2circle +{ + +flatbuffers::Offset +build_circle_TransposeOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op) +{ + circle::TransposeOptionsBuilder builtin_options_builder{fb}; + return builtin_options_builder.Finish(); +} + +} // namespace tflite2circle diff --git a/compiler/tflite2circle/src/BuildBuiltinOptions/TransposeOptions.h b/compiler/tflite2circle/src/BuildBuiltinOptions/TransposeOptions.h new file mode 100644 index 00000000000..bc5e5317ae8 --- /dev/null +++ b/compiler/tflite2circle/src/BuildBuiltinOptions/TransposeOptions.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 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 __BBO_TRANSPOSE_OPTIONS_H__ +#define __BBO_TRANSPOSE_OPTIONS_H__ + +#include +#include + +namespace tflite2circle +{ + +flatbuffers::Offset +build_circle_TransposeOptions(flatbuffers::FlatBufferBuilder &fb, const tflite::Operator *op); + +} // namespace tflite2circle + +#endif // __BBO_TRANSPOSE_OPTIONS_H__ diff --git a/compiler/tflite2circle/src/CircleModel.cpp b/compiler/tflite2circle/src/CircleModel.cpp index 4576edb3d8b..3a569323c2d 100644 --- a/compiler/tflite2circle/src/CircleModel.cpp +++ b/compiler/tflite2circle/src/CircleModel.cpp @@ -27,8 +27,8 @@ Offset::Offset(FlatBufBuilder &fb, const TFLFlatBufVec *tfli { if (tflite_flatbuffer_vec == nullptr) return; - std::vector metadata_buffer_vec{tflite_flatbuffer_vec->begin(), - tflite_flatbuffer_vec->end()}; + std::vector metadata_buffer_vec{tflite_flatbuffer_vec->begin(), + tflite_flatbuffer_vec->end()}; _circle_flatbuffer_vec_offset = fb->CreateVector(metadata_buffer_vec); } @@ -56,125 +56,129 @@ Offset::Offset(FlatBufBuilder &fb, const TFLFlatBufVec *tflite_flatb template <> Offset::Offset(FlatBufBuilder &fb, const TFLFlatBufVec *tflite_flatbuffer_vec) { - // tensors of subgraph - std::vector> tensor_vec; + std::vector> subgprahs_vec; - auto tflite_tensors = tflite_flatbuffer_vec->Get(0)->tensors(); - for (auto it : *tflite_tensors) + for (auto it_sg : *tflite_flatbuffer_vec) { - // shape - std::vector shape_vec{it->shape()->begin(), it->shape()->end()}; - auto shape = fb->CreateVector(shape_vec); - // name - flatbuffers::Offset name; - if (it->name()) - name = fb->CreateString(it->name()->str()); - // quantization - flatbuffers::Offset quantization; - if (it->quantization()) - { - std::vector tfmin; - std::vector tfmax; - std::vector tfscale; - std::vector tfzerop; - flatbuffers::Offset> min; - flatbuffers::Offset> max; - flatbuffers::Offset> scale; - flatbuffers::Offset> zero_point; - - if (it->quantization()->min() && it->quantization()->max()) - { - auto rmin = it->quantization()->min(); - auto rmax = it->quantization()->max(); - tfmin = std::vector{rmin->begin(), rmin->end()}; - tfmax = std::vector{rmax->begin(), rmax->end()}; - min = fb->CreateVector(tfmin); - max = fb->CreateVector(tfmax); - } + // tensors of subgraph + std::vector> tensor_vec; - if (it->quantization()->scale() && it->quantization()->zero_point()) + auto tflite_tensors = it_sg->tensors(); + for (auto it : *tflite_tensors) + { + // shape + std::vector shape_vec{it->shape()->begin(), it->shape()->end()}; + auto shape = fb->CreateVector(shape_vec); + // name + flatbuffers::Offset name; + if (it->name()) + name = fb->CreateString(it->name()->str()); + // quantization + flatbuffers::Offset quantization; + if (it->quantization()) { - auto rs = it->quantization()->scale(); - auto rz = it->quantization()->zero_point(); - tfscale = std::vector{rs->begin(), rs->end()}; - tfzerop = std::vector{rz->begin(), rz->end()}; - scale = fb->CreateVector(tfscale); - zero_point = fb->CreateVector(tfzerop); + std::vector tfmin; + std::vector tfmax; + std::vector tfscale; + std::vector tfzerop; + flatbuffers::Offset> min; + flatbuffers::Offset> max; + flatbuffers::Offset> scale; + flatbuffers::Offset> zero_point; + + if (it->quantization()->min() && it->quantization()->max()) + { + auto rmin = it->quantization()->min(); + auto rmax = it->quantization()->max(); + tfmin = std::vector{rmin->begin(), rmin->end()}; + tfmax = std::vector{rmax->begin(), rmax->end()}; + min = fb->CreateVector(tfmin); + max = fb->CreateVector(tfmax); + } + + if (it->quantization()->scale() && it->quantization()->zero_point()) + { + auto rs = it->quantization()->scale(); + auto rz = it->quantization()->zero_point(); + tfscale = std::vector{rs->begin(), rs->end()}; + tfzerop = std::vector{rz->begin(), rz->end()}; + scale = fb->CreateVector(tfscale); + zero_point = fb->CreateVector(tfzerop); + } + + quantization = circle::CreateQuantizationParameters(*fb, min, max, scale, zero_point); } - - quantization = circle::CreateQuantizationParameters(*fb, min, max, scale, zero_point); + // is_variable + bool is_variable = it->is_variable(); + + circle::TensorBuilder tensor_builder{*fb}; + tensor_builder.add_shape(shape); + tensor_builder.add_type(get_circle_tensortype(it->type())); + tensor_builder.add_buffer(it->buffer()); + tensor_builder.add_name(name); + tensor_builder.add_quantization(quantization); + tensor_builder.add_is_variable(is_variable); + auto tensor = tensor_builder.Finish(); + tensor_vec.emplace_back(tensor); } - // is_variable - bool is_variable = it->is_variable(); - - circle::TensorBuilder tensor_builder{*fb}; - tensor_builder.add_shape(shape); - tensor_builder.add_type(get_circle_tensortype(it->type())); - tensor_builder.add_buffer(it->buffer()); - tensor_builder.add_name(name); - tensor_builder.add_quantization(quantization); - tensor_builder.add_is_variable(is_variable); - auto tensor = tensor_builder.Finish(); - tensor_vec.emplace_back(tensor); - } - auto circle_tensors = fb->CreateVector(tensor_vec); + auto circle_tensors = fb->CreateVector(tensor_vec); - // inputs of subgraph - auto tflite_inputs = tflite_flatbuffer_vec->Get(0)->inputs(); - std::vector input_vec{tflite_inputs->begin(), tflite_inputs->end()}; + // inputs of subgraph + auto tflite_inputs = it_sg->inputs(); + std::vector input_vec{tflite_inputs->begin(), tflite_inputs->end()}; - auto circle_inputs = fb->CreateVector(input_vec); + auto circle_inputs = fb->CreateVector(input_vec); - // outputs of subgraph - auto tflite_outputs = tflite_flatbuffer_vec->Get(0)->outputs(); - std::vector output_vec{tflite_outputs->begin(), tflite_outputs->end()}; + // outputs of subgraph + auto tflite_outputs = it_sg->outputs(); + std::vector output_vec{tflite_outputs->begin(), tflite_outputs->end()}; - auto circle_outputs = fb->CreateVector(output_vec); + auto circle_outputs = fb->CreateVector(output_vec); - // operators of subgraph - std::vector> operator_vec; + // operators of subgraph + std::vector> operator_vec; - auto tflite_operators = tflite_flatbuffer_vec->Get(0)->operators(); - for (auto it : *tflite_operators) - { - // inputs - std::vector input_vec{it->inputs()->begin(), it->inputs()->end()}; - auto circle_inputs = fb->CreateVector(input_vec); - // outputs - std::vector output_vec{it->outputs()->begin(), it->outputs()->end()}; - auto circle_outputs = fb->CreateVector(output_vec); - // builtin options - auto circle_builtin_options = get_circle_builtin_options(*fb, it); - auto circle_builtin_options_type = get_circle_builtin_options_type(it); - - circle::OperatorBuilder operator_builder{*fb}; - operator_builder.add_opcode_index(it->opcode_index()); - operator_builder.add_inputs(circle_inputs); - operator_builder.add_outputs(circle_outputs); - operator_builder.add_builtin_options(circle_builtin_options); - operator_builder.add_builtin_options_type(circle_builtin_options_type); - // TODO custom_options, mutating_variable_inputs - auto opeartor = operator_builder.Finish(); - operator_vec.emplace_back(opeartor); - } - auto circle_operators = fb->CreateVector(operator_vec); + auto tflite_operators = it_sg->operators(); + for (auto it : *tflite_operators) + { + // inputs + std::vector input_vec{it->inputs()->begin(), it->inputs()->end()}; + auto circle_inputs = fb->CreateVector(input_vec); + // outputs + std::vector output_vec{it->outputs()->begin(), it->outputs()->end()}; + auto circle_outputs = fb->CreateVector(output_vec); + // builtin options + auto circle_builtin_options = get_circle_builtin_options(*fb, it); + auto circle_builtin_options_type = get_circle_builtin_options_type(it); + + circle::OperatorBuilder operator_builder{*fb}; + operator_builder.add_opcode_index(it->opcode_index()); + operator_builder.add_inputs(circle_inputs); + operator_builder.add_outputs(circle_outputs); + operator_builder.add_builtin_options(circle_builtin_options); + operator_builder.add_builtin_options_type(circle_builtin_options_type); + // TODO custom_options, mutating_variable_inputs + auto opeartor = operator_builder.Finish(); + operator_vec.emplace_back(opeartor); + } + auto circle_operators = fb->CreateVector(operator_vec); - // name of subgraph - auto subgraphs_name = fb->CreateString(tflite_flatbuffer_vec->Get(0)->name()); + // name of subgraph + auto subgraphs_name = fb->CreateString(it_sg->name()); - // subgraphs - std::vector> subgprahs_vec; - auto circle_subgraph_builder = circle::SubGraphBuilder{*fb}; + // subgraphs + auto circle_subgraph_builder = circle::SubGraphBuilder{*fb}; - circle_subgraph_builder.add_tensors(circle_tensors); - circle_subgraph_builder.add_inputs(circle_inputs); - circle_subgraph_builder.add_outputs(circle_outputs); - circle_subgraph_builder.add_operators(circle_operators); - circle_subgraph_builder.add_name(subgraphs_name); - circle_subgraph_builder.add_data_format(circle::DataFormat_CHANNELS_LAST); + circle_subgraph_builder.add_tensors(circle_tensors); + circle_subgraph_builder.add_inputs(circle_inputs); + circle_subgraph_builder.add_outputs(circle_outputs); + circle_subgraph_builder.add_operators(circle_operators); + circle_subgraph_builder.add_name(subgraphs_name); + circle_subgraph_builder.add_data_format(circle::DataFormat_CHANNELS_LAST); - auto circle_subgraph = circle_subgraph_builder.Finish(); - subgprahs_vec.emplace_back(circle_subgraph); + auto circle_subgraph = circle_subgraph_builder.Finish(); + subgprahs_vec.emplace_back(circle_subgraph); + } _circle_flatbuffer_vec_offset = fb->CreateVector(subgprahs_vec); } @@ -188,6 +192,7 @@ Offset::Offset(FlatBufBuilder &fb, const TFLFlatBufVec *tflite auto custom_code = fb->CreateString(it->custom_code()); circle::OperatorCodeBuilder operator_code_builder{*fb}; operator_code_builder.add_builtin_code(get_circle_builtin_code(it->builtin_code())); + operator_code_builder.add_custom_code(custom_code); operator_code_builder.add_version(it->version()); auto code = operator_code_builder.Finish(); operator_code_vec.emplace_back(code); diff --git a/compiler/tflite2circle/src/TFLActivationFunctionType.lst b/compiler/tflite2circle/src/TFLActivationFunctionType.lst index 6681f258a58..a378bdc670c 100644 --- a/compiler/tflite2circle/src/TFLActivationFunctionType.lst +++ b/compiler/tflite2circle/src/TFLActivationFunctionType.lst @@ -2,6 +2,8 @@ #error "Activation function type is not defined." #endif +// NOTE order of function follows TensorFlow lite schema.fbs 'enum ActivationFunctionType' + TFL_ACTIVATION_FUNCTION(NONE) TFL_ACTIVATION_FUNCTION(RELU) TFL_ACTIVATION_FUNCTION(RELU_N1_TO_1) diff --git a/compiler/tflite2circle/src/TFLBuiltinOptions.lst b/compiler/tflite2circle/src/TFLBuiltinOptions.lst index ce19c62d209..b4292584ea5 100644 --- a/compiler/tflite2circle/src/TFLBuiltinOptions.lst +++ b/compiler/tflite2circle/src/TFLBuiltinOptions.lst @@ -2,6 +2,8 @@ #error "TFL_BUILTIN_OPTIONS is not defined" #endif +// NOTE order of option follows TensorFlow lite schema.fbs 'union BuiltinOptions' + TFL_BUILTIN_OPTIONS(Conv2DOptions) TFL_BUILTIN_OPTIONS(DepthwiseConv2DOptions) //TFL_BUILTIN_OPTIONS(ConcatEmbeddingsOptions) @@ -22,23 +24,23 @@ TFL_BUILTIN_OPTIONS(ReshapeOptions) //TFL_BUILTIN_OPTIONS(SkipGramOptions) //TFL_BUILTIN_OPTIONS(SpaceToDepthOptions) //TFL_BUILTIN_OPTIONS(EmbeddingLookupSparseOptions) -//TFL_BUILTIN_OPTIONS(MulOptions) -//TFL_BUILTIN_OPTIONS(PadOptions) +TFL_BUILTIN_OPTIONS(MulOptions) +TFL_BUILTIN_OPTIONS(PadOptions) //TFL_BUILTIN_OPTIONS(GatherOptions) //TFL_BUILTIN_OPTIONS(BatchToSpaceNDOptions) //TFL_BUILTIN_OPTIONS(SpaceToBatchNDOptions) -//TFL_BUILTIN_OPTIONS(TransposeOptions) -//TFL_BUILTIN_OPTIONS(ReducerOptions) +TFL_BUILTIN_OPTIONS(TransposeOptions) +TFL_BUILTIN_OPTIONS(ReducerOptions) TFL_BUILTIN_OPTIONS(SubOptions) TFL_BUILTIN_OPTIONS(DivOptions) -//TFL_BUILTIN_OPTIONS(SqueezeOptions) +TFL_BUILTIN_OPTIONS(SqueezeOptions) //TFL_BUILTIN_OPTIONS(SequenceRNNOptions) //TFL_BUILTIN_OPTIONS(StridedSliceOptions) //TFL_BUILTIN_OPTIONS(ExpOptions) //TFL_BUILTIN_OPTIONS(TopKV2Options) -//TFL_BUILTIN_OPTIONS(SplitOptions) +TFL_BUILTIN_OPTIONS(SplitOptions) //TFL_BUILTIN_OPTIONS(LogSoftmaxOptions) -//TFL_BUILTIN_OPTIONS(CastOptions) +TFL_BUILTIN_OPTIONS(CastOptions) //TFL_BUILTIN_OPTIONS(DequantizeOptions) //TFL_BUILTIN_OPTIONS(MaximumMinimumOptions) TFL_BUILTIN_OPTIONS(ArgMaxOptions) @@ -46,30 +48,30 @@ TFL_BUILTIN_OPTIONS(ArgMaxOptions) //TFL_BUILTIN_OPTIONS(NegOptions) //TFL_BUILTIN_OPTIONS(PadV2Options) //TFL_BUILTIN_OPTIONS(GreaterOptions) -//TFL_BUILTIN_OPTIONS(GreaterEqualOptions) +TFL_BUILTIN_OPTIONS(GreaterEqualOptions) //TFL_BUILTIN_OPTIONS(LessEqualOptions) //TFL_BUILTIN_OPTIONS(SelectOptions) //TFL_BUILTIN_OPTIONS(SliceOptions) //TFL_BUILTIN_OPTIONS(TransposeConvOptions) //TFL_BUILTIN_OPTIONS(SparseToDenseOptions) //TFL_BUILTIN_OPTIONS(TileOptions) -//TFL_BUILTIN_OPTIONS(ExpandDimsOptions) -//TFL_BUILTIN_OPTIONS(EqualOptions) -//TFL_BUILTIN_OPTIONS(NotEqualOptions) -//TFL_BUILTIN_OPTIONS(ShapeOptions) +TFL_BUILTIN_OPTIONS(ExpandDimsOptions) +TFL_BUILTIN_OPTIONS(EqualOptions) +TFL_BUILTIN_OPTIONS(NotEqualOptions) +TFL_BUILTIN_OPTIONS(ShapeOptions) //TFL_BUILTIN_OPTIONS(PowOptions) //TFL_BUILTIN_OPTIONS(ArgMinOptions) //TFL_BUILTIN_OPTIONS(FakeQuantOptions) -//TFL_BUILTIN_OPTIONS(PackOptions) -//TFL_BUILTIN_OPTIONS(LogicalOrOptions) +TFL_BUILTIN_OPTIONS(PackOptions) +TFL_BUILTIN_OPTIONS(LogicalOrOptions) //TFL_BUILTIN_OPTIONS(OneHotOptions) //TFL_BUILTIN_OPTIONS(LogicalAndOptions) -//TFL_BUILTIN_OPTIONS(LogicalNotOptions) +TFL_BUILTIN_OPTIONS(LogicalNotOptions) //TFL_BUILTIN_OPTIONS(UnpackOptions) //TFL_BUILTIN_OPTIONS(FloorDivOptions) //TFL_BUILTIN_OPTIONS(SquareOptions) //TFL_BUILTIN_OPTIONS(ZerosLikeOptions) -//TFL_BUILTIN_OPTIONS(FillOptions) +TFL_BUILTIN_OPTIONS(FillOptions) //TFL_BUILTIN_OPTIONS(BidirectionalSequenceLSTMOptions) //TFL_BUILTIN_OPTIONS(BidirectionalSequenceRNNOptions) //TFL_BUILTIN_OPTIONS(UnidirectionalSequenceLSTMOptions) @@ -79,5 +81,23 @@ TFL_BUILTIN_OPTIONS(ArgMaxOptions) //TFL_BUILTIN_OPTIONS(LeakyReluOptions) //TFL_BUILTIN_OPTIONS(SquaredDifferenceOptions) //TFL_BUILTIN_OPTIONS(MirrorPadOptions) -//TFL_BUILTIN_OPTIONS(AbsOptions) +TFL_BUILTIN_OPTIONS(AbsOptions) //TFL_BUILTIN_OPTIONS(SplitVOptions) +//TFL_BUILTIN_OPTIONS(UniqueOptions) +//TFL_BUILTIN_OPTIONS(ReverseV2Options) +//TFL_BUILTIN_OPTIONS(AddNOptions) +//TFL_BUILTIN_OPTIONS(GatherNdOptions) +TFL_BUILTIN_OPTIONS(CosOptions) +//TFL_BUILTIN_OPTIONS(WhereOptions) +//TFL_BUILTIN_OPTIONS(RankOptions) +//TFL_BUILTIN_OPTIONS(ReverseSequenceOptions) +//TFL_BUILTIN_OPTIONS(MatrixDiagOptions) +//TFL_BUILTIN_OPTIONS(QuantizeOptions) +//TFL_BUILTIN_OPTIONS(MatrixSetDiagOptions) +//TFL_BUILTIN_OPTIONS(HardSwishOptions) +//TFL_BUILTIN_OPTIONS(IfOptions) +//TFL_BUILTIN_OPTIONS(WhileOptions) +//TFL_BUILTIN_OPTIONS(DepthToSpaceOptions) +//TFL_BUILTIN_OPTIONS(NonMaxSuppressionV4Options) +//TFL_BUILTIN_OPTIONS(NonMaxSuppressionV5Options) +//TFL_BUILTIN_OPTIONS(ScatterNdOptions) diff --git a/compiler/tflite2circle/src/TFLOperator.lst b/compiler/tflite2circle/src/TFLOperator.lst index 2f2f9419ce9..ac2f9daec56 100644 --- a/compiler/tflite2circle/src/TFLOperator.lst +++ b/compiler/tflite2circle/src/TFLOperator.lst @@ -2,6 +2,8 @@ #error "TFL_OPERATOR is not defined." #endif +// NOTE order of operator follows TensorFlow lite schema.fbs 'enum BuiltinOperator' + TFL_OPERATOR(ADD) TFL_OPERATOR(AVERAGE_POOL_2D) TFL_OPERATOR(CONCATENATION) @@ -96,3 +98,31 @@ TFL_OPERATOR(REDUCE_ANY) TFL_OPERATOR(SQUARE) TFL_OPERATOR(ZEROS_LIKE) TFL_OPERATOR(FILL) +TFL_OPERATOR(FLOOR_MOD) +TFL_OPERATOR(RANGE) +TFL_OPERATOR(RESIZE_NEAREST_NEIGHBOR) +TFL_OPERATOR(LEAKY_RELU) +TFL_OPERATOR(SQUARED_DIFFERENCE) +TFL_OPERATOR(MIRROR_PAD) +TFL_OPERATOR(ABS) +TFL_OPERATOR(SPLIT_V) +TFL_OPERATOR(UNIQUE) +TFL_OPERATOR(CEIL) +TFL_OPERATOR(REVERSE_V2) +TFL_OPERATOR(ADD_N) +TFL_OPERATOR(GATHER_ND) +TFL_OPERATOR(COS) +TFL_OPERATOR(WHERE) +TFL_OPERATOR(RANK) +TFL_OPERATOR(ELU) +TFL_OPERATOR(REVERSE_SEQUENCE) +TFL_OPERATOR(MATRIX_DIAG) +TFL_OPERATOR(QUANTIZE) +TFL_OPERATOR(MATRIX_SET_DIAG) +TFL_OPERATOR(ROUND) +TFL_OPERATOR(HARD_SWISH) +TFL_OPERATOR(IF) +TFL_OPERATOR(WHILE) +TFL_OPERATOR(NON_MAX_SUPPRESSION_V4) +TFL_OPERATOR(NON_MAX_SUPPRESSION_V5) +TFL_OPERATOR(SCATTER_ND) diff --git a/compiler/tflite2circle/src/TFLTensorType.lst b/compiler/tflite2circle/src/TFLTensorType.lst index d0e1f6e990b..968153a5d42 100644 --- a/compiler/tflite2circle/src/TFLTensorType.lst +++ b/compiler/tflite2circle/src/TFLTensorType.lst @@ -2,6 +2,8 @@ #error "TFL_TENSORTYPE is not defined." #endif +// NOTE order of type follows TensorFlow lite schema.fbs 'enum TensorType' + TFL_TENSORTYPE(FLOAT32) TFL_TENSORTYPE(FLOAT16) TFL_TENSORTYPE(INT32) diff --git a/compute/ARMComputeEx/CMakeLists.txt b/compute/ARMComputeEx/CMakeLists.txt index aaebff758db..8dfe0c40b21 100644 --- a/compute/ARMComputeEx/CMakeLists.txt +++ b/compute/ARMComputeEx/CMakeLists.txt @@ -28,5 +28,9 @@ target_compile_definitions(arm_compute_ex PRIVATE EMBEDDED_KERNELS ARM_COMPUTE_LOGGING_ENABLED>) # Validate check functions are not used on release build # Some parameter are used for validate check function call, and these parameter may not used on release build -target_compile_options(arm_compute_ex PRIVATE $<$>:-Wno-unused-parameter -Wno-unused-function>) +# Because clang requires to add "-Wno-unused-parameter -Wno-unused-function" after "-Wall", +# this should be after linking nnfw_common and use interface lib linking +add_library(ignore_unused_warning INTERFACE) +target_compile_options(ignore_unused_warning INTERFACE -Wno-unused-parameter -Wno-unused-function) +target_link_libraries(arm_compute_ex PRIVATE $<$>:ignore_unused_warning>) install(TARGETS arm_compute_ex DESTINATION lib) diff --git a/compute/ARMComputeEx/arm_compute/runtime/NEON/functions/NEGEMMLowpMatrixMultiplyCoreEx.h b/compute/ARMComputeEx/arm_compute/runtime/NEON/functions/NEGEMMLowpMatrixMultiplyCoreEx.h index 3077ce7be7d..d844513c9a1 100644 --- a/compute/ARMComputeEx/arm_compute/runtime/NEON/functions/NEGEMMLowpMatrixMultiplyCoreEx.h +++ b/compute/ARMComputeEx/arm_compute/runtime/NEON/functions/NEGEMMLowpMatrixMultiplyCoreEx.h @@ -146,7 +146,6 @@ class NEGEMMLowpMatrixMultiplyCoreEx : public IFunction NEGEMMLowpMatrixBReductionKernel _mtx_b_reduction_kernel; NEGEMMLowpOffsetContributionKernel _offset_contribution_kernel; NEGEMMLowpOffsetContributionOutputStageKernel _offset_contribution_output_stage_kernel; - // NEActivationLayer _activation_func; Tensor _vector_sum_col; Tensor _vector_sum_row; @@ -165,7 +164,6 @@ class NEGEMMLowpMatrixMultiplyCoreEx : public IFunction bool _reshape_b_only_on_first_run; bool _is_prepared; bool _fuse_output_stage; - bool _run_activation; bool _flip_signedness; }; } // namespace arm_compute diff --git a/compute/ARMComputeEx/resolve_includes.py b/compute/ARMComputeEx/resolve_includes.py old mode 100644 new mode 100755 diff --git a/compute/ARMComputeEx/src/core/NEON/kernels/NEMultiplyScaleFactorKernel.cpp b/compute/ARMComputeEx/src/core/NEON/kernels/NEMultiplyScaleFactorKernel.cpp index e04bef1f584..b92130cece4 100644 --- a/compute/ARMComputeEx/src/core/NEON/kernels/NEMultiplyScaleFactorKernel.cpp +++ b/compute/ARMComputeEx/src/core/NEON/kernels/NEMultiplyScaleFactorKernel.cpp @@ -87,12 +87,6 @@ inline int32x4x4_t load_value(const int32_t *input_ptr) wrapper::vloadq(input_ptr + 8), wrapper::vloadq(input_ptr + 12)}; } -inline float32x4x4_t load_value(const float *input_ptr) -{ - return {wrapper::vloadq(input_ptr), wrapper::vloadq(input_ptr + 4), - wrapper::vloadq(input_ptr + 8), wrapper::vloadq(input_ptr + 12)}; -} - #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC inline const float32x4x4_t load_value(const float16_t *input_ptr) { diff --git a/compute/ARMComputeEx/src/runtime/CL/functions/CLGEMMLowpMatrixMultiplyCoreEx.cpp b/compute/ARMComputeEx/src/runtime/CL/functions/CLGEMMLowpMatrixMultiplyCoreEx.cpp index 34bd55c6b32..ca5499dfcc7 100644 --- a/compute/ARMComputeEx/src/runtime/CL/functions/CLGEMMLowpMatrixMultiplyCoreEx.cpp +++ b/compute/ARMComputeEx/src/runtime/CL/functions/CLGEMMLowpMatrixMultiplyCoreEx.cpp @@ -93,8 +93,8 @@ void CLGEMMLowpMatrixMultiplyCoreEx::configure(const ICLTensor *a, const ICLTens // Set the target for the kernels _mm_midgard_kernel.set_target(gpu_target); - GEMMRHSMatrixInfo rhs_info; - GEMMLHSMatrixInfo lhs_info; + // GEMMRHSMatrixInfo rhs_info; + // GEMMLHSMatrixInfo lhs_info; // Arguments used by GEMMReshapeInfo // If we pass the matrix A and matrix B reshaped to CLGEMMMatrixMultiplyKernel, we need to pass m, @@ -130,10 +130,6 @@ Status CLGEMMLowpMatrixMultiplyCoreEx::validate(const ITensorInfo *a, const ITen const ITensorInfo *matrix_a_info = a; - TensorInfo tmp_b_info{}; - GEMMRHSMatrixInfo rhs_info; - GEMMLHSMatrixInfo lhs_info; - // Get the GPU target const GPUTarget gpu_target = CLScheduler::get().target(); diff --git a/compute/ARMComputeEx/src/runtime/NEON/functions/NEGEMMLowpMatrixMultiplyCoreEx.cpp b/compute/ARMComputeEx/src/runtime/NEON/functions/NEGEMMLowpMatrixMultiplyCoreEx.cpp index e076a3a9452..1290cfd3928 100644 --- a/compute/ARMComputeEx/src/runtime/NEON/functions/NEGEMMLowpMatrixMultiplyCoreEx.cpp +++ b/compute/ARMComputeEx/src/runtime/NEON/functions/NEGEMMLowpMatrixMultiplyCoreEx.cpp @@ -66,7 +66,7 @@ NEGEMMLowpMatrixMultiplyCoreEx::NEGEMMLowpMatrixMultiplyCoreEx( _tmp_b(), _mm_result_s32(), _signed_a(), _signed_output(), _original_b(nullptr), _a_offset(0), _b_offset(0), _run_vector_matrix_multiplication(false), _assembly_path(false), _fused_assembly_path(false), _reshape_b_only_on_first_run(false), _is_prepared(false), - _fuse_output_stage(false), _run_activation(false), _flip_signedness(false) + _fuse_output_stage(false), _flip_signedness(false) { } diff --git a/compute/cker/CMakeLists.txt b/compute/cker/CMakeLists.txt index 90bbfd25eb9..b8ceba5e39c 100644 --- a/compute/cker/CMakeLists.txt +++ b/compute/cker/CMakeLists.txt @@ -1,5 +1,7 @@ nnfw_find_package(Eigen REQUIRED) +nnfw_find_package(GEMMLowp REQUIRED) add_library(nnfw_lib_cker INTERFACE) target_link_libraries(nnfw_lib_cker INTERFACE eigen) +target_link_libraries(nnfw_lib_cker INTERFACE gemmlowp) target_include_directories(nnfw_lib_cker INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include) diff --git a/compute/cker/README.md b/compute/cker/README.md index a92603ba010..3d98362aba5 100644 --- a/compute/cker/README.md +++ b/compute/cker/README.md @@ -4,4 +4,4 @@ cker - CPU kernel library __cker__ means `CPU kernel` -Current __cker__ is porting of Tensorflow lite's operation kernel and gemmlowp +Current __cker__ is porting of Tensorflow lite's operation kernel diff --git a/compute/cker/include/cker/NeonTensorUtils.h b/compute/cker/include/cker/NeonTensorUtils.h new file mode 100644 index 00000000000..4d97dd18748 --- /dev/null +++ b/compute/cker/include/cker/NeonTensorUtils.h @@ -0,0 +1,319 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved + * Copyright 2017 The TensorFlow Authors. 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 __NNFW_CKER_NEON_TENSOR_UTILS_H__ +#define __NNFW_CKER_NEON_TENSOR_UTILS_H__ + +#include "cker/neon/neon_check.h" + +#include +#include + +#ifdef USE_NEON + +#define kFloatWeightsPerNeonLane 4 + +namespace nnfw +{ +namespace cker +{ + +namespace +{ + +// Allocates, at least, size bytes of uninitialized storage whose alignment is +// specified by alignment. The size parameter must be an integral multiple of +// alignment. +// Caller is responsible by freeing the allocated memory by calling free on +// the passed freeing_buffer pointer. +void *aligned_alloc(size_t alignment, size_t size, void **freeing_buffer) +{ + *freeing_buffer = malloc(size + alignment); + const size_t offset = ((uintptr_t)*freeing_buffer) % alignment; // NOLINT + return offset == 0 ? *freeing_buffer : ((char *)*freeing_buffer + (alignment - offset)); // NOLINT +} + +} // namespace + +bool NeonIsZeroVector(const float *vector, int v_size) +{ + // If v_size is not divisible by kFloatWeightsPerNeonLane, we cannot + // use the main vectorized loop, and we need to process sequentially. + // postamble_start shows the start index where this should happen. + const int postamble_start = v_size - (v_size & (kFloatWeightsPerNeonLane - 1)); + + const float32x4_t zero_x4_float = vmovq_n_f32(0.0f); + for (int v = 0; v < postamble_start; v += kFloatWeightsPerNeonLane) + { + const float32x4_t i_x4_float = vld1q_f32(vector + v); + uint32x4_t cmp_result = vceqq_f32(i_x4_float, zero_x4_float); + if (vgetq_lane_u32(cmp_result, 0) == 0) + return false; + if (vgetq_lane_u32(cmp_result, 1) == 0) + return false; + if (vgetq_lane_u32(cmp_result, 2) == 0) + return false; + if (vgetq_lane_u32(cmp_result, 3) == 0) + return false; + } + + // Postamble loop + for (int v = postamble_start; v < v_size; ++v) + { + if (vector[v] != 0.0) + return false; + } + return true; +} + +void NeonSymmetricQuantizeFloats(const float *values, const int size, int8_t *quantized_values, + float *min, float *max, float *scaling_factor) +{ + // TODO(raziel): vectorize min/max calculation. + auto minmax = std::minmax_element(values, values + size); + *min = *minmax.first; + *max = *minmax.second; + const int kScale = 127; + const float range = std::max(std::abs(*min), std::abs(*max)); + if (range == 0) + { + memset(quantized_values, 0, size * sizeof(int8_t)); + *scaling_factor = 1; + return; + } + *scaling_factor = range / kScale; + const float scaling_factor_inv = kScale / range; + + const int postamble_start = size - (size & (2 * kFloatWeightsPerNeonLane - 1)); + + // Vectorized constants. + const float32x4_t q_factor_f32x4 = vmovq_n_f32(scaling_factor_inv); + const float32x4_t point5_f32x4 = vmovq_n_f32(0.5); + const float32x4_t zero_f32x4 = vmovq_n_f32(0.0); + const int32x4_t scale_i32x4 = vmovq_n_s32(kScale); + const int32x4_t neg_scale_i32x4 = vmovq_n_s32(-kScale); + + for (int i = 0; i < postamble_start; i += 2 * kFloatWeightsPerNeonLane) + { + // Implements the vectorized version of the following: + // const int32_t quantized_value = static_cast( + // std::round(*scaling_factor * values[i])); + // Since the vectorized round intrinsics (vrndqa_f32) is not supported + // on all Neon flavors, we use the following method for rounding: if (x + // < 0) (int)(x - 0.5) if (x >= 0) (int)(x + 0.5) + float32x4_t value0_f32x4 = vld1q_f32(&values[i]); + float32x4_t value1_f32x4 = vld1q_f32(&values[i + kFloatWeightsPerNeonLane]); + float32x4_t mul0_f32x4 = vmulq_f32(value0_f32x4, q_factor_f32x4); + float32x4_t mul1_f32x4 = vmulq_f32(value1_f32x4, q_factor_f32x4); + + int32x4_t cmp_with_zero0_ui32x4 = (int32x4_t)vcltq_f32(mul0_f32x4, zero_f32x4); // NOLINT + int32x4_t cmp_with_zero1_ui32x4 = (int32x4_t)vcltq_f32(mul1_f32x4, zero_f32x4); // NOLINT + + float32x4_t cmp_with_zero0_f32x4 = vcvtq_f32_s32(cmp_with_zero0_ui32x4); + float32x4_t cmp_with_zero1_f32x4 = vcvtq_f32_s32(cmp_with_zero1_ui32x4); + cmp_with_zero0_f32x4 = vaddq_f32(cmp_with_zero0_f32x4, point5_f32x4); + cmp_with_zero1_f32x4 = vaddq_f32(cmp_with_zero1_f32x4, point5_f32x4); + + mul0_f32x4 = vaddq_f32(mul0_f32x4, cmp_with_zero0_f32x4); + mul1_f32x4 = vaddq_f32(mul1_f32x4, cmp_with_zero1_f32x4); + + int32x4_t f2i0_i32x4 = vcvtq_s32_f32(mul0_f32x4); + int32x4_t f2i1_i32x4 = vcvtq_s32_f32(mul1_f32x4); + + // Implements the vectorized version of the folowing block: + // quantized_values[i] = std::min(kScale, std::max(-kScale, + // quantized_value)); + int32x4_t max0_i32x4 = vmaxq_s32(f2i0_i32x4, neg_scale_i32x4); + int32x4_t max1_i32x4 = vmaxq_s32(f2i1_i32x4, neg_scale_i32x4); + int32x4_t min0_i32x4 = vminq_s32(max0_i32x4, scale_i32x4); + int32x4_t min1_i32x4 = vminq_s32(max1_i32x4, scale_i32x4); + + int16x4_t min0_16x4 = vmovn_s32(min0_i32x4); + int16x4_t min1_16x4 = vmovn_s32(min1_i32x4); + + int16x8_t min_16x8 = vcombine_s16(min0_16x4, min1_16x4); + int8x8_t min_s8x8 = vqmovn_s16(min_16x8); + vst1_s8(&quantized_values[i], min_s8x8); + } + + for (int i = postamble_start; i < size; ++i) + { + const int32_t quantized_value = + static_cast(std::round(scaling_factor_inv * values[i])); + quantized_values[i] = std::min(kScale, std::max(-kScale, quantized_value)); + } +} + +void NeonMatrixBatchVectorMultiplyAccumulate(const int8_t *__restrict__ matrix, const int m_rows, + const int m_cols, const int8_t *__restrict__ vectors, + const float *scaling_factors, int n_batch, + float *__restrict__ result, int result_stride) +{ + const int kWeightsPerUint32 = 4; + const int kWeightsPerNeonLane = 16; + // If the number of rows is not divisible by kWeightsPerUint32, we set a + // flag and allocate an aligned memory block. The flag is used to use the + // aligned memory block later in the kernel loop. + bool unaligned = false; + int8_t *aligned_row = nullptr; + void *aligned_row_free = nullptr; + if ((m_cols & (kWeightsPerUint32 - 1)) != 0) + { + unaligned = true; + aligned_row = (int8_t *)aligned_alloc(kWeightsPerUint32, m_cols, // NOLINT + &aligned_row_free); + } + void *aligned_vec_free = nullptr; + int8_t *aligned_vec = (int8_t *)aligned_alloc(kWeightsPerUint32, m_cols, // NOLINT + &aligned_vec_free); + + // If m_cols is not at least kWeightsPerNeonLane, we cannot use the main + // vectorized loop, and we need to process sequentially. postamble_start shows + // the start index where this should happen. + const int postamble_start = m_cols - (m_cols & (kWeightsPerNeonLane - 1)); + + int batch, row, col; + for (batch = 0; batch < n_batch; ++batch) + { + const float batch_scaling_factor = scaling_factors[batch]; + // Copy the vector data to an aligned vector. + memcpy(aligned_vec, vectors + batch * m_cols, sizeof(int8_t) * m_cols); + // Compute dot-product for every column. + for (row = 0; row < m_rows; ++row, result += result_stride) + { + // Get the address of the first element of the row. + int8_t *row_ptr = (int8_t *)matrix + row * m_cols; // NOLINT + if (unaligned) + { + memcpy(aligned_row, row_ptr, sizeof(int8_t) * m_cols); + row_ptr = aligned_row; + } + + // Initialize the dot product sum for the row to 0. + int32x4_t dotprod = vmovq_n_s32(0); + + // Prefetch the row to cache. + __builtin_prefetch(row_ptr, 0 /* prefetch for read */, 3 /* temporal locality */); + + // For every block of 16 8-bit elements. + col = 0; + for (; col < postamble_start; col += kWeightsPerNeonLane) + { + // Load 16 8-bit values from the row and vector, each, to operate on. + // Here the assumption is that each buffer is 4-byte aligned. + assert(((uintptr_t)(&row_ptr[col]) & (kWeightsPerUint32 - 1)) == 0); + const int8x16_t s1_8x16 = vld1q_s8((const int8_t *)(aligned_vec + col)); + const int8x16_t s2_8x16 = vld1q_s8((const int8_t *)(row_ptr + col)); + // Multiply the low bits (i.e. the lower 8 8bit numbers in the + // registers). + int16x8_t prod_16x8 = vmull_s8(vget_low_s8(s1_8x16), vget_low_s8(s2_8x16)); + // Multiply the high bits (i.e. the lower 8 8bit numbers in the + // registers), and accumulate with the result of the low bits product. + // The assumption here is that overflow will not happen as we quantize + // our values to be in the range [-127, 127]. As such the sum of the 2 + // products is always strictly smaller than 15-bits (32767 in absolute + // value). + prod_16x8 = vmlal_s8(prod_16x8, vget_high_s8(s1_8x16), vget_high_s8(s2_8x16)); + + dotprod = vpadalq_s16(dotprod, prod_16x8); + } // for col + + int32_t postable_sum = 0; + // Postamble loop. + // TODO(raziel): if (ABSL_PREDICT_FALSE(postamble_start < m_rows)) + if (postamble_start < m_cols) + { + col = postamble_start; + if ((m_cols - postamble_start) >= (kWeightsPerNeonLane >> 1)) + { + // Load 8 8-bit values from the row and column each to operate on. + // Here the assumption is that each buffer is 4-bytes aligned. + assert(((uintptr_t)(&row_ptr[col]) & (kWeightsPerUint32 - 1)) == 0); + const int8x8_t s1_8x8 = vld1_s8((const int8_t *)(aligned_vec + col)); + const int8x8_t s2_8x8 = vld1_s8((const int8_t *)(row_ptr + col)); + const int16x8_t prod_16x8 = vmull_s8(s1_8x8, s2_8x8); + dotprod = vpadalq_s16(dotprod, prod_16x8); + col += (kWeightsPerNeonLane >> 1); + } + for (; col < m_cols; ++col) + { + postable_sum += row_ptr[col] * aligned_vec[col]; + } // for col + } + // Add the 4 intermediate sum values to get the final dot-prod value for + // this row. + int64x2_t pairwiseAdded = vpaddlq_s32(dotprod); + int32_t neon_sum = vgetq_lane_s64(pairwiseAdded, 0) + vgetq_lane_s64(pairwiseAdded, 1); + + *result += ((neon_sum + postable_sum) * batch_scaling_factor); + } // for row + } // for batch + + if (unaligned) + { + free(aligned_row_free); + } + free(aligned_vec_free); +} + +void NeonMatrixBatchVectorMultiplyAccumulate(const float *matrix, int m_rows, int m_cols, + const float *vector, int n_batch, float *result, + int result_stride) +{ + // If v_size is not divisible by kWeightsPerNeonLane, we cannot use the main + // vectorized loop, and we need to process sequentially. postamble_start shows + // the start index where this should happen. + const int postamble_start = m_cols - (m_cols & (kFloatWeightsPerNeonLane - 1)); + + for (int b = 0; b < n_batch; b++) + { + float *result_in_batch = result + b * m_rows * result_stride; + const float *vector_in_batch = vector + b * m_cols; + const float *matrix_row = matrix; + + // Main matrix by vector multiplication loop + for (int r = 0; r < m_rows; r++) + { + float32x4_t acc_32x4 = vmovq_n_f32(0.0); + for (int c = 0; c < postamble_start; c += kFloatWeightsPerNeonLane) + { + // Load 4 float values from vector and matrix row. + float32x4_t vector_f32x4 = vld1q_f32(vector_in_batch + c); + float32x4_t matrix_f32x4 = vld1q_f32(matrix_row + c); + // Multiply the vector and matrix row and add to accumulator. + acc_32x4 = vmlaq_f32(acc_32x4, matrix_f32x4, vector_f32x4); + } + // Add the 4 intermediate sum values to get the final dot-prod value for + // this column. + *result_in_batch += (vgetq_lane_f32(acc_32x4, 0) + vgetq_lane_f32(acc_32x4, 1) + + vgetq_lane_f32(acc_32x4, 2) + vgetq_lane_f32(acc_32x4, 3)); + for (int c = postamble_start; c < m_cols; c++) + { + *result_in_batch += matrix_row[c] * vector_in_batch[c]; + } + matrix_row += m_cols; + result_in_batch += result_stride; + } + } +} + +} // namespace cker +} // namespace nnfw + +#endif // USE_NEON + +#endif // __NNFW_CKER_NEON_TENSOR_UTILS_H__ diff --git a/compute/cker/include/cker/PortableTensorUtils.h b/compute/cker/include/cker/PortableTensorUtils.h new file mode 100644 index 00000000000..87b792e6e7c --- /dev/null +++ b/compute/cker/include/cker/PortableTensorUtils.h @@ -0,0 +1,167 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved + * Copyright 2017 The TensorFlow Authors. 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 __NNFW_CKER_PORTABLE_TENSOR_UTILS_H__ +#define __NNFW_CKER_PORTABLE_TENSOR_UTILS_H__ + +#include "cker/Types.h" +#include "cker/neon/neon_check.h" + +#include +#include + +namespace nnfw +{ +namespace cker +{ + +class ActivationFunctor +{ +public: + explicit ActivationFunctor(FusedActivationFunctionType act) : act_(act) {} + + float operator()(float a) const + { + switch (act_) + { + case FusedActivationFunctionType::kNone: + return a; + case FusedActivationFunctionType::kRelu: + return a < 0.f ? 0.f : a; + case FusedActivationFunctionType::kRelu6: + return std::max(0.f, std::min(a, 6.f)); + default: + // TODO(aselle): More informative fatal error! + exit(1); + } + } + +private: + FusedActivationFunctionType act_; +}; + +void PortableVectorBatchVectorAssign(const float *vector, int v_size, int n_batch, + float *batch_vector) +{ + for (int b = 0; b < n_batch; b++) + { + memcpy(batch_vector + b * v_size, vector, v_size * sizeof(float)); + } +} + +bool PortableIsZeroVector(const float *vector, int v_size) +{ + for (int i = 0; i < v_size; ++i) + { + if (*vector++ != 0.0f) + return false; + } + return true; +} + +void PortableApplyActivationToVector(const float *vector, int v_size, + FusedActivationFunctionType activation, float *result) +{ + auto activation_func = ActivationFunctor(activation); + for (int v = 0; v < v_size; v++) + { + *result++ = (activation_func)(*vector++); + } +} + +void PortableSymmetricQuantizeFloats(const float *values, const int size, int8_t *quantized_values, + float *min_value, float *max_value, float *scaling_factor) +{ + auto minmax = std::minmax_element(values, values + size); + *min_value = *minmax.first; + *max_value = *minmax.second; + const int kScale = 127; + const float range = std::max(std::abs(*min_value), std::abs(*max_value)); + if (range == 0) + { + memset(quantized_values, 0, size * sizeof(int8_t)); + *scaling_factor = 1; + return; + } + *scaling_factor = range / kScale; + const float scaling_factor_inv = kScale / range; + for (int i = 0; i < size; ++i) + { + const int32_t quantized_value = + static_cast(std::round(values[i] * scaling_factor_inv)); + // Clamp: just in case some odd numeric offset. + quantized_values[i] = std::min(kScale, std::max(-kScale, quantized_value)); + } +} + +void PortableMatrixBatchVectorMultiplyAccumulate(const int8_t *__restrict__ matrix, + const int m_rows, const int m_cols, + const int8_t *__restrict__ vectors, + const float *scaling_factors, int n_batch, + float *__restrict__ result, int result_stride) +{ + int batch, row, col; + for (batch = 0; batch < n_batch; ++batch, vectors += m_cols) + { + const float batch_scaling_factor = scaling_factors[batch]; + // Get the address of the first row. + const int8_t *row_ptr = matrix; + for (row = 0; row < m_rows; ++row, result += result_stride) + { + // Initialize the dot product sum for the row to 0. + int32_t dotprod = 0; +#if defined(__GNUC__) + // Prefetch the row to cache. + __builtin_prefetch(row_ptr, 0 /* prefetch for read */, 3 /* temporal locality */); +#endif + for (col = 0; col < m_cols; ++col, ++row_ptr) + { + dotprod += (*row_ptr) * (vectors[col]); + } // for col + *result += (dotprod * batch_scaling_factor); + } // for row + } // for batch +} + +void PortableMatrixBatchVectorMultiplyAccumulate(const float *matrix, int m_rows, int m_cols, + const float *vector, int n_batch, float *result, + int result_stride) +{ + float *result_in_batch = result; + for (int b = 0; b < n_batch; b++) + { + const float *matrix_ptr = matrix; + for (int r = 0; r < m_rows; r++) + { + float dot_prod = 0.0f; + const float *vector_in_batch = vector + b * m_cols; + for (int c = 0; c < m_cols; c++) + { + dot_prod += *matrix_ptr++ * *vector_in_batch++; + } + *result_in_batch += dot_prod; + result_in_batch += result_stride; + } + } +} + +void PortableZeroVector(float *vector, int v_size) { std::fill_n(vector, v_size, 0); } + +} // namespace cker +} // namespace nnfw + +#endif // __NNFW_CKER_PORTABLE_TENSOR_UTILS_H__ diff --git a/compute/cker/include/cker/TensorUtils.h b/compute/cker/include/cker/TensorUtils.h index e1eed81c043..6c5bacb8e0c 100644 --- a/compute/cker/include/cker/TensorUtils.h +++ b/compute/cker/include/cker/TensorUtils.h @@ -19,77 +19,26 @@ #define __NNFW_CKER_TENSOR_UTILS_H__ #include "cker/Types.h" +#include "cker/PortableTensorUtils.h" +#include "cker/NeonTensorUtils.h" +#include "cker/neon/neon_check.h" #include #include -// TODO Introduce neon & portable tensor utils -// Current implementation uses portable tensor utils only - namespace nnfw { namespace cker { -class ActivationFunctor -{ -public: - explicit ActivationFunctor(FusedActivationFunctionType act) : act_(act) {} - - float operator()(float a) const - { - switch (act_) - { - case FusedActivationFunctionType::kNone: - return a; - case FusedActivationFunctionType::kRelu: - return a < 0.f ? 0.f : a; - case FusedActivationFunctionType::kRelu6: - return std::max(0.f, std::min(a, 6.f)); - default: - // TODO(aselle): More informative fatal error! - exit(1); - } - } - -private: - FusedActivationFunctionType act_; -}; - -void PortableVectorBatchVectorAssign(const float *vector, int v_size, int n_batch, - float *batch_vector) -{ - for (int b = 0; b < n_batch; b++) - { - memcpy(batch_vector + b * v_size, vector, v_size * sizeof(float)); - } -} - void VectorBatchVectorAssign(const float *vector, int v_size, int n_batch, float *batch_vector) { PortableVectorBatchVectorAssign(vector, v_size, n_batch, batch_vector); } -bool PortableIsZeroVector(const float *vector, int v_size) -{ - for (int i = 0; i < v_size; ++i) - { - if (*vector++ != 0.0f) - return false; - } - return true; -} - -bool IsZeroVector(const float *vector, int v_size) { return PortableIsZeroVector(vector, v_size); } - -void PortableApplyActivationToVector(const float *vector, int v_size, - FusedActivationFunctionType activation, float *result) +bool IsZeroVector(const float *vector, int v_size) { - auto activation_func = ActivationFunctor(activation); - for (int v = 0; v < v_size; v++) - { - *result++ = (activation_func)(*vector++); - } + return NEON_OR_PORTABLE(IsZeroVector, vector, v_size); } void ApplyActivationToVector(const float *vector, int v_size, @@ -98,74 +47,31 @@ void ApplyActivationToVector(const float *vector, int v_size, PortableApplyActivationToVector(vector, v_size, activation, result); } -void PortableSymmetricQuantizeFloats(const float *values, const int size, int8_t *quantized_values, - float *min_value, float *max_value, float *scaling_factor) -{ - auto minmax = std::minmax_element(values, values + size); - *min_value = *minmax.first; - *max_value = *minmax.second; - const int kScale = 127; - const float range = std::max(std::abs(*min_value), std::abs(*max_value)); - if (range == 0) - { - memset(quantized_values, 0, size * sizeof(int8_t)); - *scaling_factor = 1; - return; - } - *scaling_factor = range / kScale; - const float scaling_factor_inv = kScale / range; - for (int i = 0; i < size; ++i) - { - const int32_t quantized_value = - static_cast(std::round(values[i] * scaling_factor_inv)); - // Clamp: just in case some odd numeric offset. - quantized_values[i] = std::min(kScale, std::max(-kScale, quantized_value)); - } -} - void SymmetricQuantizeFloats(const float *values, const int size, int8_t *quantized_values, float *min, float *max, float *scaling_factor) { - return PortableSymmetricQuantizeFloats(values, size, quantized_values, min, max, scaling_factor); -} - -void PortableMatrixBatchVectorMultiplyAccumulate(const int8_t *__restrict__ matrix, - const int m_rows, const int m_cols, - const int8_t *__restrict__ vectors, - const float *scaling_factors, int n_batch, - float *__restrict__ result, int result_stride) -{ - int batch, row, col; - for (batch = 0; batch < n_batch; ++batch, vectors += m_cols) - { - const float batch_scaling_factor = scaling_factors[batch]; - // Get the address of the first row. - const int8_t *row_ptr = matrix; - for (row = 0; row < m_rows; ++row, result += result_stride) - { - // Initialize the dot product sum for the row to 0. - int32_t dotprod = 0; -#if defined(__GNUC__) - // Prefetch the row to cache. - __builtin_prefetch(row_ptr, 0 /* prefetch for read */, 3 /* temporal locality */); -#endif - for (col = 0; col < m_cols; ++col, ++row_ptr) - { - dotprod += (*row_ptr) * (vectors[col]); - } // for col - *result += (dotprod * batch_scaling_factor); - } // for row - } // for batch + return NEON_OR_PORTABLE(SymmetricQuantizeFloats, values, size, quantized_values, min, max, + scaling_factor); } void MatrixBatchVectorMultiplyAccumulate(const int8_t *matrix, const int m_rows, const int m_cols, const int8_t *vector, const float *scaling_factors, int n_batch, float *result, int result_stride) { - PortableMatrixBatchVectorMultiplyAccumulate(matrix, m_rows, m_cols, vector, scaling_factors, - n_batch, result, result_stride); + NEON_OR_PORTABLE(MatrixBatchVectorMultiplyAccumulate, matrix, m_rows, m_cols, vector, + scaling_factors, n_batch, result, result_stride); } +void MatrixBatchVectorMultiplyAccumulate(const float *matrix, int m_rows, int m_cols, + const float *vector, int n_batch, float *result, + int result_stride) +{ + NEON_OR_PORTABLE(MatrixBatchVectorMultiplyAccumulate, matrix, m_rows, m_cols, vector, n_batch, + result, result_stride); +} + +void ZeroVector(float *vector, int v_size) { PortableZeroVector(vector, v_size); } + } // namespace cker } // namespace nnfw diff --git a/compute/cker/include/cker/Types.h b/compute/cker/include/cker/Types.h index 9ec5c819e17..3c3396abee6 100644 --- a/compute/cker/include/cker/Types.h +++ b/compute/cker/include/cker/Types.h @@ -221,7 +221,7 @@ struct DepthwiseConvParams struct FullyConnectedParams { - FusedActivationFunctionType activation; + FusedActivationFunctionType activation{FusedActivationFunctionType::kNone}; // uint8 inference params. // TODO(b/65838351): Use smaller types if appropriate. int32_t input_offset; @@ -283,6 +283,28 @@ struct SliceParams int32_t size[4]; }; +struct StridedSliceParams +{ + int8_t start_indices_count; + int16_t start_indices[4]; + int8_t stop_indices_count; + int16_t stop_indices[4]; + int8_t strides_count; + int16_t strides[4]; + + int16_t begin_mask; + int16_t ellipsis_mask; + int16_t end_mask; + int16_t new_axis_mask; + int16_t shrink_axis_mask; +}; + +struct SplitParams +{ + uint16_t num_split; + int16_t axis; +}; + } // namespace cker } // namespace nnfw diff --git a/compute/cker/include/cker/Utils.h b/compute/cker/include/cker/Utils.h index 83c2747c6f7..17ef3c374b0 100644 --- a/compute/cker/include/cker/Utils.h +++ b/compute/cker/include/cker/Utils.h @@ -18,11 +18,11 @@ #ifndef __NNFW_CKER_UTILS_H__ #define __NNFW_CKER_UTILS_H__ +#include "Shape.h" + #include #include - -#include "cker/gemmlowp/FixedPoint.h" -#include "Shape.h" +#include namespace nnfw { diff --git a/compute/cker/include/cker/eigen/eigen_spatial_convolutions-inl.h b/compute/cker/include/cker/eigen/eigen_spatial_convolutions-inl.h index 00ed64c2060..6536c6f3e14 100644 --- a/compute/cker/include/cker/eigen/eigen_spatial_convolutions-inl.h +++ b/compute/cker/include/cker/eigen/eigen_spatial_convolutions-inl.h @@ -1245,6 +1245,9 @@ struct gemm_pack_rhs< eigen_assert(stride == 0); eigen_assert(offset == 0); + (void)stride; + (void)offset; + const int packet_size = 2; const Index packet_cols4 = (cols / 4) * 4; const Index peeled_k = (depth / packet_size) * packet_size; @@ -1465,6 +1468,9 @@ struct gemm_pack_rhs< eigen_assert(stride == 0); eigen_assert(offset == 0); + (void)offset; + (void)stride; + const Index packet_cols4 = (cols / 4) * 4; for (Index j2 = 0; j2 < packet_cols4; j2 += 4) diff --git a/compute/cker/include/cker/gemmlowp/FixedPoint.h b/compute/cker/include/cker/gemmlowp/FixedPoint.h deleted file mode 100644 index 159e01a221b..00000000000 --- a/compute/cker/include/cker/gemmlowp/FixedPoint.h +++ /dev/null @@ -1,289 +0,0 @@ -/* - * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved - * Copyright 2015 The Gemmlowp Authors. 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 __NNFW_CKER_GEMMLOWP_FIXED_POINT_H__ -#define __NNFW_CKER_GEMMLOWP_FIXED_POINT_H__ - -#include -#include - -namespace nnfw -{ -namespace cker -{ -namespace gemmlowp -{ - -inline int32_t RoundingHalfSum(int32_t a, int32_t b) -{ - int64_t a64 = a; - int64_t b64 = b; - int64_t sum = a64 + b64; - int64_t sign = sum >= 0 ? 1 : -1; - return static_cast((sum + sign) / 2); -} - -inline int32_t SaturatingRoundingDoublingHighMul(int32_t a, int32_t b) -{ - bool overflow = a == b && a == std::numeric_limits::min(); - int64_t a_64(a); - int64_t b_64(b); - int64_t ab_64 = a_64 * b_64; - int32_t nudge = ab_64 >= 0 ? (1 << 30) : (1 - (1 << 30)); - int32_t ab_x2_high32 = static_cast((ab_64 + nudge) / (1ll << 31)); - return overflow ? std::numeric_limits::max() : ab_x2_high32; -} - -// Correctly-rounded-to-nearest division by a power-of-two. -// Also known as a rounding arithmetic right shift. -inline int32_t RoundingDivideByPOT(int32_t x, int exponent) -{ - assert(exponent >= 0); - assert(exponent <= 31); - const int32_t mask = ((1ll << exponent) - 1); - const int32_t zero = 0; - const int32_t one = 1; - const int32_t remainder = x & mask; - const int32_t threshold = (mask >> 1) + ((x < zero) ? one : zero); - return ((x >> exponent) + ((remainder > threshold) ? one : zero)); -} - -// Returns the product of a run-time integer value by a compile-time power -// of two, with either a positive exponent (equivalent to an arithmetic -// left shift, saturating) or a negative exponent (equivalent to an arithmetic -// right shift, rounding to nearest). -template 0 ? 1 : Exponent < 0 ? -1 : 0)> -struct ImplSaturatingRoundingMultiplyByPOT -{ -}; - -template struct ImplSaturatingRoundingMultiplyByPOT -{ - static int32_t eval(int32_t x) { return x; } -}; - -template struct ImplSaturatingRoundingMultiplyByPOT -{ - static int32_t eval(int32_t x) - { - const int32_t min = (std::numeric_limits::min()); - const int32_t max = (std::numeric_limits::max()); - const int32_t threshold = ((1 << (31 - Exponent)) - 1); - const int32_t zero = 0; - const int32_t one = 1; - - const int32_t positive_mask = ((x > threshold) ? ~zero : zero); - const int32_t negative_mask = ((x < -threshold) ? ~zero : zero); - - int32_t result = (x * (one << Exponent)); - result = (positive_mask ? max : result); - result = (negative_mask ? min : result); - return result; - } -}; - -template struct ImplSaturatingRoundingMultiplyByPOT -{ - static int32_t eval(int32_t x) { return RoundingDivideByPOT(x, -Exponent); } -}; - -template int32_t SaturatingRoundingMultiplyByPOT(int32_t x) -{ - return ImplSaturatingRoundingMultiplyByPOT::eval(x); -} - -template class FixedPoint -{ -public: - static constexpr int kTotalBits = 8 * sizeof(int32_t); - static constexpr int kIntegerBits = tIntegerBits; - static constexpr int kFractionalBits = kTotalBits - 1 - kIntegerBits; - static_assert(kIntegerBits >= 0 && kIntegerBits < kTotalBits, "bad IntegerBits"); - - static int32_t ScalarRawMax() { return std::numeric_limits::max(); } - - static FixedPoint FromRaw(int32_t x) - { - FixedPoint retval; - retval.raw() = x; - return retval; - } - - static FixedPoint FromScalarRaw(int32_t x) { return FromRaw(x); } - - template static FixedPoint ConstantPOT() - { - static constexpr int kOffset = kFractionalBits + Exponent; - static_assert(kOffset < 31, "Constant not exactly representable in this fixed-point format"); - return FromScalarRaw((int32_t)1 << kOffset); - } - - static FixedPoint Zero() { return FromScalarRaw(0); } - - static FixedPoint One() - { - return FromScalarRaw(kIntegerBits == 0 ? ScalarRawMax() : ((int32_t)1 << kFractionalBits)); - } - - int32_t raw() const { return i_; } - int32_t &raw() { return i_; } - -private: - int32_t i_; -}; - -// A FixedPoint multiplication is just a -// SaturatingRoundingDoublingHighMul operation on the underlying -// raw integer values. The IntegerBits simply add up, as is obvious -// from the fact that the range is [-2^IntegerBits, 2^IntegerBits). -template -FixedPoint operator*(FixedPoint a, - FixedPoint b) -{ - FixedPoint c; - c.raw() = SaturatingRoundingDoublingHighMul(a.raw(), b.raw()); - return c; -} - -// Tweaking IntegerBits gives exact multiplication by a power of two. -template -FixedPoint ExactMulByPot(FixedPoint a) -{ - FixedPoint c; - c.raw() = a.raw(); - return c; -} - -template -FixedPoint operator+(FixedPoint a, FixedPoint b) -{ - return FixedPoint::FromRaw((a.raw() + b.raw())); -} -template -FixedPoint operator-(FixedPoint a, FixedPoint b) -{ - return FixedPoint::FromRaw((a.raw() - b.raw())); -} -template -FixedPoint operator&(FixedPoint a, FixedPoint b) -{ - return FixedPoint::FromRaw((a.raw() & b.raw())); -} - -// Rescale changes the number of IntegerBits and updates the underlying -// raw integer value accordingly. -template -FixedPoint Rescale(FixedPoint x) -{ - static constexpr int kExponent = tIntegerBitsSrc - tIntegerBitsDst; - FixedPoint result; - result.raw() = SaturatingRoundingMultiplyByPOT(x.raw()); - return result; -} - -// Implementation of exponential function. - -// Returns exp(x) for x in [-1/4, 0). -inline FixedPoint<0> exp_on_interval_between_negative_one_quarter_and_0_excl(FixedPoint<0> a) -{ - typedef FixedPoint<0> F; - const F constant_term = F::FromScalarRaw(RoundingDivideByPOT(1895147668, 0)); - const F constant_1_over_3 = F::FromScalarRaw(RoundingDivideByPOT(715827883, 0)); - // We're evaluating a Taylor expansion around -1/8, so we do the change of - // variable: x = a + 1/8. - // In fixed-point with 0 integer bits, 1/8 is represented by 1 << 28. - F x = a + F::template ConstantPOT<-3>(); - F x2 = x * x; - F x3 = x2 * x; - F x4 = x2 * x2; - F x4_over_4 = F::FromScalarRaw(SaturatingRoundingMultiplyByPOT<-2>(x4.raw())); - F x4_over_24_plus_x3_over_6_plus_x2_over_2 = F::FromScalarRaw( - SaturatingRoundingMultiplyByPOT<-1>((((x4_over_4 + x3) * constant_1_over_3) + x2).raw())); - return (constant_term + constant_term * (x + x4_over_24_plus_x3_over_6_plus_x2_over_2)); -} - -// Returns exp(x) for x < 0. -template FixedPoint<0> exp_on_negative_values(FixedPoint a) -{ - typedef FixedPoint InputF; - typedef FixedPoint<0> ResultF; - static constexpr int kFractionalBits = InputF::kFractionalBits; - static constexpr int kIntegerBits = InputF::kIntegerBits; - const InputF kOneQuarter = InputF::template ConstantPOT<-2>(); - InputF mask = kOneQuarter - InputF::FromScalarRaw(1); - InputF a_mod_quarter_minus_one_quarter = (a & mask) - kOneQuarter; - ResultF result = exp_on_interval_between_negative_one_quarter_and_0_excl( - Rescale<0>(a_mod_quarter_minus_one_quarter)); - int32_t remainder = (a_mod_quarter_minus_one_quarter - a).raw(); - -#define GEMMLOWP_EXP_BARREL_SHIFTER(Exponent, FixedPointMultiplier) \ - if (kIntegerBits > Exponent) \ - { \ - const ResultF kMultiplier = \ - ResultF::FromScalarRaw(RoundingDivideByPOT(FixedPointMultiplier, 0)); \ - static constexpr int kShiftAmount = \ - ((kIntegerBits > Exponent) ? (kFractionalBits + Exponent) : 0); \ - result = ((remainder & (1 << kShiftAmount)) ? (result * kMultiplier) : result); \ - } - - GEMMLOWP_EXP_BARREL_SHIFTER(-2, 1672461947); - GEMMLOWP_EXP_BARREL_SHIFTER(-1, 1302514674); - GEMMLOWP_EXP_BARREL_SHIFTER(+0, 790015084); - GEMMLOWP_EXP_BARREL_SHIFTER(+1, 290630308); - GEMMLOWP_EXP_BARREL_SHIFTER(+2, 39332535); - GEMMLOWP_EXP_BARREL_SHIFTER(+3, 720401); - GEMMLOWP_EXP_BARREL_SHIFTER(+4, 242); - -#undef GEMMLOWP_EXP_BARREL_SHIFTER - - static constexpr int clampB = ((kIntegerBits > 5) ? (36 - kIntegerBits) : 0); - if (kIntegerBits > 5) - { - const InputF clamp = InputF::FromScalarRaw(RoundingDivideByPOT(-(1 << clampB), 0)); - result.raw() = ((a.raw() < clamp.raw()) ? ResultF::Zero().raw() : result.raw()); - } - - result.raw() = (a.raw() ? result.raw() : ResultF::One().raw()); - return result; -} - -// Returns 1 / (1 + x) for x in (0, 1). -inline FixedPoint<0> one_over_one_plus_x_for_x_in_0_1(FixedPoint<0> a) -{ - typedef FixedPoint<0> F0; - typedef FixedPoint<2> F2; - F0 half_denominator = F0::FromScalarRaw(RoundingHalfSum(a.raw(), F0::One().raw())); - // Newton-Raphson division - // https://en.wikipedia.org/wiki/Division_algorithm#Newton.E2.80.93Raphson_division - // Refer to that page for the logic behind the 48/17 and 32/17 constants. - const F2 constant_48_over_17 = F2::FromScalarRaw(RoundingDivideByPOT(1515870810, 0)); - const F2 constant_neg_32_over_17 = F2::FromScalarRaw(RoundingDivideByPOT(-1010580540, 0)); - F2 x = constant_48_over_17 + half_denominator * constant_neg_32_over_17; - for (int i = 0; i < 3; i++) - { - F2 half_denominator_times_x = half_denominator * x; - F2 one_minus_half_denominator_times_x = F2::One() - half_denominator_times_x; - x = x + Rescale<2>(x * one_minus_half_denominator_times_x); - } - return Rescale<0>(ExactMulByPot<-1>(x)); -} - -} // namespace gemmlowp -} // namespace cker -} // namespace nnfw - -#endif // __NNFW_CKER_GEMMLOWP_FIXED_POINT_H__ diff --git a/compute/cker/include/cker/gemmlowp/GEMMSupport.h b/compute/cker/include/cker/gemmlowp/GEMMSupport.h new file mode 100644 index 00000000000..76486eded37 --- /dev/null +++ b/compute/cker/include/cker/gemmlowp/GEMMSupport.h @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved + * Copyright 2017 The TensorFlow Authors. 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 __NNFW_CKER_GEMMLOWP_GEMM_SUPPORT_H__ +#define __NNFW_CKER_GEMMLOWP_GEMM_SUPPORT_H__ + +#include + +#include +#include + +namespace nnfw +{ +namespace cker +{ +namespace gemm_support +{ + +struct GemmContext +{ + std::unique_ptr gemm_context; + constexpr static int default_num_threadpool_threads = 4; + + GemmContext() + { + int num_threads = std::thread::hardware_concurrency() / 2; + if (num_threads == 0) + { + num_threads = default_num_threadpool_threads; + } + + gemm_context.reset(new gemmlowp::GemmContext()); + gemm_context->set_max_num_threads(num_threads); + } + + static inline GemmContext &GetGemmLowpContext() + { + static GemmContext instance; + return instance; + } +}; + +inline gemmlowp::GemmContext *GetGemmLowpContext() +{ + auto &ctx = GemmContext::GetGemmLowpContext(); + return ctx.gemm_context.get(); +} + +} // namespace gemm_support +} // namespace cker +} // namespace nnfw + +#endif // __NNFW_CKER_GEMMLOWP_GEMM_SUPPORT_H__ diff --git a/compute/cker/include/cker/operation/AveragePool.h b/compute/cker/include/cker/operation/AveragePool.h index 90470384e5f..de43ba3bd67 100644 --- a/compute/cker/include/cker/operation/AveragePool.h +++ b/compute/cker/include/cker/operation/AveragePool.h @@ -18,10 +18,12 @@ #ifndef __NNFW_CKER_AVERAGE_POOL_H__ #define __NNFW_CKER_AVERAGE_POOL_H__ +#include "cker/neon/neon_check.h" #include "cker/eigen/Utils.h" #include "cker/Shape.h" #include "cker/Types.h" #include "cker/Utils.h" + #include namespace nnfw @@ -92,9 +94,17 @@ inline void AveragePool(const PoolParams ¶ms, const Shape &input_shape, cons } } -inline void AveragePool(const PoolParams ¶ms, const Shape &input_shape, - const uint8_t *input_data, const Shape &output_shape, uint8_t *output_data) +inline void AveragePool16(const PoolParams ¶ms, const Shape &input_shape, + const uint8_t *input_data, const Shape &output_shape, + uint8_t *output_data) { + // Here, and in other pooling ops, in order to maintain locality of reference, + // to minimize some recalculations, and to load into NEON vector registers, we + // use an inner loop down the depth. Since depths can be large and hence we + // would need arbitrarily large temporary storage, we divide the work up into + // depth tranches just within the batch loop. + static constexpr int kPoolingAccTrancheSize = 256; + assert(params.quantized_activation_min <= params.quantized_activation_max); assert(input_shape.DimensionsCount() == 4); assert(output_shape.DimensionsCount() == 4); @@ -106,48 +116,274 @@ inline void AveragePool(const PoolParams ¶ms, const Shape &input_shape, const int output_width = output_shape.Dims(2); const int stride_height = params.stride_height; const int stride_width = params.stride_width; + + uint16_t acc[kPoolingAccTrancheSize]; for (int batch = 0; batch < batches; ++batch) { - for (int out_y = 0; out_y < output_height; ++out_y) + // We proceed through the depth in tranches (see comment above). The + // depth_base is the depth at the beginning of the tranche. The + // tranche_depth is the depth dimension of the tranche. + for (int depth_base = 0; depth_base < depth; depth_base += kPoolingAccTrancheSize) { - for (int out_x = 0; out_x < output_width; ++out_x) + const int tranche_depth = std::min(depth - depth_base, kPoolingAccTrancheSize); + for (int out_y = 0; out_y < output_height; ++out_y) { - const int in_x_origin = (out_x * stride_width) - params.padding_values.width; - const int in_y_origin = (out_y * stride_height) - params.padding_values.height; - // Compute the boundaries of the filter region clamped so as to - // ensure that the filter window fits in the input array. - const int filter_x_start = std::max(0, -in_x_origin); - const int filter_x_end = std::min(params.filter_width, input_width - in_x_origin); - const int filter_y_start = std::max(0, -in_y_origin); - const int filter_y_end = std::min(params.filter_height, input_height - in_y_origin); - int filter_count = (filter_y_end - filter_y_start) * (filter_x_end - filter_x_start); - if (filter_count <= 0) + for (int out_x = 0; out_x < output_width; ++out_x) { - continue; + const int in_x_origin = (out_x * stride_width) - params.padding_values.width; + const int in_y_origin = (out_y * stride_height) - params.padding_values.height; + const int filter_x_start = std::max(0, -in_x_origin); + const int filter_x_end = std::min(params.filter_width, input_width - in_x_origin); + const int filter_y_start = std::max(0, -in_y_origin); + const int filter_y_end = std::min(params.filter_height, input_height - in_y_origin); + const int filter_count = + (filter_x_end - filter_x_start) * (filter_y_end - filter_y_start); + memset(acc, 0, tranche_depth * sizeof(acc[0])); + const uint8_t *input_ptr = + input_data + depth_base + + depth * (in_x_origin + input_width * (in_y_origin + input_height * batch)); + for (int fy = filter_y_start; fy < filter_y_end; fy++) + { + const uint8_t *input_row_ptr = input_ptr + depth * (fy * input_width + filter_x_start); + for (int fx = filter_x_start; fx < filter_x_end; fx++) + { + const uint8_t *input_channel_ptr = input_row_ptr; + int channel = 0; +#ifdef USE_NEON + for (; channel <= tranche_depth - 16; channel += 16) + { + uint16x8_t acc_reg[2]; + for (int i = 0; i < 2; i++) + { + acc_reg[i] = vld1q_u16(acc + channel + 8 * i); + } + uint8x16_t input_reg = vld1q_u8(input_channel_ptr); + input_channel_ptr += 16; + acc_reg[0] = vaddw_u8(acc_reg[0], vget_low_u8(input_reg)); + acc_reg[1] = vaddw_u8(acc_reg[1], vget_high_u8(input_reg)); + for (int i = 0; i < 2; i++) + { + vst1q_u16(acc + channel + 8 * i, acc_reg[i]); + } + } + for (; channel <= tranche_depth - 8; channel += 8) + { + uint16x8_t acc_reg = vld1q_u16(acc + channel); + uint8x8_t input_reg = vld1_u8(input_channel_ptr); + input_channel_ptr += 8; + acc_reg = vaddw_u8(acc_reg, input_reg); + vst1q_u16(acc + channel, acc_reg); + } +#endif + for (; channel < tranche_depth; ++channel) + { + acc[channel] += *input_channel_ptr++; + } + input_row_ptr += depth; + } + } + uint8_t *output_ptr = output_data + Offset(output_shape, batch, out_y, out_x, depth_base); + int channel = 0; +#ifdef USE_NEON +#define AVGPOOL_DIVIDING_BY(FILTER_COUNT) \ + if (filter_count == FILTER_COUNT) \ + { \ + for (; channel <= tranche_depth - 8; channel += 8) \ + { \ + uint16_t buf[8]; \ + for (int i = 0; i < 8; i++) \ + { \ + buf[i] = (acc[channel + i] + FILTER_COUNT / 2) / FILTER_COUNT; \ + } \ + uint8x8_t buf8 = vqmovn_u16(vld1q_u16(buf)); \ + buf8 = vmin_u8(buf8, vdup_n_u8(params.quantized_activation_max)); \ + buf8 = vmax_u8(buf8, vdup_n_u8(params.quantized_activation_min)); \ + vst1_u8(output_ptr + channel, buf8); \ + } \ + } + AVGPOOL_DIVIDING_BY(9) + AVGPOOL_DIVIDING_BY(15) +#undef AVGPOOL_DIVIDING_BY + for (; channel <= tranche_depth - 8; channel += 8) + { + uint16_t buf[8]; + for (int i = 0; i < 8; i++) + { + buf[i] = (acc[channel + i] + filter_count / 2) / filter_count; + } + uint8x8_t buf8 = vqmovn_u16(vld1q_u16(buf)); + buf8 = vmin_u8(buf8, vdup_n_u8(params.quantized_activation_max)); + buf8 = vmax_u8(buf8, vdup_n_u8(params.quantized_activation_min)); + vst1_u8(output_ptr + channel, buf8); + } +#endif + for (; channel < tranche_depth; ++channel) + { + uint8_t a = (acc[channel] + filter_count / 2) / filter_count; + a = std::max(a, params.quantized_activation_min); + a = std::min(a, params.quantized_activation_max); + output_ptr[channel] = static_cast(a); + } } - for (int channel = 0; channel < depth; ++channel) + } + } + } +} + +inline void AveragePool32(const PoolParams ¶ms, const Shape &input_shape, + const uint8_t *input_data, const Shape &output_shape, + uint8_t *output_data) +{ + + // Here, and in other pooling ops, in order to maintain locality of reference, + // to minimize some recalculations, and to load into NEON vector registers, we + // use an inner loop down the depth. Since depths can be large and hence we + // would need arbitrarily large temporary storage, we divide the work up into + // depth tranches just within the batch loop. + static constexpr int kPoolingAccTrancheSize = 256; + + assert(params.quantized_activation_min <= params.quantized_activation_max); + assert(input_shape.DimensionsCount() == 4); + assert(output_shape.DimensionsCount() == 4); + const int batches = MatchingDim(input_shape, 0, output_shape, 0); + const int depth = MatchingDim(input_shape, 3, output_shape, 3); + const int input_height = input_shape.Dims(1); + const int input_width = input_shape.Dims(2); + const int output_height = output_shape.Dims(1); + const int output_width = output_shape.Dims(2); + const int stride_height = params.stride_height; + const int stride_width = params.stride_width; + + uint32_t acc[kPoolingAccTrancheSize]; + for (int batch = 0; batch < batches; ++batch) + { + // We proceed through the depth in tranches (see comment above). The + // depth_base is the depth at the beginning of the tranche. The + // tranche_depth is the depth dimension of the tranche. + for (int depth_base = 0; depth_base < depth; depth_base += kPoolingAccTrancheSize) + { + const int tranche_depth = std::min(depth - depth_base, kPoolingAccTrancheSize); + for (int out_y = 0; out_y < output_height; ++out_y) + { + for (int out_x = 0; out_x < output_width; ++out_x) { - int32_t acc = 0; - for (int filter_y = filter_y_start; filter_y < filter_y_end; ++filter_y) + const int in_x_origin = (out_x * stride_width) - params.padding_values.width; + const int in_y_origin = (out_y * stride_height) - params.padding_values.height; + const int filter_x_start = std::max(0, -in_x_origin); + const int filter_x_end = std::min(params.filter_width, input_width - in_x_origin); + const int filter_y_start = std::max(0, -in_y_origin); + const int filter_y_end = std::min(params.filter_height, input_height - in_y_origin); + const int filter_count = + (filter_x_end - filter_x_start) * (filter_y_end - filter_y_start); + memset(acc, 0, tranche_depth * sizeof(acc[0])); + const uint8_t *input_ptr = + input_data + depth_base + + depth * (in_x_origin + input_width * (in_y_origin + input_height * batch)); + for (int fy = filter_y_start; fy < filter_y_end; fy++) + { + const uint8_t *input_row_ptr = input_ptr + depth * (fy * input_width + filter_x_start); + for (int fx = filter_x_start; fx < filter_x_end; fx++) + { + const uint8_t *input_channel_ptr = input_row_ptr; + int channel = 0; +#ifdef USE_NEON + for (; channel <= tranche_depth - 16; channel += 16) + { + uint16x4_t acc_reg[4]; + uint8x16_t input_reg = vld1q_u8(input_channel_ptr); + input_channel_ptr += 16; + acc_reg[0] = vget_low_u16(vmovl_u8(vget_low_u8(input_reg))); + acc_reg[1] = vget_high_u16(vmovl_u8(vget_low_u8(input_reg))); + acc_reg[2] = vget_low_u16(vmovl_u8(vget_high_u8(input_reg))); + acc_reg[3] = vget_high_u16(vmovl_u8(vget_high_u8(input_reg))); + for (int i = 0; i < 4; i++) + { + vst1q_u32(acc + channel + 4 * i, + vaddw_u16(vld1q_u32(acc + channel + 4 * i), acc_reg[i])); + } + } + for (; channel <= tranche_depth - 8; channel += 8) + { + uint16x4_t acc_reg[2]; + uint16x8_t input_reg = vmovl_u8(vld1_u8(input_channel_ptr)); + input_channel_ptr += 8; + acc_reg[0] = vget_low_u16(input_reg); + acc_reg[1] = vget_high_u16(input_reg); + for (int i = 0; i < 2; i++) + { + vst1q_u32(acc + channel + 4 * i, + vaddw_u16(vld1q_u32(acc + channel + 4 * i), acc_reg[i])); + } + } +#endif + for (; channel < tranche_depth; ++channel) + { + acc[channel] += *input_channel_ptr++; + } + input_row_ptr += depth; + } + } + uint8_t *output_ptr = output_data + Offset(output_shape, batch, out_y, out_x, depth_base); + int channel = 0; +#ifdef USE_NEON +#define AVGPOOL_DIVIDING_BY(FILTER_COUNT) \ + if (filter_count == FILTER_COUNT) \ + { \ + for (; channel <= tranche_depth - 8; channel += 8) \ + { \ + uint16_t buf[8]; \ + for (int i = 0; i < 8; i++) \ + { \ + buf[i] = (acc[channel + i] + FILTER_COUNT / 2) / FILTER_COUNT; \ + } \ + uint8x8_t buf8 = vqmovn_u16(vld1q_u16(buf)); \ + buf8 = vmin_u8(buf8, vdup_n_u8(params.quantized_activation_max)); \ + buf8 = vmax_u8(buf8, vdup_n_u8(params.quantized_activation_min)); \ + vst1_u8(output_ptr + channel, buf8); \ + } \ + } + AVGPOOL_DIVIDING_BY(9) + AVGPOOL_DIVIDING_BY(15) +#undef AVGPOOL_DIVIDING_BY + for (; channel <= tranche_depth - 8; channel += 8) { - for (int filter_x = filter_x_start; filter_x < filter_x_end; ++filter_x) + uint16_t buf[8]; + for (int i = 0; i < 8; i++) { - const int in_x = in_x_origin + filter_x; - const int in_y = in_y_origin + filter_y; - acc += input_data[Offset(input_shape, batch, in_y, in_x, channel)]; + buf[i] = (acc[channel + i] + filter_count / 2) / filter_count; } + uint8x8_t buf8 = vqmovn_u16(vld1q_u16(buf)); + buf8 = vmin_u8(buf8, vdup_n_u8(params.quantized_activation_max)); + buf8 = vmax_u8(buf8, vdup_n_u8(params.quantized_activation_min)); + vst1_u8(output_ptr + channel, buf8); + } +#endif + for (; channel < tranche_depth; ++channel) + { + uint16_t a = (acc[channel] + filter_count / 2) / filter_count; + a = std::max(a, params.quantized_activation_min); + a = std::min(a, params.quantized_activation_max); + output_ptr[channel] = static_cast(a); } - acc = (acc + filter_count / 2) / filter_count; - acc = std::max(acc, params.quantized_activation_min); - acc = std::min(acc, params.quantized_activation_max); - output_data[Offset(output_shape, batch, out_y, out_x, channel)] = - static_cast(acc); } } } } } +inline void AveragePool(const PoolParams ¶ms, const Shape &input_shape, + const uint8_t *input_data, const Shape &output_shape, uint8_t *output_data) +{ + if (params.filter_height * params.filter_width > 16 * 16) + { + AveragePool32(params, input_shape, input_data, output_shape, output_data); + } + else + { + AveragePool16(params, input_shape, input_data, output_shape, output_data); + } +} + } // namespace cker } // namespace nnfw diff --git a/compute/cker/include/cker/operation/Concatenation.h b/compute/cker/include/cker/operation/Concatenation.h index 8fa6317cf82..394123e30c9 100644 --- a/compute/cker/include/cker/operation/Concatenation.h +++ b/compute/cker/include/cker/operation/Concatenation.h @@ -18,11 +18,12 @@ #ifndef __NNFW_CKER_CONCATENATION_H__ #define __NNFW_CKER_CONCATENATION_H__ -#include - #include "cker/Shape.h" #include "cker/Types.h" +#include +#include + namespace nnfw { namespace cker @@ -78,6 +79,78 @@ inline void Concatenation(const ConcatenationParams ¶ms, const Shape *const } } +// quantized as it takes scale as a floating point value. This should be fixed +// when optimizng this routine further. +inline void ConcatenationWithScaling(const ConcatenationParams ¶ms, + const Shape *const *input_shapes, + const uint8_t *const *input_data, const Shape &output_shape, + uint8_t *output_data) +{ + int axis = params.axis; + const int32_t *input_zeropoint = params.input_zeropoint; + const float *input_scale = params.input_scale; + int inputs_count = params.inputs_count; + const int32_t output_zeropoint = params.output_zeropoint; + const float output_scale = params.output_scale; + + const int concat_dimensions = output_shape.DimensionsCount(); + assert(axis <= concat_dimensions); + + int64_t concat_size = 0; + for (int i = 0; i < inputs_count; i++) + { + assert(input_shapes[i]->DimensionsCount() == concat_dimensions); + for (int j = 0; j < concat_dimensions; j++) + { + if (j != axis) + { + assert(input_shapes[i]->Dims(j) == output_shape.Dims(j)); + } + } + concat_size += input_shapes[i]->Dims(axis); + } + assert(concat_size == output_shape.Dims(axis)); + int64_t outer_size = 1; + for (int i = 0; i < axis; ++i) + { + outer_size *= output_shape.Dims(i); + } + // For all input arrays, + // FlatSize() = outer_size * Dims(axis) * base_inner_size; + int64_t base_inner_size = 1; + for (int i = axis + 1; i < concat_dimensions; ++i) + { + base_inner_size *= output_shape.Dims(i); + } + + const float inverse_output_scale = 1.f / output_scale; + uint8_t *output_ptr = output_data; + for (int k = 0; k < outer_size; k++) + { + for (int i = 0; i < inputs_count; ++i) + { + const int copy_size = input_shapes[i]->Dims(axis) * base_inner_size; + const uint8_t *input_ptr = input_data[i] + k * copy_size; + if (input_zeropoint[i] == output_zeropoint && input_scale[i] == output_scale) + { + memcpy(output_ptr, input_ptr, copy_size); + } + else + { + const float scale = input_scale[i] * inverse_output_scale; + const float bias = -input_zeropoint[i] * scale; + for (int j = 0; j < copy_size; ++j) + { + const int32_t value = + static_cast(std::round(input_ptr[j] * scale + bias)) + output_zeropoint; + output_ptr[j] = static_cast(std::max(std::min(255, value), 0)); + } + } + output_ptr += copy_size; + } + } +} + } // namespace cker } // namespace nnfw diff --git a/compute/cker/include/cker/operation/Conv.h b/compute/cker/include/cker/operation/Conv.h index 78693335856..191cdb35edf 100644 --- a/compute/cker/include/cker/operation/Conv.h +++ b/compute/cker/include/cker/operation/Conv.h @@ -54,7 +54,11 @@ inline void TransposeFloatTensor(const float *input_data, const nnfw::cker::Shap class Conv { public: - Conv() : _modified_filter_data(), _prepared(false) {} + Conv() + : _modified_filter_data(), _im2col_data(), _im2col_shape(4), _need_im2col(false), + _prepared(false) + { + } void prepare(const Shape &filter_shape, const float *filter_data, PaddingType padding_type, bool &is_replaced_weights) @@ -77,6 +81,22 @@ class Conv } } + void prepareQuant(const Shape &input_shape, const Shape &kernel_shape, const Shape &output_shape, + uint32_t stride_width, uint32_t stride_height) + { + _need_im2col = stride_width != 1 || stride_height != 1 || kernel_shape.Dims(1) != 1 || + kernel_shape.Dims(2) != 1; + if (!_prepared && _need_im2col) + { + _im2col_shape.SetDim(0, output_shape.Dims(0)); + _im2col_shape.SetDim(1, output_shape.Dims(1)); + _im2col_shape.SetDim(2, output_shape.Dims(2)); + _im2col_shape.SetDim(3, input_shape.Dims(3) * kernel_shape.Dims(1) * kernel_shape.Dims(2)); + _im2col_data.resize(_im2col_shape.FlatSize()); + } + _prepared = true; + } + void operator()(const ConvParams ¶ms, const Shape &input_shape, const float *input_data, const Shape &filter_shape, const float *filter_data, const Shape &bias_shape, const float *bias_data, const Shape &output_shape, float *output_data) @@ -104,88 +124,24 @@ class Conv const Shape &filter_shape, const uint8_t *filter_data, const Shape &bias_shape, const int32_t *bias_data, const Shape &output_shape, uint8_t *output_data) { - const int stride_width = params.stride_width; - const int stride_height = params.stride_height; - const int dilation_width_factor = params.dilation_width_factor; - const int dilation_height_factor = params.dilation_height_factor; - const int pad_width = params.padding_values.width; - const int pad_height = params.padding_values.height; - const int32_t input_offset = params.input_offset; - const int32_t filter_offset = params.weights_offset; - const int32_t output_offset = params.output_offset; - const int32_t output_multiplier = params.output_multiplier; - const int output_shift = params.output_shift; - const int32_t output_activation_min = params.quantized_activation_min; - const int32_t output_activation_max = params.quantized_activation_max; - assert(output_activation_min <= output_activation_max); - - assert(input_shape.DimensionsCount() == 4); - assert(filter_shape.DimensionsCount() == 4); - assert(output_shape.DimensionsCount() == 4); - UNUSED_RELEASE(bias_shape); - const int batches = MatchingDim(input_shape, 0, output_shape, 0); - const int input_depth = MatchingDim(input_shape, 3, filter_shape, 3); - const int output_depth = MatchingDim(filter_shape, 0, output_shape, 3); - if (bias_data) + if (_prepared) { - assert(bias_shape.FlatSize() == output_depth); + uint8_t *im2col_raw_data = _im2col_data.data(); + optimized::Conv(params, input_shape, input_data, filter_shape, filter_data, bias_shape, + bias_data, output_shape, output_data, _im2col_shape, im2col_raw_data); } - const int input_height = input_shape.Dims(1); - const int input_width = input_shape.Dims(2); - const int filter_height = filter_shape.Dims(1); - const int filter_width = filter_shape.Dims(2); - const int output_height = output_shape.Dims(1); - const int output_width = output_shape.Dims(2); - for (int batch = 0; batch < batches; ++batch) + else { - for (int out_y = 0; out_y < output_height; ++out_y) - { - for (int out_x = 0; out_x < output_width; ++out_x) - { - for (int out_channel = 0; out_channel < output_depth; ++out_channel) - { - const int in_x_origin = (out_x * stride_width) - pad_width; - const int in_y_origin = (out_y * stride_height) - pad_height; - int32_t acc = 0; - for (int filter_y = 0; filter_y < filter_height; ++filter_y) - { - for (int filter_x = 0; filter_x < filter_width; ++filter_x) - { - const int in_x = in_x_origin + dilation_width_factor * filter_x; - const int in_y = in_y_origin + dilation_height_factor * filter_y; - // If the location is outside the bounds of the input image, - // use zero as a default value. - const int in_base = Offset(input_shape, batch, in_y, in_x, 0); - const int filter_base = Offset(filter_shape, out_channel, filter_y, filter_x, 0); - if ((in_x >= 0) && (in_x < input_width) && (in_y >= 0) && (in_y < input_height)) - { - for (int in_channel = 0; in_channel < input_depth; in_channel++) - { - int32_t input_val = input_data[in_channel + in_base]; - int32_t filter_val = filter_data[in_channel + filter_base]; - acc += (filter_val + filter_offset) * (input_val + input_offset); - } - } - } - } - if (bias_data) - { - acc += bias_data[out_channel]; - } - acc = MultiplyByQuantizedMultiplier(acc, output_multiplier, output_shift); - acc += output_offset; - acc = std::max(acc, output_activation_min); - acc = std::min(acc, output_activation_max); - output_data[Offset(output_shape, batch, out_y, out_x, out_channel)] = - static_cast(acc); - } - } - } + reference::Conv(params, input_shape, input_data, filter_shape, filter_data, bias_shape, + bias_data, output_shape, output_data); } } private: std::vector _modified_filter_data; + std::vector _im2col_data; + Shape _im2col_shape; + bool _need_im2col; bool _prepared; }; } // namespace cker diff --git a/compute/cker/include/cker/operation/DepthwiseConv.h b/compute/cker/include/cker/operation/DepthwiseConv.h index 8b5d6dad6ab..814a9e0196b 100644 --- a/compute/cker/include/cker/operation/DepthwiseConv.h +++ b/compute/cker/include/cker/operation/DepthwiseConv.h @@ -21,6 +21,8 @@ #include "cker/Shape.h" #include "cker/Types.h" #include "cker/Utils.h" +#include "cker/neon/neon_check.h" +#include "cker/operation/optimized/DepthwiseConvUint8.h" namespace nnfw { @@ -32,83 +34,55 @@ inline void DepthwiseConv(const DepthwiseConvParams ¶ms, const Shape &input_ const uint8_t *filter_data, const Shape &bias_shape, const int32_t *bias_data, const Shape &output_shape, uint8_t *output_data) { - const int stride_width = params.stride_width; - const int stride_height = params.stride_height; - const int dilation_width_factor = params.dilation_width_factor; - const int dilation_height_factor = params.dilation_height_factor; - const int pad_width = params.padding_values.width; - const int pad_height = params.padding_values.height; const int depth_multiplier = params.depth_multiplier; const int32_t output_activation_min = params.quantized_activation_min; const int32_t output_activation_max = params.quantized_activation_max; - const int32_t input_offset = params.input_offset; - const int32_t filter_offset = params.weights_offset; - const int32_t output_offset = params.output_offset; - const int32_t output_multiplier = params.output_multiplier; - const int output_shift = params.output_shift; + const int dilation_width_factor = params.dilation_width_factor; + const int dilation_height_factor = params.dilation_height_factor; + assert(dilation_width_factor >= 1); + assert(dilation_height_factor >= 1); + UNUSED_RELEASE(dilation_width_factor); + UNUSED_RELEASE(dilation_height_factor); assert(input_shape.DimensionsCount() == 4); assert(filter_shape.DimensionsCount() == 4); assert(output_shape.DimensionsCount() == 4); - assert(output_activation_min <= output_activation_max); - const int batches = MatchingDim(input_shape, 0, output_shape, 0); + UNUSED_RELEASE(output_activation_min); + UNUSED_RELEASE(output_activation_max); const int output_depth = MatchingDim(filter_shape, 3, output_shape, 3); - const int input_height = input_shape.Dims(1); - const int input_width = input_shape.Dims(2); const int input_depth = input_shape.Dims(3); - const int filter_height = filter_shape.Dims(1); - const int filter_width = filter_shape.Dims(2); - const int output_height = output_shape.Dims(1); - const int output_width = output_shape.Dims(2); assert(output_depth == input_depth * depth_multiplier); assert(bias_shape.FlatSize() == output_depth); + UNUSED_RELEASE(input_depth); UNUSED_RELEASE(output_depth); - UNUSED_RELEASE(bias_shape); + UNUSED_RELEASE(depth_multiplier); - for (int b = 0; b < batches; ++b) - { - for (int out_y = 0; out_y < output_height; ++out_y) - { - for (int out_x = 0; out_x < output_width; ++out_x) - { - for (int ic = 0; ic < input_depth; ++ic) - { - for (int m = 0; m < depth_multiplier; m++) - { - const int oc = m + ic * depth_multiplier; - const int in_x_origin = (out_x * stride_width) - pad_width; - const int in_y_origin = (out_y * stride_height) - pad_height; - int32_t acc = 0; - for (int filter_y = 0; filter_y < filter_height; ++filter_y) - { - for (int filter_x = 0; filter_x < filter_width; ++filter_x) - { - const int in_x = in_x_origin + dilation_width_factor * filter_x; - const int in_y = in_y_origin + dilation_height_factor * filter_y; - // If the location is outside the bounds of the input image, - // use zero as a default value. - if ((in_x >= 0) && (in_x < input_width) && (in_y >= 0) && (in_y < input_height)) - { - int32_t input_val = input_data[Offset(input_shape, b, in_y, in_x, ic)]; - int32_t filter_val = filter_data[Offset(filter_shape, 0, filter_y, filter_x, oc)]; - acc += (filter_val + filter_offset) * (input_val + input_offset); - } - } - } - if (bias_data) - { - acc += bias_data[oc]; - } - acc = MultiplyByQuantizedMultiplier(acc, output_multiplier, output_shift); - acc += output_offset; - acc = std::max(acc, output_activation_min); - acc = std::min(acc, output_activation_max); - output_data[Offset(output_shape, b, out_y, out_x, oc)] = static_cast(acc); - } - } - } - } - } +// Enable for arm64 except for the Nvidia Linux 4 Tegra (L4T) running on +// Jetson TX-2. This compiler does not support the offsetof() macro. +#if defined(__aarch64__) +// TODO Use below codes + +// const int stride_width = params.stride_width; +// const int stride_height = params.stride_height; +// const int pad_width = params.padding_values.width; +// const int pad_height = params.padding_values.height; +// const int output_shift = params.output_shift; +// +// // Call kernel optimized for depthwise convolutions using 3x3 filters if +// // parameters are supported. +// if (Fast3x3FilterKernelSupported( +// input_shape, filter_shape, stride_width, stride_height, +// dilation_width_factor, dilation_height_factor, pad_width, pad_height, +// depth_multiplier, output_shape, output_shift)) { +// DepthwiseConv3x3Filter(params, input_shape, input_data, filter_shape, +// filter_data, bias_shape, bias_data, output_shape, +// output_data); +// return; +// } +#endif + + optimized::DepthwiseConvGeneral(params, input_shape, input_data, filter_shape, filter_data, + bias_shape, bias_data, output_shape, output_data); } inline void DepthwiseConv(const DepthwiseConvParams ¶ms, const Shape &input_shape, diff --git a/compute/cker/include/cker/operation/Elementwise.h b/compute/cker/include/cker/operation/Elementwise.h new file mode 100644 index 00000000000..83581e84b63 --- /dev/null +++ b/compute/cker/include/cker/operation/Elementwise.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved + * Copyright 2018 The TensorFlow Authors. 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 __NNFW_CKER_ELEMENTWISE_H__ +#define __NNFW_CKER_ELEMENTWISE_H__ + +#include "cker/eigen/Utils.h" +#include "cker/Shape.h" +#include "cker/Types.h" +#include + +namespace nnfw +{ +namespace cker +{ + +inline void Sin(const Shape &input_shape, const float *input_data, const Shape &output_shape, + float *output_data) +{ + const int size = MatchingFlatSize(input_shape, output_shape); + for (int i = 0; i < size; i++) + { + output_data[i] = std::sin(input_data[i]); + } +} + +inline void Abs(const Shape &input_shape, const float *input_data, const Shape &output_shape, + float *output_data) +{ + auto input_map = MapAsVector(input_data, input_shape); + auto output_map = MapAsVector(output_data, output_shape); + output_map.array() = input_map.array().abs(); +} + +inline void Rsqrt(const Shape &input_shape, const float *input_data, const Shape &output_shape, + float *output_data) +{ + const int size = MatchingFlatSize(input_shape, output_shape); + for (int i = 0; i < size; i++) + { + output_data[i] = 1.f / std::sqrt(input_data[i]); + } +} + +} // namespace cker +} // namespace nnfw + +#endif // __NNFW_CKER_ELEMENTWISE_H__ diff --git a/compute/cker/include/cker/operation/FullyConnected.h b/compute/cker/include/cker/operation/FullyConnected.h index 68cb246c705..01b925efbd0 100644 --- a/compute/cker/include/cker/operation/FullyConnected.h +++ b/compute/cker/include/cker/operation/FullyConnected.h @@ -55,42 +55,30 @@ class FCTempArena inline void FullyConnected(const FullyConnectedParams ¶ms, const Shape &input_shape, const float *input_data, const Shape &weights_shape, - const float *weights_data, const Shape &bias_shape, - const float *bias_data, const Shape &output_shape, float *output_data) + const float *weights_data, const Shape &, const float *bias_data, + const Shape &, float *output_data) { - UNUSED_RELEASE(input_shape); - UNUSED_RELEASE(bias_shape); - const float output_activation_min = params.float_activation_min; - const float output_activation_max = params.float_activation_max; - // TODO(benoitjacob): This really should be: - // const int batches = ArraySize(output_dims, 1); - // but the current --variable_batch hack consists in overwriting the 3rd - // dimension with the runtime batch size, as we don't keep track for each - // array of which dimension is the batch dimension in it. - const int output_dims_count = output_shape.DimensionsCount(); - const int weights_dims_count = weights_shape.DimensionsCount(); - const int batches = FlatSizeSkipDim(output_shape, output_dims_count - 1); - const int output_depth = - MatchingDim(weights_shape, weights_dims_count - 2, output_shape, output_dims_count - 1); - const int accum_depth = weights_shape.Dims(weights_dims_count - 1); - for (int b = 0; b < batches; ++b) + int total_input_size = input_shape.FlatSize(); + int input_size = weights_shape.Dims(1); + const int batch_size = total_input_size / input_size; + const int num_units = weights_shape.Dims(0); + + // Output = bias if bias tensor exists. + if (bias_data) { - for (int out_c = 0; out_c < output_depth; ++out_c) - { - float total = 0.f; - for (int d = 0; d < accum_depth; ++d) - { - total += input_data[b * accum_depth + d] * weights_data[out_c * accum_depth + d]; - } - float bias_value = 0.0f; - if (bias_data) - { - bias_value = bias_data[out_c]; - } - output_data[out_c + output_depth * b] = ActivationFunctionWithMinMax( - total + bias_value, output_activation_min, output_activation_max); - } + VectorBatchVectorAssign(bias_data, num_units, batch_size, output_data); + } + else + { + ZeroVector(output_data, batch_size * num_units); } + + // Compute output += weight * input + MatrixBatchVectorMultiplyAccumulate(weights_data, num_units, input_size, input_data, batch_size, + output_data, /*result_stride=*/1); + + // Apply activation function + ApplyActivationToVector(output_data, batch_size * num_units, params.activation, output_data); } inline void FullyConnected(const FullyConnectedParams ¶ms, const Shape &input_shape, diff --git a/compute/cker/include/cker/operation/MaxPool.h b/compute/cker/include/cker/operation/MaxPool.h index 894eeb1bbab..33954729815 100644 --- a/compute/cker/include/cker/operation/MaxPool.h +++ b/compute/cker/include/cker/operation/MaxPool.h @@ -21,6 +21,7 @@ #include "cker/Shape.h" #include "cker/Types.h" #include "cker/Utils.h" +#include "cker/neon/neon_check.h" #include "cker/eigen/Utils.h" #include @@ -88,9 +89,15 @@ inline void MaxPool(const PoolParams ¶ms, const Shape &input_shape, const fl inline void MaxPool(const PoolParams ¶ms, const Shape &input_shape, const uint8_t *input_data, const Shape &output_shape, uint8_t *output_data) { + + // Here, and in other pooling ops, in order to maintain locality of reference, + // to minimize some recalculations, and to load into NEON vector registers, we + // use an inner loop down the depth. Since depths can be large and hence we + // would need arbitrarily large temporary storage, we divide the work up into + // depth tranches just within the batch loop. + static constexpr int kPoolingAccTrancheSize = 256; + assert(params.quantized_activation_min <= params.quantized_activation_max); - assert(params.quantized_activation_min >= 0); - assert(params.quantized_activation_max <= 255); assert(input_shape.DimensionsCount() == 4); assert(output_shape.DimensionsCount() == 4); const int batches = MatchingDim(input_shape, 0, output_shape, 0); @@ -101,36 +108,88 @@ inline void MaxPool(const PoolParams ¶ms, const Shape &input_shape, const ui const int output_width = output_shape.Dims(2); const int stride_height = params.stride_height; const int stride_width = params.stride_width; + + uint8_t acc[kPoolingAccTrancheSize]; for (int batch = 0; batch < batches; ++batch) { - for (int out_y = 0; out_y < output_height; ++out_y) + // We proceed through the depth in tranches (see comment above). The + // depth_base is the depth at the beginning of the tranche. The + // tranche_depth is the depth dimension of the tranche. + for (int depth_base = 0; depth_base < depth; depth_base += kPoolingAccTrancheSize) { - for (int out_x = 0; out_x < output_width; ++out_x) + const int tranche_depth = std::min(depth - depth_base, kPoolingAccTrancheSize); + for (int out_y = 0; out_y < output_height; ++out_y) { - for (int channel = 0; channel < depth; ++channel) + for (int out_x = 0; out_x < output_width; ++out_x) { const int in_x_origin = (out_x * stride_width) - params.padding_values.width; const int in_y_origin = (out_y * stride_height) - params.padding_values.height; - // Compute the boundaries of the filter region clamped so as to - // ensure that the filter window fits in the input array. const int filter_x_start = std::max(0, -in_x_origin); const int filter_x_end = std::min(params.filter_width, input_width - in_x_origin); const int filter_y_start = std::max(0, -in_y_origin); const int filter_y_end = std::min(params.filter_height, input_height - in_y_origin); - uint8_t max = 0; - for (int filter_y = filter_y_start; filter_y < filter_y_end; ++filter_y) + memset(acc, 0, tranche_depth * sizeof(acc[0])); + const uint8_t *input_ptr = + input_data + depth_base + + depth * (in_x_origin + input_width * (in_y_origin + input_height * batch)); + for (int fy = filter_y_start; fy < filter_y_end; fy++) { - for (int filter_x = filter_x_start; filter_x < filter_x_end; ++filter_x) + const uint8_t *input_row_ptr = input_ptr + depth * (fy * input_width + filter_x_start); + for (int fx = filter_x_start; fx < filter_x_end; fx++) { - const int in_x = in_x_origin + filter_x; - const int in_y = in_y_origin + filter_y; - max = std::max(max, input_data[Offset(input_shape, batch, in_y, in_x, channel)]); + const uint8_t *input_channel_ptr = input_row_ptr; + int channel = 0; +#ifdef USE_NEON + for (; channel <= tranche_depth - 16; channel += 16) + { + uint8x16_t acc_reg = vld1q_u8(acc + channel); + uint8x16_t input_reg = vld1q_u8(input_channel_ptr); + input_channel_ptr += 16; + acc_reg = vmaxq_u8(acc_reg, input_reg); + vst1q_u8(acc + channel, acc_reg); + } + + for (; channel <= tranche_depth - 8; channel += 8) + { + uint8x8_t acc_reg = vld1_u8(acc + channel); + uint8x8_t input_reg = vld1_u8(input_channel_ptr); + input_channel_ptr += 8; + acc_reg = vmax_u8(acc_reg, input_reg); + vst1_u8(acc + channel, acc_reg); + } +#endif + for (; channel < tranche_depth; ++channel) + { + acc[channel] = std::max(acc[channel], *input_channel_ptr++); + } + input_row_ptr += depth; } } - max = std::max(max, params.quantized_activation_min); - max = std::min(max, params.quantized_activation_max); - output_data[Offset(output_shape, batch, out_y, out_x, channel)] = - static_cast(max); + uint8_t *output_ptr = output_data + Offset(output_shape, batch, out_y, out_x, depth_base); + int channel = 0; +#ifdef USE_NEON + for (; channel <= tranche_depth - 16; channel += 16) + { + uint8x16_t a = vld1q_u8(acc + channel); + a = vminq_u8(a, vdupq_n_u8(params.quantized_activation_max)); + a = vmaxq_u8(a, vdupq_n_u8(params.quantized_activation_min)); + vst1q_u8(output_ptr + channel, a); + } + for (; channel <= tranche_depth - 8; channel += 8) + { + uint8x8_t a = vld1_u8(acc + channel); + a = vmin_u8(a, vdup_n_u8(params.quantized_activation_max)); + a = vmax_u8(a, vdup_n_u8(params.quantized_activation_min)); + vst1_u8(output_ptr + channel, a); + } +#endif + for (; channel < tranche_depth; ++channel) + { + uint8_t a = acc[channel]; + a = std::max(a, params.quantized_activation_min); + a = std::min(a, params.quantized_activation_max); + output_ptr[channel] = static_cast(a); + } } } } diff --git a/compute/cker/include/cker/operation/SoftMax.h b/compute/cker/include/cker/operation/SoftMax.h index af1f804b5fb..bb394619e1d 100644 --- a/compute/cker/include/cker/operation/SoftMax.h +++ b/compute/cker/include/cker/operation/SoftMax.h @@ -21,10 +21,10 @@ #include "cker/Shape.h" #include "cker/Utils.h" #include "cker/Types.h" -#include "cker/gemmlowp/FixedPoint.h" #include "cker/eigen/Utils.h" #include +#include #include namespace nnfw @@ -63,9 +63,9 @@ inline void Softmax(const SoftmaxParams ¶ms, const Shape &input_shape, // accumulation, but exp(-16) definitely is. static const int kScaledDiffIntegerBits = 5; static const int kAccumulationIntegerBits = 12; - using FixedPointScaledDiff = gemmlowp::FixedPoint; - using FixedPointAccum = gemmlowp::FixedPoint; - using FixedPoint0 = gemmlowp::FixedPoint<0>; + using FixedPointScaledDiff = gemmlowp::FixedPoint; + using FixedPointAccum = gemmlowp::FixedPoint; + using FixedPoint0 = gemmlowp::FixedPoint; const int trailing_dim = input_shape.DimensionsCount() - 1; const int outer_size = MatchingFlatSizeSkipDim(input_shape, trailing_dim, output_shape); diff --git a/compute/cker/include/cker/operation/Split.h b/compute/cker/include/cker/operation/Split.h new file mode 100644 index 00000000000..08a436ee939 --- /dev/null +++ b/compute/cker/include/cker/operation/Split.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved + * Copyright 2017 The TensorFlow Authors. 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 __NNFW_CKER_SPLIT_H__ +#define __NNFW_CKER_SPLIT_H__ + +#include "cker/Shape.h" +#include "cker/Types.h" + +namespace nnfw +{ +namespace cker +{ + +template +void Split(const SplitParams ¶ms, const Shape &input_shape, const Scalar *input_data, + const Shape &output_shape, Scalar *const *output_data) +{ + const int split_dimensions = input_shape.DimensionsCount(); + int axis = params.axis < 0 ? params.axis + split_dimensions : params.axis; + int outputs_count = params.num_split; + + int64_t outer_size = 1; + for (int i = 0; i < axis; ++i) + { + outer_size *= input_shape.Dims(i); + } + // For all output arrays, + // FlatSize() = outer_size * Dims(axis) * base_inner_size; + int64_t base_inner_size = 1; + for (int i = axis + 1; i < split_dimensions; ++i) + { + base_inner_size *= input_shape.Dims(i); + } + + const Scalar *input_ptr = input_data; + for (int k = 0; k < outer_size; k++) + { + for (int i = 0; i < outputs_count; ++i) + { + const int copy_size = output_shape.Dims(axis) * base_inner_size; + memcpy(output_data[i] + k * copy_size, input_ptr, copy_size * sizeof(Scalar)); + input_ptr += copy_size; + } + } +} + +} // namespace cker +} // namespace nnfw + +#endif // __NNFW_CKER_SPLIT_H__ diff --git a/compute/cker/include/cker/operation/StridedSlice.h b/compute/cker/include/cker/operation/StridedSlice.h new file mode 100644 index 00000000000..c57b4daa0c5 --- /dev/null +++ b/compute/cker/include/cker/operation/StridedSlice.h @@ -0,0 +1,308 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved + * Copyright 2018 The TensorFlow Authors. 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 __NNFW_CKER_STRIDEDSLICE_H__ +#define __NNFW_CKER_STRIDEDSLICE_H__ + +#include "cker/Shape.h" +#include "cker/Types.h" +#include "cker/Utils.h" + +#include + +namespace nnfw +{ +namespace cker +{ +// Use until std::clamp() is available from C++17. +inline int Clamp(const int v, const int lo, const int hi) +{ + assert(!(hi < lo)); + if (hi < v) + return hi; + if (v < lo) + return lo; + return v; +} + +inline void StridedSlicePadIndices(StridedSliceParams *p, int dim_count) +{ + // Add indices and mask bits to fully include extra dimensions + assert(dim_count <= 4); + assert(dim_count >= p->start_indices_count); + assert(p->start_indices_count == p->stop_indices_count); + assert(p->stop_indices_count == p->strides_count); + + const int pad_count = dim_count - p->start_indices_count; + + // Pad indices at start, so move arrays by pad_count. + for (int i = p->start_indices_count - 1; i >= 0; --i) + { + p->strides[i + pad_count] = p->strides[i]; + p->start_indices[i + pad_count] = p->start_indices[i]; + p->stop_indices[i + pad_count] = p->stop_indices[i]; + } + for (int i = 0; i < pad_count; ++i) + { + p->start_indices[i] = 0; + p->stop_indices[i] = 1; + p->strides[i] = 1; + } + + // Pad masks with 0s or 1s as required. + p->shrink_axis_mask <<= pad_count; + p->ellipsis_mask <<= pad_count; + p->new_axis_mask <<= pad_count; + p->begin_mask <<= pad_count; + p->end_mask <<= pad_count; + p->begin_mask |= (1 << pad_count) - 1; + p->end_mask |= (1 << pad_count) - 1; + + p->start_indices_count = dim_count; + p->stop_indices_count = dim_count; + p->strides_count = dim_count; +} + +// Return the index for the first element along that axis. This index will be a +// positive integer between [0, axis_size - 1] that can be used to index +// directly into the data. +inline int StartForAxis(const StridedSliceParams ¶ms, const Shape &input_shape, int axis) +{ + const auto begin_mask = params.begin_mask; + const auto *start_indices = params.start_indices; + const auto *strides = params.strides; + // Begin with the specified index. + int start = start_indices[axis]; + + // begin_mask override + if (begin_mask & 1 << axis) + { + if (strides[axis] > 0) + { + // Forward iteration - use the first element. These values will get + // clamped below (Note: We could have set them to 0 and axis_size-1, but + // use lowest() and max() to maintain symmetry with StopForAxis()) + start = std::numeric_limits::lowest(); + } + else + { + // Backward iteration - use the last element. + start = std::numeric_limits::max(); + } + } + + // Handle negative indices + int axis_size = input_shape.Dims(axis); + if (start < 0) + { + start += axis_size; + } + + // Clamping + start = Clamp(start, 0, axis_size - 1); + + return start; +} + +// Return the "real" index for the end of iteration along that axis. This is an +// "end" in the traditional C sense, in that it points to one past the last +// element. ie. So if you were iterating through all elements of a 1D array of +// size 4, this function would return 4 as the stop, because it is one past the +// "real" indices of 0, 1, 2 & 3. +inline int StopForAxis(const StridedSliceParams ¶ms, const Shape &input_shape, int axis, + int start_for_axis) +{ + const auto end_mask = params.end_mask; + const auto shrink_axis_mask = params.shrink_axis_mask; + const auto *stop_indices = params.stop_indices; + const auto *strides = params.strides; + + // Begin with the specified index + const bool shrink_axis = shrink_axis_mask & (1 << axis); + int stop = stop_indices[axis]; + + // When shrinking an axis, the end position does not matter (and can be + // incorrect when negative indexing is used, see Issue #19260). Always use + // start_for_axis + 1 to generate a length 1 slice, since start_for_axis has + // already been adjusted for negative indices. + if (shrink_axis) + { + stop = start_for_axis + 1; + } + + // end_mask override + if (end_mask & (1 << axis)) + { + if (strides[axis] > 0) + { + // Forward iteration - use the last element. These values will get + // clamped below + stop = std::numeric_limits::max(); + } + else + { + // Backward iteration - use the first element. + stop = std::numeric_limits::lowest(); + } + } + + // Handle negative indices + const int axis_size = input_shape.Dims(axis); + if (stop < 0) + { + stop += axis_size; + } + + // Clamping + // Because the end index points one past the last element, we need slightly + // different clamping ranges depending on the direction. + if (strides[axis] > 0) + { + // Forward iteration + stop = Clamp(stop, 0, axis_size); + } + else + { + // Backward iteration + stop = Clamp(stop, -1, axis_size - 1); + } + + return stop; +} + +inline bool LoopCondition(int index, int stop, int stride) +{ + // True when we have reached the end of an axis and should loop. + return stride > 0 ? index >= stop : index <= stop; +} + +template +inline StridedSliceParams +buildStridedSliceParams(const T *begin, const T *end, const T *strides, const uint32_t begin_mask, + const uint32_t end_mask, const uint32_t shrink_axis_mask, + const uint8_t rank) +{ + StridedSliceParams op_params; + op_params.start_indices_count = rank; + op_params.stop_indices_count = rank; + op_params.strides_count = rank; + + for (int i = 0; i < rank; ++i) + { + op_params.start_indices[i] = begin[i]; + op_params.stop_indices[i] = end[i]; + op_params.strides[i] = strides[i]; + + assert(op_params.strides[i] != 0); + } + + op_params.begin_mask = begin_mask; + op_params.ellipsis_mask = 0; // NYI + op_params.end_mask = end_mask; + op_params.new_axis_mask = 0; // NYI + op_params.shrink_axis_mask = shrink_axis_mask; + + assert(sizeof(op_params.begin_mask) * 4 >= rank); + + return op_params; +} + +void checkOutputSize(const StridedSliceParams &op_params, const Shape &input_shape, + const Shape &output_shape, uint32_t rank) +{ + UNUSED_RELEASE(output_shape); + + int32_t shape_size = 0; + + for (uint32_t idx = 0; idx < rank; ++idx) + { + int32_t stride = op_params.strides[idx]; + int32_t begin = StartForAxis(op_params, input_shape, idx); + int32_t end = StopForAxis(op_params, input_shape, idx, begin); + + // When shrinking an axis, the end position does not matter (and can be + // incorrect when negative indexing is used, see Issue #19260). Always use + // begin + 1 to generate a length 1 slice, since begin has + // already been adjusted for negative indices by StartForAxis. + const bool shrink_axis = op_params.shrink_axis_mask & (1 << idx); + if (shrink_axis) + { + end = begin + 1; + } + + int32_t dim_shape = std::ceil((end - begin) / static_cast(stride)); + dim_shape = dim_shape < 0 ? 0 : dim_shape; + if (!shrink_axis) + { + assert(output_shape.Dims(shape_size) == dim_shape); + shape_size++; + } + } + + assert(output_shape.DimensionsCount() == shape_size); +} + +template +inline void StridedSlice(const StridedSliceParams &op_params, const Shape &unextended_input_shape, + const T *input_data, const Shape &unextended_output_shape, T *output_data) +{ + // Note that the output_shape is not used herein. + StridedSliceParams params_copy = op_params; + + assert(unextended_input_shape.DimensionsCount() <= 4); + assert(unextended_output_shape.DimensionsCount() <= 4); + + const Shape input_shape = Shape::ExtendedShape(4, unextended_input_shape); + const Shape output_shape = Shape::ExtendedShape(4, unextended_output_shape); + + // Reverse and pad to 4 dimensions because that is what the runtime code + // requires (ie. all shapes must be 4D and are given backwards). + StridedSlicePadIndices(¶ms_copy, 4); + + const int start_b = StartForAxis(params_copy, input_shape, 0); + const int stop_b = StopForAxis(params_copy, input_shape, 0, start_b); + const int start_h = StartForAxis(params_copy, input_shape, 1); + const int stop_h = StopForAxis(params_copy, input_shape, 1, start_h); + const int start_w = StartForAxis(params_copy, input_shape, 2); + const int stop_w = StopForAxis(params_copy, input_shape, 2, start_w); + const int start_d = StartForAxis(params_copy, input_shape, 3); + const int stop_d = StopForAxis(params_copy, input_shape, 3, start_d); + + T *out_ptr = output_data; + for (int in_b = start_b; !LoopCondition(in_b, stop_b, params_copy.strides[0]); + in_b += params_copy.strides[0]) + { + for (int in_h = start_h; !LoopCondition(in_h, stop_h, params_copy.strides[1]); + in_h += params_copy.strides[1]) + { + for (int in_w = start_w; !LoopCondition(in_w, stop_w, params_copy.strides[2]); + in_w += params_copy.strides[2]) + { + for (int in_d = start_d; !LoopCondition(in_d, stop_d, params_copy.strides[3]); + in_d += params_copy.strides[3]) + { + *out_ptr++ = input_data[Offset(input_shape, in_b, in_h, in_w, in_d)]; + } + } + } + } +} + +} // namespace cker +} // namespace nnfw + +#endif // __NNFW_CKER_STRIDEDSLICE_H__ diff --git a/compute/cker/include/cker/operation/optimized/Conv.h b/compute/cker/include/cker/operation/optimized/Conv.h index f6a1c0308b7..0f620146c03 100644 --- a/compute/cker/include/cker/operation/optimized/Conv.h +++ b/compute/cker/include/cker/operation/optimized/Conv.h @@ -18,13 +18,22 @@ #ifndef __NNFW_CKER_OPTIMIZED_CONV_H__ #define __NNFW_CKER_OPTIMIZED_CONV_H__ +#include "OptimizedUtils.h" + #include "cker/eigen/EigenSupport.h" #include "cker/eigen/Utils.h" +#include "cker/gemmlowp/GEMMSupport.h" #include "cker/neon/neon_check.h" #include "cker/operation/Common.h" #include "cker/Shape.h" #include "cker/Types.h" + +#include +#include +#include + #include +#include namespace nnfw { @@ -32,6 +41,34 @@ namespace cker { namespace optimized { + +struct GemmlowpOutputPipeline +{ + typedef gemmlowp::VectorMap ColVectorMap; + typedef std::tuple, + gemmlowp::OutputStageScaleInt32ByFixedPointAndExponent, + gemmlowp::OutputStageClamp, gemmlowp::OutputStageSaturatingCastToUint8> + Pipeline; + static Pipeline MakeExp(const int32_t *bias_data, int output_rows, int32_t output_offset, + int32_t output_multiplier, int output_left_shift, + int32_t output_activation_min, int32_t output_activation_max) + { + ColVectorMap bias_vector(bias_data, output_rows); + gemmlowp::OutputStageBiasAddition bias_addition_stage; + bias_addition_stage.bias_vector = bias_vector; + gemmlowp::OutputStageScaleInt32ByFixedPointAndExponent quantize_down_stage; + quantize_down_stage.result_offset_after_shift = output_offset; + quantize_down_stage.result_fixedpoint_multiplier = output_multiplier; + quantize_down_stage.result_exponent = output_left_shift; + gemmlowp::OutputStageClamp clamp_stage; + clamp_stage.min = output_activation_min; + clamp_stage.max = output_activation_max; + gemmlowp::OutputStageSaturatingCastToUint8 saturating_cast_stage; + return std::make_tuple(bias_addition_stage, quantize_down_stage, clamp_stage, + saturating_cast_stage); + } +}; + inline void AddBiasAndEvalActivationFunction(float output_activation_min, float output_activation_max, const Shape &bias_shape, const float *bias_data, const Shape &array_shape, @@ -40,6 +77,98 @@ inline void AddBiasAndEvalActivationFunction(float output_activation_min, BiasAndClamp(output_activation_min, output_activation_max, bias_shape.FlatSize(), bias_data, array_shape.FlatSize(), array_data); } + +inline void Conv(const ConvParams ¶ms, const Shape &input_shape, const uint8_t *input_data, + const Shape &filter_shape, const uint8_t *filter_data, const Shape &bias_shape, + const int32_t *bias_data, const Shape &output_shape, uint8_t *output_data, + const Shape &im2col_shape, uint8_t *im2col_data) +{ + gemmlowp::GemmContext *gemm_context = gemm_support::GetGemmLowpContext(); + + const int stride_width = params.stride_width; + const int stride_height = params.stride_height; + const int dilation_width_factor = params.dilation_width_factor; + const int dilation_height_factor = params.dilation_height_factor; + const int32_t input_offset = params.input_offset; + const int32_t filter_offset = params.weights_offset; + const int32_t output_offset = params.output_offset; + const int32_t output_multiplier = params.output_multiplier; + const int output_shift = params.output_shift; + const int32_t output_activation_min = params.quantized_activation_min; + const int32_t output_activation_max = params.quantized_activation_max; + assert(input_shape.DimensionsCount() == 4); + assert(filter_shape.DimensionsCount() == 4); + assert(output_shape.DimensionsCount() == 4); + + const uint8_t *gemm_input_data = nullptr; + const Shape *gemm_input_shape = nullptr; + const int filter_width = filter_shape.Dims(2); + const int filter_height = filter_shape.Dims(1); + const bool need_dilated_im2col = dilation_width_factor != 1 || dilation_height_factor != 1; + const bool need_im2col = + stride_width != 1 || stride_height != 1 || filter_width != 1 || filter_height != 1; + if (need_dilated_im2col) + { + assert(im2col_data); + const int input_zero_point = -input_offset; + assert(input_zero_point >= 0); + assert(input_zero_point <= 255); + DilatedIm2col(params, input_zero_point, input_shape, input_data, filter_shape, output_shape, + im2col_data); + gemm_input_data = im2col_data; + gemm_input_shape = &im2col_shape; + } + else if (need_im2col) + { + assert(im2col_data); + const int input_zero_point = -input_offset; + assert(input_zero_point >= 0); + assert(input_zero_point <= 255); + Im2col(params, filter_height, filter_width, input_zero_point, input_shape, input_data, + im2col_shape, im2col_data); + gemm_input_data = im2col_data; + gemm_input_shape = &im2col_shape; + } + else + { + gemm_input_data = input_data; + gemm_input_shape = &input_shape; + } + + const int gemm_input_rows = gemm_input_shape->Dims(3); + // Using FlatSizeSkipDim causes segfault in some contexts (see b/79927784). + // The root cause has not yet been identified though. Same applies below for + // the other calls commented out. This is a partial rollback of cl/196819423. + // const int gemm_input_cols = FlatSizeSkipDim(*gemm_input_shape, 3); + const int gemm_input_cols = + gemm_input_shape->Dims(0) * gemm_input_shape->Dims(1) * gemm_input_shape->Dims(2); + const int filter_rows = filter_shape.Dims(0); + // See b/79927784. + // const int filter_cols = FlatSizeSkipDim(filter_shape, 0); + const int filter_cols = filter_shape.Dims(1) * filter_shape.Dims(2) * filter_shape.Dims(3); + const int output_rows = output_shape.Dims(3); + // See b/79927784. + // const int output_cols = FlatSizeSkipDim(output_shape, 3); + const int output_cols = output_shape.Dims(0) * output_shape.Dims(1) * output_shape.Dims(2); + assert(output_rows == filter_rows); + assert(output_cols == gemm_input_cols); + assert(filter_cols == gemm_input_rows); + assert(bias_shape.FlatSize() == output_rows); + UNUSED_RELEASE(bias_shape); + gemmlowp::MatrixMap filter_matrix( + filter_data, filter_rows, filter_cols); + gemmlowp::MatrixMap input_matrix( + gemm_input_data, gemm_input_rows, gemm_input_cols); + gemmlowp::MatrixMap output_matrix(output_data, output_rows, + output_cols); + const auto &output_pipeline = + GemmlowpOutputPipeline::MakeExp(bias_data, output_rows, output_offset, output_multiplier, + output_shift, output_activation_min, output_activation_max); + gemmlowp::GemmWithOutputPipeline( + gemm_context, filter_matrix, input_matrix, &output_matrix, filter_offset, input_offset, + output_pipeline); +} + } // namespace optimized namespace multithreaded diff --git a/compute/cker/include/cker/operation/optimized/DepthwiseConvUint8.h b/compute/cker/include/cker/operation/optimized/DepthwiseConvUint8.h new file mode 100644 index 00000000000..d383b126dc0 --- /dev/null +++ b/compute/cker/include/cker/operation/optimized/DepthwiseConvUint8.h @@ -0,0 +1,2123 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved + * Copyright 2017 The TensorFlow Authors. 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 __NNFW_CKER_OPTIMIZED_DEPTHWISE_CONV_UINT8_H__ +#define __NNFW_CKER_OPTIMIZED_DEPTHWISE_CONV_UINT8_H__ + +#include "cker/Shape.h" +#include "cker/Types.h" +#include "cker/Utils.h" +#include "cker/neon/neon_check.h" + +#include +#include + +namespace nnfw +{ +namespace cker +{ +namespace optimized +{ + +// Implementation of quantized DepthwiseConv + +template +struct QuantizedDepthwiseConvKernel +{ +}; + +#ifdef USE_NEON +template <> struct QuantizedDepthwiseConvKernel +{ + static void Run(int num_output_pixels, int input_depth, int depth_multiplier, + const uint8_t *input_ptr, uint16_t input_offset, int input_ptr_increment, + const uint8_t *filter_ptr, uint16_t filter_offset, int32_t *acc_buffer_ptr) + { + (void)input_depth; + (void)depth_multiplier; + // Load the filters, add filter_offset. + uint8x8x2_t filter_u8; + filter_u8.val[0] = vld1_u8(filter_ptr); + filter_u8.val[1] = vld1_u8(filter_ptr + 8); + int16x8_t filter[2]; + for (int i = 0; i < 2; i++) + { + filter[i] = + vaddq_s16(vreinterpretq_s16_u16(vmovl_u8(filter_u8.val[i])), vdupq_n_s16(filter_offset)); + } + // Handle one output pixel at a time. + for (int outp = 0; outp < num_output_pixels; outp++) + { + // Load the accumulators from acc_buffer + int32x4x2_t acc[2]; + for (int i = 0; i < 2; i++) + { + acc[i].val[0] = vld1q_s32(acc_buffer_ptr + 4 * i); + acc[i].val[1] = vld1q_s32(acc_buffer_ptr + 4 * i + 8); + } + // Load the inputs, add input_offset. + const uint8x8_t input_u8 = vld1_u8(input_ptr); + input_ptr += input_ptr_increment; + const int16x8_t input_s16 = vreinterpretq_s16_u16(vmovl_u8(input_u8)); + const int16x8_t input = vaddq_s16(input_s16, vdupq_n_s16(input_offset)); + // Duplicate the input values, 2-fold + const int16x8x2_t input_dup2 = vzipq_s16(input, input); + // Multiply-accumulate + for (int i = 0; i < 2; i++) + { + acc[0].val[i] = + vmlal_s16(acc[0].val[i], vget_low_s16(filter[i]), vget_low_s16(input_dup2.val[i])); + acc[1].val[i] = + vmlal_s16(acc[1].val[i], vget_high_s16(filter[i]), vget_high_s16(input_dup2.val[i])); + } + // Store the accumulators back to acc_buffer + for (int i = 0; i < 2; i++) + { + vst1q_s32(acc_buffer_ptr + 4 * i, acc[i].val[0]); + vst1q_s32(acc_buffer_ptr + 4 * i + 8, acc[i].val[1]); + } + acc_buffer_ptr += 16; + } + } +}; + +template <> struct QuantizedDepthwiseConvKernel +{ + static void Run(int num_output_pixels, int input_depth, int depth_multiplier, + const uint8_t *input_ptr, uint16_t input_offset, int input_ptr_increment, + const uint8_t *filter_ptr, uint16_t filter_offset, int32_t *acc_buffer_ptr) + { + (void)input_depth; + (void)depth_multiplier; + (void)input_ptr_increment; + // Load the filters, add filter_offset. + const uint8x8_t filter_u8 = vld1_u8(filter_ptr); + const int16x8_t filter_s16 = vreinterpretq_s16_u16(vmovl_u8(filter_u8)); + const int16x8_t filter = vaddq_s16(filter_s16, vdupq_n_s16(filter_offset)); + + int outp = 0; + // Handle 2 output pixels at a time. + for (; outp <= num_output_pixels - 2; outp += 2) + { + // Load the accumulators from acc_buffer. + int32x4_t acc[4]; + for (int i = 0; i < 4; i++) + { + acc[i] = vld1q_s32(acc_buffer_ptr + 4 * i); + } + // Load the inputs, add input_offset. + uint8x8_t input_u8[2]; + for (int i = 0; i < 2; i++) + { + input_u8[i] = vld1_u8(input_ptr + 8 * i); + } + input_ptr += 16; + int16x8_t input[2]; + for (int i = 0; i < 2; i++) + { + input[i] = vreinterpretq_s16_u16(vmovl_u8(input_u8[i])); + } + for (int i = 0; i < 2; i++) + { + input[i] = vaddq_s16(input[i], vdupq_n_s16(input_offset)); + } + // Multiply-accumulate. + acc[0] = vmlal_s16(acc[0], vget_low_s16(filter), vget_low_s16(input[0])); + acc[1] = vmlal_s16(acc[1], vget_high_s16(filter), vget_high_s16(input[0])); + acc[2] = vmlal_s16(acc[2], vget_low_s16(filter), vget_low_s16(input[1])); + acc[3] = vmlal_s16(acc[3], vget_high_s16(filter), vget_high_s16(input[1])); + // Store the accumulators back to acc_buffer + for (int i = 0; i < 4; i++) + { + vst1q_s32(acc_buffer_ptr + 4 * i, acc[i]); + } + acc_buffer_ptr += 16; + } + // Handle 1 output pixel at a time. + for (; outp < num_output_pixels; outp++) + { + // Load the accumulators from acc_buffer. + int32x4_t acc[2]; + acc[0] = vld1q_s32(acc_buffer_ptr); + acc[1] = vld1q_s32(acc_buffer_ptr + 4); + + // Load the inputs, add input_offset. + const uint8x8_t input_u8 = vld1_u8(input_ptr); + input_ptr += 8; + const int16x8_t input_s16 = vreinterpretq_s16_u16(vmovl_u8(input_u8)); + const int16x8_t input = vaddq_s16(input_s16, vdupq_n_s16(input_offset)); + // Multiply-accumulate. + acc[0] = vmlal_s16(acc[0], vget_low_s16(filter), vget_low_s16(input)); + acc[1] = vmlal_s16(acc[1], vget_high_s16(filter), vget_high_s16(input)); + // Store the accumulators back to acc_buffer + vst1q_s32(acc_buffer_ptr, acc[0]); + vst1q_s32(acc_buffer_ptr + 4, acc[1]); + acc_buffer_ptr += 8; + } + } +}; + +template <> struct QuantizedDepthwiseConvKernel +{ + static void Run(int num_output_pixels, int input_depth, int depth_multiplier, + const uint8_t *input_ptr, uint16_t input_offset, int input_ptr_increment, + const uint8_t *filter_ptr, uint16_t filter_offset, int32_t *acc_buffer_ptr) + { + (void)input_depth; + (void)depth_multiplier; + (void)input_ptr_increment; + // Load the filters, add filter_offset. + const uint8x8_t filter_u8 = vld1_u8(filter_ptr); + const int16x8_t filter_s16 = vreinterpretq_s16_u16(vmovl_u8(filter_u8)); + const int16x8_t filter = vaddq_s16(filter_s16, vdupq_n_s16(filter_offset)); + + int outp = 0; + // Handle 2 output pixels at a time. + for (; outp <= num_output_pixels - 2; outp += 2) + { + // Load the accumulators from acc_buffer + int32x4_t acc[4]; + for (int i = 0; i < 4; i++) + { + acc[i] = vld1q_s32(acc_buffer_ptr + 4 * i); + } + // Load the inputs, add input_offset. + const uint8x8_t input_u8 = vld1_u8(input_ptr); + input_ptr += 8; + const int16x8_t input_s16 = vreinterpretq_s16_u16(vmovl_u8(input_u8)); + const int16x8_t input = vaddq_s16(input_s16, vdupq_n_s16(input_offset)); + // Duplicate the input values, 2-fold + const int16x8x2_t input_dup2 = vzipq_s16(input, input); + // Multiply-accumulate + for (int i = 0; i < 2; i++) + { + acc[2 * i + 0] = + vmlal_s16(acc[2 * i + 0], vget_low_s16(filter), vget_low_s16(input_dup2.val[i])); + acc[2 * i + 1] = + vmlal_s16(acc[2 * i + 1], vget_high_s16(filter), vget_high_s16(input_dup2.val[i])); + } + // Store the accumulators back to acc_buffer + for (int i = 0; i < 4; i++) + { + vst1q_s32(acc_buffer_ptr + 4 * i, acc[i]); + } + acc_buffer_ptr += 16; + } + // Handle one output pixel at a time. + for (; outp < num_output_pixels; outp++) + { + // Load the accumulators from acc_buffer + int32x4_t acc[2]; + for (int i = 0; i < 2; i++) + { + acc[i] = vld1q_s32(acc_buffer_ptr + 4 * i); + } + // Load the inputs, add input_offset. + uint8x8_t input_u8 = vdup_n_u8(0); + input_u8 = vset_lane_u8(input_ptr[0], input_u8, 0); + input_u8 = vset_lane_u8(input_ptr[1], input_u8, 1); + input_u8 = vset_lane_u8(input_ptr[2], input_u8, 2); + input_u8 = vset_lane_u8(input_ptr[3], input_u8, 3); + input_ptr += 4; + const int16x4_t input_s16 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(input_u8))); + const int16x4_t input = vadd_s16(input_s16, vdup_n_s16(input_offset)); + // Duplicate the input values, 2-fold + const int16x4x2_t input_dup2 = vzip_s16(input, input); + // Multiply-accumulate + acc[0] = vmlal_s16(acc[0], vget_low_s16(filter), input_dup2.val[0]); + acc[1] = vmlal_s16(acc[1], vget_high_s16(filter), input_dup2.val[1]); + // Store the accumulators back to acc_buffer + for (int i = 0; i < 2; i++) + { + vst1q_s32(acc_buffer_ptr + 4 * i, acc[i]); + } + acc_buffer_ptr += 8; + } + } +}; + +template <> struct QuantizedDepthwiseConvKernel +{ + static void Run(int num_output_pixels, int input_depth, int depth_multiplier, + const uint8_t *input_ptr, uint16_t input_offset, int input_ptr_increment, + const uint8_t *filter_ptr, uint16_t filter_offset, int32_t *acc_buffer_ptr) + { + (void)input_depth; + (void)depth_multiplier; + (void)input_ptr_increment; + // Load the filters, add filter_offset. + int16x8_t filter[2]; + for (int i = 0; i < 2; i++) + { + const uint8x8_t filter_u8 = vld1_u8(filter_ptr + 8 * i); + const int16x8_t filter_s16 = vreinterpretq_s16_u16(vmovl_u8(filter_u8)); + filter[i] = vaddq_s16(filter_s16, vdupq_n_s16(filter_offset)); + } + int outp = 0; + // Handle two output pixels at a time. + for (; outp <= num_output_pixels - 2; outp += 2) + { + // Load the accumulators from acc_buffer. + int32x4_t acc[8]; + for (int i = 0; i < 8; i++) + { + acc[i] = vld1q_s32(acc_buffer_ptr + 4 * i); + } + // Load the inputs, add input_offset. + uint8x8_t input_u8 = vdup_n_u8(0); + input_u8 = vset_lane_u8(input_ptr[0], input_u8, 0); + input_u8 = vset_lane_u8(input_ptr[1], input_u8, 1); + input_u8 = vset_lane_u8(input_ptr[2], input_u8, 2); + input_u8 = vset_lane_u8(input_ptr[3], input_u8, 3); + input_ptr += 4; + const int16x4_t input_s16 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(input_u8))); + const int16x4_t input = vadd_s16(input_s16, vdup_n_s16(input_offset)); + // Multiply-accumulate. + acc[0] = vmlal_lane_s16(acc[0], vget_low_s16(filter[0]), input, 0); + acc[1] = vmlal_lane_s16(acc[1], vget_high_s16(filter[0]), input, 0); + acc[2] = vmlal_lane_s16(acc[2], vget_low_s16(filter[1]), input, 1); + acc[3] = vmlal_lane_s16(acc[3], vget_high_s16(filter[1]), input, 1); + acc[4] = vmlal_lane_s16(acc[4], vget_low_s16(filter[0]), input, 2); + acc[5] = vmlal_lane_s16(acc[5], vget_high_s16(filter[0]), input, 2); + acc[6] = vmlal_lane_s16(acc[6], vget_low_s16(filter[1]), input, 3); + acc[7] = vmlal_lane_s16(acc[7], vget_high_s16(filter[1]), input, 3); + // Store the accumulators back to acc_buffer. + for (int i = 0; i < 8; i++) + { + vst1q_s32(acc_buffer_ptr + 4 * i, acc[i]); + } + acc_buffer_ptr += 32; + } + // Handle one output pixel at a time. + for (; outp < num_output_pixels; outp++) + { + // Load the accumulators from acc_buffer. + int32x4_t acc[4]; + for (int i = 0; i < 4; i++) + { + acc[i] = vld1q_s32(acc_buffer_ptr + 4 * i); + } + // Load the inputs, add input_offset. + uint8x8_t input_u8 = vdup_n_u8(0); + input_u8 = vset_lane_u8(input_ptr[0], input_u8, 0); + input_u8 = vset_lane_u8(input_ptr[1], input_u8, 1); + input_ptr += 2; + const int16x4_t input_s16 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(input_u8))); + const int16x4_t input = vadd_s16(input_s16, vdup_n_s16(input_offset)); + + // Multiply-accumulate. + acc[0] = vmlal_lane_s16(acc[0], vget_low_s16(filter[0]), input, 0); + acc[1] = vmlal_lane_s16(acc[1], vget_high_s16(filter[0]), input, 0); + acc[2] = vmlal_lane_s16(acc[2], vget_low_s16(filter[1]), input, 1); + acc[3] = vmlal_lane_s16(acc[3], vget_high_s16(filter[1]), input, 1); + + // Store the accumulators back to acc_buffer. + for (int i = 0; i < 4; i++) + { + vst1q_s32(acc_buffer_ptr + 4 * i, acc[i]); + } + acc_buffer_ptr += 16; + } + } +}; + +template <> struct QuantizedDepthwiseConvKernel +{ + static void Run(int num_output_pixels, int input_depth, int depth_multiplier, + const uint8_t *input_ptr, uint16_t input_offset, int input_ptr_increment, + const uint8_t *filter_ptr, uint16_t filter_offset, int32_t *acc_buffer_ptr) + { + (void)input_depth; + (void)depth_multiplier; + (void)input_ptr_increment; + // Load the filters, add filter_offset. + uint8x8_t filter_u8 = vdup_n_u8(0); + filter_u8 = vset_lane_u8(filter_ptr[0], filter_u8, 0); + filter_u8 = vset_lane_u8(filter_ptr[1], filter_u8, 1); + filter_u8 = vset_lane_u8(filter_ptr[2], filter_u8, 2); + filter_u8 = vset_lane_u8(filter_ptr[3], filter_u8, 3); + const int16x4_t filter_s16 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(filter_u8))); + const int16x4_t filter = vadd_s16(filter_s16, vdup_n_s16(filter_offset)); + + int outp = 0; + // Handle 4 output pixels at a time. + for (; outp <= num_output_pixels - 4; outp += 4) + { + // Load the accumulators from acc_buffer + int32x4_t acc[4]; + for (int i = 0; i < 4; i++) + { + acc[i] = vld1q_s32(acc_buffer_ptr + 4 * i); + } + + // Load the inputs, add input_offset. + const uint8x8_t input_u8 = vld1_u8(input_ptr); + input_ptr += 8; + const int16x8_t input_s16 = vreinterpretq_s16_u16(vmovl_u8(input_u8)); + const int16x8_t input = vaddq_s16(input_s16, vdupq_n_s16(input_offset)); + // Duplicate the input values, 2-fold + const int16x8x2_t input_dup2 = vzipq_s16(input, input); + // Multiply-accumulate + acc[0] = vmlal_s16(acc[0], filter, vget_low_s16(input_dup2.val[0])); + acc[1] = vmlal_s16(acc[1], filter, vget_high_s16(input_dup2.val[0])); + acc[2] = vmlal_s16(acc[2], filter, vget_low_s16(input_dup2.val[1])); + acc[3] = vmlal_s16(acc[3], filter, vget_high_s16(input_dup2.val[1])); + // Store the accumulators back to acc_buffer + for (int i = 0; i < 4; i++) + { + vst1q_s32(acc_buffer_ptr + 4 * i, acc[i]); + } + acc_buffer_ptr += 16; + } + // Handle one output pixel at a time. + for (; outp < num_output_pixels; outp++) + { + // Load the accumulators from acc_buffer + int32x4_t acc = vld1q_s32(acc_buffer_ptr); + + uint8x8_t input_u8 = vdup_n_u8(0); + input_u8 = vset_lane_u8(input_ptr[0], input_u8, 0); + input_u8 = vset_lane_u8(input_ptr[1], input_u8, 1); + input_ptr += 2; + const int16x4_t input_s16 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(input_u8))); + const int16x4_t input = vadd_s16(input_s16, vdup_n_s16(input_offset)); + // Duplicate the input values, 2-fold + const int16x4_t input_dup2 = vzip_s16(input, input).val[0]; + // Multiply-accumulate + acc = vmlal_s16(acc, filter, input_dup2); + // Store the accumulators back to acc_buffer + vst1q_s32(acc_buffer_ptr, acc); + acc_buffer_ptr += 4; + } + } +}; + +template <> struct QuantizedDepthwiseConvKernel +{ + static void Run(int num_output_pixels, int input_depth, int depth_multiplier, + const uint8_t *input_ptr, uint16_t input_offset, int input_ptr_increment, + const uint8_t *filter_ptr, uint16_t filter_offset, int32_t *acc_buffer_ptr) + { + (void)input_depth; + (void)depth_multiplier; + (void)input_ptr_increment; + // Load the filters, add filter_offset. + uint8x8_t filter_u8 = vdup_n_u8(0); + filter_u8 = vset_lane_u8(filter_ptr[0], filter_u8, 0); + filter_u8 = vset_lane_u8(filter_ptr[1], filter_u8, 1); + filter_u8 = vset_lane_u8(filter_ptr[0], filter_u8, 2); + filter_u8 = vset_lane_u8(filter_ptr[1], filter_u8, 3); + const int16x4_t filter_s16 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(filter_u8))); + const int16x4_t filter = vadd_s16(filter_s16, vdup_n_s16(filter_offset)); + + int outp = 0; + // Handle 8 output pixels at a time. + for (; outp <= num_output_pixels - 8; outp += 8) + { + // Load the accumulators from acc_buffer. + int32x4_t acc[4]; + for (int i = 0; i < 4; i++) + { + acc[i] = vld1q_s32(acc_buffer_ptr + 4 * i); + } + // Load the inputs, add input_offset. + uint8x8_t input_u8[2]; + for (int i = 0; i < 2; i++) + { + input_u8[i] = vld1_u8(input_ptr + 8 * i); + } + input_ptr += 16; + int16x8_t input[2]; + for (int i = 0; i < 2; i++) + { + input[i] = vreinterpretq_s16_u16(vmovl_u8(input_u8[i])); + } + for (int i = 0; i < 2; i++) + { + input[i] = vaddq_s16(input[i], vdupq_n_s16(input_offset)); + } + + // Multiply-accumulate. + acc[0] = vmlal_s16(acc[0], filter, vget_low_s16(input[0])); + acc[1] = vmlal_s16(acc[1], filter, vget_high_s16(input[0])); + acc[2] = vmlal_s16(acc[2], filter, vget_low_s16(input[1])); + acc[3] = vmlal_s16(acc[3], filter, vget_high_s16(input[1])); + // Store the accumulators back to acc_buffer. + for (int i = 0; i < 4; i++) + { + vst1q_s32(acc_buffer_ptr + 4 * i, acc[i]); + } + acc_buffer_ptr += 16; + } + // Handle 4 output pixels at a time. + for (; outp <= num_output_pixels - 4; outp += 4) + { + // Load the accumulators from acc_buffer. + int32x4_t acc[2]; + for (int i = 0; i < 2; i++) + { + acc[i] = vld1q_s32(acc_buffer_ptr + 4 * i); + } + // Load the inputs, add input_offset. + const uint8x8_t input_u8 = vld1_u8(input_ptr); + input_ptr += 8; + const int16x8_t input_s16 = vreinterpretq_s16_u16(vmovl_u8(input_u8)); + const int16x8_t input = vaddq_s16(input_s16, vdupq_n_s16(input_offset)); + + // Multiply-accumulate. + acc[0] = vmlal_s16(acc[0], filter, vget_low_s16(input)); + acc[1] = vmlal_s16(acc[1], filter, vget_high_s16(input)); + // Store the accumulators back to acc_buffer. + for (int i = 0; i < 2; i++) + { + vst1q_s32(acc_buffer_ptr + 4 * i, acc[i]); + } + acc_buffer_ptr += 8; + } + // Handle 2 output pixels at a time. + for (; outp <= num_output_pixels - 2; outp += 2) + { + // Load the accumulators from acc_buffer. + int32x4_t acc = vld1q_s32(acc_buffer_ptr); + // Load the inputs, add input_offset. + uint8x8_t input_u8 = vdup_n_u8(0); + input_u8 = vset_lane_u8(input_ptr[0], input_u8, 0); + input_u8 = vset_lane_u8(input_ptr[1], input_u8, 1); + input_u8 = vset_lane_u8(input_ptr[2], input_u8, 2); + input_u8 = vset_lane_u8(input_ptr[3], input_u8, 3); + input_ptr += 4; + const int16x4_t input_s16 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(input_u8))); + const int16x4_t input = vadd_s16(input_s16, vdup_n_s16(input_offset)); + + // Multiply-accumulate. + acc = vmlal_s16(acc, filter, input); + // Store the accumulators back to acc_buffer. + vst1q_s32(acc_buffer_ptr, acc); + acc_buffer_ptr += 4; + } + // Handle 1 output pixel at a time. + for (; outp < num_output_pixels; outp++) + { + // Load the accumulators from acc_buffer. + int32x2_t acc = vld1_s32(acc_buffer_ptr); + // Load the inputs, add input_offset. + uint8x8_t input_u8 = vdup_n_u8(0); + input_u8 = vset_lane_u8(input_ptr[0], input_u8, 0); + input_u8 = vset_lane_u8(input_ptr[1], input_u8, 1); + input_ptr += 2; + const int16x4_t input_s16 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(input_u8))); + const int16x4_t input = vadd_s16(input_s16, vdup_n_s16(input_offset)); + + // Multiply-accumulate. + acc = vget_low_s32(vmlal_s16(vcombine_s32(acc, acc), filter, input)); + // Store the accumulators back to acc_buffer. + vst1_s32(acc_buffer_ptr, acc); + acc_buffer_ptr += 2; + } + } +}; + +template <> struct QuantizedDepthwiseConvKernel +{ + static void Run(int num_output_pixels, int input_depth, int depth_multiplier, + const uint8_t *input_ptr, uint16_t input_offset, int input_ptr_increment, + const uint8_t *filter_ptr, uint16_t filter_offset, int32_t *acc_buffer_ptr) + { + (void)input_depth; + (void)depth_multiplier; + (void)input_ptr_increment; + // Load the filters, add filter_offset. + uint8x8_t filter_u8 = vdup_n_u8(0); + filter_u8 = vset_lane_u8(filter_ptr[0], filter_u8, 0); + filter_u8 = vset_lane_u8(filter_ptr[1], filter_u8, 1); + filter_u8 = vset_lane_u8(filter_ptr[0], filter_u8, 2); + filter_u8 = vset_lane_u8(filter_ptr[1], filter_u8, 3); + const int16x4_t filter_s16 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(filter_u8))); + const int16x4_t filter = vadd_s16(filter_s16, vdup_n_s16(filter_offset)); + + int outp = 0; + // Handle 8 output pixels at a time. + for (; outp <= num_output_pixels - 8; outp += 8) + { + // Load the accumulators from acc_buffer + int32x4_t acc[4]; + for (int i = 0; i < 4; i++) + { + acc[i] = vld1q_s32(acc_buffer_ptr + 4 * i); + } + + // Load the inputs, add input_offset. + const uint8x8_t input_u8 = vld1_u8(input_ptr); + input_ptr += 8; + const int16x8_t input_s16 = vreinterpretq_s16_u16(vmovl_u8(input_u8)); + const int16x8_t input = vaddq_s16(input_s16, vdupq_n_s16(input_offset)); + // Duplicate the input values, 2-fold + const int16x8x2_t input_dup2 = vzipq_s16(input, input); + // Multiply-accumulate + acc[0] = vmlal_s16(acc[0], filter, vget_low_s16(input_dup2.val[0])); + acc[1] = vmlal_s16(acc[1], filter, vget_high_s16(input_dup2.val[0])); + acc[2] = vmlal_s16(acc[2], filter, vget_low_s16(input_dup2.val[1])); + acc[3] = vmlal_s16(acc[3], filter, vget_high_s16(input_dup2.val[1])); + // Store the accumulators back to acc_buffer + for (int i = 0; i < 4; i++) + { + vst1q_s32(acc_buffer_ptr + 4 * i, acc[i]); + } + acc_buffer_ptr += 16; + } + // Handle one output pixel at a time. + for (; outp < num_output_pixels; outp++) + { + // Load the accumulators from acc_buffer + int32x2_t acc = vld1_s32(acc_buffer_ptr); + + // Load the inputs, add input_offset. + const uint32_t input = *input_ptr++ + input_offset; + + // Multiply-accumulate + acc = vget_low_s32(vmlal_n_s16(vcombine_s32(acc, acc), filter, input)); + // Store the accumulators back to acc_buffer + vst1_s32(acc_buffer_ptr, acc); + acc_buffer_ptr += 2; + } + } +}; + +template <> struct QuantizedDepthwiseConvKernel +{ + static void Run(int num_output_pixels, int input_depth, int depth_multiplier, + const uint8_t *input_ptr, uint16_t input_offset, int input_ptr_increment, + const uint8_t *filter_ptr, uint16_t filter_offset, int32_t *acc_buffer_ptr) + { + (void)input_depth; + (void)depth_multiplier; + (void)input_ptr_increment; + // Load the filters, add filter_offset. + uint8x8_t filter_u8 = vdup_n_u8(0); + filter_u8 = vset_lane_u8(filter_ptr[0], filter_u8, 0); + filter_u8 = vset_lane_u8(filter_ptr[1], filter_u8, 1); + filter_u8 = vset_lane_u8(filter_ptr[2], filter_u8, 2); + filter_u8 = vset_lane_u8(filter_ptr[3], filter_u8, 3); + const int16x4_t filter_s16 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(filter_u8))); + const int16x4_t filter = vadd_s16(filter_s16, vdup_n_s16(filter_offset)); + + int outp = 0; + // Handle 8 output pixels at a time. + for (; outp <= num_output_pixels - 8; outp += 8) + { + // Load the accumulators from acc_buffer + int32x4_t acc[8]; + for (int i = 0; i < 8; i++) + { + acc[i] = vld1q_s32(acc_buffer_ptr + 4 * i); + } + + // Load the inputs, add input_offset. + uint8x8_t input_u8 = vld1_u8(input_ptr); + input_ptr += 8; + const int16x8_t input_s16 = vreinterpretq_s16_u16(vmovl_u8(input_u8)); + const int16x8_t input = vaddq_s16(input_s16, vdupq_n_s16(input_offset)); + + // Multiply-accumulate + acc[0] = vmlal_lane_s16(acc[0], filter, vget_low_s16(input), 0); + acc[1] = vmlal_lane_s16(acc[1], filter, vget_low_s16(input), 1); + acc[2] = vmlal_lane_s16(acc[2], filter, vget_low_s16(input), 2); + acc[3] = vmlal_lane_s16(acc[3], filter, vget_low_s16(input), 3); + acc[4] = vmlal_lane_s16(acc[4], filter, vget_high_s16(input), 0); + acc[5] = vmlal_lane_s16(acc[5], filter, vget_high_s16(input), 1); + acc[6] = vmlal_lane_s16(acc[6], filter, vget_high_s16(input), 2); + acc[7] = vmlal_lane_s16(acc[7], filter, vget_high_s16(input), 3); + + // Store the accumulators back to acc_buffer + for (int i = 0; i < 8; i++) + { + vst1q_s32(acc_buffer_ptr + 4 * i, acc[i]); + } + acc_buffer_ptr += 32; + } + // Handle 4 output pixels at a time. + for (; outp <= num_output_pixels - 4; outp += 4) + { + // Load the accumulators from acc_buffer + int32x4_t acc[4]; + for (int i = 0; i < 4; i++) + { + acc[i] = vld1q_s32(acc_buffer_ptr + 4 * i); + } + + // Load the inputs, add input_offset. + uint8x8_t input_u8 = vdup_n_u8(0); + input_u8 = vset_lane_u8(input_ptr[0], input_u8, 0); + input_u8 = vset_lane_u8(input_ptr[1], input_u8, 1); + input_u8 = vset_lane_u8(input_ptr[2], input_u8, 2); + input_u8 = vset_lane_u8(input_ptr[3], input_u8, 3); + input_ptr += 4; + const int16x4_t input_s16 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(input_u8))); + const int16x4_t input = vadd_s16(input_s16, vdup_n_s16(input_offset)); + + // Multiply-accumulate + acc[0] = vmlal_lane_s16(acc[0], filter, input, 0); + acc[1] = vmlal_lane_s16(acc[1], filter, input, 1); + acc[2] = vmlal_lane_s16(acc[2], filter, input, 2); + acc[3] = vmlal_lane_s16(acc[3], filter, input, 3); + + // Store the accumulators back to acc_buffer + for (int i = 0; i < 4; i++) + { + vst1q_s32(acc_buffer_ptr + 4 * i, acc[i]); + } + acc_buffer_ptr += 16; + } + // Handle one output pixel at a time. + for (; outp < num_output_pixels; outp++) + { + // Load the accumulators from acc_buffer + int32x4_t acc = vld1q_s32(acc_buffer_ptr); + + // Load the inputs, add input_offset. + const uint32_t input = *input_ptr++ + input_offset; + + // Multiply-accumulate + acc = vmlal_n_s16(acc, filter, input); + // Store the accumulators back to acc_buffer + vst1q_s32(acc_buffer_ptr, acc); + acc_buffer_ptr += 4; + } + } +}; + +template <> struct QuantizedDepthwiseConvKernel +{ + static void Run(int num_output_pixels, int input_depth, int depth_multiplier, + const uint8_t *input_ptr, uint16_t input_offset, int input_ptr_increment, + const uint8_t *filter_ptr, uint16_t filter_offset, int32_t *acc_buffer_ptr) + { + (void)input_depth; + (void)depth_multiplier; + (void)input_ptr_increment; + // Load the filters, add filter_offset. + uint8x8_t filter_u8 = vdup_n_u8(0); + filter_u8 = vset_lane_u8(filter_ptr[0], filter_u8, 0); + filter_u8 = vset_lane_u8(filter_ptr[1], filter_u8, 1); + filter_u8 = vset_lane_u8(filter_ptr[2], filter_u8, 2); + filter_u8 = vset_lane_u8(filter_ptr[3], filter_u8, 3); + const int16x4_t filter_s16 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(filter_u8))); + const int16x4_t filter = vadd_s16(filter_s16, vdup_n_s16(filter_offset)); + + int outp = 0; + // Handle 4 output pixels at a time. + for (; outp <= num_output_pixels - 4; outp += 4) + { + // Load the accumulators from acc_buffer + int32x4_t acc[4]; + for (int i = 0; i < 4; i++) + { + acc[i] = vld1q_s32(acc_buffer_ptr + 4 * i); + } + // Load the inputs, add input_offset. + int16x8_t input[2]; + for (int i = 0; i < 2; i++) + { + const uint8x8_t input_u8 = vld1_u8(input_ptr + 8 * i); + const int16x8_t input_s16 = vreinterpretq_s16_u16(vmovl_u8(input_u8)); + input[i] = vaddq_s16(input_s16, vdupq_n_s16(input_offset)); + } + input_ptr += 16; + // Multiply-accumulate + for (int i = 0; i < 2; i++) + { + acc[2 * i + 0] = vmlal_s16(acc[2 * i + 0], filter, vget_low_s16(input[i])); + acc[2 * i + 1] = vmlal_s16(acc[2 * i + 1], filter, vget_high_s16(input[i])); + } + // Store the accumulators back to acc_buffer + for (int i = 0; i < 4; i++) + { + vst1q_s32(acc_buffer_ptr + 4 * i, acc[i]); + } + acc_buffer_ptr += 16; + } + // Handle one output pixel at a time. + for (; outp < num_output_pixels; outp++) + { + // Load the accumulators from acc_buffer + int32x4_t acc; + acc = vld1q_s32(acc_buffer_ptr); + + // Load the inputs, add input_offset. + uint8x8_t input_u8 = vdup_n_u8(0); + input_u8 = vset_lane_u8(input_ptr[0], input_u8, 0); + input_u8 = vset_lane_u8(input_ptr[1], input_u8, 1); + input_u8 = vset_lane_u8(input_ptr[2], input_u8, 2); + input_u8 = vset_lane_u8(input_ptr[3], input_u8, 3); + input_ptr += 4; + const int16x4_t input_s16 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(input_u8))); + const int16x4_t input = vadd_s16(input_s16, vdup_n_s16(input_offset)); + // Multiply-accumulate + acc = vmlal_s16(acc, filter, input); + // Store the accumulators back to acc_buffer + vst1q_s32(acc_buffer_ptr, acc); + acc_buffer_ptr += 4; + } + } +}; + +template <> struct QuantizedDepthwiseConvKernel +{ + static void Run(int num_output_pixels, int input_depth, int depth_multiplier, + const uint8_t *input_ptr, uint16_t input_offset, int input_ptr_increment, + const uint8_t *filter_ptr, uint16_t filter_offset, int32_t *acc_buffer_ptr) + { + (void)input_depth; + (void)depth_multiplier; + (void)input_ptr_increment; + // Load the filters, add filter_offset. + int16x8_t filter[2]; + for (int i = 0; i < 2; i++) + { + const uint8x8_t filter_u8 = vld1_u8(filter_ptr + 8 * i); + const int16x8_t filter_s16 = vreinterpretq_s16_u16(vmovl_u8(filter_u8)); + filter[i] = vaddq_s16(filter_s16, vdupq_n_s16(filter_offset)); + } + + int outp = 0; + // Handle 2 output pixels at a time. + for (; outp <= num_output_pixels - 2; outp += 2) + { + // Load the accumulators from acc_buffer + int32x4_t acc[8]; + for (int i = 0; i < 8; i++) + { + acc[i] = vld1q_s32(acc_buffer_ptr + 4 * i); + } + + // Load the inputs, add input_offset. + uint8x8_t input_u8 = vld1_u8(input_ptr); + input_ptr += 8; + const int16x8_t input_s16 = vreinterpretq_s16_u16(vmovl_u8(input_u8)); + const int16x8_t input = vaddq_s16(input_s16, vdupq_n_s16(input_offset)); + + // Multiply-accumulate + acc[0] = vmlal_lane_s16(acc[0], vget_low_s16(filter[0]), vget_low_s16(input), 0); + acc[1] = vmlal_lane_s16(acc[1], vget_high_s16(filter[0]), vget_low_s16(input), 1); + acc[2] = vmlal_lane_s16(acc[2], vget_low_s16(filter[1]), vget_low_s16(input), 2); + acc[3] = vmlal_lane_s16(acc[3], vget_high_s16(filter[1]), vget_low_s16(input), 3); + acc[4] = vmlal_lane_s16(acc[4], vget_low_s16(filter[0]), vget_high_s16(input), 0); + acc[5] = vmlal_lane_s16(acc[5], vget_high_s16(filter[0]), vget_high_s16(input), 1); + acc[6] = vmlal_lane_s16(acc[6], vget_low_s16(filter[1]), vget_high_s16(input), 2); + acc[7] = vmlal_lane_s16(acc[7], vget_high_s16(filter[1]), vget_high_s16(input), 3); + // Store the accumulators back to acc_buffer + for (int i = 0; i < 8; i++) + { + vst1q_s32(acc_buffer_ptr + 4 * i, acc[i]); + } + acc_buffer_ptr += 32; + } + // Handle one output pixel at a time. + for (; outp < num_output_pixels; outp++) + { + // Load the accumulators from acc_buffer + int32x4_t acc[4]; + for (int i = 0; i < 4; i++) + { + acc[i] = vld1q_s32(acc_buffer_ptr + 4 * i); + } + + // Load the inputs, add input_offset. + uint8x8_t input_u8 = vdup_n_u8(0); + input_u8 = vset_lane_u8(input_ptr[0], input_u8, 0); + input_u8 = vset_lane_u8(input_ptr[1], input_u8, 1); + input_u8 = vset_lane_u8(input_ptr[2], input_u8, 2); + input_u8 = vset_lane_u8(input_ptr[3], input_u8, 3); + input_ptr += 4; + const int16x4_t input_s16 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(input_u8))); + const int16x4_t input = vadd_s16(input_s16, vdup_n_s16(input_offset)); + + // Multiply-accumulate + acc[0] = vmlal_lane_s16(acc[0], vget_low_s16(filter[0]), input, 0); + acc[1] = vmlal_lane_s16(acc[1], vget_high_s16(filter[0]), input, 1); + acc[2] = vmlal_lane_s16(acc[2], vget_low_s16(filter[1]), input, 2); + acc[3] = vmlal_lane_s16(acc[3], vget_high_s16(filter[1]), input, 3); + // Store the accumulators back to acc_buffer + for (int i = 0; i < 4; i++) + { + vst1q_s32(acc_buffer_ptr + 4 * i, acc[i]); + } + acc_buffer_ptr += 16; + } + } +}; + +template <> struct QuantizedDepthwiseConvKernel +{ + static void Run(int num_output_pixels, int input_depth, int depth_multiplier, + const uint8_t *input_ptr, uint16_t input_offset, int input_ptr_increment, + const uint8_t *filter_ptr, uint16_t filter_offset, int32_t *acc_buffer_ptr) + { + (void)input_depth; + (void)depth_multiplier; + // We will have to duplicate bytes in a NEON register, 3-fold. + // We will do that by register-level table-look-up using VTBL instructions. + // Here we prepare the registers containing the table-lookup indices. + static const uint8_t dup3_indices_array[3][8] = { + {0, 0, 0, 1, 1, 1, 2, 2}, {2, 3, 3, 3, 4, 4, 4, 5}, {5, 5, 6, 6, 6, 7, 7, 7}}; + uint8x8_t dup3_indices[3]; + for (int i = 0; i < 3; i++) + { + dup3_indices[i] = vld1_u8(dup3_indices_array[i]); + } + + // Handle one output pixel at a time. + for (int outp = 0; outp < num_output_pixels; outp++) + { + const uint8_t *local_filter_ptr = filter_ptr; + const uint8_t *local_input_ptr = input_ptr; + int ic = 0; + // Handle 8 input channels at a time. + for (; ic <= input_depth - 8; ic += 8) + { + // Load the filters, add filter_offset. + int16x8_t filter[3]; + uint8x8x3_t filter_u8; + filter_u8.val[0] = vld1_u8(local_filter_ptr); + filter_u8.val[1] = vld1_u8(local_filter_ptr + 8); + filter_u8.val[2] = vld1_u8(local_filter_ptr + 16); + local_filter_ptr += 24; + for (int i = 0; i < 3; i++) + { + const int16x8_t filter_s16 = vreinterpretq_s16_u16(vmovl_u8(filter_u8.val[i])); + filter[i] = vaddq_s16(filter_s16, vdupq_n_s16(filter_offset)); + } + // Load the inputs, duplicate 3-fold, add input_offset. + const uint8x8_t input_u8 = vld1_u8(local_input_ptr); + local_input_ptr += 8; + + uint8x8_t input_u8_dup3[3]; + for (int i = 0; i < 3; i++) + { + input_u8_dup3[i] = vtbl1_u8(input_u8, dup3_indices[i]); + } + int16x8_t input_dup3[3]; + for (int i = 0; i < 3; i++) + { + const int16x8_t input_s16_dup3 = vreinterpretq_s16_u16(vmovl_u8(input_u8_dup3[i])); + input_dup3[i] = vaddq_s16(input_s16_dup3, vdupq_n_s16(input_offset)); + } + // Load the accumulators from acc_buffer + int32x4x3_t acc[2]; + for (int i = 0; i < 2; i++) + { + acc[i].val[0] = vld1q_s32(acc_buffer_ptr + 4 * i); + acc[i].val[1] = vld1q_s32(acc_buffer_ptr + 4 * i + 8); + acc[i].val[2] = vld1q_s32(acc_buffer_ptr + 4 * i + 16); + } + // Multiply-accumulate + for (int j = 0; j < 3; j++) + { + acc[0].val[j] = + vmlal_s16(acc[0].val[j], vget_low_s16(input_dup3[j]), vget_low_s16(filter[j])); + acc[1].val[j] = + vmlal_s16(acc[1].val[j], vget_high_s16(input_dup3[j]), vget_high_s16(filter[j])); + } + // Store the accumulators back to acc_buffer + for (int i = 0; i < 2; i++) + { + vst1q_s32(acc_buffer_ptr + 4 * i, acc[i].val[0]); + vst1q_s32(acc_buffer_ptr + 4 * i + 8, acc[i].val[1]); + vst1q_s32(acc_buffer_ptr + 4 * i + 16, acc[i].val[2]); + } + acc_buffer_ptr += 24; + } + // Handle one input channel at a time. + for (; ic < input_depth; ic++) + { + const uint16_t input_val = *local_input_ptr++ + input_offset; + for (int i = 0; i < 3; i++) + { + const uint16_t filter_val = local_filter_ptr[i] + filter_offset; + *acc_buffer_ptr++ += static_cast(filter_val) * input_val; + } + local_filter_ptr += 3; + } + input_ptr += input_ptr_increment; + } + } +}; + +template <> struct QuantizedDepthwiseConvKernel +{ + static void Run(int num_output_pixels, int input_depth, int depth_multiplier, + const uint8_t *input_ptr, uint16_t input_offset, int input_ptr_increment, + const uint8_t *filter_ptr, uint16_t filter_offset, int32_t *acc_buffer_ptr) + { + (void)input_depth; + (void)depth_multiplier; + // Handle one output pixel at a time. + for (int outp = 0; outp < num_output_pixels; outp++) + { + const uint8_t *local_filter_ptr = filter_ptr; + const uint8_t *local_input_ptr = input_ptr; + int ic = 0; + // Handle 8 input channels at a time. + for (; ic <= input_depth - 8; ic += 8) + { + // Load the filters, add filter_offset. + int16x8_t filter[2]; + uint8x8x2_t filter_u8; + filter_u8.val[0] = vld1_u8(local_filter_ptr); + filter_u8.val[1] = vld1_u8(local_filter_ptr + 8); + local_filter_ptr += 16; + for (int i = 0; i < 2; i++) + { + const int16x8_t filter_s16 = vreinterpretq_s16_u16(vmovl_u8(filter_u8.val[i])); + filter[i] = vaddq_s16(filter_s16, vdupq_n_s16(filter_offset)); + } + // Load the inputs, add input_offset, duplicate 2-fold. + const uint8x8_t input_u8 = vld1_u8(local_input_ptr); + local_input_ptr += 8; + const int16x8_t input_s16 = vreinterpretq_s16_u16(vmovl_u8(input_u8)); + const int16x8_t input = vaddq_s16(input_s16, vdupq_n_s16(input_offset)); + const int16x8x2_t input_dup2 = vzipq_s16(input, input); + // Load the accumulators from acc_buffer. + int32x4x2_t acc[2]; + for (int i = 0; i < 2; i++) + { + acc[i].val[0] = vld1q_s32(acc_buffer_ptr + 4 * i); + acc[i].val[1] = vld1q_s32(acc_buffer_ptr + 4 * i + 8); + } + // Multiply-accumulate. + for (int j = 0; j < 2; j++) + { + acc[0].val[j] = + vmlal_s16(acc[0].val[j], vget_low_s16(filter[j]), vget_low_s16(input_dup2.val[j])); + acc[1].val[j] = + vmlal_s16(acc[1].val[j], vget_high_s16(filter[j]), vget_high_s16(input_dup2.val[j])); + } + // Store the accumulators back to acc_buffer. + for (int i = 0; i < 2; i++) + { + vst1q_s32(acc_buffer_ptr + 4 * i, acc[i].val[0]); + vst1q_s32(acc_buffer_ptr + 4 * i + 8, acc[i].val[1]); + } + acc_buffer_ptr += 16; + } + // Handle one input channel at a time. + for (; ic < input_depth; ic++) + { + // Load the inputs. + const uint16_t input_val = *local_input_ptr++ + input_offset; + for (int i = 0; i < 2; i++) + { + const uint16_t filter_val = local_filter_ptr[i] + filter_offset; + *acc_buffer_ptr++ += static_cast(filter_val) * input_val; + } + local_filter_ptr += 2; + } + input_ptr += input_ptr_increment; + } + } +}; + +template <> struct QuantizedDepthwiseConvKernel +{ + static void Run(int num_output_pixels, int input_depth, int depth_multiplier, + const uint8_t *input_ptr, uint16_t input_offset, int input_ptr_increment, + const uint8_t *filter_ptr, uint16_t filter_offset, int32_t *acc_buffer_ptr) + { + (void)input_depth; + (void)depth_multiplier; + // Handle one output pixel at a time. + for (int outp = 0; outp < num_output_pixels; outp++) + { + const uint8_t *local_filter_ptr = filter_ptr; + const uint8_t *local_input_ptr = input_ptr; + int ic = 0; + // Handle 16 input channels at a time. + for (; ic <= input_depth - 16; ic += 16) + { + // Load the filters, add filter_offset. + uint8x8_t filter_u8_0 = vld1_u8(local_filter_ptr + 8 * 0); + uint8x8_t filter_u8_1 = vld1_u8(local_filter_ptr + 8 * 1); + local_filter_ptr += 16; + int16x8_t filter_0 = vreinterpretq_s16_u16(vmovl_u8(filter_u8_0)); + int16x8_t filter_1 = vreinterpretq_s16_u16(vmovl_u8(filter_u8_1)); + filter_0 = vaddq_s16(filter_0, vdupq_n_s16(filter_offset)); + filter_1 = vaddq_s16(filter_1, vdupq_n_s16(filter_offset)); + // Load the inputs, add input_offset. + uint8x8_t input_u8_0 = vld1_u8(local_input_ptr + 8 * 0); + uint8x8_t input_u8_1 = vld1_u8(local_input_ptr + 8 * 1); + local_input_ptr += 16; + int16x8_t input_0 = vreinterpretq_s16_u16(vmovl_u8(input_u8_0)); + int16x8_t input_1 = vreinterpretq_s16_u16(vmovl_u8(input_u8_1)); + input_0 = vaddq_s16(input_0, vdupq_n_s16(input_offset)); + input_1 = vaddq_s16(input_1, vdupq_n_s16(input_offset)); + // Load the accumulators from acc_buffer + int32x4_t acc_0 = vld1q_s32(acc_buffer_ptr + 4 * 0); + int32x4_t acc_1 = vld1q_s32(acc_buffer_ptr + 4 * 1); + int32x4_t acc_2 = vld1q_s32(acc_buffer_ptr + 4 * 2); + int32x4_t acc_3 = vld1q_s32(acc_buffer_ptr + 4 * 3); + acc_0 = vmlal_s16(acc_0, vget_low_s16(input_0), vget_low_s16(filter_0)); + acc_1 = vmlal_s16(acc_1, vget_high_s16(input_0), vget_high_s16(filter_0)); + acc_2 = vmlal_s16(acc_2, vget_low_s16(input_1), vget_low_s16(filter_1)); + acc_3 = vmlal_s16(acc_3, vget_high_s16(input_1), vget_high_s16(filter_1)); + // Store the accumulators back to acc_buffer + vst1q_s32(acc_buffer_ptr + 4 * 0, acc_0); + vst1q_s32(acc_buffer_ptr + 4 * 1, acc_1); + vst1q_s32(acc_buffer_ptr + 4 * 2, acc_2); + vst1q_s32(acc_buffer_ptr + 4 * 3, acc_3); + acc_buffer_ptr += 16; + } + // Handle 8 input channels at a time. + for (; ic <= input_depth - 8; ic += 8) + { + // Load the filters, add filter_offset. + const uint8x8_t filter_u8 = vld1_u8(local_filter_ptr); + local_filter_ptr += 8; + const int16x8_t filter_s16 = vreinterpretq_s16_u16(vmovl_u8(filter_u8)); + const int16x8_t filter = vaddq_s16(filter_s16, vdupq_n_s16(filter_offset)); + // Load the inputs, add input_offset. + const uint8x8_t input_u8 = vld1_u8(local_input_ptr); + local_input_ptr += 8; + const int16x8_t input_s16 = vreinterpretq_s16_u16(vmovl_u8(input_u8)); + const int16x8_t input = vaddq_s16(input_s16, vdupq_n_s16(input_offset)); + // Load the accumulators from acc_buffer + int32x4_t acc[2]; + for (int i = 0; i < 2; i++) + { + acc[i] = vld1q_s32(acc_buffer_ptr + 4 * i); + } + // Multiply-accumulate + acc[0] = vmlal_s16(acc[0], vget_low_s16(input), vget_low_s16(filter)); + acc[1] = vmlal_s16(acc[1], vget_high_s16(input), vget_high_s16(filter)); + // Store the accumulators back to acc_buffer + for (int i = 0; i < 2; i++) + { + vst1q_s32(acc_buffer_ptr + 4 * i, acc[i]); + } + acc_buffer_ptr += 8; + } + // Handle one input channel at a time. + for (; ic < input_depth; ic++) + { + const uint16_t input_val = *local_input_ptr++ + input_offset; + const uint16_t filter_val = *local_filter_ptr++ + filter_offset; + *acc_buffer_ptr++ += static_cast(filter_val) * input_val; + } + input_ptr += input_ptr_increment; + } + } +}; + +template <> struct QuantizedDepthwiseConvKernel +{ + static void Run(int num_output_pixels, int input_depth, int depth_multiplier, + const uint8_t *input_ptr, uint16_t input_offset, int input_ptr_increment, + const uint8_t *filter_ptr, uint16_t filter_offset, int32_t *acc_buffer_ptr) + { + (void)input_depth; + (void)depth_multiplier; + // Load the filters, add filter_offset. + uint8x8_t filter_u8[2]; + for (int i = 0; i < 2; i++) + { + filter_u8[i] = vld1_u8(filter_ptr + 8 * i); + } + int16x8_t filter[2]; + for (int i = 0; i < 2; i++) + { + filter[i] = vreinterpretq_s16_u16(vmovl_u8(filter_u8[i])); + } + for (int i = 0; i < 2; i++) + { + filter[i] = vaddq_s16(filter[i], vdupq_n_s16(filter_offset)); + } + // Handle one output pixel at a time. + for (int outp = 0; outp < num_output_pixels; outp++) + { + // Load the inputs, add input_offset. + uint8x8_t input_u8[2]; + for (int i = 0; i < 2; i++) + { + input_u8[i] = vld1_u8(input_ptr + 8 * i); + } + input_ptr += input_ptr_increment; + int16x8_t input[2]; + for (int i = 0; i < 2; i++) + { + input[i] = vreinterpretq_s16_u16(vmovl_u8(input_u8[i])); + } + for (int i = 0; i < 2; i++) + { + input[i] = vaddq_s16(input[i], vdupq_n_s16(input_offset)); + } + // Load the accumulators from acc_buffer + int32x4_t acc[4]; + for (int i = 0; i < 4; i++) + { + acc[i] = vld1q_s32(acc_buffer_ptr + 4 * i); + } + // Multiply-accumulate + for (int i = 0; i < 2; i++) + { + acc[2 * i + 0] = vmlal_s16(acc[2 * i + 0], vget_low_s16(input[i]), vget_low_s16(filter[i])); + acc[2 * i + 1] = + vmlal_s16(acc[2 * i + 1], vget_high_s16(input[i]), vget_high_s16(filter[i])); + } + // Store the accumulators back to acc_buffer + for (int i = 0; i < 4; i++) + { + vst1q_s32(acc_buffer_ptr + 4 * i, acc[i]); + } + acc_buffer_ptr += 16; + } + } +}; + +template <> struct QuantizedDepthwiseConvKernel +{ + static void Run(int num_output_pixels, int input_depth, int depth_multiplier, + const uint8_t *input_ptr, uint16_t input_offset, int input_ptr_increment, + const uint8_t *filter_ptr, uint16_t filter_offset, int32_t *acc_buffer_ptr) + { + (void)input_depth; + (void)depth_multiplier; + // Load the filters, add filter_offset. + const uint8x8_t filter_u8 = vld1_u8(filter_ptr); + const int16x8_t filter_s16 = vreinterpretq_s16_u16(vmovl_u8(filter_u8)); + const int16x8_t filter = vaddq_s16(filter_s16, vdupq_n_s16(filter_offset)); + // Handle one output pixel at a time. + for (int outp = 0; outp < num_output_pixels; outp++) + { + // Load the inputs, add input_offset. + const uint8x8_t input_u8 = vld1_u8(input_ptr); + const int16x8_t input_s16 = vreinterpretq_s16_u16(vmovl_u8(input_u8)); + const int16x8_t input = vaddq_s16(input_s16, vdupq_n_s16(input_offset)); + // Load the accumulators from acc_buffer + int32x4_t acc[2]; + for (int i = 0; i < 2; i++) + { + acc[i] = vld1q_s32(acc_buffer_ptr + 4 * i); + } + // Multiply-accumulate + acc[0] = vmlal_s16(acc[0], vget_low_s16(input), vget_low_s16(filter)); + acc[1] = vmlal_s16(acc[1], vget_high_s16(input), vget_high_s16(filter)); + // Store the accumulators back to acc_buffer + for (int i = 0; i < 2; i++) + { + vst1q_s32(acc_buffer_ptr + 4 * i, acc[i]); + } + acc_buffer_ptr += 8; + input_ptr += input_ptr_increment; + } + } +}; + +template <> struct QuantizedDepthwiseConvKernel +{ + static void Run(int num_output_pixels, int input_depth, int depth_multiplier, + const uint8_t *input_ptr, uint16_t input_offset, int input_ptr_increment, + const uint8_t *filter_ptr, uint16_t filter_offset, int32_t *acc_buffer_ptr) + { + (void)input_depth; + (void)depth_multiplier; + // Load the filters, add filter_offset. + uint8x8_t filter_u8[2]; + for (int i = 0; i < 2; i++) + { + filter_u8[i] = vld1_u8(filter_ptr + 8 * i); + } + int16x8_t filter[2]; + for (int i = 0; i < 2; i++) + { + filter[i] = vreinterpretq_s16_u16(vmovl_u8(filter_u8[i])); + } + for (int i = 0; i < 2; i++) + { + filter[i] = vaddq_s16(filter[i], vdupq_n_s16(filter_offset)); + } + // Handle one output pixel at a time. + for (int outp = 0; outp < num_output_pixels; outp++) + { + uint8_t input_u8 = *input_ptr; + input_ptr += input_ptr_increment; + uint16_t input = static_cast(input_u8 + input_offset); + // Load the accumulators from acc_buffer + int32x4_t acc[4]; + for (int i = 0; i < 4; i++) + { + acc[i] = vld1q_s32(acc_buffer_ptr + 4 * i); + } + // Multiply-accumulate + for (int i = 0; i < 2; i++) + { + acc[2 * i + 0] = vmlal_n_s16(acc[2 * i + 0], vget_low_s16(filter[i]), input); + acc[2 * i + 1] = vmlal_n_s16(acc[2 * i + 1], vget_high_s16(filter[i]), input); + } + // Store the accumulators back to acc_buffer + for (int i = 0; i < 4; i++) + { + vst1q_s32(acc_buffer_ptr + 4 * i, acc[i]); + } + acc_buffer_ptr += 16; + } + } +}; + +template <> struct QuantizedDepthwiseConvKernel +{ + static void Run(int num_output_pixels, int input_depth, int depth_multiplier, + const uint8_t *input_ptr, uint16_t input_offset, int input_ptr_increment, + const uint8_t *filter_ptr, uint16_t filter_offset, int32_t *acc_buffer_ptr) + { + (void)input_depth; + (void)depth_multiplier; + // Load the filters, add filter_offset. + uint8x8_t filter_u8_0 = vld1_u8(filter_ptr + 8 * 0); + uint8x8_t filter_u8_1 = vld1_u8(filter_ptr + 8 * 1); + uint8x8_t filter_u8_2 = vld1_u8(filter_ptr + 8 * 2); + uint8x8_t filter_u8_3 = vld1_u8(filter_ptr + 8 * 3); + int16x8_t filter_0 = vreinterpretq_s16_u16(vmovl_u8(filter_u8_0)); + int16x8_t filter_1 = vreinterpretq_s16_u16(vmovl_u8(filter_u8_1)); + int16x8_t filter_2 = vreinterpretq_s16_u16(vmovl_u8(filter_u8_2)); + int16x8_t filter_3 = vreinterpretq_s16_u16(vmovl_u8(filter_u8_3)); + filter_0 = vaddq_s16(filter_0, vdupq_n_s16(filter_offset)); + filter_1 = vaddq_s16(filter_1, vdupq_n_s16(filter_offset)); + filter_2 = vaddq_s16(filter_2, vdupq_n_s16(filter_offset)); + filter_3 = vaddq_s16(filter_3, vdupq_n_s16(filter_offset)); + // Handle one output pixel at a time. + for (int outp = 0; outp < num_output_pixels; outp++) + { + uint8_t input_u8 = *input_ptr; + input_ptr += input_ptr_increment; + uint16_t input = static_cast(input_u8 + input_offset); + // Load the accumulators from acc_buffer + int32x4_t acc_0 = vld1q_s32(acc_buffer_ptr + 4 * 0); + int32x4_t acc_1 = vld1q_s32(acc_buffer_ptr + 4 * 1); + int32x4_t acc_2 = vld1q_s32(acc_buffer_ptr + 4 * 2); + int32x4_t acc_3 = vld1q_s32(acc_buffer_ptr + 4 * 3); + int32x4_t acc_4 = vld1q_s32(acc_buffer_ptr + 4 * 4); + int32x4_t acc_5 = vld1q_s32(acc_buffer_ptr + 4 * 5); + int32x4_t acc_6 = vld1q_s32(acc_buffer_ptr + 4 * 6); + int32x4_t acc_7 = vld1q_s32(acc_buffer_ptr + 4 * 7); + // Multiply-accumulate + acc_0 = vmlal_n_s16(acc_0, vget_low_s16(filter_0), input); + acc_1 = vmlal_n_s16(acc_1, vget_high_s16(filter_0), input); + acc_2 = vmlal_n_s16(acc_2, vget_low_s16(filter_1), input); + acc_3 = vmlal_n_s16(acc_3, vget_high_s16(filter_1), input); + acc_4 = vmlal_n_s16(acc_4, vget_low_s16(filter_2), input); + acc_5 = vmlal_n_s16(acc_5, vget_high_s16(filter_2), input); + acc_6 = vmlal_n_s16(acc_6, vget_low_s16(filter_3), input); + acc_7 = vmlal_n_s16(acc_7, vget_high_s16(filter_3), input); + // Store the accumulators back to acc_buffer + vst1q_s32(acc_buffer_ptr + 4 * 0, acc_0); + vst1q_s32(acc_buffer_ptr + 4 * 1, acc_1); + vst1q_s32(acc_buffer_ptr + 4 * 2, acc_2); + vst1q_s32(acc_buffer_ptr + 4 * 3, acc_3); + vst1q_s32(acc_buffer_ptr + 4 * 4, acc_4); + vst1q_s32(acc_buffer_ptr + 4 * 5, acc_5); + vst1q_s32(acc_buffer_ptr + 4 * 6, acc_6); + vst1q_s32(acc_buffer_ptr + 4 * 7, acc_7); + acc_buffer_ptr += 32; + } + } +}; + +template <> struct QuantizedDepthwiseConvKernel +{ + static void Run(int num_output_pixels, int input_depth, int depth_multiplier, + const uint8_t *input_ptr, uint16_t input_offset, int input_ptr_increment, + const uint8_t *filter_ptr, uint16_t filter_offset, int32_t *acc_buffer_ptr) + { + (void)input_depth; + (void)depth_multiplier; + // Load the filters, add filter_offset. + // NEON wants to load 8 bytes at a time, but 20 is not divisible by 8. + // We load the first 16 bytes into filter_u8_{0,1} as usual. + // Then we load the 8 last bytes into filter_u8_x (x for 'extra'). + // This is redundant: the first 4 bytes of filter_u8_x are the same + // as the last 4 bytes of filter_u8_x. + uint8x8_t filter_u8_0 = vld1_u8(filter_ptr + 8 * 0); + uint8x8_t filter_u8_1 = vld1_u8(filter_ptr + 8 * 1); + uint8x8_t filter_u8_x = vld1_u8(filter_ptr + 8 * 1 + 4); + int16x8_t filter_0 = vreinterpretq_s16_u16(vmovl_u8(filter_u8_0)); + int16x8_t filter_1 = vreinterpretq_s16_u16(vmovl_u8(filter_u8_1)); + int16x8_t filter_x = vreinterpretq_s16_u16(vmovl_u8(filter_u8_x)); + filter_0 = vaddq_s16(filter_0, vdupq_n_s16(filter_offset)); + filter_1 = vaddq_s16(filter_1, vdupq_n_s16(filter_offset)); + filter_x = vaddq_s16(filter_x, vdupq_n_s16(filter_offset)); + // Handle one output pixel at a time. + for (int outp = 0; outp < num_output_pixels; outp++) + { + uint8_t input_u8 = *input_ptr; + input_ptr += input_ptr_increment; + uint16_t input = static_cast(input_u8 + input_offset); + // Load the accumulators from acc_buffer + int32x4_t acc_0 = vld1q_s32(acc_buffer_ptr + 4 * 0); + int32x4_t acc_1 = vld1q_s32(acc_buffer_ptr + 4 * 1); + int32x4_t acc_2 = vld1q_s32(acc_buffer_ptr + 4 * 2); + int32x4_t acc_3 = vld1q_s32(acc_buffer_ptr + 4 * 3); + int32x4_t acc_4 = vld1q_s32(acc_buffer_ptr + 4 * 4); + // Multiply-accumulate + acc_0 = vmlal_n_s16(acc_0, vget_low_s16(filter_0), input); + acc_1 = vmlal_n_s16(acc_1, vget_high_s16(filter_0), input); + acc_2 = vmlal_n_s16(acc_2, vget_low_s16(filter_1), input); + acc_3 = vmlal_n_s16(acc_3, vget_high_s16(filter_1), input); + acc_4 = vmlal_n_s16(acc_4, vget_high_s16(filter_x), input); + // Store the accumulators back to acc_buffer + vst1q_s32(acc_buffer_ptr + 4 * 0, acc_0); + vst1q_s32(acc_buffer_ptr + 4 * 1, acc_1); + vst1q_s32(acc_buffer_ptr + 4 * 2, acc_2); + vst1q_s32(acc_buffer_ptr + 4 * 3, acc_3); + vst1q_s32(acc_buffer_ptr + 4 * 4, acc_4); + acc_buffer_ptr += 20; + } + } +}; + +template <> struct QuantizedDepthwiseConvKernel +{ + static void Run(int num_output_pixels, int input_depth, int depth_multiplier, + const uint8_t *input_ptr, uint16_t input_offset, int input_ptr_increment, + const uint8_t *filter_ptr, uint16_t filter_offset, int32_t *acc_buffer_ptr) + { + (void)input_depth; + (void)depth_multiplier; + // Load the filters, add filter_offset. + const uint8x8_t filter_u8 = vld1_u8(filter_ptr); + const int16x8_t filter = + vaddq_s16(vreinterpretq_s16_u16(vmovl_u8(filter_u8)), vdupq_n_s16(filter_offset)); + // Handle one output pixel at a time. + for (int outp = 0; outp < num_output_pixels; outp++) + { + uint8_t input_u8 = *input_ptr; + input_ptr += input_ptr_increment; + uint16_t input = static_cast(input_u8 + input_offset); + // Load the accumulators from acc_buffer + int32x4_t acc[2]; + for (int i = 0; i < 2; i++) + { + acc[i] = vld1q_s32(acc_buffer_ptr + 4 * i); + } + // Multiply-accumulate + acc[0] = vmlal_n_s16(acc[0], vget_low_s16(filter), input); + acc[1] = vmlal_n_s16(acc[1], vget_high_s16(filter), input); + // Store the accumulators back to acc_buffer + for (int i = 0; i < 2; i++) + { + vst1q_s32(acc_buffer_ptr + 4 * i, acc[i]); + } + acc_buffer_ptr += 8; + } + } +}; + +template <> struct QuantizedDepthwiseConvKernel +{ + static void Run(int num_output_pixels, int input_depth, int depth_multiplier, + const uint8_t *input_ptr, uint16_t input_offset, int input_ptr_increment, + const uint8_t *filter_ptr, uint16_t filter_offset, int32_t *acc_buffer_ptr) + { + (void)input_depth; + (void)depth_multiplier; + // Load the filters, add filter_offset. + uint8x8_t filter_u8 = vdup_n_u8(0); + filter_u8 = vset_lane_u8(filter_ptr[0], filter_u8, 0); + filter_u8 = vset_lane_u8(filter_ptr[1], filter_u8, 1); + filter_u8 = vset_lane_u8(filter_ptr[0], filter_u8, 2); + filter_u8 = vset_lane_u8(filter_ptr[1], filter_u8, 3); + const int16x4_t filter_s16 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(filter_u8))); + const int16x4_t filter = vadd_s16(filter_s16, vdup_n_s16(filter_offset)); + + int outp = 0; + + // Handle 2 output pixels at a time. + for (; outp <= num_output_pixels - 2; outp += 2) + { + // Load the accumulators from acc_buffer. + int32x4_t acc = vld1q_s32(acc_buffer_ptr); + // Load the inputs, add input_offset. + uint16x4_t input_u16 = vdup_n_u16(0); + input_u16 = vset_lane_u16((reinterpret_cast(input_ptr))[0], input_u16, 0); + input_ptr += input_ptr_increment; + input_u16 = vset_lane_u16((reinterpret_cast(input_ptr))[0], input_u16, 1); + input_ptr += input_ptr_increment; + const int16x4_t input_s16 = + vreinterpret_s16_u16(vget_low_u16(vmovl_u8(vreinterpret_u8_u16(input_u16)))); + const int16x4_t input = vadd_s16(input_s16, vdup_n_s16(input_offset)); + + // Multiply-accumulate. + acc = vmlal_s16(acc, filter, input); + // Store the accumulators back to acc_buffer. + vst1q_s32(acc_buffer_ptr, acc); + acc_buffer_ptr += 4; + } + + // Handle 1 output pixel at a time. + for (; outp < num_output_pixels; outp++) + { + // Load the accumulators from acc_buffer. + int32x2_t acc = vld1_s32(acc_buffer_ptr); + // Load the inputs, add input_offset. + uint8x8_t input_u8 = vdup_n_u8(0); + input_u8 = vset_lane_u8(input_ptr[0], input_u8, 0); + input_u8 = vset_lane_u8(input_ptr[1], input_u8, 1); + input_ptr += input_ptr_increment; + const int16x4_t input_s16 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(input_u8))); + const int16x4_t input = vadd_s16(input_s16, vdup_n_s16(input_offset)); + + // Multiply-accumulate. + acc = vget_low_s32(vmlal_s16(vcombine_s32(acc, acc), filter, input)); + // Store the accumulators back to acc_buffer. + vst1_s32(acc_buffer_ptr, acc); + acc_buffer_ptr += 2; + } + } +}; + +template <> struct QuantizedDepthwiseConvKernel +{ + static void Run(int num_output_pixels, int input_depth, int depth_multiplier, + const uint8_t *input_ptr, uint16_t input_offset, int input_ptr_increment, + const uint8_t *filter_ptr, uint16_t filter_offset, int32_t *acc_buffer_ptr) + { + (void)input_depth; + (void)depth_multiplier; + if (num_output_pixels <= 0) + { + return; + } + + // Load the filters, add filter_offset. + uint8x8_t filter_u8 = vdup_n_u8(0); + filter_u8 = vset_lane_u8(filter_ptr[0], filter_u8, 0); + filter_u8 = vset_lane_u8(filter_ptr[1], filter_u8, 1); + filter_u8 = vset_lane_u8(filter_ptr[2], filter_u8, 2); + filter_u8 = vset_lane_u8(filter_ptr[3], filter_u8, 3); + const int16x4_t filter_s16 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(filter_u8))); + const int16x4_t filter = vadd_s16(filter_s16, vdup_n_s16(filter_offset)); + + int outp = 0; + + // Handle one output pixel at a time until second to the last pixel. Second + // to the last because we read eight input pixels while only processing + // four. + for (; outp < num_output_pixels - 1; outp++) + { + // Load the accumulators from acc_buffer + int32x4_t acc; + acc = vld1q_s32(acc_buffer_ptr); + + // Load the inputs, add input_offset. + uint8x8_t input_u8 = vld1_u8(input_ptr); + input_ptr += input_ptr_increment; + const int16x4_t input_s16 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(input_u8))); + const int16x4_t input = vadd_s16(input_s16, vdup_n_s16(input_offset)); + // Multiply-accumulate + acc = vmlal_s16(acc, filter, input); + // Store the accumulators back to acc_buffer + vst1q_s32(acc_buffer_ptr, acc); + acc_buffer_ptr += 4; + } + + // Handle the last output pixel. + // Load the accumulators from acc_buffer + int32x4_t acc; + acc = vld1q_s32(acc_buffer_ptr); + + // Load the inputs, add input_offset. + uint8x8_t input_u8 = vdup_n_u8(0); + input_u8 = vset_lane_u8(input_ptr[0], input_u8, 0); + input_u8 = vset_lane_u8(input_ptr[1], input_u8, 1); + input_u8 = vset_lane_u8(input_ptr[2], input_u8, 2); + input_u8 = vset_lane_u8(input_ptr[3], input_u8, 3); + const int16x4_t input_s16 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(input_u8))); + const int16x4_t input = vadd_s16(input_s16, vdup_n_s16(input_offset)); + // Multiply-accumulate + acc = vmlal_s16(acc, filter, input); + // Store the accumulators back to acc_buffer + vst1q_s32(acc_buffer_ptr, acc); + } +}; + +template <> struct QuantizedDepthwiseConvKernel +{ + static void Run(int num_output_pixels, int input_depth, int depth_multiplier, + const uint8_t *input_ptr, uint16_t input_offset, int input_ptr_increment, + const uint8_t *filter_ptr, uint16_t filter_offset, int32_t *acc_buffer_ptr) + { + (void)input_depth; + (void)depth_multiplier; + // Load the filters, add filter_offset. + uint8x8_t filter_u8_0 = vld1_u8(filter_ptr); + uint8x8_t filter_u8_1 = vld1_u8(filter_ptr + 4); + int16x8_t filter_s16_0 = vreinterpretq_s16_u16(vmovl_u8(filter_u8_0)); + int16x8_t filter_s16_1 = vreinterpretq_s16_u16(vmovl_u8(filter_u8_1)); + filter_s16_0 = vaddq_s16(filter_s16_0, vdupq_n_s16(filter_offset)); + filter_s16_1 = vaddq_s16(filter_s16_1, vdupq_n_s16(filter_offset)); + int16x4_t filter_0 = vget_low_s16(filter_s16_0); + int16x4_t filter_1 = vget_high_s16(filter_s16_0); + int16x4_t filter_2 = vget_high_s16(filter_s16_1); + + // Handle one output pixel at a time. + for (int outp = 0; outp < num_output_pixels; outp++) + { + // Load the inputs, add input_offset. + uint8x8_t input_u8_0 = vld1_u8(input_ptr); + uint8x8_t input_u8_1 = vld1_u8(input_ptr + 4); + input_ptr += input_ptr_increment; + int16x8_t input_0 = vreinterpretq_s16_u16(vmovl_u8(input_u8_0)); + int16x8_t input_1 = vreinterpretq_s16_u16(vmovl_u8(input_u8_1)); + input_0 = vaddq_s16(input_0, vdupq_n_s16(input_offset)); + input_1 = vaddq_s16(input_1, vdupq_n_s16(input_offset)); + + // Load the accumulators from acc_buffer + int32x4_t acc_0 = vld1q_s32(acc_buffer_ptr + 4 * 0); + int32x4_t acc_1 = vld1q_s32(acc_buffer_ptr + 4 * 1); + int32x4_t acc_2 = vld1q_s32(acc_buffer_ptr + 4 * 2); + + // Multiply-accumulate + acc_0 = vmlal_s16(acc_0, vget_low_s16(input_0), filter_0); + acc_1 = vmlal_s16(acc_1, vget_high_s16(input_0), filter_1); + acc_2 = vmlal_s16(acc_2, vget_high_s16(input_1), filter_2); + + // Store the accumulators back to acc_buffer + vst1q_s32(acc_buffer_ptr + 4 * 0, acc_0); + vst1q_s32(acc_buffer_ptr + 4 * 1, acc_1); + vst1q_s32(acc_buffer_ptr + 4 * 2, acc_2); + + acc_buffer_ptr += 12; + } + } +}; +#endif + +// Accumulates the effect of one row of the filter, on a segment of one row +// of the output, accessing the corresponding one row of the input. +template +void QuantizedDepthwiseConvAccumRow(int stride, int dilation_factor, int input_depth, + int input_width, const uint8_t *input_data, + int16_t input_offset, int pad_width, int depth_multiplier, + int filter_width, const uint8_t *filter_data, + int16_t filter_offset, int out_x_buffer_start, + int out_x_buffer_end, int output_depth, int32_t *acc_buffer) +{ + // Sanity check parameters. This is important in particular to ensure + // that we keep the number of template instantiations minimal, so we don't + // increase binary size unnecessarily. + static_assert(kFixedDepthMultiplier || !kFixedInputDepth, ""); + static_assert(kFixedInputDepth || kAllowStrided, ""); + assert(stride == 1 || kAllowStrided); + if (kFixedInputDepth) + { + assert(input_depth == kFixedInputDepth); + } + if (kFixedDepthMultiplier) + { + assert(depth_multiplier == kFixedDepthMultiplier); + } + assert(output_depth == input_depth * depth_multiplier); + const int input_ptr_increment = stride * input_depth; + const uint8_t *filter_base_ptr = filter_data; + for (int filter_x = 0; filter_x < filter_width; ++filter_x) + { + // For the current (filter_x, filter_y) point in the filter, + // compute the boundaries of the corresponding output row segment. + int out_x_loop_start_unclampled = 0; + int out_x_loop_end_unclampled = 0; + if (kAllowStrided) + { + if (stride == 2) + { + out_x_loop_start_unclampled = (pad_width - dilation_factor * filter_x + 1) / 2; + out_x_loop_end_unclampled = (pad_width + input_width - dilation_factor * filter_x + 1) / 2; + } + else if (stride == 4) + { + out_x_loop_start_unclampled = (pad_width - dilation_factor * filter_x + 3) / 4; + out_x_loop_end_unclampled = (pad_width + input_width - dilation_factor * filter_x + 3) / 4; + } + else + { + out_x_loop_start_unclampled = + (pad_width - dilation_factor * filter_x + stride - 1) / stride; + out_x_loop_end_unclampled = + (pad_width + input_width - dilation_factor * filter_x + stride - 1) / stride; + } + } + else + { + out_x_loop_start_unclampled = pad_width - dilation_factor * filter_x; + out_x_loop_end_unclampled = pad_width + input_width - dilation_factor * filter_x; + } + // The kernel will have to iterate on the segment of the + // output row that starts at out_x_loop_start and out_x_loop_end. + const int out_x_loop_start = std::max(out_x_buffer_start, out_x_loop_start_unclampled); + const int out_x_loop_end = std::min(out_x_buffer_end, out_x_loop_end_unclampled); + + int32_t *acc_buffer_ptr = acc_buffer + (out_x_loop_start - out_x_buffer_start) * output_depth; + const int in_x_origin = (out_x_loop_start * stride) - pad_width + dilation_factor * filter_x; + const uint8_t *input_ptr = input_data + in_x_origin * input_depth; + const int num_output_pixels = out_x_loop_end - out_x_loop_start; + QuantizedDepthwiseConvKernel::Run( + num_output_pixels, input_depth, depth_multiplier, input_ptr, input_offset, + input_ptr_increment, filter_base_ptr, filter_offset, acc_buffer_ptr); + filter_base_ptr += output_depth; + } +} + +// generic fallback of DepthwiseConvAccumRow, portable, non-templatized. +inline void QuantizedDepthwiseConvAccumRowGeneric(int stride, int dilation_factor, int input_depth, + int input_width, const uint8_t *input_data, + int16_t input_offset, int pad_width, + int depth_multiplier, int filter_width, + const uint8_t *filter_data, int16_t filter_offset, + int out_x_buffer_start, int out_x_buffer_end, + int output_depth, int32_t *acc_buffer) +{ + const uint8_t *filter_base_ptr = filter_data; + for (int filter_x = 0; filter_x < filter_width; ++filter_x) + { + const int out_x_loop_start = std::max( + out_x_buffer_start, (pad_width - dilation_factor * filter_x + stride - 1) / stride); + const int out_x_loop_end = + std::min(out_x_buffer_end, + (pad_width + input_width - dilation_factor * filter_x + stride - 1) / stride); + + int32_t *acc_buffer_ptr = acc_buffer + (out_x_loop_start - out_x_buffer_start) * output_depth; + const int in_x_origin = (out_x_loop_start * stride) - pad_width + dilation_factor * filter_x; + const uint8_t *input_ptr = input_data + in_x_origin * input_depth; + const int input_ptr_increment = (stride - 1) * input_depth; + for (int out_x = out_x_loop_start; out_x < out_x_loop_end; out_x++) + { + const uint8_t *filter_ptr = filter_base_ptr; + for (int ic = 0; ic < input_depth; ++ic) + { + const int16_t input_val = *input_ptr++ + input_offset; + for (int m = 0; m < depth_multiplier; m++) + { + const int16_t filter_val = *filter_ptr++ + filter_offset; + *acc_buffer_ptr++ += static_cast(filter_val) * input_val; + } + } + input_ptr += input_ptr_increment; + } + filter_base_ptr += output_depth; + } +} + +// Initializes the accumulator buffer with bias values. +inline void DepthwiseConvInitAccBuffer(int num_output_pixels, int output_depth, + const int32_t *bias_data, int32_t *acc_buffer) +{ + int i = 0; +#ifdef USE_NEON + if (output_depth == 1) + { + const int32x4_t b = vdupq_n_s32(bias_data[0]); + for (; i <= num_output_pixels - 16; i += 16) + { + vst1q_s32(acc_buffer + i + 0, b); + vst1q_s32(acc_buffer + i + 4, b); + vst1q_s32(acc_buffer + i + 8, b); + vst1q_s32(acc_buffer + i + 12, b); + } + for (; i <= num_output_pixels - 4; i += 4) + { + vst1q_s32(acc_buffer + i, b); + } + } + else if (output_depth == 2) + { + int32x4_t b = vdupq_n_s32(bias_data[0]); + b = vsetq_lane_s32(bias_data[1], b, 1); + b = vsetq_lane_s32(bias_data[1], b, 3); + for (; i <= num_output_pixels - 8; i += 8) + { + vst1q_s32(acc_buffer + 2 * i + 0, b); + vst1q_s32(acc_buffer + 2 * i + 4, b); + vst1q_s32(acc_buffer + 2 * i + 8, b); + vst1q_s32(acc_buffer + 2 * i + 12, b); + } + for (; i <= num_output_pixels - 2; i += 2) + { + vst1q_s32(acc_buffer + 2 * i, b); + } + } + else if (output_depth == 4) + { + const int32x4_t b = vld1q_s32(bias_data); + for (; i <= num_output_pixels - 4; i += 4) + { + vst1q_s32(acc_buffer + 4 * i + 0, b); + vst1q_s32(acc_buffer + 4 * i + 4, b); + vst1q_s32(acc_buffer + 4 * i + 8, b); + vst1q_s32(acc_buffer + 4 * i + 12, b); + } + for (; i < num_output_pixels; i++) + { + vst1q_s32(acc_buffer + 4 * i, b); + } + } + else if (output_depth == 8) + { + const int32x4_t b0 = vld1q_s32(bias_data); + const int32x4_t b1 = vld1q_s32(bias_data + 4); + for (; i <= num_output_pixels - 2; i += 2) + { + vst1q_s32(acc_buffer + 8 * i + 0, b0); + vst1q_s32(acc_buffer + 8 * i + 4, b1); + vst1q_s32(acc_buffer + 8 * i + 8, b0); + vst1q_s32(acc_buffer + 8 * i + 12, b1); + } + for (; i < num_output_pixels; i++) + { + vst1q_s32(acc_buffer + 8 * i + 0, b0); + vst1q_s32(acc_buffer + 8 * i + 4, b1); + } + } + else if (output_depth == 16) + { + const int32x4_t b0 = vld1q_s32(bias_data); + const int32x4_t b1 = vld1q_s32(bias_data + 4); + const int32x4_t b2 = vld1q_s32(bias_data + 8); + const int32x4_t b3 = vld1q_s32(bias_data + 12); + for (; i < num_output_pixels; i++) + { + vst1q_s32(acc_buffer + 16 * i + 0, b0); + vst1q_s32(acc_buffer + 16 * i + 4, b1); + vst1q_s32(acc_buffer + 16 * i + 8, b2); + vst1q_s32(acc_buffer + 16 * i + 12, b3); + } + } +#endif + for (; i < num_output_pixels; i++) + { + memcpy(acc_buffer + i * output_depth, bias_data, sizeof(acc_buffer[0]) * output_depth); + } +} + +inline void DepthwiseConvGeneral(const DepthwiseConvParams ¶ms, const Shape &input_shape, + const uint8_t *input_data, const Shape &filter_shape, + const uint8_t *filter_data, const Shape &bias_shape, + const int32_t *bias_data, const Shape &output_shape, + uint8_t *output_data) +{ + (void)bias_shape; + const int stride_width = params.stride_width; + const int stride_height = params.stride_height; + const int pad_width = params.padding_values.width; + const int pad_height = params.padding_values.height; + const int depth_multiplier = params.depth_multiplier; + const int32_t output_activation_min = params.quantized_activation_min; + const int32_t output_activation_max = params.quantized_activation_max; + const int32_t input_offset = params.input_offset; + const int32_t filter_offset = params.weights_offset; + const int32_t output_offset = params.output_offset; + const int32_t output_multiplier = params.output_multiplier; + const int output_shift = params.output_shift; + const int dilation_width_factor = params.dilation_width_factor; + const int dilation_height_factor = params.dilation_height_factor; + const int batches = MatchingDim(input_shape, 0, output_shape, 0); + const int output_depth = MatchingDim(filter_shape, 3, output_shape, 3); + const int input_height = input_shape.Dims(1); + const int input_width = input_shape.Dims(2); + const int input_depth = input_shape.Dims(3); + const int filter_height = filter_shape.Dims(1); + const int filter_width = filter_shape.Dims(2); + const int output_height = output_shape.Dims(1); + const int output_width = output_shape.Dims(2); +#ifdef USE_NEON + const bool shift_left = (output_shift > 0); + const int32_t multiplier_power_of_two = shift_left ? (1 << output_shift) : 1; +#endif + + static const int kAccBufferMaxSize = 2048; + int32_t acc_buffer[kAccBufferMaxSize]; + assert(kAccBufferMaxSize >= output_depth); + const int kOutputPixelsInAccBuffer = kAccBufferMaxSize / output_depth; + const int kAccBufferActualSize = kOutputPixelsInAccBuffer * output_depth; + assert(kOutputPixelsInAccBuffer * output_depth <= kAccBufferActualSize); + assert(kAccBufferActualSize <= kAccBufferMaxSize); + assert(kOutputPixelsInAccBuffer >= 1); + UNUSED_RELEASE(kAccBufferActualSize); + + // row_accum_func will point to the core accumulation function to be used + // for this DepthwiseConv op. + using row_accum_func_t = decltype(&QuantizedDepthwiseConvAccumRowGeneric); + row_accum_func_t row_accum_func = nullptr; + +#define TFMINI_USE_DEPTHWISECONV_KERNEL(ALLOW_STRIDED, FIXED_INPUT_DEPTH, FIXED_DEPTH_MULTIPLIER) \ + if (!row_accum_func && (stride_width == 1 || ALLOW_STRIDED) && \ + (input_depth == FIXED_INPUT_DEPTH || FIXED_INPUT_DEPTH == 0) && \ + depth_multiplier == FIXED_DEPTH_MULTIPLIER) \ + { \ + row_accum_func = \ + QuantizedDepthwiseConvAccumRow; \ + } + +#ifdef USE_NEON + // We go over our list of kernels by decreasing order of preference + // for the cases where multiple kernels could apply. + + // Start with the fastest kernels: AllowStrided=false, fixed input depth. + + TFMINI_USE_DEPTHWISECONV_KERNEL(false, 1, 2) + TFMINI_USE_DEPTHWISECONV_KERNEL(false, 2, 2) + TFMINI_USE_DEPTHWISECONV_KERNEL(false, 4, 2) + TFMINI_USE_DEPTHWISECONV_KERNEL(false, 1, 4) + TFMINI_USE_DEPTHWISECONV_KERNEL(false, 4, 1) + TFMINI_USE_DEPTHWISECONV_KERNEL(false, 4, 4) + TFMINI_USE_DEPTHWISECONV_KERNEL(false, 8, 1) + TFMINI_USE_DEPTHWISECONV_KERNEL(false, 2, 8) + TFMINI_USE_DEPTHWISECONV_KERNEL(false, 2, 1) + TFMINI_USE_DEPTHWISECONV_KERNEL(false, 12, 1) + + // Next come the strided kernels: AllowStrided=true, fixed input depth. + // They are a bit less efficient, but allow stride!=1. + + TFMINI_USE_DEPTHWISECONV_KERNEL(true, 8, 2) + TFMINI_USE_DEPTHWISECONV_KERNEL(true, 16, 1) + TFMINI_USE_DEPTHWISECONV_KERNEL(true, 1, 16) + TFMINI_USE_DEPTHWISECONV_KERNEL(true, 1, 20) + TFMINI_USE_DEPTHWISECONV_KERNEL(true, 1, 32) + TFMINI_USE_DEPTHWISECONV_KERNEL(true, 1, 8) + TFMINI_USE_DEPTHWISECONV_KERNEL(true, 8, 1) + TFMINI_USE_DEPTHWISECONV_KERNEL(true, 2, 1) + TFMINI_USE_DEPTHWISECONV_KERNEL(true, 4, 1) + + // Finally, the kernels allowing a variable input depth, + // these are the least efficient but most general kernels. + + TFMINI_USE_DEPTHWISECONV_KERNEL(true, 0, 1) + TFMINI_USE_DEPTHWISECONV_KERNEL(true, 0, 2) + TFMINI_USE_DEPTHWISECONV_KERNEL(true, 0, 3) +#endif // USE_NEON + + // No matching fast kernel found, use slow fallback. + if (!row_accum_func) + { + row_accum_func = QuantizedDepthwiseConvAccumRowGeneric; + } + +#undef TFMINI_USE_DEPTHWISECONV_KERNEL + + const int input_height_stride = input_shape.Dims(3) * input_shape.Dims(2); + const int input_batch_stride = input_height_stride * input_shape.Dims(1); + const int filter_height_stride = filter_shape.Dims(3) * filter_shape.Dims(2); + + // Now that we have determined row_accum_func, we can start work. + uint8_t *output_ptr = output_data; + for (int b = 0; b < batches; ++b) + { + for (int out_y = 0; out_y < output_height; ++out_y) + { + const int in_y_origin = (out_y * stride_height) - pad_height; + const int filter_y_start = + std::max(0, (-in_y_origin + dilation_height_factor - 1) / dilation_height_factor); + const int filter_y_end = + std::min(filter_height, (input_height - in_y_origin + dilation_height_factor - 1) / + dilation_height_factor); + for (int out_x_buffer_start = 0; out_x_buffer_start < output_width; + out_x_buffer_start += kOutputPixelsInAccBuffer) + { + const int out_x_buffer_end = + std::min(output_width, out_x_buffer_start + kOutputPixelsInAccBuffer); + // We call a 'pixel' a group of activation that share all but the + // 'depth'/'channel' coordinate. num_output_pixels is the number of + // output pixels that we will accumulate in this loop iteration. + const int num_output_pixels = out_x_buffer_end - out_x_buffer_start; + // Initialize our local accumulator with the bias values, so we don't + // have to add them later. + DepthwiseConvInitAccBuffer(num_output_pixels, output_depth, bias_data, acc_buffer); + // Accumulation loop. Most of the time should be spent in here. + for (int filter_y = filter_y_start; filter_y < filter_y_end; ++filter_y) + { + const int in_y = in_y_origin + dilation_height_factor * filter_y; + row_accum_func(stride_width, dilation_width_factor, input_depth, input_width, + input_data + in_y * input_height_stride + b * input_batch_stride, + input_offset, pad_width, depth_multiplier, filter_width, + filter_data + filter_y * filter_height_stride, filter_offset, + out_x_buffer_start, out_x_buffer_end, output_depth, acc_buffer); + } + // Finished accumulating int32 values. Now need to convert them to + // the final 8bit form and store them. + const int num_output_values = output_depth * num_output_pixels; + int i = 0; +#ifdef USE_NEON + using gemmlowp::RoundingDivideByPOT; + const int32x4_t output_offset_vec = vdupq_n_s32(output_offset); + const int32x4_t output_activation_min_vec = vdupq_n_s32(output_activation_min); + const int32x4_t output_activation_max_vec = vdupq_n_s32(output_activation_max); + // Handle 16 values at once. + // This allows us to issue 4 mutually independent int32 + // multiplications (vqrdmulh), which should alleviate most of their + // high latency. + for (; i <= num_output_values - 16; i += 16) + { + int32x4_t acc[4]; + for (int j = 0; j < 4; j++) + { + acc[j] = vld1q_s32(acc_buffer + i + 4 * j); + } + + if (!shift_left) + { + // Fixed-point multiplication. + for (int j = 0; j < 4; j++) + { + acc[j] = vqrdmulhq_n_s32(acc[j], output_multiplier); + } + for (int j = 0; j < 4; j++) + { + acc[j] = RoundingDivideByPOT(acc[j], -output_shift); + } + } + else + { + // Fixed-point multiplication. + for (int j = 0; j < 4; j++) + { + acc[j] = vmulq_n_s32(acc[j], multiplier_power_of_two); + acc[j] = vqrdmulhq_n_s32(acc[j], output_multiplier); + } + } + // Add the output offset. + for (int j = 0; j < 4; j++) + { + acc[j] = vaddq_s32(acc[j], output_offset_vec); + } + // Apply the activation function. + for (int j = 0; j < 4; j++) + { + acc[j] = vmaxq_s32(acc[j], output_activation_min_vec); + } + for (int j = 0; j < 4; j++) + { + acc[j] = vminq_s32(acc[j], output_activation_max_vec); + } + // Saturating cast to uint8_t and store to destination. + int16x4_t acc_s16[4]; + for (int j = 0; j < 4; j++) + { + acc_s16[j] = vqmovn_s32(acc[j]); + } + const int16x8_t res_s16_0 = vcombine_s16(acc_s16[0], acc_s16[1]); + const int16x8_t res_s16_1 = vcombine_s16(acc_s16[2], acc_s16[3]); + const uint8x8_t res_u8_0 = vqmovun_s16(res_s16_0); + const uint8x8_t res_u8_1 = vqmovun_s16(res_s16_1); + vst1q_u8(output_ptr, vcombine_u8(res_u8_0, res_u8_1)); + output_ptr += 16; + } + // Handle 8 values at once. + // Not as good as 16 (now we're only issuing 2 mutually independent + // vqrdmulh instructions, so we're probably paying for their high + // latency). + for (; i <= num_output_values - 8; i += 8) + { + int32x4_t acc0 = vld1q_s32(acc_buffer + i); + int32x4_t acc1 = vld1q_s32(acc_buffer + i + 4); + if (!shift_left) + { + // Fixed-point multiplication. + acc0 = vqrdmulhq_n_s32(acc0, output_multiplier); + acc1 = vqrdmulhq_n_s32(acc1, output_multiplier); + // Rounding right shift. + acc0 = RoundingDivideByPOT(acc0, -output_shift); + acc1 = RoundingDivideByPOT(acc1, -output_shift); + } + else + { + // Fixed-point multiplication. + acc0 = vmulq_n_s32(acc0, multiplier_power_of_two); + acc0 = vqrdmulhq_n_s32(acc0, output_multiplier); + + acc1 = vmulq_n_s32(acc1, multiplier_power_of_two); + acc1 = vqrdmulhq_n_s32(acc1, output_multiplier); + } + // Add the output offset. + acc0 = vaddq_s32(acc0, output_offset_vec); + acc1 = vaddq_s32(acc1, output_offset_vec); + // Apply the activation function. + acc0 = vmaxq_s32(acc0, output_activation_min_vec); + acc1 = vmaxq_s32(acc1, output_activation_min_vec); + acc0 = vminq_s32(acc0, output_activation_max_vec); + acc1 = vminq_s32(acc1, output_activation_max_vec); + // Saturating cast to uint8_t and store to destination. + const int16x4_t acc0_s16 = vqmovn_s32(acc0); + const int16x4_t acc1_s16 = vqmovn_s32(acc1); + const int16x8_t res_s16 = vcombine_s16(acc0_s16, acc1_s16); + const uint8x8_t res_u8 = vqmovun_s16(res_s16); + vst1_u8(output_ptr, res_u8); + output_ptr += 8; + } + // Handle 4 values at once. Now we're paying the full price of the + // high latency of vqrdmulh. Also, storing only 4 bytes at the end + // (without any alignment) can only be done 1 byte at a time. + // Yet, that is still worth doing to minimize the amount of leftover + // that will have to go through the very slow scalar code. + for (; i <= num_output_values - 4; i += 4) + { + int32x4_t acc = vld1q_s32(acc_buffer + i); + if (!shift_left) + { + // Fixed-point multiplication. + acc = vqrdmulhq_n_s32(acc, output_multiplier); + // Rounding right shift. + acc = RoundingDivideByPOT(acc, -output_shift); + } + else + { + // Fixed-point multiplication. + acc = vmulq_n_s32(acc, multiplier_power_of_two); + acc = vqrdmulhq_n_s32(acc, output_multiplier); + } + // Add the output offset. + acc = vaddq_s32(acc, output_offset_vec); + // Apply the activation function. + acc = vmaxq_s32(acc, output_activation_min_vec); + acc = vminq_s32(acc, output_activation_max_vec); + // Saturating cast to uint8_t and store to destination. + const int16x4_t acc_s16 = vqmovn_s32(acc); + const int16x8_t res_s16 = vcombine_s16(acc_s16, acc_s16); + const uint8x8_t res_u8 = vqmovun_s16(res_s16); + vst1_lane_u8(output_ptr + 0, res_u8, 0); + vst1_lane_u8(output_ptr + 1, res_u8, 1); + vst1_lane_u8(output_ptr + 2, res_u8, 2); + vst1_lane_u8(output_ptr + 3, res_u8, 3); + output_ptr += 4; + } +#endif // USE_NEON + + // Handle leftover values, one by one. This is very slow. + for (; i < num_output_values; i++) + { + int32_t acc = acc_buffer[i]; + acc = MultiplyByQuantizedMultiplier(acc, output_multiplier, output_shift); + acc += output_offset; + acc = std::max(acc, output_activation_min); + acc = std::min(acc, output_activation_max); + *output_ptr++ = static_cast(acc); + } + } + } + } +} + +} // namespace optimized +} // namespace cker +} // namespace nnfw + +#endif // __NNFW_CKER_OPTIMIZED_DEPTHWISE_CONV_UINT8_H__ diff --git a/compute/cker/include/cker/operation/optimized/OptimizedUtils.h b/compute/cker/include/cker/operation/optimized/OptimizedUtils.h new file mode 100644 index 00000000000..3f4ff8afb08 --- /dev/null +++ b/compute/cker/include/cker/operation/optimized/OptimizedUtils.h @@ -0,0 +1,176 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved + * Copyright 2018 The TensorFlow Authors. 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 __NNFW_CKER_OPTIMIZED_OPTIMIZED_UTILS_H__ +#define __NNFW_CKER_OPTIMIZED_OPTIMIZED_UTILS_H__ + +#include "cker/Types.h" +#include "cker/Shape.h" + +#include + +namespace nnfw +{ +namespace cker +{ +namespace optimized +{ + +template +inline void ExtractPatchIntoBufferColumn(const Shape &input_shape, int w, int h, int b, int kheight, + int kwidth, int stride_width, int stride_height, + int pad_width, int pad_height, int in_width, int in_height, + int in_depth, int single_buffer_length, int buffer_id, + const T *in_data, T *conv_buffer_data, uint8_t zero_byte) +{ + assert(input_shape.DimensionsCount() == 4); + // This chunk of code reshapes all the inputs corresponding to + // output (b, h, w) to a column vector in conv_buffer(:, buffer_id). + const int kwidth_times_indepth = kwidth * in_depth; + const int inwidth_times_indepth = in_width * in_depth; + const int ih_ungated_start = h * stride_height - pad_height; + const int ih_ungated_end = (ih_ungated_start + kheight); + const int ih_end = std::min(ih_ungated_end, in_height); + const int iw_ungated_start = w * stride_width - pad_width; + const int iw_ungated_end = (iw_ungated_start + kwidth); + const int iw_end = std::min(iw_ungated_end, in_width); + // If the patch is off the edge of the input image, skip writing those rows + // and columns from the patch into the output array. + const int h_offset = std::max(0, -ih_ungated_start); + const int w_offset = std::max(0, -iw_ungated_start); + const int ih_start = std::max(0, ih_ungated_start); + const int iw_start = std::max(0, iw_ungated_start); + const int single_row_num = std::min(kwidth - w_offset, in_width - iw_start) * in_depth; + const int output_row_offset = (buffer_id * single_buffer_length); + int out_offset = output_row_offset + (h_offset * kwidth + w_offset) * in_depth; + int in_offset = Offset(input_shape, b, ih_start, iw_start, 0); + + // Express all of the calculations as padding around the input patch. + const int top_padding = h_offset; + const int bottom_padding = (ih_ungated_end - ih_end); + const int left_padding = w_offset; + const int right_padding = (iw_ungated_end - iw_end); + assert(single_row_num == ((kwidth - (left_padding + right_padding)) * in_depth)); + + // Write out zeroes to the elements representing the top rows of the input + // patch that are off the edge of the input image. + if (top_padding > 0) + { + const int top_row_elements = (top_padding * kwidth * in_depth); + memset(conv_buffer_data + output_row_offset, zero_byte, (top_row_elements * sizeof(T))); + } + + // If the patch is on the interior of the input image horizontally, just copy + // over the rows sequentially, otherwise add zero padding at the start or end. + if ((left_padding == 0) && (right_padding == 0)) + { + for (int ih = ih_start; ih < ih_end; ++ih) + { + memcpy(conv_buffer_data + out_offset, in_data + in_offset, single_row_num * sizeof(T)); + out_offset += kwidth_times_indepth; + in_offset += inwidth_times_indepth; + } + } + else + { + for (int ih = ih_start; ih < ih_end; ++ih) + { + if (left_padding > 0) + { + const int left_start = (out_offset - (left_padding * in_depth)); + memset(conv_buffer_data + left_start, zero_byte, (left_padding * in_depth * sizeof(T))); + } + memcpy(conv_buffer_data + out_offset, in_data + in_offset, single_row_num * sizeof(T)); + if (right_padding > 0) + { + const int right_start = (out_offset + single_row_num); + memset(conv_buffer_data + right_start, zero_byte, (right_padding * in_depth * sizeof(T))); + } + out_offset += kwidth_times_indepth; + in_offset += inwidth_times_indepth; + } + } + + // If the bottom of the patch falls off the input image, pad the values + // representing those input rows with zeroes. + if (bottom_padding > 0) + { + const int bottom_row_elements = (bottom_padding * kwidth * in_depth); + const int bottom_start = + output_row_offset + ((top_padding + (ih_end - ih_start)) * kwidth * in_depth); + memset(conv_buffer_data + bottom_start, zero_byte, (bottom_row_elements * sizeof(T))); + } +} + +template +void DilatedIm2col(const ConvParams ¶ms, uint8_t zero_byte, const Shape &input_shape, + const T *input_data, const Shape &filter_shape, const Shape &output_shape, + T *im2col_data) +{ + (void)params; + (void)zero_byte; + (void)input_shape; + (void)input_data; + (void)filter_shape; + (void)output_shape; + (void)im2col_data; + throw std::runtime_error{"NYI: cker DilatedIm2col"}; +} + +template +void Im2col(const ConvParams ¶ms, int kheight, int kwidth, uint8_t zero_byte, + const Shape &input_shape, const T *input_data, const Shape &output_shape, + T *output_data) +{ + const int stride_width = params.stride_width; + const int stride_height = params.stride_height; + const int pad_width = params.padding_values.width; + const int pad_height = params.padding_values.height; + assert(input_shape.DimensionsCount() == 4); + assert(output_shape.DimensionsCount() == 4); + + const int batches = MatchingDim(input_shape, 0, output_shape, 0); + const int input_depth = input_shape.Dims(3); + const int input_width = input_shape.Dims(2); + const int input_height = input_shape.Dims(1); + const int output_depth = output_shape.Dims(3); + const int output_width = output_shape.Dims(2); + const int output_height = output_shape.Dims(1); + + int buffer_id = 0; + // Loop over the output nodes. + for (int b = 0; b < batches; ++b) + { + for (int h = 0; h < output_height; ++h) + { + for (int w = 0; w < output_width; ++w) + { + ExtractPatchIntoBufferColumn(input_shape, w, h, b, kheight, kwidth, stride_width, + stride_height, pad_width, pad_height, input_width, + input_height, input_depth, output_depth, buffer_id, input_data, + output_data, zero_byte); + ++buffer_id; + } + } + } +} + +} // namespace optimized +} // namespace cker +} // namespace nnfw + +#endif // __NNFW_CKER_OPTIMIZED_OPTIMIZED_UTILS_H__ diff --git a/compute/cker/include/cker/operation/reference/Conv.h b/compute/cker/include/cker/operation/reference/Conv.h index 32820002bc6..86e8b5143b5 100644 --- a/compute/cker/include/cker/operation/reference/Conv.h +++ b/compute/cker/include/cker/operation/reference/Conv.h @@ -106,6 +106,90 @@ inline void Conv(const ConvParams ¶ms, const Shape &input_shape, const float } } +inline void Conv(const ConvParams ¶ms, const Shape &input_shape, const uint8_t *input_data, + const Shape &filter_shape, const uint8_t *filter_data, const Shape &bias_shape, + const int32_t *bias_data, const Shape &output_shape, uint8_t *output_data) +{ + const int stride_width = params.stride_width; + const int stride_height = params.stride_height; + const int dilation_width_factor = params.dilation_width_factor; + const int dilation_height_factor = params.dilation_height_factor; + const int pad_width = params.padding_values.width; + const int pad_height = params.padding_values.height; + const int32_t input_offset = params.input_offset; + const int32_t filter_offset = params.weights_offset; + const int32_t output_offset = params.output_offset; + const int32_t output_multiplier = params.output_multiplier; + const int output_shift = params.output_shift; + const int32_t output_activation_min = params.quantized_activation_min; + const int32_t output_activation_max = params.quantized_activation_max; + assert(output_activation_min <= output_activation_max); + + assert(input_shape.DimensionsCount() == 4); + assert(filter_shape.DimensionsCount() == 4); + assert(output_shape.DimensionsCount() == 4); + UNUSED_RELEASE(bias_shape); + const int batches = MatchingDim(input_shape, 0, output_shape, 0); + const int input_depth = MatchingDim(input_shape, 3, filter_shape, 3); + const int output_depth = MatchingDim(filter_shape, 0, output_shape, 3); + if (bias_data) + { + assert(bias_shape.FlatSize() == output_depth); + } + const int input_height = input_shape.Dims(1); + const int input_width = input_shape.Dims(2); + const int filter_height = filter_shape.Dims(1); + const int filter_width = filter_shape.Dims(2); + const int output_height = output_shape.Dims(1); + const int output_width = output_shape.Dims(2); + for (int batch = 0; batch < batches; ++batch) + { + for (int out_y = 0; out_y < output_height; ++out_y) + { + for (int out_x = 0; out_x < output_width; ++out_x) + { + for (int out_channel = 0; out_channel < output_depth; ++out_channel) + { + const int in_x_origin = (out_x * stride_width) - pad_width; + const int in_y_origin = (out_y * stride_height) - pad_height; + int32_t acc = 0; + for (int filter_y = 0; filter_y < filter_height; ++filter_y) + { + for (int filter_x = 0; filter_x < filter_width; ++filter_x) + { + const int in_x = in_x_origin + dilation_width_factor * filter_x; + const int in_y = in_y_origin + dilation_height_factor * filter_y; + // If the location is outside the bounds of the input image, + // use zero as a default value. + if ((in_x >= 0) && (in_x < input_width) && (in_y >= 0) && (in_y < input_height)) + { + const int in_base = Offset(input_shape, batch, in_y, in_x, 0); + const int filter_base = Offset(filter_shape, out_channel, filter_y, filter_x, 0); + for (int in_channel = 0; in_channel < input_depth; in_channel++) + { + int32_t input_val = input_data[in_channel + in_base]; + int32_t filter_val = filter_data[in_channel + filter_base]; + acc += (filter_val + filter_offset) * (input_val + input_offset); + } + } + } + } + if (bias_data) + { + acc += bias_data[out_channel]; + } + acc = MultiplyByQuantizedMultiplier(acc, output_multiplier, output_shift); + acc += output_offset; + acc = std::max(acc, output_activation_min); + acc = std::min(acc, output_activation_max); + output_data[Offset(output_shape, batch, out_y, out_x, out_channel)] = + static_cast(acc); + } + } + } + } +} + } // namespace reference } // namespace cker } // namespace nnfw diff --git a/infra/cmake/packages/NNPACKSourceConfig.cmake b/infra/cmake/packages/NNPACKSourceConfig.cmake index 68c8234432b..10a08ea7c41 100644 --- a/infra/cmake/packages/NNPACKSourceConfig.cmake +++ b/infra/cmake/packages/NNPACKSourceConfig.cmake @@ -1,7 +1,7 @@ function(_NNPACKSource_import) if(NOT DOWNLOAD_NNPACK) set(NNPACKSource_FOUND FALSE PARENT_SCOPE) - message(WARN "NNPACK not downloaded") + message(WARNING "NNPACK not downloaded") return() endif(NOT DOWNLOAD_NNPACK) diff --git a/infra/cmake/packages/TensorFlowSource-2.1.0/TensorFlowSourceConfig.cmake b/infra/cmake/packages/TensorFlowSource-2.1.0/TensorFlowSourceConfig.cmake new file mode 100644 index 00000000000..0d2a95056df --- /dev/null +++ b/infra/cmake/packages/TensorFlowSource-2.1.0/TensorFlowSourceConfig.cmake @@ -0,0 +1,18 @@ +function(_TensorFlowSource_import) + if(NOT DOWNLOAD_TENSORFLOW) + set(TensorFlowSource_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT DOWNLOAD_TENSORFLOW) + + nnas_include(ExternalSourceTools) + nnas_include(OptionTools) + + envoption(TENSORFLOW_2_1_0_URL https://github.com/tensorflow/tensorflow/archive/v2.1.0.tar.gz) + + ExternalSource_Download(TENSORFLOW DIRNAME TENSORFLOW-2.1.0 ${TENSORFLOW_2_1_0_URL}) + + set(TensorFlowSource_DIR ${TENSORFLOW_SOURCE_DIR} PARENT_SCOPE) + set(TensorFlowSource_FOUND TRUE PARENT_SCOPE) +endfunction(_TensorFlowSource_import) + +_TensorFlowSource_import() diff --git a/infra/cmake/packages/TensorFlowSource-2.1.0/TensorFlowSourceConfigVersion.cmake b/infra/cmake/packages/TensorFlowSource-2.1.0/TensorFlowSourceConfigVersion.cmake new file mode 100644 index 00000000000..80f43dde814 --- /dev/null +++ b/infra/cmake/packages/TensorFlowSource-2.1.0/TensorFlowSourceConfigVersion.cmake @@ -0,0 +1,10 @@ +set(PACKAGE_VERSION "2.1.0") +set(PACKAGE_VERSION_EXACT FALSE) +set(PACKAGE_VERSION_COMPATIBLE FALSE) +set(PACKAGE_VERSION_UNSUITABLE TRUE) + +if(PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION) + set(PACKAGE_VERSION_EXACT TRUE) + set(PACKAGE_VERSION_COMPATIBLE TRUE) + set(PACKAGE_VERSION_UNSUITABLE FALSE) +endif(PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION) diff --git a/infra/command/format b/infra/command/format index 6c67ed1d53c..9fe4753718d 100644 --- a/infra/command/format +++ b/infra/command/format @@ -6,15 +6,19 @@ DIRECTORIES_TO_BE_TESTED=() DIRECTORIES_NOT_TO_BE_TESTED=() CLANG_FORMAT_CANDIDATES=() PATCH_FILE=format.patch +CHECK_DIFF_ONLY="0" +CHECK_STAGED_ONLY="0" function Usage() { - echo "Usage: $0 $(basename ${BASH_SOURCE[0]}) [OPTIONS] [ ...]" + echo "Usage: $0 $(basename ${BASH_SOURCE[0]}) [OPTIONS] [ ...]" echo "If no arguments are specified, it formats all nnas codes" echo "If s are given, it reformats the files" echo "" echo "Options:" - echo " --clang-format clang format bin (default: clang-format-3.9, clang-format)" + echo " --clang-format clang format bin (default: clang-format-3.9, clang-format)" + echo " --diff-only check diff files with master" + echo " --staged-only check git staged files" } while [[ $# -gt 0 ]] @@ -29,6 +33,19 @@ do CLANG_FORMAT_CANDIDATES=($2) shift 2 ;; + --clang-format=*) + CLANG_FORMAT_CANDIDATES=(${1#*=}) + shift + ;; + --staged-only) + CHECK_STAGED_ONLY="1" + CHECK_DIFF_ONLY="1" + shift + ;; + --diff-only) + CHECK_DIFF_ONLY="1" + shift + ;; *) DIRECTORIES_TO_BE_TESTED+=($1) shift diff --git a/infra/command/gen-coverage-report b/infra/command/gen-coverage-report index 5d3552422d3..c3a8202e7f5 100644 --- a/infra/command/gen-coverage-report +++ b/infra/command/gen-coverage-report @@ -70,6 +70,10 @@ done "${LCOV_PATH}" -r "${EXTRACTED_COVERAGE_INFO_PATH}" -o "${EXCLUDED_COVERAGE_INFO_PATH}" \ '*.test.cpp' +# Exclude flatbuffer generated files from coverage report +"${LCOV_PATH}" -r "${EXTRACTED_COVERAGE_INFO_PATH}" -o "${EXCLUDED_COVERAGE_INFO_PATH}" \ + '*_schema_generated.h' + # Final coverage data cp -v ${EXCLUDED_COVERAGE_INFO_PATH} ${COVERAGE_INFO_PATH} diff --git a/infra/docker/Dockerfile b/infra/docker/Dockerfile index 3b11e384563..e675b53ad4c 100644 --- a/infra/docker/Dockerfile +++ b/infra/docker/Dockerfile @@ -21,7 +21,7 @@ RUN apt-get update && apt-get -qqy install libboost-all-dev libgflags-dev libgoo RUN apt-get update && apt-get -qqy install libprotobuf-dev protobuf-compiler # Additonal tools -RUN apt-get update && apt-get -qqy install doxygen graphviz wget unzip clang-format-3.9 python3 python3-pip hdf5-tools pylint +RUN apt-get update && apt-get -qqy install doxygen graphviz wget unzip clang-format-3.9 python3 python3-pip python3-venv hdf5-tools pylint RUN pip3 install yapf==0.22.0 numpy # Install google test (source) diff --git a/infra/docker/Dockerfile.1804 b/infra/docker/Dockerfile.1804 index 2c60c8fddf3..fc6fc9a1a52 100644 --- a/infra/docker/Dockerfile.1804 +++ b/infra/docker/Dockerfile.1804 @@ -21,7 +21,7 @@ RUN apt-get update && apt-get -qqy install libboost-all-dev libgflags-dev libgoo RUN apt-get update && apt-get -qqy install libprotobuf-dev protobuf-compiler # Additonal tools -RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -qqy install doxygen graphviz wget unzip clang-format-3.9 python3 python3-pip hdf5-tools pylint +RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -qqy install doxygen graphviz wget unzip clang-format-3.9 python3 python3-pip python3-venv hdf5-tools pylint RUN pip3 install yapf==0.22.0 numpy # Install google test (source) diff --git a/infra/doxygen/Doxyfile b/infra/doxygen/Doxyfile index 844c441b20d..0dc6fdfff00 100644 --- a/infra/doxygen/Doxyfile +++ b/infra/doxygen/Doxyfile @@ -1487,7 +1487,7 @@ DISABLE_INDEX = NO # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. -GENERATE_TREEVIEW = NO +GENERATE_TREEVIEW = YES # The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that # doxygen will group on one line in the generated HTML documentation. diff --git a/infra/git-hooks/pre-commit.sh b/infra/git-hooks/pre-commit.sh index 73466c5ec6c..127245da124 100755 --- a/infra/git-hooks/pre-commit.sh +++ b/infra/git-hooks/pre-commit.sh @@ -27,6 +27,6 @@ url="$2" REPO_PATH=$(git rev-parse --show-toplevel) cd $REPO_PATH -CHECK_DIFF_ONLY=1 CHECK_STAGED_ONLY=1 ./nnas format +./nnas format --staged-only exit $? diff --git a/infra/git-hooks/pre-push.sh b/infra/git-hooks/pre-push.sh index ce751333a2d..d64c723176a 100755 --- a/infra/git-hooks/pre-push.sh +++ b/infra/git-hooks/pre-push.sh @@ -27,6 +27,6 @@ url="$2" REPO_PATH=$(git rev-parse --show-toplevel) cd $REPO_PATH -CHECK_DIFF_ONLY=1 ./nnas format +./nnas format --diff-only exit $? diff --git a/infra/nncc/command/utcount b/infra/nncc/command/utcount new file mode 100644 index 00000000000..917f2f1cd08 --- /dev/null +++ b/infra/nncc/command/utcount @@ -0,0 +1,40 @@ +#!/bin/bash + +import "build.configuration" + +BUILD_WORKSPACE_PATH="${NNCC_PROJECT_PATH}/${BUILD_WORKSPACE_RPATH}" + +if [[ ! -d "${BUILD_WORKSPACE_PATH}" ]]; then + echo "'${BUILD_WORKSPACE_RPATH}' does not exist. Please run 'configure' first" + exit 255 +fi + +BUILD_ITEMS="angkor cwrap pepper-str pepper-strcast pp stdex \ +oops pepper-assert \ +hermes hermes-std \ +loco locop locomotiv logo-core logo \ +safemain mio-circle mio-tflite \ +tflite2circle \ +luci" + +function count_all() +{ + local result=`ctest --verbose | grep -c '\[ RUN \]'` + echo $result +} + +function count_neg() +{ + local result=`ctest --verbose | grep '\[ RUN \]' | grep -c '_NEG'` + echo $result +} + +export CTEST_OUTPUT_ON_FAILURE=0 + +for item in $BUILD_ITEMS +do + cd ${BUILD_WORKSPACE_PATH}/compiler/$item && + printf "$item = " && + res="$(count_all)" && printf "$res " && + res="$(count_neg)" && echo "$res" +done diff --git a/infra/nnfw/CMakeLists.txt b/infra/nnfw/CMakeLists.txt index 4108f3e2a00..4375735418d 100644 --- a/infra/nnfw/CMakeLists.txt +++ b/infra/nnfw/CMakeLists.txt @@ -92,6 +92,12 @@ if(ENABLE_STRICT_BUILD) target_compile_options(nnfw_common INTERFACE -Werror -Wall -Wextra) endif(ENABLE_STRICT_BUILD) +macro(nnfw_strict_build TARGET) + if(ENABLE_STRICT_BUILD) + target_compile_options(${TARGET} PRIVATE -Werror -Wall -Wextra) + endif(ENABLE_STRICT_BUILD) +endmacro(nnfw_strict_build) + # TODO Replace using default build option setting in cmake/buildtool/config/config_linux.cmake # to link nnfw_coverage on each module which want to check coverage add_library(nnfw_coverage INTERFACE) diff --git a/infra/nnfw/cmake/ApplyCompileFlags.cmake b/infra/nnfw/cmake/ApplyCompileFlags.cmake index 956ddfe1c4c..0ee7e8ef0e3 100644 --- a/infra/nnfw/cmake/ApplyCompileFlags.cmake +++ b/infra/nnfw/cmake/ApplyCompileFlags.cmake @@ -16,7 +16,7 @@ set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG") # # Platform specific compile flag setting # -include("cmake/buildtool/config/config_${TARGET_PLATFORM}.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/buildtool/config/config_${TARGET_PLATFORM}.cmake") # # Apply compile flags diff --git a/infra/nnfw/cmake/CfgOptionFlags.cmake b/infra/nnfw/cmake/CfgOptionFlags.cmake index e6c190a0b40..794fcc355ff 100644 --- a/infra/nnfw/cmake/CfgOptionFlags.cmake +++ b/infra/nnfw/cmake/CfgOptionFlags.cmake @@ -13,7 +13,7 @@ include("cmake/options/options_${TARGET_PLATFORM}.cmake") option(ENABLE_STRICT_BUILD "Treat warning as error" ON) option(ENABLE_COVERAGE "Build for coverage test" OFF) option(BUILD_EXT_MULTITHREAD "Build external build using multi thread" ON) -option(BUILD_NEURUN "Build neurun" ON) +option(BUILD_ONERT "Build onert" ON) option(BUILD_LOGGING "Build logging runtime" ON) option(BUILD_PURE_ARM_COMPUTE "Build pure_arm_compute runtime" OFF) CMAKE_DEPENDENT_OPTION(BUILD_RUNTIME_NNAPI_TEST "Build Runtime NN API Generated Test" @@ -32,7 +32,7 @@ option(BUILD_TFLITE_LOADER "Build TensorFlow Lite loader" ON) option(BUILD_CIRCLE_LOADER "Build circle loader" ON) option(BUILD_TFLITE_LOADER_TEST_TOOL "Build tflite loader testing tool" ON) option(GENERATE_RUNTIME_NNAPI_TESTS "Generate NNAPI operation gtest" ON) -option(ENVVAR_NEURUN_CONFIG "Use environment variable for neurun configuration" ON) +option(ENVVAR_ONERT_CONFIG "Use environment variable for onert configuration" ON) option(INSTALL_TEST_SCRIPTS "Install test scripts" ON) # # Default build configuration for contrib diff --git a/infra/nnfw/cmake/buildtool/config/config_armv7l-linux.cmake b/infra/nnfw/cmake/buildtool/config/config_armv7l-linux.cmake index 6d6459f0fd6..9a0b5e52877 100644 --- a/infra/nnfw/cmake/buildtool/config/config_armv7l-linux.cmake +++ b/infra/nnfw/cmake/buildtool/config/config_armv7l-linux.cmake @@ -5,7 +5,7 @@ message(STATUS "Building for ARMv7l Linux") # include linux common -include("cmake/buildtool/config/config_linux.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/config_linux.cmake") # addition for arm-linux set(FLAGS_COMMON ${FLAGS_COMMON} diff --git a/infra/nnfw/cmake/options/options_aarch64-android.cmake b/infra/nnfw/cmake/options/options_aarch64-android.cmake index 2393764a1ae..903267b7264 100644 --- a/infra/nnfw/cmake/options/options_aarch64-android.cmake +++ b/infra/nnfw/cmake/options/options_aarch64-android.cmake @@ -13,5 +13,3 @@ option(BUILD_NNPACKAGE_RUN "Build nnpackge_run" OFF) option(BUILD_TFLITE_RUN "Build tflite-run" OFF) option(BUILD_TFLITE_LOADER_TEST_TOOL "Build tflite loader testing tool" OFF) option(BUILD_LOGGING "Build logging runtime" OFF) - -option(ENABLE_STRICT_BUILD "Treat warning as error" OFF) diff --git a/infra/nnfw/cmake/options/options_aarch64-tizen.cmake b/infra/nnfw/cmake/options/options_aarch64-tizen.cmake index 23eecbc467c..4499fcd1b42 100644 --- a/infra/nnfw/cmake/options/options_aarch64-tizen.cmake +++ b/infra/nnfw/cmake/options/options_aarch64-tizen.cmake @@ -12,4 +12,4 @@ option(BUILD_TFLITE_RUN "Build tflite-run" OFF) option(BUILD_TFLITE_LOADER_TEST_TOOL "Build tflite loader testing tool" OFF) option(BUILD_SRCN_KERNEL "Build srcn kernel" ON) option(GENERATE_RUNTIME_NNAPI_TESTS "Generate NNAPI operation gtest" OFF) -option(ENVVAR_NEURUN_CONFIG "Use environment variable for neurun configuration" OFF) +option(ENVVAR_ONERT_CONFIG "Use environment variable for onert configuration" OFF) diff --git a/infra/nnfw/cmake/options/options_armv7l-tizen.cmake b/infra/nnfw/cmake/options/options_armv7l-tizen.cmake index fdb5d2d0751..e1e4e68f538 100644 --- a/infra/nnfw/cmake/options/options_armv7l-tizen.cmake +++ b/infra/nnfw/cmake/options/options_armv7l-tizen.cmake @@ -10,4 +10,4 @@ option(BUILD_LOGGING "Build logging runtime" OFF) option(BUILD_TFLITE_RUN "Build tflite-run" OFF) option(BUILD_SRCN_KERNEL "Build srcn kernel" ON) option(GENERATE_RUNTIME_NNAPI_TESTS "Generate NNAPI operation gtest" OFF) -option(ENVVAR_NEURUN_CONFIG "Use environment variable for neurun configuration" OFF) +option(ENVVAR_ONERT_CONFIG "Use environment variable for onert configuration" OFF) diff --git a/infra/nnfw/cmake/packages/GEMMLowpConfig.cmake b/infra/nnfw/cmake/packages/GEMMLowpConfig.cmake new file mode 100644 index 00000000000..ddfcc787eeb --- /dev/null +++ b/infra/nnfw/cmake/packages/GEMMLowpConfig.cmake @@ -0,0 +1,20 @@ +function(_GEMMLowp_import) + nnfw_find_package(GEMMLowpSource QUIET) + + if(NOT GEMMLowpSource_FOUND) + set(GEMMLowp_FOUND FALSE PARENT_SCOPE) + return() + endif(NOT GEMMLowpSource_FOUND) + + if(NOT TARGET gemmlowp) + find_package(Threads REQUIRED) + + add_library(gemmlowp INTERFACE) + target_include_directories(gemmlowp SYSTEM INTERFACE ${GEMMLowpSource_DIR}) + target_link_libraries(gemmlowp INTERFACE ${LIB_PTHREAD}) + endif(NOT TARGET gemmlowp) + + set(GEMMLowp_FOUND TRUE PARENT_SCOPE) +endfunction(_GEMMLowp_import) + +_GEMMLowp_import() diff --git a/infra/nnfw/command/gen-coverage-report b/infra/nnfw/command/gen-coverage-report deleted file mode 100644 index 8fd398db32e..00000000000 --- a/infra/nnfw/command/gen-coverage-report +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/bash - -# This file is based on https://github.sec.samsung.net/STAR/nncc/pull/80 - -LCOV_PATH=$(command -v lcov) -GENHTML_PATH=$(command -v genhtml) - -SRC_PREFIX=${SRC_PREFIX:-${NNFW_PROJECT_PATH}} - -if [[ -z "${LCOV_PATH}" ]]; then - echo "ERROR: 'lcov' is not found" - exit 255 -fi - -if [[ -z "${GENHTML_PATH}" ]]; then - echo "ERROR: 'genhtml' is not found" - exit 255 -fi - -if [[ -z "${GCOV_PATH}" ]]; then - GCOV_PATH=$(command -v gcov) - if [[ -z "${GCOV_PATH}" ]]; then - echo "ERROR: 'gcov' is not found" - exit 255 - fi -fi - -OUTPUT_PATH="$1" - -if [[ -z "${OUTPUT_PATH}" ]]; then - OUTPUT_PATH="$NNFW_PROJECT_PATH/coverage" -fi - -if [[ -e "${OUTPUT_PATH}" ]]; then - echo "ERROR: '${OUTPUT_PATH}' already exists" - exit 255 -fi - -mkdir -p "${OUTPUT_PATH}" - -RAW_COVERAGE_INFO_PATH="${OUTPUT_PATH}/coverage.raw.info" -LIBS_COVERAGE_INFO_PATH="${OUTPUT_PATH}/coverage.libs.info" -INCLUDE_COVERAGE_INFO_PATH="${OUTPUT_PATH}/coverage.include.info" -RUNTIMES_COVERAGE_INFO_PATH="${OUTPUT_PATH}/coverage.runtimes.info" -TOOLS_COVERAGE_INFO_PATH="${OUTPUT_PATH}/coverage.tools.info" -FINAL_COVERAGE_INFO_PATH="${OUTPUT_PATH}/coverage.info" -HTML_PATH="${OUTPUT_PATH}/html" -COVERTURA_PATH="${OUTPUT_PATH}/nnfw_coverage.xml" - -"${LCOV_PATH}" -c -d "${NNFW_PROJECT_PATH}" --gcov-tool ${GCOV_PATH} -o "${RAW_COVERAGE_INFO_PATH}" -#"${LCOV_PATH}" -e "${RAW_COVERAGE_INFO_PATH}" -o "${LIBS_COVERAGE_INFO_PATH}" "${SRC_PREFIX}/libs/*" -#"${LCOV_PATH}" -e "${RAW_COVERAGE_INFO_PATH}" -o "${INCLUDE_COVERAGE_INFO_PATH}" "${SRC_PREFIX}/include/*" -"${LCOV_PATH}" -e "${RAW_COVERAGE_INFO_PATH}" -o "${RUNTIMES_COVERAGE_INFO_PATH}" "${SRC_PREFIX}/runtimes/*" -"${LCOV_PATH}" -e "${RAW_COVERAGE_INFO_PATH}" -o "${TOOLS_COVERAGE_INFO_PATH}" "${SRC_PREFIX}/tests/tools/*" -#"${LCOV_PATH}" -a "${LIBS_COVERAGE_INFO_PATH}" -a "${INCLUDE_COVERAGE_INFO_PATH}" \ -# -a "${RUNTIMES_COVERAGE_INFO_PATH}" -a "${TOOLS_COVERAGE_INFO_PATH}" \ -# -o "${FINAL_COVERAGE_INFO_PATH}" -"${LCOV_PATH}" -a "${RUNTIMES_COVERAGE_INFO_PATH}" -a "${TOOLS_COVERAGE_INFO_PATH}" -o "${FINAL_COVERAGE_INFO_PATH}" -"${GENHTML_PATH}" "${FINAL_COVERAGE_INFO_PATH}" --output-directory "${HTML_PATH}" ${GENHTML_FLAG:-} diff --git a/infra/scripts/build_android_neurun_release.sh b/infra/scripts/build_android_runtime_release.sh similarity index 100% rename from infra/scripts/build_android_neurun_release.sh rename to infra/scripts/build_android_runtime_release.sh diff --git a/infra/scripts/common.sh b/infra/scripts/common.sh old mode 100644 new mode 100755 diff --git a/infra/scripts/docker_build_cross_aarch64_neurun.sh b/infra/scripts/docker_build_cross_aarch64_runtime.sh similarity index 100% rename from infra/scripts/docker_build_cross_aarch64_neurun.sh rename to infra/scripts/docker_build_cross_aarch64_runtime.sh diff --git a/infra/scripts/docker_build_cross_arm_benchmark_model.sh b/infra/scripts/docker_build_cross_arm_benchmark_model.sh index 9a511741da2..f63edf118f9 100755 --- a/infra/scripts/docker_build_cross_arm_benchmark_model.sh +++ b/infra/scripts/docker_build_cross_arm_benchmark_model.sh @@ -43,7 +43,7 @@ pushd $ROOT_PATH > /dev/null # TODO use command instead of makefile export DOCKER_ENV_VARS export DOCKER_VOLUMES -CMD="export OPTIONS='-DBUILD_PURE_ARM_COMPUTE=ON -DBUILD_NEURUN=OFF -DBUILD_TFLITE_BENCHMARK_MODEL=ON -DBUILD_TFLITE_LOADER=OFF' && \ +CMD="export OPTIONS='-DBUILD_PURE_ARM_COMPUTE=ON -DBUILD_ONERT=OFF -DBUILD_TFLITE_BENCHMARK_MODEL=ON -DBUILD_TFLITE_LOADER=OFF' && \ cp -nv Makefile.template Makefile && \ make all install build_test_suite" ./nnfw docker-run bash -c "$CMD" diff --git a/infra/scripts/docker_build_cross_arm_neurun.sh b/infra/scripts/docker_build_cross_arm_runtime.sh similarity index 100% rename from infra/scripts/docker_build_cross_arm_neurun.sh rename to infra/scripts/docker_build_cross_arm_runtime.sh diff --git a/infra/scripts/docker_build_cross_arm_neurun_release.sh b/infra/scripts/docker_build_cross_arm_runtime_release.sh similarity index 100% rename from infra/scripts/docker_build_cross_arm_neurun_release.sh rename to infra/scripts/docker_build_cross_arm_runtime_release.sh diff --git a/infra/scripts/docker_build_test_x64.sh b/infra/scripts/docker_build_test_x64.sh index 96fbf3154d3..eb620df953d 100755 --- a/infra/scripts/docker_build_test_x64.sh +++ b/infra/scripts/docker_build_test_x64.sh @@ -44,6 +44,6 @@ fi export DOCKER_ENV_VARS=" -e MODELFILE_SERVER=$MODELFILE_SERVER" ./nnfw docker-run-user ./infra/scripts/test_ubuntu_runtime.sh --backend cpu -./nnfw docker-run-user ./infra/scripts/test_neurun_interp.sh +./nnfw docker-run-user ./infra/scripts/test_ubuntu_runtime_interp.sh popd > /dev/null diff --git a/infra/scripts/test_aarch64_neurun_acl_cl.sh b/infra/scripts/test_aarch64_neurun_acl_cl.sh deleted file mode 100755 index 7c307cd61f0..00000000000 --- a/infra/scripts/test_aarch64_neurun_acl_cl.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -### -### This script will be deprecated -### - -CURRENT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -ROOT_PATH="$CURRENT_PATH/../../" - -set -eo pipefail - -# Test tflite_loader -pushd ${ROOT_PATH} > /dev/null - -./infra/scripts/test_ubuntu_runtime.sh --backend acl_cl --tflite-loader - -popd > /dev/null - diff --git a/infra/scripts/test_aarch64_neurun_acl_neon.sh b/infra/scripts/test_aarch64_neurun_acl_neon.sh deleted file mode 100755 index b57030549c6..00000000000 --- a/infra/scripts/test_aarch64_neurun_acl_neon.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -### -### This script will be deprecated -### - -CURRENT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -ROOT_PATH="$CURRENT_PATH/../../" - -set -eo pipefail - -# Test tflite_loader -pushd ${ROOT_PATH} > /dev/null - -./infra/scripts/test_ubuntu_runtime.sh --backend acl_neon - -# TODO Independent test when supporting ops are increased -export NCNN_LAYOUT="NCHW" -./infra/scripts/test_ubuntu_runtime.sh --backend srcn --linear-only -unset NCNN_LAYOUT - -popd > /dev/null diff --git a/infra/scripts/test_aarch64_neurun_cpu.sh b/infra/scripts/test_aarch64_neurun_cpu.sh deleted file mode 100755 index 33d6fd273f6..00000000000 --- a/infra/scripts/test_aarch64_neurun_cpu.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -### -### This script will be deprecated -### - -CURRENT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -ROOT_PATH="$CURRENT_PATH/../../" - -set -eo pipefail - -# Test tflite_loader -pushd ${ROOT_PATH} > /dev/null - -./infra/scripts/test_ubuntu_runtime.sh --backend cpu - -popd > /dev/null diff --git a/infra/scripts/test_arm_neurun_acl_cl.sh b/infra/scripts/test_arm_neurun_acl_cl.sh deleted file mode 100755 index 853c1daf470..00000000000 --- a/infra/scripts/test_arm_neurun_acl_cl.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -### -### This script will be deprecated -### - -CURRENT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -ROOT_PATH="$CURRENT_PATH/../../" - -set -eo pipefail - -# Test tflite_loader -pushd ${ROOT_PATH} > /dev/null - -./infra/scripts/test_ubuntu_runtime.sh --backend acl_cl --tflite-loader - -popd > /dev/null diff --git a/infra/scripts/test_arm_neurun_acl_neon.sh b/infra/scripts/test_arm_neurun_acl_neon.sh deleted file mode 100755 index b57030549c6..00000000000 --- a/infra/scripts/test_arm_neurun_acl_neon.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -### -### This script will be deprecated -### - -CURRENT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -ROOT_PATH="$CURRENT_PATH/../../" - -set -eo pipefail - -# Test tflite_loader -pushd ${ROOT_PATH} > /dev/null - -./infra/scripts/test_ubuntu_runtime.sh --backend acl_neon - -# TODO Independent test when supporting ops are increased -export NCNN_LAYOUT="NCHW" -./infra/scripts/test_ubuntu_runtime.sh --backend srcn --linear-only -unset NCNN_LAYOUT - -popd > /dev/null diff --git a/infra/scripts/test_arm_neurun_cpu.sh b/infra/scripts/test_arm_neurun_cpu.sh deleted file mode 100755 index 33d6fd273f6..00000000000 --- a/infra/scripts/test_arm_neurun_cpu.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -### -### This script will be deprecated -### - -CURRENT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -ROOT_PATH="$CURRENT_PATH/../../" - -set -eo pipefail - -# Test tflite_loader -pushd ${ROOT_PATH} > /dev/null - -./infra/scripts/test_ubuntu_runtime.sh --backend cpu - -popd > /dev/null diff --git a/infra/scripts/test_arm_neurun_mixed.sh b/infra/scripts/test_arm_neurun_mixed.sh deleted file mode 100755 index 900b401a838..00000000000 --- a/infra/scripts/test_arm_neurun_mixed.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash - -set -eo pipefail -source "$(dirname "${BASH_SOURCE[0]}")/common.sh" - -CheckTestPrepared - -pushd ${ROOT_PATH} - -# NOTE Fixed backend assignment by type of operation -# TODO Enhance this with randomized test -BACKENDS=(acl_cl acl_neon cpu) - -# Get the intersect of framework test list files -TESTLIST_PREFIX="tests/scripts/list/neurun_frameworktest_list.armv7l" -SKIPLIST_PREFIX="Product/out/unittest/nnapi_gtest.skip.armv7l-linux" -sort $TESTLIST_PREFIX.${BACKENDS[0]}.txt > $TESTLIST_PREFIX.intersect.txt -sort $SKIPLIST_PREFIX.${BACKENDS[0]} > $SKIPLIST_PREFIX.union -for BACKEND in "${BACKENDS[@]:1}"; do - comm -12 <(sort $TESTLIST_PREFIX.intersect.txt) <(sort $TESTLIST_PREFIX.$BACKEND.txt) > $TESTLIST_PREFIX.intersect.next.txt - comm <(sort $SKIPLIST_PREFIX.union) <(sort $SKIPLIST_PREFIX.$BACKEND) | tr -d "[:blank:]" > $SKIPLIST_PREFIX.union.next - mv $TESTLIST_PREFIX.intersect.next.txt $TESTLIST_PREFIX.intersect.txt - mv $SKIPLIST_PREFIX.union.next $SKIPLIST_PREFIX.union -done -popd > /dev/null - -# Run the test -export OP_BACKEND_Conv2D="cpu" -export OP_BACKEND_MaxPool2D="acl_cl" -export OP_BACKEND_AvgPool2D="acl_neon" -export ACL_LAYOUT="NCHW" -export NCNN_LAYOUT="NCHW" -Unittests "acl_cl;acl_neon;cpu" "Product/out/unittest/nnapi_gtest.skip.armv7l-linux.union" "report/mixed" -TFLiteModelVerification "acl_cl;acl_neon;cpu" "${TESTLIST_PREFIX}.intersect.txt" "report/mixed" diff --git a/infra/scripts/test_coverage.sh b/infra/scripts/test_coverage.sh index 9f948e40a2a..773122e9b52 100755 --- a/infra/scripts/test_coverage.sh +++ b/infra/scripts/test_coverage.sh @@ -24,19 +24,19 @@ if [[ ! -e $ROOT_PATH/tests/scripts/build_path_depth.txt ]]; then fi export GCOV_PREFIX_STRIP=`cat $ROOT_PATH/tests/scripts/build_path_depth.txt` -./infra/scripts/test_arm_neurun_acl_cl.sh -./infra/scripts/test_arm_neurun_acl_neon.sh -./infra/scripts/test_arm_neurun_cpu.sh +./infra/scripts/test_ubuntu_runtime.sh --backend acl_cl --tflite-loader +./infra/scripts/test_ubuntu_runtime.sh --backend acl_neon +./infra/scripts/test_ubuntu_runtime.sh --backend cpu # Enable all logs (mixed backend) -TENSOR_LOGGING=trace_log.txt NEURUN_LOG_ENABLE=1 GRAPH_DOT_DUMP=1 ./infra/scripts/test_arm_neurun_mixed.sh +TENSOR_LOGGING=trace_log.txt ONERT_LOG_ENABLE=1 GRAPH_DOT_DUMP=1 ./infra/scripts/test_ubuntu_runtime_mixed.sh # Enable trace event (acl_cl default backend) export TRACE_FILEPATH=trace.json -TFLiteModelVerification "acl_cl" "tests/scripts/list/neurun_frameworktest_list.armv7l.acl_cl.txt" "report/acl_cl/trace" +TFLiteModelVerification "acl_cl" "tests/scripts/list/frameworktest_list.armv7l.acl_cl.txt" "report/acl_cl/trace" unset TRACE_FILEPATH # Interpreter -./infra/scripts/test_neurun_interp.sh +./infra/scripts/test_ubuntu_runtime_interp.sh # nnpackage test suite if [[ -e ${ARCHIVE_PATH}/nnpkg-test-suite.tar.gz ]]; then diff --git a/infra/scripts/test_ubuntu_runtime.sh b/infra/scripts/test_ubuntu_runtime.sh index 0b627053324..d4190bd8026 100755 --- a/infra/scripts/test_ubuntu_runtime.sh +++ b/infra/scripts/test_ubuntu_runtime.sh @@ -4,7 +4,7 @@ set -eo pipefail source "$(dirname "${BASH_SOURCE[0]}")/common.sh" BACKEND="cpu" -TEST_ARCH=$(uname -p | tr '[:upper:]' '[:lower:]') +TEST_ARCH=$(uname -m | tr '[:upper:]' '[:lower:]') TEST_OS="linux" TFLITE_LOADER="0" LINEAR_ONLY="0" @@ -31,6 +31,10 @@ do BACKEND=$(echo $2 | tr '[:upper:]' '[:lower:]') shift 2 ;; + --backend=*) + BACKEND=$(echo ${1#*=} | tr '[:upper:]' '[:lower:]') + shift + ;; --tflite-loader) TFLITE_LOADER="1" shift @@ -49,7 +53,7 @@ done CheckTestPrepared echo "[[ ${TEST_ARCH}-${TEST_OS}: ${BACKEND} backend test ]]" UNITTEST_SKIPLIST="Product/out/unittest/nnapi_gtest.skip.${TEST_ARCH}-${TEST_OS}.${BACKEND}" -FRAMEWORK_TESTLIST="tests/scripts/list/neurun_frameworktest_list.${TEST_ARCH}.${BACKEND}.txt" +FRAMEWORK_TESTLIST="tests/scripts/list/frameworktest_list.${TEST_ARCH}.${BACKEND}.txt" REPORT_BASE="report/${BACKEND}" EXECUTORS=("Linear" "Dataflow" "Parallel") if [ $LINEAR_ONLY = "1" ]; then diff --git a/infra/scripts/test_neurun_interp.sh b/infra/scripts/test_ubuntu_runtime_interp.sh similarity index 70% rename from infra/scripts/test_neurun_interp.sh rename to infra/scripts/test_ubuntu_runtime_interp.sh index b21886da1eb..4113b0653bd 100755 --- a/infra/scripts/test_neurun_interp.sh +++ b/infra/scripts/test_ubuntu_runtime_interp.sh @@ -7,6 +7,6 @@ export DISABLE_COMPILE=1 CheckTestPrepared echo "[[ Interpreter test ]]" Unittests "cpu" "Product/out/unittest/nnapi_gtest.skip.noarch.interp" "report/interp" -TFLiteModelVerification "cpu" "tests/scripts/list/neurun_frameworktest_list.noarch.interp.txt" "report/interp" +TFLiteModelVerification "cpu" "tests/scripts/list/frameworktest_list.noarch.interp.txt" "report/interp" unset DISABLE_COMPILE diff --git a/infra/scripts/test_aarch64_neurun_mixed.sh b/infra/scripts/test_ubuntu_runtime_mixed.sh similarity index 79% rename from infra/scripts/test_aarch64_neurun_mixed.sh rename to infra/scripts/test_ubuntu_runtime_mixed.sh index e0d6287573a..71b33deb503 100755 --- a/infra/scripts/test_aarch64_neurun_mixed.sh +++ b/infra/scripts/test_ubuntu_runtime_mixed.sh @@ -5,6 +5,10 @@ source "$(dirname "${BASH_SOURCE[0]}")/common.sh" CheckTestPrepared +# TODO Get argument for mix configuration +TEST_ARCH=$(uname -m | tr '[:upper:]' '[:lower:]') +TEST_OS="linux" + pushd ${ROOT_PATH} # NOTE Fixed backend assignment by type of operation @@ -12,8 +16,8 @@ pushd ${ROOT_PATH} BACKENDS=(acl_cl acl_neon cpu) # Get the intersect of framework test list files -TESTLIST_PREFIX="tests/scripts/list/neurun_frameworktest_list.aarch64" -SKIPLIST_PREFIX="Product/out/unittest/nnapi_gtest.skip.aarch64-linux" +TESTLIST_PREFIX="tests/scripts/list/frameworktest_list.${TEST_ARCH}" +SKIPLIST_PREFIX="Product/out/unittest/nnapi_gtest.skip.${TEST_ARCH}-${TEST_OS}" sort $TESTLIST_PREFIX.${BACKENDS[0]}.txt > $TESTLIST_PREFIX.intersect.txt sort $SKIPLIST_PREFIX.${BACKENDS[0]} > $SKIPLIST_PREFIX.union for BACKEND in "${BACKENDS[@]:1}"; do @@ -29,6 +33,5 @@ export OP_BACKEND_Conv2D="cpu" export OP_BACKEND_MaxPool2D="acl_cl" export OP_BACKEND_AvgPool2D="acl_neon" export ACL_LAYOUT="NCHW" -export NCNN_LAYOUT="NCHW" -Unittests "acl_cl;acl_neon;cpu" "Product/out/unittest/nnapi_gtest.skip.aarch64-linux.union" "report/mixed" +Unittests "acl_cl;acl_neon;cpu" "Product/out/unittest/nnapi_gtest.skip.${TEST_ARCH}-${TEST_OS}.union" "report/mixed" TFLiteModelVerification "acl_cl;acl_neon;cpu" "${TESTLIST_PREFIX}.intersect.txt" "report/mixed" diff --git a/infra/scripts/tizen_xu4_test.sh b/infra/scripts/tizen_xu4_test.sh index 396bc5ac07a..6a479b7894c 100755 --- a/infra/scripts/tizen_xu4_test.sh +++ b/infra/scripts/tizen_xu4_test.sh @@ -120,11 +120,11 @@ else fi if [ -z "${GCOV_DIR}" ]; then - ${SDB_CMD} shell /bin/bash -c "IGNORE_MD5=1 ${TEST_ROOT}/infra/scripts/test_arm_neurun_acl_cl.sh" - ${SDB_CMD} shell /bin/bash -c "IGNORE_MD5=1 ${TEST_ROOT}/infra/scripts/test_arm_neurun_acl_neon.sh" - ${SDB_CMD} shell /bin/bash -c "IGNORE_MD5=1 ${TEST_ROOT}/infra/scripts/test_arm_neurun_cpu.sh" - ${SDB_CMD} shell /bin/bash -c "IGNORE_MD5=1 ${TEST_ROOT}/infra/scripts/test_arm_neurun_mixed.sh" - ${SDB_CMD} shell /bin/bash -c "IGNORE_MD5=1 ${TEST_ROOT}/infra/scripts/test_neurun_interp.sh" + ${SDB_CMD} shell /bin/bash -c "IGNORE_MD5=1 ${TEST_ROOT}/infra/scripts/test_ubuntu_runtime.sh --backend acl_cl --tflite-loader" + ${SDB_CMD} shell /bin/bash -c "IGNORE_MD5=1 ${TEST_ROOT}/infra/scripts/test_ubuntu_runtime.sh --backend acl_neon" + ${SDB_CMD} shell /bin/bash -c "IGNORE_MD5=1 ${TEST_ROOT}/infra/scripts/test_ubuntu_runtime.sh --backend cpu" + ${SDB_CMD} shell /bin/bash -c "IGNORE_MD5=1 ${TEST_ROOT}/infra/scripts/test_ubuntu_runtime_mixed.sh" + ${SDB_CMD} shell /bin/bash -c "IGNORE_MD5=1 ${TEST_ROOT}/infra/scripts/test_ubuntu_runtime_interp.sh" else mkdir -p ${GCOV_DIR} rm -rf ${GCOV_DIR}/* @@ -136,11 +136,11 @@ else GCOV_DATA_PATH="/opt/usr/nnfw-gcov" # TODO For coverage check, we run acl_cl and mixed test - ${SDB_CMD} shell /bin/bash -c "GCOV_PREFIX_STRIP=${GCOV_PREFIX_STRIP} IGNORE_MD5=1 ${TEST_ROOT}/infra/scripts/test_arm_neurun_acl_cl.sh" - ${SDB_CMD} shell /bin/bash -c "GCOV_PREFIX_STRIP=${GCOV_PREFIX_STRIP} IGNORE_MD5=1 ${TEST_ROOT}/infra/scripts/test_arm_neurun_acl_neon.sh" - ${SDB_CMD} shell /bin/bash -c "GCOV_PREFIX_STRIP=${GCOV_PREFIX_STRIP} IGNORE_MD5=1 ${TEST_ROOT}/infra/scripts/test_arm_neurun_cpu.sh" - ${SDB_CMD} shell /bin/bash -c "GCOV_PREFIX_STRIP=${GCOV_PREFIX_STRIP} IGNORE_MD5=1 ${TEST_ROOT}/infra/scripts/test_arm_neurun_mixed.sh" - ${SDB_CMD} shell /bin/bash -c "GCOV_PREFIX_STRIP=${GCOV_PREFIX_STRIP} IGNORE_MD5=1 ${TEST_ROOT}/infra/scripts/test_neurun_interp.sh" + ${SDB_CMD} shell /bin/bash -c "GCOV_PREFIX_STRIP=${GCOV_PREFIX_STRIP} IGNORE_MD5=1 ${TEST_ROOT}/infra/scripts/test_ubuntu_runtime.sh --backend acl_cl --tflite-loader" + ${SDB_CMD} shell /bin/bash -c "GCOV_PREFIX_STRIP=${GCOV_PREFIX_STRIP} IGNORE_MD5=1 ${TEST_ROOT}/infra/scripts/test_ubuntu_runtime.sh --backend acl_neon" + ${SDB_CMD} shell /bin/bash -c "GCOV_PREFIX_STRIP=${GCOV_PREFIX_STRIP} IGNORE_MD5=1 ${TEST_ROOT}/infra/scripts/test_ubuntu_runtime.sh --backend cpu" + ${SDB_CMD} shell /bin/bash -c "GCOV_PREFIX_STRIP=${GCOV_PREFIX_STRIP} IGNORE_MD5=1 ${TEST_ROOT}/infra/scripts/test_ubuntu_runtime_mixed.sh" + ${SDB_CMD} shell /bin/bash -c "GCOV_PREFIX_STRIP=${GCOV_PREFIX_STRIP} IGNORE_MD5=1 ${TEST_ROOT}/infra/scripts/test_ubuntu_runtime_interp.sh" # More test to check coverage ${SDB_CMD} shell "rm -rf ${GCOV_DATA_PATH} && mkdir -p ${GCOV_DATA_PATH}" diff --git a/nnpackage/schema/circle_schema.fbs b/nnpackage/schema/circle_schema.fbs index fe0d9447d4e..1eefb32e168 100644 --- a/nnpackage/schema/circle_schema.fbs +++ b/nnpackage/schema/circle_schema.fbs @@ -1,4 +1,4 @@ -// Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved +// Copyright (c) 2019~2020 Samsung Electronics Co., Ltd. All Rights Reserved // Copyright 2017 The TensorFlow Authors. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +14,18 @@ // limitations under the License. // Revision History -// Version 0: Initial version. Based on TensorFlow Lite v1.13.1 schema. +// +// Version Major.Minor +// +// Major version is schema version. +// We keep schema version if it is compatible +// Minor version is for human communication +// It will not be stored in circle model. +// +// Version 0.0: Initial version. Based on TensorFlow Lite v1.13.1 schema. +// Version 0.1: Based on TF v2.2-rc2 + more (from TensorFlow `56d281c`) +// `BATCH_MATMUL` operator, `FLOAT64` tensor type, +// `asymmetric_quantize_inputs` for several operator options namespace circle; @@ -38,6 +49,7 @@ enum TensorType : byte { INT16 = 7, COMPLEX64 = 8, INT8 = 9, + FLOAT64 = 10, } // Custom quantization parameters for experimenting with new quantization @@ -62,9 +74,119 @@ table QuantizationParameters { scale:[float]; // For dequantizing the tensor's values. zero_point:[long]; - // If this is not none, the quantization parameters above are ignored and the - // value of the QuantizationDetails union below should be used. + // If this is not none, the other quantization parameters (i.e. min, max, + // scale, zero_point fields above) are ignored and the value of the + // QuantizationDetails union should be used. details:QuantizationDetails; + + // Specifies the dimension of the Tensor's shape that the scales and + // zero_points correspond to. For example, a tensor t, with dims=[4, 3, 2, 1] + // with quantization params: + // scale=[1.0, 2.0, 3.0], zero_point=[1, 2, 3], quantization_dimension=1 + // will be quantized across the second dimension of t. + // t[:, 0, :, :] will have scale[0]=1.0, zero_point[0]=1 + // t[:, 1, :, :] will have scale[1]=2.0, zero_point[0]=2 + // t[:, 2, :, :] will have scale[2]=3.0, zero_point[0]=3 + quantized_dimension:int; +} + +// Sparse tensors. +// We use a modification of the TACO format. +// Reference: http://tensor-compiler.org/kjolstad-oopsla17-tensor-compiler.pdf +// +// To encode a conceptual n-dimensional dense tensor with dims (d0, ..., dn-1), +// potentially with a k-dimensional block (0 <= k <= n) with dims +// (dn, ..., dn+k-1), the format needs to specify: +// 1. In what order to traverse these dimensions. For example, to store a 2-D +// matrix in row major order, the traversal order would be (d0, d1), +// whereas to store it in column major order, the traversal order would be +// (d1, d0). If the 2-D matrix has a 2-D inner block, the traversal order +// could be (d0, d1, d2, d3). +// 2. How each block dimension in (dn, ..., dn+k-1) maps to the original +// tensor dimension in (d0, ..., dn-1). +// 3. In the traversal order defined above, the format (dense vs. sparse) and +// index metadata for each dimension. For a dense dimension, this is just +// the size of that dimension. For a sparse dimension, it's the same as +// the compressed index defined in the Compressed Sparse Row (CSR) format. +// (http://scipy-lectures.org/advanced/scipy_sparse/csr_matrix.html) + +// The storage type for a dimension. Currently we support: +// 1. DENSE: each coordinate in this dimension is stored implicitly. +// 2. SPARSE_CSR: only the coordinates with non-zero elements are stored. The +// compression technique is the same what CSR uses. +// More types like a sparse dimension with a different compression technique +// could be added to the list in the future. +enum DimensionType : byte { + DENSE = 0, + SPARSE_CSR = 1, +} + +table Int32Vector { + values:[int]; +} + +table Uint16Vector { + values:[ushort] (force_align: 4); +} + +table Uint8Vector { + values:[ubyte] (force_align: 4); +} + +// Variable-typed buffer to store the index metadata for a sparse dimension. +// The widest type is Int32 instead of UInt32 because tensor's shape is a int32 +// vector. We don't want the per-dimensional index to overflow that range. +union SparseIndexVector { + Int32Vector, + Uint16Vector, + Uint8Vector +} + +table DimensionMetadata { + // Whether a dimension is dense or sparse. + format:DimensionType; + // Index metadata used for a dimension. + // - If format is DimensionType.DENSE then we use the dense_size field to + // store the size of that dimension. Each index in that dimension is + // stored implicitly. + // - If format is DimensionType.SPARSE_CSR then we use array_segments and + // array_indices to encode that dimension. array_segments represents how + // to segment the indices array, each segment corresponds to one element + // in the previous dimension. array_indices represents the index of the + // non-zero elements within this dimension (as those in the CSR matrix + // format, where the first array is row pointers and the second array is + // column indices). + dense_size:int; + array_segments:SparseIndexVector; + array_indices:SparseIndexVector; +} + +// Parameters to encode a sparse TfLite tensor. +table SparsityParameters { + // The traversal order of the dimensions defined in the `shape` field of the + // conceptual dense tensor. For a n-dimensional tensors with dims (d0, d1, + // ..., dn-1), + // - if not block sparse, the traversal_order is just a permutation of (d0, + // ..., dn-1). For example, a 2-D matrix stored in row-major order would + // have traversal_order = (d0, d1). + // - if block sparse with a k-dimensional block (0 <= k <= n), the + // traversal_order has n + k elements. The first n elements are still a + // permutation of (d0, ..., dn-1). The lask k elements are a permutation + // of (dn, ..., dn+k-1), defining how to traverse a block internally. For + // example, a 2-D matrix with 2-D blocks, both stored in row-major order + // would have traversal_order = (d0, d1, d2, d3). + traversal_order:[int]; + // For an n-dimensional tensor with a k-dimensional block (0 <= k <= n), + // stores how a block dimension in (dn, ..., dn+k-1) maps to the original + // tensor dimension in (d0, ..., dn). + // It's stored in the order of (dn, ..., dn+k-1). + // If not block-sparse, this field is NULL. + block_map:[int]; + // In the traversal order defined above, the metadata needed for + // each dimension to locate the non-zero values in the original dense tensor. + // The size of the dim_metadata array = the size of the traversal_order array + // = n + k. + dim_metadata:[DimensionMetadata]; } table Tensor { @@ -86,19 +208,28 @@ table Tensor { quantization:QuantizationParameters; // Optional. is_variable:bool = false; + + // Parameters to encode a sparse tensor. See the example in + // tensorflow/lite/testdata/sparse_tensor.json. + sparsity:SparsityParameters; // Optional. + + // Encodes `shape` with unknown dimensions. Unknown dimensions are + // represented with -1. + shape_signature:[int]; // Optional. } // A list of builtin operators. Builtin operators are slightly faster than custom // ones, but not by much. Moreover, while custom operators accept an opaque // object containing configuration parameters, builtins have a predetermined // set of acceptable options. + enum BuiltinOperator : ubyte { ADD = 0, AVERAGE_POOL_2D = 1, CONCATENATION = 2, CONV_2D = 3, DEPTHWISE_CONV_2D = 4, - // DEPTH_TO_SPACE = 5, + DEPTH_TO_SPACE = 5, DEQUANTIZE = 6, EMBEDDING_LOOKUP = 7, FLOOR = 8, @@ -203,6 +334,30 @@ enum BuiltinOperator : ubyte { MIRROR_PAD = 100, ABS = 101, SPLIT_V = 102, + UNIQUE = 103, + CEIL = 104, + REVERSE_V2 = 105, + ADD_N = 106, + GATHER_ND = 107, + COS = 108, + WHERE = 109, + RANK = 110, + ELU = 111, + REVERSE_SEQUENCE = 112, + MATRIX_DIAG = 113, + QUANTIZE = 114, + MATRIX_SET_DIAG = 115, + ROUND = 116, + HARD_SWISH = 117, + IF = 118, + WHILE = 119, + NON_MAX_SUPPRESSION_V4 = 120, + NON_MAX_SUPPRESSION_V5 = 121, + SCATTER_ND = 122, + SELECT_V2 = 123, + DENSIFY = 124, + SEGMENT_SUM = 125, + BATCH_MATMUL = 126, INSTANCE_NORM = 254, } @@ -288,6 +443,28 @@ union BuiltinOptions { AbsOptions, SplitVOptions, InstanceNormOptions, + UniqueOptions, + ReverseV2Options, + AddNOptions, + GatherNdOptions, + CosOptions, + WhereOptions, + RankOptions, + ReverseSequenceOptions, + MatrixDiagOptions, + QuantizeOptions, + MatrixSetDiagOptions, + HardSwishOptions, + IfOptions, + WhileOptions, + DepthToSpaceOptions, + NonMaxSuppressionV4Options, + NonMaxSuppressionV5Options, + ScatterNdOptions, + SelectV2Options, + DensifyOptions, + SegmentSumOptions, + BatchMatMulOptions, } enum Padding : byte { SAME, VALID } @@ -324,6 +501,9 @@ table DepthwiseConv2DOptions { padding:Padding; stride_w:int; stride_h:int; + // `depth_multiplier` is redundant. It's used by CPU kernels in + // TensorFlow 2.0 or below, but ignored in versions above. + // See comments in lite/c/builtin_op_data.h for more details. depth_multiplier:int; fused_activation_function:ActivationFunctionType; // Parameters for DepthwiseConv version 2 or above. @@ -350,17 +530,22 @@ table LSHProjectionOptions { table SVDFOptions { rank:int; fused_activation_function:ActivationFunctionType; + // For weights-only quantization, use asymmetric quantization for non + // constant inputs at evaluation time. + asymmetric_quantize_inputs:bool; } // An implementation of TensorFlow RNNCell. table RNNOptions { fused_activation_function:ActivationFunctionType; + asymmetric_quantize_inputs:bool; } // An implementation of TensorFlow dynamic_rnn with RNNCell. table SequenceRNNOptions { time_major:bool; fused_activation_function:ActivationFunctionType; + asymmetric_quantize_inputs:bool; } // An implementation of TensorFlow bidrectional_dynamic_rnn with RNNCell. @@ -368,6 +553,7 @@ table BidirectionalSequenceRNNOptions { time_major:bool; fused_activation_function:ActivationFunctionType; merge_outputs: bool; + asymmetric_quantize_inputs:bool; } enum FullyConnectedOptionsWeightsFormat: byte { @@ -382,6 +568,16 @@ table FullyConnectedOptions { // Parameters for FullyConnected version 2 or above. weights_format:FullyConnectedOptionsWeightsFormat = DEFAULT; + + // Parameters for FullyConnected version 5 or above. + // If set to true, then the number of dimension is preserved. Furthermore, + // all but the last dimension of the input and output shapes will be equal. + keep_num_dims: bool; + + // Parameters for FullyConnected version 7 or above. + // If set to true, then weights-only op will use asymmetric quantization for + // inputs. + asymmetric_quantize_inputs: bool; } table SoftmaxOptions { @@ -430,6 +626,9 @@ table LSTMOptions { // Parameters for LSTM version 2 or above. // Basic kernel is only supported in version 2 or above. kernel_type: LSTMKernelType = FULL; + + // Parameters for LSTM version 4 or above. + asymmetric_quantize_inputs: bool; } // An implementation of TensorFlow dynamic_rnn with LSTMCell. @@ -440,21 +639,35 @@ table UnidirectionalSequenceLSTMOptions { // If true then first dimension is sequence, otherwise batch. time_major:bool; + + // Parameter for Unidirectional Sequence LSTM version 4. + asymmetric_quantize_inputs:bool; } table BidirectionalSequenceLSTMOptions { + // Parameters supported by version 1: fused_activation_function:ActivationFunctionType; cell_clip: float; // Optional, 0.0 means no clipping proj_clip: float; // Optional, 0.0 means no clipping // If true, store the outputs of both directions into the first output. merge_outputs: bool; + + // Parameters supported by version 2: + // If true then first dimension is sequence, otherwise batch. + // Version 1 implementations assumed time_major to be true, so this default + // value should never change. + time_major: bool = true; + + // Parameters for version 3 or above. + asymmetric_quantize_inputs:bool; } table ResizeBilinearOptions { new_height: int (deprecated); new_width: int (deprecated); align_corners: bool; + half_pixel_centers: bool; } table ResizeNearestNeighborOptions { @@ -493,6 +706,10 @@ table SpaceToDepthOptions { block_size: int; } +table DepthToSpaceOptions { + block_size: int; +} + table SubOptions { fused_activation_function:ActivationFunctionType; } @@ -524,6 +741,9 @@ table TransposeOptions { table ExpOptions { } +table CosOptions { +} + table ReducerOptions { keep_dims: bool; } @@ -618,6 +838,9 @@ table ShapeOptions { out_type : TensorType; } +table RankOptions { +} + table PowOptions { } @@ -647,6 +870,9 @@ table AbsOptions { } +table HardSwishOptions { +} + table LogicalAndOptions { } @@ -694,6 +920,69 @@ table MirrorPadOptions { mode:MirrorPadMode; } +table UniqueOptions { + idx_out_type:TensorType = INT32; +} + +table ReverseV2Options { +} + +table AddNOptions { +} + +table GatherNdOptions { +} + +table WhereOptions { +} + +table ReverseSequenceOptions { + seq_dim:int; + batch_dim:int = 0; +} + +table MatrixDiagOptions { +} + +table QuantizeOptions { +} + +table MatrixSetDiagOptions { +} + +table IfOptions { + then_subgraph_index:int; + else_subgraph_index:int; +} + +table WhileOptions { + cond_subgraph_index:int; + body_subgraph_index:int; +} + +table NonMaxSuppressionV4Options { +} + +table NonMaxSuppressionV5Options { +} + +table ScatterNdOptions { +} + +table SelectV2Options { +} + +table DensifyOptions { +} + +table SegmentSumOptions { +} + +table BatchMatMulOptions { + adjoint_lhs:bool; + adjoint_rhs:bool; +} + table InstanceNormOptions { epsilon:float; fused_activation_function:ActivationFunctionType; @@ -732,7 +1021,7 @@ table Operator { // complicate map lookups. opcode_index:uint; - // Optional input and output tensors are indicated by -1. + // Optional input are indicated by -1. inputs:[int]; outputs:[int]; @@ -749,6 +1038,15 @@ table Operator { // If the list is empty, no variable is mutated in this operator. // The list either has the same length as `inputs`, or is empty. mutating_variable_inputs:[bool]; + + // A list of indices to the subgraph's "tensors" that are internal to an Op. + // Internal tensors are those that do not flow in or out of the operation, + // but instead are part of internal computation. As such, the operation's + // implementation may manage its memory more efficiently. They are needed + // however (i.e. not just an implementation detail) since they are part of the + // computation, which may require relevant metadata such as quantization + // parameters. + intermediates:[int]; } // The root type, defining a subgraph, which typically represents an entire @@ -782,6 +1080,13 @@ table Buffer { data:[ubyte] (force_align: 16); } +table Metadata { + // A human readable string to uniquely identify a Metadata. + name:string; + // An index to the buffers table. + buffer:uint; +} + table Model { // Version of the schema. version:uint; @@ -804,8 +1109,12 @@ table Model { // their buffer. buffers:[Buffer]; - // Metadata about the model. Indirects into the existings buffers list. + // Metadata about the model. Indirects into the existings buffers list. + // Deprecated, prefer to use metadata field. metadata_buffer:[int]; + + // Metadata about the model. + metadata:[Metadata]; } root_type Model; diff --git a/nnpackage/schema/circle_schema_v0.fbs b/nnpackage/schema/circle_schema_v0.fbs new file mode 100644 index 00000000000..fe0d9447d4e --- /dev/null +++ b/nnpackage/schema/circle_schema_v0.fbs @@ -0,0 +1,811 @@ +// Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved +// Copyright 2017 The TensorFlow Authors. 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. + +// Revision History +// Version 0: Initial version. Based on TensorFlow Lite v1.13.1 schema. + +namespace circle; + +// This corresponds to the version. +file_identifier "CIR0"; +// File extension of any written files. +file_extension "circle"; + +// IMPORTANT: All new members of tables, enums and unions must be added at the +// end to ensure backwards compatibility. + +// The type of data stored in a tensor. +enum TensorType : byte { + FLOAT32 = 0, + FLOAT16 = 1, + INT32 = 2, + UINT8 = 3, + INT64 = 4, + STRING = 5, + BOOL = 6, + INT16 = 7, + COMPLEX64 = 8, + INT8 = 9, +} + +// Custom quantization parameters for experimenting with new quantization +// techniques. +table CustomQuantization { + custom:[ubyte] (force_align: 16); +} + +// Represents a specific quantization technique's parameters. +union QuantizationDetails { + CustomQuantization, +} + +// Parameters for converting a quantized tensor back to float. +table QuantizationParameters { + // These four parameters are the asymmetric linear quantization parameters. + // Given a quantized value q, the corresponding float value f should be: + // f = scale * (q - zero_point) + // For other quantization types, the QuantizationDetails below is used. + min:[float]; // For importing back into tensorflow. + max:[float]; // For importing back into tensorflow. + scale:[float]; // For dequantizing the tensor's values. + zero_point:[long]; + + // If this is not none, the quantization parameters above are ignored and the + // value of the QuantizationDetails union below should be used. + details:QuantizationDetails; +} + +table Tensor { + // The tensor shape. The meaning of each entry is operator-specific but + // builtin ops use: [batch size, height, width, number of channels] (That's + // Tensorflow's NHWC). + shape:[int]; + type:TensorType; + // An index that refers to the buffers table at the root of the model. Or, + // if there is no data buffer associated (i.e. intermediate results), then + // this is 0 (which refers to an always existent empty buffer). + // + // The data_buffer itself is an opaque container, with the assumption that the + // target device is little-endian. In addition, all builtin operators assume + // the memory is ordered such that if `shape` is [4, 3, 2], then index + // [i, j, k] maps to data_buffer[i*3*2 + j*2 + k]. + buffer:uint; + name:string; // For debugging and importing back into tensorflow. + quantization:QuantizationParameters; // Optional. + + is_variable:bool = false; +} + +// A list of builtin operators. Builtin operators are slightly faster than custom +// ones, but not by much. Moreover, while custom operators accept an opaque +// object containing configuration parameters, builtins have a predetermined +// set of acceptable options. +enum BuiltinOperator : ubyte { + ADD = 0, + AVERAGE_POOL_2D = 1, + CONCATENATION = 2, + CONV_2D = 3, + DEPTHWISE_CONV_2D = 4, + // DEPTH_TO_SPACE = 5, + DEQUANTIZE = 6, + EMBEDDING_LOOKUP = 7, + FLOOR = 8, + FULLY_CONNECTED = 9, + HASHTABLE_LOOKUP = 10, + L2_NORMALIZATION = 11, + L2_POOL_2D = 12, + LOCAL_RESPONSE_NORMALIZATION = 13, + LOGISTIC = 14, + LSH_PROJECTION = 15, + LSTM = 16, + MAX_POOL_2D = 17, + MUL = 18, + RELU = 19, + // NOTE(aselle): RELU_N1_TO_1 used to be called RELU1, but it was renamed + // since different model developers use RELU1 in different ways. Never + // create another op called RELU1. + RELU_N1_TO_1 = 20, + RELU6 = 21, + RESHAPE = 22, + RESIZE_BILINEAR = 23, + RNN = 24, + SOFTMAX = 25, + SPACE_TO_DEPTH = 26, + SVDF = 27, + TANH = 28, + // TODO(aselle): Consider rename to CONCATENATE_EMBEDDINGS + CONCAT_EMBEDDINGS = 29, + SKIP_GRAM = 30, + CALL = 31, + CUSTOM = 32, + EMBEDDING_LOOKUP_SPARSE = 33, + PAD = 34, + UNIDIRECTIONAL_SEQUENCE_RNN = 35, + GATHER = 36, + BATCH_TO_SPACE_ND = 37, + SPACE_TO_BATCH_ND = 38, + TRANSPOSE = 39, + MEAN = 40, + SUB = 41, + DIV = 42, + SQUEEZE = 43, + UNIDIRECTIONAL_SEQUENCE_LSTM = 44, + STRIDED_SLICE = 45, + BIDIRECTIONAL_SEQUENCE_RNN = 46, + EXP = 47, + TOPK_V2 = 48, + SPLIT = 49, + LOG_SOFTMAX = 50, + // DELEGATE is a special op type for the operations which are delegated to + // other backends. + // WARNING: Experimental interface, subject to change + DELEGATE = 51, + BIDIRECTIONAL_SEQUENCE_LSTM = 52, + CAST = 53, + PRELU = 54, + MAXIMUM = 55, + ARG_MAX = 56, + MINIMUM = 57, + LESS = 58, + NEG = 59, + PADV2 = 60, + GREATER = 61, + GREATER_EQUAL = 62, + LESS_EQUAL = 63, + SELECT = 64, + SLICE = 65, + SIN = 66, + TRANSPOSE_CONV = 67, + SPARSE_TO_DENSE = 68, + TILE = 69, + EXPAND_DIMS = 70, + EQUAL = 71, + NOT_EQUAL = 72, + LOG = 73, + SUM = 74, + SQRT = 75, + RSQRT = 76, + SHAPE = 77, + POW = 78, + ARG_MIN = 79, + FAKE_QUANT = 80, + REDUCE_PROD = 81, + REDUCE_MAX = 82, + PACK = 83, + LOGICAL_OR = 84, + ONE_HOT = 85, + LOGICAL_AND = 86, + LOGICAL_NOT = 87, + UNPACK = 88, + REDUCE_MIN = 89, + FLOOR_DIV = 90, + REDUCE_ANY = 91, + SQUARE = 92, + ZEROS_LIKE = 93, + FILL = 94, + FLOOR_MOD = 95, + RANGE = 96, + RESIZE_NEAREST_NEIGHBOR = 97, + LEAKY_RELU = 98, + SQUARED_DIFFERENCE = 99, + MIRROR_PAD = 100, + ABS = 101, + SPLIT_V = 102, + INSTANCE_NORM = 254, +} + +// Options for the builtin operators. +union BuiltinOptions { + Conv2DOptions, + DepthwiseConv2DOptions, + ConcatEmbeddingsOptions, + LSHProjectionOptions, + Pool2DOptions, + SVDFOptions, + RNNOptions, + FullyConnectedOptions, + SoftmaxOptions, + ConcatenationOptions, + AddOptions, + L2NormOptions, + LocalResponseNormalizationOptions, + LSTMOptions, + ResizeBilinearOptions, + CallOptions, + ReshapeOptions, + SkipGramOptions, + SpaceToDepthOptions, + EmbeddingLookupSparseOptions, + MulOptions, + PadOptions, + GatherOptions, + BatchToSpaceNDOptions, + SpaceToBatchNDOptions, + TransposeOptions, + ReducerOptions, + SubOptions, + DivOptions, + SqueezeOptions, + SequenceRNNOptions, + StridedSliceOptions, + ExpOptions, + TopKV2Options, + SplitOptions, + LogSoftmaxOptions, + CastOptions, + DequantizeOptions, + MaximumMinimumOptions, + ArgMaxOptions, + LessOptions, + NegOptions, + PadV2Options, + GreaterOptions, + GreaterEqualOptions, + LessEqualOptions, + SelectOptions, + SliceOptions, + TransposeConvOptions, + SparseToDenseOptions, + TileOptions, + ExpandDimsOptions, + EqualOptions, + NotEqualOptions, + ShapeOptions, + PowOptions, + ArgMinOptions, + FakeQuantOptions, + PackOptions, + LogicalOrOptions, + OneHotOptions, + LogicalAndOptions, + LogicalNotOptions, + UnpackOptions, + FloorDivOptions, + SquareOptions, + ZerosLikeOptions, + FillOptions, + BidirectionalSequenceLSTMOptions, + BidirectionalSequenceRNNOptions, + UnidirectionalSequenceLSTMOptions, + FloorModOptions, + RangeOptions, + ResizeNearestNeighborOptions, + LeakyReluOptions, + SquaredDifferenceOptions, + MirrorPadOptions, + AbsOptions, + SplitVOptions, + InstanceNormOptions, +} + +enum Padding : byte { SAME, VALID } + +enum ActivationFunctionType : byte { + NONE = 0, + RELU = 1, + RELU_N1_TO_1 = 2, + RELU6 = 3, + TANH = 4, + SIGN_BIT = 5, +} + +table Conv2DOptions { + padding:Padding; + stride_w:int; + stride_h:int; + fused_activation_function:ActivationFunctionType; + dilation_w_factor:int = 1; + dilation_h_factor:int = 1; +} + +table Pool2DOptions { + padding:Padding; + stride_w:int; + stride_h:int; + filter_width:int; + filter_height:int; + fused_activation_function:ActivationFunctionType; +} + +table DepthwiseConv2DOptions { + // Parameters for DepthwiseConv version 1 or above. + padding:Padding; + stride_w:int; + stride_h:int; + depth_multiplier:int; + fused_activation_function:ActivationFunctionType; + // Parameters for DepthwiseConv version 2 or above. + dilation_w_factor:int = 1; + dilation_h_factor:int = 1; +} + +table ConcatEmbeddingsOptions { + num_channels:int; + num_columns_per_channel:[int]; + embedding_dim_per_channel:[int]; // This could be inferred from parameters. +} + +enum LSHProjectionType: byte { + UNKNOWN = 0, + SPARSE = 1, + DENSE = 2, +} + +table LSHProjectionOptions { + type: LSHProjectionType; +} + +table SVDFOptions { + rank:int; + fused_activation_function:ActivationFunctionType; +} + +// An implementation of TensorFlow RNNCell. +table RNNOptions { + fused_activation_function:ActivationFunctionType; +} + +// An implementation of TensorFlow dynamic_rnn with RNNCell. +table SequenceRNNOptions { + time_major:bool; + fused_activation_function:ActivationFunctionType; +} + +// An implementation of TensorFlow bidrectional_dynamic_rnn with RNNCell. +table BidirectionalSequenceRNNOptions { + time_major:bool; + fused_activation_function:ActivationFunctionType; + merge_outputs: bool; +} + +enum FullyConnectedOptionsWeightsFormat: byte { + DEFAULT = 0, + SHUFFLED4x16INT8 = 1, +} + +// An implementation of TensorFlow fully_connected (a.k.a Dense) layer. +table FullyConnectedOptions { + // Parameters for FullyConnected version 1 or above. + fused_activation_function:ActivationFunctionType; + + // Parameters for FullyConnected version 2 or above. + weights_format:FullyConnectedOptionsWeightsFormat = DEFAULT; +} + +table SoftmaxOptions { + beta: float; +} + +// An implementation of TensorFlow concat. +table ConcatenationOptions { + axis:int; + fused_activation_function:ActivationFunctionType; +} + +table AddOptions { + fused_activation_function:ActivationFunctionType; +} + +table MulOptions { + fused_activation_function:ActivationFunctionType; +} + +table L2NormOptions { + fused_activation_function:ActivationFunctionType; +} + +table LocalResponseNormalizationOptions { + radius:int; + bias:float; + alpha:float; + beta:float; +} + +enum LSTMKernelType : byte { + // Full LSTM kernel which supports peephole and projection. + FULL = 0, + // Basic LSTM kernels. Equivalent to TensorFlow BasicLSTMCell. + BASIC = 1, +} + +// An implementation of TensorFlow LSTMCell and CoupledInputForgetGateLSTMCell +table LSTMOptions { + // Parameters for LSTM version 1 or above. + fused_activation_function:ActivationFunctionType; + cell_clip: float; // Optional, 0.0 means no clipping + proj_clip: float; // Optional, 0.0 means no clipping + + // Parameters for LSTM version 2 or above. + // Basic kernel is only supported in version 2 or above. + kernel_type: LSTMKernelType = FULL; +} + +// An implementation of TensorFlow dynamic_rnn with LSTMCell. +table UnidirectionalSequenceLSTMOptions { + fused_activation_function:ActivationFunctionType; + cell_clip: float; // Optional, 0.0 means no clipping + proj_clip: float; // Optional, 0.0 means no clipping + + // If true then first dimension is sequence, otherwise batch. + time_major:bool; +} + +table BidirectionalSequenceLSTMOptions { + fused_activation_function:ActivationFunctionType; + cell_clip: float; // Optional, 0.0 means no clipping + proj_clip: float; // Optional, 0.0 means no clipping + + // If true, store the outputs of both directions into the first output. + merge_outputs: bool; +} + +table ResizeBilinearOptions { + new_height: int (deprecated); + new_width: int (deprecated); + align_corners: bool; +} + +table ResizeNearestNeighborOptions { + align_corners: bool; +} + +// A call operation options +table CallOptions { + // The subgraph index that needs to be called. + subgraph:uint; +} + +table PadOptions { +} + +table PadV2Options { +} + +table ReshapeOptions { + new_shape:[int]; +} + +table SpaceToBatchNDOptions { +} + +table BatchToSpaceNDOptions { +} + +table SkipGramOptions { + ngram_size: int; + max_skip_size: int; + include_all_ngrams: bool; +} + +table SpaceToDepthOptions { + block_size: int; +} + +table SubOptions { + fused_activation_function:ActivationFunctionType; +} + +table DivOptions { + fused_activation_function:ActivationFunctionType; +} + +table TopKV2Options { +} + +enum CombinerType : byte { + SUM = 0, + MEAN = 1, + SQRTN = 2, +} + +table EmbeddingLookupSparseOptions { + combiner:CombinerType; +} + +table GatherOptions { + axis: int; +} + +table TransposeOptions { +} + +table ExpOptions { +} + +table ReducerOptions { + keep_dims: bool; +} + +table SqueezeOptions { + squeeze_dims:[int]; +} + +table SplitOptions { + num_splits: int; +} + +table SplitVOptions { + num_splits: int; +} + +table StridedSliceOptions { + begin_mask: int; + end_mask: int; + ellipsis_mask: int; + new_axis_mask: int; + shrink_axis_mask: int; +} + +table LogSoftmaxOptions { +} + +table CastOptions { + in_data_type: TensorType; + out_data_type: TensorType; +} + +table DequantizeOptions { +} + +table MaximumMinimumOptions { +} + +table TileOptions { +} + +table ArgMaxOptions { + output_type : TensorType; +} + +table ArgMinOptions { + output_type : TensorType; +} + +table GreaterOptions { +} + +table GreaterEqualOptions { +} + +table LessOptions { +} + +table LessEqualOptions { +} + +table NegOptions { +} + +table SelectOptions { +} + +table SliceOptions { +} + +table TransposeConvOptions { + padding:Padding; + stride_w:int; + stride_h:int; +} + +table ExpandDimsOptions { +} + +table SparseToDenseOptions { + validate_indices:bool; +} + +table EqualOptions { +} + +table NotEqualOptions { +} + +table ShapeOptions { + // Optional output type of the operation (int32 or int64). Defaults to int32. + out_type : TensorType; +} + +table PowOptions { +} + +table FakeQuantOptions { + // Parameters supported by version 1: + min:float; + max:float; + num_bits:int; + + // Parameters supported by version 2: + narrow_range:bool; +} + +table PackOptions { + values_count:int; + axis:int; +} + +table LogicalOrOptions { +} + +table OneHotOptions { + axis:int; +} + +table AbsOptions { +} + + +table LogicalAndOptions { +} + +table LogicalNotOptions { +} + +table UnpackOptions { + num:int; + axis:int; +} + +table FloorDivOptions { +} + +table SquareOptions { +} + +table ZerosLikeOptions { +} + +table FillOptions { +} + +table FloorModOptions { +} + +table RangeOptions { +} + +table LeakyReluOptions { + alpha:float; +} + +table SquaredDifferenceOptions { +} + +enum MirrorPadMode : byte { + // Doesn't include borders. + REFLECT = 0, + // Includes borders. + SYMMETRIC = 1, +} + +table MirrorPadOptions { + mode:MirrorPadMode; +} + +table InstanceNormOptions { + epsilon:float; + fused_activation_function:ActivationFunctionType; +} + +// An OperatorCode can be an enum value (BuiltinOperator) if the operator is a +// builtin, or a string if the operator is custom. +table OperatorCode { + builtin_code:BuiltinOperator; + custom_code:string; + + // The version of the operator. The version need to be bumped whenever new + // parameters are introduced into an op. + version:int = 1; +} + +enum CustomOptionsFormat : byte { + FLEXBUFFERS = 0, +} + +enum DataFormat : byte { + // For 2D data, NHWC(batch, height, width, channels) + // For 3D data, NDHWC(batch, depth, height, width, channels) + CHANNELS_LAST = 0, + // For 2D data, NCHW(batch, channels, height, width) + // For 3D data, NCDHW(batch, channels, depth, height, width) + CHANNELS_FIRST = 1, +} + +// An operator takes tensors as inputs and outputs. The type of operation being +// performed is determined by an index into the list of valid OperatorCodes, +// while the specifics of each operations is configured using builtin_options +// or custom_options. +table Operator { + // Index into the operator_codes array. Using an integer here avoids + // complicate map lookups. + opcode_index:uint; + + // Optional input and output tensors are indicated by -1. + inputs:[int]; + outputs:[int]; + + builtin_options:BuiltinOptions; + custom_options:[ubyte]; + custom_options_format:CustomOptionsFormat; + + // A list of booleans indicating the input tensors which are being mutated by + // this operator.(e.g. used by RNN and LSTM). + // For example, if the "inputs" array refers to 5 tensors and the second and + // fifth are mutable variables, then this list will contain + // [false, true, false, false, true]. + // + // If the list is empty, no variable is mutated in this operator. + // The list either has the same length as `inputs`, or is empty. + mutating_variable_inputs:[bool]; +} + +// The root type, defining a subgraph, which typically represents an entire +// model. +table SubGraph { + // A list of all tensors used in this subgraph. + tensors:[Tensor]; + + // Indices of the tensors that are inputs into this subgraph. Note this is + // the list of non-static tensors that feed into the subgraph for inference. + inputs:[int]; + + // Indices of the tensors that are outputs out of this subgraph. Note this is + // the list of output tensors that are considered the product of the + // subgraph's inference. + outputs:[int]; + + // All operators, in execution order. + operators:[Operator]; + + // Name of this subgraph (used for debugging). + name:string; + + // Data format for input/output of SubGraph + data_format: DataFormat; +} + +// Table of raw data buffers (used for constant tensors). Referenced by tensors +// by index. The generous alignment accommodates mmap-friendly data structures. +table Buffer { + data:[ubyte] (force_align: 16); +} + +table Model { + // Version of the schema. + version:uint; + + // A list of all operator codes used in this model. This is + // kept in order because operators carry an index into this + // vector. + operator_codes:[OperatorCode]; + + // All the subgraphs of the model. The 0th is assumed to be the main + // model. + subgraphs:[SubGraph]; + + // A description of the model. + description:string; + + // Buffers of the model. + // Note the 0th entry of this array must be an empty buffer (sentinel). + // This is a convention so that tensors without a buffer can provide 0 as + // their buffer. + buffers:[Buffer]; + + // Metadata about the model. Indirects into the existings buffers list. + metadata_buffer:[int]; +} + +root_type Model; diff --git a/packaging/gemmlowp.tar.gz b/packaging/gemmlowp.tar.gz new file mode 100644 index 00000000000..68339cdb155 Binary files /dev/null and b/packaging/gemmlowp.tar.gz differ diff --git a/packaging/nnfw.spec b/packaging/nnfw.spec index 67360486d65..731e388e90a 100644 --- a/packaging/nnfw.spec +++ b/packaging/nnfw.spec @@ -11,15 +11,18 @@ Source1001: flatbuffers.tar.gz Source1002: nnapi_test_generated.tar.gz Source1003: gtest.tar.gz Source1004: eigen.tar.gz +Source1005: gemmlowp.tar.gz Source2001: nnfw.pc.in +%{!?build_type: %define build_type Release} +%{!?coverage_build: %define coverage_build 0} +%{!?test_build: %define test_build 1} +%{!?extra_option: %define extra_option %{nil}} +%if %{coverage_build} == 1 +%define test_build 1 +%endif + BuildRequires: cmake -BuildRequires: boost-devel -BuildRequires: tensorflow-lite-devel -BuildRequires: hdf5-devel -BuildRequires: libaec-devel -BuildRequires: zlib-devel -BuildRequires: libjpeg-devel %ifarch %{arm} aarch64 # Require python for acl-ex library build pre-process @@ -30,9 +33,14 @@ BuildRequires: libarmcl-devel Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig -%{!?build_type: %define build_type Release} -%{!?coverage_build: %define coverage_build 0} -%{!?extra_option: %define extra_option %{nil}} +%if %{test_build} == 1 +BuildRequires: boost-devel +BuildRequires: tensorflow-lite-devel +BuildRequires: hdf5-devel +BuildRequires: libaec-devel +BuildRequires: zlib-devel +BuildRequires: libjpeg-devel +%endif %description nnfw is a high-performance, on-device neural network framework for Tizen @@ -44,11 +52,13 @@ Requires: %{name} = %{version}-%{release} %description devel NNFW devel package. +%if %{test_build} == 1 %package test Summary: NNFW Test %description test NNFW test rpm. It does not depends on nnfw rpm since it contains nnfw runtime. +%endif %ifarch %{arm} %define target_arch armv7l @@ -63,7 +73,7 @@ NNFW test rpm. It does not depends on nnfw rpm since it contains nnfw runtime. %define install_dir %{_prefix} %define install_path %{buildroot}%{install_dir} %define build_env NNFW_WORKSPACE=build -%define build_options -DCMAKE_BUILD_TYPE=%{build_type} -DTARGET_ARCH=%{target_arch} -DTARGET_OS=tizen +%define build_options -DCMAKE_BUILD_TYPE=%{build_type} -DTARGET_ARCH=%{target_arch} -DTARGET_OS=tizen -DENABLE_TEST=off # Set option for test build (and coverage test build) %define test_install_home /opt/usr/nnfw-test @@ -77,7 +87,7 @@ NNFW test rpm. It does not depends on nnfw rpm since it contains nnfw runtime. %define test_build_type Debug %endif %define test_build_env NNFW_INSTALL_PREFIX=%{test_install_path} NNFW_WORKSPACE=build_for_test -%define test_build_options %{coverage_option} -DCMAKE_BUILD_TYPE=%{test_build_type} -DTARGET_ARCH=%{target_arch} -DTARGET_OS=tizen -DENVVAR_NEURUN_CONFIG=ON +%define test_build_options %{coverage_option} -DCMAKE_BUILD_TYPE=%{test_build_type} -DTARGET_ARCH=%{target_arch} -DTARGET_OS=tizen -DENVVAR_ONERT_CONFIG=ON %prep %setup -q @@ -87,6 +97,7 @@ tar -xf %{SOURCE1001} -C ./externals tar -xf %{SOURCE1002} -C ./tests/nnapi/src/ tar -xf %{SOURCE1003} -C ./externals tar -xf %{SOURCE1004} -C ./externals +tar -xf %{SOURCE1005} -C ./externals %build %ifarch arm armv7l aarch64 @@ -97,23 +108,25 @@ tar -xf %{SOURCE1004} -C ./externals # TODO Set install path %{build_env} ./nnfw install +%if %{test_build} == 1 # test runtime # TODO remove duplicated build process %{test_build_env} ./nnfw configure %{test_build_options} %{extra_option} %{test_build_env} ./nnfw build %if %{coverage_build} == 1 pwd > tests/scripts/build_path.txt -%endif +%endif # coverage_build tar -zcf test-suite.tar.gz infra/scripts tests/scripts -%endif +%endif # test_build +%endif # arm armv7l aarch64 %install %ifarch arm armv7l aarch64 mkdir -p %{buildroot}%{_libdir} -mkdir -p %{buildroot}%{_includedir} +mkdir -p %{buildroot}%{_includedir}/nnfw install -m 644 build/out/lib/*.so %{buildroot}%{_libdir} -cp -r build/out/include/* %{buildroot}%{_includedir}/ +cp -r build/out/include/nnfw/* %{buildroot}%{_includedir}/nnfw/ # For developer cp %{SOURCE2001} . @@ -122,16 +135,18 @@ sed -i 's:@libdir@:%{_libdir}:g mkdir -p %{buildroot}%{_libdir}/pkgconfig install -m 0644 ./nnfw.pc.in %{buildroot}%{_libdir}/pkgconfig/nnfw.pc +%if %{test_build} == 1 %{test_build_env} ./nnfw install # Share test script with ubuntu (ignore error if there is no list for target) cp tests/nnapi/nnapi_gtest.skip.* %{buildroot}%{test_install_dir}/unittest/. -cp %{buildroot}%{test_install_dir}/unittest/nnapi_gtest.skip.%{target_arch}-tizen.acl_cl %{buildroot}%{test_install_dir}/unittest/nnapi_gtest.skip.%{target_arch}-linux.acl_cl || true +cp %{buildroot}%{test_install_dir}/unittest/nnapi_gtest.skip.%{target_arch}-linux.cpu %{buildroot}%{test_install_dir}/unittest/nnapi_gtest.skip tar -zxf test-suite.tar.gz -C %{buildroot}%{test_install_home} %if %{coverage_build} == 1 mkdir -p %{buildroot}%{test_install_home}/gcov find . -name "*.gcno" -exec xargs cp {} %{buildroot}%{test_install_home}/gcov/. \; -%endif +%endif # coverage_build +%endif # test_build %endif @@ -154,6 +169,7 @@ find . -name "*.gcno" -exec xargs cp {} %{buildroot}%{test_install_home}/gcov/. %{_libdir}/pkgconfig/nnfw.pc %endif +%if %{test_build} == 1 %files test %manifest %{name}.manifest %defattr(-,root,root,-) @@ -161,7 +177,8 @@ find . -name "*.gcno" -exec xargs cp {} %{buildroot}%{test_install_home}/gcov/. %dir %{test_install_home} %{test_install_home}/* %exclude %{_libdir}/debug -%endif +%endif # arm armv7l aarch64 +%endif # test_build %changelog * Thu Mar 15 2018 Chunseok Lee diff --git a/res/TensorFlowLiteRecipes/Abs_000/test.recipe b/res/TensorFlowLiteRecipes/Abs_000/test.recipe new file mode 100644 index 00000000000..0603a43fd5f --- /dev/null +++ b/res/TensorFlowLiteRecipes/Abs_000/test.recipe @@ -0,0 +1,17 @@ +operand { + name: "ifm" + type: FLOAT32 + shape { dim: 1 dim: 3 dim: 3 dim: 2 } +} +operand { + name: "ofm" + type: FLOAT32 + shape { dim: 1 dim: 3 dim: 3 dim: 2 } +} +operation { + type: "Abs" + input: "ifm" + output: "ofm" +} +input: "ifm" +output: "ofm" diff --git a/res/TensorFlowLiteRecipes/Abs_000/test.reverse b/res/TensorFlowLiteRecipes/Abs_000/test.reverse new file mode 100644 index 00000000000..e69de29bb2d diff --git a/res/TensorFlowLiteRecipes/Add_U8_000/test.recipe b/res/TensorFlowLiteRecipes/Add_U8_000/test.recipe index 5f2b5b5803d..f4ccc3cc8bb 100644 --- a/res/TensorFlowLiteRecipes/Add_U8_000/test.recipe +++ b/res/TensorFlowLiteRecipes/Add_U8_000/test.recipe @@ -2,19 +2,19 @@ operand { name: "ifm1" type: UINT8 shape { dim: 1 dim: 4 dim: 4 dim: 3 } - quant { min: 0 max: 1 scale: 0.004 zero_point: 0 } + quant { min: 0 max: 255 scale: 1.0 zero_point: 0 } } operand { name: "ifm2" type: UINT8 shape { dim: 1 dim: 4 dim: 4 dim: 3 } - quant { min: 0 max: 1 scale: 0.004 zero_point: 0 } + quant { min: 0 max: 255 scale: 1.0 zero_point: 0 } } operand { name: "ofm" type: UINT8 shape { dim: 1 dim: 4 dim: 4 dim: 3 } - quant { min: 0 max: 1 scale: 0.004 zero_point: 0 } + quant { min: 0 max: 255 scale: 1.0 zero_point: 0 } } operation { type: "Add" diff --git a/res/TensorFlowLiteRecipes/ArgMax_000/test.reverse b/res/TensorFlowLiteRecipes/ArgMax_000/test.reverse new file mode 100644 index 00000000000..e69de29bb2d diff --git a/res/TensorFlowLiteRecipes/ArgMax_001/test.reverse b/res/TensorFlowLiteRecipes/ArgMax_001/test.reverse new file mode 100644 index 00000000000..e69de29bb2d diff --git a/res/TensorFlowLiteRecipes/ArgMax_002/test.reverse b/res/TensorFlowLiteRecipes/ArgMax_002/test.reverse new file mode 100644 index 00000000000..e69de29bb2d diff --git a/res/TensorFlowLiteRecipes/ArgMax_003/test.reverse b/res/TensorFlowLiteRecipes/ArgMax_003/test.reverse new file mode 100644 index 00000000000..e69de29bb2d diff --git a/res/TensorFlowLiteRecipes/ArgMax_U8_000/test.recipe b/res/TensorFlowLiteRecipes/ArgMax_U8_000/test.recipe new file mode 100644 index 00000000000..12e2b250b38 --- /dev/null +++ b/res/TensorFlowLiteRecipes/ArgMax_U8_000/test.recipe @@ -0,0 +1,31 @@ +operand { + name: "ifm" + type: UINT8 + shape { dim: 4 } + quant { min: 0 max: 255 scale: 1.0 zero_point: 0 } +} +operand { + name: "ofm" + type: INT64 + shape { } +} +operand { + name: "argmax/dim" + type: INT32 + shape { } + filler { + tag: "explicit" + arg: "0" + } +} +operation { + type: "ArgMax" + argmax_options { + output_type: INT64 + } + input: "ifm" + input: "argmax/dim" + output: "ofm" +} +input: "ifm" +output: "ofm" diff --git a/res/TensorFlowLiteRecipes/ArgMax_U8_000/test.reverse b/res/TensorFlowLiteRecipes/ArgMax_U8_000/test.reverse new file mode 100644 index 00000000000..e69de29bb2d diff --git a/res/TensorFlowLiteRecipes/ArgMax_U8_001/test.recipe b/res/TensorFlowLiteRecipes/ArgMax_U8_001/test.recipe new file mode 100644 index 00000000000..78a51930474 --- /dev/null +++ b/res/TensorFlowLiteRecipes/ArgMax_U8_001/test.recipe @@ -0,0 +1,31 @@ +operand { + name: "ifm" + type: UINT8 + shape { dim: 4 dim: 5 } + quant { min: 0 max: 255 scale: 1.0 zero_point: 0 } +} +operand { + name: "ofm" + type: INT64 + shape { dim: 5 } +} +operand { + name: "argmax/dim" + type: INT32 + shape { } + filler { + tag: "explicit" + arg: "0" + } +} +operation { + type: "ArgMax" + argmax_options { + output_type: INT64 + } + input: "ifm" + input: "argmax/dim" + output: "ofm" +} +input: "ifm" +output: "ofm" diff --git a/res/TensorFlowLiteRecipes/ArgMax_U8_001/test.reverse b/res/TensorFlowLiteRecipes/ArgMax_U8_001/test.reverse new file mode 100644 index 00000000000..e69de29bb2d diff --git a/res/TensorFlowLiteRecipes/ArgMax_U8_002/test.recipe b/res/TensorFlowLiteRecipes/ArgMax_U8_002/test.recipe new file mode 100644 index 00000000000..3f1e5ec53d9 --- /dev/null +++ b/res/TensorFlowLiteRecipes/ArgMax_U8_002/test.recipe @@ -0,0 +1,31 @@ +operand { + name: "ifm" + type: UINT8 + shape { dim: 4 dim: 5 } + quant { min: 0 max: 255 scale: 1.0 zero_point: 0 } +} +operand { + name: "ofm" + type: INT64 + shape { dim: 4 } +} +operand { + name: "argmax/dim" + type: INT32 + shape { } + filler { + tag: "explicit" + arg: "1" + } +} +operation { + type: "ArgMax" + argmax_options { + output_type: INT64 + } + input: "ifm" + input: "argmax/dim" + output: "ofm" +} +input: "ifm" +output: "ofm" diff --git a/res/TensorFlowLiteRecipes/ArgMax_U8_002/test.reverse b/res/TensorFlowLiteRecipes/ArgMax_U8_002/test.reverse new file mode 100644 index 00000000000..e69de29bb2d diff --git a/res/TensorFlowLiteRecipes/ArgMax_U8_003/test.recipe b/res/TensorFlowLiteRecipes/ArgMax_U8_003/test.recipe new file mode 100644 index 00000000000..2ef29204583 --- /dev/null +++ b/res/TensorFlowLiteRecipes/ArgMax_U8_003/test.recipe @@ -0,0 +1,31 @@ +operand { + name: "ifm" + type: UINT8 + shape { dim: 4 dim: 5 dim: 6 } + quant { min: 0 max: 255 scale: 1.0 zero_point: 0 } +} +operand { + name: "ofm" + type: INT64 + shape { dim: 4 dim: 6 } +} +operand { + name: "argmax/dim" + type: INT32 + shape { } + filler { + tag: "explicit" + arg: "1" + } +} +operation { + type: "ArgMax" + argmax_options { + output_type: INT64 + } + input: "ifm" + input: "argmax/dim" + output: "ofm" +} +input: "ifm" +output: "ofm" diff --git a/res/TensorFlowLiteRecipes/ArgMax_U8_003/test.reverse b/res/TensorFlowLiteRecipes/ArgMax_U8_003/test.reverse new file mode 100644 index 00000000000..e69de29bb2d diff --git a/res/TensorFlowLiteRecipes/Concatenation_U8_000/test.recipe b/res/TensorFlowLiteRecipes/Concatenation_U8_000/test.recipe new file mode 100644 index 00000000000..3ae21e35699 --- /dev/null +++ b/res/TensorFlowLiteRecipes/Concatenation_U8_000/test.recipe @@ -0,0 +1,31 @@ +operand { + name: "ifm1" + type: UINT8 + shape { dim: 1 dim: 4 dim: 4 dim: 1 } + quant { min: 0 max: 255 scale: 1.0 zero_point: 0 } +} +operand { + name: "ifm2" + type: UINT8 + shape { dim: 1 dim: 4 dim: 4 dim: 2 } + quant { min: 0 max: 255 scale: 1.0 zero_point: 0 } +} +operand { + name: "ofm" + type: UINT8 + shape { dim: 1 dim: 4 dim: 4 dim: 3 } + quant { min: 0 max: 255 scale: 1.0 zero_point: 0 } +} +operation { + type: "Concatenation" + concatenation_options { + axis: 3 + activation: NONE + } + input: "ifm1" + input: "ifm2" + output: "ofm" +} +input: "ifm1" +input: "ifm2" +output: "ofm" diff --git a/res/TensorFlowLiteRecipes/Cos_000/test.recipe b/res/TensorFlowLiteRecipes/Cos_000/test.recipe new file mode 100644 index 00000000000..6fa8ac9b8be --- /dev/null +++ b/res/TensorFlowLiteRecipes/Cos_000/test.recipe @@ -0,0 +1,17 @@ +operand { + name: "ifm" + type: FLOAT32 + shape { dim: 1 dim: 3 dim: 3 dim: 2 } +} +operand { + name: "ofm" + type: FLOAT32 + shape { dim: 1 dim: 3 dim: 3 dim: 2 } +} +operation { + type: "Cos" + input: "ifm" + output: "ofm" +} +input: "ifm" +output: "ofm" diff --git a/res/TensorFlowLiteRecipes/Cos_000/test.reverse b/res/TensorFlowLiteRecipes/Cos_000/test.reverse new file mode 100644 index 00000000000..e69de29bb2d diff --git a/res/TensorFlowLiteRecipes/DepthwiseConv2D_U8_000/test.recipe b/res/TensorFlowLiteRecipes/DepthwiseConv2D_U8_000/test.recipe new file mode 100644 index 00000000000..9a4ddf155f8 --- /dev/null +++ b/res/TensorFlowLiteRecipes/DepthwiseConv2D_U8_000/test.recipe @@ -0,0 +1,46 @@ +operand { + name: "ifm" + type: UINT8 + shape { dim: 1 dim: 64 dim: 64 dim: 8 } + quant { min: 0 max: 255 scale: 1.0 zero_point: 0 } +} +operand { + name: "ker" + type: UINT8 + shape { dim: 1 dim: 3 dim: 3 dim: 8 } + quant { min: 0 max: 255 scale: 1.0 zero_point: 0 } +} +operand { + name: "bias" + type: INT32 + shape { dim: 8 } + filler { + tag: "gaussian" + arg: "0" + arg: "1024" + } + quant { min: 0 max: 255 scale: 1.0 zero_point: 0 } +} +operand { + name: "ofm" + type: UINT8 + shape { dim: 1 dim: 64 dim: 64 dim: 8 } + quant { min: 0 max: 255 scale: 1.0 zero_point: 0 } +} +operation { + type: "DepthwiseConv2D" + depthwiseconv2d_options { + padding: SAME + stride_w: 1 + stride_h: 1 + depth_multiplier: 1 + activation : RELU6 + } + input: "ifm" + input: "ker" + input: "bias" + output: "ofm" +} +input: "ifm" +input: "ker" +output: "ofm" diff --git a/res/TensorFlowLiteRecipes/DepthwiseConv2D_U8_000/test.reverse b/res/TensorFlowLiteRecipes/DepthwiseConv2D_U8_000/test.reverse new file mode 100644 index 00000000000..e69de29bb2d diff --git a/res/TensorFlowLiteRecipes/Equal_000/test.recipe b/res/TensorFlowLiteRecipes/Equal_000/test.recipe new file mode 100644 index 00000000000..dcc81f9f5db --- /dev/null +++ b/res/TensorFlowLiteRecipes/Equal_000/test.recipe @@ -0,0 +1,26 @@ +operand { + name: "ifm1" + type: FLOAT32 + shape { dim: 1 dim: 4 dim: 4 dim: 3 } +} +operand { + name: "ifm2" + type: FLOAT32 + shape { dim: 1 dim: 4 dim: 4 dim: 3 } +} +operand { + name: "ofm" + type: BOOL + shape { dim: 1 dim: 4 dim: 4 dim: 3 } +} +operation { + type: "Equal" + equal_options { + } + input: "ifm1" + input: "ifm2" + output: "ofm" +} +input: "ifm1" +input: "ifm2" +output: "ofm" diff --git a/res/TensorFlowLiteRecipes/Equal_000/test.reverse b/res/TensorFlowLiteRecipes/Equal_000/test.reverse new file mode 100644 index 00000000000..e69de29bb2d diff --git a/res/TensorFlowLiteRecipes/FullyConnected_U8_000/test.recipe b/res/TensorFlowLiteRecipes/FullyConnected_U8_000/test.recipe new file mode 100644 index 00000000000..3c996218ffd --- /dev/null +++ b/res/TensorFlowLiteRecipes/FullyConnected_U8_000/test.recipe @@ -0,0 +1,35 @@ +operand { + name: "in" + type: FLOAT32 + shape { dim: 1 dim: 64 } +} +operand { + name: "weight" + type: UINT8 + shape { dim: 8 dim: 64 } + quant { min: 0 max: 1 scale: 0.000553869 zero_point: 0 } +} +operand { + name: "bias" + type: FLOAT32 + shape { dim: 8 } +} +operand { + name: "out" + type: FLOAT32 + shape { dim: 1 dim: 8 } +} +operation { + type: "FullyConnected" + fullyconnected_options { + activation: NONE + } + input: "in" + input: "weight" + input: "bias" + output: "out" +} +input: "in" +input: "weight" +input: "bias" +output: "out" diff --git a/res/TensorFlowLiteRecipes/FullyConnected_U8_000/test.reverse b/res/TensorFlowLiteRecipes/FullyConnected_U8_000/test.reverse new file mode 100644 index 00000000000..e69de29bb2d diff --git a/res/TensorFlowLiteRecipes/LogicalNot_000/test.recipe b/res/TensorFlowLiteRecipes/LogicalNot_000/test.recipe new file mode 100644 index 00000000000..da02bd9afa9 --- /dev/null +++ b/res/TensorFlowLiteRecipes/LogicalNot_000/test.recipe @@ -0,0 +1,17 @@ +operand { + name: "ifm" + type: BOOL + shape { dim: 1 dim: 3 dim: 3 dim: 2 } +} +operand { + name: "ofm" + type: BOOL + shape { dim: 1 dim: 3 dim: 3 dim: 2 } +} +operation { + type: "LogicalNot" + input: "ifm" + output: "ofm" +} +input: "ifm" +output: "ofm" diff --git a/res/TensorFlowLiteRecipes/LogicalNot_000/test.reverse b/res/TensorFlowLiteRecipes/LogicalNot_000/test.reverse new file mode 100644 index 00000000000..e69de29bb2d diff --git a/res/TensorFlowLiteRecipes/LogicalOr_000/test.recipe b/res/TensorFlowLiteRecipes/LogicalOr_000/test.recipe new file mode 100644 index 00000000000..636c8b857b9 --- /dev/null +++ b/res/TensorFlowLiteRecipes/LogicalOr_000/test.recipe @@ -0,0 +1,24 @@ +operand { + name: "ifm1" + type: BOOL + shape { dim: 1 dim: 4 dim: 4 dim: 3 } +} +operand { + name: "ifm2" + type: BOOL + shape { dim: 1 dim: 4 dim: 4 dim: 3 } +} +operand { + name: "ofm" + type: BOOL + shape { dim: 1 dim: 4 dim: 4 dim: 3 } +} +operation { + type: "LogicalOr" + input: "ifm1" + input: "ifm2" + output: "ofm" +} +input: "ifm1" +input: "ifm2" +output: "ofm" diff --git a/res/TensorFlowLiteRecipes/LogicalOr_000/test.reverse b/res/TensorFlowLiteRecipes/LogicalOr_000/test.reverse new file mode 100644 index 00000000000..e69de29bb2d diff --git a/res/TensorFlowLiteRecipes/Mean_000/test.recipe b/res/TensorFlowLiteRecipes/Mean_000/test.recipe new file mode 100644 index 00000000000..d383997d3a8 --- /dev/null +++ b/res/TensorFlowLiteRecipes/Mean_000/test.recipe @@ -0,0 +1,27 @@ +operand { + name: "ifm" + type: FLOAT32 + shape { dim: 1 dim: 8 dim: 8 dim: 4 } +} +operand { + name: "reduction_indices" + type: INT32 + shape { dim: 1 } + filler { tag: "explicit" arg: "-1" } +} +operand { + name: "ofm" + type: FLOAT32 + shape { dim: 1 dim: 8 dim: 8 dim: 1 } +} +operation { + type: "Mean" + mean_options { + keep_dims: true + } + input: "ifm" + input: "reduction_indices" + output: "ofm" +} +input: "ifm" +output: "ofm" diff --git a/res/TensorFlowLiteRecipes/Mul_000/test.recipe b/res/TensorFlowLiteRecipes/Mul_000/test.recipe new file mode 100644 index 00000000000..43ca30dece5 --- /dev/null +++ b/res/TensorFlowLiteRecipes/Mul_000/test.recipe @@ -0,0 +1,27 @@ +operand { + name: "ifm1" + type: FLOAT32 + shape { dim: 1 dim: 4 dim: 4 dim: 3 } +} +operand { + name: "ifm2" + type: FLOAT32 + shape { dim: 1 dim: 4 dim: 4 dim: 3 } +} +operand { + name: "ofm" + type: FLOAT32 + shape { dim: 1 dim: 4 dim: 4 dim: 3 } +} +operation { + type: "Mul" + input: "ifm1" + input: "ifm2" + output: "ofm" + mul_options { + activation: NONE + } +} +input: "ifm1" +input: "ifm2" +output: "ofm" diff --git a/res/TensorFlowLiteRecipes/Mul_U8_000/test.recipe b/res/TensorFlowLiteRecipes/Mul_U8_000/test.recipe new file mode 100644 index 00000000000..2fbf96d294a --- /dev/null +++ b/res/TensorFlowLiteRecipes/Mul_U8_000/test.recipe @@ -0,0 +1,30 @@ +operand { + name: "ifm1" + type: UINT8 + shape { dim: 1 dim: 4 dim: 4 dim: 3 } + quant { min: 0 max: 255 scale: 0.5 zero_point: 0 } +} +operand { + name: "ifm2" + type: UINT8 + shape { dim: 1 dim: 4 dim: 4 dim: 3 } + quant { min: 0 max: 255 scale: 0.5 zero_point: 0 } +} +operand { + name: "ofm" + type: UINT8 + shape { dim: 1 dim: 4 dim: 4 dim: 3 } + quant { min: 0 max: 255 scale: 0.5 zero_point: 0 } +} +operation { + type: "Mul" + input: "ifm1" + input: "ifm2" + output: "ofm" + mul_options { + activation: NONE + } +} +input: "ifm1" +input: "ifm2" +output: "ofm" diff --git a/res/TensorFlowLiteRecipes/Pack_000/test.recipe b/res/TensorFlowLiteRecipes/Pack_000/test.recipe new file mode 100644 index 00000000000..5d9141d9ee1 --- /dev/null +++ b/res/TensorFlowLiteRecipes/Pack_000/test.recipe @@ -0,0 +1,28 @@ +operand { + name: "input" + type: FLOAT32 + shape { dim: 2 dim: 4 dim: 3 } +} +operand { + name: "input_1" + type: FLOAT32 + shape { dim: 2 dim: 4 dim: 3 } +} +operand { + name: "stack_4d" + type: FLOAT32 + shape { dim: 2 dim: 2 dim: 4 dim: 3 } +} +operation { + type: "Pack" + pack_options { + values_count: 2, + axis: 1 + } + input: "input" + input: "input_1" + output: "stack_4d" +} +input: "input" +input: "input_1" +output: "stack_4d" diff --git a/res/TensorFlowLiteRecipes/Pack_000/test.reverse b/res/TensorFlowLiteRecipes/Pack_000/test.reverse new file mode 100644 index 00000000000..e69de29bb2d diff --git a/res/TensorFlowLiteRecipes/Pack_U8_000/test.recipe b/res/TensorFlowLiteRecipes/Pack_U8_000/test.recipe new file mode 100644 index 00000000000..f0019998047 --- /dev/null +++ b/res/TensorFlowLiteRecipes/Pack_U8_000/test.recipe @@ -0,0 +1,31 @@ +operand { + name: "input" + type: UINT8 + shape { dim: 2 dim: 4 dim: 3 } + quant { min: 0 max: 255 scale: 1.0 zero_point: 0 } +} +operand { + name: "input_1" + type: UINT8 + shape { dim: 2 dim: 4 dim: 3 } + quant { min: 0 max: 255 scale: 1.0 zero_point: 0 } +} +operand { + name: "stack_4d" + type: UINT8 + shape { dim: 2 dim: 2 dim: 4 dim: 3 } + quant { min: 0 max: 255 scale: 1.0 zero_point: 0 } +} +operation { + type: "Pack" + pack_options { + values_count: 2, + axis: 1 + } + input: "input" + input: "input_1" + output: "stack_4d" +} +input: "input" +input: "input_1" +output: "stack_4d" diff --git a/res/TensorFlowLiteRecipes/Pack_U8_000/test.reverse b/res/TensorFlowLiteRecipes/Pack_U8_000/test.reverse new file mode 100644 index 00000000000..e69de29bb2d diff --git a/res/TensorFlowLiteRecipes/Pad_000/test.recipe b/res/TensorFlowLiteRecipes/Pad_000/test.recipe new file mode 100644 index 00000000000..2cc980b9c55 --- /dev/null +++ b/res/TensorFlowLiteRecipes/Pad_000/test.recipe @@ -0,0 +1,30 @@ +operand { + name: "ifm" + type: FLOAT32 + shape { dim: 1 dim: 3 dim: 3 dim: 2 } +} +operand { + name: "padding" + type: INT32 + shape { dim: 4 dim: 2 } + filler { + tag: "explicit" + arg: "0" arg: "0" + arg: "1" arg: "1" + arg: "2" arg: "2" + arg: "0" arg: "0" + } +} +operand { + name: "ofm" + type: FLOAT32 + shape { dim: 1 dim: 5 dim: 7 dim: 2 } +} +operation { + type: "Pad" + input: "ifm" + input: "padding" + output: "ofm" +} +input: "ifm" +output: "ofm" diff --git a/res/TensorFlowLiteRecipes/Pad_U8_000/test.recipe b/res/TensorFlowLiteRecipes/Pad_U8_000/test.recipe new file mode 100644 index 00000000000..7a835bdb8ea --- /dev/null +++ b/res/TensorFlowLiteRecipes/Pad_U8_000/test.recipe @@ -0,0 +1,32 @@ +operand { + name: "ifm" + type: UINT8 + shape { dim: 1 dim: 3 dim: 3 dim: 2 } + quant { min: 0 max: 255 scale: 1.0 zero_point: 0 } +} +operand { + name: "padding" + type: INT32 + shape { dim: 4 dim: 2 } + filler { + tag: "explicit" + arg: "0" arg: "0" + arg: "1" arg: "1" + arg: "2" arg: "2" + arg: "0" arg: "0" + } +} +operand { + name: "ofm" + type: UINT8 + shape { dim: 1 dim: 5 dim: 7 dim: 2 } + quant { min: 0 max: 255 scale: 1.0 zero_point: 0 } +} +operation { + type: "Pad" + input: "ifm" + input: "padding" + output: "ofm" +} +input: "ifm" +output: "ofm" diff --git a/res/TensorFlowLiteRecipes/Reshape_U8_000/test.recipe b/res/TensorFlowLiteRecipes/Reshape_U8_000/test.recipe index 8633a267f4f..5fe10e599cd 100644 --- a/res/TensorFlowLiteRecipes/Reshape_U8_000/test.recipe +++ b/res/TensorFlowLiteRecipes/Reshape_U8_000/test.recipe @@ -1,18 +1,20 @@ operand { name: "ifm" type: UINT8 - shape { dim: 1 dim: 3 dim: 3 dim: 1 } - quant { min: 0 max: 1 scale: 0.004 zero_point: 0 } + shape { dim: 1 dim: 1 dim: 1 dim: 10 } + quant { min: 0 max: 255 scale: 1.0 zero_point: 0 } } operand { name: "ofm" type: UINT8 - shape { dim: 1 dim: 3 dim: 3 dim: 1 } - quant { min: 0 max: 1 scale: 0.004 zero_point: 0 } + shape { dim: 10 } + quant { min: 0 max: 255 scale: 1.0 zero_point: 0 } } operation { type: "Reshape" - reshape_options { new_shape: 1 new_shape: 3 new_shape: 3 new_shape: 1 } + reshape_options { + new_shape: 10 + } input: "ifm" output: "ofm" } diff --git a/res/TensorFlowLiteRecipes/Softmax_000/test.recipe b/res/TensorFlowLiteRecipes/Softmax_000/test.recipe new file mode 100644 index 00000000000..ce9abf55589 --- /dev/null +++ b/res/TensorFlowLiteRecipes/Softmax_000/test.recipe @@ -0,0 +1,20 @@ +operand { + name: "ifm" + type: FLOAT32 + shape { dim: 1 dim: 3 dim: 3 dim: 2 } +} +operand { + name: "ofm" + type: FLOAT32 + shape { dim: 1 dim: 3 dim: 3 dim: 2 } +} +operation { + type: "Softmax" + softmax_options { + beta: 0.0 + } + input: "ifm" + output: "ofm" +} +input: "ifm" +output: "ofm" diff --git a/res/TensorFlowLiteRecipes/Softmax_000/test.reverse b/res/TensorFlowLiteRecipes/Softmax_000/test.reverse new file mode 100644 index 00000000000..e69de29bb2d diff --git a/res/TensorFlowLiteRecipes/Softmax_U8_000/test.recipe b/res/TensorFlowLiteRecipes/Softmax_U8_000/test.recipe new file mode 100644 index 00000000000..a753ca43767 --- /dev/null +++ b/res/TensorFlowLiteRecipes/Softmax_U8_000/test.recipe @@ -0,0 +1,22 @@ +operand { + name: "ifm" + type: UINT8 + shape { dim: 1 dim: 1001 } + quant { min: -6.02353 max: 5.97647 scale: 0.0470588 zero_point: 128 } +} +operand { + name: "ofm" + type: UINT8 + shape { dim: 1 dim: 1001 } + quant { min: 0 max: 0.996094 scale: 0.00390625 zero_point: 0 } +} +operation { + type: "Softmax" + softmax_options { + beta: 1.0 + } + input: "ifm" + output: "ofm" +} +input: "ifm" +output: "ofm" diff --git a/res/TensorFlowLiteRecipes/Softmax_U8_000/test.reverse b/res/TensorFlowLiteRecipes/Softmax_U8_000/test.reverse new file mode 100644 index 00000000000..e69de29bb2d diff --git a/res/TensorFlowLiteRecipes/Sub_U8_000/test.recipe b/res/TensorFlowLiteRecipes/Sub_U8_000/test.recipe new file mode 100644 index 00000000000..eeeb8aaccf0 --- /dev/null +++ b/res/TensorFlowLiteRecipes/Sub_U8_000/test.recipe @@ -0,0 +1,30 @@ +operand { + name: "ifm1" + type: UINT8 + shape { dim: 1 dim: 4 dim: 4 dim: 3 } + quant { min: 0 max: 255 scale: 1.0 zero_point: 0 } +} +operand { + name: "ifm2" + type: UINT8 + shape { dim: 1 dim: 4 dim: 4 dim: 3 } + quant { min: 0 max: 255 scale: 1.0 zero_point: 0 } +} +operand { + name: "ofm" + type: UINT8 + shape { dim: 1 dim: 4 dim: 4 dim: 3 } + quant { min: 0 max: 255 scale: 1.0 zero_point: 0 } +} +operation { + type: "Sub" + input: "ifm1" + input: "ifm2" + output: "ofm" + sub_options { + activation: NONE + } +} +input: "ifm1" +input: "ifm2" +output: "ofm" diff --git a/res/TensorFlowLiteRecipes/Sub_U8_000/test.reverse b/res/TensorFlowLiteRecipes/Sub_U8_000/test.reverse new file mode 100644 index 00000000000..e69de29bb2d diff --git a/res/TensorFlowLiteRecipes/Transpose_000/test.recipe b/res/TensorFlowLiteRecipes/Transpose_000/test.recipe new file mode 100644 index 00000000000..82a85c13b11 --- /dev/null +++ b/res/TensorFlowLiteRecipes/Transpose_000/test.recipe @@ -0,0 +1,27 @@ +operand { + name: "ifm" + type: FLOAT32 + shape { dim: 3 dim: 8 dim: 1 } +} +operand { + name: "perm" + type: INT32 + shape { dim: 3 } + filler { tag: "explicit" arg: "1" arg: "2" arg: "0" } +} +operand { + name: "ofm" + type: FLOAT32 + shape { dim: 8 dim: 1 dim: 3 } +} + +operation { + type: "Transpose" + transpose_options { + } + input: "ifm" + input: "perm" + output: "ofm" +} +input: "ifm" +output: "ofm" diff --git a/res/TensorFlowLiteRecipes/Transpose_000/test.reverse b/res/TensorFlowLiteRecipes/Transpose_000/test.reverse new file mode 100644 index 00000000000..e69de29bb2d diff --git a/runtime/neurun/frontend/tflite/tflite_schema.fbs b/res/TensorFlowLiteSchema/1.13.1/schema.fbs similarity index 99% rename from runtime/neurun/frontend/tflite/tflite_schema.fbs rename to res/TensorFlowLiteSchema/1.13.1/schema.fbs index ede4dfa3ac7..980f13b19b4 100644 --- a/runtime/neurun/frontend/tflite/tflite_schema.fbs +++ b/res/TensorFlowLiteSchema/1.13.1/schema.fbs @@ -18,8 +18,7 @@ // Version 2: Rename operators to conform to NN API. // Version 3: Move buffer data from Model.Subgraph.Tensors to Model.Buffers. -// Change namespace to neurun_tflite -namespace neurun_tflite; +namespace tflite; // This corresponds to the version. file_identifier "TFL3"; diff --git a/res/TensorFlowLiteSchema/1.14.0/schema.fbs b/res/TensorFlowLiteSchema/1.14.0/schema.fbs new file mode 100644 index 00000000000..b5fc0f31be0 --- /dev/null +++ b/res/TensorFlowLiteSchema/1.14.0/schema.fbs @@ -0,0 +1,873 @@ +// Copyright 2017 The TensorFlow Authors. 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. + +// Revision History +// Version 0: Initial version. +// Version 1: Add subgraphs to schema. +// Version 2: Rename operators to conform to NN API. +// Version 3: Move buffer data from Model.Subgraph.Tensors to Model.Buffers. + +namespace tflite; + +// This corresponds to the version. +file_identifier "TFL3"; +// File extension of any written files. +file_extension "tflite"; + +// IMPORTANT: All new members of tables, enums and unions must be added at the +// end to ensure backwards compatibility. + +// The type of data stored in a tensor. +enum TensorType : byte { + FLOAT32 = 0, + FLOAT16 = 1, + INT32 = 2, + UINT8 = 3, + INT64 = 4, + STRING = 5, + BOOL = 6, + INT16 = 7, + COMPLEX64 = 8, + INT8 = 9, +} + +// Custom quantization parameters for experimenting with new quantization +// techniques. +table CustomQuantization { + custom:[ubyte] (force_align: 16); +} + +// Represents a specific quantization technique's parameters. +union QuantizationDetails { + CustomQuantization, +} + +// Parameters for converting a quantized tensor back to float. +table QuantizationParameters { + // These four parameters are the asymmetric linear quantization parameters. + // Given a quantized value q, the corresponding float value f should be: + // f = scale * (q - zero_point) + // For other quantization types, the QuantizationDetails below is used. + min:[float]; // For importing back into tensorflow. + max:[float]; // For importing back into tensorflow. + scale:[float]; // For dequantizing the tensor's values. + zero_point:[long]; + + // If this is not none, the other quantization parameters (i.e. min, max, + // scale, zero_point fields above) are ignored and the value of the + // QuantizationDetails union should be used. + details:QuantizationDetails; + + // Specifies the dimension of the Tensor's shape that the scales and + // zero_points correspond to. For example, a tensor t, with dims=[4, 3, 2, 1] + // with quantization params: + // scale=[1.0, 2.0, 3.0], zero_point=[1, 2, 3], quantization_dimension=1 + // will be quantized across the second dimension of t. + // t[:, 0, :, :] will have scale[0]=1.0, zero_point[0]=1 + // t[:, 1, :, :] will have scale[1]=2.0, zero_point[0]=2 + // t[:, 2, :, :] will have scale[2]=3.0, zero_point[0]=3 + quantized_dimension:int; +} + +table Tensor { + // The tensor shape. The meaning of each entry is operator-specific but + // builtin ops use: [batch size, height, width, number of channels] (That's + // Tensorflow's NHWC). + shape:[int]; + type:TensorType; + // An index that refers to the buffers table at the root of the model. Or, + // if there is no data buffer associated (i.e. intermediate results), then + // this is 0 (which refers to an always existent empty buffer). + // + // The data_buffer itself is an opaque container, with the assumption that the + // target device is little-endian. In addition, all builtin operators assume + // the memory is ordered such that if `shape` is [4, 3, 2], then index + // [i, j, k] maps to data_buffer[i*3*2 + j*2 + k]. + buffer:uint; + name:string; // For debugging and importing back into tensorflow. + quantization:QuantizationParameters; // Optional. + + is_variable:bool = false; +} + +// A list of builtin operators. Builtin operators are slightly faster than custom +// ones, but not by much. Moreover, while custom operators accept an opaque +// object containing configuration parameters, builtins have a predetermined +// set of acceptable options. +enum BuiltinOperator : byte { + ADD = 0, + AVERAGE_POOL_2D = 1, + CONCATENATION = 2, + CONV_2D = 3, + DEPTHWISE_CONV_2D = 4, + // DEPTH_TO_SPACE = 5, + DEQUANTIZE = 6, + EMBEDDING_LOOKUP = 7, + FLOOR = 8, + FULLY_CONNECTED = 9, + HASHTABLE_LOOKUP = 10, + L2_NORMALIZATION = 11, + L2_POOL_2D = 12, + LOCAL_RESPONSE_NORMALIZATION = 13, + LOGISTIC = 14, + LSH_PROJECTION = 15, + LSTM = 16, + MAX_POOL_2D = 17, + MUL = 18, + RELU = 19, + // NOTE(aselle): RELU_N1_TO_1 used to be called RELU1, but it was renamed + // since different model developers use RELU1 in different ways. Never + // create another op called RELU1. + RELU_N1_TO_1 = 20, + RELU6 = 21, + RESHAPE = 22, + RESIZE_BILINEAR = 23, + RNN = 24, + SOFTMAX = 25, + SPACE_TO_DEPTH = 26, + SVDF = 27, + TANH = 28, + // TODO(aselle): Consider rename to CONCATENATE_EMBEDDINGS + CONCAT_EMBEDDINGS = 29, + SKIP_GRAM = 30, + CALL = 31, + CUSTOM = 32, + EMBEDDING_LOOKUP_SPARSE = 33, + PAD = 34, + UNIDIRECTIONAL_SEQUENCE_RNN = 35, + GATHER = 36, + BATCH_TO_SPACE_ND = 37, + SPACE_TO_BATCH_ND = 38, + TRANSPOSE = 39, + MEAN = 40, + SUB = 41, + DIV = 42, + SQUEEZE = 43, + UNIDIRECTIONAL_SEQUENCE_LSTM = 44, + STRIDED_SLICE = 45, + BIDIRECTIONAL_SEQUENCE_RNN = 46, + EXP = 47, + TOPK_V2 = 48, + SPLIT = 49, + LOG_SOFTMAX = 50, + // DELEGATE is a special op type for the operations which are delegated to + // other backends. + // WARNING: Experimental interface, subject to change + DELEGATE = 51, + BIDIRECTIONAL_SEQUENCE_LSTM = 52, + CAST = 53, + PRELU = 54, + MAXIMUM = 55, + ARG_MAX = 56, + MINIMUM = 57, + LESS = 58, + NEG = 59, + PADV2 = 60, + GREATER = 61, + GREATER_EQUAL = 62, + LESS_EQUAL = 63, + SELECT = 64, + SLICE = 65, + SIN = 66, + TRANSPOSE_CONV = 67, + SPARSE_TO_DENSE = 68, + TILE = 69, + EXPAND_DIMS = 70, + EQUAL = 71, + NOT_EQUAL = 72, + LOG = 73, + SUM = 74, + SQRT = 75, + RSQRT = 76, + SHAPE = 77, + POW = 78, + ARG_MIN = 79, + FAKE_QUANT = 80, + REDUCE_PROD = 81, + REDUCE_MAX = 82, + PACK = 83, + LOGICAL_OR = 84, + ONE_HOT = 85, + LOGICAL_AND = 86, + LOGICAL_NOT = 87, + UNPACK = 88, + REDUCE_MIN = 89, + FLOOR_DIV = 90, + REDUCE_ANY = 91, + SQUARE = 92, + ZEROS_LIKE = 93, + FILL = 94, + FLOOR_MOD = 95, + RANGE = 96, + RESIZE_NEAREST_NEIGHBOR = 97, + LEAKY_RELU = 98, + SQUARED_DIFFERENCE = 99, + MIRROR_PAD = 100, + ABS = 101, + SPLIT_V = 102, + UNIQUE = 103, + CEIL = 104, + REVERSE_V2 = 105, + ADD_N = 106, + GATHER_ND = 107, + COS = 108, + WHERE = 109, + RANK = 110, + ELU = 111, + REVERSE_SEQUENCE = 112, + MATRIX_DIAG = 113, + QUANTIZE = 114, + MATRIX_SET_DIAG = 115, + ROUND = 116, +} + +// Options for the builtin operators. +union BuiltinOptions { + Conv2DOptions, + DepthwiseConv2DOptions, + ConcatEmbeddingsOptions, + LSHProjectionOptions, + Pool2DOptions, + SVDFOptions, + RNNOptions, + FullyConnectedOptions, + SoftmaxOptions, + ConcatenationOptions, + AddOptions, + L2NormOptions, + LocalResponseNormalizationOptions, + LSTMOptions, + ResizeBilinearOptions, + CallOptions, + ReshapeOptions, + SkipGramOptions, + SpaceToDepthOptions, + EmbeddingLookupSparseOptions, + MulOptions, + PadOptions, + GatherOptions, + BatchToSpaceNDOptions, + SpaceToBatchNDOptions, + TransposeOptions, + ReducerOptions, + SubOptions, + DivOptions, + SqueezeOptions, + SequenceRNNOptions, + StridedSliceOptions, + ExpOptions, + TopKV2Options, + SplitOptions, + LogSoftmaxOptions, + CastOptions, + DequantizeOptions, + MaximumMinimumOptions, + ArgMaxOptions, + LessOptions, + NegOptions, + PadV2Options, + GreaterOptions, + GreaterEqualOptions, + LessEqualOptions, + SelectOptions, + SliceOptions, + TransposeConvOptions, + SparseToDenseOptions, + TileOptions, + ExpandDimsOptions, + EqualOptions, + NotEqualOptions, + ShapeOptions, + PowOptions, + ArgMinOptions, + FakeQuantOptions, + PackOptions, + LogicalOrOptions, + OneHotOptions, + LogicalAndOptions, + LogicalNotOptions, + UnpackOptions, + FloorDivOptions, + SquareOptions, + ZerosLikeOptions, + FillOptions, + BidirectionalSequenceLSTMOptions, + BidirectionalSequenceRNNOptions, + UnidirectionalSequenceLSTMOptions, + FloorModOptions, + RangeOptions, + ResizeNearestNeighborOptions, + LeakyReluOptions, + SquaredDifferenceOptions, + MirrorPadOptions, + AbsOptions, + SplitVOptions, + UniqueOptions, + ReverseV2Options, + AddNOptions, + GatherNdOptions, + CosOptions, + WhereOptions, + RankOptions, + ReverseSequenceOptions, + MatrixDiagOptions, + QuantizeOptions, + MatrixSetDiagOptions +} + +enum Padding : byte { SAME, VALID } + +enum ActivationFunctionType : byte { + NONE = 0, + RELU = 1, + RELU_N1_TO_1 = 2, + RELU6 = 3, + TANH = 4, + SIGN_BIT = 5, +} + +table Conv2DOptions { + padding:Padding; + stride_w:int; + stride_h:int; + fused_activation_function:ActivationFunctionType; + dilation_w_factor:int = 1; + dilation_h_factor:int = 1; +} + +table Pool2DOptions { + padding:Padding; + stride_w:int; + stride_h:int; + filter_width:int; + filter_height:int; + fused_activation_function:ActivationFunctionType; +} + +table DepthwiseConv2DOptions { + // Parameters for DepthwiseConv version 1 or above. + padding:Padding; + stride_w:int; + stride_h:int; + depth_multiplier:int; + fused_activation_function:ActivationFunctionType; + // Parameters for DepthwiseConv version 2 or above. + dilation_w_factor:int = 1; + dilation_h_factor:int = 1; +} + +table ConcatEmbeddingsOptions { + num_channels:int; + num_columns_per_channel:[int]; + embedding_dim_per_channel:[int]; // This could be inferred from parameters. +} + +enum LSHProjectionType: byte { + UNKNOWN = 0, + SPARSE = 1, + DENSE = 2, +} + +table LSHProjectionOptions { + type: LSHProjectionType; +} + +table SVDFOptions { + rank:int; + fused_activation_function:ActivationFunctionType; +} + +// An implementation of TensorFlow RNNCell. +table RNNOptions { + fused_activation_function:ActivationFunctionType; +} + +// An implementation of TensorFlow dynamic_rnn with RNNCell. +table SequenceRNNOptions { + time_major:bool; + fused_activation_function:ActivationFunctionType; +} + +// An implementation of TensorFlow bidrectional_dynamic_rnn with RNNCell. +table BidirectionalSequenceRNNOptions { + time_major:bool; + fused_activation_function:ActivationFunctionType; + merge_outputs: bool; +} + +enum FullyConnectedOptionsWeightsFormat: byte { + DEFAULT = 0, + SHUFFLED4x16INT8 = 1, +} + +// An implementation of TensorFlow fully_connected (a.k.a Dense) layer. +table FullyConnectedOptions { + // Parameters for FullyConnected version 1 or above. + fused_activation_function:ActivationFunctionType; + + // Parameters for FullyConnected version 2 or above. + weights_format:FullyConnectedOptionsWeightsFormat = DEFAULT; +} + +table SoftmaxOptions { + beta: float; +} + +// An implementation of TensorFlow concat. +table ConcatenationOptions { + axis:int; + fused_activation_function:ActivationFunctionType; +} + +table AddOptions { + fused_activation_function:ActivationFunctionType; +} + +table MulOptions { + fused_activation_function:ActivationFunctionType; +} + +table L2NormOptions { + fused_activation_function:ActivationFunctionType; +} + +table LocalResponseNormalizationOptions { + radius:int; + bias:float; + alpha:float; + beta:float; +} + +enum LSTMKernelType : byte { + // Full LSTM kernel which supports peephole and projection. + FULL = 0, + // Basic LSTM kernels. Equivalent to TensorFlow BasicLSTMCell. + BASIC = 1, +} + +// An implementation of TensorFlow LSTMCell and CoupledInputForgetGateLSTMCell +table LSTMOptions { + // Parameters for LSTM version 1 or above. + fused_activation_function:ActivationFunctionType; + cell_clip: float; // Optional, 0.0 means no clipping + proj_clip: float; // Optional, 0.0 means no clipping + + // Parameters for LSTM version 2 or above. + // Basic kernel is only supported in version 2 or above. + kernel_type: LSTMKernelType = FULL; +} + +// An implementation of TensorFlow dynamic_rnn with LSTMCell. +table UnidirectionalSequenceLSTMOptions { + fused_activation_function:ActivationFunctionType; + cell_clip: float; // Optional, 0.0 means no clipping + proj_clip: float; // Optional, 0.0 means no clipping + + // If true then first dimension is sequence, otherwise batch. + time_major:bool; +} + +table BidirectionalSequenceLSTMOptions { + // Parameters supported by version 1: + fused_activation_function:ActivationFunctionType; + cell_clip: float; // Optional, 0.0 means no clipping + proj_clip: float; // Optional, 0.0 means no clipping + + // If true, store the outputs of both directions into the first output. + merge_outputs: bool; + + // Parameters supported by version 2: + // If true then first dimension is sequence, otherwise batch. + // Version 1 implementations assumed time_major to be true, so this default + // value should never change. + time_major: bool = true; +} + +table ResizeBilinearOptions { + new_height: int (deprecated); + new_width: int (deprecated); + align_corners: bool; +} + +table ResizeNearestNeighborOptions { + align_corners: bool; +} + +// A call operation options +table CallOptions { + // The subgraph index that needs to be called. + subgraph:uint; +} + +table PadOptions { +} + +table PadV2Options { +} + +table ReshapeOptions { + new_shape:[int]; +} + +table SpaceToBatchNDOptions { +} + +table BatchToSpaceNDOptions { +} + +table SkipGramOptions { + ngram_size: int; + max_skip_size: int; + include_all_ngrams: bool; +} + +table SpaceToDepthOptions { + block_size: int; +} + +table SubOptions { + fused_activation_function:ActivationFunctionType; +} + +table DivOptions { + fused_activation_function:ActivationFunctionType; +} + +table TopKV2Options { +} + +enum CombinerType : byte { + SUM = 0, + MEAN = 1, + SQRTN = 2, +} + +table EmbeddingLookupSparseOptions { + combiner:CombinerType; +} + +table GatherOptions { + axis: int; +} + +table TransposeOptions { +} + +table ExpOptions { +} + +table CosOptions { +} + +table ReducerOptions { + keep_dims: bool; +} + +table SqueezeOptions { + squeeze_dims:[int]; +} + +table SplitOptions { + num_splits: int; +} + +table SplitVOptions { + num_splits: int; +} + +table StridedSliceOptions { + begin_mask: int; + end_mask: int; + ellipsis_mask: int; + new_axis_mask: int; + shrink_axis_mask: int; +} + +table LogSoftmaxOptions { +} + +table CastOptions { + in_data_type: TensorType; + out_data_type: TensorType; +} + +table DequantizeOptions { +} + +table MaximumMinimumOptions { +} + +table TileOptions { +} + +table ArgMaxOptions { + output_type : TensorType; +} + +table ArgMinOptions { + output_type : TensorType; +} + +table GreaterOptions { +} + +table GreaterEqualOptions { +} + +table LessOptions { +} + +table LessEqualOptions { +} + +table NegOptions { +} + +table SelectOptions { +} + +table SliceOptions { +} + +table TransposeConvOptions { + padding:Padding; + stride_w:int; + stride_h:int; +} + +table ExpandDimsOptions { +} + +table SparseToDenseOptions { + validate_indices:bool; +} + +table EqualOptions { +} + +table NotEqualOptions { +} + +table ShapeOptions { + // Optional output type of the operation (int32 or int64). Defaults to int32. + out_type : TensorType; +} + +table RankOptions { +} + +table PowOptions { +} + +table FakeQuantOptions { + // Parameters supported by version 1: + min:float; + max:float; + num_bits:int; + + // Parameters supported by version 2: + narrow_range:bool; +} + +table PackOptions { + values_count:int; + axis:int; +} + +table LogicalOrOptions { +} + +table OneHotOptions { + axis:int; +} + +table AbsOptions { +} + + +table LogicalAndOptions { +} + +table LogicalNotOptions { +} + +table UnpackOptions { + num:int; + axis:int; +} + +table FloorDivOptions { +} + +table SquareOptions { +} + +table ZerosLikeOptions { +} + +table FillOptions { +} + +table FloorModOptions { +} + +table RangeOptions { +} + +table LeakyReluOptions { + alpha:float; +} + +table SquaredDifferenceOptions { +} + +enum MirrorPadMode : byte { + // Doesn't include borders. + REFLECT = 0, + // Includes borders. + SYMMETRIC = 1, +} + +table MirrorPadOptions { + mode:MirrorPadMode; +} + +table UniqueOptions { + idx_out_type:TensorType = INT32; +} + +table ReverseV2Options { +} + +table AddNOptions { +} + +table GatherNdOptions { +} + +table WhereOptions { +} + +table ReverseSequenceOptions { + seq_dim:int; + batch_dim:int = 0; +} + +table MatrixDiagOptions { +} + +table QuantizeOptions { +} + +table MatrixSetDiagOptions { +} + +// An OperatorCode can be an enum value (BuiltinOperator) if the operator is a +// builtin, or a string if the operator is custom. +table OperatorCode { + builtin_code:BuiltinOperator; + custom_code:string; + + // The version of the operator. The version need to be bumped whenever new + // parameters are introduced into an op. + version:int = 1; +} + +enum CustomOptionsFormat : byte { + FLEXBUFFERS = 0, +} + +// An operator takes tensors as inputs and outputs. The type of operation being +// performed is determined by an index into the list of valid OperatorCodes, +// while the specifics of each operations is configured using builtin_options +// or custom_options. +table Operator { + // Index into the operator_codes array. Using an integer here avoids + // complicate map lookups. + opcode_index:uint; + + // Optional input and output tensors are indicated by -1. + inputs:[int]; + outputs:[int]; + + builtin_options:BuiltinOptions; + custom_options:[ubyte]; + custom_options_format:CustomOptionsFormat; + + // A list of booleans indicating the input tensors which are being mutated by + // this operator.(e.g. used by RNN and LSTM). + // For example, if the "inputs" array refers to 5 tensors and the second and + // fifth are mutable variables, then this list will contain + // [false, true, false, false, true]. + // + // If the list is empty, no variable is mutated in this operator. + // The list either has the same length as `inputs`, or is empty. + mutating_variable_inputs:[bool]; +} + +// The root type, defining a subgraph, which typically represents an entire +// model. +table SubGraph { + // A list of all tensors used in this subgraph. + tensors:[Tensor]; + + // Indices of the tensors that are inputs into this subgraph. Note this is + // the list of non-static tensors that feed into the subgraph for inference. + inputs:[int]; + + // Indices of the tensors that are outputs out of this subgraph. Note this is + // the list of output tensors that are considered the product of the + // subgraph's inference. + outputs:[int]; + + // All operators, in execution order. + operators:[Operator]; + + // Name of this subgraph (used for debugging). + name:string; +} + +// Table of raw data buffers (used for constant tensors). Referenced by tensors +// by index. The generous alignment accommodates mmap-friendly data structures. +table Buffer { + data:[ubyte] (force_align: 16); +} + +table Model { + // Version of the schema. + version:uint; + + // A list of all operator codes used in this model. This is + // kept in order because operators carry an index into this + // vector. + operator_codes:[OperatorCode]; + + // All the subgraphs of the model. The 0th is assumed to be the main + // model. + subgraphs:[SubGraph]; + + // A description of the model. + description:string; + + // Buffers of the model. + // Note the 0th entry of this array must be an empty buffer (sentinel). + // This is a convention so that tensors without a buffer can provide 0 as + // their buffer. + buffers:[Buffer]; + + // Metadata about the model. Indirects into the existings buffers list. + metadata_buffer:[int]; +} + +root_type Model; diff --git a/res/TensorFlowLiteSchema/1.15.2/schema.fbs b/res/TensorFlowLiteSchema/1.15.2/schema.fbs new file mode 100644 index 00000000000..d6338603576 --- /dev/null +++ b/res/TensorFlowLiteSchema/1.15.2/schema.fbs @@ -0,0 +1,922 @@ +// Copyright 2017 The TensorFlow Authors. 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. + +// Revision History +// Version 0: Initial version. +// Version 1: Add subgraphs to schema. +// Version 2: Rename operators to conform to NN API. +// Version 3: Move buffer data from Model.Subgraph.Tensors to Model.Buffers. + +namespace tflite; + +// This corresponds to the version. +file_identifier "TFL3"; +// File extension of any written files. +file_extension "tflite"; + +// IMPORTANT: All new members of tables, enums and unions must be added at the +// end to ensure backwards compatibility. + +// The type of data stored in a tensor. +enum TensorType : byte { + FLOAT32 = 0, + FLOAT16 = 1, + INT32 = 2, + UINT8 = 3, + INT64 = 4, + STRING = 5, + BOOL = 6, + INT16 = 7, + COMPLEX64 = 8, + INT8 = 9, +} + +// Custom quantization parameters for experimenting with new quantization +// techniques. +table CustomQuantization { + custom:[ubyte] (force_align: 16); +} + +// Represents a specific quantization technique's parameters. +union QuantizationDetails { + CustomQuantization, +} + +// Parameters for converting a quantized tensor back to float. +table QuantizationParameters { + // These four parameters are the asymmetric linear quantization parameters. + // Given a quantized value q, the corresponding float value f should be: + // f = scale * (q - zero_point) + // For other quantization types, the QuantizationDetails below is used. + min:[float]; // For importing back into tensorflow. + max:[float]; // For importing back into tensorflow. + scale:[float]; // For dequantizing the tensor's values. + zero_point:[long]; + + // If this is not none, the other quantization parameters (i.e. min, max, + // scale, zero_point fields above) are ignored and the value of the + // QuantizationDetails union should be used. + details:QuantizationDetails; + + // Specifies the dimension of the Tensor's shape that the scales and + // zero_points correspond to. For example, a tensor t, with dims=[4, 3, 2, 1] + // with quantization params: + // scale=[1.0, 2.0, 3.0], zero_point=[1, 2, 3], quantization_dimension=1 + // will be quantized across the second dimension of t. + // t[:, 0, :, :] will have scale[0]=1.0, zero_point[0]=1 + // t[:, 1, :, :] will have scale[1]=2.0, zero_point[0]=2 + // t[:, 2, :, :] will have scale[2]=3.0, zero_point[0]=3 + quantized_dimension:int; +} + +table Tensor { + // The tensor shape. The meaning of each entry is operator-specific but + // builtin ops use: [batch size, height, width, number of channels] (That's + // Tensorflow's NHWC). + shape:[int]; + type:TensorType; + // An index that refers to the buffers table at the root of the model. Or, + // if there is no data buffer associated (i.e. intermediate results), then + // this is 0 (which refers to an always existent empty buffer). + // + // The data_buffer itself is an opaque container, with the assumption that the + // target device is little-endian. In addition, all builtin operators assume + // the memory is ordered such that if `shape` is [4, 3, 2], then index + // [i, j, k] maps to data_buffer[i*3*2 + j*2 + k]. + buffer:uint; + name:string; // For debugging and importing back into tensorflow. + quantization:QuantizationParameters; // Optional. + + is_variable:bool = false; +} + +// A list of builtin operators. Builtin operators are slightly faster than custom +// ones, but not by much. Moreover, while custom operators accept an opaque +// object containing configuration parameters, builtins have a predetermined +// set of acceptable options. +enum BuiltinOperator : byte { + ADD = 0, + AVERAGE_POOL_2D = 1, + CONCATENATION = 2, + CONV_2D = 3, + DEPTHWISE_CONV_2D = 4, + DEPTH_TO_SPACE = 5, + DEQUANTIZE = 6, + EMBEDDING_LOOKUP = 7, + FLOOR = 8, + FULLY_CONNECTED = 9, + HASHTABLE_LOOKUP = 10, + L2_NORMALIZATION = 11, + L2_POOL_2D = 12, + LOCAL_RESPONSE_NORMALIZATION = 13, + LOGISTIC = 14, + LSH_PROJECTION = 15, + LSTM = 16, + MAX_POOL_2D = 17, + MUL = 18, + RELU = 19, + // NOTE(aselle): RELU_N1_TO_1 used to be called RELU1, but it was renamed + // since different model developers use RELU1 in different ways. Never + // create another op called RELU1. + RELU_N1_TO_1 = 20, + RELU6 = 21, + RESHAPE = 22, + RESIZE_BILINEAR = 23, + RNN = 24, + SOFTMAX = 25, + SPACE_TO_DEPTH = 26, + SVDF = 27, + TANH = 28, + // TODO(aselle): Consider rename to CONCATENATE_EMBEDDINGS + CONCAT_EMBEDDINGS = 29, + SKIP_GRAM = 30, + CALL = 31, + CUSTOM = 32, + EMBEDDING_LOOKUP_SPARSE = 33, + PAD = 34, + UNIDIRECTIONAL_SEQUENCE_RNN = 35, + GATHER = 36, + BATCH_TO_SPACE_ND = 37, + SPACE_TO_BATCH_ND = 38, + TRANSPOSE = 39, + MEAN = 40, + SUB = 41, + DIV = 42, + SQUEEZE = 43, + UNIDIRECTIONAL_SEQUENCE_LSTM = 44, + STRIDED_SLICE = 45, + BIDIRECTIONAL_SEQUENCE_RNN = 46, + EXP = 47, + TOPK_V2 = 48, + SPLIT = 49, + LOG_SOFTMAX = 50, + // DELEGATE is a special op type for the operations which are delegated to + // other backends. + // WARNING: Experimental interface, subject to change + DELEGATE = 51, + BIDIRECTIONAL_SEQUENCE_LSTM = 52, + CAST = 53, + PRELU = 54, + MAXIMUM = 55, + ARG_MAX = 56, + MINIMUM = 57, + LESS = 58, + NEG = 59, + PADV2 = 60, + GREATER = 61, + GREATER_EQUAL = 62, + LESS_EQUAL = 63, + SELECT = 64, + SLICE = 65, + SIN = 66, + TRANSPOSE_CONV = 67, + SPARSE_TO_DENSE = 68, + TILE = 69, + EXPAND_DIMS = 70, + EQUAL = 71, + NOT_EQUAL = 72, + LOG = 73, + SUM = 74, + SQRT = 75, + RSQRT = 76, + SHAPE = 77, + POW = 78, + ARG_MIN = 79, + FAKE_QUANT = 80, + REDUCE_PROD = 81, + REDUCE_MAX = 82, + PACK = 83, + LOGICAL_OR = 84, + ONE_HOT = 85, + LOGICAL_AND = 86, + LOGICAL_NOT = 87, + UNPACK = 88, + REDUCE_MIN = 89, + FLOOR_DIV = 90, + REDUCE_ANY = 91, + SQUARE = 92, + ZEROS_LIKE = 93, + FILL = 94, + FLOOR_MOD = 95, + RANGE = 96, + RESIZE_NEAREST_NEIGHBOR = 97, + LEAKY_RELU = 98, + SQUARED_DIFFERENCE = 99, + MIRROR_PAD = 100, + ABS = 101, + SPLIT_V = 102, + UNIQUE = 103, + CEIL = 104, + REVERSE_V2 = 105, + ADD_N = 106, + GATHER_ND = 107, + COS = 108, + WHERE = 109, + RANK = 110, + ELU = 111, + REVERSE_SEQUENCE = 112, + MATRIX_DIAG = 113, + QUANTIZE = 114, + MATRIX_SET_DIAG = 115, + ROUND = 116, + HARD_SWISH = 117, + IF = 118, + WHILE = 119, +} + +// Options for the builtin operators. +union BuiltinOptions { + Conv2DOptions, + DepthwiseConv2DOptions, + ConcatEmbeddingsOptions, + LSHProjectionOptions, + Pool2DOptions, + SVDFOptions, + RNNOptions, + FullyConnectedOptions, + SoftmaxOptions, + ConcatenationOptions, + AddOptions, + L2NormOptions, + LocalResponseNormalizationOptions, + LSTMOptions, + ResizeBilinearOptions, + CallOptions, + ReshapeOptions, + SkipGramOptions, + SpaceToDepthOptions, + EmbeddingLookupSparseOptions, + MulOptions, + PadOptions, + GatherOptions, + BatchToSpaceNDOptions, + SpaceToBatchNDOptions, + TransposeOptions, + ReducerOptions, + SubOptions, + DivOptions, + SqueezeOptions, + SequenceRNNOptions, + StridedSliceOptions, + ExpOptions, + TopKV2Options, + SplitOptions, + LogSoftmaxOptions, + CastOptions, + DequantizeOptions, + MaximumMinimumOptions, + ArgMaxOptions, + LessOptions, + NegOptions, + PadV2Options, + GreaterOptions, + GreaterEqualOptions, + LessEqualOptions, + SelectOptions, + SliceOptions, + TransposeConvOptions, + SparseToDenseOptions, + TileOptions, + ExpandDimsOptions, + EqualOptions, + NotEqualOptions, + ShapeOptions, + PowOptions, + ArgMinOptions, + FakeQuantOptions, + PackOptions, + LogicalOrOptions, + OneHotOptions, + LogicalAndOptions, + LogicalNotOptions, + UnpackOptions, + FloorDivOptions, + SquareOptions, + ZerosLikeOptions, + FillOptions, + BidirectionalSequenceLSTMOptions, + BidirectionalSequenceRNNOptions, + UnidirectionalSequenceLSTMOptions, + FloorModOptions, + RangeOptions, + ResizeNearestNeighborOptions, + LeakyReluOptions, + SquaredDifferenceOptions, + MirrorPadOptions, + AbsOptions, + SplitVOptions, + UniqueOptions, + ReverseV2Options, + AddNOptions, + GatherNdOptions, + CosOptions, + WhereOptions, + RankOptions, + ReverseSequenceOptions, + MatrixDiagOptions, + QuantizeOptions, + MatrixSetDiagOptions, + HardSwishOptions, + IfOptions, + WhileOptions, + DepthToSpaceOptions +} + +enum Padding : byte { SAME, VALID } + +enum ActivationFunctionType : byte { + NONE = 0, + RELU = 1, + RELU_N1_TO_1 = 2, + RELU6 = 3, + TANH = 4, + SIGN_BIT = 5, +} + +table Conv2DOptions { + padding:Padding; + stride_w:int; + stride_h:int; + fused_activation_function:ActivationFunctionType; + dilation_w_factor:int = 1; + dilation_h_factor:int = 1; +} + +table Pool2DOptions { + padding:Padding; + stride_w:int; + stride_h:int; + filter_width:int; + filter_height:int; + fused_activation_function:ActivationFunctionType; +} + +table DepthwiseConv2DOptions { + // Parameters for DepthwiseConv version 1 or above. + padding:Padding; + stride_w:int; + stride_h:int; + depth_multiplier:int; + fused_activation_function:ActivationFunctionType; + // Parameters for DepthwiseConv version 2 or above. + dilation_w_factor:int = 1; + dilation_h_factor:int = 1; +} + +table ConcatEmbeddingsOptions { + num_channels:int; + num_columns_per_channel:[int]; + embedding_dim_per_channel:[int]; // This could be inferred from parameters. +} + +enum LSHProjectionType: byte { + UNKNOWN = 0, + SPARSE = 1, + DENSE = 2, +} + +table LSHProjectionOptions { + type: LSHProjectionType; +} + +table SVDFOptions { + rank:int; + fused_activation_function:ActivationFunctionType; +} + +// An implementation of TensorFlow RNNCell. +table RNNOptions { + fused_activation_function:ActivationFunctionType; +} + +// An implementation of TensorFlow dynamic_rnn with RNNCell. +table SequenceRNNOptions { + time_major:bool; + fused_activation_function:ActivationFunctionType; +} + +// An implementation of TensorFlow bidrectional_dynamic_rnn with RNNCell. +table BidirectionalSequenceRNNOptions { + time_major:bool; + fused_activation_function:ActivationFunctionType; + merge_outputs: bool; +} + +enum FullyConnectedOptionsWeightsFormat: byte { + DEFAULT = 0, + SHUFFLED4x16INT8 = 1, +} + +// An implementation of TensorFlow fully_connected (a.k.a Dense) layer. +table FullyConnectedOptions { + // Parameters for FullyConnected version 1 or above. + fused_activation_function:ActivationFunctionType; + + // Parameters for FullyConnected version 2 or above. + weights_format:FullyConnectedOptionsWeightsFormat = DEFAULT; + + // Parameters for FullyConnected version 5 or above. + // If set to true, then the number of dimension is preserved. Furthermore, + // all but the last dimension of the input and output shapes will be equal. + keep_num_dims: bool; +} + +table SoftmaxOptions { + beta: float; +} + +// An implementation of TensorFlow concat. +table ConcatenationOptions { + axis:int; + fused_activation_function:ActivationFunctionType; +} + +table AddOptions { + fused_activation_function:ActivationFunctionType; +} + +table MulOptions { + fused_activation_function:ActivationFunctionType; +} + +table L2NormOptions { + fused_activation_function:ActivationFunctionType; +} + +table LocalResponseNormalizationOptions { + radius:int; + bias:float; + alpha:float; + beta:float; +} + +enum LSTMKernelType : byte { + // Full LSTM kernel which supports peephole and projection. + FULL = 0, + // Basic LSTM kernels. Equivalent to TensorFlow BasicLSTMCell. + BASIC = 1, +} + +// An implementation of TensorFlow LSTMCell and CoupledInputForgetGateLSTMCell +table LSTMOptions { + // Parameters for LSTM version 1 or above. + fused_activation_function:ActivationFunctionType; + cell_clip: float; // Optional, 0.0 means no clipping + proj_clip: float; // Optional, 0.0 means no clipping + + // Parameters for LSTM version 2 or above. + // Basic kernel is only supported in version 2 or above. + kernel_type: LSTMKernelType = FULL; +} + +// An implementation of TensorFlow dynamic_rnn with LSTMCell. +table UnidirectionalSequenceLSTMOptions { + fused_activation_function:ActivationFunctionType; + cell_clip: float; // Optional, 0.0 means no clipping + proj_clip: float; // Optional, 0.0 means no clipping + + // If true then first dimension is sequence, otherwise batch. + time_major:bool; +} + +table BidirectionalSequenceLSTMOptions { + // Parameters supported by version 1: + fused_activation_function:ActivationFunctionType; + cell_clip: float; // Optional, 0.0 means no clipping + proj_clip: float; // Optional, 0.0 means no clipping + + // If true, store the outputs of both directions into the first output. + merge_outputs: bool; + + // Parameters supported by version 2: + // If true then first dimension is sequence, otherwise batch. + // Version 1 implementations assumed time_major to be true, so this default + // value should never change. + time_major: bool = true; +} + +table ResizeBilinearOptions { + new_height: int (deprecated); + new_width: int (deprecated); + align_corners: bool; +} + +table ResizeNearestNeighborOptions { + align_corners: bool; +} + +// A call operation options +table CallOptions { + // The subgraph index that needs to be called. + subgraph:uint; +} + +table PadOptions { +} + +table PadV2Options { +} + +table ReshapeOptions { + new_shape:[int]; +} + +table SpaceToBatchNDOptions { +} + +table BatchToSpaceNDOptions { +} + +table SkipGramOptions { + ngram_size: int; + max_skip_size: int; + include_all_ngrams: bool; +} + +table SpaceToDepthOptions { + block_size: int; +} + +table DepthToSpaceOptions { + block_size: int; +} + +table SubOptions { + fused_activation_function:ActivationFunctionType; +} + +table DivOptions { + fused_activation_function:ActivationFunctionType; +} + +table TopKV2Options { +} + +enum CombinerType : byte { + SUM = 0, + MEAN = 1, + SQRTN = 2, +} + +table EmbeddingLookupSparseOptions { + combiner:CombinerType; +} + +table GatherOptions { + axis: int; +} + +table TransposeOptions { +} + +table ExpOptions { +} + +table CosOptions { +} + +table ReducerOptions { + keep_dims: bool; +} + +table SqueezeOptions { + squeeze_dims:[int]; +} + +table SplitOptions { + num_splits: int; +} + +table SplitVOptions { + num_splits: int; +} + +table StridedSliceOptions { + begin_mask: int; + end_mask: int; + ellipsis_mask: int; + new_axis_mask: int; + shrink_axis_mask: int; +} + +table LogSoftmaxOptions { +} + +table CastOptions { + in_data_type: TensorType; + out_data_type: TensorType; +} + +table DequantizeOptions { +} + +table MaximumMinimumOptions { +} + +table TileOptions { +} + +table ArgMaxOptions { + output_type : TensorType; +} + +table ArgMinOptions { + output_type : TensorType; +} + +table GreaterOptions { +} + +table GreaterEqualOptions { +} + +table LessOptions { +} + +table LessEqualOptions { +} + +table NegOptions { +} + +table SelectOptions { +} + +table SliceOptions { +} + +table TransposeConvOptions { + padding:Padding; + stride_w:int; + stride_h:int; +} + +table ExpandDimsOptions { +} + +table SparseToDenseOptions { + validate_indices:bool; +} + +table EqualOptions { +} + +table NotEqualOptions { +} + +table ShapeOptions { + // Optional output type of the operation (int32 or int64). Defaults to int32. + out_type : TensorType; +} + +table RankOptions { +} + +table PowOptions { +} + +table FakeQuantOptions { + // Parameters supported by version 1: + min:float; + max:float; + num_bits:int; + + // Parameters supported by version 2: + narrow_range:bool; +} + +table PackOptions { + values_count:int; + axis:int; +} + +table LogicalOrOptions { +} + +table OneHotOptions { + axis:int; +} + +table AbsOptions { +} + + +table HardSwishOptions { +} + +table LogicalAndOptions { +} + +table LogicalNotOptions { +} + +table UnpackOptions { + num:int; + axis:int; +} + +table FloorDivOptions { +} + +table SquareOptions { +} + +table ZerosLikeOptions { +} + +table FillOptions { +} + +table FloorModOptions { +} + +table RangeOptions { +} + +table LeakyReluOptions { + alpha:float; +} + +table SquaredDifferenceOptions { +} + +enum MirrorPadMode : byte { + // Doesn't include borders. + REFLECT = 0, + // Includes borders. + SYMMETRIC = 1, +} + +table MirrorPadOptions { + mode:MirrorPadMode; +} + +table UniqueOptions { + idx_out_type:TensorType = INT32; +} + +table ReverseV2Options { +} + +table AddNOptions { +} + +table GatherNdOptions { +} + +table WhereOptions { +} + +table ReverseSequenceOptions { + seq_dim:int; + batch_dim:int = 0; +} + +table MatrixDiagOptions { +} + +table QuantizeOptions { +} + +table MatrixSetDiagOptions { +} + +table IfOptions { + then_subgraph_index:int; + else_subgraph_index:int; +} + +table WhileOptions { + cond_subgraph_index:int; + body_subgraph_index:int; +} + +// An OperatorCode can be an enum value (BuiltinOperator) if the operator is a +// builtin, or a string if the operator is custom. +table OperatorCode { + builtin_code:BuiltinOperator; + custom_code:string; + + // The version of the operator. The version need to be bumped whenever new + // parameters are introduced into an op. + version:int = 1; +} + +enum CustomOptionsFormat : byte { + FLEXBUFFERS = 0, +} + +// An operator takes tensors as inputs and outputs. The type of operation being +// performed is determined by an index into the list of valid OperatorCodes, +// while the specifics of each operations is configured using builtin_options +// or custom_options. +table Operator { + // Index into the operator_codes array. Using an integer here avoids + // complicate map lookups. + opcode_index:uint; + + // Optional input and output tensors are indicated by -1. + inputs:[int]; + outputs:[int]; + + builtin_options:BuiltinOptions; + custom_options:[ubyte]; + custom_options_format:CustomOptionsFormat; + + // A list of booleans indicating the input tensors which are being mutated by + // this operator.(e.g. used by RNN and LSTM). + // For example, if the "inputs" array refers to 5 tensors and the second and + // fifth are mutable variables, then this list will contain + // [false, true, false, false, true]. + // + // If the list is empty, no variable is mutated in this operator. + // The list either has the same length as `inputs`, or is empty. + mutating_variable_inputs:[bool]; + + // A list of indices to the subgraph's "tensors" that are internal to an Op. + // Internal tensors are those that do not flow in or out of the operation, + // but instead are part of internal computation. As such, the operation's + // implementation may manage its memory more efficiently. They are needed + // however (i.e. not just an implementation detail) since they are part of the + // computation, which may require relevant metadata such as quantization + // parameters. + intermediates:[int]; +} + +// The root type, defining a subgraph, which typically represents an entire +// model. +table SubGraph { + // A list of all tensors used in this subgraph. + tensors:[Tensor]; + + // Indices of the tensors that are inputs into this subgraph. Note this is + // the list of non-static tensors that feed into the subgraph for inference. + inputs:[int]; + + // Indices of the tensors that are outputs out of this subgraph. Note this is + // the list of output tensors that are considered the product of the + // subgraph's inference. + outputs:[int]; + + // All operators, in execution order. + operators:[Operator]; + + // Name of this subgraph (used for debugging). + name:string; +} + +// Table of raw data buffers (used for constant tensors). Referenced by tensors +// by index. The generous alignment accommodates mmap-friendly data structures. +table Buffer { + data:[ubyte] (force_align: 16); +} + +table Metadata { + // A human readable string to uniquely identify a Metadata. + name:string; + // An index to the buffers table. + buffer:uint; +} + +table Model { + // Version of the schema. + version:uint; + + // A list of all operator codes used in this model. This is + // kept in order because operators carry an index into this + // vector. + operator_codes:[OperatorCode]; + + // All the subgraphs of the model. The 0th is assumed to be the main + // model. + subgraphs:[SubGraph]; + + // A description of the model. + description:string; + + // Buffers of the model. + // Note the 0th entry of this array must be an empty buffer (sentinel). + // This is a convention so that tensors without a buffer can provide 0 as + // their buffer. + buffers:[Buffer]; + + // Metadata about the model. Indirects into the existings buffers list. + // Deprecated, prefer to use metadata field. + metadata_buffer:[int]; + + // Metadata about the model. + metadata:[Metadata]; +} + +root_type Model; diff --git a/res/TensorFlowLiteSchema/2.1.0/schema.fbs b/res/TensorFlowLiteSchema/2.1.0/schema.fbs new file mode 100644 index 00000000000..f1fbfc655d6 --- /dev/null +++ b/res/TensorFlowLiteSchema/2.1.0/schema.fbs @@ -0,0 +1,940 @@ +// Copyright 2017 The TensorFlow Authors. 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. + +// Revision History +// Version 0: Initial version. +// Version 1: Add subgraphs to schema. +// Version 2: Rename operators to conform to NN API. +// Version 3: Move buffer data from Model.Subgraph.Tensors to Model.Buffers. + +namespace tflite; + +// This corresponds to the version. +file_identifier "TFL3"; +// File extension of any written files. +file_extension "tflite"; + +// IMPORTANT: All new members of tables, enums and unions must be added at the +// end to ensure backwards compatibility. + +// The type of data stored in a tensor. +enum TensorType : byte { + FLOAT32 = 0, + FLOAT16 = 1, + INT32 = 2, + UINT8 = 3, + INT64 = 4, + STRING = 5, + BOOL = 6, + INT16 = 7, + COMPLEX64 = 8, + INT8 = 9, +} + +// Custom quantization parameters for experimenting with new quantization +// techniques. +table CustomQuantization { + custom:[ubyte] (force_align: 16); +} + +// Represents a specific quantization technique's parameters. +union QuantizationDetails { + CustomQuantization, +} + +// Parameters for converting a quantized tensor back to float. +table QuantizationParameters { + // These four parameters are the asymmetric linear quantization parameters. + // Given a quantized value q, the corresponding float value f should be: + // f = scale * (q - zero_point) + // For other quantization types, the QuantizationDetails below is used. + min:[float]; // For importing back into tensorflow. + max:[float]; // For importing back into tensorflow. + scale:[float]; // For dequantizing the tensor's values. + zero_point:[long]; + + // If this is not none, the other quantization parameters (i.e. min, max, + // scale, zero_point fields above) are ignored and the value of the + // QuantizationDetails union should be used. + details:QuantizationDetails; + + // Specifies the dimension of the Tensor's shape that the scales and + // zero_points correspond to. For example, a tensor t, with dims=[4, 3, 2, 1] + // with quantization params: + // scale=[1.0, 2.0, 3.0], zero_point=[1, 2, 3], quantization_dimension=1 + // will be quantized across the second dimension of t. + // t[:, 0, :, :] will have scale[0]=1.0, zero_point[0]=1 + // t[:, 1, :, :] will have scale[1]=2.0, zero_point[0]=2 + // t[:, 2, :, :] will have scale[2]=3.0, zero_point[0]=3 + quantized_dimension:int; +} + +table Tensor { + // The tensor shape. The meaning of each entry is operator-specific but + // builtin ops use: [batch size, height, width, number of channels] (That's + // Tensorflow's NHWC). + shape:[int]; + type:TensorType; + // An index that refers to the buffers table at the root of the model. Or, + // if there is no data buffer associated (i.e. intermediate results), then + // this is 0 (which refers to an always existent empty buffer). + // + // The data_buffer itself is an opaque container, with the assumption that the + // target device is little-endian. In addition, all builtin operators assume + // the memory is ordered such that if `shape` is [4, 3, 2], then index + // [i, j, k] maps to data_buffer[i*3*2 + j*2 + k]. + buffer:uint; + name:string; // For debugging and importing back into tensorflow. + quantization:QuantizationParameters; // Optional. + + is_variable:bool = false; +} + +// A list of builtin operators. Builtin operators are slightly faster than custom +// ones, but not by much. Moreover, while custom operators accept an opaque +// object containing configuration parameters, builtins have a predetermined +// set of acceptable options. +enum BuiltinOperator : byte { + ADD = 0, + AVERAGE_POOL_2D = 1, + CONCATENATION = 2, + CONV_2D = 3, + DEPTHWISE_CONV_2D = 4, + DEPTH_TO_SPACE = 5, + DEQUANTIZE = 6, + EMBEDDING_LOOKUP = 7, + FLOOR = 8, + FULLY_CONNECTED = 9, + HASHTABLE_LOOKUP = 10, + L2_NORMALIZATION = 11, + L2_POOL_2D = 12, + LOCAL_RESPONSE_NORMALIZATION = 13, + LOGISTIC = 14, + LSH_PROJECTION = 15, + LSTM = 16, + MAX_POOL_2D = 17, + MUL = 18, + RELU = 19, + // NOTE(aselle): RELU_N1_TO_1 used to be called RELU1, but it was renamed + // since different model developers use RELU1 in different ways. Never + // create another op called RELU1. + RELU_N1_TO_1 = 20, + RELU6 = 21, + RESHAPE = 22, + RESIZE_BILINEAR = 23, + RNN = 24, + SOFTMAX = 25, + SPACE_TO_DEPTH = 26, + SVDF = 27, + TANH = 28, + // TODO(aselle): Consider rename to CONCATENATE_EMBEDDINGS + CONCAT_EMBEDDINGS = 29, + SKIP_GRAM = 30, + CALL = 31, + CUSTOM = 32, + EMBEDDING_LOOKUP_SPARSE = 33, + PAD = 34, + UNIDIRECTIONAL_SEQUENCE_RNN = 35, + GATHER = 36, + BATCH_TO_SPACE_ND = 37, + SPACE_TO_BATCH_ND = 38, + TRANSPOSE = 39, + MEAN = 40, + SUB = 41, + DIV = 42, + SQUEEZE = 43, + UNIDIRECTIONAL_SEQUENCE_LSTM = 44, + STRIDED_SLICE = 45, + BIDIRECTIONAL_SEQUENCE_RNN = 46, + EXP = 47, + TOPK_V2 = 48, + SPLIT = 49, + LOG_SOFTMAX = 50, + // DELEGATE is a special op type for the operations which are delegated to + // other backends. + // WARNING: Experimental interface, subject to change + DELEGATE = 51, + BIDIRECTIONAL_SEQUENCE_LSTM = 52, + CAST = 53, + PRELU = 54, + MAXIMUM = 55, + ARG_MAX = 56, + MINIMUM = 57, + LESS = 58, + NEG = 59, + PADV2 = 60, + GREATER = 61, + GREATER_EQUAL = 62, + LESS_EQUAL = 63, + SELECT = 64, + SLICE = 65, + SIN = 66, + TRANSPOSE_CONV = 67, + SPARSE_TO_DENSE = 68, + TILE = 69, + EXPAND_DIMS = 70, + EQUAL = 71, + NOT_EQUAL = 72, + LOG = 73, + SUM = 74, + SQRT = 75, + RSQRT = 76, + SHAPE = 77, + POW = 78, + ARG_MIN = 79, + FAKE_QUANT = 80, + REDUCE_PROD = 81, + REDUCE_MAX = 82, + PACK = 83, + LOGICAL_OR = 84, + ONE_HOT = 85, + LOGICAL_AND = 86, + LOGICAL_NOT = 87, + UNPACK = 88, + REDUCE_MIN = 89, + FLOOR_DIV = 90, + REDUCE_ANY = 91, + SQUARE = 92, + ZEROS_LIKE = 93, + FILL = 94, + FLOOR_MOD = 95, + RANGE = 96, + RESIZE_NEAREST_NEIGHBOR = 97, + LEAKY_RELU = 98, + SQUARED_DIFFERENCE = 99, + MIRROR_PAD = 100, + ABS = 101, + SPLIT_V = 102, + UNIQUE = 103, + CEIL = 104, + REVERSE_V2 = 105, + ADD_N = 106, + GATHER_ND = 107, + COS = 108, + WHERE = 109, + RANK = 110, + ELU = 111, + REVERSE_SEQUENCE = 112, + MATRIX_DIAG = 113, + QUANTIZE = 114, + MATRIX_SET_DIAG = 115, + ROUND = 116, + HARD_SWISH = 117, + IF = 118, + WHILE = 119, + NON_MAX_SUPPRESSION_V4 = 120, + NON_MAX_SUPPRESSION_V5 = 121, + SCATTER_ND = 122 +} + +// Options for the builtin operators. +union BuiltinOptions { + Conv2DOptions, + DepthwiseConv2DOptions, + ConcatEmbeddingsOptions, + LSHProjectionOptions, + Pool2DOptions, + SVDFOptions, + RNNOptions, + FullyConnectedOptions, + SoftmaxOptions, + ConcatenationOptions, + AddOptions, + L2NormOptions, + LocalResponseNormalizationOptions, + LSTMOptions, + ResizeBilinearOptions, + CallOptions, + ReshapeOptions, + SkipGramOptions, + SpaceToDepthOptions, + EmbeddingLookupSparseOptions, + MulOptions, + PadOptions, + GatherOptions, + BatchToSpaceNDOptions, + SpaceToBatchNDOptions, + TransposeOptions, + ReducerOptions, + SubOptions, + DivOptions, + SqueezeOptions, + SequenceRNNOptions, + StridedSliceOptions, + ExpOptions, + TopKV2Options, + SplitOptions, + LogSoftmaxOptions, + CastOptions, + DequantizeOptions, + MaximumMinimumOptions, + ArgMaxOptions, + LessOptions, + NegOptions, + PadV2Options, + GreaterOptions, + GreaterEqualOptions, + LessEqualOptions, + SelectOptions, + SliceOptions, + TransposeConvOptions, + SparseToDenseOptions, + TileOptions, + ExpandDimsOptions, + EqualOptions, + NotEqualOptions, + ShapeOptions, + PowOptions, + ArgMinOptions, + FakeQuantOptions, + PackOptions, + LogicalOrOptions, + OneHotOptions, + LogicalAndOptions, + LogicalNotOptions, + UnpackOptions, + FloorDivOptions, + SquareOptions, + ZerosLikeOptions, + FillOptions, + BidirectionalSequenceLSTMOptions, + BidirectionalSequenceRNNOptions, + UnidirectionalSequenceLSTMOptions, + FloorModOptions, + RangeOptions, + ResizeNearestNeighborOptions, + LeakyReluOptions, + SquaredDifferenceOptions, + MirrorPadOptions, + AbsOptions, + SplitVOptions, + UniqueOptions, + ReverseV2Options, + AddNOptions, + GatherNdOptions, + CosOptions, + WhereOptions, + RankOptions, + ReverseSequenceOptions, + MatrixDiagOptions, + QuantizeOptions, + MatrixSetDiagOptions, + HardSwishOptions, + IfOptions, + WhileOptions, + DepthToSpaceOptions, + NonMaxSuppressionV4Options, + NonMaxSuppressionV5Options, + ScatterNdOptions +} + +enum Padding : byte { SAME, VALID } + +enum ActivationFunctionType : byte { + NONE = 0, + RELU = 1, + RELU_N1_TO_1 = 2, + RELU6 = 3, + TANH = 4, + SIGN_BIT = 5, +} + +table Conv2DOptions { + padding:Padding; + stride_w:int; + stride_h:int; + fused_activation_function:ActivationFunctionType; + dilation_w_factor:int = 1; + dilation_h_factor:int = 1; +} + +table Pool2DOptions { + padding:Padding; + stride_w:int; + stride_h:int; + filter_width:int; + filter_height:int; + fused_activation_function:ActivationFunctionType; +} + +table DepthwiseConv2DOptions { + // Parameters for DepthwiseConv version 1 or above. + padding:Padding; + stride_w:int; + stride_h:int; + // `depth_multiplier` is redundant. It's used by CPU kernels in + // TensorFlow 2.0 or below, but ignored in versions above. + // See comments in lite/c/builtin_op_data.h for more details. + depth_multiplier:int; + fused_activation_function:ActivationFunctionType; + // Parameters for DepthwiseConv version 2 or above. + dilation_w_factor:int = 1; + dilation_h_factor:int = 1; +} + +table ConcatEmbeddingsOptions { + num_channels:int; + num_columns_per_channel:[int]; + embedding_dim_per_channel:[int]; // This could be inferred from parameters. +} + +enum LSHProjectionType: byte { + UNKNOWN = 0, + SPARSE = 1, + DENSE = 2, +} + +table LSHProjectionOptions { + type: LSHProjectionType; +} + +table SVDFOptions { + rank:int; + fused_activation_function:ActivationFunctionType; +} + +// An implementation of TensorFlow RNNCell. +table RNNOptions { + fused_activation_function:ActivationFunctionType; +} + +// An implementation of TensorFlow dynamic_rnn with RNNCell. +table SequenceRNNOptions { + time_major:bool; + fused_activation_function:ActivationFunctionType; +} + +// An implementation of TensorFlow bidrectional_dynamic_rnn with RNNCell. +table BidirectionalSequenceRNNOptions { + time_major:bool; + fused_activation_function:ActivationFunctionType; + merge_outputs: bool; +} + +enum FullyConnectedOptionsWeightsFormat: byte { + DEFAULT = 0, + SHUFFLED4x16INT8 = 1, +} + +// An implementation of TensorFlow fully_connected (a.k.a Dense) layer. +table FullyConnectedOptions { + // Parameters for FullyConnected version 1 or above. + fused_activation_function:ActivationFunctionType; + + // Parameters for FullyConnected version 2 or above. + weights_format:FullyConnectedOptionsWeightsFormat = DEFAULT; + + // Parameters for FullyConnected version 5 or above. + // If set to true, then the number of dimension is preserved. Furthermore, + // all but the last dimension of the input and output shapes will be equal. + keep_num_dims: bool; +} + +table SoftmaxOptions { + beta: float; +} + +// An implementation of TensorFlow concat. +table ConcatenationOptions { + axis:int; + fused_activation_function:ActivationFunctionType; +} + +table AddOptions { + fused_activation_function:ActivationFunctionType; +} + +table MulOptions { + fused_activation_function:ActivationFunctionType; +} + +table L2NormOptions { + fused_activation_function:ActivationFunctionType; +} + +table LocalResponseNormalizationOptions { + radius:int; + bias:float; + alpha:float; + beta:float; +} + +enum LSTMKernelType : byte { + // Full LSTM kernel which supports peephole and projection. + FULL = 0, + // Basic LSTM kernels. Equivalent to TensorFlow BasicLSTMCell. + BASIC = 1, +} + +// An implementation of TensorFlow LSTMCell and CoupledInputForgetGateLSTMCell +table LSTMOptions { + // Parameters for LSTM version 1 or above. + fused_activation_function:ActivationFunctionType; + cell_clip: float; // Optional, 0.0 means no clipping + proj_clip: float; // Optional, 0.0 means no clipping + + // Parameters for LSTM version 2 or above. + // Basic kernel is only supported in version 2 or above. + kernel_type: LSTMKernelType = FULL; +} + +// An implementation of TensorFlow dynamic_rnn with LSTMCell. +table UnidirectionalSequenceLSTMOptions { + fused_activation_function:ActivationFunctionType; + cell_clip: float; // Optional, 0.0 means no clipping + proj_clip: float; // Optional, 0.0 means no clipping + + // If true then first dimension is sequence, otherwise batch. + time_major:bool; +} + +table BidirectionalSequenceLSTMOptions { + // Parameters supported by version 1: + fused_activation_function:ActivationFunctionType; + cell_clip: float; // Optional, 0.0 means no clipping + proj_clip: float; // Optional, 0.0 means no clipping + + // If true, store the outputs of both directions into the first output. + merge_outputs: bool; + + // Parameters supported by version 2: + // If true then first dimension is sequence, otherwise batch. + // Version 1 implementations assumed time_major to be true, so this default + // value should never change. + time_major: bool = true; +} + +table ResizeBilinearOptions { + new_height: int (deprecated); + new_width: int (deprecated); + align_corners: bool; +} + +table ResizeNearestNeighborOptions { + align_corners: bool; +} + +// A call operation options +table CallOptions { + // The subgraph index that needs to be called. + subgraph:uint; +} + +table PadOptions { +} + +table PadV2Options { +} + +table ReshapeOptions { + new_shape:[int]; +} + +table SpaceToBatchNDOptions { +} + +table BatchToSpaceNDOptions { +} + +table SkipGramOptions { + ngram_size: int; + max_skip_size: int; + include_all_ngrams: bool; +} + +table SpaceToDepthOptions { + block_size: int; +} + +table DepthToSpaceOptions { + block_size: int; +} + +table SubOptions { + fused_activation_function:ActivationFunctionType; +} + +table DivOptions { + fused_activation_function:ActivationFunctionType; +} + +table TopKV2Options { +} + +enum CombinerType : byte { + SUM = 0, + MEAN = 1, + SQRTN = 2, +} + +table EmbeddingLookupSparseOptions { + combiner:CombinerType; +} + +table GatherOptions { + axis: int; +} + +table TransposeOptions { +} + +table ExpOptions { +} + +table CosOptions { +} + +table ReducerOptions { + keep_dims: bool; +} + +table SqueezeOptions { + squeeze_dims:[int]; +} + +table SplitOptions { + num_splits: int; +} + +table SplitVOptions { + num_splits: int; +} + +table StridedSliceOptions { + begin_mask: int; + end_mask: int; + ellipsis_mask: int; + new_axis_mask: int; + shrink_axis_mask: int; +} + +table LogSoftmaxOptions { +} + +table CastOptions { + in_data_type: TensorType; + out_data_type: TensorType; +} + +table DequantizeOptions { +} + +table MaximumMinimumOptions { +} + +table TileOptions { +} + +table ArgMaxOptions { + output_type : TensorType; +} + +table ArgMinOptions { + output_type : TensorType; +} + +table GreaterOptions { +} + +table GreaterEqualOptions { +} + +table LessOptions { +} + +table LessEqualOptions { +} + +table NegOptions { +} + +table SelectOptions { +} + +table SliceOptions { +} + +table TransposeConvOptions { + padding:Padding; + stride_w:int; + stride_h:int; +} + +table ExpandDimsOptions { +} + +table SparseToDenseOptions { + validate_indices:bool; +} + +table EqualOptions { +} + +table NotEqualOptions { +} + +table ShapeOptions { + // Optional output type of the operation (int32 or int64). Defaults to int32. + out_type : TensorType; +} + +table RankOptions { +} + +table PowOptions { +} + +table FakeQuantOptions { + // Parameters supported by version 1: + min:float; + max:float; + num_bits:int; + + // Parameters supported by version 2: + narrow_range:bool; +} + +table PackOptions { + values_count:int; + axis:int; +} + +table LogicalOrOptions { +} + +table OneHotOptions { + axis:int; +} + +table AbsOptions { +} + + +table HardSwishOptions { +} + +table LogicalAndOptions { +} + +table LogicalNotOptions { +} + +table UnpackOptions { + num:int; + axis:int; +} + +table FloorDivOptions { +} + +table SquareOptions { +} + +table ZerosLikeOptions { +} + +table FillOptions { +} + +table FloorModOptions { +} + +table RangeOptions { +} + +table LeakyReluOptions { + alpha:float; +} + +table SquaredDifferenceOptions { +} + +enum MirrorPadMode : byte { + // Doesn't include borders. + REFLECT = 0, + // Includes borders. + SYMMETRIC = 1, +} + +table MirrorPadOptions { + mode:MirrorPadMode; +} + +table UniqueOptions { + idx_out_type:TensorType = INT32; +} + +table ReverseV2Options { +} + +table AddNOptions { +} + +table GatherNdOptions { +} + +table WhereOptions { +} + +table ReverseSequenceOptions { + seq_dim:int; + batch_dim:int = 0; +} + +table MatrixDiagOptions { +} + +table QuantizeOptions { +} + +table MatrixSetDiagOptions { +} + +table IfOptions { + then_subgraph_index:int; + else_subgraph_index:int; +} + +table WhileOptions { + cond_subgraph_index:int; + body_subgraph_index:int; +} + +table NonMaxSuppressionV4Options { +} + +table NonMaxSuppressionV5Options { +} + +table ScatterNdOptions { +} + +// An OperatorCode can be an enum value (BuiltinOperator) if the operator is a +// builtin, or a string if the operator is custom. +table OperatorCode { + builtin_code:BuiltinOperator; + custom_code:string; + + // The version of the operator. The version need to be bumped whenever new + // parameters are introduced into an op. + version:int = 1; +} + +enum CustomOptionsFormat : byte { + FLEXBUFFERS = 0, +} + +// An operator takes tensors as inputs and outputs. The type of operation being +// performed is determined by an index into the list of valid OperatorCodes, +// while the specifics of each operations is configured using builtin_options +// or custom_options. +table Operator { + // Index into the operator_codes array. Using an integer here avoids + // complicate map lookups. + opcode_index:uint; + + // Optional input and output tensors are indicated by -1. + inputs:[int]; + outputs:[int]; + + builtin_options:BuiltinOptions; + custom_options:[ubyte]; + custom_options_format:CustomOptionsFormat; + + // A list of booleans indicating the input tensors which are being mutated by + // this operator.(e.g. used by RNN and LSTM). + // For example, if the "inputs" array refers to 5 tensors and the second and + // fifth are mutable variables, then this list will contain + // [false, true, false, false, true]. + // + // If the list is empty, no variable is mutated in this operator. + // The list either has the same length as `inputs`, or is empty. + mutating_variable_inputs:[bool]; + + // A list of indices to the subgraph's "tensors" that are internal to an Op. + // Internal tensors are those that do not flow in or out of the operation, + // but instead are part of internal computation. As such, the operation's + // implementation may manage its memory more efficiently. They are needed + // however (i.e. not just an implementation detail) since they are part of the + // computation, which may require relevant metadata such as quantization + // parameters. + intermediates:[int]; +} + +// The root type, defining a subgraph, which typically represents an entire +// model. +table SubGraph { + // A list of all tensors used in this subgraph. + tensors:[Tensor]; + + // Indices of the tensors that are inputs into this subgraph. Note this is + // the list of non-static tensors that feed into the subgraph for inference. + inputs:[int]; + + // Indices of the tensors that are outputs out of this subgraph. Note this is + // the list of output tensors that are considered the product of the + // subgraph's inference. + outputs:[int]; + + // All operators, in execution order. + operators:[Operator]; + + // Name of this subgraph (used for debugging). + name:string; +} + +// Table of raw data buffers (used for constant tensors). Referenced by tensors +// by index. The generous alignment accommodates mmap-friendly data structures. +table Buffer { + data:[ubyte] (force_align: 16); +} + +table Metadata { + // A human readable string to uniquely identify a Metadata. + name:string; + // An index to the buffers table. + buffer:uint; +} + +table Model { + // Version of the schema. + version:uint; + + // A list of all operator codes used in this model. This is + // kept in order because operators carry an index into this + // vector. + operator_codes:[OperatorCode]; + + // All the subgraphs of the model. The 0th is assumed to be the main + // model. + subgraphs:[SubGraph]; + + // A description of the model. + description:string; + + // Buffers of the model. + // Note the 0th entry of this array must be an empty buffer (sentinel). + // This is a convention so that tensors without a buffer can provide 0 as + // their buffer. + buffers:[Buffer]; + + // Metadata about the model. Indirects into the existings buffers list. + // Deprecated, prefer to use metadata field. + metadata_buffer:[int]; + + // Metadata about the model. + metadata:[Metadata]; +} + +root_type Model; diff --git a/res/TensorFlowLiteSchema/README.md b/res/TensorFlowLiteSchema/README.md new file mode 100644 index 00000000000..b99cfe4a6d1 --- /dev/null +++ b/res/TensorFlowLiteSchema/README.md @@ -0,0 +1,7 @@ +# TensorFlow Lite Schema + +A collection of T/F Lite schema files (for each version) + +## How to add a new schema? + +Update [SCHEMA.lst](SCHEMA.lst) and run "download.sh". diff --git a/res/TensorFlowLiteSchema/SCHEMA.lst b/res/TensorFlowLiteSchema/SCHEMA.lst new file mode 100644 index 00000000000..f264b0c9f46 --- /dev/null +++ b/res/TensorFlowLiteSchema/SCHEMA.lst @@ -0,0 +1,5 @@ +VERSION,URL +1.13.1,https://raw.githubusercontent.com/tensorflow/tensorflow/v1.13.1/tensorflow/lite/schema/schema.fbs +1.14.0,https://raw.githubusercontent.com/tensorflow/tensorflow/v1.14.0/tensorflow/lite/schema/schema.fbs +1.15.2,https://raw.githubusercontent.com/tensorflow/tensorflow/v1.15.2/tensorflow/lite/schema/schema.fbs +2.1.0,https://raw.githubusercontent.com/tensorflow/tensorflow/v2.1.0/tensorflow/lite/schema/schema.fbs diff --git a/res/TensorFlowLiteSchema/download.sh b/res/TensorFlowLiteSchema/download.sh new file mode 100755 index 00000000000..9a946c3d915 --- /dev/null +++ b/res/TensorFlowLiteSchema/download.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +while IFS=',' read -r VERSION URL +do + echo "Download ${VERSION} from '${URL}'" + mkdir -p "${VERSION}" + wget -nv -O "${VERSION}/schema.fbs" "${URL}" + echo "Download ${VERSION} from '${URL}' - Done" +done < <(cat SCHEMA.lst | tail -n +2) diff --git a/res/TensorFlowPythonExamples/examples/abs/__init__.py b/res/TensorFlowPythonExamples/examples/abs/__init__.py new file mode 100755 index 00000000000..fd55155950d --- /dev/null +++ b/res/TensorFlowPythonExamples/examples/abs/__init__.py @@ -0,0 +1,4 @@ +import tensorflow as tf + +in_ = tf.compat.v1.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") +abs_ = tf.compat.v1.abs(in_) diff --git a/res/TensorFlowPythonExamples/examples/add/__init__.py b/res/TensorFlowPythonExamples/examples/add/__init__.py old mode 100644 new mode 100755 index 9a08cc2e146..7e283f35ff8 --- a/res/TensorFlowPythonExamples/examples/add/__init__.py +++ b/res/TensorFlowPythonExamples/examples/add/__init__.py @@ -1,5 +1,5 @@ import tensorflow as tf -lhs_ = tf.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") -rhs_ = tf.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") -op_ = tf.add(lhs_, rhs_) +lhs_ = tf.compat.v1.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") +rhs_ = tf.compat.v1.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") +op_ = tf.compat.v1.add(lhs_, rhs_) diff --git a/res/TensorFlowPythonExamples/examples/argmax/__init__.py b/res/TensorFlowPythonExamples/examples/argmax/__init__.py old mode 100644 new mode 100755 index 13e0cf7c75a..059df97f903 --- a/res/TensorFlowPythonExamples/examples/argmax/__init__.py +++ b/res/TensorFlowPythonExamples/examples/argmax/__init__.py @@ -1,4 +1,4 @@ import tensorflow as tf -in_ = tf.placeholder(dtype=tf.float32, shape=(1, 1), name="Hole") -op_ = tf.math.argmax(in_) +in_ = tf.compat.v1.placeholder(dtype=tf.float32, shape=(1, 1), name="Hole") +op_ = tf.compat.v1.math.argmax(in_) diff --git a/res/TensorFlowPythonExamples/examples/cos/__init__.py b/res/TensorFlowPythonExamples/examples/cos/__init__.py new file mode 100755 index 00000000000..cfce5d8306b --- /dev/null +++ b/res/TensorFlowPythonExamples/examples/cos/__init__.py @@ -0,0 +1,4 @@ +import tensorflow as tf + +in_ = tf.compat.v1.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") +op_ = tf.compat.v1.cos(in_) diff --git a/res/TensorFlowPythonExamples/examples/div/__init__.py b/res/TensorFlowPythonExamples/examples/div/__init__.py old mode 100644 new mode 100755 index 6956f45519b..2887771ff5c --- a/res/TensorFlowPythonExamples/examples/div/__init__.py +++ b/res/TensorFlowPythonExamples/examples/div/__init__.py @@ -1,5 +1,5 @@ import tensorflow as tf -lhs_ = tf.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") -rhs_ = tf.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") -op_ = tf.div(lhs_, rhs_) +lhs_ = tf.compat.v1.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") +rhs_ = tf.compat.v1.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") +op_ = tf.compat.v1.div(lhs_, rhs_) diff --git a/res/TensorFlowPythonExamples/examples/elu/__init__.py b/res/TensorFlowPythonExamples/examples/elu/__init__.py old mode 100644 new mode 100755 index 5c394097c40..b41f65111da --- a/res/TensorFlowPythonExamples/examples/elu/__init__.py +++ b/res/TensorFlowPythonExamples/examples/elu/__init__.py @@ -1,4 +1,4 @@ import tensorflow as tf -in_ = tf.placeholder(dtype=tf.float32, shape=(1, 1), name="Hole") -elu_ = tf.nn.elu(in_) +in_ = tf.compat.v1.placeholder(dtype=tf.float32, shape=(1, 1), name="Hole") +elu_ = tf.compat.v1.nn.elu(in_) diff --git a/res/TensorFlowPythonExamples/examples/floor/__init__.py b/res/TensorFlowPythonExamples/examples/floor/__init__.py old mode 100644 new mode 100755 index 6358c6d4061..3b3f5bfc3f5 --- a/res/TensorFlowPythonExamples/examples/floor/__init__.py +++ b/res/TensorFlowPythonExamples/examples/floor/__init__.py @@ -1,4 +1,4 @@ import tensorflow as tf -in_ = tf.placeholder(dtype=tf.float32, shape=(1, 1), name="Hole") -op_ = tf.floor(in_) +in_ = tf.compat.v1.placeholder(dtype=tf.float32, shape=(1, 1), name="Hole") +op_ = tf.compat.v1.floor(in_) diff --git a/res/TensorFlowPythonExamples/examples/floordiv/__init__.py b/res/TensorFlowPythonExamples/examples/floordiv/__init__.py old mode 100644 new mode 100755 index b1a1dedafae..34f413f2bdf --- a/res/TensorFlowPythonExamples/examples/floordiv/__init__.py +++ b/res/TensorFlowPythonExamples/examples/floordiv/__init__.py @@ -1,5 +1,5 @@ import tensorflow as tf -lhs_ = tf.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") -rhs_ = tf.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") -op_ = tf.floordiv(lhs_, rhs_) +lhs_ = tf.compat.v1.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") +rhs_ = tf.compat.v1.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") +op_ = tf.compat.v1.floordiv(lhs_, rhs_) diff --git a/res/TensorFlowPythonExamples/examples/greater/__init__.py b/res/TensorFlowPythonExamples/examples/greater/__init__.py old mode 100644 new mode 100755 index c6822abee68..e88f5747135 --- a/res/TensorFlowPythonExamples/examples/greater/__init__.py +++ b/res/TensorFlowPythonExamples/examples/greater/__init__.py @@ -1,5 +1,5 @@ import tensorflow as tf -lhs_ = tf.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") -rhs_ = tf.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") -op_ = tf.greater(lhs_, rhs_) +lhs_ = tf.compat.v1.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") +rhs_ = tf.compat.v1.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") +op_ = tf.compat.v1.greater(lhs_, rhs_) diff --git a/res/TensorFlowPythonExamples/examples/greater_equal/__init__.py b/res/TensorFlowPythonExamples/examples/greater_equal/__init__.py old mode 100644 new mode 100755 index ce2d118be77..b15fbd32453 --- a/res/TensorFlowPythonExamples/examples/greater_equal/__init__.py +++ b/res/TensorFlowPythonExamples/examples/greater_equal/__init__.py @@ -1,5 +1,5 @@ import tensorflow as tf -lhs_ = tf.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") -rhs_ = tf.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") -op_ = tf.greater_equal(lhs_, rhs_) +lhs_ = tf.compat.v1.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") +rhs_ = tf.compat.v1.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") +op_ = tf.compat.v1.greater_equal(lhs_, rhs_) diff --git a/res/TensorFlowPythonExamples/examples/leaky_relu/__init__.py b/res/TensorFlowPythonExamples/examples/leaky_relu/__init__.py old mode 100644 new mode 100755 index 723c65b696e..d595edbd0b0 --- a/res/TensorFlowPythonExamples/examples/leaky_relu/__init__.py +++ b/res/TensorFlowPythonExamples/examples/leaky_relu/__init__.py @@ -1,4 +1,4 @@ import tensorflow as tf -in_ = tf.placeholder(dtype=tf.float32, shape=(1, 1), name="Hole") -op_ = tf.nn.leaky_relu(in_) +in_ = tf.compat.v1.placeholder(dtype=tf.float32, shape=(1, 1), name="Hole") +op_ = tf.compat.v1.nn.leaky_relu(in_) diff --git a/res/TensorFlowPythonExamples/examples/less/__init__.py b/res/TensorFlowPythonExamples/examples/less/__init__.py old mode 100644 new mode 100755 index 01e3cbf0716..41ba18c6265 --- a/res/TensorFlowPythonExamples/examples/less/__init__.py +++ b/res/TensorFlowPythonExamples/examples/less/__init__.py @@ -1,5 +1,5 @@ import tensorflow as tf -lhs_ = tf.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") -rhs_ = tf.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") -op_ = tf.less(lhs_, rhs_) +lhs_ = tf.compat.v1.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") +rhs_ = tf.compat.v1.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") +op_ = tf.compat.v1.less(lhs_, rhs_) diff --git a/res/TensorFlowPythonExamples/examples/less_equal/__init__.py b/res/TensorFlowPythonExamples/examples/less_equal/__init__.py old mode 100644 new mode 100755 index 2dff57d0b8a..d60bf2a73df --- a/res/TensorFlowPythonExamples/examples/less_equal/__init__.py +++ b/res/TensorFlowPythonExamples/examples/less_equal/__init__.py @@ -1,5 +1,5 @@ import tensorflow as tf -lhs_ = tf.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") -rhs_ = tf.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") -op_ = tf.less_equal(lhs_, rhs_) +lhs_ = tf.compat.v1.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") +rhs_ = tf.compat.v1.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") +op_ = tf.compat.v1.less_equal(lhs_, rhs_) diff --git a/res/TensorFlowPythonExamples/examples/logical_not/__init__.py b/res/TensorFlowPythonExamples/examples/logical_not/__init__.py new file mode 100755 index 00000000000..f1bcc2c8fec --- /dev/null +++ b/res/TensorFlowPythonExamples/examples/logical_not/__init__.py @@ -0,0 +1,4 @@ +import tensorflow as tf + +in_ = tf.compat.v1.placeholder(dtype=tf.bool, shape=(4, 4), name="Hole") +op_ = tf.compat.v1.logical_not(in_) diff --git a/res/TensorFlowPythonExamples/examples/logical_or/__init__.py b/res/TensorFlowPythonExamples/examples/logical_or/__init__.py old mode 100644 new mode 100755 index 83100bb591a..991d61ab952 --- a/res/TensorFlowPythonExamples/examples/logical_or/__init__.py +++ b/res/TensorFlowPythonExamples/examples/logical_or/__init__.py @@ -1,5 +1,5 @@ import tensorflow as tf -lhs_ = tf.placeholder(dtype=tf.bool, shape=(4, 4), name="Hole") -rhs_ = tf.placeholder(dtype=tf.bool, shape=(4, 4), name="Hole") -op_ = tf.logical_or(lhs_, rhs_) +lhs_ = tf.compat.v1.placeholder(dtype=tf.bool, shape=(4, 4), name="Hole") +rhs_ = tf.compat.v1.placeholder(dtype=tf.bool, shape=(4, 4), name="Hole") +op_ = tf.compat.v1.logical_or(lhs_, rhs_) diff --git a/res/TensorFlowPythonExamples/examples/matmul/__init__.py b/res/TensorFlowPythonExamples/examples/matmul/__init__.py old mode 100644 new mode 100755 index e88279142d4..760241de7d5 --- a/res/TensorFlowPythonExamples/examples/matmul/__init__.py +++ b/res/TensorFlowPythonExamples/examples/matmul/__init__.py @@ -1,5 +1,5 @@ import tensorflow as tf -lhs_ = tf.placeholder(dtype=tf.float32, shape=(3, 4), name="Hole") -rhs_ = tf.constant(dtype=tf.float32, shape=(4, 4), name="Hole", value=1.0) -op_ = tf.matmul(lhs_, rhs_) +lhs_ = tf.compat.v1.placeholder(dtype=tf.float32, shape=(3, 4), name="Hole") +rhs_ = tf.compat.v1.constant(dtype=tf.float32, shape=(4, 4), name="Hole", value=1.0) +op_ = tf.compat.v1.matmul(lhs_, rhs_) diff --git a/res/TensorFlowPythonExamples/examples/multiply/__init__.py b/res/TensorFlowPythonExamples/examples/multiply/__init__.py old mode 100644 new mode 100755 index 545543d20a9..da888566039 --- a/res/TensorFlowPythonExamples/examples/multiply/__init__.py +++ b/res/TensorFlowPythonExamples/examples/multiply/__init__.py @@ -1,5 +1,5 @@ import tensorflow as tf -lhs_ = tf.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") -rhs_ = tf.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") -op_ = tf.multiply(lhs_, rhs_) +lhs_ = tf.compat.v1.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") +rhs_ = tf.compat.v1.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") +op_ = tf.compat.v1.multiply(lhs_, rhs_) diff --git a/res/TensorFlowPythonExamples/examples/not_equal/__init__.py b/res/TensorFlowPythonExamples/examples/not_equal/__init__.py old mode 100644 new mode 100755 index 96a0baf2c4c..95073fe4a3b --- a/res/TensorFlowPythonExamples/examples/not_equal/__init__.py +++ b/res/TensorFlowPythonExamples/examples/not_equal/__init__.py @@ -1,5 +1,5 @@ import tensorflow as tf -lhs_ = tf.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") -rhs_ = tf.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") -op_ = tf.not_equal(lhs_, rhs_) +lhs_ = tf.compat.v1.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") +rhs_ = tf.compat.v1.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") +op_ = tf.compat.v1.not_equal(lhs_, rhs_) diff --git a/res/TensorFlowPythonExamples/examples/pack/__init__.py b/res/TensorFlowPythonExamples/examples/pack/__init__.py new file mode 100755 index 00000000000..609bc9b7652 --- /dev/null +++ b/res/TensorFlowPythonExamples/examples/pack/__init__.py @@ -0,0 +1,5 @@ +import tensorflow as tf + +in_1 = tf.compat.v1.placeholder(dtype=tf.float32, shape=(2, 3, 4), name="Hole") +in_2 = tf.compat.v1.placeholder(dtype=tf.float32, shape=(2, 3, 4), name="Hole") +op_ = tf.compat.v1.stack([in_1, in_2]) diff --git a/res/TensorFlowPythonExamples/examples/pad/__init__.py b/res/TensorFlowPythonExamples/examples/pad/__init__.py old mode 100644 new mode 100755 index f390c99af66..ac5cf81fa55 --- a/res/TensorFlowPythonExamples/examples/pad/__init__.py +++ b/res/TensorFlowPythonExamples/examples/pad/__init__.py @@ -1,5 +1,5 @@ import tensorflow as tf -tensor_ = tf.placeholder(dtype=tf.float32, shape=(2, 3), name="Hole") -paddings_ = tf.constant([[1, 1], [2, 2]], name="Hole") -op_ = tf.pad(tensor_, paddings_) +tensor_ = tf.compat.v1.placeholder(dtype=tf.float32, shape=(2, 3), name="Hole") +paddings_ = tf.compat.v1.constant([[1, 1], [2, 2]], name="Hole") +op_ = tf.compat.v1.pad(tensor_, paddings_) diff --git a/res/TensorFlowPythonExamples/examples/pow/__init__.py b/res/TensorFlowPythonExamples/examples/pow/__init__.py old mode 100644 new mode 100755 index edbc9a5b99e..960032a841d --- a/res/TensorFlowPythonExamples/examples/pow/__init__.py +++ b/res/TensorFlowPythonExamples/examples/pow/__init__.py @@ -1,5 +1,5 @@ import tensorflow as tf -lhs_ = tf.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") -rhs_ = tf.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") -op_ = tf.pow(lhs_, rhs_) +lhs_ = tf.compat.v1.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") +rhs_ = tf.compat.v1.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") +op_ = tf.compat.v1.pow(lhs_, rhs_) diff --git a/res/TensorFlowPythonExamples/examples/prelu/__init__.py b/res/TensorFlowPythonExamples/examples/prelu/__init__.py old mode 100644 new mode 100755 index bae519c0a6c..2ab0302656c --- a/res/TensorFlowPythonExamples/examples/prelu/__init__.py +++ b/res/TensorFlowPythonExamples/examples/prelu/__init__.py @@ -1,7 +1,7 @@ import tensorflow as tf from tensorflow.compat.v1.keras import layers -model = tf.keras.Sequential() +model = tf.compat.v1.keras.Sequential() model.add(layers.PReLU()) # TODO Find a way to freeze Keras model for inference model.build((1, 1)) diff --git a/res/TensorFlowPythonExamples/examples/relu/__init__.py b/res/TensorFlowPythonExamples/examples/relu/__init__.py old mode 100644 new mode 100755 index 69538cfc9db..a144a12120d --- a/res/TensorFlowPythonExamples/examples/relu/__init__.py +++ b/res/TensorFlowPythonExamples/examples/relu/__init__.py @@ -1,4 +1,4 @@ import tensorflow as tf -in_ = tf.placeholder(dtype=tf.float32, shape=(1, 1), name="Hole") -op_ = tf.nn.relu(in_) +in_ = tf.compat.v1.placeholder(dtype=tf.float32, shape=(1, 1), name="Hole") +op_ = tf.compat.v1.nn.relu(in_) diff --git a/res/TensorFlowPythonExamples/examples/relu6/__init__.py b/res/TensorFlowPythonExamples/examples/relu6/__init__.py old mode 100644 new mode 100755 index ed414ebed35..f58ae7c2ca8 --- a/res/TensorFlowPythonExamples/examples/relu6/__init__.py +++ b/res/TensorFlowPythonExamples/examples/relu6/__init__.py @@ -1,4 +1,4 @@ import tensorflow as tf -in_ = tf.placeholder(dtype=tf.float32, shape=(1, 1), name="Hole") -op_ = tf.nn.relu6(in_) +in_ = tf.compat.v1.placeholder(dtype=tf.float32, shape=(1, 1), name="Hole") +op_ = tf.compat.v1.nn.relu6(in_) diff --git a/res/TensorFlowPythonExamples/examples/resize_bilinear/__init__.py b/res/TensorFlowPythonExamples/examples/resize_bilinear/__init__.py old mode 100644 new mode 100755 index c12d77a3bfa..422bf1db55a --- a/res/TensorFlowPythonExamples/examples/resize_bilinear/__init__.py +++ b/res/TensorFlowPythonExamples/examples/resize_bilinear/__init__.py @@ -1,4 +1,4 @@ import tensorflow as tf -in_ = tf.placeholder(dtype=tf.float32, shape=(1, 8, 8, 3), name="Hole") -op_ = tf.image.resize_bilinear(in_, [16, 16]) +in_ = tf.compat.v1.placeholder(dtype=tf.float32, shape=(1, 8, 8, 3), name="Hole") +op_ = tf.compat.v1.image.resize_bilinear(in_, [16, 16]) diff --git a/res/TensorFlowPythonExamples/examples/resize_nearest_neighbor/__init__.py b/res/TensorFlowPythonExamples/examples/resize_nearest_neighbor/__init__.py old mode 100644 new mode 100755 index cab1fbe9a7a..a1402294846 --- a/res/TensorFlowPythonExamples/examples/resize_nearest_neighbor/__init__.py +++ b/res/TensorFlowPythonExamples/examples/resize_nearest_neighbor/__init__.py @@ -1,4 +1,4 @@ import tensorflow as tf -in_ = tf.placeholder(dtype=tf.float32, shape=(1, 8, 8, 3), name="Hole") -op_ = tf.image.resize_nearest_neighbor(in_, [16, 16]) +in_ = tf.compat.v1.placeholder(dtype=tf.float32, shape=(1, 8, 8, 3), name="Hole") +op_ = tf.compat.v1.image.resize_nearest_neighbor(in_, [16, 16]) diff --git a/res/TensorFlowPythonExamples/examples/rsqrt/__init__.py b/res/TensorFlowPythonExamples/examples/rsqrt/__init__.py old mode 100644 new mode 100755 index 6ec8e995d8b..90500bd113d --- a/res/TensorFlowPythonExamples/examples/rsqrt/__init__.py +++ b/res/TensorFlowPythonExamples/examples/rsqrt/__init__.py @@ -1,4 +1,4 @@ import tensorflow as tf -in_ = tf.placeholder(dtype=tf.float32, shape=(1, 1), name="Hole") -op_ = tf.rsqrt(in_) +in_ = tf.compat.v1.placeholder(dtype=tf.float32, shape=(1, 1), name="Hole") +op_ = tf.compat.v1.rsqrt(in_) diff --git a/res/TensorFlowPythonExamples/examples/sigmoid/__init__.py b/res/TensorFlowPythonExamples/examples/sigmoid/__init__.py old mode 100644 new mode 100755 index d3f8a736036..43328f2cb6b --- a/res/TensorFlowPythonExamples/examples/sigmoid/__init__.py +++ b/res/TensorFlowPythonExamples/examples/sigmoid/__init__.py @@ -1,4 +1,4 @@ import tensorflow as tf -in_ = tf.placeholder(dtype=tf.float32, shape=(1, 1), name="Hole") -op_ = tf.nn.sigmoid(in_) +in_ = tf.compat.v1.placeholder(dtype=tf.float32, shape=(1, 1), name="Hole") +op_ = tf.compat.v1.nn.sigmoid(in_) diff --git a/res/TensorFlowPythonExamples/examples/softmax/__init__.py b/res/TensorFlowPythonExamples/examples/softmax/__init__.py old mode 100644 new mode 100755 index dccb3f9bcf9..5b8d1cdfb5a --- a/res/TensorFlowPythonExamples/examples/softmax/__init__.py +++ b/res/TensorFlowPythonExamples/examples/softmax/__init__.py @@ -1,4 +1,4 @@ import tensorflow as tf -in_ = tf.placeholder(dtype=tf.float32, shape=(1, 1), name="Hole") -op_ = tf.nn.softmax(in_) +in_ = tf.compat.v1.placeholder(dtype=tf.float32, shape=(1, 1), name="Hole") +op_ = tf.compat.v1.nn.softmax(in_) diff --git a/res/TensorFlowPythonExamples/examples/sqrt/__init__.py b/res/TensorFlowPythonExamples/examples/sqrt/__init__.py old mode 100644 new mode 100755 index 0ed3bb476b9..4aab5da9ca7 --- a/res/TensorFlowPythonExamples/examples/sqrt/__init__.py +++ b/res/TensorFlowPythonExamples/examples/sqrt/__init__.py @@ -1,4 +1,4 @@ import tensorflow as tf -in_ = tf.placeholder(dtype=tf.float32, shape=(1, 1), name="Hole") -op_ = tf.sqrt(in_) +in_ = tf.compat.v1.placeholder(dtype=tf.float32, shape=(1, 1), name="Hole") +op_ = tf.compat.v1.sqrt(in_) diff --git a/res/TensorFlowPythonExamples/examples/subtract/__init__.py b/res/TensorFlowPythonExamples/examples/subtract/__init__.py old mode 100644 new mode 100755 index 222c9d81712..feb11b12eee --- a/res/TensorFlowPythonExamples/examples/subtract/__init__.py +++ b/res/TensorFlowPythonExamples/examples/subtract/__init__.py @@ -1,5 +1,5 @@ import tensorflow as tf -lhs_ = tf.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") -rhs_ = tf.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") -op_ = tf.subtract(lhs_, rhs_) +lhs_ = tf.compat.v1.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") +rhs_ = tf.compat.v1.placeholder(dtype=tf.float32, shape=(4, 4), name="Hole") +op_ = tf.compat.v1.subtract(lhs_, rhs_) diff --git a/res/TensorFlowPythonExamples/examples/tanh/__init__.py b/res/TensorFlowPythonExamples/examples/tanh/__init__.py old mode 100644 new mode 100755 index e38e21afbd2..dd202a78d3c --- a/res/TensorFlowPythonExamples/examples/tanh/__init__.py +++ b/res/TensorFlowPythonExamples/examples/tanh/__init__.py @@ -1,4 +1,4 @@ import tensorflow as tf -in_ = tf.placeholder(dtype=tf.float32, shape=(1, 1), name="Hole") -op_ = tf.tanh(in_) +in_ = tf.compat.v1.placeholder(dtype=tf.float32, shape=(1, 1), name="Hole") +op_ = tf.compat.v1.tanh(in_) diff --git a/res/TensorFlowPythonExamples/examples/yuv_to_rgb/__init__.py b/res/TensorFlowPythonExamples/examples/yuv_to_rgb/__init__.py old mode 100644 new mode 100755 index d107d9bede3..5230bbac6dc --- a/res/TensorFlowPythonExamples/examples/yuv_to_rgb/__init__.py +++ b/res/TensorFlowPythonExamples/examples/yuv_to_rgb/__init__.py @@ -1,4 +1,4 @@ import tensorflow as tf -in_ = tf.placeholder(dtype=tf.float32, shape=(1, 16, 16, 3), name="Hole") -op_ = tf.image.yuv_to_rgb(in_) +in_ = tf.compat.v1.placeholder(dtype=tf.float32, shape=(1, 16, 16, 3), name="Hole") +op_ = tf.compat.v1.image.yuv_to_rgb(in_) diff --git a/res/TensorFlowPythonExamples/tfpem.py b/res/TensorFlowPythonExamples/tfpem.py index 7028327c39d..514200c1904 100755 --- a/res/TensorFlowPythonExamples/tfpem.py +++ b/res/TensorFlowPythonExamples/tfpem.py @@ -15,11 +15,11 @@ for example in args.examples: print("Generate '" + example + ".pbtxt'") - tf.reset_default_graph() + tf.compat.v1.reset_default_graph() # https://stackoverflow.com/questions/37808866/proper-way-to-dynamically-import-a-module-with-relative-imports importlib.import_module("examples." + example) with open(example + ".pbtxt", "w") as f: - f.write(str(tf.get_default_graph().as_graph_def(add_shapes=True))) + f.write(str(tf.compat.v1.get_default_graph().as_graph_def(add_shapes=True))) print("Generate '" + example + ".pbtxt' - Done") diff --git a/res/TensorFlowTests/NET_0003/test.py b/res/TensorFlowTests/NET_0003/test.py old mode 100644 new mode 100755 diff --git a/res/TensorFlowTests/NET_0004/test.py b/res/TensorFlowTests/NET_0004/test.py old mode 100644 new mode 100755 diff --git a/runtime/contrib/README.md b/runtime/contrib/README.md deleted file mode 100644 index 2f8b709ebfa..00000000000 --- a/runtime/contrib/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# nnfw contrib - -The `contrib` directory is basically a contribution channel where contributors can create a project -and start the code development. The projects in the `contrib` directory may not be directly related -to `nnfw` but should have its own purpose that could augment the nnfw project. - -If you are interested in proposing a new project, please create a pull request (PR) with a new -project directory under `contrib` including the description of proposing project. The PR will be -reviewed by reviewers in `nnfw`, and the acceptance of new project will be determined based on the -PR reviews. diff --git a/runtime/contrib/android_benchmark_app/CMakeLists.txt b/runtime/contrib/android_benchmark_app/CMakeLists.txt index 8e9d3c7a139..ac511cfa3d6 100644 --- a/runtime/contrib/android_benchmark_app/CMakeLists.txt +++ b/runtime/contrib/android_benchmark_app/CMakeLists.txt @@ -81,11 +81,11 @@ add_custom_target(android-benchmark-apk ALL COMMAND ${CMAKE_COMMAND} -E copy ${CORE_LIBRARY} ${LIB_DIR} COMMAND ${CMAKE_COMMAND} -E copy ${RUNTIME_LIBRARY} ${LIB_DIR} COMMAND ${CMAKE_COMMAND} -E copy $ ${LIB_DIR} - COMMAND ${CMAKE_COMMAND} -E copy $ ${LIB_DIR} - COMMAND ${CMAKE_COMMAND} -E copy $ ${LIB_DIR} + COMMAND ${CMAKE_COMMAND} -E copy $ ${LIB_DIR} + COMMAND ${CMAKE_COMMAND} -E copy $ ${LIB_DIR} COMMAND ${CMAKE_COMMAND} -E copy $ ${LIB_DIR} - COMMAND ${CMAKE_COMMAND} -E copy $ ${LIB_DIR} - COMMAND ${CMAKE_COMMAND} -E copy $ ${LIB_DIR} + COMMAND ${CMAKE_COMMAND} -E copy $ ${LIB_DIR} + COMMAND ${CMAKE_COMMAND} -E copy $ ${LIB_DIR} COMMAND ${CMAKE_COMMAND} -E echo ${ANDROID_BUILD_TOOLS_DIR}/aapt package -f -0 tflite -M ${CMAKE_CURRENT_SOURCE_DIR}/AndroidManifest.xml -S ${CMAKE_CURRENT_SOURCE_DIR}/res/ -I ${ANDROID_PLATFORM_DIR}/android.jar -F ${CMAKE_CURRENT_BINARY_DIR}/android-benchmark.unsigned.pkg ${PKG_DIR} COMMAND ${ANDROID_BUILD_TOOLS_DIR}/aapt package -f -0 tflite @@ -94,4 +94,4 @@ add_custom_target(android-benchmark-apk ALL -I ${ANDROID_PLATFORM_DIR}/android.jar -F ${CMAKE_CURRENT_BINARY_DIR}/android-benchmark.unsigned.pkg ${PKG_DIR} - DEPENDS android_benchmark_native neurun neurun_backend_acl_cl neurun_backend_acl_neon neurun_backend_cpu) + DEPENDS android_benchmark_native onert onert_backend_acl_cl onert_backend_acl_neon onert_backend_cpu) diff --git a/runtime/contrib/android_benchmark_app/README.md b/runtime/contrib/android_benchmark_app/README.md index fafce7cb58c..ce165cd5d49 100644 --- a/runtime/contrib/android_benchmark_app/README.md +++ b/runtime/contrib/android_benchmark_app/README.md @@ -5,7 +5,7 @@ An Android sample app that run `.tflite` and measure performance. You can run with two engines. - Tensorflow Lite Interpreter -- NN API Delegate (neurun) +- NN API Delegate (onert) ## Build diff --git a/runtime/contrib/custom_op/README.md b/runtime/contrib/custom_op/README.md new file mode 100644 index 00000000000..7815ce9d589 --- /dev/null +++ b/runtime/contrib/custom_op/README.md @@ -0,0 +1,25 @@ +This document is about custom operators. + +# Introduction + +# Requirements + +- [ ] Support tizen in-house custom op developer +- [ ] Minimiz exposed headers (structures and functions) +- [ ] Provide acceptable performance + +# Design + +## Design + +### Workflow + +![](customOp-workflow.png) + +## Candidate Architecture 1 + +## Candidate Architecture 2 + +## Discussion + +# Conclusion diff --git a/runtime/contrib/heap_trace/tests/src/memory_pool_for_symbol_searcher_internals_test.cc b/runtime/contrib/heap_trace/tests/src/memory_pool_for_symbol_searcher_internals_test.cc index 6cb6435877b..c0e2e1d3cba 100644 --- a/runtime/contrib/heap_trace/tests/src/memory_pool_for_symbol_searcher_internals_test.cc +++ b/runtime/contrib/heap_trace/tests/src/memory_pool_for_symbol_searcher_internals_test.cc @@ -66,4 +66,4 @@ TEST_F(MemoryPoolForSymbolSearcherInternals, memory.deallocate(p1); free(p2); } -} +} // namespace backstage diff --git a/runtime/contrib/hi_perf_cpu/CMakeLists.txt b/runtime/contrib/hi_perf_cpu/CMakeLists.txt index 437b1d0cae8..141698a8af4 100644 --- a/runtime/contrib/hi_perf_cpu/CMakeLists.txt +++ b/runtime/contrib/hi_perf_cpu/CMakeLists.txt @@ -1,47 +1,47 @@ -set(LIB_NEURUN_BACKEND_HI_PERF_CPU neurun_backend_hi_perf) +set(LIB_ONERT_BACKEND_HI_PERF_CPU onert_backend_hi_perf) nnas_find_package(NNPACK QUIET) -option(BUILD_NEURUN_HI_PERF_CPU_BACKEND - "Build neurun HI_PERF_CPU backend" +option(BUILD_ONERT_HI_PERF_CPU_BACKEND + "Build onert HI_PERF_CPU backend" ${NNPACK_FOUND} # Default value when there is no explicit user request ) -message(STATUS "Build neurun HI_PERF_CPU backend: ${BUILD_NEURUN_HI_PERF_CPU_BACKEND}") +message(STATUS "Build onert HI_PERF_CPU backend: ${BUILD_ONERT_HI_PERF_CPU_BACKEND}") -if(NOT BUILD_NEURUN_HI_PERF_CPU_BACKEND) +if(NOT BUILD_ONERT_HI_PERF_CPU_BACKEND) return() -endif(NOT BUILD_NEURUN_HI_PERF_CPU_BACKEND) +endif(NOT BUILD_ONERT_HI_PERF_CPU_BACKEND) file(GLOB_RECURSE SOURCES "*.cc") file(GLOB_RECURSE TESTS "*.test.cc") list(REMOVE_ITEM SOURCES ${TESTS}) -add_library(${LIB_NEURUN_BACKEND_HI_PERF_CPU} SHARED ${SOURCES}) +add_library(${LIB_ONERT_BACKEND_HI_PERF_CPU} SHARED ${SOURCES}) -target_link_libraries(${LIB_NEURUN_BACKEND_HI_PERF_CPU} PRIVATE nnfw_lib_misc) -target_link_libraries(${LIB_NEURUN_BACKEND_HI_PERF_CPU} PRIVATE neurun_core) -target_link_libraries(${LIB_NEURUN_BACKEND_HI_PERF_CPU} PRIVATE nnfw_common) -target_link_libraries(${LIB_NEURUN_BACKEND_HI_PERF_CPU} PRIVATE nnpack pthreadpool cpuinfo) -target_link_libraries(${LIB_NEURUN_BACKEND_HI_PERF_CPU} PRIVATE nnfw_coverage) -target_include_directories(${LIB_NEURUN_BACKEND_HI_PERF_CPU} PRIVATE ${NNPACK_INCLUDE_DIRS}) +target_link_libraries(${LIB_ONERT_BACKEND_HI_PERF_CPU} PRIVATE nnfw_lib_misc) +target_link_libraries(${LIB_ONERT_BACKEND_HI_PERF_CPU} PRIVATE onert_core) +target_link_libraries(${LIB_ONERT_BACKEND_HI_PERF_CPU} PRIVATE nnfw_common) +target_link_libraries(${LIB_ONERT_BACKEND_HI_PERF_CPU} PRIVATE nnpack pthreadpool cpuinfo) +target_link_libraries(${LIB_ONERT_BACKEND_HI_PERF_CPU} PRIVATE nnfw_coverage) +target_include_directories(${LIB_ONERT_BACKEND_HI_PERF_CPU} PRIVATE ${NNPACK_INCLUDE_DIRS}) -set_target_properties(${LIB_NEURUN_BACKEND_HI_PERF_CPU} PROPERTIES OUTPUT_NAME backend_NNPACK) +set_target_properties(${LIB_ONERT_BACKEND_HI_PERF_CPU} PROPERTIES OUTPUT_NAME backend_NNPACK) -install(TARGETS ${LIB_NEURUN_BACKEND_HI_PERF_CPU} DESTINATION lib) +install(TARGETS ${LIB_ONERT_BACKEND_HI_PERF_CPU} DESTINATION lib) if(NOT ENABLE_TEST) return() endif(NOT ENABLE_TEST) # Unit Tests -set(TEST_NEURUN_BACKEND_HI_PERF_CPU test_neurun_backend_hi_perf) +set(TEST_ONERT_BACKEND_HI_PERF_CPU test_onert_backend_hi_perf) -add_executable(${TEST_NEURUN_BACKEND_HI_PERF_CPU} ${TESTS}) +add_executable(${TEST_ONERT_BACKEND_HI_PERF_CPU} ${TESTS}) -target_link_libraries(${TEST_NEURUN_BACKEND_HI_PERF_CPU} ${LIB_NEURUN_BACKEND_HI_PERF_CPU}) -target_link_libraries(${TEST_NEURUN_BACKEND_HI_PERF_CPU} gtest gtest_main ${LIB_PTHREAD}) -target_link_libraries(${TEST_NEURUN_BACKEND_HI_PERF_CPU} nnpack) +target_link_libraries(${TEST_ONERT_BACKEND_HI_PERF_CPU} ${LIB_ONERT_BACKEND_HI_PERF_CPU}) +target_link_libraries(${TEST_ONERT_BACKEND_HI_PERF_CPU} gtest gtest_main ${LIB_PTHREAD}) +target_link_libraries(${TEST_ONERT_BACKEND_HI_PERF_CPU} nnpack) -add_test(${TEST_NEURUN_BACKEND_HI_PERF_CPU} ${TEST_NEURUN_BACKEND_HI_PERF_CPU}) -install(TARGETS ${TEST_NEURUN_BACKEND_HI_PERF_CPU} DESTINATION unittest) +add_test(${TEST_ONERT_BACKEND_HI_PERF_CPU} ${TEST_ONERT_BACKEND_HI_PERF_CPU}) +install(TARGETS ${TEST_ONERT_BACKEND_HI_PERF_CPU} DESTINATION unittest) diff --git a/runtime/contrib/hi_perf_cpu/KernelGenerator.h b/runtime/contrib/hi_perf_cpu/KernelGenerator.h index 6ab354890ff..67278521d10 100644 --- a/runtime/contrib/hi_perf_cpu/KernelGenerator.h +++ b/runtime/contrib/hi_perf_cpu/KernelGenerator.h @@ -14,15 +14,15 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_HI_PERF_CPU_KERNEL_GENERATOR_H__ -#define __NEURUN_BACKEND_HI_PERF_CPU_KERNEL_GENERATOR_H__ +#ifndef __ONERT_BACKEND_HI_PERF_CPU_KERNEL_GENERATOR_H__ +#define __ONERT_BACKEND_HI_PERF_CPU_KERNEL_GENERATOR_H__ #include #include "ir/Operands.h" #include "TensorBuilder.h" -namespace neurun +namespace onert { namespace backend { @@ -42,6 +42,6 @@ class KernelGenerator : public IKernelGenerator } // namespace hi_perf_cpu } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_HI_PERF_CPU_KERNEL_GENERATOR_H__ +#endif // __ONERT_BACKEND_HI_PERF_CPU_KERNEL_GENERATOR_H__ diff --git a/runtime/contrib/hi_perf_cpu/TensorBuilder.h b/runtime/contrib/hi_perf_cpu/TensorBuilder.h index af879a41e32..17ebb00cfc2 100644 --- a/runtime/contrib/hi_perf_cpu/TensorBuilder.h +++ b/runtime/contrib/hi_perf_cpu/TensorBuilder.h @@ -22,7 +22,7 @@ #include #include "ir/OperandIndexMap.h" -namespace neurun +namespace onert { namespace backend { @@ -39,6 +39,6 @@ class TensorBuilder : public ITensorBuilder } // namespace hi_perf_cpu } // namespace backend -} // namespace neurun +} // namespace onert #endif // NNFW_TENSORBUILDER_H diff --git a/runtime/contrib/labs/jniacl/src/jniacl_main.cc b/runtime/contrib/labs/jniacl/src/jniacl_main.cc index 5b01d3fe37a..01b928981ed 100644 --- a/runtime/contrib/labs/jniacl/src/jniacl_main.cc +++ b/runtime/contrib/labs/jniacl/src/jniacl_main.cc @@ -26,11 +26,11 @@ extern "C" JNIEXPORT jstring JNICALL Java_com_samsung_testaclexec_ActivityMain_RunACLJNI(JNIEnv *env, jobject) { using arm_compute::DataType; - using arm_compute::graph::Tensor; - using arm_compute::graph::TargetHint; - using arm_compute::graph::Graph; using arm_compute::TensorInfo; using arm_compute::TensorShape; + using arm_compute::graph::Graph; + using arm_compute::graph::TargetHint; + using arm_compute::graph::Tensor; arm_compute::graph::Graph graph; TargetHint target_hint = TargetHint::OPENCL; diff --git a/runtime/contrib/labs/tflite_examples/src/conv.cpp b/runtime/contrib/labs/tflite_examples/src/conv.cpp index 3117c316ca8..e8542c3f5be 100644 --- a/runtime/contrib/labs/tflite_examples/src/conv.cpp +++ b/runtime/contrib/labs/tflite_examples/src/conv.cpp @@ -33,7 +33,7 @@ template struct View virtual int32_t size(void) const = 0; virtual T at(uint32_t off) const = 0; }; -} +} // namespace vector namespace feature { @@ -52,7 +52,7 @@ template struct View virtual const Shape &shape(void) const = 0; virtual T at(uint32_t ch, uint32_t row, uint32_t col) const = 0; }; -} +} // namespace feature namespace kernel { @@ -72,7 +72,7 @@ template struct View virtual const Shape &shape(void) const = 0; virtual T at(uint32_t nth, uint32_t ch, uint32_t row, uint32_t col) const = 0; }; -} +} // namespace kernel const int32_t N = 1; const int32_t C = 2; diff --git a/runtime/contrib/logging/src/nnapi_logging.cc b/runtime/contrib/logging/src/nnapi_logging.cc index c44da3f1f98..370e72a0a32 100644 --- a/runtime/contrib/logging/src/nnapi_logging.cc +++ b/runtime/contrib/logging/src/nnapi_logging.cc @@ -125,7 +125,7 @@ std::string OperandCodeResolver::resolve(int code) const return it->second; } -} +} // namespace // // Asynchronous Event diff --git a/runtime/contrib/mlapse/tfl/mlapse/benchmark_observer.h b/runtime/contrib/mlapse/tfl/mlapse/benchmark_observer.h index 8fc570d24eb..7929111571a 100644 --- a/runtime/contrib/mlapse/tfl/mlapse/benchmark_observer.h +++ b/runtime/contrib/mlapse/tfl/mlapse/benchmark_observer.h @@ -72,6 +72,6 @@ struct BenchmarkObserver virtual void notify(const NotificationArg &arg) = 0; }; -} // namespace mlpase +} // namespace mlapse #endif // __MLAPSE_BENCHMARK_OBSERVER_H__ diff --git a/runtime/contrib/mlapse/tfl/mlapse/benchmark_runner.h b/runtime/contrib/mlapse/tfl/mlapse/benchmark_runner.h index fcbb41d1b67..7f10c059f39 100644 --- a/runtime/contrib/mlapse/tfl/mlapse/benchmark_runner.h +++ b/runtime/contrib/mlapse/tfl/mlapse/benchmark_runner.h @@ -58,6 +58,6 @@ class BenchmarkRunner final BenchmarkObserver *_observer = nullptr; }; -} // namespace mlpase +} // namespace mlapse #endif // __MLAPSE_BENCHMARK_RUNNER_H__ diff --git a/runtime/contrib/pure_arm_compute/src/compilation.cc b/runtime/contrib/pure_arm_compute/src/compilation.cc index 04e383e056c..b97fab5476a 100644 --- a/runtime/contrib/pure_arm_compute/src/compilation.cc +++ b/runtime/contrib/pure_arm_compute/src/compilation.cc @@ -767,7 +767,6 @@ void Planner::visit(const ::internal::tflite::op::Mul::Node &node) param.activation = static_cast(_ctx.at(activation_index).asScalar()); auto stage = [param](const IAllocationContext &ctx, IExecutionBuilder &builder) { - auto output_alloc = ctx.at(::internal::tflite::operand::Index{param.ofm_index}); auto lhs_input_alloc = ctx.at(::internal::tflite::operand::Index{param.lhs_index}); auto rhs_input_alloc = ctx.at(::internal::tflite::operand::Index{param.rhs_index}); @@ -3630,7 +3629,6 @@ void Planner::visit(const ::internal::tflite::op::Transpose::Node &node) param.rank = _ctx.at(ifm_index).shape().rank(); auto stage = [param](const IAllocationContext &ctx, IExecutionBuilder &builder) { - auto ofm_alloc = ctx.at(::internal::tflite::operand::Index{param.ofm_index}); const auto ifm_alloc = ctx.at(::internal::tflite::operand::Index{param.ifm_index}); @@ -3647,7 +3645,6 @@ void Planner::visit(const ::internal::tflite::op::Transpose::Node &node) { throw std::runtime_error("Not supported, yet"); } - }; _builder.addStage(stage); @@ -4121,7 +4118,6 @@ void Planner::visit(const ::internal::tflite::op::SquaredDifference::Node &node) // TODO Enable NEON Support throw std::runtime_error("Not supported, yet"); } - }; _builder.addStage(stage); @@ -5350,7 +5346,6 @@ void Planner::visit(const ::internal::tflite::op::Neg::Node &node) // TODO Enable NEON Support throw std::runtime_error("Not supported, yet"); } - }; _builder.addStage(stage); } diff --git a/runtime/contrib/pure_arm_compute/src/internal/MatrixSink.h b/runtime/contrib/pure_arm_compute/src/internal/MatrixSink.h index 23ecc112bd2..b33556697d4 100644 --- a/runtime/contrib/pure_arm_compute/src/internal/MatrixSink.h +++ b/runtime/contrib/pure_arm_compute/src/internal/MatrixSink.h @@ -62,10 +62,10 @@ template class MatrixSink final : public Sink assert(tensor.info()->dimension(0) == _width); assert(tensor.info()->dimension(1) == _height); - using ::arm_compute::Window; - using ::arm_compute::Iterator; using ::arm_compute::Coordinates; using ::arm_compute::execute_window_loop; + using ::arm_compute::Iterator; + using ::arm_compute::Window; Window window; diff --git a/runtime/contrib/pure_arm_compute/src/internal/MatrixSource.h b/runtime/contrib/pure_arm_compute/src/internal/MatrixSource.h index 71d6a804f08..c19d6af0147 100644 --- a/runtime/contrib/pure_arm_compute/src/internal/MatrixSource.h +++ b/runtime/contrib/pure_arm_compute/src/internal/MatrixSource.h @@ -54,10 +54,10 @@ template class MatrixSource final : public Source */ void push(::arm_compute::ITensor &tensor) const override { - using ::arm_compute::Window; - using ::arm_compute::Iterator; using ::arm_compute::Coordinates; using ::arm_compute::execute_window_loop; + using ::arm_compute::Iterator; + using ::arm_compute::Window; Window window; window.use_tensor_dimensions(tensor.info()->tensor_shape(), ::arm_compute::Window::DimY); diff --git a/runtime/contrib/pure_arm_compute/src/internal/Sinks.h b/runtime/contrib/pure_arm_compute/src/internal/Sinks.h index 7317c67c15a..8e8d775bac3 100644 --- a/runtime/contrib/pure_arm_compute/src/internal/Sinks.h +++ b/runtime/contrib/pure_arm_compute/src/internal/Sinks.h @@ -68,8 +68,8 @@ template class TensorSink final : public Sink const ::internal::arm_compute::tensor::View from{&tensor}; ::internal::nnapi::tensor::View into{_shape, _base, _size}; - using ::nnfw::misc::tensor::iterate; using ::nnfw::misc::tensor::Index; + using ::nnfw::misc::tensor::iterate; const uint32_t rank = _shape.rank(); diff --git a/runtime/contrib/pure_arm_compute/src/internal/Tensor3DSink.h b/runtime/contrib/pure_arm_compute/src/internal/Tensor3DSink.h index 1e14e2d6c9b..e471308604e 100644 --- a/runtime/contrib/pure_arm_compute/src/internal/Tensor3DSink.h +++ b/runtime/contrib/pure_arm_compute/src/internal/Tensor3DSink.h @@ -57,10 +57,10 @@ template class Tensor3DSink final : public Sink */ void pull(::arm_compute::ITensor &tensor) const override { - using ::arm_compute::Window; - using ::arm_compute::Iterator; using ::arm_compute::Coordinates; using ::arm_compute::execute_window_loop; + using ::arm_compute::Iterator; + using ::arm_compute::Window; Window window; diff --git a/runtime/contrib/pure_arm_compute/src/internal/Tensor3DSource.h b/runtime/contrib/pure_arm_compute/src/internal/Tensor3DSource.h index 3d8d1b9585b..1e7fb52723b 100644 --- a/runtime/contrib/pure_arm_compute/src/internal/Tensor3DSource.h +++ b/runtime/contrib/pure_arm_compute/src/internal/Tensor3DSource.h @@ -57,10 +57,10 @@ template class Tensor3DSource final : public Source */ void push(::arm_compute::ITensor &tensor) const override { - using ::arm_compute::Window; - using ::arm_compute::Iterator; using ::arm_compute::Coordinates; using ::arm_compute::execute_window_loop; + using ::arm_compute::Iterator; + using ::arm_compute::Window; Window window; diff --git a/runtime/contrib/pure_arm_compute/src/internal/arm_compute.cc b/runtime/contrib/pure_arm_compute/src/internal/arm_compute.cc index a7be2068d4a..e1a903e5256 100644 --- a/runtime/contrib/pure_arm_compute/src/internal/arm_compute.cc +++ b/runtime/contrib/pure_arm_compute/src/internal/arm_compute.cc @@ -45,7 +45,7 @@ void Object::access(const std::function &f } } // namespace operand -} // namepsace arm_compute +} // namespace arm_compute } // namespace internal namespace internal @@ -65,7 +65,7 @@ Context &Context::set(const ::internal::tflite::operand::Index &id, } } // namespace operand -} // namepsace arm_compute +} // namespace arm_compute } // namespace internal namespace internal @@ -83,5 +83,5 @@ bool isGpuMode() return true; } -} // namepsace arm_compute +} // namespace arm_compute } // namespace internal diff --git a/runtime/contrib/pure_arm_compute/src/internal/arm_compute.h b/runtime/contrib/pure_arm_compute/src/internal/arm_compute.h index fb6acaf81c2..64827476cc9 100644 --- a/runtime/contrib/pure_arm_compute/src/internal/arm_compute.h +++ b/runtime/contrib/pure_arm_compute/src/internal/arm_compute.h @@ -68,7 +68,7 @@ class Object }; } // namespace operand -} // namepsace arm_compute +} // namespace arm_compute } // namespace internal #include "internal/Model.h" @@ -131,7 +131,7 @@ class Context }; } // namespace operand -} // namepsace arm_compute +} // namespace arm_compute } // namespace internal #include @@ -192,13 +192,14 @@ class Step * @return The operation index as reference */ int &op_idx() { return _op_idx; } + private: int _op_idx; #endif }; } // namespace op -} // namepsace arm_compute +} // namespace arm_compute } // namespace internal namespace internal @@ -252,7 +253,7 @@ class Sequence }; } // namespace op -} // namepsace arm_compute +} // namespace arm_compute } // namespace internal namespace internal @@ -312,7 +313,7 @@ class Plan op::Sequence _ops; }; -} // namepsace arm_compute +} // namespace arm_compute } // namespace internal #include @@ -331,7 +332,7 @@ bool isGpuMode(); #define CAST_CL(tensor) static_cast<::arm_compute::CLTensor *>(tensor) #define CAST_NE(tensor) static_cast<::arm_compute::Tensor *>(tensor) -} // namepsace arm_compute +} // namespace arm_compute } // namespace internal #endif // __INTERNAL_ARM_COMPUTE_H__ diff --git a/runtime/contrib/pure_arm_compute/src/internal/arm_compute/Cast.h b/runtime/contrib/pure_arm_compute/src/internal/arm_compute/Cast.h index 211a6ac87d9..a407d5fadb5 100644 --- a/runtime/contrib/pure_arm_compute/src/internal/arm_compute/Cast.h +++ b/runtime/contrib/pure_arm_compute/src/internal/arm_compute/Cast.h @@ -49,11 +49,11 @@ ::arm_compute::Coordinates asARMComputeCoordinates(const ::arm_compute::Coordina const ::arm_compute::Coordinates &axises); /** -* @brief Generate arm compute permutation vector from runtime permutation vector -* @param[in] rank Rank number supported upto 4 -* @param[in] runtime_pv Integer array for runtime permutation vector -* @return Permutation vector of arm compute -*/ + * @brief Generate arm compute permutation vector from runtime permutation vector + * @param[in] rank Rank number supported upto 4 + * @param[in] runtime_pv Integer array for runtime permutation vector + * @return Permutation vector of arm compute + */ ::arm_compute::PermutationVector getARMComputePermutationVector(uint32_t rank, const int32_t *runtime_pv); /** diff --git a/runtime/contrib/pure_arm_compute/src/internal/op/Mean.h b/runtime/contrib/pure_arm_compute/src/internal/op/Mean.h index f8e7ed308e1..998ba6693d9 100644 --- a/runtime/contrib/pure_arm_compute/src/internal/op/Mean.h +++ b/runtime/contrib/pure_arm_compute/src/internal/op/Mean.h @@ -51,12 +51,12 @@ struct Param */ Param() = default; /** - * @brief Construct a new Param object with params - * @param[in] inputCount Count of inputs - * @param[in] inputs Pointer of inputs - * @param[in] outputCount Count of outputs - * @param[in] outputs Pointer of outputs - */ + * @brief Construct a new Param object with params + * @param[in] inputCount Count of inputs + * @param[in] inputs Pointer of inputs + * @param[in] outputCount Count of outputs + * @param[in] outputs Pointer of outputs + */ Param(uint32_t inputCount, const uint32_t *inputs, uint32_t outputCount, const uint32_t *outputs); }; diff --git a/runtime/contrib/pure_arm_compute/src/memory.cc b/runtime/contrib/pure_arm_compute/src/memory.cc index 938f60e0b80..6699a00c87c 100644 --- a/runtime/contrib/pure_arm_compute/src/memory.cc +++ b/runtime/contrib/pure_arm_compute/src/memory.cc @@ -18,7 +18,7 @@ #include #include -#include "memory" +#include #include "memory.h" int ANeuralNetworksMemory_createFromFd(size_t size, int protect, int fd, size_t offset, diff --git a/runtime/contrib/pure_arm_compute/src/model.cc b/runtime/contrib/pure_arm_compute/src/model.cc index ddca589dbf7..0ecd838b306 100644 --- a/runtime/contrib/pure_arm_compute/src/model.cc +++ b/runtime/contrib/pure_arm_compute/src/model.cc @@ -188,8 +188,8 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, assert(inputCount == 3); assert(outputCount == 1); - using internal::tflite::op::Add::Param; using internal::tflite::op::Add::Node; + using internal::tflite::op::Add::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -203,8 +203,8 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, assert(inputCount == 3); assert(outputCount == 1); - using internal::tflite::op::Sub::Param; using internal::tflite::op::Sub::Node; + using internal::tflite::op::Sub::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -218,8 +218,8 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, assert(inputCount == 3); assert(outputCount == 1); - using internal::tflite::op::Mul::Param; using internal::tflite::op::Mul::Node; + using internal::tflite::op::Mul::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -233,8 +233,8 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, assert(inputCount == 3); assert(outputCount == 1); - using internal::tflite::op::Div::Param; using internal::tflite::op::Div::Node; + using internal::tflite::op::Div::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -253,8 +253,8 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, if (inputCount == 7) { - using internal::tflite::op::Conv2D::Implicit::Param; using internal::tflite::op::Conv2D::Implicit::Node; + using internal::tflite::op::Conv2D::Implicit::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -263,8 +263,8 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, } else { - using internal::tflite::op::Conv2D::Explicit::Param; using internal::tflite::op::Conv2D::Explicit::Node; + using internal::tflite::op::Conv2D::Explicit::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -284,8 +284,8 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, if (inputCount == 8) { - using internal::tflite::op::DepthwiseConv2D::Implicit::Param; using internal::tflite::op::DepthwiseConv2D::Implicit::Node; + using internal::tflite::op::DepthwiseConv2D::Implicit::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -294,8 +294,8 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, } else { - using internal::tflite::op::DepthwiseConv2D::Explicit::Param; using internal::tflite::op::DepthwiseConv2D::Explicit::Node; + using internal::tflite::op::DepthwiseConv2D::Explicit::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -315,8 +315,8 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, if (inputCount == 7) { - using internal::tflite::op::MaxPool2D::Implicit::Param; using internal::tflite::op::MaxPool2D::Implicit::Node; + using internal::tflite::op::MaxPool2D::Implicit::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -325,8 +325,8 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, } else { - using internal::tflite::op::MaxPool2D::Explicit::Param; using internal::tflite::op::MaxPool2D::Explicit::Node; + using internal::tflite::op::MaxPool2D::Explicit::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -339,8 +339,8 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, case ANEURALNETWORKS_DEQUANTIZE: { assert(outputCount == 1 && inputCount == 1); - using internal::tflite::op::Dequantize::Param; using internal::tflite::op::Dequantize::Node; + using internal::tflite::op::Dequantize::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -359,8 +359,8 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, if (inputCount == 7) { - using internal::tflite::op::AvgPool2D::Implicit::Param; using internal::tflite::op::AvgPool2D::Implicit::Node; + using internal::tflite::op::AvgPool2D::Implicit::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -369,8 +369,8 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, } else { - using internal::tflite::op::AvgPool2D::Explicit::Param; using internal::tflite::op::AvgPool2D::Explicit::Node; + using internal::tflite::op::AvgPool2D::Explicit::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -382,8 +382,8 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, } case ANEURALNETWORKS_CONCATENATION: { - using internal::tflite::op::Concat::Param; using internal::tflite::op::Concat::Node; + using internal::tflite::op::Concat::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -394,8 +394,8 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, } case ANEURALNETWORKS_RESIZE_BILINEAR: { - using internal::tflite::op::ResizeBilinear::Param; using internal::tflite::op::ResizeBilinear::Node; + using internal::tflite::op::ResizeBilinear::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -406,8 +406,8 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, } case ANEURALNETWORKS_RESHAPE: { - using internal::tflite::op::Reshape::Param; using internal::tflite::op::Reshape::Node; + using internal::tflite::op::Reshape::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -418,8 +418,8 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, } case ANEURALNETWORKS_SQUEEZE: { - using internal::tflite::op::Squeeze::Param; using internal::tflite::op::Squeeze::Node; + using internal::tflite::op::Squeeze::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -430,8 +430,8 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, } case ANEURALNETWORKS_FULLY_CONNECTED: { - using internal::tflite::op::FullyConnected::Param; using internal::tflite::op::FullyConnected::Node; + using internal::tflite::op::FullyConnected::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -442,8 +442,8 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, } case ANEURALNETWORKS_SOFTMAX: { - using internal::tflite::op::Softmax::Param; using internal::tflite::op::Softmax::Node; + using internal::tflite::op::Softmax::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -454,8 +454,8 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, } case ANEURALNETWORKS_RELU: { - using internal::tflite::op::ReLU::Param; using internal::tflite::op::ReLU::Node; + using internal::tflite::op::ReLU::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -466,8 +466,8 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, } case ANEURALNETWORKS_RELU1: { - using internal::tflite::op::ReLU1::Param; using internal::tflite::op::ReLU1::Node; + using internal::tflite::op::ReLU1::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -478,8 +478,8 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, } case ANEURALNETWORKS_RELU6: { - using internal::tflite::op::ReLU6::Param; using internal::tflite::op::ReLU6::Node; + using internal::tflite::op::ReLU6::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -490,8 +490,8 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, } case ANEURALNETWORKS_TANH: { - using internal::tflite::op::Tanh::Param; using internal::tflite::op::Tanh::Node; + using internal::tflite::op::Tanh::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -502,8 +502,8 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, } case ANEURALNETWORKS_STRIDED_SLICE: { - using internal::tflite::op::StridedSlice::Param; using internal::tflite::op::StridedSlice::Node; + using internal::tflite::op::StridedSlice::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -514,8 +514,8 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, } case ANEURALNETWORKS_LOGISTIC: { - using internal::tflite::op::Logistic::Param; using internal::tflite::op::Logistic::Node; + using internal::tflite::op::Logistic::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -526,8 +526,8 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, } case ANEURALNETWORKS_MEAN: { - using internal::tflite::op::Mean::Param; using internal::tflite::op::Mean::Node; + using internal::tflite::op::Mean::Param; auto &operations = model->deref().operations(); operations.emplace_back(Param{inputCount, inputs, outputCount, outputs}); @@ -536,8 +536,8 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, } case ANEURALNETWORKS_RNN: { - using internal::tflite::op::RNN::Param; using internal::tflite::op::RNN::Node; + using internal::tflite::op::RNN::Param; auto &operations = model->deref().operations(); @@ -547,8 +547,8 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, } case ANEURALNETWORKS_TRANSPOSE: { - using internal::tflite::op::Transpose::Param; using internal::tflite::op::Transpose::Node; + using internal::tflite::op::Transpose::Param; auto &operations = model->deref().operations(); operations.emplace_back(Param{inputCount, inputs, outputCount, outputs}); @@ -557,8 +557,8 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, } case ANEURALNETWORKS_LSTM: { - using internal::tflite::op::LSTM::Param; using internal::tflite::op::LSTM::Node; + using internal::tflite::op::LSTM::Param; auto &operations = model->deref().operations(); @@ -568,8 +568,8 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, } case ANEURALNETWORKS_FLOOR: { - using internal::tflite::op::Floor::Param; using internal::tflite::op::Floor::Node; + using internal::tflite::op::Floor::Param; auto &operations = model->deref().operations(); @@ -581,8 +581,8 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, { assert(inputCount == 2 && outputCount == 1); - using internal::tflite::op::Pad::Param; using internal::tflite::op::Pad::Node; + using internal::tflite::op::Pad::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -593,8 +593,8 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, } case ANEURALNETWORKS_SPACE_TO_DEPTH: { - using internal::tflite::op::SpaceToDepth::Param; using internal::tflite::op::SpaceToDepth::Node; + using internal::tflite::op::SpaceToDepth::Param; auto &operations = model->deref().operations(); @@ -604,8 +604,8 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, } case ANEURALNETWORKS_SPACE_TO_BATCH_ND: { - using internal::tflite::op::SpaceToBatchND::Param; using internal::tflite::op::SpaceToBatchND::Node; + using internal::tflite::op::SpaceToBatchND::Param; auto &operations = model->deref().operations(); @@ -615,8 +615,8 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, } case ANEURALNETWORKS_BATCH_TO_SPACE_ND: { - using internal::tflite::op::BatchToSpaceNd::Param; using internal::tflite::op::BatchToSpaceNd::Node; + using internal::tflite::op::BatchToSpaceNd::Param; auto &operations = model->deref().operations(); @@ -633,8 +633,8 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, if (inputCount == 7) { - using internal::tflite::op::L2Pool2D::Implicit::Param; using internal::tflite::op::L2Pool2D::Implicit::Node; + using internal::tflite::op::L2Pool2D::Implicit::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -643,8 +643,8 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, } else { - using internal::tflite::op::L2Pool2D::Explicit::Param; using internal::tflite::op::L2Pool2D::Explicit::Node; + using internal::tflite::op::L2Pool2D::Explicit::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -659,8 +659,8 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, assert(inputCount == 2); assert(outputCount == 1); - using internal::tflite::op::EmbeddingLookup::Param; using internal::tflite::op::EmbeddingLookup::Node; + using internal::tflite::op::EmbeddingLookup::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -673,8 +673,8 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, { assert(inputCount == 1 && outputCount == 1); - using internal::tflite::op::L2Normalization::Param; using internal::tflite::op::L2Normalization::Node; + using internal::tflite::op::L2Normalization::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -688,8 +688,8 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, assert(inputCount == 3); assert(outputCount == 2); - using internal::tflite::op::HashtableLookup::Param; using internal::tflite::op::HashtableLookup::Node; + using internal::tflite::op::HashtableLookup::Param; auto &operations = model->deref().operations(); @@ -700,8 +700,8 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, case ANEURALNETWORKS_LOCAL_RESPONSE_NORMALIZATION: { - using internal::tflite::op::LocalResponseNormalization::Param; using internal::tflite::op::LocalResponseNormalization::Node; + using internal::tflite::op::LocalResponseNormalization::Param; auto &operations = model->deref().operations(); @@ -711,8 +711,8 @@ int ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, } case ANEURALNETWORKS_DEPTH_TO_SPACE: { - using internal::tflite::op::DepthToSpace::Param; using internal::tflite::op::DepthToSpace::Node; + using internal::tflite::op::DepthToSpace::Param; auto &operations = model->deref().operations(); @@ -741,8 +741,8 @@ int ANeuralNetworksModel_addOperationEx(ANeuralNetworksModel *model, { case ANEURALNETWORKS_CAST_EX: { - using internal::tflite::op::Cast::Param; using internal::tflite::op::Cast::Node; + using internal::tflite::op::Cast::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -753,8 +753,8 @@ int ANeuralNetworksModel_addOperationEx(ANeuralNetworksModel *model, } case ANEURALNETWORKS_REDUCE_MIN_EX: { - using internal::tflite::op::ReduceMin::Param; using internal::tflite::op::ReduceMin::Node; + using internal::tflite::op::ReduceMin::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -765,8 +765,8 @@ int ANeuralNetworksModel_addOperationEx(ANeuralNetworksModel *model, } case ANEURALNETWORKS_REDUCE_MAX_EX: { - using internal::tflite::op::ReduceMax::Param; using internal::tflite::op::ReduceMax::Node; + using internal::tflite::op::ReduceMax::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -777,8 +777,8 @@ int ANeuralNetworksModel_addOperationEx(ANeuralNetworksModel *model, } case ANEURALNETWORKS_PRELU_EX: { - using internal::tflite::op::PReLU::Param; using internal::tflite::op::PReLU::Node; + using internal::tflite::op::PReLU::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -789,8 +789,8 @@ int ANeuralNetworksModel_addOperationEx(ANeuralNetworksModel *model, } case ANEURALNETWORKS_TRANSPOSE_CONV_EX: { - using internal::tflite::op::TransposeConv::Param; using internal::tflite::op::TransposeConv::Node; + using internal::tflite::op::TransposeConv::Param; auto &operations = model->deref().operations(); @@ -800,8 +800,8 @@ int ANeuralNetworksModel_addOperationEx(ANeuralNetworksModel *model, } case ANEURALNETWORKS_LOGICAL_AND_EX: { - using internal::tflite::op::LogicalAnd::Param; using internal::tflite::op::LogicalAnd::Node; + using internal::tflite::op::LogicalAnd::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -812,8 +812,8 @@ int ANeuralNetworksModel_addOperationEx(ANeuralNetworksModel *model, } case ANEURALNETWORKS_LOGICAL_OR_EX: { - using internal::tflite::op::LogicalOr::Param; using internal::tflite::op::LogicalOr::Node; + using internal::tflite::op::LogicalOr::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -824,8 +824,8 @@ int ANeuralNetworksModel_addOperationEx(ANeuralNetworksModel *model, } case ANEURALNETWORKS_LOGICAL_NOT_EX: { - using internal::tflite::op::LogicalNot::Param; using internal::tflite::op::LogicalNot::Node; + using internal::tflite::op::LogicalNot::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -836,8 +836,8 @@ int ANeuralNetworksModel_addOperationEx(ANeuralNetworksModel *model, } case ANEURALNETWORKS_RSQRT_EX: { - using internal::tflite::op::RSQRT::Param; using internal::tflite::op::RSQRT::Node; + using internal::tflite::op::RSQRT::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -848,8 +848,8 @@ int ANeuralNetworksModel_addOperationEx(ANeuralNetworksModel *model, } case ANEURALNETWORKS_SQRT_EX: { - using internal::tflite::op::SQRT::Param; using internal::tflite::op::SQRT::Node; + using internal::tflite::op::SQRT::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -860,8 +860,8 @@ int ANeuralNetworksModel_addOperationEx(ANeuralNetworksModel *model, } case ANEURALNETWORKS_EQUAL_EX: { - using internal::tflite::op::Equal::Param; using internal::tflite::op::Equal::Node; + using internal::tflite::op::Equal::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -872,8 +872,8 @@ int ANeuralNetworksModel_addOperationEx(ANeuralNetworksModel *model, } case ANEURALNETWORKS_SQUARED_DIFFERENCE_EX: { - using internal::tflite::op::SquaredDifference::Param; using internal::tflite::op::SquaredDifference::Node; + using internal::tflite::op::SquaredDifference::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -884,8 +884,8 @@ int ANeuralNetworksModel_addOperationEx(ANeuralNetworksModel *model, } case ANEURALNETWORKS_TOPK_V2_EX: { - using internal::tflite::op::TopKV2::Param; using internal::tflite::op::TopKV2::Node; + using internal::tflite::op::TopKV2::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -896,8 +896,8 @@ int ANeuralNetworksModel_addOperationEx(ANeuralNetworksModel *model, } case ANEURALNETWORKS_GATHER_EX: { - using internal::tflite::op::Gather::Param; using internal::tflite::op::Gather::Node; + using internal::tflite::op::Gather::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -908,8 +908,8 @@ int ANeuralNetworksModel_addOperationEx(ANeuralNetworksModel *model, } case ANEURALNETWORKS_SPLIT_EX: { - using internal::tflite::op::Split::Param; using internal::tflite::op::Split::Node; + using internal::tflite::op::Split::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -920,8 +920,8 @@ int ANeuralNetworksModel_addOperationEx(ANeuralNetworksModel *model, } case ANEURALNETWORKS_UNPACK_EX: { - using internal::tflite::op::Unpack::Param; using internal::tflite::op::Unpack::Node; + using internal::tflite::op::Unpack::Param; auto &operations = model->deref().operations(); @@ -931,8 +931,8 @@ int ANeuralNetworksModel_addOperationEx(ANeuralNetworksModel *model, } case ANEURALNETWORKS_NEG_EX: { - using internal::tflite::op::Neg::Param; using internal::tflite::op::Neg::Node; + using internal::tflite::op::Neg::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -943,8 +943,8 @@ int ANeuralNetworksModel_addOperationEx(ANeuralNetworksModel *model, } case ANEURALNETWORKS_EXP_EX: { - using internal::tflite::op::Exp::Param; using internal::tflite::op::Exp::Node; + using internal::tflite::op::Exp::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -955,8 +955,8 @@ int ANeuralNetworksModel_addOperationEx(ANeuralNetworksModel *model, } case ANEURALNETWORKS_REDUCE_SUM_EX: { - using internal::tflite::op::ReduceSum::Param; using internal::tflite::op::ReduceSum::Node; + using internal::tflite::op::ReduceSum::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -967,8 +967,8 @@ int ANeuralNetworksModel_addOperationEx(ANeuralNetworksModel *model, } case ANEURALNETWORKS_PACK_EX: { - using internal::tflite::op::Pack::Param; using internal::tflite::op::Pack::Node; + using internal::tflite::op::Pack::Param; auto &operations = model->deref().operations(); @@ -978,8 +978,8 @@ int ANeuralNetworksModel_addOperationEx(ANeuralNetworksModel *model, } case ANEURALNETWORKS_ABS_EX: { - using internal::tflite::op::Abs::Param; using internal::tflite::op::Abs::Node; + using internal::tflite::op::Abs::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -990,8 +990,8 @@ int ANeuralNetworksModel_addOperationEx(ANeuralNetworksModel *model, } case ANEURALNETWORKS_ARGMAX_EX: { - using internal::tflite::op::ArgMax::Param; using internal::tflite::op::ArgMax::Node; + using internal::tflite::op::ArgMax::Param; // Add 'operations' auto &operations = model->deref().operations(); @@ -1002,8 +1002,8 @@ int ANeuralNetworksModel_addOperationEx(ANeuralNetworksModel *model, } case ANEURALNETWORKS_NOT_EQUAL_EX: { - using internal::tflite::op::NotEqual::Param; using internal::tflite::op::NotEqual::Node; + using internal::tflite::op::NotEqual::Param; // Add 'operations' auto &operations = model->deref().operations(); diff --git a/runtime/contrib/style_transfer_app/CMakeLists.txt b/runtime/contrib/style_transfer_app/CMakeLists.txt index b61ad750850..4896e6710f4 100644 --- a/runtime/contrib/style_transfer_app/CMakeLists.txt +++ b/runtime/contrib/style_transfer_app/CMakeLists.txt @@ -2,9 +2,9 @@ if(NOT BUILD_STYLE_TRANSFER_APP) return() endif(NOT BUILD_STYLE_TRANSFER_APP) -if(NOT BUILD_NEURUN) +if(NOT BUILD_ONERT) return() -endif(NOT BUILD_NEURUN) +endif(NOT BUILD_ONERT) find_package(JPEG) if(JPEG_FOUND) @@ -29,7 +29,7 @@ if(JPEG_FOUND) target_include_directories(style_transfer_app PRIVATE ${JPEG_INCLUDE_DIRS}) endif(JPEG_FOUND) -target_link_libraries(style_transfer_app neurun_core neurun tflite_loader) +target_link_libraries(style_transfer_app onert_core onert tflite_loader) target_link_libraries(style_transfer_app tensorflow-lite ${LIB_PTHREAD} dl nnfw_lib_tflite) target_link_libraries(style_transfer_app nnfw-dev) target_link_libraries(style_transfer_app boost_program_options boost_system boost_filesystem) diff --git a/runtime/libs/benchmark/include/benchmark/Result.h b/runtime/libs/benchmark/include/benchmark/Result.h index 570fa21144d..2d86d95ec93 100644 --- a/runtime/libs/benchmark/include/benchmark/Result.h +++ b/runtime/libs/benchmark/include/benchmark/Result.h @@ -39,7 +39,7 @@ uint32_t maxMemory(const std::unordered_map &map) return answer.second; } -} // namespace anonymous +} // namespace namespace benchmark { diff --git a/runtime/libs/benchmark/src/CsvWriter.cpp b/runtime/libs/benchmark/src/CsvWriter.cpp index c7563ac7c7f..5f47c65114f 100644 --- a/runtime/libs/benchmark/src/CsvWriter.cpp +++ b/runtime/libs/benchmark/src/CsvWriter.cpp @@ -24,7 +24,7 @@ const std::vector csv_header{ #include "benchmark/CsvHeader.lst" }; -} // namespace anonymous +} // namespace namespace benchmark { diff --git a/runtime/libs/benchmark/src/MemoryPoller.cpp b/runtime/libs/benchmark/src/MemoryPoller.cpp index 436d536e416..95fc34bb24d 100644 --- a/runtime/libs/benchmark/src/MemoryPoller.cpp +++ b/runtime/libs/benchmark/src/MemoryPoller.cpp @@ -82,7 +82,7 @@ std::vector getValueFromFileStatus(const std::string &file, const s return val; } -} // namespace anonymous +} // namespace namespace benchmark { diff --git a/runtime/libs/misc/CMakeLists.txt b/runtime/libs/misc/CMakeLists.txt index 557d403ecd4..5efa300f8af 100644 --- a/runtime/libs/misc/CMakeLists.txt +++ b/runtime/libs/misc/CMakeLists.txt @@ -7,5 +7,11 @@ set_target_properties(nnfw_lib_misc PROPERTIES POSITION_INDEPENDENT_CODE ON) target_link_libraries(nnfw_lib_misc PRIVATE nnfw_common) target_link_libraries(nnfw_lib_misc PRIVATE nnfw_coverage) +install(TARGETS nnfw_lib_misc ARCHIVE DESTINATION lib) +install(DIRECTORY "include/misc" + DESTINATION "include/onert" # FIXME This is only for onert developers + FILES_MATCHING PATTERN "*.h" + ) + add_executable(nnfw_tensor_index_iterator "examples/tensor_index_iterator.cpp") target_link_libraries(nnfw_tensor_index_iterator nnfw_lib_misc) diff --git a/runtime/libs/misc/examples/tensor_index_iterator.cpp b/runtime/libs/misc/examples/tensor_index_iterator.cpp index d94da9f494c..590b433df89 100644 --- a/runtime/libs/misc/examples/tensor_index_iterator.cpp +++ b/runtime/libs/misc/examples/tensor_index_iterator.cpp @@ -31,8 +31,8 @@ void test_iterate(void) array.fill(0); - using nnfw::misc::tensor::iterate; using nnfw::misc::tensor::Index; + using nnfw::misc::tensor::iterate; iterate(shape) << [&](const Index &index) { assert(index.rank() == shape.rank()); diff --git a/runtime/libs/misc/include/misc/string_helpers.h b/runtime/libs/misc/include/misc/string_helpers.h index e42a127549f..6aac3a83be7 100644 --- a/runtime/libs/misc/include/misc/string_helpers.h +++ b/runtime/libs/misc/include/misc/string_helpers.h @@ -36,7 +36,7 @@ template void _str(std::ostream &os, Arg &&arg, _str(os, std::forward(args)...); } -} // namespace {anonymous} +} // namespace namespace nnfw { diff --git a/runtime/libs/profiling/include/profiling/profiling.h b/runtime/libs/profiling/include/profiling/profiling.h index ee0df13388e..79ad060c584 100644 --- a/runtime/libs/profiling/include/profiling/profiling.h +++ b/runtime/libs/profiling/include/profiling/profiling.h @@ -25,7 +25,7 @@ namespace profiling { class Profiler; // forward declaration } -} +} // namespace tflite namespace profiling { diff --git a/runtime/libs/rua/dyn/include/rua/DynamicBinder.h b/runtime/libs/rua/dyn/include/rua/DynamicBinder.h index 8ce0c42f858..1e2d3066541 100644 --- a/runtime/libs/rua/dyn/include/rua/DynamicBinder.h +++ b/runtime/libs/rua/dyn/include/rua/DynamicBinder.h @@ -30,6 +30,6 @@ struct DynamicBinder static const rua::RuntimeService *get(void); }; -} // namespace +} // namespace rua #endif // __NNFW_RUA_DYNAMIC_BINDER_H__ diff --git a/runtime/libs/tflite/CMakeLists.txt b/runtime/libs/tflite/CMakeLists.txt index b5a16bcd969..04ced8e0f55 100644 --- a/runtime/libs/tflite/CMakeLists.txt +++ b/runtime/libs/tflite/CMakeLists.txt @@ -1,3 +1,9 @@ +nnfw_find_package(TensorFlowLite QUIET) +if(NOT TensorFlowLite_FOUND) + message(STATUS "Check tensorflow lite library extension build: need tensorflow lite library") + return() +endif(NOT TensorFlowLite_FOUND) + add_subdirectory(port) file(GLOB_RECURSE SOURCES "src/*.cpp") @@ -13,5 +19,9 @@ target_link_libraries(nnfw_lib_tflite PRIVATE ${LIB_PTHREAD} dl) target_link_libraries(nnfw_lib_tflite PRIVATE nnfw_common) target_link_libraries(nnfw_lib_tflite PRIVATE nnfw_coverage) +if(NOT ENABLE_TEST) + return() +endif(NOT ENABLE_TEST) + add_executable(nnfw_lib_tflite_test_TensorView src/TensorView.test.cpp) target_link_libraries(nnfw_lib_tflite_test_TensorView nnfw_lib_tflite) diff --git a/runtime/libs/tflite/port/1.13.1/CMakeLists.txt b/runtime/libs/tflite/port/1.13.1/CMakeLists.txt index 311e11cae64..e3cf9756953 100644 --- a/runtime/libs/tflite/port/1.13.1/CMakeLists.txt +++ b/runtime/libs/tflite/port/1.13.1/CMakeLists.txt @@ -2,8 +2,6 @@ if(NOT SUPPORT_TFLITE_VERSION VERSION_EQUAL 1.13.1) return() endif(NOT SUPPORT_TFLITE_VERSION VERSION_EQUAL 1.13.1) -nnfw_find_package(TensorFlowLite REQUIRED) - file(GLOB_RECURSE SOURCES "src/*.cpp") add_library(tensorflow-lite-ex STATIC ${SOURCES}) diff --git a/runtime/libs/tflite/port/1.13.1/src/nnapi_delegate.cpp b/runtime/libs/tflite/port/1.13.1/src/nnapi_delegate.cpp index 908a05ca8b2..38890951fb1 100644 --- a/runtime/libs/tflite/port/1.13.1/src/nnapi_delegate.cpp +++ b/runtime/libs/tflite/port/1.13.1/src/nnapi_delegate.cpp @@ -855,6 +855,10 @@ TfLiteStatus AddOpsAndParams( augmented_inputs.data(), static_cast(node.outputs->size), reinterpret_cast(node.outputs->data))); continue; // _EX operator should use `continue` to skip addOperanation. + case tflite::BuiltinOperator_SIN: + nnapi_version = 12; // require NNAPI 1.2 + nn_op_type = ANEURALNETWORKS_SIN; + break; case tflite::BuiltinOperator_CONCAT_EMBEDDINGS: case tflite::BuiltinOperator_LSH_PROJECTION: case tflite::BuiltinOperator_BIDIRECTIONAL_SEQUENCE_RNN: @@ -892,7 +896,7 @@ TfLiteStatus AddOpsAndParams( //case tflite::BuiltinOperator_NEG: case tflite::BuiltinOperator_SELECT: // case tflite::BuiltinOperator_SLICE: - case tflite::BuiltinOperator_SIN: + //case tflite::BuiltinOperator_SIN: case tflite::BuiltinOperator_LOG: //case tflite::BuiltinOperator_TRANSPOSE_CONV: case tflite::BuiltinOperator_TILE: diff --git a/runtime/libs/tflite/port/1.13.1/src/nnapi_delegate_ex_AddOpsAndParams_lambda.inc b/runtime/libs/tflite/port/1.13.1/src/nnapi_delegate_ex_AddOpsAndParams_lambda.inc index 8b5e6ef7b20..ee758105fd1 100644 --- a/runtime/libs/tflite/port/1.13.1/src/nnapi_delegate_ex_AddOpsAndParams_lambda.inc +++ b/runtime/libs/tflite/port/1.13.1/src/nnapi_delegate_ex_AddOpsAndParams_lambda.inc @@ -148,7 +148,7 @@ }; auto add_one_hot_tensor_inputs_as_scalar = [subgraph, &node, &augmented_inputs, - &add_scalar_int32, &add_scalar_float32]() { + &add_scalar_float32]() { assert(augmented_inputs.size() == 4); const auto on_value_idx = node.inputs->data[2]; const auto off_value_idx = node.inputs->data[3]; diff --git a/runtime/libs/tflite/src/Diff.cpp b/runtime/libs/tflite/src/Diff.cpp index 67aec335dd2..9e66bbb5db7 100644 --- a/runtime/libs/tflite/src/Diff.cpp +++ b/runtime/libs/tflite/src/Diff.cpp @@ -86,8 +86,8 @@ bool TfLiteInterpMatchApp::compareSingleTensorView(const nnfw::tflite::TensorVie std::vector> diffs; assert(expected.shape() == obtained.shape()); - using nnfw::misc::tensor::zip; using nnfw::misc::tensor::Index; + using nnfw::misc::tensor::zip; zip(expected.shape(), expected, obtained) << [&](const Index &index, T expected_value, T obtained_value) { diff --git a/runtime/neurun/api/CMakeLists.txt b/runtime/neurun/api/CMakeLists.txt deleted file mode 100644 index c3f7702ad20..00000000000 --- a/runtime/neurun/api/CMakeLists.txt +++ /dev/null @@ -1,21 +0,0 @@ -file(GLOB_RECURSE API_SRC "*.cc") - -set(NEURUN_DEV nnfw-dev) -add_library(${NEURUN_DEV} SHARED ${API_SRC}) - -# Public headers to publish -# nnfw_debug.h is header for runtime developer, so it will not be installed -# But runtime developer can use nnfw_debug.h by linking nnfw-dev -set(NNFW_API_HEADERS include/nnfw.h include/nnfw_dev.h) - -target_link_libraries(${NEURUN_DEV} PUBLIC nnfw-nnapi-header) -target_link_libraries(${NEURUN_DEV} PRIVATE neurun_core) -target_link_libraries(${NEURUN_DEV} PRIVATE jsoncpp tflite_loader circle_loader ${LIB_PTHREAD}) -target_link_libraries(${NEURUN_DEV} PRIVATE nnfw_common) -target_link_libraries(${NEURUN_DEV} PRIVATE nnfw_coverage) -target_include_directories(${NEURUN_DEV} PUBLIC include) -set_target_properties(${NEURUN_DEV} PROPERTIES PUBLIC_HEADER "${NNFW_API_HEADERS}") - -install(TARGETS ${NEURUN_DEV} - LIBRARY DESTINATION lib - PUBLIC_HEADER DESTINATION include/nnfw) diff --git a/runtime/neurun/backend/acl_cl/CMakeLists.txt b/runtime/neurun/backend/acl_cl/CMakeLists.txt deleted file mode 100644 index da6a4bf5b3f..00000000000 --- a/runtime/neurun/backend/acl_cl/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -# Unsupported architecture -nnas_find_package(ARMCompute QUIET) -if(NOT ARMCompute_FOUND) - return() -endif(NOT ARMCompute_FOUND) - -set(LIB_NEURUN_BACKEND_ACL_CL neurun_backend_acl_cl) - -file(GLOB_RECURSE SOURCES "*.cc") - -add_library(${LIB_NEURUN_BACKEND_ACL_CL} SHARED ${SOURCES}) - -target_link_libraries(${LIB_NEURUN_BACKEND_ACL_CL} PRIVATE ${LIB_NEURUN_BACKEND_ACL_COMMON}) -target_link_libraries(${LIB_NEURUN_BACKEND_ACL_CL} PRIVATE nnfw_common) -target_link_libraries(${LIB_NEURUN_BACKEND_ACL_CL} PRIVATE nnfw_coverage) - -set_target_properties(${LIB_NEURUN_BACKEND_ACL_CL} PROPERTIES OUTPUT_NAME backend_acl_cl) - -install(TARGETS ${LIB_NEURUN_BACKEND_ACL_CL} DESTINATION lib) diff --git a/runtime/neurun/backend/acl_common/CMakeLists.txt b/runtime/neurun/backend/acl_common/CMakeLists.txt deleted file mode 100644 index 440448568d0..00000000000 --- a/runtime/neurun/backend/acl_common/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -# Unsupported architecture -nnas_find_package(ARMCompute QUIET) -if(NOT ARMCompute_FOUND) - return() -endif(NOT ARMCompute_FOUND) - -file(GLOB SOURCES "*.cc") - -add_library(${LIB_NEURUN_BACKEND_ACL_COMMON} STATIC ${SOURCES}) - -target_include_directories(${LIB_NEURUN_BACKEND_ACL_COMMON} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) -target_link_libraries(${LIB_NEURUN_BACKEND_ACL_COMMON} PUBLIC neurun_core) -target_link_libraries(${LIB_NEURUN_BACKEND_ACL_COMMON} PUBLIC arm_compute arm_compute_ex) -target_link_libraries(${LIB_NEURUN_BACKEND_ACL_COMMON} PUBLIC nnfw_lib_misc) -target_link_libraries(${LIB_NEURUN_BACKEND_ACL_COMMON} PRIVATE nnfw_common) -target_link_libraries(${LIB_NEURUN_BACKEND_ACL_COMMON} PRIVATE nnfw_coverage) - -set_target_properties(${LIB_NEURUN_BACKEND_ACL_COMMON} PROPERTIES POSITION_INDEPENDENT_CODE ON) -set_target_properties(${LIB_NEURUN_BACKEND_ACL_COMMON} PROPERTIES OUTPUT_NAME backend_acl_common) diff --git a/runtime/neurun/backend/acl_neon/CMakeLists.txt b/runtime/neurun/backend/acl_neon/CMakeLists.txt deleted file mode 100644 index be07c7e2b1a..00000000000 --- a/runtime/neurun/backend/acl_neon/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -# Unsupported architecture -nnas_find_package(ARMCompute QUIET) -if(NOT ARMCompute_FOUND) - return() -endif(NOT ARMCompute_FOUND) - -set(LIB_NEURUN_BACKEND_ACL_NEON neurun_backend_acl_neon) - -file(GLOB_RECURSE SOURCES "*.cc") - -add_library(${LIB_NEURUN_BACKEND_ACL_NEON} SHARED ${SOURCES}) - -target_link_libraries(${LIB_NEURUN_BACKEND_ACL_NEON} PRIVATE ${LIB_NEURUN_BACKEND_ACL_COMMON}) -target_link_libraries(${LIB_NEURUN_BACKEND_ACL_NEON} PRIVATE nnfw_common) -target_link_libraries(${LIB_NEURUN_BACKEND_ACL_NEON} PRIVATE nnfw_coverage) - -set_target_properties(${LIB_NEURUN_BACKEND_ACL_NEON} PROPERTIES OUTPUT_NAME backend_acl_neon) - -install(TARGETS ${LIB_NEURUN_BACKEND_ACL_NEON} DESTINATION lib) diff --git a/runtime/neurun/backend/cpu/CMakeLists.txt b/runtime/neurun/backend/cpu/CMakeLists.txt deleted file mode 100644 index ab8af49f773..00000000000 --- a/runtime/neurun/backend/cpu/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -set(LIB_NEURUN_BACKEND_CPU neurun_backend_cpu) - -file(GLOB_RECURSE SOURCES "*.cc") - -add_library(${LIB_NEURUN_BACKEND_CPU} SHARED ${SOURCES}) - -target_link_libraries(${LIB_NEURUN_BACKEND_CPU} PRIVATE nnfw_lib_misc nnfw_lib_cker) -target_link_libraries(${LIB_NEURUN_BACKEND_CPU} PRIVATE ${LIB_NEURUN_BACKEND_CPU_COMMON}) -target_link_libraries(${LIB_NEURUN_BACKEND_CPU} PRIVATE nnfw_common) -target_link_libraries(${LIB_NEURUN_BACKEND_CPU} PRIVATE nnfw_coverage) - -set_target_properties(${LIB_NEURUN_BACKEND_CPU} PROPERTIES OUTPUT_NAME backend_cpu) - -install(TARGETS ${LIB_NEURUN_BACKEND_CPU} DESTINATION lib) diff --git a/runtime/neurun/backend/cpu_common/CMakeLists.txt b/runtime/neurun/backend/cpu_common/CMakeLists.txt deleted file mode 100644 index 07a9b6c2dfa..00000000000 --- a/runtime/neurun/backend/cpu_common/CMakeLists.txt +++ /dev/null @@ -1,29 +0,0 @@ -file(GLOB SOURCES "*.cc") -file(GLOB_RECURSE TESTS "*.test.cc") -list(REMOVE_ITEM SOURCES ${TESTS}) - -add_library(${LIB_NEURUN_BACKEND_CPU_COMMON} STATIC ${SOURCES}) - -target_include_directories(${LIB_NEURUN_BACKEND_CPU_COMMON} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) -target_link_libraries(${LIB_NEURUN_BACKEND_CPU_COMMON} PUBLIC neurun_core) -target_link_libraries(${LIB_NEURUN_BACKEND_CPU_COMMON} PRIVATE nnfw_lib_misc) -target_link_libraries(${LIB_NEURUN_BACKEND_CPU_COMMON} PRIVATE nnfw_common) -target_link_libraries(${LIB_NEURUN_BACKEND_CPU_COMMON} PRIVATE nnfw_coverage) - -set_target_properties(${LIB_NEURUN_BACKEND_CPU_COMMON} PROPERTIES POSITION_INDEPENDENT_CODE ON) -set_target_properties(${LIB_NEURUN_BACKEND_CPU_COMMON} PROPERTIES OUTPUT_NAME backend_cpu_common) - -if(NOT ENABLE_TEST) - return() -endif(NOT ENABLE_TEST) - -# Unit Tests -set(TEST_NEURUN_BACKEND_CPU_COMMON test_neurun_backend_cpu_common) - -add_executable(${TEST_NEURUN_BACKEND_CPU_COMMON} ${TESTS}) - -target_link_libraries(${TEST_NEURUN_BACKEND_CPU_COMMON} ${LIB_NEURUN_BACKEND_CPU_COMMON}) -target_link_libraries(${TEST_NEURUN_BACKEND_CPU_COMMON} gtest gtest_main dl ${LIB_PTHREAD}) - -add_test(${TEST_NEURUN_BACKEND_CPU_COMMON} ${TEST_NEURUN_BACKEND_CPU_COMMON}) -install(TARGETS ${TEST_NEURUN_BACKEND_CPU_COMMON} DESTINATION unittest) diff --git a/runtime/neurun/core/CMakeLists.txt b/runtime/neurun/core/CMakeLists.txt deleted file mode 100644 index 1b43b664776..00000000000 --- a/runtime/neurun/core/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -file(GLOB_RECURSE SOURCES "src/*.cc") - -add_library(neurun_core SHARED ${SOURCES}) -set_target_properties(neurun_core PROPERTIES POSITION_INDEPENDENT_CODE ON) -target_include_directories(neurun_core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) -target_include_directories(neurun_core PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src) -target_link_libraries(neurun_core PUBLIC nnfw_lib_misc) -target_link_libraries(neurun_core PRIVATE nnfw_lib_cker) -target_link_libraries(neurun_core PRIVATE nnfw_common) -target_link_libraries(neurun_core PRIVATE nnfw_coverage) -target_link_libraries(neurun_core PRIVATE dl ${LIB_PTHREAD}) - -if(ENVVAR_NEURUN_CONFIG) - target_compile_definitions(neurun_core PRIVATE ENVVAR_FOR_DEFAULT_CONFIG) -endif(ENVVAR_NEURUN_CONFIG) - -install(TARGETS neurun_core DESTINATION lib) diff --git a/runtime/neurun/frontend/nnapi/CMakeLists.txt b/runtime/neurun/frontend/nnapi/CMakeLists.txt deleted file mode 100644 index ecc9524b17d..00000000000 --- a/runtime/neurun/frontend/nnapi/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -file(GLOB_RECURSE SOURCES_FRONTEND "*.cc") -file(GLOB_RECURSE TESTS_FRONTEND "*.test.cc") -list(REMOVE_ITEM SOURCES_FRONTEND ${TESTS_FRONTEND}) - -set(LIB_NEURUN neurun) - -add_library(${LIB_NEURUN} SHARED ${SOURCES_FRONTEND}) -target_link_libraries(${LIB_NEURUN} PUBLIC nnfw-nnapi-header) -target_link_libraries(${LIB_NEURUN} PUBLIC neurun_core) # TODO Link PRIVATE neurun_core -target_link_libraries(${LIB_NEURUN} PRIVATE nnfw_common) -target_link_libraries(${LIB_NEURUN} PRIVATE nnfw_coverage) - -set_target_properties(${LIB_NEURUN} PROPERTIES OUTPUT_NAME neuralnetworks) - -install(TARGETS ${LIB_NEURUN} DESTINATION lib) - -if(NOT ENABLE_TEST) - return() -endif(NOT ENABLE_TEST) - -add_executable(test_neurun_frontend_nnapi ${TESTS_FRONTEND}) - -target_link_libraries(test_neurun_frontend_nnapi PRIVATE ${LIB_NEURUN} dl) -target_link_libraries(test_neurun_frontend_nnapi PRIVATE gtest) -target_link_libraries(test_neurun_frontend_nnapi PRIVATE gtest_main) - -install(TARGETS test_neurun_frontend_nnapi DESTINATION unittest) diff --git a/runtime/neurun/test/CMakeLists.txt b/runtime/neurun/test/CMakeLists.txt deleted file mode 100644 index 81517393771..00000000000 --- a/runtime/neurun/test/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -set(TEST_NEURUN test_neurun) - -file(GLOB_RECURSE TESTS "*.cc") - -add_executable(${TEST_NEURUN} ${TESTS}) - -target_include_directories(${TEST_NEURUN} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../core/src) - -target_link_libraries(${TEST_NEURUN} neurun_core) -target_link_libraries(${TEST_NEURUN} gtest) -target_link_libraries(${TEST_NEURUN} gtest_main) -target_link_libraries(${TEST_NEURUN} ${LIB_PTHREAD} dl) -add_test(${TEST_NEURUN} ${TEST_NEURUN}) - -install(TARGETS ${TEST_NEURUN} DESTINATION unittest) diff --git a/runtime/nnapi-header/include/NeuralNetworksEx.h b/runtime/nnapi-header/include/NeuralNetworksEx.h index 87597b75f46..cff89eee48a 100644 --- a/runtime/nnapi-header/include/NeuralNetworksEx.h +++ b/runtime/nnapi-header/include/NeuralNetworksEx.h @@ -268,7 +268,7 @@ typedef enum { * ANEURALNETWORKS_NOT_EQUAL_EX operation is DEPRECATED * Use ANEURALNETWORKS_NOT_EQUAL instead * - */ + */ ANEURALNETWORKS_NOT_EQUAL_EX = 50017, /** diff --git a/runtime/neurun/CMakeLists.txt b/runtime/onert/CMakeLists.txt similarity index 82% rename from runtime/neurun/CMakeLists.txt rename to runtime/onert/CMakeLists.txt index f0134050ce8..88d52a5bd3e 100644 --- a/runtime/neurun/CMakeLists.txt +++ b/runtime/onert/CMakeLists.txt @@ -1,6 +1,6 @@ -if(NOT BUILD_NEURUN) +if(NOT BUILD_ONERT) return() -endif(NOT BUILD_NEURUN) +endif(NOT BUILD_ONERT) add_subdirectory(backend) add_subdirectory(frontend) diff --git a/runtime/onert/api/CMakeLists.txt b/runtime/onert/api/CMakeLists.txt new file mode 100644 index 00000000000..3132646c4df --- /dev/null +++ b/runtime/onert/api/CMakeLists.txt @@ -0,0 +1,21 @@ +file(GLOB_RECURSE API_SRC "*.cc") + +set(ONERT_DEV nnfw-dev) +add_library(${ONERT_DEV} SHARED ${API_SRC}) + +# Public headers to publish +# nnfw_debug.h is header for runtime developer, so it will not be installed +# But runtime developer can use nnfw_debug.h by linking nnfw-dev +set(NNFW_API_HEADERS include/nnfw.h include/nnfw_dev.h) + +target_link_libraries(${ONERT_DEV} PUBLIC nnfw-nnapi-header) +target_link_libraries(${ONERT_DEV} PRIVATE onert_core) +target_link_libraries(${ONERT_DEV} PRIVATE jsoncpp tflite_loader circle_loader ${LIB_PTHREAD}) +target_link_libraries(${ONERT_DEV} PRIVATE nnfw_common) +target_link_libraries(${ONERT_DEV} PRIVATE nnfw_coverage) +target_include_directories(${ONERT_DEV} PUBLIC include) +set_target_properties(${ONERT_DEV} PROPERTIES PUBLIC_HEADER "${NNFW_API_HEADERS}") + +install(TARGETS ${ONERT_DEV} + LIBRARY DESTINATION lib + PUBLIC_HEADER DESTINATION include/nnfw) diff --git a/runtime/neurun/api/include/nnfw.h b/runtime/onert/api/include/nnfw.h similarity index 99% rename from runtime/neurun/api/include/nnfw.h rename to runtime/onert/api/include/nnfw.h index 7bf28a76e1d..7d9fc048ff1 100644 --- a/runtime/neurun/api/include/nnfw.h +++ b/runtime/onert/api/include/nnfw.h @@ -374,8 +374,8 @@ NNFW_STATUS nnfw_set_available_backends(nnfw_session *session, const char *backe * *

Supported backends differs on each platforms. * For example, `x86_64` supports "cpu" only. - * The backend for op has higher priority than default backend specified by - * nnfw_set_default_backend.

+ * The backend for op has higher priority than available backends specified by + * nnfw_set_available_backends.

* * @note Possible backend strings are: "cpu", "acl_cl", "acl_neon" * diff --git a/runtime/neurun/api/include/nnfw_debug.h b/runtime/onert/api/include/nnfw_debug.h similarity index 89% rename from runtime/neurun/api/include/nnfw_debug.h rename to runtime/onert/api/include/nnfw_debug.h index eefca0d2950..fe335ec4e7e 100644 --- a/runtime/neurun/api/include/nnfw_debug.h +++ b/runtime/onert/api/include/nnfw_debug.h @@ -21,4 +21,6 @@ NNFW_STATUS nnfw_create_debug_session(nnfw_session **session); +NNFW_STATUS nnfw_set_config(nnfw_session *session, const char *key, const char *value); + #endif // __NNFW_DEBUG_H__ diff --git a/runtime/neurun/api/include/nnfw_dev.h b/runtime/onert/api/include/nnfw_dev.h similarity index 100% rename from runtime/neurun/api/include/nnfw_dev.h rename to runtime/onert/api/include/nnfw_dev.h diff --git a/runtime/neurun/api/include/nnfw_version.h b/runtime/onert/api/include/nnfw_version.h similarity index 100% rename from runtime/neurun/api/include/nnfw_version.h rename to runtime/onert/api/include/nnfw_version.h diff --git a/runtime/neurun/api/src/CustomKernel.cc b/runtime/onert/api/src/CustomKernel.cc similarity index 97% rename from runtime/neurun/api/src/CustomKernel.cc rename to runtime/onert/api/src/CustomKernel.cc index 60ddeedc2d1..a383dfe9c5e 100644 --- a/runtime/neurun/api/src/CustomKernel.cc +++ b/runtime/onert/api/src/CustomKernel.cc @@ -16,7 +16,7 @@ #include "CustomKernel.h" -namespace neurun +namespace onert { namespace frontend { @@ -94,5 +94,5 @@ void Kernel::configure(CustomKernelConfigParams &&inParams) void Kernel::run() { _evalFunction(&_params, _userdata, _userdata_size); } } // namespace custom -} // namespace backend -} // namespace neurun +} // namespace frontend +} // namespace onert diff --git a/runtime/neurun/api/src/CustomKernel.h b/runtime/onert/api/src/CustomKernel.h similarity index 86% rename from runtime/neurun/api/src/CustomKernel.h rename to runtime/onert/api/src/CustomKernel.h index 105ce554b49..2acf5979ea7 100644 --- a/runtime/neurun/api/src/CustomKernel.h +++ b/runtime/onert/api/src/CustomKernel.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_CUSTOM_KERNEL_H__ -#define __NEURUN_BACKEND_CUSTOM_KERNEL_H__ +#ifndef __ONERT_BACKEND_CUSTOM_KERNEL_H__ +#define __ONERT_BACKEND_CUSTOM_KERNEL_H__ #include "nnfw_dev.h" @@ -24,14 +24,14 @@ #include -namespace neurun +namespace onert { namespace frontend { namespace custom { -class Kernel : public ::neurun::exec::IFunction +class Kernel : public ::onert::exec::IFunction { public: explicit Kernel(nnfw_custom_eval evalFunction); @@ -55,6 +55,6 @@ class Kernel : public ::neurun::exec::IFunction } // namespace custom } // namespace frontend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_CUSTOM_KERNEL_H__ +#endif // __ONERT_BACKEND_CUSTOM_KERNEL_H__ diff --git a/runtime/neurun/api/src/CustomKernelRegistry.cc b/runtime/onert/api/src/CustomKernelRegistry.cc similarity index 96% rename from runtime/neurun/api/src/CustomKernelRegistry.cc rename to runtime/onert/api/src/CustomKernelRegistry.cc index 3f363c688c9..7812609d153 100644 --- a/runtime/neurun/api/src/CustomKernelRegistry.cc +++ b/runtime/onert/api/src/CustomKernelRegistry.cc @@ -16,9 +16,9 @@ #include "CustomKernelRegistry.h" -#include "memory" +#include -namespace neurun +namespace onert { namespace frontend { @@ -61,4 +61,4 @@ KernelBuilder::KernelBuilder(KernelRegistry *registry) : _registry(registry) {} } // namespace custom } // namespace frontend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/api/src/CustomKernelRegistry.h b/runtime/onert/api/src/CustomKernelRegistry.h similarity index 88% rename from runtime/neurun/api/src/CustomKernelRegistry.h rename to runtime/onert/api/src/CustomKernelRegistry.h index 207a82a0ace..fe60d5bcc36 100644 --- a/runtime/neurun/api/src/CustomKernelRegistry.h +++ b/runtime/onert/api/src/CustomKernelRegistry.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_CUSTOM_KERNEL_REGISTRY_H__ -#define __NEURUN_BACKEND_CUSTOM_KERNEL_REGISTRY_H__ +#ifndef __ONERT_BACKEND_CUSTOM_KERNEL_REGISTRY_H__ +#define __ONERT_BACKEND_CUSTOM_KERNEL_REGISTRY_H__ #include "CustomKernel.h" @@ -25,7 +25,7 @@ #include -namespace neurun +namespace onert { namespace frontend { @@ -59,6 +59,6 @@ class KernelBuilder : public backend::custom::IKernelBuilder } // namespace custom } // namespace frontend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_CUSTOM_KERNEL_REGISTRY_H__ +#endif // __ONERT_BACKEND_CUSTOM_KERNEL_REGISTRY_H__ diff --git a/runtime/neurun/api/src/OpMap.lst b/runtime/onert/api/src/OpMap.lst similarity index 98% rename from runtime/neurun/api/src/OpMap.lst rename to runtime/onert/api/src/OpMap.lst index 5e93275b8a8..a3d1b25eab4 100644 --- a/runtime/neurun/api/src/OpMap.lst +++ b/runtime/onert/api/src/OpMap.lst @@ -18,7 +18,7 @@ #error Define MAP_MACRO before including this file #endif -// circle operation | neurun internal operation +// circle operation | onert internal operation MAP_MACRO(ADD , Add) MAP_MACRO(SUB , Sub) MAP_MACRO(BATCH_TO_SPACE_ND , BatchToSpaceND) diff --git a/runtime/neurun/api/src/nnfw_api.cc b/runtime/onert/api/src/nnfw_api.cc similarity index 98% rename from runtime/neurun/api/src/nnfw_api.cc rename to runtime/onert/api/src/nnfw_api.cc index f5ffa9caa27..7e6792ff3e2 100644 --- a/runtime/neurun/api/src/nnfw_api.cc +++ b/runtime/onert/api/src/nnfw_api.cc @@ -25,6 +25,9 @@ */ NNFW_STATUS nnfw_create_session(nnfw_session **session) { + if (session == nullptr) + return NNFW_STATUS_ERROR; + *session = new nnfw_session(); return NNFW_STATUS_NO_ERROR; @@ -95,7 +98,7 @@ NNFW_STATUS nnfw_run(nnfw_session *session) * @param index index of input to be set (0-indexed) * @param type type of the input * @param buffer raw buffer for input - * @param length size of bytes of output + * @param length size of bytes of input * * @return NNFW_STATUS_NO_ERROR if successful */ diff --git a/runtime/neurun/api/src/nnfw_api_internal.cc b/runtime/onert/api/src/nnfw_api_internal.cc similarity index 82% rename from runtime/neurun/api/src/nnfw_api_internal.cc rename to runtime/onert/api/src/nnfw_api_internal.cc index c683aee9166..0a428cc1931 100644 --- a/runtime/neurun/api/src/nnfw_api_internal.cc +++ b/runtime/onert/api/src/nnfw_api_internal.cc @@ -17,6 +17,7 @@ #include "nnfw_api_internal.h" #include "CustomKernelRegistry.h" #include "compiler/Compiler.h" +#include "util/ConfigSource.h" #include "exec/Execution.h" #include "circle_loader.h" #include "tflite_loader.h" @@ -46,27 +47,29 @@ static bool null_terminating(const char *str, uint32_t length) return false; } -static neurun::ir::Layout convertLayout(NNFW_LAYOUT layout) +static onert::ir::Layout convertLayout(NNFW_LAYOUT layout) { if (layout == NNFW_LAYOUT_CHANNELS_LAST) { - return neurun::ir::Layout::NHWC; + return onert::ir::Layout::NHWC; } else if (layout == NNFW_LAYOUT_CHANNELS_FIRST) { - return neurun::ir::Layout::NCHW; + return onert::ir::Layout::NCHW; } - return neurun::ir::Layout::UNKNOWN; + return onert::ir::Layout::UNKNOWN; } nnfw_session::nnfw_session() : _graph{nullptr}, _execution{nullptr}, - _kernel_registry{std::make_shared()}, - _source{std::make_unique()} + _kernel_registry{std::make_shared()}, + _source{std::make_unique()} { // DO NOTHING } +nnfw_session::~nnfw_session() = default; + NNFW_STATUS nnfw_session::load_model_from_file(const char *package_dir) { // TODO : add support for zipped package file load @@ -95,11 +98,11 @@ NNFW_STATUS nnfw_session::load_model_from_file(const char *package_dir) auto model_type = model_types[0].asString(); // first model's type if (model_type == "tflite") { - _graph = neurun::tflite_loader::loadModel(model_file_path.c_str()); + _graph = onert::tflite_loader::loadModel(model_file_path.c_str()); } else if (model_type == "circle") { - _graph = neurun::circle_loader::loadModel(model_file_path.c_str()); + _graph = onert::circle_loader::loadModel(model_file_path.c_str()); } else { @@ -113,6 +116,9 @@ NNFW_STATUS nnfw_session::load_model_from_file(const char *package_dir) std::cerr << "Error during model loading : " << e.what() << std::endl; return NNFW_STATUS_ERROR; } + + _compiler = std::make_unique(_graph); + return NNFW_STATUS_NO_ERROR; } @@ -141,14 +147,13 @@ NNFW_STATUS nnfw_session::prepare() try { // config_source setting - using neurun::util::config_source; + using onert::util::config_source; config_source(std::move(_source)); - auto compiler = std::make_unique(_graph); - compiler->compile(); - std::shared_ptr executor; - compiler->release(executor); - _execution = std::make_shared(executor); + _compiler->compile(); + std::shared_ptr executor; + _compiler->release(executor); + _execution = std::make_shared(executor); } catch (const std::exception &e) { @@ -185,7 +190,7 @@ NNFW_STATUS nnfw_session::set_input(uint32_t index, NNFW_TYPE /*type*/, const vo { try { - _execution->setInput(neurun::ir::IOIndex(index), buffer, length); + _execution->setInput(onert::ir::IOIndex(index), buffer, length); } catch (const std::exception &e) { @@ -200,7 +205,7 @@ NNFW_STATUS nnfw_session::set_output(uint32_t index, NNFW_TYPE /*type*/, void *b { try { - _execution->setOutput(neurun::ir::IOIndex(index), buffer, length); + _execution->setOutput(onert::ir::IOIndex(index), buffer, length); } catch (const std::exception &e) { @@ -258,7 +263,7 @@ NNFW_STATUS nnfw_session::set_input_layout(uint32_t index, NNFW_LAYOUT layout) std::cerr << "Error during nnfw_session::set_input_layout, not supported layout" << std::endl; return NNFW_STATUS_ERROR; } - _execution->setInputLayout(neurun::ir::IOIndex(index), convertLayout(layout)); + _execution->setInputLayout(onert::ir::IOIndex(index), convertLayout(layout)); } catch (const std::exception &e) { @@ -279,7 +284,7 @@ NNFW_STATUS nnfw_session::set_output_layout(uint32_t index, NNFW_LAYOUT layout) << std::endl; return NNFW_STATUS_ERROR; } - _execution->setOutputLayout(neurun::ir::IOIndex(index), convertLayout(layout)); + _execution->setOutputLayout(onert::ir::IOIndex(index), convertLayout(layout)); } catch (const std::exception &e) { @@ -289,9 +294,9 @@ NNFW_STATUS nnfw_session::set_output_layout(uint32_t index, NNFW_LAYOUT layout) return NNFW_STATUS_NO_ERROR; } -static NNFW_TYPE datatype_to_nnfw_dtype(neurun::ir::DataType dt) +static NNFW_TYPE datatype_to_nnfw_dtype(onert::ir::DataType dt) { - using neurun::ir::DataType; + using onert::ir::DataType; switch (dt) { case DataType::FLOAT32: @@ -392,7 +397,7 @@ NNFW_STATUS nnfw_session::register_custom_operation(const std::string &id, static std::string get_op_backend_string(std::string op) { -#define MAP_MACRO(CircleName, NeurunName) {#CircleName, "OP_BACKEND_" #NeurunName}, +#define MAP_MACRO(CircleName, OneRTName) {#CircleName, "OP_BACKEND_" #OneRTName}, static std::unordered_map operation_map = { #include "OpMap.lst" @@ -458,3 +463,56 @@ NNFW_STATUS nnfw_session::set_op_backend(const char *op, const char *backend) } return NNFW_STATUS_NO_ERROR; } + +NNFW_STATUS nnfw_session::set_config(const char *key, const char *value) +{ + // The session must be in the state after model load + if (!_compiler) + return NNFW_STATUS_ERROR; + + auto &options = _compiler->options(); + + using namespace onert::util; + + if (key == config::TRACE_FILEPATH) + { + options.trace_filepath = value; + } + else if (key == config::GRAPH_DOT_DUMP) + { + options.graph_dump_level = toInt(value); + } + else if (key == config::OP_SEQ_MAX_NODE) + { + options.op_seq_max_node = toInt(value); + } + else if (key == config::EXECUTOR) + { + options.executor = value; + } + else if (key == config::OP_BACKEND_ALLOPS) + { + options.manual_scheduler_options.backend_for_all = value; + } + else if (key == config::USE_SCHEDULER) + { + options.he_scheduler = toBool(value); + } + else if (key == config::PROFILING_MODE) + { + options.he_profiling_mode = toBool(value); + } + else if (key == config::DELETE_CACHED_DATA) + { + options.delete_cached_data = toBool(value); + } + else if (key == config::DISABLE_COMPILE) + { + options.disable_compile = toBool(value); + } + else + { + return NNFW_STATUS_ERROR; + } + return NNFW_STATUS_NO_ERROR; +} diff --git a/runtime/neurun/api/src/nnfw_api_internal.h b/runtime/onert/api/src/nnfw_api_internal.h similarity index 81% rename from runtime/neurun/api/src/nnfw_api_internal.h rename to runtime/onert/api/src/nnfw_api_internal.h index ac8b1df0972..5fe4f382956 100644 --- a/runtime/neurun/api/src/nnfw_api_internal.h +++ b/runtime/onert/api/src/nnfw_api_internal.h @@ -25,7 +25,7 @@ #include #include -namespace neurun +namespace onert { namespace frontend { @@ -42,12 +42,17 @@ namespace ir { class Graph; } // namespace ir -} // namespace neurun +namespace compiler +{ +class Compiler; +} // namespace compiler +} // namespace onert struct nnfw_session { public: nnfw_session(); + ~nnfw_session(); NNFW_STATUS load_model_from_file(const char *package_file_path); NNFW_STATUS prepare(); @@ -72,13 +77,16 @@ struct nnfw_session NNFW_STATUS set_available_backends(const char *backends); NNFW_STATUS set_op_backend(const char *op, const char *backend); + NNFW_STATUS set_config(const char *key, const char *value); + private: - std::shared_ptr _graph; - std::shared_ptr _execution; - std::shared_ptr _kernel_registry; + std::shared_ptr _graph; + std::unique_ptr _compiler; + std::shared_ptr _execution; + std::shared_ptr _kernel_registry; protected: - std::unique_ptr _source; + std::unique_ptr _source; }; #endif // __API_NNFW_API_INTERNAL_H__ diff --git a/runtime/neurun/api/src/nnfw_debug.cc b/runtime/onert/api/src/nnfw_debug.cc similarity index 85% rename from runtime/neurun/api/src/nnfw_debug.cc rename to runtime/onert/api/src/nnfw_debug.cc index 4ea0a203f09..73d0e9c8639 100644 --- a/runtime/neurun/api/src/nnfw_debug.cc +++ b/runtime/onert/api/src/nnfw_debug.cc @@ -22,3 +22,8 @@ NNFW_STATUS nnfw_create_debug_session(nnfw_session **session) return NNFW_STATUS_NO_ERROR; } + +NNFW_STATUS nnfw_set_config(nnfw_session *session, const char *key, const char *value) +{ + return session->set_config(key, value); +} diff --git a/runtime/neurun/api/src/nnfw_debug_internal.cc b/runtime/onert/api/src/nnfw_debug_internal.cc similarity index 92% rename from runtime/neurun/api/src/nnfw_debug_internal.cc rename to runtime/onert/api/src/nnfw_debug_internal.cc index c7c56876c93..4fddfc93d7c 100644 --- a/runtime/neurun/api/src/nnfw_debug_internal.cc +++ b/runtime/onert/api/src/nnfw_debug_internal.cc @@ -21,5 +21,5 @@ nnfw_debug_session::nnfw_debug_session() : nnfw_session() { - _source = std::make_unique(); + _source = std::make_unique(); } diff --git a/runtime/neurun/api/src/nnfw_debug_internal.h b/runtime/onert/api/src/nnfw_debug_internal.h similarity index 100% rename from runtime/neurun/api/src/nnfw_debug_internal.h rename to runtime/onert/api/src/nnfw_debug_internal.h diff --git a/runtime/neurun/backend/CMakeLists.txt b/runtime/onert/backend/CMakeLists.txt similarity index 52% rename from runtime/neurun/backend/CMakeLists.txt rename to runtime/onert/backend/CMakeLists.txt index 941a231a877..7310571d85a 100644 --- a/runtime/neurun/backend/CMakeLists.txt +++ b/runtime/onert/backend/CMakeLists.txt @@ -1,5 +1,5 @@ -set(LIB_NEURUN_BACKEND_ACL_COMMON neurun_backend_acl_common) -set(LIB_NEURUN_BACKEND_CPU_COMMON neurun_backend_cpu_common) +set(LIB_ONERT_BACKEND_ACL_COMMON onert_backend_acl_common) +set(LIB_ONERT_BACKEND_CPU_COMMON onert_backend_cpu_common) add_subdirectory(cpu) add_subdirectory(cpu_common) diff --git a/runtime/neurun/backend/acl_cl/Backend.h b/runtime/onert/backend/acl_cl/Backend.h similarity index 87% rename from runtime/neurun/backend/acl_cl/Backend.h rename to runtime/onert/backend/acl_cl/Backend.h index 4c766d9aebd..fabcae38e73 100644 --- a/runtime/neurun/backend/acl_cl/Backend.h +++ b/runtime/onert/backend/acl_cl/Backend.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_ACL_CL_BACKEND_H__ -#define __NEURUN_BACKEND_ACL_CL_BACKEND_H__ +#ifndef __ONERT_BACKEND_ACL_CL_BACKEND_H__ +#define __ONERT_BACKEND_ACL_CL_BACKEND_H__ #include #include @@ -27,14 +27,14 @@ #include "TensorManager.h" #include "Optimizer.h" -namespace neurun +namespace onert { namespace backend { namespace acl_cl { -class Backend : public ::neurun::backend::Backend +class Backend : public ::onert::backend::Backend { public: Backend() : _config{std::make_shared()} {} @@ -53,7 +53,7 @@ class Backend : public ::neurun::backend::Backend context->kernel_gen = std::make_shared(operands, tb); context->shape_fixer = std::make_shared(operands, tb); context->tensor_register = nullptr; - context->optimizer = nullptr; + context->optimizer = std::make_shared(context.get()); return context; } @@ -63,6 +63,6 @@ class Backend : public ::neurun::backend::Backend } // namespace acl_cl } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_ACL_CL_BACKEND_H__ +#endif // __ONERT_BACKEND_ACL_CL_BACKEND_H__ diff --git a/runtime/neurun/backend/acl_cl/CLTimer.h b/runtime/onert/backend/acl_cl/CLTimer.h similarity index 95% rename from runtime/neurun/backend/acl_cl/CLTimer.h rename to runtime/onert/backend/acl_cl/CLTimer.h index 3939ee722e8..722dc68efc1 100644 --- a/runtime/neurun/backend/acl_cl/CLTimer.h +++ b/runtime/onert/backend/acl_cl/CLTimer.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_ACL_CL_CLTIMER_H__ -#define __NEURUN_BACKEND_ACL_CL_CLTIMER_H__ +#ifndef __ONERT_BACKEND_ACL_CL_CLTIMER_H__ +#define __ONERT_BACKEND_ACL_CL_CLTIMER_H__ #include #include @@ -24,7 +24,7 @@ #include #include -namespace neurun +namespace onert { namespace backend { @@ -103,6 +103,6 @@ class CLTimer : public util::ITimer } // namespace acl_cl } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_ACL_CL_CLTIMER_H__ +#endif // __ONERT_BACKEND_ACL_CL_CLTIMER_H__ diff --git a/runtime/onert/backend/acl_cl/CMakeLists.txt b/runtime/onert/backend/acl_cl/CMakeLists.txt new file mode 100644 index 00000000000..3b56dca8197 --- /dev/null +++ b/runtime/onert/backend/acl_cl/CMakeLists.txt @@ -0,0 +1,19 @@ +# Unsupported architecture +nnas_find_package(ARMCompute QUIET) +if(NOT ARMCompute_FOUND) + return() +endif(NOT ARMCompute_FOUND) + +set(LIB_ONERT_BACKEND_ACL_CL onert_backend_acl_cl) + +file(GLOB_RECURSE SOURCES "*.cc") + +add_library(${LIB_ONERT_BACKEND_ACL_CL} SHARED ${SOURCES}) + +target_link_libraries(${LIB_ONERT_BACKEND_ACL_CL} PRIVATE ${LIB_ONERT_BACKEND_ACL_COMMON}) +target_link_libraries(${LIB_ONERT_BACKEND_ACL_CL} PRIVATE nnfw_common) +target_link_libraries(${LIB_ONERT_BACKEND_ACL_CL} PRIVATE nnfw_coverage) + +set_target_properties(${LIB_ONERT_BACKEND_ACL_CL} PROPERTIES OUTPUT_NAME backend_acl_cl) + +install(TARGETS ${LIB_ONERT_BACKEND_ACL_CL} DESTINATION lib) diff --git a/runtime/neurun/backend/acl_cl/Config.cc b/runtime/onert/backend/acl_cl/Config.cc similarity index 97% rename from runtime/neurun/backend/acl_cl/Config.cc rename to runtime/onert/backend/acl_cl/Config.cc index 36bf83686e0..1cc3cb401c1 100644 --- a/runtime/neurun/backend/acl_cl/Config.cc +++ b/runtime/onert/backend/acl_cl/Config.cc @@ -23,7 +23,7 @@ #include "Config.h" -namespace neurun +namespace onert { namespace backend { @@ -47,4 +47,4 @@ bool Config::initialize() } // namespace acl_cl } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/acl_cl/Config.h b/runtime/onert/backend/acl_cl/Config.h similarity index 86% rename from runtime/neurun/backend/acl_cl/Config.h rename to runtime/onert/backend/acl_cl/Config.h index fc07a7398f7..a64c7923e70 100644 --- a/runtime/neurun/backend/acl_cl/Config.h +++ b/runtime/onert/backend/acl_cl/Config.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_ACL_CL_CONFIG_H__ -#define __NEURUN_BACKEND_ACL_CL_CONFIG_H__ +#ifndef __ONERT_BACKEND_ACL_CL_CONFIG_H__ +#define __ONERT_BACKEND_ACL_CL_CONFIG_H__ #include "CLTimer.h" #include #include -namespace neurun +namespace onert { namespace backend { @@ -39,6 +39,6 @@ class Config : public IConfig } // namespace acl_cl } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_ACL_CL_CONFIG_H__ +#endif // __ONERT_BACKEND_ACL_CL_CONFIG_H__ diff --git a/runtime/neurun/backend/acl_cl/ConstantInitializer.cc b/runtime/onert/backend/acl_cl/ConstantInitializer.cc similarity index 99% rename from runtime/neurun/backend/acl_cl/ConstantInitializer.cc rename to runtime/onert/backend/acl_cl/ConstantInitializer.cc index 7f134c01233..d7f5f8031d8 100644 --- a/runtime/neurun/backend/acl_cl/ConstantInitializer.cc +++ b/runtime/onert/backend/acl_cl/ConstantInitializer.cc @@ -16,7 +16,7 @@ #include "ConstantInitializer.h" -namespace neurun +namespace onert { namespace backend { @@ -193,4 +193,4 @@ void ConstantInitializer::visit(const ir::operation::TransposeConv &node) } // namespace acl_cl } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/acl_cl/ConstantInitializer.h b/runtime/onert/backend/acl_cl/ConstantInitializer.h similarity index 90% rename from runtime/neurun/backend/acl_cl/ConstantInitializer.h rename to runtime/onert/backend/acl_cl/ConstantInitializer.h index c766633a6d3..c51f72b1199 100644 --- a/runtime/neurun/backend/acl_cl/ConstantInitializer.h +++ b/runtime/onert/backend/acl_cl/ConstantInitializer.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_COMPILER_ACL_CL_CONSTANT_INITIALIZER_H__ -#define __NEURUN_COMPILER_ACL_CL_CONSTANT_INITIALIZER_H__ +#ifndef __ONERT_COMPILER_ACL_CL_CONSTANT_INITIALIZER_H__ +#define __ONERT_COMPILER_ACL_CL_CONSTANT_INITIALIZER_H__ #include #include #include "TensorBuilder.h" -namespace neurun +namespace onert { namespace backend { @@ -58,6 +58,6 @@ class ConstantInitializer : public IConstantInitializer } // namespace acl_cl } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_COMPILER_ACL_CL_CONSTANT_INITIALIZER_H__ +#endif // __ONERT_COMPILER_ACL_CL_CONSTANT_INITIALIZER_H__ diff --git a/runtime/neurun/backend/acl_cl/KernelGenerator.cc b/runtime/onert/backend/acl_cl/KernelGenerator.cc similarity index 98% rename from runtime/neurun/backend/acl_cl/KernelGenerator.cc rename to runtime/onert/backend/acl_cl/KernelGenerator.cc index 9c7bf163169..25588fea7a4 100644 --- a/runtime/neurun/backend/acl_cl/KernelGenerator.cc +++ b/runtime/onert/backend/acl_cl/KernelGenerator.cc @@ -32,15 +32,15 @@ #include "util/logging.h" #include "util/Utils.h" -namespace neurun +namespace onert { namespace backend { namespace acl_cl { -using ::neurun::backend::acl_common::asAclClFunction; -using ActivationBuilder = ::neurun::backend::acl_common::AclActivationBuilder< +using ::onert::backend::acl_common::asAclClFunction; +using ActivationBuilder = ::onert::backend::acl_common::AclActivationBuilder< ::arm_compute::ICLTensor, ::arm_compute::CLActivationLayer, acl_common::AclClFunction>; KernelGenerator::KernelGenerator(const ir::Operands &ctx, @@ -385,8 +385,8 @@ void KernelGenerator::visit(const ir::operation::FullyConnected &node) fn->configure( input_alloc->handle(), weight_alloc->handle(), bias_alloc->handle(), output_alloc->handle(), needs_reshape, - ::neurun::backend::acl_common::asTensorShape( - reshape, frontend_layout, ::neurun::backend::acl_common::asRuntimeLayout(acl_layout)), + ::onert::backend::acl_common::asTensorShape( + reshape, frontend_layout, ::onert::backend::acl_common::asRuntimeLayout(acl_layout)), kernel_type); _return_fn = std::make_unique( @@ -575,8 +575,8 @@ void KernelGenerator::visit(const ir::operation::Slice &node) assert(beginData_base != nullptr); for (int n = 0; n < input_rank; ++n) { - auto axis = ::neurun::backend::acl_common::ToARMComputeAxis(input_rank, n, frontend_layout, - backend_layout) + auto axis = ::onert::backend::acl_common::ToARMComputeAxis(input_rank, n, frontend_layout, + backend_layout) .value(); int32_t begin_value = *(reinterpret_cast(beginData_base) + n); @@ -653,8 +653,8 @@ void KernelGenerator::visit(const ir::operation::StridedSlice &node) assert(startData_base != nullptr); for (int n = 0; n < input_rank; ++n) { - auto axis = ::neurun::backend::acl_common::ToARMComputeAxis(input_rank, n, frontend_layout, - backend_layout) + auto axis = ::onert::backend::acl_common::ToARMComputeAxis(input_rank, n, frontend_layout, + backend_layout) .value(); int32_t start_value = *(reinterpret_cast(startData_base) + n); @@ -712,7 +712,7 @@ void KernelGenerator::visit(const ir::operation::Transpose &node) std::vector pv(perm.cbegin(), perm.cend()); // Reversed - auto backend_pv = ::neurun::backend::acl_common::getARMComputePermutationVector( + auto backend_pv = ::onert::backend::acl_common::getARMComputePermutationVector( rank, pv, frontend_layout, backend_layout); auto fn = std::make_unique<::arm_compute::CLPermute>(); @@ -971,7 +971,7 @@ void KernelGenerator::visit(const ir::operation::LSTM &node) auto output_state_in_alloc = _tensor_builder->at(output_state_in_index).get(); auto cell_state_in_alloc = _tensor_builder->at(cell_state_in_index).get(); - auto act_info = ::neurun::backend::acl_common::asActivationLayerInfo(activation); + auto act_info = ::onert::backend::acl_common::asActivationLayerInfo(activation); auto fn = std::make_unique<::arm_compute::CLLSTMLayer>(); @@ -1275,7 +1275,7 @@ void KernelGenerator::visit(const ir::operation::RNN &node) auto recurrent_weights_alloc = _tensor_builder->at(recurrent_weights_index).get(); auto bias_alloc = _tensor_builder->at(bias_index).get(); auto hidden_state_in_alloc = _tensor_builder->at(hidden_state_in_index).get(); - auto act_info = ::neurun::backend::acl_common::asActivationLayerInfo(activation); + auto act_info = ::onert::backend::acl_common::asActivationLayerInfo(activation); auto copy_layer = std::make_unique<::arm_compute::CLCopy>(); copy_layer->configure(hidden_state_in_alloc->handle(), hidden_state_out_alloc->handle()); @@ -1384,7 +1384,7 @@ void KernelGenerator::visit(const ir::operation::L2Pool2D &node) ::arm_compute::PoolingLayerInfo info{ ::arm_compute::PoolingType::L2, ::arm_compute::Size2D{kw, kh}, - ::neurun::backend::acl_common::asPadStrideInfo(padding, stride)}; + ::onert::backend::acl_common::asPadStrideInfo(padding, stride)}; auto fn = std::make_unique<::arm_compute::CLPoolingLayer>(); @@ -1495,8 +1495,6 @@ void KernelGenerator::visit(const ir::operation::PReLU &node) void KernelGenerator::visit(const ir::operation::TransposeConv &node) { const auto ofm_index{node.getOutputs().at(0)}; - const auto output_shape_index{ - node.getInputs().at(ir::operation::TransposeConv::Input::OUTPUT_SHAPE)}; const auto ker_index{node.getInputs().at(ir::operation::TransposeConv::Input::KERNEL)}; const auto ifm_index{node.getInputs().at(ir::operation::TransposeConv::Input::INPUT)}; @@ -1651,7 +1649,7 @@ void KernelGenerator::visit(const ir::operation::Gather &node) const auto ifm_rank = node.param().rank; const auto axis_raw = node.param().axis; const auto axis_value = (axis_raw < 0 ? (ifm_rank + axis_raw) : axis_raw); - const int axis = ::neurun::backend::acl_common::ToARMComputeAxis(ifm_rank, axis_value).value(); + const int axis = ::onert::backend::acl_common::ToARMComputeAxis(ifm_rank, axis_value).value(); auto ofm_alloc = _tensor_builder->at(ofm_index).get(); auto ifm_alloc = _tensor_builder->at(ifm_index).get(); @@ -2022,4 +2020,4 @@ void KernelGenerator::visit(const ir::operation::Max &node) } // namespace acl_cl } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/acl_cl/KernelGenerator.h b/runtime/onert/backend/acl_cl/KernelGenerator.h similarity index 95% rename from runtime/neurun/backend/acl_cl/KernelGenerator.h rename to runtime/onert/backend/acl_cl/KernelGenerator.h index d5b2c41c63d..c7e1a217859 100644 --- a/runtime/neurun/backend/acl_cl/KernelGenerator.h +++ b/runtime/onert/backend/acl_cl/KernelGenerator.h @@ -14,15 +14,15 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_ACL_CL_KERNEL_GENERATOR_H__ -#define __NEURUN_BACKEND_ACL_CL_KERNEL_GENERATOR_H__ +#ifndef __ONERT_BACKEND_ACL_CL_KERNEL_GENERATOR_H__ +#define __ONERT_BACKEND_ACL_CL_KERNEL_GENERATOR_H__ #include #include "ir/Operands.h" #include "TensorBuilder.h" -namespace neurun +namespace onert { namespace backend { @@ -107,6 +107,6 @@ class KernelGenerator : public IKernelGenerator } // namespace acl_cl } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_ACL_CL_KERNEL_GENERATOR_H__ +#endif // __ONERT_BACKEND_ACL_CL_KERNEL_GENERATOR_H__ diff --git a/runtime/neurun/backend/acl_cl/Optimizer.cc b/runtime/onert/backend/acl_cl/Optimizer.cc similarity index 95% rename from runtime/neurun/backend/acl_cl/Optimizer.cc rename to runtime/onert/backend/acl_cl/Optimizer.cc index 506444c7526..6ba3143e8df 100644 --- a/runtime/neurun/backend/acl_cl/Optimizer.cc +++ b/runtime/onert/backend/acl_cl/Optimizer.cc @@ -23,7 +23,7 @@ #include #include "AclSubTensorAnalyzer.h" -namespace neurun +namespace onert { namespace backend { @@ -45,6 +45,7 @@ void Optimizer::optimize() for (auto op_info : _context->operation_list()) { auto &op = _context->graph()->operations().at(op_info.index); + sa.setLayout(op_info.layout); op.accept(sa); } @@ -54,4 +55,4 @@ void Optimizer::optimize() } // namespace acl_cl } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/acl_cl/Optimizer.h b/runtime/onert/backend/acl_cl/Optimizer.h similarity index 85% rename from runtime/neurun/backend/acl_cl/Optimizer.h rename to runtime/onert/backend/acl_cl/Optimizer.h index fc41c89f0bc..18d38ec1bcb 100644 --- a/runtime/neurun/backend/acl_cl/Optimizer.h +++ b/runtime/onert/backend/acl_cl/Optimizer.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_ACL_CL_OPTIMIZER_H__ -#define __NEURUN_BACKEND_ACL_CL_OPTIMIZER_H__ +#ifndef __ONERT_BACKEND_ACL_CL_OPTIMIZER_H__ +#define __ONERT_BACKEND_ACL_CL_OPTIMIZER_H__ #include #include #include "TensorBuilder.h" -namespace neurun +namespace onert { namespace backend { @@ -42,6 +42,6 @@ class Optimizer : public IOptimizer } // namespace acl_cl } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_ACL_CL_OPTIMIZER_H__ +#endif // __ONERT_BACKEND_ACL_CL_OPTIMIZER_H__ diff --git a/runtime/neurun/backend/acl_cl/ShapeFixer.cc b/runtime/onert/backend/acl_cl/ShapeFixer.cc similarity index 99% rename from runtime/neurun/backend/acl_cl/ShapeFixer.cc rename to runtime/onert/backend/acl_cl/ShapeFixer.cc index db433e13e44..d73cf151db3 100644 --- a/runtime/neurun/backend/acl_cl/ShapeFixer.cc +++ b/runtime/onert/backend/acl_cl/ShapeFixer.cc @@ -28,14 +28,14 @@ #include "util/logging.h" #include "util/Utils.h" -namespace neurun +namespace onert { namespace backend { namespace acl_cl { -using ::neurun::backend::acl_common::asAclFunction; +using ::onert::backend::acl_common::asAclFunction; ShapeFixer::ShapeFixer(const ir::Operands &ctx, const std::shared_ptr &tensor_builder) @@ -428,4 +428,4 @@ void ShapeFixer::visit(const ir::operation::Max &node) } // namespace acl_cl } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/acl_cl/ShapeFixer.h b/runtime/onert/backend/acl_cl/ShapeFixer.h similarity index 96% rename from runtime/neurun/backend/acl_cl/ShapeFixer.h rename to runtime/onert/backend/acl_cl/ShapeFixer.h index ec5f5c896ef..5b3e9b24897 100644 --- a/runtime/neurun/backend/acl_cl/ShapeFixer.h +++ b/runtime/onert/backend/acl_cl/ShapeFixer.h @@ -14,15 +14,15 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_ACL_CL_SHAPE_FIXER_H__ -#define __NEURUN_BACKEND_ACL_CL_SHAPE_FIXER_H__ +#ifndef __ONERT_BACKEND_ACL_CL_SHAPE_FIXER_H__ +#define __ONERT_BACKEND_ACL_CL_SHAPE_FIXER_H__ #include #include "ir/Operands.h" #include "TensorBuilder.h" -namespace neurun +namespace onert { namespace backend { @@ -105,6 +105,6 @@ class ShapeFixer : public IShapeFixer } // namespace acl_cl } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_ACL_CL_SHAPE_FIXER_H__ +#endif // __ONERT_BACKEND_ACL_CL_SHAPE_FIXER_H__ diff --git a/runtime/neurun/backend/acl_cl/TensorBuilder.h b/runtime/onert/backend/acl_cl/TensorBuilder.h similarity index 82% rename from runtime/neurun/backend/acl_cl/TensorBuilder.h rename to runtime/onert/backend/acl_cl/TensorBuilder.h index de1ec626b07..91502d39a3d 100644 --- a/runtime/neurun/backend/acl_cl/TensorBuilder.h +++ b/runtime/onert/backend/acl_cl/TensorBuilder.h @@ -14,15 +14,15 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_ACL_CL_TENSOR_BUILDER_H__ -#define __NEURUN_BACKEND_ACL_CL_TENSOR_BUILDER_H__ +#ifndef __ONERT_BACKEND_ACL_CL_TENSOR_BUILDER_H__ +#define __ONERT_BACKEND_ACL_CL_TENSOR_BUILDER_H__ #include #include "operand/CLTensor.h" #include "operand/CLSubTensor.h" -namespace neurun +namespace onert { namespace backend { @@ -34,6 +34,6 @@ using TensorBuilder = } // namespace acl_cl } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_ACL_CL_TENSOR_BUILDER_H__ +#endif // __ONERT_BACKEND_ACL_CL_TENSOR_BUILDER_H__ diff --git a/runtime/neurun/backend/acl_cl/TensorManager.h b/runtime/onert/backend/acl_cl/TensorManager.h similarity index 92% rename from runtime/neurun/backend/acl_cl/TensorManager.h rename to runtime/onert/backend/acl_cl/TensorManager.h index 711f5477d9b..bdbd0364ef4 100644 --- a/runtime/neurun/backend/acl_cl/TensorManager.h +++ b/runtime/onert/backend/acl_cl/TensorManager.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_ACL_CL_TENSOR_MANAGER_H__ -#define __NEURUN_BACKEND_ACL_CL_TENSOR_MANAGER_H__ +#ifndef __ONERT_BACKEND_ACL_CL_TENSOR_MANAGER_H__ +#define __ONERT_BACKEND_ACL_CL_TENSOR_MANAGER_H__ #include #include @@ -33,7 +33,7 @@ #include "util/logging.h" -namespace neurun +namespace onert { namespace backend { @@ -73,6 +73,6 @@ TensorManager *createTensorManager(bool is_linear_executor) } // namespace acl_cl } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_ACL_CL_TENSOR_MANAGER_H__ +#endif // __ONERT_BACKEND_ACL_CL_TENSOR_MANAGER_H__ diff --git a/runtime/neurun/backend/acl_cl/acl_cl.cc b/runtime/onert/backend/acl_cl/acl_cl.cc similarity index 72% rename from runtime/neurun/backend/acl_cl/acl_cl.cc rename to runtime/onert/backend/acl_cl/acl_cl.cc index ac3f0acff30..88378b13a0c 100644 --- a/runtime/neurun/backend/acl_cl/acl_cl.cc +++ b/runtime/onert/backend/acl_cl/acl_cl.cc @@ -19,15 +19,15 @@ #include "Backend.h" extern "C" { -neurun::backend::Backend *neurun_backend_create() +onert::backend::Backend *onert_backend_create() { - VERBOSE(neurun_backend_create) << "'acl_cl' loaded\n"; - return new neurun::backend::acl_cl::Backend; + VERBOSE(onert_backend_create) << "'acl_cl' loaded\n"; + return new onert::backend::acl_cl::Backend; } -void neurun_backend_destroy(neurun::backend::Backend *backend) +void onert_backend_destroy(onert::backend::Backend *backend) { - VERBOSE(neurun_backend_create) << "'acl_cl' unloaded\n"; + VERBOSE(onert_backend_create) << "'acl_cl' unloaded\n"; delete backend; } } diff --git a/runtime/neurun/backend/acl_cl/operand/CLSubTensor.cc b/runtime/onert/backend/acl_cl/operand/CLSubTensor.cc similarity index 97% rename from runtime/neurun/backend/acl_cl/operand/CLSubTensor.cc rename to runtime/onert/backend/acl_cl/operand/CLSubTensor.cc index 70c8829d911..2342297870d 100644 --- a/runtime/neurun/backend/acl_cl/operand/CLSubTensor.cc +++ b/runtime/onert/backend/acl_cl/operand/CLSubTensor.cc @@ -16,7 +16,7 @@ #include "CLSubTensor.h" -namespace neurun +namespace onert { namespace backend { @@ -41,4 +41,4 @@ arm_compute::CLSubTensor *CLSubTensor::handle() { return _cl_sub_tensor.get(); } } // namespace operand } // namespace acl_cl } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/acl_cl/operand/CLSubTensor.h b/runtime/onert/backend/acl_cl/operand/CLSubTensor.h similarity index 87% rename from runtime/neurun/backend/acl_cl/operand/CLSubTensor.h rename to runtime/onert/backend/acl_cl/operand/CLSubTensor.h index 31ca63e0477..fedc17fc27c 100644 --- a/runtime/neurun/backend/acl_cl/operand/CLSubTensor.h +++ b/runtime/onert/backend/acl_cl/operand/CLSubTensor.h @@ -14,13 +14,13 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_ACL_CL_OPERAND_CL_SUB_TENSOR_H__ -#define __NEURUN_BACKEND_ACL_CL_OPERAND_CL_SUB_TENSOR_H__ +#ifndef __ONERT_BACKEND_ACL_CL_OPERAND_CL_SUB_TENSOR_H__ +#define __ONERT_BACKEND_ACL_CL_OPERAND_CL_SUB_TENSOR_H__ #include #include "ICLTensor.h" -namespace neurun +namespace onert { namespace backend { @@ -57,6 +57,6 @@ class CLSubTensor : public ICLTensor } // namespace operand } // namespace acl_cl } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_ACL_CL_OPERAND_CL_SUB_TENSOR_H__ +#endif // __ONERT_BACKEND_ACL_CL_OPERAND_CL_SUB_TENSOR_H__ diff --git a/runtime/neurun/backend/acl_cl/operand/CLTensor.cc b/runtime/onert/backend/acl_cl/operand/CLTensor.cc similarity index 97% rename from runtime/neurun/backend/acl_cl/operand/CLTensor.cc rename to runtime/onert/backend/acl_cl/operand/CLTensor.cc index dab74e65f09..cd5aaa1fd39 100644 --- a/runtime/neurun/backend/acl_cl/operand/CLTensor.cc +++ b/runtime/onert/backend/acl_cl/operand/CLTensor.cc @@ -22,7 +22,7 @@ #include -namespace neurun +namespace onert { namespace backend { @@ -59,4 +59,4 @@ void CLTensor::setBuffer(void *host_ptr) } // namespace operand } // namespace acl_cl } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/acl_cl/operand/CLTensor.h b/runtime/onert/backend/acl_cl/operand/CLTensor.h similarity index 90% rename from runtime/neurun/backend/acl_cl/operand/CLTensor.h rename to runtime/onert/backend/acl_cl/operand/CLTensor.h index 8518bf0c36b..abad866c348 100644 --- a/runtime/neurun/backend/acl_cl/operand/CLTensor.h +++ b/runtime/onert/backend/acl_cl/operand/CLTensor.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_ACL_CL_OPERAND_CL_TENSOR_H__ -#define __NEURUN_BACKEND_ACL_CL_OPERAND_CL_TENSOR_H__ +#ifndef __ONERT_BACKEND_ACL_CL_OPERAND_CL_TENSOR_H__ +#define __ONERT_BACKEND_ACL_CL_OPERAND_CL_TENSOR_H__ #include #include @@ -23,7 +23,7 @@ #include "arm_compute/runtime/CL/CLTensorAllocator.h" #include "ICLTensor.h" -namespace neurun +namespace onert { namespace backend { @@ -70,6 +70,6 @@ class CLTensor : public ICLTensor } // namespace operand } // namespace acl_cl } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_ACL_CL_OPERAND_CL_TENSOR_H__ +#endif // __ONERT_BACKEND_ACL_CL_OPERAND_CL_TENSOR_H__ diff --git a/runtime/neurun/backend/acl_cl/operand/ICLTensor.cc b/runtime/onert/backend/acl_cl/operand/ICLTensor.cc similarity index 96% rename from runtime/neurun/backend/acl_cl/operand/ICLTensor.cc rename to runtime/onert/backend/acl_cl/operand/ICLTensor.cc index 6b14584e034..b400ef9cffd 100644 --- a/runtime/neurun/backend/acl_cl/operand/ICLTensor.cc +++ b/runtime/onert/backend/acl_cl/operand/ICLTensor.cc @@ -18,7 +18,7 @@ #include -namespace neurun +namespace onert { namespace backend { @@ -42,4 +42,4 @@ void ICLTensor::access(const std::function &fn) } // namespace operand } // namespace acl_cl } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/acl_cl/operand/ICLTensor.h b/runtime/onert/backend/acl_cl/operand/ICLTensor.h similarity index 85% rename from runtime/neurun/backend/acl_cl/operand/ICLTensor.h rename to runtime/onert/backend/acl_cl/operand/ICLTensor.h index 68e4e7fc51b..f709fe46594 100644 --- a/runtime/neurun/backend/acl_cl/operand/ICLTensor.h +++ b/runtime/onert/backend/acl_cl/operand/ICLTensor.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_ACL_CL_OPERAND_I_CL_TENSOR_H__ -#define __NEURUN_BACKEND_ACL_CL_OPERAND_I_CL_TENSOR_H__ +#ifndef __ONERT_BACKEND_ACL_CL_OPERAND_I_CL_TENSOR_H__ +#define __ONERT_BACKEND_ACL_CL_OPERAND_I_CL_TENSOR_H__ #include #include -namespace neurun +namespace onert { namespace backend { @@ -45,6 +45,6 @@ class ICLTensor : public acl_common::IACLTensor } // namespace operand } // namespace acl_cl } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_ACL_CL_OPERAND_I_CL_TENSOR_H__ +#endif // __ONERT_BACKEND_ACL_CL_OPERAND_I_CL_TENSOR_H__ diff --git a/runtime/neurun/backend/acl_common/AclActivationBuilder.h b/runtime/onert/backend/acl_common/AclActivationBuilder.h similarity index 94% rename from runtime/neurun/backend/acl_common/AclActivationBuilder.h rename to runtime/onert/backend/acl_common/AclActivationBuilder.h index 910e71be8ad..bfdea6ea0bb 100644 --- a/runtime/neurun/backend/acl_common/AclActivationBuilder.h +++ b/runtime/onert/backend/acl_common/AclActivationBuilder.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_ACL_COMMON_ACL_ACTIVATION_BUILDER_H__ -#define __NEURUN_BACKEND_ACL_COMMON_ACL_ACTIVATION_BUILDER_H__ +#ifndef __ONERT_BACKEND_ACL_COMMON_ACL_ACTIVATION_BUILDER_H__ +#define __ONERT_BACKEND_ACL_COMMON_ACL_ACTIVATION_BUILDER_H__ #include @@ -25,7 +25,7 @@ #include "Convert.h" -namespace neurun +namespace onert { namespace backend { @@ -120,6 +120,6 @@ AclActivationBuilder::generate(ir:: } // namespace acl_common } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_ACL_COMMON_ACL_ACTIVATION_BUILDER_H__ +#endif // __ONERT_BACKEND_ACL_COMMON_ACL_ACTIVATION_BUILDER_H__ diff --git a/runtime/neurun/backend/acl_common/AclFunction.h b/runtime/onert/backend/acl_common/AclFunction.h similarity index 83% rename from runtime/neurun/backend/acl_common/AclFunction.h rename to runtime/onert/backend/acl_common/AclFunction.h index 20bebebde5c..99972ac9c6a 100644 --- a/runtime/neurun/backend/acl_common/AclFunction.h +++ b/runtime/onert/backend/acl_common/AclFunction.h @@ -14,22 +14,22 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_ACL_COMMON_KERNEL_ACL_FUNCTION_H__ -#define __NEURUN_BACKEND_ACL_COMMON_KERNEL_ACL_FUNCTION_H__ +#ifndef __ONERT_BACKEND_ACL_COMMON_KERNEL_ACL_FUNCTION_H__ +#define __ONERT_BACKEND_ACL_COMMON_KERNEL_ACL_FUNCTION_H__ #include #include #include #include -namespace neurun +namespace onert { namespace backend { namespace acl_common { -class AclFunction : public ::neurun::exec::IFunction +class AclFunction : public ::onert::exec::IFunction { public: AclFunction() = delete; @@ -64,6 +64,6 @@ class AclClFunction : public AclFunction } // namespace acl_common } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_ACL_COMMON_KERNEL_ACL_FUNCTION_H__ +#endif // __ONERT_BACKEND_ACL_COMMON_KERNEL_ACL_FUNCTION_H__ diff --git a/runtime/neurun/backend/acl_common/AclInternalBufferManager.h b/runtime/onert/backend/acl_common/AclInternalBufferManager.h similarity index 92% rename from runtime/neurun/backend/acl_common/AclInternalBufferManager.h rename to runtime/onert/backend/acl_common/AclInternalBufferManager.h index b7183c86e6c..f893bb44b3b 100644 --- a/runtime/neurun/backend/acl_common/AclInternalBufferManager.h +++ b/runtime/onert/backend/acl_common/AclInternalBufferManager.h @@ -14,15 +14,15 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_ACL_COMMON_INTERNAL_BUFFER_MANAGER_H__ -#define __NEURUN_BACKEND_ACL_COMMON_INTERNAL_BUFFER_MANAGER_H__ +#ifndef __ONERT_BACKEND_ACL_COMMON_INTERNAL_BUFFER_MANAGER_H__ +#define __ONERT_BACKEND_ACL_COMMON_INTERNAL_BUFFER_MANAGER_H__ #include #include #include #include -namespace neurun +namespace onert { namespace backend { @@ -92,6 +92,6 @@ class AclInternalBufferManager : public IInternalBufferManager } // namespace acl_common } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_ACL_COMMON_INTERNAL_BUFFER_MANAGER_H__ +#endif // __ONERT_BACKEND_ACL_COMMON_INTERNAL_BUFFER_MANAGER_H__ diff --git a/runtime/neurun/backend/acl_common/AclLinearMemoryManager.h b/runtime/onert/backend/acl_common/AclLinearMemoryManager.h similarity index 91% rename from runtime/neurun/backend/acl_common/AclLinearMemoryManager.h rename to runtime/onert/backend/acl_common/AclLinearMemoryManager.h index 7ed719bc344..09f25e7a84f 100644 --- a/runtime/neurun/backend/acl_common/AclLinearMemoryManager.h +++ b/runtime/onert/backend/acl_common/AclLinearMemoryManager.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_ACL_COMMON_LINEAR_MEMORY_MANAGER_H__ -#define __NEURUN_BACKEND_ACL_COMMON_LINEAR_MEMORY_MANAGER_H__ +#ifndef __ONERT_BACKEND_ACL_COMMON_LINEAR_MEMORY_MANAGER_H__ +#define __ONERT_BACKEND_ACL_COMMON_LINEAR_MEMORY_MANAGER_H__ #include @@ -37,9 +37,9 @@ std::shared_ptr createMemoryManager() return mem_mgr; } -} // namespace anonymous +} // namespace -namespace neurun +namespace onert { namespace backend { @@ -105,6 +105,6 @@ class AclLinearMemoryManager : public AclMemoryManager #include @@ -26,7 +26,7 @@ #include "Convert.h" #include "util/logging.h" -namespace neurun +namespace onert { namespace backend { @@ -93,6 +93,6 @@ class AclMemoryManager : public backend::IMemoryManager } // namespace acl_common } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_ACL_COMMON_MEMORY_MANAGER_H__ +#endif // __ONERT_BACKEND_ACL_COMMON_MEMORY_MANAGER_H__ diff --git a/runtime/neurun/backend/acl_common/AclSubTensorAnalyzer.h b/runtime/onert/backend/acl_common/AclSubTensorAnalyzer.h similarity index 77% rename from runtime/neurun/backend/acl_common/AclSubTensorAnalyzer.h rename to runtime/onert/backend/acl_common/AclSubTensorAnalyzer.h index 4c51528563c..83d7ad6fd74 100644 --- a/runtime/neurun/backend/acl_common/AclSubTensorAnalyzer.h +++ b/runtime/onert/backend/acl_common/AclSubTensorAnalyzer.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_ACL_COMMON_ACL_SUB_TENSOR_ANALYZER_H__ -#define __NEURUN_BACKEND_ACL_COMMON_ACL_SUB_TENSOR_ANALYZER_H__ +#ifndef __ONERT_BACKEND_ACL_COMMON_ACL_SUB_TENSOR_ANALYZER_H__ +#define __ONERT_BACKEND_ACL_COMMON_ACL_SUB_TENSOR_ANALYZER_H__ #include #include #include "ParentInfo.h" -namespace neurun +namespace onert { namespace backend { @@ -44,15 +44,7 @@ class AclSubTensorAnalyzer : public ir::OperationVisitor } public: - void visit(const ir::OpSequence &op_seq) override - { - _current_op_seq_layout = op_seq.getLayout(); - for (const auto &e : op_seq.operations()) - { - const auto &node = *(e.node); - node.accept(*this); - } - } + void setLayout(ir::Layout layout) { _current_op_layout = layout; } void visit(const ir::operation::Concat &node) override { @@ -88,8 +80,8 @@ class AclSubTensorAnalyzer : public ir::OperationVisitor } coordinate_info.set(axis, axis_point); - _parent_map.emplace(input_index, acl_common::ParentInfo{output_index, _current_op_seq_layout, - coordinate_info}); + _parent_map.emplace( + input_index, acl_common::ParentInfo{output_index, _current_op_layout, coordinate_info}); axis_point += input_shape.dim(axis); } @@ -103,11 +95,11 @@ class AclSubTensorAnalyzer : public ir::OperationVisitor private: const ir::Graph &_graph; std::unordered_map _parent_map; - ir::Layout _current_op_seq_layout{ir::Layout::UNKNOWN}; + ir::Layout _current_op_layout{ir::Layout::UNKNOWN}; }; } // namespace acl_common } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_ACL_COMMON_ACL_SUB_TENSOR_ANALYZER_H__ +#endif // __ONERT_BACKEND_ACL_COMMON_ACL_SUB_TENSOR_ANALYZER_H__ diff --git a/runtime/neurun/backend/acl_common/AclTensorBuilder.h b/runtime/onert/backend/acl_common/AclTensorBuilder.h similarity index 98% rename from runtime/neurun/backend/acl_common/AclTensorBuilder.h rename to runtime/onert/backend/acl_common/AclTensorBuilder.h index 5a6012a9320..be8d4320948 100644 --- a/runtime/neurun/backend/acl_common/AclTensorBuilder.h +++ b/runtime/onert/backend/acl_common/AclTensorBuilder.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_ACL_COMMON_TEMPL_TENSOR_BUILDER_H__ -#define __NEURUN_BACKEND_ACL_COMMON_TEMPL_TENSOR_BUILDER_H__ +#ifndef __ONERT_BACKEND_ACL_COMMON_TEMPL_TENSOR_BUILDER_H__ +#define __ONERT_BACKEND_ACL_COMMON_TEMPL_TENSOR_BUILDER_H__ #include #include @@ -25,11 +25,11 @@ #include "ir/OperandIndexMap.h" #include #include "AclTensorManager.h" -#include "memory" +#include #include "ParentInfo.h" #include -namespace neurun +namespace onert { namespace backend { @@ -124,7 +124,7 @@ class AclTensorBuilder : public ITensorBuilder } // namespace acl_common } // namespace backend -} // namespace neurun +} // namespace onert #include #include @@ -133,7 +133,7 @@ class AclTensorBuilder : public ITensorBuilder #include "util/logging.h" -namespace neurun +namespace onert { namespace backend { @@ -478,6 +478,6 @@ AclTensorBuilder::findRootParent(ir::OperandIn } // namespace acl_common } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_ACL_COMMON_TEMPL_TENSOR_BUILDER_H__ +#endif // __ONERT_BACKEND_ACL_COMMON_TEMPL_TENSOR_BUILDER_H__ diff --git a/runtime/neurun/backend/acl_common/AclTensorManager.h b/runtime/onert/backend/acl_common/AclTensorManager.h similarity index 97% rename from runtime/neurun/backend/acl_common/AclTensorManager.h rename to runtime/onert/backend/acl_common/AclTensorManager.h index 0b0cadd849f..b999a39a917 100644 --- a/runtime/neurun/backend/acl_common/AclTensorManager.h +++ b/runtime/onert/backend/acl_common/AclTensorManager.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_ACL_COMMON_TENSOR_MANAGER_H__ -#define __NEURUN_BACKEND_ACL_COMMON_TENSOR_MANAGER_H__ +#ifndef __ONERT_BACKEND_ACL_COMMON_TENSOR_MANAGER_H__ +#define __ONERT_BACKEND_ACL_COMMON_TENSOR_MANAGER_H__ #include @@ -24,7 +24,7 @@ #include "AclInternalBufferManager.h" #include "ir/OperandIndexMap.h" -namespace neurun +namespace onert { namespace backend { @@ -83,12 +83,12 @@ class AclTensorManager : public backend::ITensorManager } // namespace acl_common } // namespace backend -} // namespace neurun +} // namespace onert #include #include "util/logging.h" -namespace neurun +namespace onert { namespace backend { @@ -296,6 +296,6 @@ void AclTensorManager::tryDeallocConstants(voi } // namespace acl_common } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_ACL_COMMON_TENSOR_MANAGER_H__ +#endif // __ONERT_BACKEND_ACL_COMMON_TENSOR_MANAGER_H__ diff --git a/runtime/onert/backend/acl_common/CMakeLists.txt b/runtime/onert/backend/acl_common/CMakeLists.txt new file mode 100644 index 00000000000..b87db2621aa --- /dev/null +++ b/runtime/onert/backend/acl_common/CMakeLists.txt @@ -0,0 +1,19 @@ +# Unsupported architecture +nnas_find_package(ARMCompute QUIET) +if(NOT ARMCompute_FOUND) + return() +endif(NOT ARMCompute_FOUND) + +file(GLOB SOURCES "*.cc") + +add_library(${LIB_ONERT_BACKEND_ACL_COMMON} STATIC ${SOURCES}) + +target_include_directories(${LIB_ONERT_BACKEND_ACL_COMMON} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +target_link_libraries(${LIB_ONERT_BACKEND_ACL_COMMON} PUBLIC onert_core) +target_link_libraries(${LIB_ONERT_BACKEND_ACL_COMMON} PUBLIC arm_compute arm_compute_ex) +target_link_libraries(${LIB_ONERT_BACKEND_ACL_COMMON} PUBLIC nnfw_lib_misc) +target_link_libraries(${LIB_ONERT_BACKEND_ACL_COMMON} PRIVATE nnfw_common) +target_link_libraries(${LIB_ONERT_BACKEND_ACL_COMMON} PRIVATE nnfw_coverage) + +set_target_properties(${LIB_ONERT_BACKEND_ACL_COMMON} PROPERTIES POSITION_INDEPENDENT_CODE ON) +set_target_properties(${LIB_ONERT_BACKEND_ACL_COMMON} PROPERTIES OUTPUT_NAME backend_acl_common) diff --git a/runtime/neurun/backend/acl_common/Convert.cc b/runtime/onert/backend/acl_common/Convert.cc similarity index 97% rename from runtime/neurun/backend/acl_common/Convert.cc rename to runtime/onert/backend/acl_common/Convert.cc index d961ceb9370..0ea2be01064 100644 --- a/runtime/neurun/backend/acl_common/Convert.cc +++ b/runtime/onert/backend/acl_common/Convert.cc @@ -23,13 +23,13 @@ namespace { -::arm_compute::DataLayout asDataLayout(neurun::ir::Layout layout) +::arm_compute::DataLayout asDataLayout(onert::ir::Layout layout) { switch (layout) { - case neurun::ir::Layout::NHWC: + case onert::ir::Layout::NHWC: return ::arm_compute::DataLayout::NHWC; - case neurun::ir::Layout::NCHW: + case onert::ir::Layout::NCHW: return ::arm_compute::DataLayout::NCHW; default: return ::arm_compute::DataLayout::UNKNOWN; @@ -38,7 +38,7 @@ ::arm_compute::DataLayout asDataLayout(neurun::ir::Layout layout) } // namespace -namespace neurun +namespace onert { namespace backend { @@ -195,4 +195,4 @@ ir::Layout asRuntimeLayout(::arm_compute::DataLayout data_layout) } // namespace acl_common } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/acl_common/Convert.h b/runtime/onert/backend/acl_common/Convert.h similarity index 93% rename from runtime/neurun/backend/acl_common/Convert.h rename to runtime/onert/backend/acl_common/Convert.h index 6bcc99787db..760a73f51ca 100644 --- a/runtime/neurun/backend/acl_common/Convert.h +++ b/runtime/onert/backend/acl_common/Convert.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_ACL_COMMON_CONVERT_H__ -#define __NEURUN_BACKEND_ACL_COMMON_CONVERT_H__ +#ifndef __ONERT_BACKEND_ACL_COMMON_CONVERT_H__ +#define __ONERT_BACKEND_ACL_COMMON_CONVERT_H__ #include #include @@ -33,7 +33,7 @@ #include "AclFunction.h" -namespace neurun +namespace onert { namespace backend { @@ -69,6 +69,6 @@ ir::Layout asRuntimeLayout(::arm_compute::DataLayout data_layout); } // namespace acl_common } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_ACL_COMMON_CONVERT_H__ +#endif // __ONERT_BACKEND_ACL_COMMON_CONVERT_H__ diff --git a/runtime/neurun/backend/acl_common/IACLTensor.cc b/runtime/onert/backend/acl_common/IACLTensor.cc similarity index 97% rename from runtime/neurun/backend/acl_common/IACLTensor.cc rename to runtime/onert/backend/acl_common/IACLTensor.cc index 936b9a5529d..3796b9e4b39 100644 --- a/runtime/neurun/backend/acl_common/IACLTensor.cc +++ b/runtime/onert/backend/acl_common/IACLTensor.cc @@ -18,7 +18,7 @@ #include "Convert.h" #include "Swizzle.h" -namespace neurun +namespace onert { namespace backend { @@ -60,4 +60,4 @@ ir::Layout IACLTensor::layout() const { return acl_common::asRuntimeLayout(info( } // namespace acl_common } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/acl_common/IACLTensor.h b/runtime/onert/backend/acl_common/IACLTensor.h similarity index 77% rename from runtime/neurun/backend/acl_common/IACLTensor.h rename to runtime/onert/backend/acl_common/IACLTensor.h index 3bdb3960ffb..36a5d210716 100644 --- a/runtime/neurun/backend/acl_common/IACLTensor.h +++ b/runtime/onert/backend/acl_common/IACLTensor.h @@ -14,19 +14,25 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_ACL_COMMON_I_ACL_TENSOR_H__ -#define __NEURUN_BACKEND_ACL_COMMON_I_ACL_TENSOR_H__ +#ifndef __ONERT_BACKEND_ACL_COMMON_I_ACL_TENSOR_H__ +#define __ONERT_BACKEND_ACL_COMMON_I_ACL_TENSOR_H__ #include #include -namespace neurun +namespace onert { namespace backend { namespace acl_common { +/** + * @brief Class representing Tensor for ACL + * @todo Override is_dynamic() method. We don't support dynamic tensor for ACL yet as of Apr, 2020. + * FYI, ACL ITensorInfo has is_dynamic() method, which seems currently not used. + * Maybe for ACL, this method can be implemented using ITensorInfo::is_dynamic() in future. + */ class IACLTensor : public ITensor { public: @@ -57,6 +63,6 @@ class IACLTensor : public ITensor } // namespace acl_common } // namespace backend -} // namespace neurun +} // namespace onert -#endif //__NEURUN_BACKEND_ACL_COMMON_I_ACL_TENSOR_H__ +#endif //__ONERT_BACKEND_ACL_COMMON_I_ACL_TENSOR_H__ diff --git a/runtime/neurun/backend/acl_common/ParentInfo.h b/runtime/onert/backend/acl_common/ParentInfo.h similarity index 83% rename from runtime/neurun/backend/acl_common/ParentInfo.h rename to runtime/onert/backend/acl_common/ParentInfo.h index eb7dd48673b..7084363273d 100644 --- a/runtime/neurun/backend/acl_common/ParentInfo.h +++ b/runtime/onert/backend/acl_common/ParentInfo.h @@ -14,13 +14,13 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_ACL_COMMON_PARENT_INFO_H__ -#define __NEURUN_BACKEND_ACL_COMMON_PARENT_INFO_H__ +#ifndef __ONERT_BACKEND_ACL_COMMON_PARENT_INFO_H__ +#define __ONERT_BACKEND_ACL_COMMON_PARENT_INFO_H__ #include #include -namespace neurun +namespace onert { namespace backend { @@ -39,6 +39,6 @@ struct ParentInfo } // namespace acl_common } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_ACL_COMMON_PARENT_INFO_H__ +#endif // __ONERT_BACKEND_ACL_COMMON_PARENT_INFO_H__ diff --git a/runtime/neurun/backend/acl_common/Swizzle.h b/runtime/onert/backend/acl_common/Swizzle.h similarity index 95% rename from runtime/neurun/backend/acl_common/Swizzle.h rename to runtime/onert/backend/acl_common/Swizzle.h index 11874b5929a..e1c7f804150 100644 --- a/runtime/neurun/backend/acl_common/Swizzle.h +++ b/runtime/onert/backend/acl_common/Swizzle.h @@ -14,13 +14,13 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_ACL_COMMON_SWIZZLE_H__ -#define __NEURUN_BACKEND_ACL_COMMON_SWIZZLE_H__ +#ifndef __ONERT_BACKEND_ACL_COMMON_SWIZZLE_H__ +#define __ONERT_BACKEND_ACL_COMMON_SWIZZLE_H__ #include #include -namespace neurun +namespace onert { namespace backend { @@ -155,6 +155,6 @@ inline T ReorderBits(T in, size_t numOfBits, const ir::Layout org_layout = ir::L } // namespace acl_common } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_ACL_COMMON_SWIZZLE_H__ +#endif // __ONERT_BACKEND_ACL_COMMON_SWIZZLE_H__ diff --git a/runtime/neurun/backend/acl_neon/Backend.h b/runtime/onert/backend/acl_neon/Backend.h similarity index 86% rename from runtime/neurun/backend/acl_neon/Backend.h rename to runtime/onert/backend/acl_neon/Backend.h index 30ee26e3a82..609545dd90e 100644 --- a/runtime/neurun/backend/acl_neon/Backend.h +++ b/runtime/onert/backend/acl_neon/Backend.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_ACL_NEON_BACKEND_H__ -#define __NEURUN_BACKEND_ACL_NEON_BACKEND_H__ +#ifndef __ONERT_BACKEND_ACL_NEON_BACKEND_H__ +#define __ONERT_BACKEND_ACL_NEON_BACKEND_H__ #include #include @@ -28,14 +28,14 @@ #include "TensorManager.h" #include "Optimizer.h" -namespace neurun +namespace onert { namespace backend { namespace acl_neon { -class Backend : public ::neurun::backend::Backend +class Backend : public ::onert::backend::Backend { public: Backend() : _config{std::make_shared()} {} @@ -54,7 +54,7 @@ class Backend : public ::neurun::backend::Backend context->kernel_gen = std::make_shared(operands, tb); context->shape_fixer = std::make_shared(operands, tb); context->tensor_register = nullptr; - context->optimizer = nullptr; + context->optimizer = std::make_shared(context.get()); return context; } @@ -64,6 +64,6 @@ class Backend : public ::neurun::backend::Backend } // namespace acl_neon } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_ACL_NEON_BACKEND_H__ +#endif // __ONERT_BACKEND_ACL_NEON_BACKEND_H__ diff --git a/runtime/onert/backend/acl_neon/CMakeLists.txt b/runtime/onert/backend/acl_neon/CMakeLists.txt new file mode 100644 index 00000000000..05343dd8c44 --- /dev/null +++ b/runtime/onert/backend/acl_neon/CMakeLists.txt @@ -0,0 +1,19 @@ +# Unsupported architecture +nnas_find_package(ARMCompute QUIET) +if(NOT ARMCompute_FOUND) + return() +endif(NOT ARMCompute_FOUND) + +set(LIB_ONERT_BACKEND_ACL_NEON onert_backend_acl_neon) + +file(GLOB_RECURSE SOURCES "*.cc") + +add_library(${LIB_ONERT_BACKEND_ACL_NEON} SHARED ${SOURCES}) + +target_link_libraries(${LIB_ONERT_BACKEND_ACL_NEON} PRIVATE ${LIB_ONERT_BACKEND_ACL_COMMON}) +target_link_libraries(${LIB_ONERT_BACKEND_ACL_NEON} PRIVATE nnfw_common) +target_link_libraries(${LIB_ONERT_BACKEND_ACL_NEON} PRIVATE nnfw_coverage) + +set_target_properties(${LIB_ONERT_BACKEND_ACL_NEON} PROPERTIES OUTPUT_NAME backend_acl_neon) + +install(TARGETS ${LIB_ONERT_BACKEND_ACL_NEON} DESTINATION lib) diff --git a/runtime/neurun/backend/acl_neon/Config.cc b/runtime/onert/backend/acl_neon/Config.cc similarity index 95% rename from runtime/neurun/backend/acl_neon/Config.cc rename to runtime/onert/backend/acl_neon/Config.cc index 352bc0b417e..2033f5b4e25 100644 --- a/runtime/neurun/backend/acl_neon/Config.cc +++ b/runtime/onert/backend/acl_neon/Config.cc @@ -16,7 +16,7 @@ #include "Config.h" -namespace neurun +namespace onert { namespace backend { @@ -27,4 +27,4 @@ bool Config::initialize() { return true; } } // namespace acl_neon } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/acl_neon/Config.h b/runtime/onert/backend/acl_neon/Config.h similarity index 85% rename from runtime/neurun/backend/acl_neon/Config.h rename to runtime/onert/backend/acl_neon/Config.h index 03e3d72f98d..a6d6b467321 100644 --- a/runtime/neurun/backend/acl_neon/Config.h +++ b/runtime/onert/backend/acl_neon/Config.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_ACL_NEON_CONFIG_H__ -#define __NEURUN_BACKEND_ACL_NEON_CONFIG_H__ +#ifndef __ONERT_BACKEND_ACL_NEON_CONFIG_H__ +#define __ONERT_BACKEND_ACL_NEON_CONFIG_H__ #include #include #include -namespace neurun +namespace onert { namespace backend { @@ -40,6 +40,6 @@ class Config : public IConfig } // namespace acl_neon } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_ACL_NEON_CONFIG_H__ +#endif // __ONERT_BACKEND_ACL_NEON_CONFIG_H__ diff --git a/runtime/neurun/backend/acl_neon/ConstantInitializer.cc b/runtime/onert/backend/acl_neon/ConstantInitializer.cc similarity index 99% rename from runtime/neurun/backend/acl_neon/ConstantInitializer.cc rename to runtime/onert/backend/acl_neon/ConstantInitializer.cc index 408674062d6..4191b277ffe 100644 --- a/runtime/neurun/backend/acl_neon/ConstantInitializer.cc +++ b/runtime/onert/backend/acl_neon/ConstantInitializer.cc @@ -16,7 +16,7 @@ #include "ConstantInitializer.h" -namespace neurun +namespace onert { namespace backend { @@ -180,4 +180,4 @@ void ConstantInitializer::visit(const ir::operation::TransposeConv &node) } // namespace acl_neon } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/acl_neon/ConstantInitializer.h b/runtime/onert/backend/acl_neon/ConstantInitializer.h similarity index 89% rename from runtime/neurun/backend/acl_neon/ConstantInitializer.h rename to runtime/onert/backend/acl_neon/ConstantInitializer.h index 3c3717e8887..6b4c1f145da 100644 --- a/runtime/neurun/backend/acl_neon/ConstantInitializer.h +++ b/runtime/onert/backend/acl_neon/ConstantInitializer.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_COMPILER_ACL_NEON_CONSTANT_INITIALIZER_H__ -#define __NEURUN_COMPILER_ACL_NEON_CONSTANT_INITIALIZER_H__ +#ifndef __ONERT_COMPILER_ACL_NEON_CONSTANT_INITIALIZER_H__ +#define __ONERT_COMPILER_ACL_NEON_CONSTANT_INITIALIZER_H__ #include #include #include "TensorBuilder.h" -namespace neurun +namespace onert { namespace backend { @@ -55,6 +55,6 @@ class ConstantInitializer : public IConstantInitializer } // namespace acl_neon } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_COMPILER_ACL_NEON_CONSTANT_INITIALIZER_H__ +#endif // __ONERT_COMPILER_ACL_NEON_CONSTANT_INITIALIZER_H__ diff --git a/runtime/neurun/backend/acl_neon/KernelGenerator.cc b/runtime/onert/backend/acl_neon/KernelGenerator.cc similarity index 98% rename from runtime/neurun/backend/acl_neon/KernelGenerator.cc rename to runtime/onert/backend/acl_neon/KernelGenerator.cc index 3dac2cee20a..42a115438b2 100644 --- a/runtime/neurun/backend/acl_neon/KernelGenerator.cc +++ b/runtime/onert/backend/acl_neon/KernelGenerator.cc @@ -32,15 +32,15 @@ #include "util/logging.h" #include "util/Utils.h" -namespace neurun +namespace onert { namespace backend { namespace acl_neon { -using ::neurun::backend::acl_common::asAclFunction; -using ActivationBuilder = ::neurun::backend::acl_common::AclActivationBuilder< +using ::onert::backend::acl_common::asAclFunction; +using ActivationBuilder = ::onert::backend::acl_common::AclActivationBuilder< ::arm_compute::ITensor, ::arm_compute::NEActivationLayer, acl_common::AclFunction>; KernelGenerator::KernelGenerator(const ir::Operands &ctx, @@ -549,8 +549,8 @@ void KernelGenerator::visit(const ir::operation::FullyConnected &node) fn->configure( input_alloc->handle(), weight_alloc->handle(), bias_alloc->handle(), output_alloc->handle(), needs_reshape, - ::neurun::backend::acl_common::asTensorShape( - reshape, frontend_layout, ::neurun::backend::acl_common::asRuntimeLayout(acl_layout)), + ::onert::backend::acl_common::asTensorShape( + reshape, frontend_layout, ::onert::backend::acl_common::asRuntimeLayout(acl_layout)), kernel_type); _return_fn = std::make_unique( @@ -597,7 +597,7 @@ void KernelGenerator::visit(const ir::operation::Gather &node) const auto axis_raw = node.param().axis; const auto axis_value = (axis_raw < 0 ? (ifm_rank + axis_raw) : axis_raw); // Converting in reverse order - const int axis = ::neurun::backend::acl_common::ToARMComputeAxis(ifm_rank, axis_value).value(); + const int axis = ::onert::backend::acl_common::ToARMComputeAxis(ifm_rank, axis_value).value(); auto ofm_alloc = _tensor_builder->at(ofm_index).get(); auto ifm_alloc = _tensor_builder->at(ifm_index).get(); @@ -703,7 +703,7 @@ void KernelGenerator::visit(const ir::operation::L2Pool2D &node) ::arm_compute::PoolingLayerInfo info{ ::arm_compute::PoolingType::L2, ::arm_compute::Size2D{kw, kh}, - ::neurun::backend::acl_common::asPadStrideInfo(padding, stride)}; + ::onert::backend::acl_common::asPadStrideInfo(padding, stride)}; auto fn = std::make_unique<::arm_compute::NEPoolingLayer>(); @@ -922,7 +922,7 @@ void KernelGenerator::visit(const ir::operation::LSTM &node) auto output_state_in_alloc = _tensor_builder->at(output_state_in_index).get(); auto cell_state_in_alloc = _tensor_builder->at(cell_state_in_index).get(); - auto act_info = ::neurun::backend::acl_common::asActivationLayerInfo(activation); + auto act_info = ::onert::backend::acl_common::asActivationLayerInfo(activation); auto fn = std::make_unique<::arm_compute::NELSTMLayer>(); @@ -1396,7 +1396,7 @@ void KernelGenerator::visit(const ir::operation::RNN &node) auto recurrent_weights_alloc = _tensor_builder->at(recurrent_weights_index).get(); auto bias_alloc = _tensor_builder->at(bias_index).get(); auto hidden_state_in_alloc = _tensor_builder->at(hidden_state_in_index).get(); - auto act_info = ::neurun::backend::acl_common::asActivationLayerInfo(activation); + auto act_info = ::onert::backend::acl_common::asActivationLayerInfo(activation); auto copy_layer = std::make_unique<::arm_compute::NECopy>(); copy_layer->configure(hidden_state_in_alloc->handle(), hidden_state_out_alloc->handle()); @@ -1659,8 +1659,8 @@ void KernelGenerator::visit(const ir::operation::Slice &node) assert(beginData_base != nullptr); for (int n = 0; n < input_rank; ++n) { - auto axis = ::neurun::backend::acl_common::ToARMComputeAxis(input_rank, n, frontend_layout, - backend_layout) + auto axis = ::onert::backend::acl_common::ToARMComputeAxis(input_rank, n, frontend_layout, + backend_layout) .value(); int32_t begin_value = *(reinterpret_cast(beginData_base) + n); @@ -1734,8 +1734,8 @@ void KernelGenerator::visit(const ir::operation::StridedSlice &node) assert(startData_base != nullptr); for (int n = 0; n < input_rank; ++n) { - auto axis = ::neurun::backend::acl_common::ToARMComputeAxis(input_rank, n, frontend_layout, - backend_layout) + auto axis = ::onert::backend::acl_common::ToARMComputeAxis(input_rank, n, frontend_layout, + backend_layout) .value(); int32_t start_value = *(reinterpret_cast(startData_base) + n); @@ -1780,8 +1780,6 @@ void KernelGenerator::visit(const ir::operation::StridedSlice &node) void KernelGenerator::visit(const ir::operation::TransposeConv &node) { const auto ofm_index{node.getOutputs().at(0)}; - const auto output_shape_index{ - node.getInputs().at(ir::operation::TransposeConv::Input::OUTPUT_SHAPE)}; const auto ker_index{node.getInputs().at(ir::operation::TransposeConv::Input::KERNEL)}; const auto ifm_index{node.getInputs().at(ir::operation::TransposeConv::Input::INPUT)}; @@ -1834,7 +1832,7 @@ void KernelGenerator::visit(const ir::operation::Transpose &node) const auto rank = node.param().rank; std::vector pv(perm.cbegin(), perm.cend()); - auto backend_pv = ::neurun::backend::acl_common::getARMComputePermutationVector( + auto backend_pv = ::onert::backend::acl_common::getARMComputePermutationVector( rank, pv, frontend_layout, backend_layout); std::unique_ptr<::arm_compute::IFunction> fn; @@ -2029,4 +2027,4 @@ void KernelGenerator::visit(const ir::operation::OneHot &node) } // namespace acl_neon } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/acl_neon/KernelGenerator.h b/runtime/onert/backend/acl_neon/KernelGenerator.h similarity index 95% rename from runtime/neurun/backend/acl_neon/KernelGenerator.h rename to runtime/onert/backend/acl_neon/KernelGenerator.h index be3f6de02e0..a29b0780547 100644 --- a/runtime/neurun/backend/acl_neon/KernelGenerator.h +++ b/runtime/onert/backend/acl_neon/KernelGenerator.h @@ -14,15 +14,15 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_ACL_NEON_KERNEL_GENERATOR_H__ -#define __NEURUN_BACKEND_ACL_NEON_KERNEL_GENERATOR_H__ +#ifndef __ONERT_BACKEND_ACL_NEON_KERNEL_GENERATOR_H__ +#define __ONERT_BACKEND_ACL_NEON_KERNEL_GENERATOR_H__ #include #include "ir/Operands.h" #include "TensorBuilder.h" -namespace neurun +namespace onert { namespace backend { @@ -107,6 +107,6 @@ class KernelGenerator : public IKernelGenerator } // namespace acl_neon } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_ACL_NEON_KERNEL_GENERATOR_H__ +#endif // __ONERT_BACKEND_ACL_NEON_KERNEL_GENERATOR_H__ diff --git a/runtime/neurun/backend/acl_neon/Optimizer.cc b/runtime/onert/backend/acl_neon/Optimizer.cc similarity index 95% rename from runtime/neurun/backend/acl_neon/Optimizer.cc rename to runtime/onert/backend/acl_neon/Optimizer.cc index 4f3eac2c2b8..2948cab097c 100644 --- a/runtime/neurun/backend/acl_neon/Optimizer.cc +++ b/runtime/onert/backend/acl_neon/Optimizer.cc @@ -23,7 +23,7 @@ #include #include "AclSubTensorAnalyzer.h" -namespace neurun +namespace onert { namespace backend { @@ -45,6 +45,7 @@ void Optimizer::optimize() for (auto op_info : _context->operation_list()) { auto &op = _context->graph()->operations().at(op_info.index); + sa.setLayout(op_info.layout); op.accept(sa); } @@ -54,4 +55,4 @@ void Optimizer::optimize() } // namespace acl_neon } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/acl_neon/Optimizer.h b/runtime/onert/backend/acl_neon/Optimizer.h similarity index 84% rename from runtime/neurun/backend/acl_neon/Optimizer.h rename to runtime/onert/backend/acl_neon/Optimizer.h index 36949f79d43..5fe0d519c8f 100644 --- a/runtime/neurun/backend/acl_neon/Optimizer.h +++ b/runtime/onert/backend/acl_neon/Optimizer.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_ACL_NEON_OPTIMZIER_H__ -#define __NEURUN_BACKEND_ACL_NEON_OPTIMIZER_H__ +#ifndef __ONERT_BACKEND_ACL_NEON_OPTIMIZER_H__ +#define __ONERT_BACKEND_ACL_NEON_OPTIMIZER_H__ #include #include #include "TensorBuilder.h" -namespace neurun +namespace onert { namespace backend { @@ -42,6 +42,6 @@ class Optimizer : public IOptimizer } // namespace acl_neon } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_ACL_NEON_OPTIMIZER_H__ +#endif // __ONERT_BACKEND_ACL_NEON_OPTIMIZER_H__ diff --git a/runtime/neurun/backend/acl_neon/ShapeFixer.cc b/runtime/onert/backend/acl_neon/ShapeFixer.cc similarity index 99% rename from runtime/neurun/backend/acl_neon/ShapeFixer.cc rename to runtime/onert/backend/acl_neon/ShapeFixer.cc index e74b43eb3f2..756222f4b64 100644 --- a/runtime/neurun/backend/acl_neon/ShapeFixer.cc +++ b/runtime/onert/backend/acl_neon/ShapeFixer.cc @@ -36,14 +36,14 @@ #include "util/logging.h" #include "util/Utils.h" -namespace neurun +namespace onert { namespace backend { namespace acl_neon { -using ::neurun::backend::acl_common::asAclFunction; +using ::onert::backend::acl_common::asAclFunction; ShapeFixer::ShapeFixer(const ir::Operands &ctx, const std::shared_ptr &tensor_builder) @@ -434,4 +434,4 @@ void ShapeFixer::visit(const ir::operation::OneHot &) { /* Do NOTHING */} } // namespace acl_neon } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/acl_neon/ShapeFixer.h b/runtime/onert/backend/acl_neon/ShapeFixer.h similarity index 95% rename from runtime/neurun/backend/acl_neon/ShapeFixer.h rename to runtime/onert/backend/acl_neon/ShapeFixer.h index d463d8f6011..434cfd24097 100644 --- a/runtime/neurun/backend/acl_neon/ShapeFixer.h +++ b/runtime/onert/backend/acl_neon/ShapeFixer.h @@ -14,15 +14,15 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_ACL_NEON_SHAPE_FIXER_H__ -#define __NEURUN_BACKEND_ACL_NEON_SHAPE_FIXER_H__ +#ifndef __ONERT_BACKEND_ACL_NEON_SHAPE_FIXER_H__ +#define __ONERT_BACKEND_ACL_NEON_SHAPE_FIXER_H__ #include #include "ir/Operands.h" #include "TensorBuilder.h" -namespace neurun +namespace onert { namespace backend { @@ -105,6 +105,6 @@ class ShapeFixer : public IShapeFixer } // namespace acl_neon } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_ACL_NEON_SHAPE_FIXER_H__ +#endif // __ONERT_BACKEND_ACL_NEON_SHAPE_FIXER_H__ diff --git a/runtime/neurun/backend/acl_neon/TensorBuilder.h b/runtime/onert/backend/acl_neon/TensorBuilder.h similarity index 82% rename from runtime/neurun/backend/acl_neon/TensorBuilder.h rename to runtime/onert/backend/acl_neon/TensorBuilder.h index b71f163340c..070dc20ac86 100644 --- a/runtime/neurun/backend/acl_neon/TensorBuilder.h +++ b/runtime/onert/backend/acl_neon/TensorBuilder.h @@ -14,15 +14,15 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_ACL_NEON_TENSOR_BUILDER_H__ -#define __NEURUN_BACKEND_ACL_NEON_TENSOR_BUILDER_H__ +#ifndef __ONERT_BACKEND_ACL_NEON_TENSOR_BUILDER_H__ +#define __ONERT_BACKEND_ACL_NEON_TENSOR_BUILDER_H__ #include #include "operand/NETensor.h" #include "operand/NESubTensor.h" -namespace neurun +namespace onert { namespace backend { @@ -34,6 +34,6 @@ using TensorBuilder = } // namespace acl_neon } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_ACL_NEON_TENSOR_BUILDER_H__ +#endif // __ONERT_BACKEND_ACL_NEON_TENSOR_BUILDER_H__ diff --git a/runtime/neurun/backend/acl_neon/TensorManager.h b/runtime/onert/backend/acl_neon/TensorManager.h similarity index 92% rename from runtime/neurun/backend/acl_neon/TensorManager.h rename to runtime/onert/backend/acl_neon/TensorManager.h index 2e59f186abb..3ec9efa8fca 100644 --- a/runtime/neurun/backend/acl_neon/TensorManager.h +++ b/runtime/onert/backend/acl_neon/TensorManager.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_ACL_NEON_TENSOR_MANAGER_H__ -#define __NEURUN_BACKEND_ACL_NEON_TENSOR_MANAGER_H__ +#ifndef __ONERT_BACKEND_ACL_NEON_TENSOR_MANAGER_H__ +#define __ONERT_BACKEND_ACL_NEON_TENSOR_MANAGER_H__ #include #include @@ -33,7 +33,7 @@ #include "util/logging.h" -namespace neurun +namespace onert { namespace backend { @@ -72,6 +72,6 @@ TensorManager *createTensorManager(bool is_linear_executor) } // namespace acl_neon } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_ACL_NEON_TENSOR_MANAGER_H__ +#endif // __ONERT_BACKEND_ACL_NEON_TENSOR_MANAGER_H__ diff --git a/runtime/neurun/backend/acl_neon/acl_neon.cc b/runtime/onert/backend/acl_neon/acl_neon.cc similarity index 72% rename from runtime/neurun/backend/acl_neon/acl_neon.cc rename to runtime/onert/backend/acl_neon/acl_neon.cc index 75f2e97972d..f490d132d17 100644 --- a/runtime/neurun/backend/acl_neon/acl_neon.cc +++ b/runtime/onert/backend/acl_neon/acl_neon.cc @@ -19,15 +19,15 @@ #include "Backend.h" extern "C" { -neurun::backend::Backend *neurun_backend_create() +onert::backend::Backend *onert_backend_create() { - VERBOSE(neurun_backend_create) << "'acl_neon' loaded\n"; - return new neurun::backend::acl_neon::Backend; + VERBOSE(onert_backend_create) << "'acl_neon' loaded\n"; + return new onert::backend::acl_neon::Backend; } -void neurun_backend_destroy(neurun::backend::Backend *backend) +void onert_backend_destroy(onert::backend::Backend *backend) { - VERBOSE(neurun_backend_create) << "'acl_neon' unloaded\n"; + VERBOSE(onert_backend_create) << "'acl_neon' unloaded\n"; delete backend; } } diff --git a/runtime/neurun/backend/acl_neon/operand/INETensor.cc b/runtime/onert/backend/acl_neon/operand/INETensor.cc similarity index 95% rename from runtime/neurun/backend/acl_neon/operand/INETensor.cc rename to runtime/onert/backend/acl_neon/operand/INETensor.cc index fdb20970df0..179ed691afb 100644 --- a/runtime/neurun/backend/acl_neon/operand/INETensor.cc +++ b/runtime/onert/backend/acl_neon/operand/INETensor.cc @@ -16,7 +16,7 @@ #include "INETensor.h" -namespace neurun +namespace onert { namespace backend { @@ -30,4 +30,4 @@ void INETensor::access(const std::function &fn) { fn(*thi } // namespace operand } // namespace acl_neon } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/acl_neon/operand/INETensor.h b/runtime/onert/backend/acl_neon/operand/INETensor.h similarity index 83% rename from runtime/neurun/backend/acl_neon/operand/INETensor.h rename to runtime/onert/backend/acl_neon/operand/INETensor.h index 22b1140cf3b..db0ce6fdc7d 100644 --- a/runtime/neurun/backend/acl_neon/operand/INETensor.h +++ b/runtime/onert/backend/acl_neon/operand/INETensor.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_ACL_NEON_OPERAND_I_NE_TENSOR_H__ -#define __NEURUN_BACKEND_ACL_NEON_OPERAND_I_NE_TENSOR_H__ +#ifndef __ONERT_BACKEND_ACL_NEON_OPERAND_I_NE_TENSOR_H__ +#define __ONERT_BACKEND_ACL_NEON_OPERAND_I_NE_TENSOR_H__ #include #include -namespace neurun +namespace onert { namespace backend { @@ -41,6 +41,6 @@ class INETensor : public acl_common::IACLTensor } // namespace operand } // namespace acl_neon } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_ACL_NEON_OPERAND_I_NE_TENSOR_H__ +#endif // __ONERT_BACKEND_ACL_NEON_OPERAND_I_NE_TENSOR_H__ diff --git a/runtime/neurun/backend/acl_neon/operand/NESubTensor.cc b/runtime/onert/backend/acl_neon/operand/NESubTensor.cc similarity index 97% rename from runtime/neurun/backend/acl_neon/operand/NESubTensor.cc rename to runtime/onert/backend/acl_neon/operand/NESubTensor.cc index a36af609c2c..457addd5506 100644 --- a/runtime/neurun/backend/acl_neon/operand/NESubTensor.cc +++ b/runtime/onert/backend/acl_neon/operand/NESubTensor.cc @@ -16,7 +16,7 @@ #include "NESubTensor.h" -namespace neurun +namespace onert { namespace backend { @@ -41,4 +41,4 @@ arm_compute::SubTensor *NESubTensor::handle() { return _ne_sub_tensor.get(); } } // namespace operand } // namespace acl_neon } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/acl_neon/operand/NESubTensor.h b/runtime/onert/backend/acl_neon/operand/NESubTensor.h similarity index 87% rename from runtime/neurun/backend/acl_neon/operand/NESubTensor.h rename to runtime/onert/backend/acl_neon/operand/NESubTensor.h index 0918d0f67d1..e7f77d7fc05 100644 --- a/runtime/neurun/backend/acl_neon/operand/NESubTensor.h +++ b/runtime/onert/backend/acl_neon/operand/NESubTensor.h @@ -14,13 +14,13 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_ACL_NEON_OPERAND_NE_SUB_TENSOR_H__ -#define __NEURUN_BACKEND_ACL_NEON_OPERAND_NE_SUB_TENSOR_H__ +#ifndef __ONERT_BACKEND_ACL_NEON_OPERAND_NE_SUB_TENSOR_H__ +#define __ONERT_BACKEND_ACL_NEON_OPERAND_NE_SUB_TENSOR_H__ #include #include "INETensor.h" -namespace neurun +namespace onert { namespace backend { @@ -57,6 +57,6 @@ class NESubTensor : public INETensor } // namespace operand } // namespace acl_neon } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_ACL_NEON_OPERAND_NE_SUB_TENSOR_H__ +#endif // __ONERT_BACKEND_ACL_NEON_OPERAND_NE_SUB_TENSOR_H__ diff --git a/runtime/neurun/backend/acl_neon/operand/NETensor.cc b/runtime/onert/backend/acl_neon/operand/NETensor.cc similarity index 97% rename from runtime/neurun/backend/acl_neon/operand/NETensor.cc rename to runtime/onert/backend/acl_neon/operand/NETensor.cc index 8a9ece88fe5..53dbb3021dc 100644 --- a/runtime/neurun/backend/acl_neon/operand/NETensor.cc +++ b/runtime/onert/backend/acl_neon/operand/NETensor.cc @@ -18,7 +18,7 @@ #include #include "NETensor.h" -namespace neurun +namespace onert { namespace backend { @@ -42,4 +42,4 @@ arm_compute::TensorAllocator *NETensor::allocator() { return _ne_tensor->allocat } // namespace operand } // namespace acl_neon } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/acl_neon/operand/NETensor.h b/runtime/onert/backend/acl_neon/operand/NETensor.h similarity index 87% rename from runtime/neurun/backend/acl_neon/operand/NETensor.h rename to runtime/onert/backend/acl_neon/operand/NETensor.h index 3de4695e9bf..0dd81afeca6 100644 --- a/runtime/neurun/backend/acl_neon/operand/NETensor.h +++ b/runtime/onert/backend/acl_neon/operand/NETensor.h @@ -14,15 +14,15 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_ACL_NEON_OPERAND_NE_TENSOR_H__ -#define __NEURUN_BACKEND_ACL_NEON_OPERAND_NE_TENSOR_H__ +#ifndef __ONERT_BACKEND_ACL_NEON_OPERAND_NE_TENSOR_H__ +#define __ONERT_BACKEND_ACL_NEON_OPERAND_NE_TENSOR_H__ #include #include #include "arm_compute/runtime/TensorAllocator.h" #include "INETensor.h" -namespace neurun +namespace onert { namespace backend { @@ -59,6 +59,6 @@ class NETensor : public INETensor } // namespace operand } // namespace acl_neon } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_ACL_NEON_OPERAND_NE_TENSOR_H__ +#endif // __ONERT_BACKEND_ACL_NEON_OPERAND_NE_TENSOR_H__ diff --git a/runtime/neurun/backend/cpu/Backend.h b/runtime/onert/backend/cpu/Backend.h similarity index 89% rename from runtime/neurun/backend/cpu/Backend.h rename to runtime/onert/backend/cpu/Backend.h index 53795403266..d12c809cdbb 100644 --- a/runtime/neurun/backend/cpu/Backend.h +++ b/runtime/onert/backend/cpu/Backend.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_CPU_BACKEND_H__ -#define __NEURUN_BACKEND_CPU_BACKEND_H__ +#ifndef __ONERT_BACKEND_CPU_BACKEND_H__ +#define __ONERT_BACKEND_CPU_BACKEND_H__ #include "Config.h" #include "ConstantInitializer.h" @@ -26,14 +26,14 @@ #include -namespace neurun +namespace onert { namespace backend { namespace cpu { -class Backend : public ::neurun::backend::Backend +class Backend : public ::onert::backend::Backend { public: Backend() : _config{std::make_shared()} {} @@ -62,6 +62,6 @@ class Backend : public ::neurun::backend::Backend } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_CPU_BACKEND_H__ +#endif // __ONERT_BACKEND_CPU_BACKEND_H__ diff --git a/runtime/onert/backend/cpu/CMakeLists.txt b/runtime/onert/backend/cpu/CMakeLists.txt new file mode 100644 index 00000000000..ed2dcd11037 --- /dev/null +++ b/runtime/onert/backend/cpu/CMakeLists.txt @@ -0,0 +1,14 @@ +set(LIB_ONERT_BACKEND_CPU onert_backend_cpu) + +file(GLOB_RECURSE SOURCES "*.cc") + +add_library(${LIB_ONERT_BACKEND_CPU} SHARED ${SOURCES}) + +target_link_libraries(${LIB_ONERT_BACKEND_CPU} PRIVATE nnfw_lib_misc nnfw_lib_cker) +target_link_libraries(${LIB_ONERT_BACKEND_CPU} PRIVATE ${LIB_ONERT_BACKEND_CPU_COMMON}) +target_link_libraries(${LIB_ONERT_BACKEND_CPU} PRIVATE nnfw_common) +target_link_libraries(${LIB_ONERT_BACKEND_CPU} PRIVATE nnfw_coverage) + +set_target_properties(${LIB_ONERT_BACKEND_CPU} PROPERTIES OUTPUT_NAME backend_cpu) + +install(TARGETS ${LIB_ONERT_BACKEND_CPU} DESTINATION lib) diff --git a/runtime/neurun/backend/cpu/Config.cc b/runtime/onert/backend/cpu/Config.cc similarity index 95% rename from runtime/neurun/backend/cpu/Config.cc rename to runtime/onert/backend/cpu/Config.cc index 39127406fd3..cea8095b15c 100644 --- a/runtime/neurun/backend/cpu/Config.cc +++ b/runtime/onert/backend/cpu/Config.cc @@ -16,7 +16,7 @@ #include "Config.h" -namespace neurun +namespace onert { namespace backend { @@ -27,4 +27,4 @@ bool Config::initialize() { return true; } } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/cpu/Config.h b/runtime/onert/backend/cpu/Config.h similarity index 86% rename from runtime/neurun/backend/cpu/Config.h rename to runtime/onert/backend/cpu/Config.h index ef0bc191a14..e7818fa04e1 100644 --- a/runtime/neurun/backend/cpu/Config.h +++ b/runtime/onert/backend/cpu/Config.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_CPU_CONFIG_H__ -#define __NEURUN_BACKEND_CPU_CONFIG_H__ +#ifndef __ONERT_BACKEND_CPU_CONFIG_H__ +#define __ONERT_BACKEND_CPU_CONFIG_H__ #include #include #include -namespace neurun +namespace onert { namespace backend { @@ -40,6 +40,6 @@ class Config : public IConfig } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_CPU_CONFIG_H__ +#endif // __ONERT_BACKEND_CPU_CONFIG_H__ diff --git a/runtime/neurun/backend/cpu/ConstantInitializer.cc b/runtime/onert/backend/cpu/ConstantInitializer.cc similarity index 98% rename from runtime/neurun/backend/cpu/ConstantInitializer.cc rename to runtime/onert/backend/cpu/ConstantInitializer.cc index 05b0a14b1ed..a77a48b308a 100644 --- a/runtime/neurun/backend/cpu/ConstantInitializer.cc +++ b/runtime/onert/backend/cpu/ConstantInitializer.cc @@ -16,7 +16,7 @@ #include "ConstantInitializer.h" -namespace neurun +namespace onert { namespace backend { @@ -65,4 +65,4 @@ void ConstantInitializer::visit(const ir::operation::FullyConnected &node) } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/cpu/ConstantInitializer.h b/runtime/onert/backend/cpu/ConstantInitializer.h similarity index 86% rename from runtime/neurun/backend/cpu/ConstantInitializer.h rename to runtime/onert/backend/cpu/ConstantInitializer.h index 33b2709538b..bd06c64d15c 100644 --- a/runtime/neurun/backend/cpu/ConstantInitializer.h +++ b/runtime/onert/backend/cpu/ConstantInitializer.h @@ -14,15 +14,15 @@ * limitations under the License. */ -#ifndef __NEURUN_COMPILER_CPU_CONSTANT_INITIALIZER_H__ -#define __NEURUN_COMPILER_CPU_CONSTANT_INITIALIZER_H__ +#ifndef __ONERT_COMPILER_CPU_CONSTANT_INITIALIZER_H__ +#define __ONERT_COMPILER_CPU_CONSTANT_INITIALIZER_H__ #include "TensorBuilder.h" #include #include -namespace neurun +namespace onert { namespace backend { @@ -49,6 +49,6 @@ class ConstantInitializer : public IConstantInitializer } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_COMPILER_CPU_CONSTANT_INITIALIZER_H__ +#endif // __ONERT_COMPILER_CPU_CONSTANT_INITIALIZER_H__ diff --git a/runtime/neurun/backend/cpu/KernelGenerator.cc b/runtime/onert/backend/cpu/KernelGenerator.cc similarity index 79% rename from runtime/neurun/backend/cpu/KernelGenerator.cc rename to runtime/onert/backend/cpu/KernelGenerator.cc index 87d95cdb4b7..e65c37cba3a 100644 --- a/runtime/neurun/backend/cpu/KernelGenerator.cc +++ b/runtime/onert/backend/cpu/KernelGenerator.cc @@ -16,6 +16,7 @@ #include "KernelGenerator.h" +#include "kernel/AbsLayer.h" #include "kernel/AddLayer.h" #include "kernel/AvgPoolLayer.h" #include "kernel/CastLayer.h" @@ -39,8 +40,12 @@ #include "kernel/PermuteLayer.h" #include "kernel/ReduceLayer.h" #include "kernel/ReshapeLayer.h" +#include "kernel/RsqrtLayer.h" +#include "kernel/SinLayer.h" #include "kernel/SliceLayer.h" #include "kernel/SoftMaxLayer.h" +#include "kernel/StridedSliceLayer.h" +#include "kernel/SplitLayer.h" #include "kernel/SubLayer.h" #include "kernel/TanhLayer.h" #include "kernel/TransposeLayer.h" @@ -54,7 +59,7 @@ #include -namespace neurun +namespace onert { namespace backend { @@ -124,7 +129,7 @@ void KernelGenerator::visit(const ir::operation::Conv2D &node) auto ker_alloc = _tensor_builder->at(ker_index).get(); auto bias_alloc = _tensor_builder->at(bias_index).get(); - auto fn = std::make_unique<::neurun::backend::cpu::kernel::ConvolutionLayer>(); + auto fn = std::make_unique<::onert::backend::cpu::kernel::ConvolutionLayer>(); fn->configure(ifm_alloc, ker_alloc, bias_alloc, padding_type, padding.left, padding.right, padding.top, padding.bottom, stride.horizontal, stride.vertical, activation, @@ -159,7 +164,7 @@ void KernelGenerator::visit(const ir::operation::DepthwiseConv2D &node) auto ker_alloc = _tensor_builder->at(ker_index).get(); auto bias_alloc = _tensor_builder->at(bias_index).get(); - auto fn = std::make_unique<::neurun::backend::cpu::kernel::DepthwiseConvolutionLayer>(); + auto fn = std::make_unique<::onert::backend::cpu::kernel::DepthwiseConvolutionLayer>(); fn->configure(ifm_alloc, ker_alloc, bias_alloc, padding.left, padding.right, padding.top, padding.bottom, stride.horizontal, stride.vertical, multiplier, activation, @@ -186,7 +191,7 @@ void KernelGenerator::visit(const ir::operation::MaxPool2D &node) auto ofm_alloc = _tensor_builder->at(ofm_index).get(); auto ifm_alloc = _tensor_builder->at(ifm_index).get(); - auto fn = std::make_unique<::neurun::backend::cpu::kernel::MaxPoolLayer>(); + auto fn = std::make_unique<::onert::backend::cpu::kernel::MaxPoolLayer>(); fn->configure(ifm_alloc, padding.left, padding.right, padding.top, padding.bottom, stride.horizontal, stride.vertical, kw, kh, activation, ofm_alloc); @@ -211,7 +216,7 @@ void KernelGenerator::visit(const ir::operation::AvgPool2D &node) auto ofm_alloc = _tensor_builder->at(ofm_index).get(); auto ifm_alloc = _tensor_builder->at(ifm_index).get(); - auto fn = std::make_unique<::neurun::backend::cpu::kernel::AvgPoolLayer>(); + auto fn = std::make_unique<::onert::backend::cpu::kernel::AvgPoolLayer>(); fn->configure(ifm_alloc, padding.left, padding.right, padding.top, padding.bottom, stride.horizontal, stride.vertical, kw, kh, activation, ofm_alloc); @@ -225,7 +230,7 @@ void KernelGenerator::visit(const ir::operation::Concat &node) const auto rank = _ctx.at(ofm_index).shape().rank(); const auto axis = - ::neurun::backend::cpu::kernel::getAxis(rank, node.param().axis, _current_op_seq_layout); + ::onert::backend::cpu::kernel::getAxis(rank, node.param().axis, _current_op_seq_layout); auto output_alloc = _tensor_builder->at(ofm_index).get(); @@ -233,7 +238,7 @@ void KernelGenerator::visit(const ir::operation::Concat &node) for (auto &ifm_idx : node.getInputs()) input_tensors.emplace_back(_tensor_builder->at(ifm_idx).get()); - auto fn = std::make_unique<::neurun::backend::cpu::kernel::ConcatLayer>(); + auto fn = std::make_unique<::onert::backend::cpu::kernel::ConcatLayer>(); fn->configure(input_tensors, axis, output_alloc); @@ -255,7 +260,7 @@ void KernelGenerator::visit(const ir::operation::FullyConnected &node) auto weight_alloc = _tensor_builder->at(weight_index).get(); auto bias_alloc = _tensor_builder->at(bias_index).get(); - auto fn = std::make_unique<::neurun::backend::cpu::kernel::FullyConnectedLayer>(); + auto fn = std::make_unique<::onert::backend::cpu::kernel::FullyConnectedLayer>(); fn->configure(input_alloc, weight_alloc, bias_alloc, activation, output_alloc); @@ -270,10 +275,18 @@ void KernelGenerator::visit(const ir::operation::Reshape &node) auto output_alloc = _tensor_builder->at(output_index).get(); auto input_alloc = _tensor_builder->at(input_index).get(); - auto fn = std::make_unique<::neurun::backend::cpu::kernel::ReshapeLayer>(); + // optional 2nd input + operand::Tensor *shape_alloc = nullptr; - fn->configure(input_alloc, output_alloc); + if (node.getInputs().size() == 2) + { + const auto shape_index{node.getInputs().at(ir::operation::Reshape::Input::SHAPE)}; + shape_alloc = _tensor_builder->at(shape_index).get(); + } + auto fn = std::make_unique<::onert::backend::cpu::kernel::ReshapeLayer>(); + + fn->configure(input_alloc, shape_alloc, output_alloc); _return_fn = std::move(fn); } @@ -286,9 +299,9 @@ void KernelGenerator::visit(const ir::operation::Squeeze &node) auto input_alloc = _tensor_builder->at(input_index).get(); // Squeeze can share same kernel with reshape - auto fn = std::make_unique<::neurun::backend::cpu::kernel::ReshapeLayer>(); + auto fn = std::make_unique<::onert::backend::cpu::kernel::ReshapeLayer>(); - fn->configure(input_alloc, output_alloc); + fn->configure(input_alloc, nullptr, output_alloc); _return_fn = std::move(fn); } @@ -303,7 +316,7 @@ void KernelGenerator::visit(const ir::operation::Softmax &node) auto output_alloc = _tensor_builder->at(output_index).get(); auto input_alloc = _tensor_builder->at(input_index).get(); - auto fn = std::make_unique<::neurun::backend::cpu::kernel::SoftMaxLayer>(); + auto fn = std::make_unique<::onert::backend::cpu::kernel::SoftMaxLayer>(); fn->configure(input_alloc, beta, output_alloc); @@ -322,7 +335,7 @@ void KernelGenerator::visit(const ir::operation::Add &node) auto lhs_alloc = _tensor_builder->at(lhs_index).get(); auto rhs_alloc = _tensor_builder->at(rhs_index).get(); - auto fn = std::make_unique<::neurun::backend::cpu::kernel::AddLayer>(); + auto fn = std::make_unique<::onert::backend::cpu::kernel::AddLayer>(); fn->configure(lhs_alloc, rhs_alloc, activation, ofm_alloc); @@ -341,7 +354,7 @@ void KernelGenerator::visit(const ir::operation::Comparison &node) auto comparison_type = node.param().comparison_type; - auto fn = std::make_unique<::neurun::backend::cpu::kernel::CompareLayer>(); + auto fn = std::make_unique<::onert::backend::cpu::kernel::CompareLayer>(); fn->configure(lhs_alloc, rhs_alloc, comparison_type, ofm_alloc); @@ -378,7 +391,7 @@ void KernelGenerator::visit(const ir::operation::Gather &node) const auto axis_raw = node.param().axis; const auto axis_value = (axis_raw < 0 ? (input_shape.rank() + axis_raw) : axis_raw); - auto fn = std::make_unique<::neurun::backend::cpu::kernel::GatherLayer>(); + auto fn = std::make_unique<::onert::backend::cpu::kernel::GatherLayer>(); fn->configure(input_alloc, indices_alloc, output_alloc, axis_value); @@ -398,7 +411,7 @@ void KernelGenerator::visit(const ir::operation::Sub &node) auto lhs_alloc = _tensor_builder->at(lhs_index).get(); auto rhs_alloc = _tensor_builder->at(rhs_index).get(); - auto fn = std::make_unique<::neurun::backend::cpu::kernel::SubLayer>(); + auto fn = std::make_unique<::onert::backend::cpu::kernel::SubLayer>(); fn->configure(lhs_alloc, rhs_alloc, activation, ofm_alloc); @@ -409,8 +422,8 @@ void KernelGenerator::visit(const ir::operation::Mul &node) { // The same as Add const auto ofm_index{node.getOutputs().at(0)}; - const auto lhs_index{node.getInputs().at(ir::operation::Sub::Input::LHS)}; - const auto rhs_index{node.getInputs().at(ir::operation::Sub::Input::RHS)}; + const auto lhs_index{node.getInputs().at(ir::operation::Mul::Input::LHS)}; + const auto rhs_index{node.getInputs().at(ir::operation::Mul::Input::RHS)}; const auto activation = node.param().activation; @@ -418,7 +431,7 @@ void KernelGenerator::visit(const ir::operation::Mul &node) auto lhs_alloc = _tensor_builder->at(lhs_index).get(); auto rhs_alloc = _tensor_builder->at(rhs_index).get(); - auto fn = std::make_unique<::neurun::backend::cpu::kernel::MulLayer>(); + auto fn = std::make_unique<::onert::backend::cpu::kernel::MulLayer>(); fn->configure(lhs_alloc, rhs_alloc, activation, ofm_alloc); @@ -441,7 +454,7 @@ void KernelGenerator::visit(const ir::operation::OneHot &node) assert(indices_alloc->data_type() == OperandType::INT32); assert(axis <= static_cast(indices_alloc->num_dimensions())); - auto fn = std::make_unique<::neurun::backend::cpu::kernel::OneHotLayer>(); + auto fn = std::make_unique<::onert::backend::cpu::kernel::OneHotLayer>(); fn->configure(indices_alloc, output_alloc, depth, on_value, off_value, axis); @@ -452,8 +465,8 @@ void KernelGenerator::visit(const ir::operation::Div &node) { // The same as Add const auto ofm_index{node.getOutputs().at(0)}; - const auto lhs_index{node.getInputs().at(ir::operation::Sub::Input::LHS)}; - const auto rhs_index{node.getInputs().at(ir::operation::Sub::Input::RHS)}; + const auto lhs_index{node.getInputs().at(ir::operation::Div::Input::LHS)}; + const auto rhs_index{node.getInputs().at(ir::operation::Div::Input::RHS)}; const auto activation = node.param().activation; @@ -461,7 +474,7 @@ void KernelGenerator::visit(const ir::operation::Div &node) auto lhs_alloc = _tensor_builder->at(lhs_index).get(); auto rhs_alloc = _tensor_builder->at(rhs_index).get(); - auto fn = std::make_unique<::neurun::backend::cpu::kernel::DivLayer>(); + auto fn = std::make_unique<::onert::backend::cpu::kernel::DivLayer>(); fn->configure(lhs_alloc, rhs_alloc, activation, ofm_alloc); @@ -483,7 +496,7 @@ void KernelGenerator::visit(const ir::operation::Permute &node) assert(output_tensor != nullptr); assert(input_tensor != nullptr); - auto fn = std::make_unique<::neurun::backend::cpu::kernel::PermuteLayer>(); + auto fn = std::make_unique<::onert::backend::cpu::kernel::PermuteLayer>(); // TODO Support NCHW frontend auto out_shape = shape; @@ -521,7 +534,7 @@ void KernelGenerator::visit(const ir::operation::Permute &node) void KernelGenerator::visit(const ir::operation::Custom &node) { - auto get_type_info = [this](const ir::Operand &operand) -> custom::TypeInfo { + auto get_type_info = [](const ir::Operand &operand) -> custom::TypeInfo { const auto &frontend_shape = operand.shape(); custom::Shape shape(frontend_shape.rank()); for (auto d = 0; d < frontend_shape.rank(); ++d) @@ -565,7 +578,7 @@ void KernelGenerator::visit(const ir::operation::Exp &node) auto output_alloc = _tensor_builder->at(output_index).get(); auto input_alloc = _tensor_builder->at(input_index).get(); - auto fn = std::make_unique<::neurun::backend::cpu::kernel::ExpLayer>(); + auto fn = std::make_unique<::onert::backend::cpu::kernel::ExpLayer>(); fn->configure(input_alloc, output_alloc); @@ -580,7 +593,7 @@ void KernelGenerator::visit(const ir::operation::Logistic &node) auto output_alloc = _tensor_builder->at(output_index).get(); auto input_alloc = _tensor_builder->at(input_index).get(); - auto fn = std::make_unique<::neurun::backend::cpu::kernel::LogisticLayer>(); + auto fn = std::make_unique<::onert::backend::cpu::kernel::LogisticLayer>(); fn->configure(input_alloc, output_alloc); @@ -595,7 +608,7 @@ void KernelGenerator::visit(const ir::operation::Tanh &node) auto output_alloc = _tensor_builder->at(output_index).get(); auto input_alloc = _tensor_builder->at(input_index).get(); - auto fn = std::make_unique<::neurun::backend::cpu::kernel::TanhLayer>(); + auto fn = std::make_unique<::onert::backend::cpu::kernel::TanhLayer>(); fn->configure(input_alloc, output_alloc); @@ -608,7 +621,7 @@ void KernelGenerator::visit(const ir::operation::Pack &node) const auto rank = node.param().rank; const auto axis = - ::neurun::backend::cpu::kernel::getAxis(rank, node.param().axis, _current_op_seq_layout); + ::onert::backend::cpu::kernel::getAxis(rank, node.param().axis, _current_op_seq_layout); assert(-rank <= axis && axis < rank); @@ -618,7 +631,7 @@ void KernelGenerator::visit(const ir::operation::Pack &node) for (auto &ifm_idx : node.getInputs()) input_tensors.emplace_back(_tensor_builder->at(ifm_idx).get()); - auto fn = std::make_unique<::neurun::backend::cpu::kernel::PackLayer>(); + auto fn = std::make_unique<::onert::backend::cpu::kernel::PackLayer>(); fn->configure(input_tensors, axis, output_alloc); @@ -631,7 +644,7 @@ void KernelGenerator::visit(const ir::operation::Unpack &node) const auto rank = node.param().rank; const auto axis = - ::neurun::backend::cpu::kernel::getAxis(rank, node.param().axis, _current_op_seq_layout); + ::onert::backend::cpu::kernel::getAxis(rank, node.param().axis, _current_op_seq_layout); assert(-rank <= axis && axis < rank); @@ -641,7 +654,7 @@ void KernelGenerator::visit(const ir::operation::Unpack &node) for (auto &output_idx : node.getOutputs()) output_tensors.emplace_back(_tensor_builder->at(output_idx).get()); - auto fn = std::make_unique<::neurun::backend::cpu::kernel::UnpackLayer>(); + auto fn = std::make_unique<::onert::backend::cpu::kernel::UnpackLayer>(); uint32_t axis_resolved = (axis < 0 ? axis + rank : axis); @@ -662,7 +675,7 @@ void KernelGenerator::visit(const ir::operation::Pad &node) auto pad_rank = _ctx.at(pad_index).shape().dim(0); auto pad_base = reinterpret_cast(_ctx.at(pad_index).data()->base()); - auto fn = std::make_unique<::neurun::backend::cpu::kernel::PadLayer>(); + auto fn = std::make_unique<::onert::backend::cpu::kernel::PadLayer>(); fn->configure(input, output, pad_base, pad_rank); @@ -679,7 +692,7 @@ void KernelGenerator::visit(const ir::operation::Max &node) auto lhs_alloc = _tensor_builder->at(lhs_index).get(); auto rhs_alloc = _tensor_builder->at(rhs_index).get(); - auto fn = std::make_unique<::neurun::backend::cpu::kernel::MaxLayer>(); + auto fn = std::make_unique<::onert::backend::cpu::kernel::MaxLayer>(); fn->configure(lhs_alloc, rhs_alloc, ofm_alloc); @@ -696,7 +709,7 @@ void KernelGenerator::visit(const ir::operation::Min &node) auto lhs_alloc = _tensor_builder->at(lhs_index).get(); auto rhs_alloc = _tensor_builder->at(rhs_index).get(); - auto fn = std::make_unique<::neurun::backend::cpu::kernel::MinLayer>(); + auto fn = std::make_unique<::onert::backend::cpu::kernel::MinLayer>(); fn->configure(lhs_alloc, rhs_alloc, ofm_alloc); @@ -711,7 +724,7 @@ void KernelGenerator::visit(const ir::operation::Cast &node) auto ofm_alloc = _tensor_builder->at(ofm_index).get(); auto ifm_alloc = _tensor_builder->at(ifm_index).get(); - auto fn = std::make_unique<::neurun::backend::cpu::kernel::CastLayer>(); + auto fn = std::make_unique<::onert::backend::cpu::kernel::CastLayer>(); fn->configure(ifm_alloc, ofm_alloc); @@ -727,7 +740,7 @@ void KernelGenerator::visit(const ir::operation::Transpose &node) auto input_alloc = _tensor_builder->at(input_index).get(); auto rank = node.param().rank; - auto fn = std::make_unique<::neurun::backend::cpu::kernel::TransposeLayer>(); + auto fn = std::make_unique<::onert::backend::cpu::kernel::TransposeLayer>(); fn->configure(input_alloc, output_alloc, node.param().perm, rank); @@ -794,13 +807,110 @@ void KernelGenerator::visit(const ir::operation::Slice &node) auto begins_alloc = _tensor_builder->at(begins_index).get(); auto sizes_alloc = _tensor_builder->at(sizes_index).get(); - auto fn = std::make_unique<::neurun::backend::cpu::kernel::SliceLayer>(); + auto fn = std::make_unique<::onert::backend::cpu::kernel::SliceLayer>(); fn->configure(input_alloc, begins_alloc, sizes_alloc, output_alloc); _return_fn = std::move(fn); } +void KernelGenerator::visit(const ir::operation::StridedSlice &node) +{ + const auto output_index{node.getOutputs().at(0)}; + const auto input_index{node.getInputs().at(ir::operation::StridedSlice::Input::INPUT)}; + const auto starts_index{node.getInputs().at(ir::operation::StridedSlice::Input::STARTS)}; + const auto ends_index{node.getInputs().at(ir::operation::StridedSlice::Input::ENDS)}; + const auto strides_index{node.getInputs().at(ir::operation::StridedSlice::Input::STRIDES)}; + + auto output_alloc = _tensor_builder->at(output_index).get(); + auto input_alloc = _tensor_builder->at(input_index).get(); + auto starts_alloc = _tensor_builder->at(starts_index).get(); + auto ends_alloc = _tensor_builder->at(ends_index).get(); + auto strides_alloc = _tensor_builder->at(strides_index).get(); + + auto begin_mask = node.param().begin_mask; + auto end_mask = node.param().end_mask; + auto shrink_axis_mask = node.param().shrink_axis_mask; + auto rank = node.param().rank; + + auto fn = std::make_unique<::onert::backend::cpu::kernel::StridedSliceLayer>(); + + fn->configure(input_alloc, starts_alloc, ends_alloc, strides_alloc, output_alloc, begin_mask, + end_mask, shrink_axis_mask, rank); + + _return_fn = std::move(fn); +} + +void KernelGenerator::visit(const ir::operation::Split &node) +{ + const auto num_splits = node.param().num_splits; + assert(num_splits == static_cast(node.getOutputs().size())); + + const auto rank = node.param().rank; + const auto axis = + ::onert::backend::cpu::kernel::getAxis(rank, node.param().axis, _current_op_seq_layout); + auto axis_resolved = axis < 0 ? axis + rank : axis; + assert(0 <= axis_resolved && axis_resolved < rank); + + const auto input_idx{node.getInputs().at(ir::operation::Split::Input::INPUT)}; + auto in_tensor = _tensor_builder->at(input_idx).get(); + + std::vector out_tensors; + for (auto &output_idx : node.getOutputs()) + out_tensors.emplace_back(_tensor_builder->at(output_idx).get()); + + auto fn = std::make_unique<::onert::backend::cpu::kernel::SplitLayer>(); + + fn->configure(in_tensor, num_splits, axis_resolved, out_tensors); + + _return_fn = std::move(fn); +} + +void KernelGenerator::visit(const ir::operation::Abs &node) +{ + const auto ofm_index{node.getOutputs().at(0)}; + const auto ifm_index{node.getInputs().at(ir::operation::Abs::Input::INPUT)}; + + auto ofm_alloc = _tensor_builder->at(ofm_index).get(); + auto ifm_alloc = _tensor_builder->at(ifm_index).get(); + + auto fn = std::make_unique<::onert::backend::cpu::kernel::AbsLayer>(); + + fn->configure(ifm_alloc, ofm_alloc); + + _return_fn = std::move(fn); +} + +void KernelGenerator::visit(const ir::operation::Sin &node) +{ + const auto ofm_index{node.getOutputs().at(0)}; + const auto ifm_index{node.getInputs().at(ir::operation::Sin::Input::INPUT)}; + + auto ofm_alloc = _tensor_builder->at(ofm_index).get(); + auto ifm_alloc = _tensor_builder->at(ifm_index).get(); + + auto fn = std::make_unique<::onert::backend::cpu::kernel::SinLayer>(); + + fn->configure(ifm_alloc, ofm_alloc); + + _return_fn = std::move(fn); +} + +void KernelGenerator::visit(const ir::operation::RSQRT &node) +{ + const auto ofm_index{node.getOutputs().at(0)}; + const auto ifm_index{node.getInputs().at(ir::operation::RSQRT::Input::INPUT)}; + + auto ofm_alloc = _tensor_builder->at(ofm_index).get(); + auto ifm_alloc = _tensor_builder->at(ifm_index).get(); + + auto fn = std::make_unique<::onert::backend::cpu::kernel::RsqrtLayer>(); + + fn->configure(ifm_alloc, ofm_alloc); + + _return_fn = std::move(fn); +} + } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/cpu/KernelGenerator.h b/runtime/onert/backend/cpu/KernelGenerator.h similarity index 87% rename from runtime/neurun/backend/cpu/KernelGenerator.h rename to runtime/onert/backend/cpu/KernelGenerator.h index dde17e26d02..bcb0ed657a9 100644 --- a/runtime/neurun/backend/cpu/KernelGenerator.h +++ b/runtime/onert/backend/cpu/KernelGenerator.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_CPU_KERNEL_GENERATOR_H__ -#define __NEURUN_BACKEND_CPU_KERNEL_GENERATOR_H__ +#ifndef __ONERT_BACKEND_CPU_KERNEL_GENERATOR_H__ +#define __ONERT_BACKEND_CPU_KERNEL_GENERATOR_H__ #include "TensorBuilder.h" #include "operand/Tensor.h" @@ -24,7 +24,7 @@ #include #include -namespace neurun +namespace onert { namespace backend { @@ -72,6 +72,11 @@ class KernelGenerator : public IKernelGenerator void visit(const ir::operation::ReduceMax &) override; void visit(const ir::operation::ReduceMin &) override; void visit(const ir::operation::Slice &) override; + void visit(const ir::operation::StridedSlice &) override; + void visit(const ir::operation::Split &) override; + void visit(const ir::operation::Abs &) override; + void visit(const ir::operation::Sin &) override; + void visit(const ir::operation::RSQRT &) override; private: const ir::Operands &_ctx; @@ -82,6 +87,6 @@ class KernelGenerator : public IKernelGenerator } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_CPU_KERNEL_GENERATOR_H__ +#endif // __ONERT_BACKEND_CPU_KERNEL_GENERATOR_H__ diff --git a/runtime/neurun/backend/cpu/ShapeFixer.cc b/runtime/onert/backend/cpu/ShapeFixer.cc similarity index 92% rename from runtime/neurun/backend/cpu/ShapeFixer.cc rename to runtime/onert/backend/cpu/ShapeFixer.cc index cba3965433c..224360a8920 100644 --- a/runtime/neurun/backend/cpu/ShapeFixer.cc +++ b/runtime/onert/backend/cpu/ShapeFixer.cc @@ -42,7 +42,7 @@ #include -namespace neurun +namespace onert { namespace backend { @@ -164,6 +164,16 @@ void ShapeFixer::visit(const ir::operation::ReduceMin &) { /* DO NOTHING */} void ShapeFixer::visit(const ir::operation::Slice &) { /* DO NOTHING */} +void ShapeFixer::visit(const ir::operation::StridedSlice &) { /* DO NOTHING */} + +void ShapeFixer::visit(const ir::operation::Split &) { /* DO NOTHING */} + +void ShapeFixer::visit(const ir::operation::Abs &) { /* DO NOTHING */} + +void ShapeFixer::visit(const ir::operation::Sin &) { /* DO NOTHING */} + +void ShapeFixer::visit(const ir::operation::RSQRT &) { /* DO NOTHING */} + } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/cpu/ShapeFixer.h b/runtime/onert/backend/cpu/ShapeFixer.h similarity index 86% rename from runtime/neurun/backend/cpu/ShapeFixer.h rename to runtime/onert/backend/cpu/ShapeFixer.h index d6ed1b3288d..1a888ed4ed1 100644 --- a/runtime/neurun/backend/cpu/ShapeFixer.h +++ b/runtime/onert/backend/cpu/ShapeFixer.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_CPU_SHAPE_FIXER_H__ -#define __NEURUN_BACKEND_CPU_SHAPE_FIXER_H__ +#ifndef __ONERT_BACKEND_CPU_SHAPE_FIXER_H__ +#define __ONERT_BACKEND_CPU_SHAPE_FIXER_H__ #include "TensorBuilder.h" #include "operand/Tensor.h" @@ -23,7 +23,7 @@ #include #include -namespace neurun +namespace onert { namespace backend { @@ -67,6 +67,11 @@ class ShapeFixer : public IShapeFixer void visit(const ir::operation::ReduceMax &) override; void visit(const ir::operation::ReduceMin &) override; void visit(const ir::operation::Slice &) override; + void visit(const ir::operation::StridedSlice &) override; + void visit(const ir::operation::Split &) override; + void visit(const ir::operation::Abs &) override; + void visit(const ir::operation::Sin &) override; + void visit(const ir::operation::RSQRT &) override; private: const ir::Operands &_ctx; @@ -74,6 +79,6 @@ class ShapeFixer : public IShapeFixer } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_CPU_SHAPE_FIXER_H__ +#endif // __ONERT_BACKEND_CPU_SHAPE_FIXER_H__ diff --git a/runtime/neurun/backend/cpu/TensorBuilder.cc b/runtime/onert/backend/cpu/TensorBuilder.cc similarity index 98% rename from runtime/neurun/backend/cpu/TensorBuilder.cc rename to runtime/onert/backend/cpu/TensorBuilder.cc index 8cb179a02d5..cbf7c9e5c20 100644 --- a/runtime/neurun/backend/cpu/TensorBuilder.cc +++ b/runtime/onert/backend/cpu/TensorBuilder.cc @@ -20,7 +20,7 @@ #include -namespace neurun +namespace onert { namespace backend { @@ -90,4 +90,4 @@ std::unique_ptr TensorBuilder::releaseTensorManager(void) } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/cpu/TensorBuilder.h b/runtime/onert/backend/cpu/TensorBuilder.h similarity index 91% rename from runtime/neurun/backend/cpu/TensorBuilder.h rename to runtime/onert/backend/cpu/TensorBuilder.h index eb612038ef1..863eb77e247 100644 --- a/runtime/neurun/backend/cpu/TensorBuilder.h +++ b/runtime/onert/backend/cpu/TensorBuilder.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_CPU_TENSOR_BUILDER_H__ -#define __NEURUN_BACKEND_CPU_TENSOR_BUILDER_H__ +#ifndef __ONERT_BACKEND_CPU_TENSOR_BUILDER_H__ +#define __ONERT_BACKEND_CPU_TENSOR_BUILDER_H__ #include "TensorManager.h" #include "operand/Tensor.h" @@ -25,7 +25,7 @@ #include -namespace neurun +namespace onert { namespace backend { @@ -71,6 +71,6 @@ class TensorBuilder : public ITensorBuilder } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_CPU_TENSOR_BUILDER_H__ +#endif // __ONERT_BACKEND_CPU_TENSOR_BUILDER_H__ diff --git a/runtime/neurun/backend/cpu/TensorManager.cc b/runtime/onert/backend/cpu/TensorManager.cc similarity index 98% rename from runtime/neurun/backend/cpu/TensorManager.cc rename to runtime/onert/backend/cpu/TensorManager.cc index 77286e72af6..96071bc51a8 100644 --- a/runtime/neurun/backend/cpu/TensorManager.cc +++ b/runtime/onert/backend/cpu/TensorManager.cc @@ -18,7 +18,7 @@ #include -namespace neurun +namespace onert { namespace backend { @@ -111,4 +111,4 @@ void TensorManager::iterate(const std::function } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/cpu/TensorManager.h b/runtime/onert/backend/cpu/TensorManager.h similarity index 90% rename from runtime/neurun/backend/cpu/TensorManager.h rename to runtime/onert/backend/cpu/TensorManager.h index 2de0329fcdf..ab1eec3fc15 100644 --- a/runtime/neurun/backend/cpu/TensorManager.h +++ b/runtime/onert/backend/cpu/TensorManager.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_CPU_TENSOR_MANAGER_H__ -#define __NEURUN_BACKEND_CPU_TENSOR_MANAGER_H__ +#ifndef __ONERT_BACKEND_CPU_TENSOR_MANAGER_H__ +#define __ONERT_BACKEND_CPU_TENSOR_MANAGER_H__ #include "MemoryManager.h" #include "operand/Tensor.h" @@ -24,7 +24,7 @@ #include #include -namespace neurun +namespace onert { namespace backend { @@ -60,6 +60,6 @@ class TensorManager : public backend::ITensorManager } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_CPU_TENSOR_MANAGER_H__ +#endif // __ONERT_BACKEND_CPU_TENSOR_MANAGER_H__ diff --git a/runtime/neurun/backend/cpu/cpu.cc b/runtime/onert/backend/cpu/cpu.cc similarity index 73% rename from runtime/neurun/backend/cpu/cpu.cc rename to runtime/onert/backend/cpu/cpu.cc index 8e5403dc0cd..5385bb2a3c4 100644 --- a/runtime/neurun/backend/cpu/cpu.cc +++ b/runtime/onert/backend/cpu/cpu.cc @@ -19,15 +19,15 @@ #include extern "C" { -neurun::backend::Backend *neurun_backend_create() +onert::backend::Backend *onert_backend_create() { - VERBOSE(neurun_backend_create) << "'cpu' loaded\n"; - return new neurun::backend::cpu::Backend; + VERBOSE(onert_backend_create) << "'cpu' loaded\n"; + return new onert::backend::cpu::Backend; } -void neurun_backend_destroy(neurun::backend::Backend *backend) +void onert_backend_destroy(onert::backend::Backend *backend) { - VERBOSE(neurun_backend_create) << "'cpu' unloaded\n"; + VERBOSE(onert_backend_create) << "'cpu' unloaded\n"; delete backend; } } diff --git a/runtime/onert/backend/cpu/kernel/AbsLayer.cc b/runtime/onert/backend/cpu/kernel/AbsLayer.cc new file mode 100644 index 00000000000..77038682643 --- /dev/null +++ b/runtime/onert/backend/cpu/kernel/AbsLayer.cc @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2020 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 "AbsLayer.h" + +#include "OperationUtils.h" + +#include + +namespace onert +{ +namespace backend +{ +namespace cpu +{ +namespace kernel +{ + +AbsLayer::AbsLayer() : _input(nullptr), _output(nullptr) +{ + // DO NOTHING +} + +void AbsLayer::absFloat32() +{ + nnfw::cker::Abs(convertTensorToCkerShape(_input), + reinterpret_cast(_input->buffer()), + convertTensorToCkerShape(_output), reinterpret_cast(_output->buffer())); +} + +void AbsLayer::absQuant8() { throw std::runtime_error{"NYI"}; } + +void AbsLayer::configure(const operand::Tensor *input, operand::Tensor *output) +{ + _input = input; + _output = output; +} + +void AbsLayer::run() +{ + if (_input->data_type() == OperandType::FLOAT32) + { + absFloat32(); + } + else if (_input->data_type() == OperandType::QUANT8_ASYMM) + { + absQuant8(); + } +} + +} // namespace kernel +} // namespace cpu +} // namespace backend +} // namespace onert diff --git a/runtime/onert/backend/cpu/kernel/AbsLayer.h b/runtime/onert/backend/cpu/kernel/AbsLayer.h new file mode 100644 index 00000000000..551782a4587 --- /dev/null +++ b/runtime/onert/backend/cpu/kernel/AbsLayer.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2020 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 riting, 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 __ONERT_BACKEND_CPU_KERNEL_ABSLAYER_H__ +#define __ONERT_BACKEND_CPU_KERNEL_ABSLAYER_H__ + +#include "../operand/Tensor.h" + +#include + +namespace onert +{ +namespace backend +{ +namespace cpu +{ +namespace kernel +{ + +class AbsLayer : public ::onert::exec::IFunction +{ +public: + AbsLayer(); + +public: + void absFloat32(); + + void absQuant8(); + + void configure(const operand::Tensor *input, operand::Tensor *output); + + void run(); + void runSync() + { + // this abstract method is used just for profiling and called for + // backend::acl_common::AclFunction + run(); + } + +private: + const operand::Tensor *_input; + operand::Tensor *_output; +}; + +} // namespace kernel +} // namespace cpu +} // namespace backend +} // namespace onert + +#endif // __ONERT_BACKEND_CPU_KERNEL_ABSLAYER_H__ diff --git a/runtime/neurun/backend/cpu/kernel/AddLayer.cc b/runtime/onert/backend/cpu/kernel/AddLayer.cc similarity index 98% rename from runtime/neurun/backend/cpu/kernel/AddLayer.cc rename to runtime/onert/backend/cpu/kernel/AddLayer.cc index e8dfdb26a47..51320907d34 100644 --- a/runtime/neurun/backend/cpu/kernel/AddLayer.cc +++ b/runtime/onert/backend/cpu/kernel/AddLayer.cc @@ -18,7 +18,7 @@ #include -namespace neurun +namespace onert { namespace backend { @@ -93,4 +93,4 @@ void AddLayer::run() } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/cpu/kernel/AddLayer.h b/runtime/onert/backend/cpu/kernel/AddLayer.h similarity index 86% rename from runtime/neurun/backend/cpu/kernel/AddLayer.h rename to runtime/onert/backend/cpu/kernel/AddLayer.h index f742f08cae8..657decc727d 100644 --- a/runtime/neurun/backend/cpu/kernel/AddLayer.h +++ b/runtime/onert/backend/cpu/kernel/AddLayer.h @@ -14,15 +14,15 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_CPU_KERNEL_ADDLAYER_H__ -#define __NEURUN_BACKEND_CPU_KERNEL_ADDLAYER_H__ +#ifndef __ONERT_BACKEND_CPU_KERNEL_ADDLAYER_H__ +#define __ONERT_BACKEND_CPU_KERNEL_ADDLAYER_H__ #include "../operand/Tensor.h" #include "OperationUtils.h" #include -namespace neurun +namespace onert { namespace backend { @@ -31,7 +31,7 @@ namespace cpu namespace kernel { -class AddLayer : public ::neurun::exec::IFunction +class AddLayer : public ::onert::exec::IFunction { public: AddLayer() : _lhs(nullptr), _rhs(nullptr), _output(nullptr) @@ -66,6 +66,6 @@ class AddLayer : public ::neurun::exec::IFunction } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_CPU_KERNEL_ADDLAYER_H__ +#endif // __ONERT_BACKEND_CPU_KERNEL_ADDLAYER_H__ diff --git a/runtime/neurun/backend/cpu/kernel/AvgPoolLayer.cc b/runtime/onert/backend/cpu/kernel/AvgPoolLayer.cc similarity index 99% rename from runtime/neurun/backend/cpu/kernel/AvgPoolLayer.cc rename to runtime/onert/backend/cpu/kernel/AvgPoolLayer.cc index f0e1c2e191a..ba11b7cdef9 100644 --- a/runtime/neurun/backend/cpu/kernel/AvgPoolLayer.cc +++ b/runtime/onert/backend/cpu/kernel/AvgPoolLayer.cc @@ -18,7 +18,7 @@ #include -namespace neurun +namespace onert { namespace backend { @@ -113,4 +113,4 @@ void AvgPoolLayer::run() } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/cpu/kernel/AvgPoolLayer.h b/runtime/onert/backend/cpu/kernel/AvgPoolLayer.h similarity index 87% rename from runtime/neurun/backend/cpu/kernel/AvgPoolLayer.h rename to runtime/onert/backend/cpu/kernel/AvgPoolLayer.h index 67760491479..7d7ef980ddd 100644 --- a/runtime/neurun/backend/cpu/kernel/AvgPoolLayer.h +++ b/runtime/onert/backend/cpu/kernel/AvgPoolLayer.h @@ -14,15 +14,15 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_CPU_KERNEL_AVGPOOLLAYER_H__ -#define __NEURUN_BACKEND_CPU_KERNEL_AVGPOOLLAYER_H__ +#ifndef __ONERT_BACKEND_CPU_KERNEL_AVGPOOLLAYER_H__ +#define __ONERT_BACKEND_CPU_KERNEL_AVGPOOLLAYER_H__ #include "../operand/Tensor.h" #include "OperationUtils.h" #include -namespace neurun +namespace onert { namespace backend { @@ -31,7 +31,7 @@ namespace cpu namespace kernel { -class AvgPoolLayer : public ::neurun::exec::IFunction +class AvgPoolLayer : public ::onert::exec::IFunction { public: AvgPoolLayer(); @@ -76,6 +76,6 @@ class AvgPoolLayer : public ::neurun::exec::IFunction } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_CPU_KERNEL_AVGPOOLLAYER_H__ +#endif // __ONERT_BACKEND_CPU_KERNEL_AVGPOOLLAYER_H__ diff --git a/runtime/neurun/backend/cpu/kernel/CastLayer.cc b/runtime/onert/backend/cpu/kernel/CastLayer.cc similarity index 89% rename from runtime/neurun/backend/cpu/kernel/CastLayer.cc rename to runtime/onert/backend/cpu/kernel/CastLayer.cc index 5c24671a013..e485e04c778 100644 --- a/runtime/neurun/backend/cpu/kernel/CastLayer.cc +++ b/runtime/onert/backend/cpu/kernel/CastLayer.cc @@ -16,7 +16,7 @@ #include "CastLayer.h" -namespace neurun +namespace onert { namespace backend { @@ -66,7 +66,8 @@ template void CastLayer::castPtr(const FromT *in, DataPtr out) return; case ir::DataType::QUANT8_ASYMM: case ir::DataType::QUANT8_SYMM: - throw std::runtime_error("Not supported output type" + (int)_output->data_type()); + throw std::runtime_error("Not supported output type" + + std::to_string((int)_output->data_type())); } } @@ -96,11 +97,12 @@ void CastLayer::run() return; case ir::DataType::QUANT8_ASYMM: case ir::DataType::QUANT8_SYMM: - throw std::runtime_error("Not supported input type" + (int)_input->data_type()); + throw std::runtime_error("Not supported input type" + + std::to_string((int)_input->data_type())); } } } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/cpu/kernel/CastLayer.h b/runtime/onert/backend/cpu/kernel/CastLayer.h similarity index 84% rename from runtime/neurun/backend/cpu/kernel/CastLayer.h rename to runtime/onert/backend/cpu/kernel/CastLayer.h index b41e93d5ef4..4690e10071e 100644 --- a/runtime/neurun/backend/cpu/kernel/CastLayer.h +++ b/runtime/onert/backend/cpu/kernel/CastLayer.h @@ -14,15 +14,15 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_CPU_KERNEL_CASTLAYER_H__ -#define __NEURUN_BACKEND_CPU_KERNEL_CASTLAYER_H__ +#ifndef __ONERT_BACKEND_CPU_KERNEL_CASTLAYER_H__ +#define __ONERT_BACKEND_CPU_KERNEL_CASTLAYER_H__ #include "../operand/Tensor.h" #include "OperationUtils.h" #include -namespace neurun +namespace onert { namespace backend { @@ -31,7 +31,7 @@ namespace cpu namespace kernel { -class CastLayer : public ::neurun::exec::IFunction +class CastLayer : public ::onert::exec::IFunction { public: CastLayer(); @@ -58,6 +58,6 @@ class CastLayer : public ::neurun::exec::IFunction } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_CPU_KERNEL_CASTLAYER_H__ +#endif // __ONERT_BACKEND_CPU_KERNEL_CASTLAYER_H__ diff --git a/runtime/neurun/backend/cpu/kernel/CompareLayer.cc b/runtime/onert/backend/cpu/kernel/CompareLayer.cc similarity index 97% rename from runtime/neurun/backend/cpu/kernel/CompareLayer.cc rename to runtime/onert/backend/cpu/kernel/CompareLayer.cc index f8fbdc8833a..c8ee683b173 100644 --- a/runtime/neurun/backend/cpu/kernel/CompareLayer.cc +++ b/runtime/onert/backend/cpu/kernel/CompareLayer.cc @@ -19,7 +19,7 @@ #include -namespace neurun +namespace onert { namespace backend { @@ -31,8 +31,8 @@ namespace kernel namespace { -using OpType = neurun::ir::operation::Comparison::ComparisonType; -using namespace neurun::backend::cpu; +using OpType = onert::ir::operation::Comparison::ComparisonType; +using namespace onert::backend::cpu; template void compareScalar(const operand::Tensor *lhs, const operand::Tensor *rhs, operand::Tensor *output, @@ -177,4 +177,4 @@ void CompareLayer::run() } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/cpu/kernel/CompareLayer.h b/runtime/onert/backend/cpu/kernel/CompareLayer.h similarity index 84% rename from runtime/neurun/backend/cpu/kernel/CompareLayer.h rename to runtime/onert/backend/cpu/kernel/CompareLayer.h index 08fdcce7bbd..b62e5a2e4a2 100644 --- a/runtime/neurun/backend/cpu/kernel/CompareLayer.h +++ b/runtime/onert/backend/cpu/kernel/CompareLayer.h @@ -14,15 +14,15 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_CPU_KERNEL_COMPARELAYER_H__ -#define __NEURUN_BACKEND_CPU_KERNEL_COMPARELAYER_H__ +#ifndef __ONERT_BACKEND_CPU_KERNEL_COMPARELAYER_H__ +#define __ONERT_BACKEND_CPU_KERNEL_COMPARELAYER_H__ #include "../operand/Tensor.h" #include #include -namespace neurun +namespace onert { namespace backend { @@ -31,7 +31,7 @@ namespace cpu namespace kernel { -class CompareLayer : public ::neurun::exec::IFunction +class CompareLayer : public ::onert::exec::IFunction { public: CompareLayer(); @@ -60,6 +60,6 @@ class CompareLayer : public ::neurun::exec::IFunction } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_CPU_KERNEL_COMPARELAYER_H__ +#endif // __ONERT_BACKEND_CPU_KERNEL_COMPARELAYER_H__ diff --git a/runtime/neurun/backend/cpu/kernel/ConcatLayer.cc b/runtime/onert/backend/cpu/kernel/ConcatLayer.cc similarity index 92% rename from runtime/neurun/backend/cpu/kernel/ConcatLayer.cc rename to runtime/onert/backend/cpu/kernel/ConcatLayer.cc index 0402b5613ef..80a29e8ce99 100644 --- a/runtime/neurun/backend/cpu/kernel/ConcatLayer.cc +++ b/runtime/onert/backend/cpu/kernel/ConcatLayer.cc @@ -20,7 +20,7 @@ #include -namespace neurun +namespace onert { namespace backend { @@ -100,9 +100,9 @@ void ConcatLayer::concatenationQuant8() inputDataPtrs.emplace_back(reinterpret_cast(input->buffer())); } - nnfw::cker::Concatenation(op_params, inputDimsPtr.data(), inputDataPtrs.data(), - convertTensorToCkerShape(_output), - reinterpret_cast(_output->buffer())); + nnfw::cker::ConcatenationWithScaling(op_params, inputDimsPtr.data(), inputDataPtrs.data(), + convertTensorToCkerShape(_output), + reinterpret_cast(_output->buffer())); } void ConcatLayer::configure(const std::vector &inputs, int32_t axis, @@ -131,4 +131,4 @@ void ConcatLayer::run() } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/cpu/kernel/ConcatLayer.h b/runtime/onert/backend/cpu/kernel/ConcatLayer.h similarity index 84% rename from runtime/neurun/backend/cpu/kernel/ConcatLayer.h rename to runtime/onert/backend/cpu/kernel/ConcatLayer.h index 0ecaf5b937a..1ac1604cf67 100644 --- a/runtime/neurun/backend/cpu/kernel/ConcatLayer.h +++ b/runtime/onert/backend/cpu/kernel/ConcatLayer.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_CPU_KERNEL_CONCATLAYER_H__ -#define __NEURUN_BACKEND_CPU_KERNEL_CONCATLAYER_H__ +#ifndef __ONERT_BACKEND_CPU_KERNEL_CONCATLAYER_H__ +#define __ONERT_BACKEND_CPU_KERNEL_CONCATLAYER_H__ #include "../operand/Tensor.h" #include -namespace neurun +namespace onert { namespace backend { @@ -30,7 +30,7 @@ namespace cpu namespace kernel { -class ConcatLayer : public ::neurun::exec::IFunction +class ConcatLayer : public ::onert::exec::IFunction { public: ConcatLayer(); @@ -60,6 +60,6 @@ class ConcatLayer : public ::neurun::exec::IFunction } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_CPU_KERNEL_CONCATLAYER_H__ +#endif // __ONERT_BACKEND_CPU_KERNEL_CONCATLAYER_H__ diff --git a/runtime/neurun/backend/cpu/kernel/ConvolutionLayer.cc b/runtime/onert/backend/cpu/kernel/ConvolutionLayer.cc similarity index 94% rename from runtime/neurun/backend/cpu/kernel/ConvolutionLayer.cc rename to runtime/onert/backend/cpu/kernel/ConvolutionLayer.cc index 2b8d1b20b32..3980545276a 100644 --- a/runtime/neurun/backend/cpu/kernel/ConvolutionLayer.cc +++ b/runtime/onert/backend/cpu/kernel/ConvolutionLayer.cc @@ -18,7 +18,7 @@ #include -namespace neurun +namespace onert { namespace backend { @@ -82,7 +82,7 @@ void ConvolutionLayer::convQuant8() CalculateActivationRangeUint8(_activation, _output, &output_activation_min, &output_activation_max); - float real_multiplier = 0.0; + double real_multiplier = 0.0; int32_t output_multiplier = 0; int32_t output_shift = 0; GetQuantizedConvolutionMultiplier(_input, _kernel, _bias, _output, &real_multiplier); @@ -105,6 +105,12 @@ void ConvolutionLayer::convQuant8() op_params.quantized_activation_max = output_activation_max; nnfw::cker::Conv &kernel = *_conv_kernel; + if (!_prepare) + { + kernel.prepareQuant(convertTensorToCkerShape(_input), convertTensorToCkerShape(_kernel), + convertTensorToCkerShape(_output), _strideWidth, _strideHeight); + _prepare = true; + } kernel(op_params, convertTensorToCkerShape(_input), reinterpret_cast(_input->buffer()), convertTensorToCkerShape(_kernel), reinterpret_cast(_kernel->buffer()), convertTensorToCkerShape(_bias), @@ -150,4 +156,4 @@ void ConvolutionLayer::run() } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/cpu/kernel/ConvolutionLayer.h b/runtime/onert/backend/cpu/kernel/ConvolutionLayer.h similarity index 88% rename from runtime/neurun/backend/cpu/kernel/ConvolutionLayer.h rename to runtime/onert/backend/cpu/kernel/ConvolutionLayer.h index e5a6c0a02b0..70af098c4e5 100644 --- a/runtime/neurun/backend/cpu/kernel/ConvolutionLayer.h +++ b/runtime/onert/backend/cpu/kernel/ConvolutionLayer.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_CPU_KERNEL_CONVOLUTIONLAYER_H__ -#define __NEURUN_BACKEND_CPU_KERNEL_CONVOLUTIONLAYER_H__ +#ifndef __ONERT_BACKEND_CPU_KERNEL_CONVOLUTIONLAYER_H__ +#define __ONERT_BACKEND_CPU_KERNEL_CONVOLUTIONLAYER_H__ #include "../operand/Tensor.h" #include "OperationUtils.h" @@ -32,7 +32,7 @@ class Conv; } } // namespace nnfw -namespace neurun +namespace onert { namespace backend { @@ -41,7 +41,7 @@ namespace cpu namespace kernel { -class ConvolutionLayer : public ::neurun::exec::IFunction +class ConvolutionLayer : public ::onert::exec::IFunction { public: ConvolutionLayer(); @@ -91,6 +91,6 @@ class ConvolutionLayer : public ::neurun::exec::IFunction } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_CPU_KERNEL_CONVOLUTIONLAYER_H__ +#endif // __ONERT_BACKEND_CPU_KERNEL_CONVOLUTIONLAYER_H__ diff --git a/runtime/neurun/backend/cpu/kernel/DepthwiseConvolutionLayer.cc b/runtime/onert/backend/cpu/kernel/DepthwiseConvolutionLayer.cc similarity index 98% rename from runtime/neurun/backend/cpu/kernel/DepthwiseConvolutionLayer.cc rename to runtime/onert/backend/cpu/kernel/DepthwiseConvolutionLayer.cc index 37f535bcb65..a1efe9fed7b 100644 --- a/runtime/neurun/backend/cpu/kernel/DepthwiseConvolutionLayer.cc +++ b/runtime/onert/backend/cpu/kernel/DepthwiseConvolutionLayer.cc @@ -18,7 +18,7 @@ #include -namespace neurun +namespace onert { namespace backend { @@ -66,7 +66,7 @@ void DepthwiseConvolutionLayer::convQuant8() CalculateActivationRangeUint8(_activation, _output, &output_activation_min, &output_activation_max); - float real_multiplier = 0.0; + double real_multiplier = 0.0; int32_t output_multiplier = 0; int32_t output_shift = 0; GetQuantizedConvolutionMultiplier(_input, _kernel, _bias, _output, &real_multiplier); @@ -133,4 +133,4 @@ void DepthwiseConvolutionLayer::run() } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/cpu/kernel/DepthwiseConvolutionLayer.h b/runtime/onert/backend/cpu/kernel/DepthwiseConvolutionLayer.h similarity index 87% rename from runtime/neurun/backend/cpu/kernel/DepthwiseConvolutionLayer.h rename to runtime/onert/backend/cpu/kernel/DepthwiseConvolutionLayer.h index 0ff7a2714b1..dcc3762cc74 100644 --- a/runtime/neurun/backend/cpu/kernel/DepthwiseConvolutionLayer.h +++ b/runtime/onert/backend/cpu/kernel/DepthwiseConvolutionLayer.h @@ -14,15 +14,15 @@ * limitations under the License. */ -#ifndef __NEURUN_KERNEL_CPU_DEPTHWISECONVOLUTIONLAYER_H__ -#define __NEURUN_KERNEL_CPU_DEPTHWISECONVOLUTIONLAYER_H__ +#ifndef __ONERT_KERNEL_CPU_DEPTHWISECONVOLUTIONLAYER_H__ +#define __ONERT_KERNEL_CPU_DEPTHWISECONVOLUTIONLAYER_H__ #include "../operand/Tensor.h" #include "OperationUtils.h" #include -namespace neurun +namespace onert { namespace backend { @@ -31,7 +31,7 @@ namespace cpu namespace kernel { -class DepthwiseConvolutionLayer : public ::neurun::exec::IFunction +class DepthwiseConvolutionLayer : public ::onert::exec::IFunction { public: DepthwiseConvolutionLayer(); @@ -78,6 +78,6 @@ class DepthwiseConvolutionLayer : public ::neurun::exec::IFunction } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_KERNEL_CPU_DEPTHWISECONVOLUTIONLAYER_H__ +#endif // __ONERT_KERNEL_CPU_DEPTHWISECONVOLUTIONLAYER_H__ diff --git a/runtime/neurun/backend/cpu/kernel/DivLayer.cc b/runtime/onert/backend/cpu/kernel/DivLayer.cc similarity index 98% rename from runtime/neurun/backend/cpu/kernel/DivLayer.cc rename to runtime/onert/backend/cpu/kernel/DivLayer.cc index e9a0f32d52e..ec9daae9bba 100644 --- a/runtime/neurun/backend/cpu/kernel/DivLayer.cc +++ b/runtime/onert/backend/cpu/kernel/DivLayer.cc @@ -18,7 +18,7 @@ #include -namespace neurun +namespace onert { namespace backend { @@ -89,4 +89,4 @@ void DivLayer::run() } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/cpu/kernel/DivLayer.h b/runtime/onert/backend/cpu/kernel/DivLayer.h similarity index 86% rename from runtime/neurun/backend/cpu/kernel/DivLayer.h rename to runtime/onert/backend/cpu/kernel/DivLayer.h index abcd1abf8fa..3e14d9c1944 100644 --- a/runtime/neurun/backend/cpu/kernel/DivLayer.h +++ b/runtime/onert/backend/cpu/kernel/DivLayer.h @@ -14,15 +14,15 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_CPU_KERNEL_DIVLAYER_H__ -#define __NEURUN_BACKEND_CPU_KERNEL_DIVLAYER_H__ +#ifndef __ONERT_BACKEND_CPU_KERNEL_DIVLAYER_H__ +#define __ONERT_BACKEND_CPU_KERNEL_DIVLAYER_H__ #include "../operand/Tensor.h" #include "OperationUtils.h" #include -namespace neurun +namespace onert { namespace backend { @@ -31,7 +31,7 @@ namespace cpu namespace kernel { -class DivLayer : public ::neurun::exec::IFunction +class DivLayer : public ::onert::exec::IFunction { public: DivLayer() : _lhs(nullptr), _rhs(nullptr), _output(nullptr) @@ -66,6 +66,6 @@ class DivLayer : public ::neurun::exec::IFunction } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_CPU_KERNEL_DIVLAYER_H__ +#endif // __ONERT_BACKEND_CPU_KERNEL_DIVLAYER_H__ diff --git a/runtime/neurun/backend/cpu/kernel/ExpLayer.cc b/runtime/onert/backend/cpu/kernel/ExpLayer.cc similarity index 97% rename from runtime/neurun/backend/cpu/kernel/ExpLayer.cc rename to runtime/onert/backend/cpu/kernel/ExpLayer.cc index 044cf20ffd9..335a789b2fc 100644 --- a/runtime/neurun/backend/cpu/kernel/ExpLayer.cc +++ b/runtime/onert/backend/cpu/kernel/ExpLayer.cc @@ -20,7 +20,7 @@ #include -namespace neurun +namespace onert { namespace backend { @@ -68,4 +68,4 @@ void ExpLayer::run() } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/cpu/kernel/ExpLayer.h b/runtime/onert/backend/cpu/kernel/ExpLayer.h similarity index 83% rename from runtime/neurun/backend/cpu/kernel/ExpLayer.h rename to runtime/onert/backend/cpu/kernel/ExpLayer.h index d9afe3bbdea..5a7222fadcd 100644 --- a/runtime/neurun/backend/cpu/kernel/ExpLayer.h +++ b/runtime/onert/backend/cpu/kernel/ExpLayer.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_CPU_KERNEL_EXPLAYER_H__ -#define __NEURUN_BACKEND_CPU_KERNEL_EXPLAYER_H__ +#ifndef __ONERT_BACKEND_CPU_KERNEL_EXPLAYER_H__ +#define __ONERT_BACKEND_CPU_KERNEL_EXPLAYER_H__ #include "../operand/Tensor.h" #include -namespace neurun +namespace onert { namespace backend { @@ -30,7 +30,7 @@ namespace cpu namespace kernel { -class ExpLayer : public ::neurun::exec::IFunction +class ExpLayer : public ::onert::exec::IFunction { public: ExpLayer(); @@ -58,6 +58,6 @@ class ExpLayer : public ::neurun::exec::IFunction } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_CPU_KERNEL_EXPLAYER_H__ +#endif // __ONERT_BACKEND_CPU_KERNEL_EXPLAYER_H__ diff --git a/runtime/neurun/backend/cpu/kernel/FullyConnectedLayer.cc b/runtime/onert/backend/cpu/kernel/FullyConnectedLayer.cc similarity index 97% rename from runtime/neurun/backend/cpu/kernel/FullyConnectedLayer.cc rename to runtime/onert/backend/cpu/kernel/FullyConnectedLayer.cc index 68299ca29e8..636df89414c 100644 --- a/runtime/neurun/backend/cpu/kernel/FullyConnectedLayer.cc +++ b/runtime/onert/backend/cpu/kernel/FullyConnectedLayer.cc @@ -18,7 +18,7 @@ #include -namespace neurun +namespace onert { namespace backend { @@ -44,6 +44,7 @@ void FullyConnectedLayer::fullyConnectedFloat32() nnfw::cker::FullyConnectedParams op_params; op_params.float_activation_min = output_activation_min; op_params.float_activation_max = output_activation_max; + op_params.activation = convertActivationType(_activation); nnfw::cker::FullyConnected( op_params, convertTensorToCkerShape(_input), @@ -57,7 +58,7 @@ void FullyConnectedLayer::fullyConnectedFloat32() // like gemmlowp::GemmContext. void FullyConnectedLayer::fullyConnectedQuant8() { - float real_multiplier = 0.0; + double real_multiplier = 0.0; int32_t output_multiplier = 0; int32_t output_shift = 0; int32_t output_activation_min = 0; @@ -137,4 +138,4 @@ void FullyConnectedLayer::run() } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/cpu/kernel/FullyConnectedLayer.h b/runtime/onert/backend/cpu/kernel/FullyConnectedLayer.h similarity index 85% rename from runtime/neurun/backend/cpu/kernel/FullyConnectedLayer.h rename to runtime/onert/backend/cpu/kernel/FullyConnectedLayer.h index 50c9e2ee9f2..616124bac0a 100644 --- a/runtime/neurun/backend/cpu/kernel/FullyConnectedLayer.h +++ b/runtime/onert/backend/cpu/kernel/FullyConnectedLayer.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_CPU_KERNEL_FULLYCONNECTEDLAYER_H__ -#define __NEURUN_BACKEND_CPU_KERNEL_FULLYCONNECTEDLAYER_H__ +#ifndef __ONERT_BACKEND_CPU_KERNEL_FULLYCONNECTEDLAYER_H__ +#define __ONERT_BACKEND_CPU_KERNEL_FULLYCONNECTEDLAYER_H__ #include "../operand/Tensor.h" #include "OperationUtils.h" @@ -30,7 +30,7 @@ class FCTempArena; } } // namespace nnfw -namespace neurun +namespace onert { namespace backend { @@ -39,7 +39,7 @@ namespace cpu namespace kernel { -class FullyConnectedLayer : public ::neurun::exec::IFunction +class FullyConnectedLayer : public ::onert::exec::IFunction { public: FullyConnectedLayer(); @@ -76,6 +76,6 @@ class FullyConnectedLayer : public ::neurun::exec::IFunction } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_CPU_KERNEL_FULLYCONNECTEDLAYER_H__ +#endif // __ONERT_BACKEND_CPU_KERNEL_FULLYCONNECTEDLAYER_H__ diff --git a/runtime/neurun/backend/cpu/kernel/GatherLayer.cc b/runtime/onert/backend/cpu/kernel/GatherLayer.cc similarity index 98% rename from runtime/neurun/backend/cpu/kernel/GatherLayer.cc rename to runtime/onert/backend/cpu/kernel/GatherLayer.cc index e083f20037e..07f30136c76 100644 --- a/runtime/neurun/backend/cpu/kernel/GatherLayer.cc +++ b/runtime/onert/backend/cpu/kernel/GatherLayer.cc @@ -20,7 +20,7 @@ #include -namespace neurun +namespace onert { namespace backend { @@ -74,4 +74,4 @@ void GatherLayer::run() } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/cpu/kernel/GatherLayer.h b/runtime/onert/backend/cpu/kernel/GatherLayer.h similarity index 84% rename from runtime/neurun/backend/cpu/kernel/GatherLayer.h rename to runtime/onert/backend/cpu/kernel/GatherLayer.h index 564deddcbab..2ff3605a26e 100644 --- a/runtime/neurun/backend/cpu/kernel/GatherLayer.h +++ b/runtime/onert/backend/cpu/kernel/GatherLayer.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_CPU_KERNEL_GATHERLAYER_H__ -#define __NEURUN_BACKEND_CPU_KERNEL_GATHERLAYER_H__ +#ifndef __ONERT_BACKEND_CPU_KERNEL_GATHERLAYER_H__ +#define __ONERT_BACKEND_CPU_KERNEL_GATHERLAYER_H__ #include "../operand/Tensor.h" #include -namespace neurun +namespace onert { namespace backend { @@ -30,7 +30,7 @@ namespace cpu namespace kernel { -class GatherLayer : public ::neurun::exec::IFunction +class GatherLayer : public ::onert::exec::IFunction { public: GatherLayer() : _input{nullptr}, _indices{nullptr}, _output{nullptr}, _axis{-1} @@ -61,6 +61,6 @@ class GatherLayer : public ::neurun::exec::IFunction } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_CPU_KERNEL_GATHERLAYER_H__ +#endif // __ONERT_BACKEND_CPU_KERNEL_GATHERLAYER_H__ diff --git a/runtime/neurun/backend/cpu/kernel/LogisticLayer.cc b/runtime/onert/backend/cpu/kernel/LogisticLayer.cc similarity index 97% rename from runtime/neurun/backend/cpu/kernel/LogisticLayer.cc rename to runtime/onert/backend/cpu/kernel/LogisticLayer.cc index 49ba77123ed..07f43404854 100644 --- a/runtime/neurun/backend/cpu/kernel/LogisticLayer.cc +++ b/runtime/onert/backend/cpu/kernel/LogisticLayer.cc @@ -20,7 +20,7 @@ #include -namespace neurun +namespace onert { namespace backend { @@ -68,4 +68,4 @@ void LogisticLayer::run() } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/cpu/kernel/LogisticLayer.h b/runtime/onert/backend/cpu/kernel/LogisticLayer.h similarity index 82% rename from runtime/neurun/backend/cpu/kernel/LogisticLayer.h rename to runtime/onert/backend/cpu/kernel/LogisticLayer.h index cd37ef57ff0..76ee1600fc9 100644 --- a/runtime/neurun/backend/cpu/kernel/LogisticLayer.h +++ b/runtime/onert/backend/cpu/kernel/LogisticLayer.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_CPU_KERNEL_LOGISTICLAYER_H__ -#define __NEURUN_BACKEND_CPU_KERNEL_LOGISTICLAYER_H__ +#ifndef __ONERT_BACKEND_CPU_KERNEL_LOGISTICLAYER_H__ +#define __ONERT_BACKEND_CPU_KERNEL_LOGISTICLAYER_H__ #include "../operand/Tensor.h" #include -namespace neurun +namespace onert { namespace backend { @@ -30,7 +30,7 @@ namespace cpu namespace kernel { -class LogisticLayer : public ::neurun::exec::IFunction +class LogisticLayer : public ::onert::exec::IFunction { public: LogisticLayer(); @@ -58,6 +58,6 @@ class LogisticLayer : public ::neurun::exec::IFunction } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_CPU_KERNEL_LOGISTICLAYER_H__ +#endif // __ONERT_BACKEND_CPU_KERNEL_LOGISTICLAYER_H__ diff --git a/runtime/neurun/backend/cpu/kernel/MaxLayer.cc b/runtime/onert/backend/cpu/kernel/MaxLayer.cc similarity index 98% rename from runtime/neurun/backend/cpu/kernel/MaxLayer.cc rename to runtime/onert/backend/cpu/kernel/MaxLayer.cc index 3eb1547d570..701d73a3559 100644 --- a/runtime/neurun/backend/cpu/kernel/MaxLayer.cc +++ b/runtime/onert/backend/cpu/kernel/MaxLayer.cc @@ -20,7 +20,7 @@ #include -namespace neurun +namespace onert { namespace backend { @@ -75,4 +75,4 @@ void MaxLayer::run() } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/cpu/kernel/MaxLayer.h b/runtime/onert/backend/cpu/kernel/MaxLayer.h similarity index 84% rename from runtime/neurun/backend/cpu/kernel/MaxLayer.h rename to runtime/onert/backend/cpu/kernel/MaxLayer.h index e19e3fe2463..2cccf26ae57 100644 --- a/runtime/neurun/backend/cpu/kernel/MaxLayer.h +++ b/runtime/onert/backend/cpu/kernel/MaxLayer.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_CPU_KERNEL_MAXLAYER_H__ -#define __NEURUN_BACKEND_CPU_KERNEL_MAXLAYER_H__ +#ifndef __ONERT_BACKEND_CPU_KERNEL_MAXLAYER_H__ +#define __ONERT_BACKEND_CPU_KERNEL_MAXLAYER_H__ #include "../operand/Tensor.h" #include -namespace neurun +namespace onert { namespace backend { @@ -30,7 +30,7 @@ namespace cpu namespace kernel { -class MaxLayer : public ::neurun::exec::IFunction +class MaxLayer : public ::onert::exec::IFunction { public: MaxLayer() : _lhs(nullptr), _rhs(nullptr), _output(nullptr) @@ -62,6 +62,6 @@ class MaxLayer : public ::neurun::exec::IFunction } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_CPU_KERNEL_MAXLAYER_H__ +#endif // __ONERT_BACKEND_CPU_KERNEL_MAXLAYER_H__ diff --git a/runtime/neurun/backend/cpu/kernel/MaxPoolLayer.cc b/runtime/onert/backend/cpu/kernel/MaxPoolLayer.cc similarity index 99% rename from runtime/neurun/backend/cpu/kernel/MaxPoolLayer.cc rename to runtime/onert/backend/cpu/kernel/MaxPoolLayer.cc index 9c87b60c47f..e35d5e92ad6 100644 --- a/runtime/neurun/backend/cpu/kernel/MaxPoolLayer.cc +++ b/runtime/onert/backend/cpu/kernel/MaxPoolLayer.cc @@ -18,7 +18,7 @@ #include -namespace neurun +namespace onert { namespace backend { @@ -110,4 +110,4 @@ void MaxPoolLayer::run() } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/cpu/kernel/MaxPoolLayer.h b/runtime/onert/backend/cpu/kernel/MaxPoolLayer.h similarity index 87% rename from runtime/neurun/backend/cpu/kernel/MaxPoolLayer.h rename to runtime/onert/backend/cpu/kernel/MaxPoolLayer.h index 9d254030ab5..a29e09e1b8a 100644 --- a/runtime/neurun/backend/cpu/kernel/MaxPoolLayer.h +++ b/runtime/onert/backend/cpu/kernel/MaxPoolLayer.h @@ -14,15 +14,15 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_CPU_KERNEL_MAXPOOLLAYER_H__ -#define __NEURUN_BACKEND_CPU_KERNEL_MAXPOOLLAYER_H__ +#ifndef __ONERT_BACKEND_CPU_KERNEL_MAXPOOLLAYER_H__ +#define __ONERT_BACKEND_CPU_KERNEL_MAXPOOLLAYER_H__ #include "../operand/Tensor.h" #include "OperationUtils.h" #include -namespace neurun +namespace onert { namespace backend { @@ -31,7 +31,7 @@ namespace cpu namespace kernel { -class MaxPoolLayer : public ::neurun::exec::IFunction +class MaxPoolLayer : public ::onert::exec::IFunction { public: MaxPoolLayer(); @@ -76,6 +76,6 @@ class MaxPoolLayer : public ::neurun::exec::IFunction } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_CPU_KERNEL_MAXPOOLLAYER_H__ +#endif // __ONERT_BACKEND_CPU_KERNEL_MAXPOOLLAYER_H__ diff --git a/runtime/neurun/backend/cpu/kernel/MinLayer.cc b/runtime/onert/backend/cpu/kernel/MinLayer.cc similarity index 98% rename from runtime/neurun/backend/cpu/kernel/MinLayer.cc rename to runtime/onert/backend/cpu/kernel/MinLayer.cc index ae777207d23..07cb8ab9144 100644 --- a/runtime/neurun/backend/cpu/kernel/MinLayer.cc +++ b/runtime/onert/backend/cpu/kernel/MinLayer.cc @@ -20,7 +20,7 @@ #include -namespace neurun +namespace onert { namespace backend { @@ -75,4 +75,4 @@ void MinLayer::run() } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/cpu/kernel/MinLayer.h b/runtime/onert/backend/cpu/kernel/MinLayer.h similarity index 84% rename from runtime/neurun/backend/cpu/kernel/MinLayer.h rename to runtime/onert/backend/cpu/kernel/MinLayer.h index a6f33ac2afd..5beb6444a33 100644 --- a/runtime/neurun/backend/cpu/kernel/MinLayer.h +++ b/runtime/onert/backend/cpu/kernel/MinLayer.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_CPU_KERNEL_MINLAYER_H__ -#define __NEURUN_BACKEND_CPU_KERNEL_MINLAYER_H__ +#ifndef __ONERT_BACKEND_CPU_KERNEL_MINLAYER_H__ +#define __ONERT_BACKEND_CPU_KERNEL_MINLAYER_H__ #include "../operand/Tensor.h" #include -namespace neurun +namespace onert { namespace backend { @@ -30,7 +30,7 @@ namespace cpu namespace kernel { -class MinLayer : public ::neurun::exec::IFunction +class MinLayer : public ::onert::exec::IFunction { public: MinLayer() : _lhs(nullptr), _rhs(nullptr), _output(nullptr) @@ -62,6 +62,6 @@ class MinLayer : public ::neurun::exec::IFunction } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_CPU_KERNEL_MINLAYER_H__ +#endif // __ONERT_BACKEND_CPU_KERNEL_MINLAYER_H__ diff --git a/runtime/neurun/backend/cpu/kernel/MulLayer.cc b/runtime/onert/backend/cpu/kernel/MulLayer.cc similarity index 98% rename from runtime/neurun/backend/cpu/kernel/MulLayer.cc rename to runtime/onert/backend/cpu/kernel/MulLayer.cc index 9ce5db78a0e..df7d71eec24 100644 --- a/runtime/neurun/backend/cpu/kernel/MulLayer.cc +++ b/runtime/onert/backend/cpu/kernel/MulLayer.cc @@ -18,7 +18,7 @@ #include -namespace neurun +namespace onert { namespace backend { @@ -89,4 +89,4 @@ void MulLayer::run() } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/cpu/kernel/MulLayer.h b/runtime/onert/backend/cpu/kernel/MulLayer.h similarity index 86% rename from runtime/neurun/backend/cpu/kernel/MulLayer.h rename to runtime/onert/backend/cpu/kernel/MulLayer.h index 6d0272098be..a5cf25f0fef 100644 --- a/runtime/neurun/backend/cpu/kernel/MulLayer.h +++ b/runtime/onert/backend/cpu/kernel/MulLayer.h @@ -14,15 +14,15 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_CPU_KERNEL_MULLAYER_H__ -#define __NEURUN_BACKEND_CPU_KERNEL_MULLAYER_H__ +#ifndef __ONERT_BACKEND_CPU_KERNEL_MULLAYER_H__ +#define __ONERT_BACKEND_CPU_KERNEL_MULLAYER_H__ #include "../operand/Tensor.h" #include "OperationUtils.h" #include -namespace neurun +namespace onert { namespace backend { @@ -31,7 +31,7 @@ namespace cpu namespace kernel { -class MulLayer : public ::neurun::exec::IFunction +class MulLayer : public ::onert::exec::IFunction { public: MulLayer() : _lhs(nullptr), _rhs(nullptr), _output(nullptr) @@ -66,6 +66,6 @@ class MulLayer : public ::neurun::exec::IFunction } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_CPU_KERNEL_MULLAYER_H__ +#endif // __ONERT_BACKEND_CPU_KERNEL_MULLAYER_H__ diff --git a/runtime/neurun/backend/cpu/kernel/OneHotLayer.cc b/runtime/onert/backend/cpu/kernel/OneHotLayer.cc similarity index 97% rename from runtime/neurun/backend/cpu/kernel/OneHotLayer.cc rename to runtime/onert/backend/cpu/kernel/OneHotLayer.cc index 6ce25f41ed1..fd2c1b79500 100644 --- a/runtime/neurun/backend/cpu/kernel/OneHotLayer.cc +++ b/runtime/onert/backend/cpu/kernel/OneHotLayer.cc @@ -20,7 +20,7 @@ #include -namespace neurun +namespace onert { namespace backend { @@ -67,4 +67,4 @@ void OneHotLayer::run() } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/cpu/kernel/OneHotLayer.h b/runtime/onert/backend/cpu/kernel/OneHotLayer.h similarity index 85% rename from runtime/neurun/backend/cpu/kernel/OneHotLayer.h rename to runtime/onert/backend/cpu/kernel/OneHotLayer.h index 7812b845db2..5f23481baf6 100644 --- a/runtime/neurun/backend/cpu/kernel/OneHotLayer.h +++ b/runtime/onert/backend/cpu/kernel/OneHotLayer.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_CPU_KERNEL_ONEHOTLAYER_H__ -#define __NEURUN_BACKEND_CPU_KERNEL_ONEHOTLAYER_H__ +#ifndef __ONERT_BACKEND_CPU_KERNEL_ONEHOTLAYER_H__ +#define __ONERT_BACKEND_CPU_KERNEL_ONEHOTLAYER_H__ #include "../operand/Tensor.h" #include -namespace neurun +namespace onert { namespace backend { @@ -30,7 +30,7 @@ namespace cpu namespace kernel { -class OneHotLayer : public ::neurun::exec::IFunction +class OneHotLayer : public ::onert::exec::IFunction { public: OneHotLayer() @@ -68,6 +68,6 @@ class OneHotLayer : public ::neurun::exec::IFunction } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_CPU_KERNEL_ONEHOTLAYER_H__ +#endif // __ONERT_BACKEND_CPU_KERNEL_ONEHOTLAYER_H__ diff --git a/runtime/neurun/backend/cpu/kernel/OperationUtils.cc b/runtime/onert/backend/cpu/kernel/OperationUtils.cc similarity index 96% rename from runtime/neurun/backend/cpu/kernel/OperationUtils.cc rename to runtime/onert/backend/cpu/kernel/OperationUtils.cc index 05d35d6a236..178aac83311 100644 --- a/runtime/neurun/backend/cpu/kernel/OperationUtils.cc +++ b/runtime/onert/backend/cpu/kernel/OperationUtils.cc @@ -20,7 +20,7 @@ #include #include -namespace neurun +namespace onert { namespace backend { @@ -80,11 +80,11 @@ void QuantizeMultiplier(double double_multiplier, int32_t *quantized_multiplier, void GetQuantizedConvolutionMultiplier(const operand::Tensor *input, const operand::Tensor *filter, const operand::Tensor *bias, const operand::Tensor *output, - float *multiplier) + double *multiplier) { - const float input_product_scale = input->scale() * filter->scale(); - const float bias_scale = bias->scale(); - const float output_scale = output->scale(); + const double input_product_scale = input->scale() * filter->scale(); + const double bias_scale = bias->scale(); + const double output_scale = output->scale(); // The following conditions must be guaranteed by the training pipeline. UNUSED_RELEASE(bias_scale); assert(std::abs(input_product_scale - bias_scale) <= @@ -266,4 +266,4 @@ nnfw::cker::PaddingType getPaddingType(ir::PaddingType ir_padding_type) } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/cpu/kernel/OperationUtils.h b/runtime/onert/backend/cpu/kernel/OperationUtils.h similarity index 97% rename from runtime/neurun/backend/cpu/kernel/OperationUtils.h rename to runtime/onert/backend/cpu/kernel/OperationUtils.h index b0aa946f255..be9b24f364d 100644 --- a/runtime/neurun/backend/cpu/kernel/OperationUtils.h +++ b/runtime/onert/backend/cpu/kernel/OperationUtils.h @@ -30,9 +30,9 @@ #include #include -using OperandType = neurun::ir::DataType; +using OperandType = onert::ir::DataType; -namespace neurun +namespace onert { namespace backend { @@ -135,7 +135,7 @@ void QuantizeMultiplier(double double_multiplier, int32_t *quantized_multiplier, void GetQuantizedConvolutionMultiplier(const operand::Tensor *inputDescr, const operand::Tensor *filterDescr, const operand::Tensor *biasDescr, - const operand::Tensor *outputDescr, float *multiplier); + const operand::Tensor *outputDescr, double *multiplier); void QuantizeMultiplierGreaterThanOne(double double_multiplier, int32_t *quantized_multiplier, int *left_shift); @@ -157,6 +157,6 @@ nnfw::cker::PaddingType getPaddingType(ir::PaddingType ir_padding_type); } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert #endif // __NNFW_SUPPORT_NNAPI_OPERATION_UTILS_H__ diff --git a/runtime/neurun/backend/cpu/kernel/PackLayer.cc b/runtime/onert/backend/cpu/kernel/PackLayer.cc similarity index 98% rename from runtime/neurun/backend/cpu/kernel/PackLayer.cc rename to runtime/onert/backend/cpu/kernel/PackLayer.cc index e529b197068..01e69ff1dc7 100644 --- a/runtime/neurun/backend/cpu/kernel/PackLayer.cc +++ b/runtime/onert/backend/cpu/kernel/PackLayer.cc @@ -20,7 +20,7 @@ #include -namespace neurun +namespace onert { namespace backend { @@ -95,4 +95,4 @@ void PackLayer::run() } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/cpu/kernel/PackLayer.h b/runtime/onert/backend/cpu/kernel/PackLayer.h similarity index 84% rename from runtime/neurun/backend/cpu/kernel/PackLayer.h rename to runtime/onert/backend/cpu/kernel/PackLayer.h index 1ab1120a711..5c87382be3a 100644 --- a/runtime/neurun/backend/cpu/kernel/PackLayer.h +++ b/runtime/onert/backend/cpu/kernel/PackLayer.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_CPU_KERNEL_PACKLAYER_H__ -#define __NEURUN_BACKEND_CPU_KERNEL_PACKLAYER_H__ +#ifndef __ONERT_BACKEND_CPU_KERNEL_PACKLAYER_H__ +#define __ONERT_BACKEND_CPU_KERNEL_PACKLAYER_H__ #include "../operand/Tensor.h" #include -namespace neurun +namespace onert { namespace backend { @@ -30,7 +30,7 @@ namespace cpu namespace kernel { -class PackLayer : public ::neurun::exec::IFunction +class PackLayer : public ::onert::exec::IFunction { public: PackLayer(); @@ -60,6 +60,6 @@ class PackLayer : public ::neurun::exec::IFunction } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_CPU_KERNEL_PACKLAYER_H__ +#endif // __ONERT_BACKEND_CPU_KERNEL_PACKLAYER_H__ diff --git a/runtime/neurun/backend/cpu/kernel/PadLayer.cc b/runtime/onert/backend/cpu/kernel/PadLayer.cc similarity index 97% rename from runtime/neurun/backend/cpu/kernel/PadLayer.cc rename to runtime/onert/backend/cpu/kernel/PadLayer.cc index 989b8ba61c1..39385617876 100644 --- a/runtime/neurun/backend/cpu/kernel/PadLayer.cc +++ b/runtime/onert/backend/cpu/kernel/PadLayer.cc @@ -18,7 +18,7 @@ #include -namespace neurun +namespace onert { namespace backend { @@ -67,4 +67,4 @@ void PadLayer::run() } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/cpu/kernel/PadLayer.h b/runtime/onert/backend/cpu/kernel/PadLayer.h similarity index 86% rename from runtime/neurun/backend/cpu/kernel/PadLayer.h rename to runtime/onert/backend/cpu/kernel/PadLayer.h index ee22fd3eeb2..fc14ae03391 100644 --- a/runtime/neurun/backend/cpu/kernel/PadLayer.h +++ b/runtime/onert/backend/cpu/kernel/PadLayer.h @@ -14,15 +14,15 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_CPU_KERNEL_PADLAYER_H__ -#define __NEURUN_BACKEND_CPU_KERNEL_PADLAYER_H__ +#ifndef __ONERT_BACKEND_CPU_KERNEL_PADLAYER_H__ +#define __ONERT_BACKEND_CPU_KERNEL_PADLAYER_H__ #include "../operand/Tensor.h" #include "OperationUtils.h" #include -namespace neurun +namespace onert { namespace backend { @@ -33,7 +33,7 @@ namespace kernel // Note, this is pad with mode=`CONSTANT`: it doesn't support `REFLECT` and // `SYMMETRIC` -class PadLayer : public ::neurun::exec::IFunction +class PadLayer : public ::onert::exec::IFunction { public: PadLayer(); @@ -66,6 +66,6 @@ class PadLayer : public ::neurun::exec::IFunction } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_CPU_KERNEL_PADLAYER_H__ +#endif // __ONERT_BACKEND_CPU_KERNEL_PADLAYER_H__ diff --git a/runtime/neurun/backend/cpu/kernel/PermuteLayer.cc b/runtime/onert/backend/cpu/kernel/PermuteLayer.cc similarity index 97% rename from runtime/neurun/backend/cpu/kernel/PermuteLayer.cc rename to runtime/onert/backend/cpu/kernel/PermuteLayer.cc index a725cef626b..a3e82825572 100644 --- a/runtime/neurun/backend/cpu/kernel/PermuteLayer.cc +++ b/runtime/onert/backend/cpu/kernel/PermuteLayer.cc @@ -16,7 +16,7 @@ #include "PermuteLayer.h" -namespace neurun +namespace onert { namespace backend { @@ -68,4 +68,4 @@ void PermuteLayer::run() } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/cpu/kernel/PermuteLayer.h b/runtime/onert/backend/cpu/kernel/PermuteLayer.h similarity index 96% rename from runtime/neurun/backend/cpu/kernel/PermuteLayer.h rename to runtime/onert/backend/cpu/kernel/PermuteLayer.h index 691ac704878..52b96caba6b 100644 --- a/runtime/neurun/backend/cpu/kernel/PermuteLayer.h +++ b/runtime/onert/backend/cpu/kernel/PermuteLayer.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_CPU_KERNEL_PERMUTE_LAYER_H__ -#define __NEURUN_BACKEND_CPU_KERNEL_PERMUTE_LAYER_H__ +#ifndef __ONERT_BACKEND_CPU_KERNEL_PERMUTE_LAYER_H__ +#define __ONERT_BACKEND_CPU_KERNEL_PERMUTE_LAYER_H__ #include "OperationUtils.h" @@ -27,7 +27,7 @@ #include #include -namespace neurun +namespace onert { namespace backend { @@ -36,7 +36,7 @@ namespace cpu namespace kernel { -class PermuteLayer : public ::neurun::exec::IFunction +class PermuteLayer : public ::onert::exec::IFunction { public: PermuteLayer() = default; @@ -204,6 +204,6 @@ class PermuteLayer : public ::neurun::exec::IFunction } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_CPU_KERNEL_PERMUTE_LAYER_H__ +#endif // __ONERT_BACKEND_CPU_KERNEL_PERMUTE_LAYER_H__ diff --git a/runtime/neurun/backend/cpu/kernel/ReduceLayer.cc b/runtime/onert/backend/cpu/kernel/ReduceLayer.cc similarity index 92% rename from runtime/neurun/backend/cpu/kernel/ReduceLayer.cc rename to runtime/onert/backend/cpu/kernel/ReduceLayer.cc index 0ff6bb21048..78c82f1ccd1 100644 --- a/runtime/neurun/backend/cpu/kernel/ReduceLayer.cc +++ b/runtime/onert/backend/cpu/kernel/ReduceLayer.cc @@ -20,7 +20,7 @@ #include -namespace neurun +namespace onert { namespace backend { @@ -86,7 +86,8 @@ void evalGeneric(const operand::Tensor *input, operand::Tensor *output, { case OperandType::FLOAT32: return evalType(input, output, axes, keep_dims, reduce_kernel, reduce_type); - break; + case OperandType::INT32: + return evalType(input, output, axes, keep_dims, reduce_kernel, reduce_type); default: throw std::runtime_error{"Reduce(generic): Unsupported input type"}; } @@ -102,18 +103,6 @@ ReduceLayer::ReduceLayer() ReduceLayer::~ReduceLayer() = default; -void ReduceLayer::evalSum() -{ - if (_input->data_type() == OperandType::FLOAT32) - { - evalGeneric(_input, _output, _axes, _keep_dims, *_reduce_kernel); - } - else - { - throw std::runtime_error{"ReduceSum: Unsupported input type"}; - } -} - void ReduceLayer::configure(const operand::Tensor *input, operand::Tensor *output, ReduceType reduceType, const std::vector &axes, bool keep_dims) { @@ -129,7 +118,7 @@ void ReduceLayer::run() switch (_reduceType) { case ReduceType::kSum: - evalSum(); + evalGeneric(_input, _output, _axes, _keep_dims, *_reduce_kernel); break; case ReduceType::kMax: evalGeneric(_input, _output, _axes, _keep_dims, *_reduce_kernel); @@ -145,4 +134,4 @@ void ReduceLayer::run() } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/cpu/kernel/ReduceLayer.h b/runtime/onert/backend/cpu/kernel/ReduceLayer.h similarity index 84% rename from runtime/neurun/backend/cpu/kernel/ReduceLayer.h rename to runtime/onert/backend/cpu/kernel/ReduceLayer.h index 7795de9b3e9..9310882c9bd 100644 --- a/runtime/neurun/backend/cpu/kernel/ReduceLayer.h +++ b/runtime/onert/backend/cpu/kernel/ReduceLayer.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_CPU_KERNEL_REDUCESUMLAYER_H__ -#define __NEURUN_BACKEND_CPU_KERNEL_REDUCESUMLAYER_H__ +#ifndef __ONERT_BACKEND_CPU_KERNEL_REDUCESUMLAYER_H__ +#define __ONERT_BACKEND_CPU_KERNEL_REDUCESUMLAYER_H__ #include "../operand/Tensor.h" @@ -30,7 +30,7 @@ class Reduce; } } // namespace nnfw -namespace neurun +namespace onert { namespace backend { @@ -48,15 +48,13 @@ enum class ReduceType kAny, }; -class ReduceLayer : public ::neurun::exec::IFunction +class ReduceLayer : public ::onert::exec::IFunction { public: ReduceLayer(); ~ReduceLayer(); public: - void evalSum(); - void configure(const operand::Tensor *input, operand::Tensor *output, ReduceType reduceType, const std::vector &axes, bool keep_dims); @@ -81,6 +79,6 @@ class ReduceLayer : public ::neurun::exec::IFunction } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_CPU_KERNEL_REDUCESUMLAYER_H__ +#endif // __ONERT_BACKEND_CPU_KERNEL_REDUCESUMLAYER_H__ diff --git a/runtime/neurun/backend/cpu/kernel/ReshapeLayer.cc b/runtime/onert/backend/cpu/kernel/ReshapeLayer.cc similarity index 69% rename from runtime/neurun/backend/cpu/kernel/ReshapeLayer.cc rename to runtime/onert/backend/cpu/kernel/ReshapeLayer.cc index 76a9d8a4b4c..b8bd5a45cf8 100644 --- a/runtime/neurun/backend/cpu/kernel/ReshapeLayer.cc +++ b/runtime/onert/backend/cpu/kernel/ReshapeLayer.cc @@ -16,7 +16,7 @@ #include "ReshapeLayer.h" -namespace neurun +namespace onert { namespace backend { @@ -25,20 +25,25 @@ namespace cpu namespace kernel { -ReshapeLayer::ReshapeLayer() : _input(nullptr), _output(nullptr) +ReshapeLayer::ReshapeLayer() : _input(nullptr), _shape(nullptr), _output(nullptr) { // DO NOTHING } void ReshapeLayer::reshapeGeneric() { + // TODO use _shape to calculate shape of output when _shape is not nullptr && not constant + size_t count = _input->total_size(); memcpy(_output->buffer(), _input->buffer(), count); } -void ReshapeLayer::configure(const operand::Tensor *input, operand::Tensor *output) +void ReshapeLayer::configure(const operand::Tensor *input, const operand::Tensor *shape, + operand::Tensor *output) { _input = input; + /* note : shape is optional. If not provided from model, _shape is nullptr. */ + _shape = shape; _output = output; } @@ -47,4 +52,4 @@ void ReshapeLayer::run() { reshapeGeneric(); } } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/cpu/kernel/ReshapeLayer.h b/runtime/onert/backend/cpu/kernel/ReshapeLayer.h similarity index 73% rename from runtime/neurun/backend/cpu/kernel/ReshapeLayer.h rename to runtime/onert/backend/cpu/kernel/ReshapeLayer.h index 62a4fc9f339..7a95b6d35e6 100644 --- a/runtime/neurun/backend/cpu/kernel/ReshapeLayer.h +++ b/runtime/onert/backend/cpu/kernel/ReshapeLayer.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_CPU_KERNEL_RESHAPELAYER_H__ -#define __NEURUN_BACKEND_CPU_KERNEL_RESHAPELAYER_H__ +#ifndef __ONERT_BACKEND_CPU_KERNEL_RESHAPELAYER_H__ +#define __ONERT_BACKEND_CPU_KERNEL_RESHAPELAYER_H__ #include "../operand/Tensor.h" #include -namespace neurun +namespace onert { namespace backend { @@ -30,7 +30,7 @@ namespace cpu namespace kernel { -class ReshapeLayer : public ::neurun::exec::IFunction +class ReshapeLayer : public ::onert::exec::IFunction { public: ReshapeLayer(); @@ -38,7 +38,8 @@ class ReshapeLayer : public ::neurun::exec::IFunction public: void reshapeGeneric(); - void configure(const operand::Tensor *input, operand::Tensor *output); + void configure(const operand::Tensor *input, const operand::Tensor *shape, + operand::Tensor *output); void run(); void runSync() @@ -50,12 +51,13 @@ class ReshapeLayer : public ::neurun::exec::IFunction private: const operand::Tensor *_input; + const operand::Tensor *_shape; operand::Tensor *_output; }; } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_CPU_KERNEL_RESHAPELAYER_H__ +#endif // __ONERT_BACKEND_CPU_KERNEL_RESHAPELAYER_H__ diff --git a/runtime/onert/backend/cpu/kernel/RsqrtLayer.cc b/runtime/onert/backend/cpu/kernel/RsqrtLayer.cc new file mode 100644 index 00000000000..d94ff875128 --- /dev/null +++ b/runtime/onert/backend/cpu/kernel/RsqrtLayer.cc @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2020 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 "RsqrtLayer.h" + +#include "OperationUtils.h" + +#include + +namespace onert +{ +namespace backend +{ +namespace cpu +{ +namespace kernel +{ +RsqrtLayer::RsqrtLayer() : _input(nullptr), _output(nullptr) +{ + // DO NOTHING +} + +void RsqrtLayer::rsqrtFloat32() +{ + nnfw::cker::Rsqrt( + convertTensorToCkerShape(_input), reinterpret_cast(_input->buffer()), + convertTensorToCkerShape(_output), reinterpret_cast(_output->buffer())); +} + +void RsqrtLayer::rsqrtQuant8() { throw std::runtime_error{"NYI : QASYMM8 not supported"}; } + +void RsqrtLayer::configure(const operand::Tensor *input, operand::Tensor *output) +{ + _input = input; + _output = output; +} + +void RsqrtLayer::run() +{ + if (_input->data_type() == OperandType::FLOAT32) + { + rsqrtFloat32(); + } + else if (_input->data_type() == OperandType::QUANT8_ASYMM) + { + rsqrtQuant8(); + } + else + { + throw std::runtime_error{"Rsqrt: unsupported data type"}; + } +} + +} // namespace kernel +} // namespace cpu +} // namespace backend +} // namespace onert diff --git a/runtime/onert/backend/cpu/kernel/RsqrtLayer.h b/runtime/onert/backend/cpu/kernel/RsqrtLayer.h new file mode 100644 index 00000000000..188d53160f4 --- /dev/null +++ b/runtime/onert/backend/cpu/kernel/RsqrtLayer.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2020 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 riting, 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 __ONERT_BACKEND_CPU_KERNEL_RSQRTLAYER_H__ +#define __ONERT_BACKEND_CPU_KERNEL_RSQRTLAYER_H__ + +#include "../operand/Tensor.h" + +#include + +namespace onert +{ +namespace backend +{ +namespace cpu +{ +namespace kernel +{ +class RsqrtLayer : public ::onert::exec::IFunction +{ +public: + RsqrtLayer(); + + void configure(const operand::Tensor *input, operand::Tensor *output); + + void run(); + void runSync() + { + // this rsqrttract method is used just for profiling and called for + // backend::acl_common::AclFunction + run(); + } + +private: + void rsqrtFloat32(); + void rsqrtQuant8(); + const operand::Tensor *_input; + operand::Tensor *_output; +}; + +} // namespace kernel +} // namespace cpu +} // namespace backend +} // namespace onert + +#endif // __ONERT_BACKEND_CPU_KERNEL_RSQRTLAYER_H__ diff --git a/runtime/onert/backend/cpu/kernel/SinLayer.cc b/runtime/onert/backend/cpu/kernel/SinLayer.cc new file mode 100644 index 00000000000..db8186ac672 --- /dev/null +++ b/runtime/onert/backend/cpu/kernel/SinLayer.cc @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2020 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 "SinLayer.h" +#include "OperationUtils.h" + +#include + +namespace onert +{ +namespace backend +{ +namespace cpu +{ +namespace kernel +{ +SinLayer::SinLayer() : _input(nullptr), _output(nullptr) +{ + // DO NOTHING +} + +void SinLayer::sinFloat32() +{ + nnfw::cker::Sin(convertTensorToCkerShape(_input), + reinterpret_cast(_input->buffer()), + convertTensorToCkerShape(_output), reinterpret_cast(_output->buffer())); +} + +void SinLayer::sinQuant8() { throw std::runtime_error{"NYI"}; } + +void SinLayer::configure(const operand::Tensor *input, operand::Tensor *output) +{ + _input = input; + _output = output; +} + +void SinLayer::run() +{ + if (_input->data_type() == OperandType::FLOAT32) + { + sinFloat32(); + } + else if (_input->data_type() == OperandType::QUANT8_ASYMM) + { + sinQuant8(); + } + else + { + throw std::runtime_error{"Sin: unsupported data type"}; + } +} + +} // namespace kernel +} // namespace cpu +} // namespace backend +} // namespace onert diff --git a/runtime/onert/backend/cpu/kernel/SinLayer.h b/runtime/onert/backend/cpu/kernel/SinLayer.h new file mode 100644 index 00000000000..7898cf05019 --- /dev/null +++ b/runtime/onert/backend/cpu/kernel/SinLayer.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2020 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 riting, 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 __ONERT_BACKEND_CPU_KERNEL_SINLAYER_H__ +#define __ONERT_BACKEND_CPU_KERNEL_SINLAYER_H__ + +#include "../operand/Tensor.h" + +#include + +namespace onert +{ +namespace backend +{ +namespace cpu +{ +namespace kernel +{ +class SinLayer : public ::onert::exec::IFunction +{ +public: + SinLayer(); + + void configure(const operand::Tensor *input, operand::Tensor *output); + + void run(); + void runSync() + { + // this abstract method is used just for profiling and called for + // backend::acl_common::AclFunction + run(); + } + +private: + void sinFloat32(); + void sinQuant8(); + + const operand::Tensor *_input; + operand::Tensor *_output; +}; + +} // namespace kernel +} // namespace cpu +} // namespace backend +} // namespace onert + +#endif // __ONERT_BACKEND_CPU_KERNEL_SINLAYER_H__ diff --git a/runtime/neurun/backend/cpu/kernel/SliceLayer.cc b/runtime/onert/backend/cpu/kernel/SliceLayer.cc similarity index 98% rename from runtime/neurun/backend/cpu/kernel/SliceLayer.cc rename to runtime/onert/backend/cpu/kernel/SliceLayer.cc index 1b0020410c3..1ade5fb4465 100644 --- a/runtime/neurun/backend/cpu/kernel/SliceLayer.cc +++ b/runtime/onert/backend/cpu/kernel/SliceLayer.cc @@ -20,7 +20,7 @@ #include -namespace neurun +namespace onert { namespace backend { @@ -108,4 +108,4 @@ void SliceLayer::run() } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/cpu/kernel/SliceLayer.h b/runtime/onert/backend/cpu/kernel/SliceLayer.h similarity index 86% rename from runtime/neurun/backend/cpu/kernel/SliceLayer.h rename to runtime/onert/backend/cpu/kernel/SliceLayer.h index e6cbc8126bb..bb18c890cd0 100644 --- a/runtime/neurun/backend/cpu/kernel/SliceLayer.h +++ b/runtime/onert/backend/cpu/kernel/SliceLayer.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_CPU_KERNEL_SLICELAYER_H__ -#define __NEURUN_BACKEND_CPU_KERNEL_SLICELAYER_H__ +#ifndef __ONERT_BACKEND_CPU_KERNEL_SLICELAYER_H__ +#define __ONERT_BACKEND_CPU_KERNEL_SLICELAYER_H__ #include "../operand/Tensor.h" #include -namespace neurun +namespace onert { namespace backend { @@ -30,7 +30,7 @@ namespace cpu namespace kernel { -class SliceLayer : public ::neurun::exec::IFunction +class SliceLayer : public ::onert::exec::IFunction { public: SliceLayer(); @@ -66,6 +66,6 @@ class SliceLayer : public ::neurun::exec::IFunction } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_CPU_KERNEL_SLICELAYER_H__ +#endif // __ONERT_BACKEND_CPU_KERNEL_SLICELAYER_H__ diff --git a/runtime/neurun/backend/cpu/kernel/SoftMaxLayer.cc b/runtime/onert/backend/cpu/kernel/SoftMaxLayer.cc similarity index 99% rename from runtime/neurun/backend/cpu/kernel/SoftMaxLayer.cc rename to runtime/onert/backend/cpu/kernel/SoftMaxLayer.cc index 0aae2fc938a..7a1ba48aa37 100644 --- a/runtime/neurun/backend/cpu/kernel/SoftMaxLayer.cc +++ b/runtime/onert/backend/cpu/kernel/SoftMaxLayer.cc @@ -20,7 +20,7 @@ #include -namespace neurun +namespace onert { namespace backend { @@ -170,4 +170,4 @@ void SoftMaxLayer::run() } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/cpu/kernel/SoftMaxLayer.h b/runtime/onert/backend/cpu/kernel/SoftMaxLayer.h similarity index 83% rename from runtime/neurun/backend/cpu/kernel/SoftMaxLayer.h rename to runtime/onert/backend/cpu/kernel/SoftMaxLayer.h index f455438e8cb..bb29b4fda10 100644 --- a/runtime/neurun/backend/cpu/kernel/SoftMaxLayer.h +++ b/runtime/onert/backend/cpu/kernel/SoftMaxLayer.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_CPU_KERNEL_SOFTMAXLAYER_H__ -#define __NEURUN_BACKEND_CPU_KERNEL_SOFTMAXLAYER_H__ +#ifndef __ONERT_BACKEND_CPU_KERNEL_SOFTMAXLAYER_H__ +#define __ONERT_BACKEND_CPU_KERNEL_SOFTMAXLAYER_H__ #include "../operand/Tensor.h" #include -namespace neurun +namespace onert { namespace backend { @@ -30,7 +30,7 @@ namespace cpu namespace kernel { -class SoftMaxLayer : public ::neurun::exec::IFunction +class SoftMaxLayer : public ::onert::exec::IFunction { public: SoftMaxLayer(); @@ -60,6 +60,6 @@ class SoftMaxLayer : public ::neurun::exec::IFunction } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_CPU_KERNEL_SOFTMAXLAYER_H__ +#endif // __ONERT_BACKEND_CPU_KERNEL_SOFTMAXLAYER_H__ diff --git a/runtime/onert/backend/cpu/kernel/SplitLayer.cc b/runtime/onert/backend/cpu/kernel/SplitLayer.cc new file mode 100644 index 00000000000..e4c5ef3a021 --- /dev/null +++ b/runtime/onert/backend/cpu/kernel/SplitLayer.cc @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2020 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 "SplitLayer.h" + +#include "OperationUtils.h" + +#include + +namespace onert +{ +namespace backend +{ +namespace cpu +{ +namespace kernel +{ + +SplitLayer::SplitLayer() : _input(nullptr), _num_splits(0), _axis(0), _outputs() +{ + // DO NOTHING +} + +void SplitLayer::splitFloat32() +{ + nnfw::cker::SplitParams op_params; + op_params.axis = _axis; + op_params.num_split = _num_splits; + + std::vector outputDimsPtr; + std::vector outputDims; + outputDimsPtr.reserve(_num_splits); + outputDims.reserve(_num_splits); + + for (uint32_t i = 0; i < _num_splits; i++) + { + outputDims.push_back(convertTensorToCkerShape(_outputs[i])); + outputDimsPtr.push_back(&outputDims[i]); + } + + std::vector outputFloatPtrs; + + for (const auto output : _outputs) + { + outputFloatPtrs.emplace_back(reinterpret_cast(output->buffer())); + } + + nnfw::cker::Split(op_params, convertTensorToCkerShape(_input), + reinterpret_cast(_input->buffer()), + convertTensorToCkerShape(_outputs[0]), outputFloatPtrs.data()); +} + +void SplitLayer::splitQuant8() { throw std::runtime_error{"Split: NYI quant8 type"}; } + +void SplitLayer::configure(const operand::Tensor *input, uint16_t num_splits, int16_t axis, + std::vector &outputs) +{ + assert(input != nullptr); + + _num_splits = num_splits; + _input = input; + _axis = axis; + _outputs = outputs; +} + +void SplitLayer::run() +{ + if (_input->data_type() == OperandType::FLOAT32) + { + splitFloat32(); + } + else if (_input->data_type() == OperandType::QUANT8_ASYMM) + { + splitQuant8(); + } + else + { + throw std::runtime_error{"Split: Unsupported input type"}; + } +} + +} // namespace kernel +} // namespace cpu +} // namespace backend +} // namespace onert diff --git a/runtime/onert/backend/cpu/kernel/SplitLayer.h b/runtime/onert/backend/cpu/kernel/SplitLayer.h new file mode 100644 index 00000000000..9f236f0afea --- /dev/null +++ b/runtime/onert/backend/cpu/kernel/SplitLayer.h @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2020 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 __ONERT_BACKEND_CPU_KERNEL_SPLITLAYER_H__ +#define __ONERT_BACKEND_CPU_KERNEL_SPLITLAYER_H__ + +#include "../operand/Tensor.h" + +#include + +namespace onert +{ +namespace backend +{ +namespace cpu +{ +namespace kernel +{ + +class SplitLayer : public ::onert::exec::IFunction +{ +public: + SplitLayer(); + +public: + void splitFloat32(); + + void splitQuant8(); + + void configure(const operand::Tensor *input, uint16_t num_splits, int16_t axis, + std::vector &outputs); + + void run(); + void runSync() + { + // this abstract method is used just for profiling and called for + // backend::acl_common::AclFunction + run(); + } + +private: + const operand::Tensor *_input; + uint16_t _num_splits; + int16_t _axis; + std::vector _outputs; +}; + +} // namespace kernel +} // namespace cpu +} // namespace backend +} // namespace onert + +#endif // __ONERT_BACKEND_CPU_KERNEL_SPLITLAYER_H__ diff --git a/runtime/onert/backend/cpu/kernel/StridedSliceLayer.cc b/runtime/onert/backend/cpu/kernel/StridedSliceLayer.cc new file mode 100644 index 00000000000..22315c7c679 --- /dev/null +++ b/runtime/onert/backend/cpu/kernel/StridedSliceLayer.cc @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2020 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 "StridedSliceLayer.h" + +#include "OperationUtils.h" + +#include + +namespace onert +{ +namespace backend +{ +namespace cpu +{ +namespace kernel +{ + +StridedSliceLayer::StridedSliceLayer() + : _input(nullptr), _begin(nullptr), _end(nullptr), _strides(nullptr), _output(nullptr), + _begin_mask(0), _ellipsis_mask(0), _end_mask(0), _new_axis_mask(0), _shrink_axis_mask(0), + _rank(0) +{ +} + +void StridedSliceLayer::stridedSliceFloat32() +{ + auto op_params = nnfw::cker::buildStridedSliceParams( + reinterpret_cast(_begin->buffer()), reinterpret_cast(_end->buffer()), + reinterpret_cast(_strides->buffer()), _begin_mask, _end_mask, _shrink_axis_mask, + _rank); + + nnfw::cker::checkOutputSize(op_params, convertTensorToCkerShape(_input), + convertTensorToCkerShape(_output), _rank); + + nnfw::cker::StridedSlice(op_params, convertTensorToCkerShape(_input), + reinterpret_cast(_input->buffer()), + convertTensorToCkerShape(_output), + reinterpret_cast(_output->buffer())); +} + +void StridedSliceLayer::stridedSliceQuant8() +{ + // cker quant8 stridedSlice is not implemented yet + throw std::runtime_error{"NYI"}; +} + +void StridedSliceLayer::configure(const operand::Tensor *input, const operand::Tensor *begin, + const operand::Tensor *end, const operand::Tensor *strides, + operand::Tensor *output, const int32_t begin_mask, + const int32_t end_mask, const int32_t shrink_axis_mask, + const int32_t rank) +{ + _input = input; + _begin = begin; + _end = end; + _strides = strides; + _output = output; + + _rank = rank; + _begin_mask = begin_mask; + _ellipsis_mask = 0; + _end_mask = end_mask; + _new_axis_mask = 0; + _shrink_axis_mask = shrink_axis_mask; +} + +void StridedSliceLayer::run() +{ + if (_input->data_type() == OperandType::FLOAT32) + { + stridedSliceFloat32(); + } + else if (_input->data_type() == OperandType::QUANT8_ASYMM) + { + stridedSliceQuant8(); + } +} + +} // namespace kernel +} // namespace cpu +} // namespace backend +} // namespace onert diff --git a/runtime/onert/backend/cpu/kernel/StridedSliceLayer.h b/runtime/onert/backend/cpu/kernel/StridedSliceLayer.h new file mode 100644 index 00000000000..7888eff3c97 --- /dev/null +++ b/runtime/onert/backend/cpu/kernel/StridedSliceLayer.h @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2020 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 __ONERT_BACKEND_CPU_KERNEL_STRIDEDSLICELAYER_H__ +#define __ONERT_BACKEND_CPU_KERNEL_STRIDEDSLICELAYER_H__ + +#include "../operand/Tensor.h" +#include "OperationUtils.h" + +#include + +namespace onert +{ +namespace backend +{ +namespace cpu +{ +namespace kernel +{ + +class StridedSliceLayer : public ::onert::exec::IFunction +{ +public: + StridedSliceLayer(); + +public: + void configure(const operand::Tensor *input, const operand::Tensor *begin, + const operand::Tensor *end, const operand::Tensor *strides, + operand::Tensor *output, const int32_t begin_mask, const int32_t end_mask, + const int32_t shrink_axis_mask, const int32_t rank); + + void run(); + void runSync() + { + // this abstract method is used just for profiling and called for + // backend::acl_common::AclFunction + run(); + } + +private: + void stridedSliceFloat32(); + void stridedSliceQuant8(); + +private: + const operand::Tensor *_input; + const operand::Tensor *_begin; + const operand::Tensor *_end; + const operand::Tensor *_strides; + operand::Tensor *_output; + + int32_t _begin_mask; + int32_t _ellipsis_mask; + int32_t _end_mask; + int32_t _new_axis_mask; + int32_t _shrink_axis_mask; + + int32_t _rank; +}; + +} // namespace kernel +} // namespace cpu +} // namespace backend +} // namespace onert + +#endif // __ONERT_BACKEND_CPU_KERNEL_STRIDEDSLICELAYER_H__ diff --git a/runtime/neurun/backend/cpu/kernel/SubLayer.cc b/runtime/onert/backend/cpu/kernel/SubLayer.cc similarity index 98% rename from runtime/neurun/backend/cpu/kernel/SubLayer.cc rename to runtime/onert/backend/cpu/kernel/SubLayer.cc index d5382211802..15aa4383596 100644 --- a/runtime/neurun/backend/cpu/kernel/SubLayer.cc +++ b/runtime/onert/backend/cpu/kernel/SubLayer.cc @@ -18,7 +18,7 @@ #include -namespace neurun +namespace onert { namespace backend { @@ -89,4 +89,4 @@ void SubLayer::run() } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/cpu/kernel/SubLayer.h b/runtime/onert/backend/cpu/kernel/SubLayer.h similarity index 86% rename from runtime/neurun/backend/cpu/kernel/SubLayer.h rename to runtime/onert/backend/cpu/kernel/SubLayer.h index 98d24b04fd2..48fa976692b 100644 --- a/runtime/neurun/backend/cpu/kernel/SubLayer.h +++ b/runtime/onert/backend/cpu/kernel/SubLayer.h @@ -14,15 +14,15 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_CPU_KERNEL_SUBLAYER_H__ -#define __NEURUN_BACKEND_CPU_KERNEL_SUBLAYER_H__ +#ifndef __ONERT_BACKEND_CPU_KERNEL_SUBLAYER_H__ +#define __ONERT_BACKEND_CPU_KERNEL_SUBLAYER_H__ #include "../operand/Tensor.h" #include "OperationUtils.h" #include -namespace neurun +namespace onert { namespace backend { @@ -31,7 +31,7 @@ namespace cpu namespace kernel { -class SubLayer : public ::neurun::exec::IFunction +class SubLayer : public ::onert::exec::IFunction { public: SubLayer() : _lhs(nullptr), _rhs(nullptr), _output(nullptr) @@ -66,6 +66,6 @@ class SubLayer : public ::neurun::exec::IFunction } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_CPU_KERNEL_SUBLAYER_H__ +#endif // __ONERT_BACKEND_CPU_KERNEL_SUBLAYER_H__ diff --git a/runtime/neurun/backend/cpu/kernel/TanhLayer.cc b/runtime/onert/backend/cpu/kernel/TanhLayer.cc similarity index 97% rename from runtime/neurun/backend/cpu/kernel/TanhLayer.cc rename to runtime/onert/backend/cpu/kernel/TanhLayer.cc index b5e1c4c0e45..6a9274f7a6c 100644 --- a/runtime/neurun/backend/cpu/kernel/TanhLayer.cc +++ b/runtime/onert/backend/cpu/kernel/TanhLayer.cc @@ -20,7 +20,7 @@ #include -namespace neurun +namespace onert { namespace backend { @@ -68,4 +68,4 @@ void TanhLayer::run() } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/cpu/kernel/TanhLayer.h b/runtime/onert/backend/cpu/kernel/TanhLayer.h similarity index 83% rename from runtime/neurun/backend/cpu/kernel/TanhLayer.h rename to runtime/onert/backend/cpu/kernel/TanhLayer.h index a05bd3ee6d8..8fb621cdb86 100644 --- a/runtime/neurun/backend/cpu/kernel/TanhLayer.h +++ b/runtime/onert/backend/cpu/kernel/TanhLayer.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_CPU_KERNEL_TANHLAYER_H__ -#define __NEURUN_BACKEND_CPU_KERNEL_TANHLAYER_H__ +#ifndef __ONERT_BACKEND_CPU_KERNEL_TANHLAYER_H__ +#define __ONERT_BACKEND_CPU_KERNEL_TANHLAYER_H__ #include "../operand/Tensor.h" #include -namespace neurun +namespace onert { namespace backend { @@ -30,7 +30,7 @@ namespace cpu namespace kernel { -class TanhLayer : public ::neurun::exec::IFunction +class TanhLayer : public ::onert::exec::IFunction { public: TanhLayer(); @@ -58,6 +58,6 @@ class TanhLayer : public ::neurun::exec::IFunction } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_CPU_KERNEL_TANHLAYER_H__ +#endif // __ONERT_BACKEND_CPU_KERNEL_TANHLAYER_H__ diff --git a/runtime/neurun/backend/cpu/kernel/TransposeLayer.cc b/runtime/onert/backend/cpu/kernel/TransposeLayer.cc similarity index 98% rename from runtime/neurun/backend/cpu/kernel/TransposeLayer.cc rename to runtime/onert/backend/cpu/kernel/TransposeLayer.cc index 7713b24d09a..31b1dd12d21 100644 --- a/runtime/neurun/backend/cpu/kernel/TransposeLayer.cc +++ b/runtime/onert/backend/cpu/kernel/TransposeLayer.cc @@ -20,7 +20,7 @@ #include -namespace neurun +namespace onert { namespace backend { @@ -78,4 +78,4 @@ void TransposeLayer::run() } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/cpu/kernel/TransposeLayer.h b/runtime/onert/backend/cpu/kernel/TransposeLayer.h similarity index 82% rename from runtime/neurun/backend/cpu/kernel/TransposeLayer.h rename to runtime/onert/backend/cpu/kernel/TransposeLayer.h index 811ff4edb9e..ffe7c2ae53b 100644 --- a/runtime/neurun/backend/cpu/kernel/TransposeLayer.h +++ b/runtime/onert/backend/cpu/kernel/TransposeLayer.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_CPU_KERNEL_TRANSPOSELAYER_H__ -#define __NEURUN_BACKEND_CPU_KERNEL_TRANSPOSELAYER_H__ +#ifndef __ONERT_BACKEND_CPU_KERNEL_TRANSPOSELAYER_H__ +#define __ONERT_BACKEND_CPU_KERNEL_TRANSPOSELAYER_H__ #include "../operand/Tensor.h" #include -namespace neurun +namespace onert { namespace backend { @@ -30,7 +30,7 @@ namespace cpu namespace kernel { -class TransposeLayer : public ::neurun::exec::IFunction +class TransposeLayer : public ::onert::exec::IFunction { public: TransposeLayer(); @@ -56,6 +56,6 @@ class TransposeLayer : public ::neurun::exec::IFunction } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_CPU_KERNEL_TRANSPOSELAYER_H__ +#endif // __ONERT_BACKEND_CPU_KERNEL_TRANSPOSELAYER_H__ diff --git a/runtime/neurun/backend/cpu/kernel/UnpackLayer.cc b/runtime/onert/backend/cpu/kernel/UnpackLayer.cc similarity index 98% rename from runtime/neurun/backend/cpu/kernel/UnpackLayer.cc rename to runtime/onert/backend/cpu/kernel/UnpackLayer.cc index f5bcc2b6050..fe07e3e19ce 100644 --- a/runtime/neurun/backend/cpu/kernel/UnpackLayer.cc +++ b/runtime/onert/backend/cpu/kernel/UnpackLayer.cc @@ -20,7 +20,7 @@ #include -namespace neurun +namespace onert { namespace backend { @@ -101,4 +101,4 @@ void UnpackLayer::run() } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/cpu/kernel/UnpackLayer.h b/runtime/onert/backend/cpu/kernel/UnpackLayer.h similarity index 84% rename from runtime/neurun/backend/cpu/kernel/UnpackLayer.h rename to runtime/onert/backend/cpu/kernel/UnpackLayer.h index 092a7c10781..23d064db2c7 100644 --- a/runtime/neurun/backend/cpu/kernel/UnpackLayer.h +++ b/runtime/onert/backend/cpu/kernel/UnpackLayer.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_CPU_KERNEL_UNPACKLAYER_H__ -#define __NEURUN_BACKEND_CPU_KERNEL_UNPACKLAYER_H__ +#ifndef __ONERT_BACKEND_CPU_KERNEL_UNPACKLAYER_H__ +#define __ONERT_BACKEND_CPU_KERNEL_UNPACKLAYER_H__ #include "../operand/Tensor.h" #include -namespace neurun +namespace onert { namespace backend { @@ -30,7 +30,7 @@ namespace cpu namespace kernel { -class UnpackLayer : public ::neurun::exec::IFunction +class UnpackLayer : public ::onert::exec::IFunction { public: UnpackLayer(); @@ -61,6 +61,6 @@ class UnpackLayer : public ::neurun::exec::IFunction } // namespace kernel } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_CPU_KERNEL_UNPACKLAYER_H__ +#endif // __ONERT_BACKEND_CPU_KERNEL_UNPACKLAYER_H__ diff --git a/runtime/neurun/backend/cpu/operand/Tensor.cc b/runtime/onert/backend/cpu/operand/Tensor.cc similarity index 96% rename from runtime/neurun/backend/cpu/operand/Tensor.cc rename to runtime/onert/backend/cpu/operand/Tensor.cc index 70ef32565fb..96ee9302391 100644 --- a/runtime/neurun/backend/cpu/operand/Tensor.cc +++ b/runtime/onert/backend/cpu/operand/Tensor.cc @@ -16,7 +16,7 @@ #include "Tensor.h" -namespace neurun +namespace onert { namespace backend { @@ -42,4 +42,4 @@ void Tensor::access(const std::function &fn) { fn(*this); } } // namespace operand } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/cpu/operand/Tensor.h b/runtime/onert/backend/cpu/operand/Tensor.h similarity index 91% rename from runtime/neurun/backend/cpu/operand/Tensor.h rename to runtime/onert/backend/cpu/operand/Tensor.h index 216248d98e0..f9e7b34d1bf 100644 --- a/runtime/neurun/backend/cpu/operand/Tensor.h +++ b/runtime/onert/backend/cpu/operand/Tensor.h @@ -14,15 +14,15 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_CPU_OPERAND_TENSOR_H__ -#define __NEURUN_BACKEND_CPU_OPERAND_TENSOR_H__ +#ifndef __ONERT_BACKEND_CPU_OPERAND_TENSOR_H__ +#define __ONERT_BACKEND_CPU_OPERAND_TENSOR_H__ #include "Allocator.h" #include #include -namespace neurun +namespace onert { namespace backend { @@ -84,6 +84,7 @@ class Tensor : public ITensor ir::Layout layout() const override { return ir::Layout::NHWC; } bool has_padding() const override { return false; } void access(const std::function &fn) final; + bool is_dynamic() const override { return _info.memAllocType() == ir::MemAllocType::DYNAMIC; } void increase_ref() { @@ -118,6 +119,6 @@ class Tensor : public ITensor } // namespace operand } // namespace cpu } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_CPU_OPERAND_TENSOR_H__ +#endif // __ONERT_BACKEND_CPU_OPERAND_TENSOR_H__ diff --git a/runtime/neurun/backend/cpu_common/Allocator.cc b/runtime/onert/backend/cpu_common/Allocator.cc similarity index 96% rename from runtime/neurun/backend/cpu_common/Allocator.cc rename to runtime/onert/backend/cpu_common/Allocator.cc index f37ab85132d..253fc47539f 100644 --- a/runtime/neurun/backend/cpu_common/Allocator.cc +++ b/runtime/onert/backend/cpu_common/Allocator.cc @@ -18,7 +18,7 @@ #include "util/logging.h" -namespace neurun +namespace onert { namespace backend { @@ -35,4 +35,4 @@ Allocator::Allocator(uint32_t capacity) } // namespace cpu_common } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/cpu_common/Allocator.h b/runtime/onert/backend/cpu_common/Allocator.h similarity index 86% rename from runtime/neurun/backend/cpu_common/Allocator.h rename to runtime/onert/backend/cpu_common/Allocator.h index 84ab113bde8..fa67fc7c404 100644 --- a/runtime/neurun/backend/cpu_common/Allocator.h +++ b/runtime/onert/backend/cpu_common/Allocator.h @@ -19,12 +19,12 @@ * @brief       This file contains Allocator related classes */ -#ifndef __NEURUN_BACKEND_CPU_COMMON_ALLOCATOR_H__ -#define __NEURUN_BACKEND_CPU_COMMON_ALLOCATOR_H__ +#ifndef __ONERT_BACKEND_CPU_COMMON_ALLOCATOR_H__ +#define __ONERT_BACKEND_CPU_COMMON_ALLOCATOR_H__ #include -namespace neurun +namespace onert { namespace backend { @@ -51,6 +51,6 @@ class Allocator } // namespace cpu_common } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_CPU_COMMON_ALLOCATOR_H__ +#endif // __ONERT_BACKEND_CPU_COMMON_ALLOCATOR_H__ diff --git a/runtime/onert/backend/cpu_common/CMakeLists.txt b/runtime/onert/backend/cpu_common/CMakeLists.txt new file mode 100644 index 00000000000..bc9e014e73d --- /dev/null +++ b/runtime/onert/backend/cpu_common/CMakeLists.txt @@ -0,0 +1,35 @@ +file(GLOB SOURCES "*.cc") +file(GLOB_RECURSE TESTS "*.test.cc") +list(REMOVE_ITEM SOURCES ${TESTS}) + +add_library(${LIB_ONERT_BACKEND_CPU_COMMON} STATIC ${SOURCES}) + +target_include_directories(${LIB_ONERT_BACKEND_CPU_COMMON} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +target_link_libraries(${LIB_ONERT_BACKEND_CPU_COMMON} PUBLIC onert_core) +target_link_libraries(${LIB_ONERT_BACKEND_CPU_COMMON} PRIVATE nnfw_lib_misc) +target_link_libraries(${LIB_ONERT_BACKEND_CPU_COMMON} PRIVATE nnfw_common) +target_link_libraries(${LIB_ONERT_BACKEND_CPU_COMMON} PRIVATE nnfw_coverage) + +set_target_properties(${LIB_ONERT_BACKEND_CPU_COMMON} PROPERTIES POSITION_INDEPENDENT_CODE ON) +set_target_properties(${LIB_ONERT_BACKEND_CPU_COMMON} PROPERTIES OUTPUT_NAME backend_cpu_common) + +install(TARGETS ${LIB_ONERT_BACKEND_CPU_COMMON} ARCHIVE DESTINATION lib) +install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + DESTINATION "include/onert" + FILES_MATCHING PATTERN "*.h" + ) + +if(NOT ENABLE_TEST) + return() +endif(NOT ENABLE_TEST) + +# Unit Tests +set(TEST_ONERT_BACKEND_CPU_COMMON test_onert_backend_cpu_common) + +add_executable(${TEST_ONERT_BACKEND_CPU_COMMON} ${TESTS}) + +target_link_libraries(${TEST_ONERT_BACKEND_CPU_COMMON} ${LIB_ONERT_BACKEND_CPU_COMMON}) +target_link_libraries(${TEST_ONERT_BACKEND_CPU_COMMON} gtest gtest_main dl ${LIB_PTHREAD}) + +add_test(${TEST_ONERT_BACKEND_CPU_COMMON} ${TEST_ONERT_BACKEND_CPU_COMMON}) +install(TARGETS ${TEST_ONERT_BACKEND_CPU_COMMON} DESTINATION unittest) diff --git a/runtime/neurun/backend/cpu_common/MemoryManager.cc b/runtime/onert/backend/cpu_common/MemoryManager.cc similarity index 98% rename from runtime/neurun/backend/cpu_common/MemoryManager.cc rename to runtime/onert/backend/cpu_common/MemoryManager.cc index 134316d7959..df6aa12f8d7 100644 --- a/runtime/neurun/backend/cpu_common/MemoryManager.cc +++ b/runtime/onert/backend/cpu_common/MemoryManager.cc @@ -21,7 +21,7 @@ #include #include "util/ConfigSource.h" -namespace neurun +namespace onert { namespace backend { @@ -88,4 +88,4 @@ void DynamicMemoryManager::deallocate(void) } // namespace cpu_common } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/cpu_common/MemoryManager.h b/runtime/onert/backend/cpu_common/MemoryManager.h similarity index 89% rename from runtime/neurun/backend/cpu_common/MemoryManager.h rename to runtime/onert/backend/cpu_common/MemoryManager.h index d8b2538e0d2..b6d2d5192a2 100644 --- a/runtime/neurun/backend/cpu_common/MemoryManager.h +++ b/runtime/onert/backend/cpu_common/MemoryManager.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_CPU_MEMORY_MANAGER_H__ -#define __NEURUN_BACKEND_CPU_MEMORY_MANAGER_H__ +#ifndef __ONERT_BACKEND_CPU_MEMORY_MANAGER_H__ +#define __ONERT_BACKEND_CPU_MEMORY_MANAGER_H__ #include "backend/IMemoryManager.h" -#include +#include "MemoryPlanner.h" #include "ir/OperandIndexMap.h" -namespace neurun +namespace onert { namespace backend { @@ -67,6 +67,6 @@ class DynamicMemoryManager } // namespace cpu_common } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_CPU_MEMORY_MANAGER_H__ +#endif // __ONERT_BACKEND_CPU_MEMORY_MANAGER_H__ diff --git a/runtime/neurun/backend/cpu_common/MemoryPlanner.cc b/runtime/onert/backend/cpu_common/MemoryPlanner.cc similarity index 99% rename from runtime/neurun/backend/cpu_common/MemoryPlanner.cc rename to runtime/onert/backend/cpu_common/MemoryPlanner.cc index 8f1bbaed093..4b7f12cfd5a 100644 --- a/runtime/neurun/backend/cpu_common/MemoryPlanner.cc +++ b/runtime/onert/backend/cpu_common/MemoryPlanner.cc @@ -18,7 +18,7 @@ #include "util/logging.h" #include -namespace neurun +namespace onert { namespace backend { @@ -209,4 +209,4 @@ WICPlanner::MemoryPlans &WICPlanner::memory_plans() } // namespace cpu_common } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/cpu_common/MemoryPlanner.h b/runtime/onert/backend/cpu_common/MemoryPlanner.h similarity index 95% rename from runtime/neurun/backend/cpu_common/MemoryPlanner.h rename to runtime/onert/backend/cpu_common/MemoryPlanner.h index 11cd7c0771f..4f9724328c9 100644 --- a/runtime/neurun/backend/cpu_common/MemoryPlanner.h +++ b/runtime/onert/backend/cpu_common/MemoryPlanner.h @@ -19,8 +19,8 @@ * @brief       This file contains Memory Planning related classes */ -#ifndef __NEURUN_BACKEND_CPU_COMMON_MEMORY_PLANNER_H__ -#define __NEURUN_BACKEND_CPU_COMMON_MEMORY_PLANNER_H__ +#ifndef __ONERT_BACKEND_CPU_COMMON_MEMORY_PLANNER_H__ +#define __ONERT_BACKEND_CPU_COMMON_MEMORY_PLANNER_H__ #include #include @@ -29,7 +29,7 @@ #include "Allocator.h" #include "ir/OperandIndexMap.h" -namespace neurun +namespace onert { namespace backend { @@ -195,6 +195,6 @@ class WICPlanner : public IMemoryPlanner } // namespace cpu_common } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_CPU_COMMON_MEMORY_PLANNER_H__ +#endif // __ONERT_BACKEND_CPU_COMMON_MEMORY_PLANNER_H__ diff --git a/runtime/neurun/backend/cpu_common/MemoryPlanner.test.cc b/runtime/onert/backend/cpu_common/MemoryPlanner.test.cc similarity index 87% rename from runtime/neurun/backend/cpu_common/MemoryPlanner.test.cc rename to runtime/onert/backend/cpu_common/MemoryPlanner.test.cc index b2be7db248d..5208a94d476 100644 --- a/runtime/neurun/backend/cpu_common/MemoryPlanner.test.cc +++ b/runtime/onert/backend/cpu_common/MemoryPlanner.test.cc @@ -21,16 +21,16 @@ TEST(Allocator, allocate_test) { - ::neurun::backend::cpu_common::Allocator allocator(1024); + ::onert::backend::cpu_common::Allocator allocator(1024); ASSERT_NE(allocator.base(), nullptr); } TEST(BumpPlanner, claim_test) { - ::neurun::backend::cpu_common::BumpPlanner planner; + ::onert::backend::cpu_common::BumpPlanner planner; auto claim = [&planner](uint32_t index, size_t size, uint32_t expected_offset) { - neurun::ir::OperandIndex mem_idx(index); + onert::ir::OperandIndex mem_idx(index); planner.claim(mem_idx, size); auto mem_blk = planner.memory_plans()[mem_idx]; ASSERT_EQ(mem_blk.offset, expected_offset); @@ -44,10 +44,10 @@ TEST(BumpPlanner, claim_test) TEST(FirstFitPlanner, claim_release_test) { - ::neurun::backend::cpu_common::FirstFitPlanner planner; + ::onert::backend::cpu_common::FirstFitPlanner planner; auto claim = [&planner](uint32_t index, size_t size, uint32_t expected_offset) { - neurun::ir::OperandIndex mem_idx(index); + onert::ir::OperandIndex mem_idx(index); planner.claim(mem_idx, size); auto mem_blk = planner.memory_plans()[mem_idx]; ASSERT_EQ(mem_blk.offset, expected_offset); @@ -55,7 +55,7 @@ TEST(FirstFitPlanner, claim_release_test) }; auto release = [&planner](uint32_t index) { - neurun::ir::OperandIndex mem_idx(index); + onert::ir::OperandIndex mem_idx(index); planner.release(mem_idx); }; @@ -128,20 +128,20 @@ TEST(FirstFitPlanner, claim_release_test) TEST(WICPlanner, claim_release_test) { - ::neurun::backend::cpu_common::WICPlanner planner; + ::onert::backend::cpu_common::WICPlanner planner; auto claim = [&planner](uint32_t index, size_t size) { - neurun::ir::OperandIndex mem_idx(index); + onert::ir::OperandIndex mem_idx(index); planner.claim(mem_idx, size); }; auto release = [&planner](uint32_t index) { - neurun::ir::OperandIndex mem_idx(index); + onert::ir::OperandIndex mem_idx(index); planner.release(mem_idx); }; auto verify = [&planner](uint32_t index, uint32_t size, uint32_t expected_offset) { - neurun::ir::OperandIndex mem_idx(index); + onert::ir::OperandIndex mem_idx(index); auto mem_blk = planner.memory_plans()[mem_idx]; ASSERT_EQ(mem_blk.offset, expected_offset); ASSERT_EQ(mem_blk.size, size); diff --git a/runtime/neurun/backend/cpu_common/MemoryPlannerFactory.cc b/runtime/onert/backend/cpu_common/MemoryPlannerFactory.cc similarity index 96% rename from runtime/neurun/backend/cpu_common/MemoryPlannerFactory.cc rename to runtime/onert/backend/cpu_common/MemoryPlannerFactory.cc index 9da987aa4d7..322d0de8c4d 100644 --- a/runtime/neurun/backend/cpu_common/MemoryPlannerFactory.cc +++ b/runtime/onert/backend/cpu_common/MemoryPlannerFactory.cc @@ -16,7 +16,7 @@ #include "MemoryPlannerFactory.h" -namespace neurun +namespace onert { namespace backend { @@ -48,4 +48,4 @@ IMemoryPlanner *MemoryPlannerFactory::create(const std::string &key) } // namespace cpu_common } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/backend/cpu_common/MemoryPlannerFactory.h b/runtime/onert/backend/cpu_common/MemoryPlannerFactory.h similarity index 80% rename from runtime/neurun/backend/cpu_common/MemoryPlannerFactory.h rename to runtime/onert/backend/cpu_common/MemoryPlannerFactory.h index 566a0aa4fa7..a85b67ca8cd 100644 --- a/runtime/neurun/backend/cpu_common/MemoryPlannerFactory.h +++ b/runtime/onert/backend/cpu_common/MemoryPlannerFactory.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_CPU_COMMON_MEMORY_PLANNER_FACTORY_H__ -#define __NEURUN_BACKEND_CPU_COMMON_MEMORY_PLANNER_FACTORY_H__ +#ifndef __ONERT_BACKEND_CPU_COMMON_MEMORY_PLANNER_FACTORY_H__ +#define __ONERT_BACKEND_CPU_COMMON_MEMORY_PLANNER_FACTORY_H__ #include "MemoryPlanner.h" #include -namespace neurun +namespace onert { namespace backend { @@ -42,6 +42,6 @@ class MemoryPlannerFactory } // namespace cpu_common } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_CPU_COMMON_MEMORY_PLANNER_FACTORY_H__ +#endif // __ONERT_BACKEND_CPU_COMMON_MEMORY_PLANNER_FACTORY_H__ diff --git a/runtime/onert/core/CMakeLists.txt b/runtime/onert/core/CMakeLists.txt new file mode 100644 index 00000000000..46e57427cee --- /dev/null +++ b/runtime/onert/core/CMakeLists.txt @@ -0,0 +1,21 @@ +file(GLOB_RECURSE SOURCES "src/*.cc") + +add_library(onert_core SHARED ${SOURCES}) +set_target_properties(onert_core PROPERTIES POSITION_INDEPENDENT_CODE ON) +target_include_directories(onert_core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) +target_include_directories(onert_core PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src) +target_link_libraries(onert_core PUBLIC nnfw_lib_misc) +target_link_libraries(onert_core PRIVATE nnfw_lib_cker) +target_link_libraries(onert_core PRIVATE nnfw_common) +target_link_libraries(onert_core PRIVATE nnfw_coverage) +target_link_libraries(onert_core PRIVATE dl ${LIB_PTHREAD}) + +if(ENVVAR_ONERT_CONFIG) + target_compile_definitions(onert_core PRIVATE ENVVAR_FOR_DEFAULT_CONFIG) +endif(ENVVAR_ONERT_CONFIG) + +install(TARGETS onert_core LIBRARY DESTINATION lib) +install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/" + DESTINATION "include/onert" + FILES_MATCHING PATTERN "*.h" PATTERN "*.lst" + ) diff --git a/runtime/neurun/core/include/backend/Backend.h b/runtime/onert/core/include/backend/Backend.h similarity index 82% rename from runtime/neurun/core/include/backend/Backend.h rename to runtime/onert/core/include/backend/Backend.h index b35dd684a4c..4f6ebbba7e5 100644 --- a/runtime/neurun/core/include/backend/Backend.h +++ b/runtime/onert/core/include/backend/Backend.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_BACKEND_H__ -#define __NEURUN_BACKEND_BACKEND_H__ +#ifndef __ONERT_BACKEND_BACKEND_H__ +#define __ONERT_BACKEND_BACKEND_H__ #include @@ -23,7 +23,7 @@ #include "backend/IConfig.h" #include "backend/BackendContext.h" -namespace neurun +namespace onert { namespace backend { @@ -37,7 +37,7 @@ class Backend { public: virtual ~Backend() = default; - virtual std::shared_ptr config() const = 0; + virtual std::shared_ptr config() const = 0; virtual std::unique_ptr newContext(const ir::Graph &graph, const std::shared_ptr &kb, @@ -45,6 +45,6 @@ class Backend }; } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_BACKEND_H__ +#endif // __ONERT_BACKEND_BACKEND_H__ diff --git a/runtime/neurun/core/include/backend/BackendContext.h b/runtime/onert/core/include/backend/BackendContext.h similarity index 94% rename from runtime/neurun/core/include/backend/BackendContext.h rename to runtime/onert/core/include/backend/BackendContext.h index 9cc311dbe9e..3c88b54184a 100644 --- a/runtime/neurun/core/include/backend/BackendContext.h +++ b/runtime/onert/core/include/backend/BackendContext.h @@ -14,13 +14,13 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_BACKEND_CONTEXT_H__ -#define __NEURUN_BACKEND_BACKEND_CONTEXT_H__ +#ifndef __ONERT_BACKEND_BACKEND_CONTEXT_H__ +#define __ONERT_BACKEND_BACKEND_CONTEXT_H__ #include #include "ir/Graph.h" -namespace neurun +namespace onert { namespace backend { @@ -86,6 +86,6 @@ class BackendContext using BackendContexts = std::unordered_map>; } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_BACKEND_CONTEXT_H__ +#endif // __ONERT_BACKEND_BACKEND_CONTEXT_H__ diff --git a/runtime/neurun/core/include/backend/CustomKernelBuilder.h b/runtime/onert/core/include/backend/CustomKernelBuilder.h similarity index 86% rename from runtime/neurun/core/include/backend/CustomKernelBuilder.h rename to runtime/onert/core/include/backend/CustomKernelBuilder.h index a97fad16e1e..2d35406dd12 100644 --- a/runtime/neurun/core/include/backend/CustomKernelBuilder.h +++ b/runtime/onert/core/include/backend/CustomKernelBuilder.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_CUSTOM_KERNEL_BUILDER_H__ -#define __NEURUN_BACKEND_CUSTOM_KERNEL_BUILDER_H__ +#ifndef __ONERT_BACKEND_CUSTOM_KERNEL_BUILDER_H__ +#define __ONERT_BACKEND_CUSTOM_KERNEL_BUILDER_H__ #include "misc/tensor/Shape.h" #include "ir/DataType.h" @@ -23,7 +23,7 @@ #include #include -namespace neurun +namespace onert { namespace exec { @@ -31,9 +31,9 @@ namespace exec class IFunction; } // namespace exec -} // namespace neurun +} // namespace onert -namespace neurun +namespace onert { namespace backend { @@ -72,6 +72,6 @@ class IKernelBuilder } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_CUSTOM_KERNEL_BUILDER_H__ +#endif // __ONERT_BACKEND_CUSTOM_KERNEL_BUILDER_H__ diff --git a/runtime/neurun/core/include/backend/IConfig.h b/runtime/onert/core/include/backend/IConfig.h similarity index 87% rename from runtime/neurun/core/include/backend/IConfig.h rename to runtime/onert/core/include/backend/IConfig.h index 1d2cae47f34..e4e1d5a7f70 100644 --- a/runtime/neurun/core/include/backend/IConfig.h +++ b/runtime/onert/core/include/backend/IConfig.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_ICONFIG_H__ -#define __NEURUN_BACKEND_ICONFIG_H__ +#ifndef __ONERT_BACKEND_ICONFIG_H__ +#define __ONERT_BACKEND_ICONFIG_H__ #include "util/ITimer.h" #include #include -namespace neurun +namespace onert { namespace backend { @@ -40,6 +40,6 @@ struct IConfig }; } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_ICONFIG_H__ +#endif // __ONERT_BACKEND_ICONFIG_H__ diff --git a/runtime/neurun/core/include/backend/IConstantInitializer.h b/runtime/onert/core/include/backend/IConstantInitializer.h similarity index 87% rename from runtime/neurun/core/include/backend/IConstantInitializer.h rename to runtime/onert/core/include/backend/IConstantInitializer.h index 492d17e3135..3872f333bb0 100644 --- a/runtime/neurun/core/include/backend/IConstantInitializer.h +++ b/runtime/onert/core/include/backend/IConstantInitializer.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_ICONSTANT_INITIALIZER_H__ -#define __NEURUN_BACKEND_ICONSTANT_INITIALIZER_H__ +#ifndef __ONERT_BACKEND_ICONSTANT_INITIALIZER_H__ +#define __ONERT_BACKEND_ICONSTANT_INITIALIZER_H__ #include #include @@ -32,15 +32,14 @@ namespace { template -static void Init(const neurun::ir::Operand &model_obj, neurun::backend::ITensor &obj, - const bool copy, - const neurun::ir::Layout frontend_layout = neurun::ir::Layout::UNKNOWN) +static void Init(const onert::ir::Operand &model_obj, onert::backend::ITensor &obj, const bool copy, + const onert::ir::Layout frontend_layout = onert::ir::Layout::UNKNOWN) { const auto shape = model_obj.shape(); assert(model_obj.data()); auto base = reinterpret_cast(model_obj.data()->base()); - obj.access([&](::neurun::backend::ITensor &tensor) { + obj.access([&](::onert::backend::ITensor &tensor) { switch (shape.rank()) { case 0: @@ -71,7 +70,7 @@ static void Init(const neurun::ir::Operand &model_obj, neurun::backend::ITensor for (auto i = 0; i < shape.dim(0); ++i) { - ::neurun::ir::Coordinates coords{i, 0}; + ::onert::ir::Coordinates coords{i, 0}; memcpy(tensor.buffer() + tensor.calcOffset(coords), base + i * copy_len, copy_len * sizeof(T)); } @@ -86,7 +85,7 @@ static void Init(const neurun::ir::Operand &model_obj, neurun::backend::ITensor { for (auto j = 0; j < shape.dim(1); ++j) { - ::neurun::ir::Coordinates coords{i, j, 0}; + ::onert::ir::Coordinates coords{i, j, 0}; memcpy(tensor.buffer() + tensor.calcOffset(coords), base + i * width * copy_len + j * copy_len, copy_len * sizeof(T)); } @@ -106,7 +105,7 @@ static void Init(const neurun::ir::Operand &model_obj, neurun::backend::ITensor { if (copy) { - ::neurun::ir::Coordinates coords{i, j, k, 0}; + ::onert::ir::Coordinates coords{i, j, k, 0}; memcpy(tensor.buffer() + tensor.calcOffset(coords), base + i * height * width * copy_len + j * width * copy_len + k * copy_len, copy_len * sizeof(T)); @@ -115,8 +114,8 @@ static void Init(const neurun::ir::Operand &model_obj, neurun::backend::ITensor { for (auto l = 0; l < shape.dim(3); ++l) { - const auto coords = ::neurun::ir::convertCoordinates( - {i, j, k, l}, frontend_layout, tensor.layout()); + const auto coords = ::onert::ir::convertCoordinates({i, j, k, l}, frontend_layout, + tensor.layout()); T *into = reinterpret_cast(tensor.buffer() + tensor.calcOffset(coords)); T value = *(base + i * height * width * copy_len + j * width * copy_len + k * copy_len + l); @@ -135,14 +134,14 @@ static void Init(const neurun::ir::Operand &model_obj, neurun::backend::ITensor } template -void copyInit(const neurun::ir::Operand &model_obj, neurun::backend::ITensor &obj) +void copyInit(const onert::ir::Operand &model_obj, onert::backend::ITensor &obj) { Init(model_obj, obj, true); } template -void permuteInit(const neurun::ir::Operand &model_obj, neurun::backend::ITensor &obj, - const neurun::ir::Layout frontend_layout) +void permuteInit(const onert::ir::Operand &model_obj, onert::backend::ITensor &obj, + const onert::ir::Layout frontend_layout) { const bool copy = frontend_layout == obj.layout(); Init(model_obj, obj, copy, frontend_layout); @@ -150,7 +149,7 @@ void permuteInit(const neurun::ir::Operand &model_obj, neurun::backend::ITensor } // namespace -namespace neurun +namespace onert { namespace backend { @@ -276,6 +275,6 @@ class IConstantInitializer : public ir::OperationVisitor }; } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_ICONSTANT_INITIALIZER_H__ +#endif // __ONERT_BACKEND_ICONSTANT_INITIALIZER_H__ diff --git a/runtime/neurun/core/include/backend/IKernelGenerator.h b/runtime/onert/core/include/backend/IKernelGenerator.h similarity index 84% rename from runtime/neurun/core/include/backend/IKernelGenerator.h rename to runtime/onert/core/include/backend/IKernelGenerator.h index 7c29ccbf608..afc34ec21d4 100644 --- a/runtime/neurun/core/include/backend/IKernelGenerator.h +++ b/runtime/onert/core/include/backend/IKernelGenerator.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_IKERNEL_GENERATOR_H__ -#define __NEURUN_BACKEND_IKERNEL_GENERATOR_H__ +#ifndef __ONERT_BACKEND_IKERNEL_GENERATOR_H__ +#define __ONERT_BACKEND_IKERNEL_GENERATOR_H__ #include #include @@ -24,10 +24,10 @@ #include "ITensorBuilder.h" #include "ir/OperationVisitor.h" #include "ir/OpSequence.h" -#include "memory" +#include #include "exec/FunctionSequence.h" -namespace neurun +namespace onert { namespace backend { @@ -52,6 +52,11 @@ class IKernelGenerator : public ir::OperationVisitor protected: using OperationVisitor::visit; + void visit(const ir::OpSequence &) override + { + throw std::runtime_error("KernelGenerator: NYI for operation 'OpSequence'"); + } + #define OP(InternalName) \ void visit(const ir::operation::InternalName &) override \ { \ @@ -66,6 +71,6 @@ class IKernelGenerator : public ir::OperationVisitor }; } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_IKERNEL_GENERATOR_H__ +#endif // __ONERT_BACKEND_IKERNEL_GENERATOR_H__ diff --git a/runtime/neurun/core/include/backend/IMemoryManager.h b/runtime/onert/core/include/backend/IMemoryManager.h similarity index 82% rename from runtime/neurun/core/include/backend/IMemoryManager.h rename to runtime/onert/core/include/backend/IMemoryManager.h index b06bab872e1..bad2fd51a45 100644 --- a/runtime/neurun/core/include/backend/IMemoryManager.h +++ b/runtime/onert/core/include/backend/IMemoryManager.h @@ -14,10 +14,10 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_IMEMORY_MANAGER_H__ -#define __NEURUN_BACKEND_IMEMORY_MANAGER_H__ +#ifndef __ONERT_BACKEND_IMEMORY_MANAGER_H__ +#define __ONERT_BACKEND_IMEMORY_MANAGER_H__ -namespace neurun +namespace onert { namespace backend { @@ -31,12 +31,12 @@ struct IMemoryManager }; } // namespace backend -} // namespace neurun +} // namespace onert #include #include -namespace neurun +namespace onert { namespace backend { @@ -44,6 +44,6 @@ namespace backend using MemoryManagerSet = std::unordered_set>; } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_IMEMORY_MANAGER_H__ +#endif // __ONERT_BACKEND_IMEMORY_MANAGER_H__ diff --git a/runtime/neurun/core/include/backend/IOptimizer.h b/runtime/onert/core/include/backend/IOptimizer.h similarity index 82% rename from runtime/neurun/core/include/backend/IOptimizer.h rename to runtime/onert/core/include/backend/IOptimizer.h index 8973561ffa6..4844d21b9f2 100644 --- a/runtime/neurun/core/include/backend/IOptimizer.h +++ b/runtime/onert/core/include/backend/IOptimizer.h @@ -14,18 +14,18 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_I_OPTIMIZER_H__ -#define __NEURUN_BACKEND_I_OPTIMIZER_H__ +#ifndef __ONERT_BACKEND_I_OPTIMIZER_H__ +#define __ONERT_BACKEND_I_OPTIMIZER_H__ -namespace neurun +namespace onert { namespace ir { class LoweredGraph; } -} // namespace neurun +} // namespace onert -namespace neurun +namespace onert { namespace backend { @@ -46,6 +46,6 @@ struct IOptimizer }; } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_I_OPTIMIZER_H__ +#endif // __ONERT_BACKEND_I_OPTIMIZER_H__ diff --git a/runtime/neurun/core/include/backend/IShapeFixer.h b/runtime/onert/core/include/backend/IShapeFixer.h similarity index 88% rename from runtime/neurun/core/include/backend/IShapeFixer.h rename to runtime/onert/core/include/backend/IShapeFixer.h index 281b276251f..35c8d33f023 100644 --- a/runtime/neurun/core/include/backend/IShapeFixer.h +++ b/runtime/onert/core/include/backend/IShapeFixer.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_ISHAPE_FIXER_H__ -#define __NEURUN_BACKEND_ISHAPE_FIXER_H__ +#ifndef __ONERT_BACKEND_ISHAPE_FIXER_H__ +#define __ONERT_BACKEND_ISHAPE_FIXER_H__ #include #include @@ -24,9 +24,9 @@ #include "ITensorBuilder.h" #include "ir/OperationVisitor.h" #include "ir/OpSequence.h" -#include "memory" +#include -namespace neurun +namespace onert { namespace backend { @@ -50,6 +50,6 @@ class IShapeFixer : public ir::OperationVisitor }; } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_ISHAPE_FIXER_H__ +#endif // __ONERT_BACKEND_ISHAPE_FIXER_H__ diff --git a/runtime/neurun/core/include/backend/ITensor.h b/runtime/onert/core/include/backend/ITensor.h similarity index 72% rename from runtime/neurun/core/include/backend/ITensor.h rename to runtime/onert/core/include/backend/ITensor.h index 53063fa5cd6..69f319a36d2 100644 --- a/runtime/neurun/core/include/backend/ITensor.h +++ b/runtime/onert/core/include/backend/ITensor.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_OPERAND_I_TENSOR_H__ -#define __NEURUN_BACKEND_OPERAND_I_TENSOR_H__ +#ifndef __ONERT_BACKEND_OPERAND_I_TENSOR_H__ +#define __ONERT_BACKEND_OPERAND_I_TENSOR_H__ #include #include @@ -24,7 +24,7 @@ #include "ir/Layout.h" #include "ir/Coordinates.h" -namespace neurun +namespace onert { namespace backend { @@ -43,9 +43,16 @@ class ITensor virtual ir::Layout layout() const = 0; virtual bool has_padding() const = 0; virtual void access(const std::function &fn) = 0; + + /** + * @brief Return true if the tensor needs dynamic allocation, meaning that during compile-time + * the outpus shape cannot be known and the output shape is calculated during + * kernel execution-time. + */ + virtual bool is_dynamic() const { return false; /* default */ } }; } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_OPERAND_I_TENSOR_H__ +#endif // __ONERT_BACKEND_OPERAND_I_TENSOR_H__ diff --git a/runtime/neurun/core/include/backend/ITensorBuilder.h b/runtime/onert/core/include/backend/ITensorBuilder.h similarity index 89% rename from runtime/neurun/core/include/backend/ITensorBuilder.h rename to runtime/onert/core/include/backend/ITensorBuilder.h index a45f0268ca7..f747b678fa9 100644 --- a/runtime/neurun/core/include/backend/ITensorBuilder.h +++ b/runtime/onert/core/include/backend/ITensorBuilder.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_ITENSOR_BUILDER_H__ -#define __NEURUN_BACKEND_ITENSOR_BUILDER_H__ +#ifndef __ONERT_BACKEND_ITENSOR_BUILDER_H__ +#define __ONERT_BACKEND_ITENSOR_BUILDER_H__ #include @@ -26,7 +26,7 @@ #include "ITensor.h" #include "ITensorManager.h" -namespace neurun +namespace onert { namespace backend { @@ -59,12 +59,12 @@ struct ITensorBuilder }; } // namespace backend -} // namespace neurun +} // namespace onert #include #include -namespace neurun +namespace onert { namespace backend { @@ -72,6 +72,6 @@ namespace backend using TensorBuilderSet = std::unordered_set>; } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_ITENSOR_BUILDER_H__ +#endif // __ONERT_BACKEND_ITENSOR_BUILDER_H__ diff --git a/runtime/neurun/core/include/backend/ITensorManager.h b/runtime/onert/core/include/backend/ITensorManager.h similarity index 84% rename from runtime/neurun/core/include/backend/ITensorManager.h rename to runtime/onert/core/include/backend/ITensorManager.h index 99b489bff08..1fcbe140f75 100644 --- a/runtime/neurun/core/include/backend/ITensorManager.h +++ b/runtime/onert/core/include/backend/ITensorManager.h @@ -14,10 +14,10 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_ITENSOR_MANAGER_H__ -#define __NEURUN_BACKEND_ITENSOR_MANAGER_H__ +#ifndef __ONERT_BACKEND_ITENSOR_MANAGER_H__ +#define __ONERT_BACKEND_ITENSOR_MANAGER_H__ -namespace neurun +namespace onert { namespace backend { @@ -33,12 +33,12 @@ struct ITensorManager }; } // namespace backend -} // namespace neurun +} // namespace onert #include #include -namespace neurun +namespace onert { namespace backend { @@ -46,6 +46,6 @@ namespace backend using TensorManagerSet = std::unordered_set>; } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_ITENSOR_MANAGER_H__ +#endif // __ONERT_BACKEND_ITENSOR_MANAGER_H__ diff --git a/runtime/neurun/core/include/backend/ITensorRegister.h b/runtime/onert/core/include/backend/ITensorRegister.h similarity index 89% rename from runtime/neurun/core/include/backend/ITensorRegister.h rename to runtime/onert/core/include/backend/ITensorRegister.h index ecfe10da814..bceaebf32c9 100644 --- a/runtime/neurun/core/include/backend/ITensorRegister.h +++ b/runtime/onert/core/include/backend/ITensorRegister.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_BACKEND_ITENSOR_REGISTER_H__ -#define __NEURUN_BACKEND_ITENSOR_REGISTER_H__ +#ifndef __ONERT_BACKEND_ITENSOR_REGISTER_H__ +#define __ONERT_BACKEND_ITENSOR_REGISTER_H__ #include "ir/LowerInfoMap.h" #include "ITensorBuilder.h" @@ -25,7 +25,7 @@ #include "ir/Operands.h" #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace backend { @@ -36,13 +36,13 @@ class ITensorRegister : public ir::OperationVisitor virtual ~ITensorRegister() = default; public: - void registerTensors(const ir::OpSequence &subg, const ir::LowerInfoMap *lower_info_map) + void registerTensors(const ir::OpSequence &op_seq, const ir::LowerInfoMap *lower_info_map) { - _current_op_seq_layout = subg.getLayout(); + _current_op_seq_layout = op_seq.getLayout(); _lower_info_map = lower_info_map; assert(_lower_info_map != nullptr); assert(tensor_builder().get() != nullptr); - subg.accept(*this); + op_seq.accept(*this); } protected: @@ -92,6 +92,6 @@ class ITensorRegister : public ir::OperationVisitor }; } // namespace backend -} // namespace neurun +} // namespace onert -#endif // __NEURUN_BACKEND_ITENSOR_REGISTER_H__ +#endif // __ONERT_BACKEND_ITENSOR_REGISTER_H__ diff --git a/runtime/neurun/core/include/compiler/BackendManager.h b/runtime/onert/core/include/compiler/BackendManager.h similarity index 92% rename from runtime/neurun/core/include/compiler/BackendManager.h rename to runtime/onert/core/include/compiler/BackendManager.h index 0a9f9c868d5..95ba2c223e4 100644 --- a/runtime/neurun/core/include/compiler/BackendManager.h +++ b/runtime/onert/core/include/compiler/BackendManager.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_COMPILER_BACKEND_MANAGER_H__ -#define __NEURUN_COMPILER_BACKEND_MANAGER_H__ +#ifndef __ONERT_COMPILER_BACKEND_MANAGER_H__ +#define __ONERT_COMPILER_BACKEND_MANAGER_H__ #include #include @@ -23,7 +23,7 @@ #include "ir/Operands.h" #include "backend/Backend.h" -namespace neurun +namespace onert { namespace compiler { @@ -76,6 +76,6 @@ class BackendManager }; } // namespace compiler -} // namespace neurun +} // namespace onert -#endif // __NEURUN_COMPILER_BACKEND_MANAGER_H__ +#endif // __ONERT_COMPILER_BACKEND_MANAGER_H__ diff --git a/runtime/neurun/core/include/compiler/BackendResolver.h b/runtime/onert/core/include/compiler/BackendResolver.h similarity index 88% rename from runtime/neurun/core/include/compiler/BackendResolver.h rename to runtime/onert/core/include/compiler/BackendResolver.h index 1353fc4e0f5..a316b4335c1 100644 --- a/runtime/neurun/core/include/compiler/BackendResolver.h +++ b/runtime/onert/core/include/compiler/BackendResolver.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_COMPILER_BACKEND_RESOLVER_H__ -#define __NEURUN_COMPILER_BACKEND_RESOLVER_H__ +#ifndef __ONERT_COMPILER_BACKEND_RESOLVER_H__ +#define __ONERT_COMPILER_BACKEND_RESOLVER_H__ #include #include @@ -23,7 +23,7 @@ #include "backend/Backend.h" #include "ir/OperationIndexMap.h" -namespace neurun +namespace onert { namespace compiler { @@ -55,6 +55,6 @@ class BackendResolver }; } // namespace compiler -} // namespace neurun +} // namespace onert -#endif // __NEURUN_COMPILER_BACKEND_RESOLVER_H__ +#endif // __ONERT_COMPILER_BACKEND_RESOLVER_H__ diff --git a/runtime/neurun/core/include/compiler/CodeMap.h b/runtime/onert/core/include/compiler/CodeMap.h similarity index 88% rename from runtime/neurun/core/include/compiler/CodeMap.h rename to runtime/onert/core/include/compiler/CodeMap.h index d91d3b197b7..e13d3334cd5 100644 --- a/runtime/neurun/core/include/compiler/CodeMap.h +++ b/runtime/onert/core/include/compiler/CodeMap.h @@ -14,12 +14,12 @@ * limitations under the License. */ -#ifndef __NEURUN_COMPILER_CODE_MAP_H__ -#define __NEURUN_COMPILER_CODE_MAP_H__ +#ifndef __ONERT_COMPILER_CODE_MAP_H__ +#define __ONERT_COMPILER_CODE_MAP_H__ #include -namespace neurun +namespace onert { namespace compiler { @@ -40,6 +40,6 @@ struct CodeAndInfo using CodeMap = std::unordered_map; } // namespace compiler -} // namespace neurun +} // namespace onert -#endif // __NEURUN_COMPILER_CODE_MAP_H__ +#endif // __ONERT_COMPILER_CODE_MAP_H__ diff --git a/runtime/neurun/core/include/compiler/Compiler.h b/runtime/onert/core/include/compiler/Compiler.h similarity index 95% rename from runtime/neurun/core/include/compiler/Compiler.h rename to runtime/onert/core/include/compiler/Compiler.h index c3c45b9784d..c25eb7b365c 100644 --- a/runtime/neurun/core/include/compiler/Compiler.h +++ b/runtime/onert/core/include/compiler/Compiler.h @@ -19,13 +19,13 @@ * @brief This file contains Compiler class to define and run compilation phase */ -#ifndef __NEURUN_COMPILER_COMPILE_H_ -#define __NEURUN_COMPILER_COMPILE_H_ +#ifndef __ONERT_COMPILER_COMPILE_H_ +#define __ONERT_COMPILER_COMPILE_H_ #include "ir/Graph.h" #include "exec/IExecutor.h" -namespace neurun +namespace onert { namespace compiler @@ -113,6 +113,6 @@ class Compiler } // namespace compiler -} // namespace neurun +} // namespace onert -#endif // __NEURUN_COMPILER_COMPILE_H_ +#endif // __ONERT_COMPILER_COMPILE_H_ diff --git a/runtime/neurun/core/include/compiler/ExecutionBuilder.h b/runtime/onert/core/include/compiler/ExecutionBuilder.h similarity index 85% rename from runtime/neurun/core/include/compiler/ExecutionBuilder.h rename to runtime/onert/core/include/compiler/ExecutionBuilder.h index 3b2f0836a1a..d54d9d04681 100644 --- a/runtime/neurun/core/include/compiler/ExecutionBuilder.h +++ b/runtime/onert/core/include/compiler/ExecutionBuilder.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_COMPILER_EXECUTION_BUILDER_H__ -#define __NEURUN_COMPILER_EXECUTION_BUILDER_H__ +#ifndef __ONERT_COMPILER_EXECUTION_BUILDER_H__ +#define __ONERT_COMPILER_EXECUTION_BUILDER_H__ #include @@ -24,7 +24,7 @@ #include "exec/FunctionSequence.h" #include "CodeMap.h" -namespace neurun +namespace onert { namespace compiler { @@ -44,6 +44,6 @@ class ExecutionBuilder }; } // namespace compiler -} // namespace neurun +} // namespace onert -#endif // __NEURUN_COMPILER_EXECUTION_BUILDER_H__ +#endif // __ONERT_COMPILER_EXECUTION_BUILDER_H__ diff --git a/runtime/neurun/core/include/exec/ExecTime.h b/runtime/onert/core/include/exec/ExecTime.h similarity index 96% rename from runtime/neurun/core/include/exec/ExecTime.h rename to runtime/onert/core/include/exec/ExecTime.h index 96bdda0f9c0..846d0930b65 100644 --- a/runtime/neurun/core/include/exec/ExecTime.h +++ b/runtime/onert/core/include/exec/ExecTime.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_EXEC_EXEC_TIME_H__ -#define __NEURUN_EXEC_EXEC_TIME_H__ +#ifndef __ONERT_EXEC_EXEC_TIME_H__ +#define __ONERT_EXEC_EXEC_TIME_H__ #include "backend/Backend.h" #include "backend/IConfig.h" @@ -26,7 +26,7 @@ #include #include -namespace neurun +namespace onert { namespace exec { @@ -107,6 +107,6 @@ class ExecTime }; } // namespace exec -} // namespace neurun +} // namespace onert -#endif // __NEURUN_EXEC_EXEC_TIME_H__ +#endif // __ONERT_EXEC_EXEC_TIME_H__ diff --git a/runtime/neurun/core/include/exec/Execution.h b/runtime/onert/core/include/exec/Execution.h similarity index 96% rename from runtime/neurun/core/include/exec/Execution.h rename to runtime/onert/core/include/exec/Execution.h index 7304f8aabe3..5ce5a8feec5 100644 --- a/runtime/neurun/core/include/exec/Execution.h +++ b/runtime/onert/core/include/exec/Execution.h @@ -18,8 +18,8 @@ * @file Execution.h * @brief This file defines execution */ -#ifndef __NEURUN_EXEC_EXECUTION_H__ -#define __NEURUN_EXEC_EXECUTION_H__ +#ifndef __ONERT_EXEC_EXECUTION_H__ +#define __ONERT_EXEC_EXECUTION_H__ #include "ir/Layout.h" #include "exec/IExecutor.h" @@ -27,7 +27,7 @@ #include -namespace neurun +namespace onert { namespace exec { @@ -139,6 +139,6 @@ class Execution }; } // namespace exec -} // namespace neurun +} // namespace onert -#endif // __NEURUN_EXEC_EXECUTION_H__ +#endif // __ONERT_EXEC_EXECUTION_H__ diff --git a/runtime/neurun/core/include/exec/ExecutionObservers.h b/runtime/onert/core/include/exec/ExecutionObservers.h similarity index 91% rename from runtime/neurun/core/include/exec/ExecutionObservers.h rename to runtime/onert/core/include/exec/ExecutionObservers.h index ea97b0b62d4..a993efee1e2 100644 --- a/runtime/neurun/core/include/exec/ExecutionObservers.h +++ b/runtime/onert/core/include/exec/ExecutionObservers.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_EXEC_OBSREVERS_H__ -#define __NEURUN_EXEC_OBSREVERS_H__ +#ifndef __ONERT_EXEC_OBSREVERS_H__ +#define __ONERT_EXEC_OBSREVERS_H__ #include "exec/IFunction.h" #include "ir/OpSequence.h" @@ -25,7 +25,7 @@ #include "misc/EventCollector.h" #include "misc/EventRecorder.h" -namespace neurun +namespace onert { namespace exec { @@ -69,7 +69,7 @@ class ChromeTracingObserver : public IExecutionObserver void handleEnd(IExecutor *) override; private: - static std::string subgraphTag(const ir::OpSequence *op_seq); + static std::string opSequenceTag(const ir::OpSequence *op_seq); private: std::ofstream _ofs; @@ -78,6 +78,6 @@ class ChromeTracingObserver : public IExecutionObserver }; } // namespace exec -} // namespace neurun +} // namespace onert -#endif // __NEURUN_EXEC_OBSREVERS_H__ +#endif // __ONERT_EXEC_OBSREVERS_H__ diff --git a/runtime/neurun/core/include/exec/FunctionSequence.h b/runtime/onert/core/include/exec/FunctionSequence.h similarity index 89% rename from runtime/neurun/core/include/exec/FunctionSequence.h rename to runtime/onert/core/include/exec/FunctionSequence.h index eef969e4882..e11e1004371 100644 --- a/runtime/neurun/core/include/exec/FunctionSequence.h +++ b/runtime/onert/core/include/exec/FunctionSequence.h @@ -14,17 +14,17 @@ * limitations under the License. */ -#ifndef __NEURUN_EXEC_FUNCTION_SEQUENCE_H__ -#define __NEURUN_EXEC_FUNCTION_SEQUENCE_H__ +#ifndef __ONERT_EXEC_FUNCTION_SEQUENCE_H__ +#define __ONERT_EXEC_FUNCTION_SEQUENCE_H__ #include #include #include #include "exec/IFunction.h" -#include "memory" +#include -namespace neurun +namespace onert { namespace exec { @@ -67,6 +67,6 @@ class FunctionSequence : public IFunction }; } // namespace exec -} // namespace neurun +} // namespace onert -#endif // __NEURUN_EXEC_FUNCTION_SEQUENCE_H__ +#endif // __ONERT_EXEC_FUNCTION_SEQUENCE_H__ diff --git a/runtime/neurun/core/include/exec/IExecutor.h b/runtime/onert/core/include/exec/IExecutor.h similarity index 91% rename from runtime/neurun/core/include/exec/IExecutor.h rename to runtime/onert/core/include/exec/IExecutor.h index de3291388cb..8ae492696a2 100644 --- a/runtime/neurun/core/include/exec/IExecutor.h +++ b/runtime/onert/core/include/exec/IExecutor.h @@ -18,15 +18,15 @@ * @file IExecutor.h * @brief This file defines interface of Executor */ -#ifndef __NEURUN_EXEC_I_EXECUTOR_H_ -#define __NEURUN_EXEC_I_EXECUTOR_H_ +#ifndef __ONERT_EXEC_I_EXECUTOR_H_ +#define __ONERT_EXEC_I_EXECUTOR_H_ #include "ir/Graph.h" #include "IFunction.h" #include "IODescription.h" #include "ir/OperationIndexMap.h" -namespace neurun +namespace onert { namespace exec { @@ -67,6 +67,6 @@ struct IExecutor }; } // namespace exec -} // namespace neurun +} // namespace onert -#endif // __NEURUN_EXEC_I_EXECUTOR_H_ +#endif // __ONERT_EXEC_I_EXECUTOR_H_ diff --git a/runtime/neurun/core/include/exec/IFunction.h b/runtime/onert/core/include/exec/IFunction.h similarity index 84% rename from runtime/neurun/core/include/exec/IFunction.h rename to runtime/onert/core/include/exec/IFunction.h index 5cc29ea7540..258f1e5b37d 100644 --- a/runtime/neurun/core/include/exec/IFunction.h +++ b/runtime/onert/core/include/exec/IFunction.h @@ -14,10 +14,10 @@ * limitations under the License. */ -#ifndef __NEURUN_EXEC_I_FUNCTION_H__ -#define __NEURUN_EXEC_I_FUNCTION_H__ +#ifndef __ONERT_EXEC_I_FUNCTION_H__ +#define __ONERT_EXEC_I_FUNCTION_H__ -namespace neurun +namespace onert { namespace exec { @@ -32,6 +32,6 @@ class IFunction }; } // namespace exec -} // namespace neurun +} // namespace onert -#endif // __NEURUN_EXEC_I_FUNCTION_H__ +#endif // __ONERT_EXEC_I_FUNCTION_H__ diff --git a/runtime/neurun/core/include/exec/IODescription.h b/runtime/onert/core/include/exec/IODescription.h similarity index 90% rename from runtime/neurun/core/include/exec/IODescription.h rename to runtime/onert/core/include/exec/IODescription.h index bdcc7817658..8bfddcde672 100644 --- a/runtime/neurun/core/include/exec/IODescription.h +++ b/runtime/onert/core/include/exec/IODescription.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_EXEC_IO_DESCRIPTION_H__ -#define __NEURUN_EXEC_IO_DESCRIPTION_H__ +#ifndef __ONERT_EXEC_IO_DESCRIPTION_H__ +#define __ONERT_EXEC_IO_DESCRIPTION_H__ #include #include "ir/OperandInfo.h" -namespace neurun +namespace onert { namespace exec { @@ -61,6 +61,6 @@ struct IODescription }; } // namespace exec -} // namespace neurun +} // namespace onert -#endif // __NEURUN_EXEC_IO_DESCRIPTION_H__ +#endif // __ONERT_EXEC_IO_DESCRIPTION_H__ diff --git a/runtime/neurun/core/include/exec/JSONExecTime.h b/runtime/onert/core/include/exec/JSONExecTime.h similarity index 94% rename from runtime/neurun/core/include/exec/JSONExecTime.h rename to runtime/onert/core/include/exec/JSONExecTime.h index 1d9a7827e88..a64cb3133e1 100644 --- a/runtime/neurun/core/include/exec/JSONExecTime.h +++ b/runtime/onert/core/include/exec/JSONExecTime.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_EXEC_JSON_EXEC_TIME_H__ -#define __NEURUN_EXEC_JSON_EXEC_TIME_H__ +#ifndef __ONERT_EXEC_JSON_EXEC_TIME_H__ +#define __ONERT_EXEC_JSON_EXEC_TIME_H__ #include #include @@ -24,7 +24,7 @@ #include "backend/Backend.h" #include "backend/IConfig.h" -namespace neurun +namespace onert { namespace exec { @@ -92,6 +92,6 @@ class JSON }; } // namespace exec -} // namespace neurun +} // namespace onert -#endif // __NEURUN_EXEC_JSON_EXEC_TIME_H__ +#endif // __ONERT_EXEC_JSON_EXEC_TIME_H__ diff --git a/runtime/neurun/core/include/exec/NopFunction.h b/runtime/onert/core/include/exec/NopFunction.h similarity index 87% rename from runtime/neurun/core/include/exec/NopFunction.h rename to runtime/onert/core/include/exec/NopFunction.h index 5cbd7e5ce6c..df9537cb525 100644 --- a/runtime/neurun/core/include/exec/NopFunction.h +++ b/runtime/onert/core/include/exec/NopFunction.h @@ -18,12 +18,12 @@ * @file NopFunction.h * @brief This file defines NopFunction */ -#ifndef __NEURUN_EXEC_NOP_FUNCTION_H_ -#define __NEURUN_EXEC_NOP_FUNCTION_H_ +#ifndef __ONERT_EXEC_NOP_FUNCTION_H_ +#define __ONERT_EXEC_NOP_FUNCTION_H_ #include "IFunction.h" -namespace neurun +namespace onert { namespace exec { @@ -49,6 +49,6 @@ class NopFunction : public IFunction }; } // namespace exec -} // namespace neurun +} // namespace onert -#endif // __NEURUN_EXEC_NOP_FUNCTION_H_ +#endif // __ONERT_EXEC_NOP_FUNCTION_H_ diff --git a/runtime/neurun/core/include/interp/InterpExecutor.h b/runtime/onert/core/include/interp/InterpExecutor.h similarity index 90% rename from runtime/neurun/core/include/interp/InterpExecutor.h rename to runtime/onert/core/include/interp/InterpExecutor.h index 832ca8cd980..2e3f3ca543a 100644 --- a/runtime/neurun/core/include/interp/InterpExecutor.h +++ b/runtime/onert/core/include/interp/InterpExecutor.h @@ -19,14 +19,14 @@ * @brief This file contains InterpExecutor class\n * to manage interpreter execution and environment */ -#ifndef __NEURUN_INTERP_INTERP_EXECUTOR_H__ -#define __NEURUN_INTERP_INTERP_EXECUTOR_H__ +#ifndef __ONERT_INTERP_INTERP_EXECUTOR_H__ +#define __ONERT_INTERP_INTERP_EXECUTOR_H__ #include "ir/OperandIndexMap.h" #include "ir/Graph.h" #include "exec/IExecutor.h" -namespace neurun +namespace onert { namespace interp { @@ -65,6 +65,6 @@ class InterpExecutor final : public exec::IExecutor }; } // namespace interp -} // namespace neurun +} // namespace onert -#endif // __NEURUN_INTERP_INTERP_EXECUTOR_H__ +#endif // __ONERT_INTERP_INTERP_EXECUTOR_H__ diff --git a/runtime/neurun/core/include/ir/BackendSet.h b/runtime/onert/core/include/ir/BackendSet.h similarity index 81% rename from runtime/neurun/core/include/ir/BackendSet.h rename to runtime/onert/core/include/ir/BackendSet.h index 4979286df54..dc635bdaf76 100644 --- a/runtime/neurun/core/include/ir/BackendSet.h +++ b/runtime/onert/core/include/ir/BackendSet.h @@ -14,20 +14,20 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_BACKEND_SET_H__ -#define __NEURUN_IR_BACKEND_SET_H__ +#ifndef __ONERT_IR_BACKEND_SET_H__ +#define __ONERT_IR_BACKEND_SET_H__ #include "util/Set.h" -namespace neurun +namespace onert { namespace backend { class Backend; } // namespace backend -} // namespace neurun +} // namespace onert -namespace neurun +namespace onert { namespace ir { @@ -35,6 +35,6 @@ namespace ir using BackendSet = util::Set; } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_BACKEND_SET_H__ +#endif // __ONERT_IR_BACKEND_SET_H__ diff --git a/runtime/neurun/core/include/ir/Coordinates.h b/runtime/onert/core/include/ir/Coordinates.h similarity index 94% rename from runtime/neurun/core/include/ir/Coordinates.h rename to runtime/onert/core/include/ir/Coordinates.h index 8ba99d4ccc5..6938fecef6f 100644 --- a/runtime/neurun/core/include/ir/Coordinates.h +++ b/runtime/onert/core/include/ir/Coordinates.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_COORDINATES_H__ -#define __NEURUN_IR_COORDINATES_H__ +#ifndef __ONERT_IR_COORDINATES_H__ +#define __ONERT_IR_COORDINATES_H__ #include #include @@ -23,7 +23,7 @@ #include "Layout.h" -namespace neurun +namespace onert { namespace ir { @@ -108,6 +108,6 @@ Coordinates convertCoordinates(const Coordinates &from_coordinates, Layout from_ Layout to_layout); } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_COORDINATES_H__ +#endif // __ONERT_IR_COORDINATES_H__ diff --git a/runtime/neurun/core/include/ir/Data.h b/runtime/onert/core/include/ir/Data.h similarity index 92% rename from runtime/neurun/core/include/ir/Data.h rename to runtime/onert/core/include/ir/Data.h index a0a48955332..c85eb484785 100644 --- a/runtime/neurun/core/include/ir/Data.h +++ b/runtime/onert/core/include/ir/Data.h @@ -14,12 +14,12 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_DATA_H__ -#define __NEURUN_IR_DATA_H__ +#ifndef __ONERT_IR_DATA_H__ +#define __ONERT_IR_DATA_H__ #include -namespace neurun +namespace onert { namespace ir { @@ -70,6 +70,6 @@ class ExternalData final : public Data }; } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_DATA_H__ +#endif // __ONERT_IR_DATA_H__ diff --git a/runtime/neurun/core/include/ir/DataType.h b/runtime/onert/core/include/ir/DataType.h similarity index 90% rename from runtime/neurun/core/include/ir/DataType.h rename to runtime/onert/core/include/ir/DataType.h index 6eca6eb27e4..f706d1375cd 100644 --- a/runtime/neurun/core/include/ir/DataType.h +++ b/runtime/onert/core/include/ir/DataType.h @@ -14,12 +14,12 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_DATATYPE_H__ -#define __NEURUN_IR_DATATYPE_H__ +#ifndef __ONERT_IR_DATATYPE_H__ +#define __ONERT_IR_DATATYPE_H__ #include -namespace neurun +namespace onert { namespace ir { @@ -57,6 +57,6 @@ inline size_t sizeOfDataType(DataType data_type) } } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_DATATYPE_H__ +#endif // __ONERT_IR_DATATYPE_H__ diff --git a/runtime/neurun/core/include/ir/Graph.h b/runtime/onert/core/include/ir/Graph.h similarity index 87% rename from runtime/neurun/core/include/ir/Graph.h rename to runtime/onert/core/include/ir/Graph.h index f02e47c5f71..b5d698cbdd1 100644 --- a/runtime/neurun/core/include/ir/Graph.h +++ b/runtime/onert/core/include/ir/Graph.h @@ -14,17 +14,18 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_GRAPH_H__ -#define __NEURUN_IR_GRAPH_H__ +#ifndef __ONERT_IR_GRAPH_H__ +#define __ONERT_IR_GRAPH_H__ #include +#include #include "ir/Operands.h" #include "ir/Operations.h" #include "ir/OpSequence.h" #include "ir/OpSequences.h" -namespace neurun +namespace onert { namespace backend { @@ -33,9 +34,9 @@ namespace custom class IKernelBuilder; } // namespace custom } // namespace backend -} // namespace neurun +} // namespace onert -namespace neurun +namespace onert { namespace ir { @@ -70,7 +71,7 @@ class Graph // Custom operations support public: void - bindKernelBuilder(const std::shared_ptr &kernel_builder) + bindKernelBuilder(const std::shared_ptr &kernel_builder) { _kernel_builder = kernel_builder; } @@ -100,9 +101,10 @@ class Graph Operands _operands; OperandIndexSequence _inputs; OperandIndexSequence _outputs; + std::unordered_map> _subgraphs; }; } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_GRAPH_H__ +#endif // __ONERT_IR_GRAPH_H__ diff --git a/runtime/neurun/core/include/ir/Index.h b/runtime/onert/core/include/ir/Index.h similarity index 60% rename from runtime/neurun/core/include/ir/Index.h rename to runtime/onert/core/include/ir/Index.h index 3c1c26d3a11..4f04546bc72 100644 --- a/runtime/neurun/core/include/ir/Index.h +++ b/runtime/onert/core/include/ir/Index.h @@ -14,29 +14,32 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERAND_INDEX_H__ -#define __NEURUN_IR_OPERAND_INDEX_H__ +#ifndef __ONERT_IR_OPERAND_INDEX_H__ +#define __ONERT_IR_OPERAND_INDEX_H__ #include "util/Index.h" -namespace neurun +namespace onert { namespace ir { struct OperationIndexTag; -using OperationIndex = ::neurun::util::Index; +using OperationIndex = ::onert::util::Index; struct OperandIndexTag; -using OperandIndex = ::neurun::util::Index; +using OperandIndex = ::onert::util::Index; struct IOIndexTag; -using IOIndex = ::neurun::util::Index; +using IOIndex = ::onert::util::Index; struct OpSequenceIndexTag; -using OpSequenceIndex = ::neurun::util::Index; +using OpSequenceIndex = ::onert::util::Index; + +struct SubgraphIndexTag; +using SubgraphIndex = ::onert::util::Index; } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERAND_INDEX_H__ +#endif // __ONERT_IR_OPERAND_INDEX_H__ diff --git a/runtime/neurun/core/include/ir/InternalType.h b/runtime/onert/core/include/ir/InternalType.h similarity index 84% rename from runtime/neurun/core/include/ir/InternalType.h rename to runtime/onert/core/include/ir/InternalType.h index d7b5ed5b01a..e42db72cfdd 100644 --- a/runtime/neurun/core/include/ir/InternalType.h +++ b/runtime/onert/core/include/ir/InternalType.h @@ -14,12 +14,12 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_INTERNAL_TYPE_H__ -#define __NEURUN_IR_INTERNAL_TYPE_H__ +#ifndef __ONERT_IR_INTERNAL_TYPE_H__ +#define __ONERT_IR_INTERNAL_TYPE_H__ #include -namespace neurun +namespace onert { namespace ir { @@ -41,6 +41,6 @@ struct Stride }; } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_INTERNAL_TYPE_H__ +#endif // __ONERT_IR_INTERNAL_TYPE_H__ diff --git a/runtime/neurun/core/include/ir/Layout.h b/runtime/onert/core/include/ir/Layout.h similarity index 79% rename from runtime/neurun/core/include/ir/Layout.h rename to runtime/onert/core/include/ir/Layout.h index c4edb70db90..08281017275 100644 --- a/runtime/neurun/core/include/ir/Layout.h +++ b/runtime/onert/core/include/ir/Layout.h @@ -14,13 +14,13 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_LAYOUT_H__ -#define __NEURUN_IR_LAYOUT_H__ +#ifndef __ONERT_IR_LAYOUT_H__ +#define __ONERT_IR_LAYOUT_H__ #include #include -namespace neurun +namespace onert { namespace ir { @@ -48,20 +48,20 @@ inline std::string to_string(Layout layout) } } // namespace ir -} // namespace neurun +} // namespace onert namespace std { -template <> struct hash +template <> struct hash { - size_t operator()(neurun::ir::Layout value) const noexcept + size_t operator()(onert::ir::Layout value) const noexcept { - using type = typename std::underlying_type::type; + using type = typename std::underlying_type::type; return hash()(static_cast(value)); } }; } // namespace std -#endif // __NEURUN_IR_LAYOUT_H__ +#endif // __ONERT_IR_LAYOUT_H__ diff --git a/runtime/neurun/core/include/ir/LowerInfoMap.h b/runtime/onert/core/include/ir/LowerInfoMap.h similarity index 86% rename from runtime/neurun/core/include/ir/LowerInfoMap.h rename to runtime/onert/core/include/ir/LowerInfoMap.h index 96eafcd55ad..b4241709205 100644 --- a/runtime/neurun/core/include/ir/LowerInfoMap.h +++ b/runtime/onert/core/include/ir/LowerInfoMap.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_LOWER_INFO_MAP_H__ -#define __NEURUN_IR_LOWER_INFO_MAP_H__ +#ifndef __ONERT_IR_LOWER_INFO_MAP_H__ +#define __ONERT_IR_LOWER_INFO_MAP_H__ #include #include @@ -25,7 +25,7 @@ #include "ir/OperandIndexMap.h" #include "ir/Index.h" -namespace neurun +namespace onert { namespace ir { @@ -37,6 +37,6 @@ struct LowerInfoMap }; } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_LOWER_INFO_MAP_H__ +#endif // __ONERT_IR_LOWER_INFO_MAP_H__ diff --git a/runtime/neurun/core/include/ir/LoweredGraph.h b/runtime/onert/core/include/ir/LoweredGraph.h similarity index 85% rename from runtime/neurun/core/include/ir/LoweredGraph.h rename to runtime/onert/core/include/ir/LoweredGraph.h index fa2a4ad65df..6699e237294 100644 --- a/runtime/neurun/core/include/ir/LoweredGraph.h +++ b/runtime/onert/core/include/ir/LoweredGraph.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_LOWERED_GRAPH_H__ -#define __NEURUN_IR_LOWERED_GRAPH_H__ +#ifndef __ONERT_IR_LOWERED_GRAPH_H__ +#define __ONERT_IR_LOWERED_GRAPH_H__ #include "ir/Graph.h" #include "ir/LowerInfoMap.h" @@ -23,7 +23,7 @@ #include "compiler/BackendResolver.h" #include "compiler/Compiler.h" -namespace neurun +namespace onert { namespace ir { @@ -36,10 +36,10 @@ class LoweredGraph Graph &graph() { return _graph; } const Graph &graph() const { return _graph; } const LowerInfoMap *getLowerInfo() const { return &_lower_info_map; } - const operation::LowerInfo *getLowerInfo(const OpSequenceIndex &subg_index) const; - void setLowerInfo(const OpSequenceIndex &subg_index, + const operation::LowerInfo *getLowerInfo(const OpSequenceIndex &op_seq_index) const; + void setLowerInfo(const OpSequenceIndex &op_seq_index, std::unique_ptr &&lower_info); - void removeLowerInfo(const OpSequenceIndex &subg_index); + void removeLowerInfo(const OpSequenceIndex &op_seq_index); const operand::LowerInfo *getLowerInfo(const OperandIndex &index) const; operand::LowerInfo *getLowerInfo(const OperandIndex &index); void setLowerInfo(const OperandIndex &index, std::unique_ptr &&lower_info); @@ -57,9 +57,9 @@ class LoweredGraph void manipulateLowerInfo(OperandIndexMap> &operands_lower_info); void dumpLowerInfo(); - bool mergeable(const OpSequenceIndex &subg_index, const OperationIndex &node_index, + bool mergeable(const OpSequenceIndex &op_seq_index, const OperationIndex &node_index, Layout layout); - OpSequenceIndex appendFreshSingleOpSubgraph(const OperationIndex &node_index, + OpSequenceIndex appendFreshSingleOpSequence(const OperationIndex &node_index, const Operation &node, Layout layout); private: @@ -73,6 +73,6 @@ class LoweredGraph }; } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_LOWERED_GRAPH_H__ +#endif // __ONERT_IR_LOWERED_GRAPH_H__ diff --git a/runtime/neurun/core/include/ir/OpCode.h b/runtime/onert/core/include/ir/OpCode.h similarity index 76% rename from runtime/neurun/core/include/ir/OpCode.h rename to runtime/onert/core/include/ir/OpCode.h index 2b466a21286..f22b36349ee 100644 --- a/runtime/neurun/core/include/ir/OpCode.h +++ b/runtime/onert/core/include/ir/OpCode.h @@ -14,13 +14,13 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OP_CODE_H__ -#define __NEURUN_IR_OP_CODE_H__ +#ifndef __ONERT_IR_OP_CODE_H__ +#define __ONERT_IR_OP_CODE_H__ #include #include -namespace neurun +namespace onert { namespace ir { @@ -37,20 +37,20 @@ enum class OpCode const char *toString(OpCode opcode); } // namespace ir -} // namespace neurun +} // namespace onert namespace std { -template <> struct hash +template <> struct hash { - size_t operator()(neurun::ir::OpCode value) const noexcept + size_t operator()(onert::ir::OpCode value) const noexcept { - using type = typename std::underlying_type::type; + using type = typename std::underlying_type::type; return hash()(static_cast(value)); } }; } // namespace std -#endif // __NEURUN_IR_OP_CODE_H__ +#endif // __ONERT_IR_OP_CODE_H__ diff --git a/runtime/neurun/core/include/ir/OpSequence.h b/runtime/onert/core/include/ir/OpSequence.h similarity index 94% rename from runtime/neurun/core/include/ir/OpSequence.h rename to runtime/onert/core/include/ir/OpSequence.h index 68632e589f5..1ca23138444 100644 --- a/runtime/neurun/core/include/ir/OpSequence.h +++ b/runtime/onert/core/include/ir/OpSequence.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OP_SEQUENCE_H__ -#define __NEURUN_IR_OP_SEQUENCE_H__ +#ifndef __ONERT_IR_OP_SEQUENCE_H__ +#define __ONERT_IR_OP_SEQUENCE_H__ #include #include @@ -25,7 +25,7 @@ #include "ir/Index.h" #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -101,6 +101,6 @@ class OpSequence }; } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OP_SEQUENCE_H__ +#endif // __ONERT_IR_OP_SEQUENCE_H__ diff --git a/runtime/neurun/core/include/ir/OpSequences.h b/runtime/onert/core/include/ir/OpSequences.h similarity index 87% rename from runtime/neurun/core/include/ir/OpSequences.h rename to runtime/onert/core/include/ir/OpSequences.h index 2231e82df5e..2af9579b796 100644 --- a/runtime/neurun/core/include/ir/OpSequences.h +++ b/runtime/onert/core/include/ir/OpSequences.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OP_SEQUENCES_H__ -#define __NEURUN_IR_OP_SEQUENCES_H__ +#ifndef __ONERT_IR_OP_SEQUENCES_H__ +#define __ONERT_IR_OP_SEQUENCES_H__ #include "ir/Index.h" #include "ir/OpSequence.h" #include "util/ObjectManager.h" -namespace neurun +namespace onert { namespace ir { @@ -45,10 +45,10 @@ class OpSequences : public util::ObjectManager /** * @brief Push an instance of OpSequence to objects * - * @param[in] subg An instance of OpSequence + * @param[in] op_seq An instance of OpSequence * @return OpSequenceIndex */ - OpSequenceIndex emplace(std::unique_ptr &&subg); + OpSequenceIndex emplace(std::unique_ptr &&op_seq); /** * @brief Check if an operation does exist in any OpSequences @@ -75,13 +75,13 @@ class OpSequences : public util::ObjectManager * * @param operation_index Operation index to be removed */ - void removeFromSubgraph(const OperationIndex &operation_index); + void removeFromOpSequence(const OperationIndex &operation_index); private: OpSequenceIndex findOperation(const OperationIndex &operation_index) const; }; } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OP_SEQUENCES_H__ +#endif // __ONERT_IR_OP_SEQUENCES_H__ diff --git a/runtime/neurun/core/include/ir/Operand.h b/runtime/onert/core/include/ir/Operand.h similarity index 94% rename from runtime/neurun/core/include/ir/Operand.h rename to runtime/onert/core/include/ir/Operand.h index 79e0a029eb6..3b6de9d1576 100644 --- a/runtime/neurun/core/include/ir/Operand.h +++ b/runtime/onert/core/include/ir/Operand.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERAND_H__ -#define __NEURUN_IR_OPERAND_H__ +#ifndef __ONERT_IR_OPERAND_H__ +#define __ONERT_IR_OPERAND_H__ #include #include @@ -27,7 +27,7 @@ #include "ir/OperandInfo.h" #include "ir/OperationIndexList.h" -namespace neurun +namespace onert { namespace ir { @@ -44,6 +44,7 @@ class Operand const Shape &shape(void) const { return _info.shape(); } const TypeInfo &typeInfo(void) const { return _info.typeInfo(); } const OperandInfo &info(void) const { return _info; } + OperandInfo &info(void) { return _info; } size_t operandSize(void) const; const OperationIndexList &getUses() const { return _uses; } @@ -108,6 +109,6 @@ class Operand }; } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERAND_H__ +#endif // __ONERT_IR_OPERAND_H__ diff --git a/runtime/neurun/core/include/ir/OperandConstraint.h b/runtime/onert/core/include/ir/OperandConstraint.h similarity index 89% rename from runtime/neurun/core/include/ir/OperandConstraint.h rename to runtime/onert/core/include/ir/OperandConstraint.h index de6f216342a..8da922bea6b 100644 --- a/runtime/neurun/core/include/ir/OperandConstraint.h +++ b/runtime/onert/core/include/ir/OperandConstraint.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_MODEL_OPERAND_CONSTRAINT_H__ -#define __NEURUN_MODEL_OPERAND_CONSTRAINT_H__ +#ifndef __ONERT_MODEL_OPERAND_CONSTRAINT_H__ +#define __ONERT_MODEL_OPERAND_CONSTRAINT_H__ #include #include #include -namespace neurun +namespace onert { namespace ir { @@ -53,6 +53,6 @@ class OperandConstraint }; } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_MODEL_OPERAND_CONSTRAINT_H__ +#endif // __ONERT_MODEL_OPERAND_CONSTRAINT_H__ diff --git a/runtime/neurun/core/include/ir/OperandIndexMap.h b/runtime/onert/core/include/ir/OperandIndexMap.h similarity index 82% rename from runtime/neurun/core/include/ir/OperandIndexMap.h rename to runtime/onert/core/include/ir/OperandIndexMap.h index c9234128e2f..468162ffb22 100644 --- a/runtime/neurun/core/include/ir/OperandIndexMap.h +++ b/runtime/onert/core/include/ir/OperandIndexMap.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERAND_INDEX_MAP_H__ -#define __NEURUN_IR_OPERAND_INDEX_MAP_H__ +#ifndef __ONERT_IR_OPERAND_INDEX_MAP_H__ +#define __ONERT_IR_OPERAND_INDEX_MAP_H__ #include #include "ir/Index.h" -namespace neurun +namespace onert { namespace ir { @@ -29,6 +29,6 @@ namespace ir template using OperandIndexMap = std::unordered_map; } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERAND_INDEX_MAP_H__ +#endif // __ONERT_IR_OPERAND_INDEX_MAP_H__ diff --git a/runtime/neurun/core/include/ir/OperandIndexSequence.h b/runtime/onert/core/include/ir/OperandIndexSequence.h similarity index 90% rename from runtime/neurun/core/include/ir/OperandIndexSequence.h rename to runtime/onert/core/include/ir/OperandIndexSequence.h index 6888e7ad752..1f5ab3d0a04 100644 --- a/runtime/neurun/core/include/ir/OperandIndexSequence.h +++ b/runtime/onert/core/include/ir/OperandIndexSequence.h @@ -14,15 +14,15 @@ * limitations under the License. */ -#ifndef __NEURUN_MODEL_OPERAND_INDEX_SEQUENCE_H__ -#define __NEURUN_MODEL_OPERAND_INDEX_SEQUENCE_H__ +#ifndef __ONERT_MODEL_OPERAND_INDEX_SEQUENCE_H__ +#define __ONERT_MODEL_OPERAND_INDEX_SEQUENCE_H__ #include #include #include "ir/Index.h" -namespace neurun +namespace onert { namespace ir { @@ -58,6 +58,6 @@ class OperandIndexSequence }; } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_MODEL_OPERAND_INDEX_SET_H__ +#endif // __ONERT_MODEL_OPERAND_INDEX_SET_H__ diff --git a/runtime/neurun/core/include/ir/OperandInfo.h b/runtime/onert/core/include/ir/OperandInfo.h similarity index 54% rename from runtime/neurun/core/include/ir/OperandInfo.h rename to runtime/onert/core/include/ir/OperandInfo.h index 82ad7ef0fbe..6d66f1e123b 100644 --- a/runtime/neurun/core/include/ir/OperandInfo.h +++ b/runtime/onert/core/include/ir/OperandInfo.h @@ -18,18 +18,36 @@ * @file OperandInfo.h * @brief This file contains OperandInfo class */ -#ifndef __NEURUN_IR_OPERAND_INFO_H__ -#define __NEURUN_IR_OPERAND_INFO_H__ +#ifndef __ONERT_IR_OPERAND_INFO_H__ +#define __ONERT_IR_OPERAND_INFO_H__ #include "ir/Shape.h" #include "ir/TypeInfo.h" #include "ir/Layout.h" -namespace neurun +namespace onert { namespace ir { +/** + * @brief enum class indicating when the memory for a tensor is allocated + */ +enum class MemAllocType +{ + /** + * @brief At compile time, shape for a tensor is known, thus requried memory capacity can be + * calculated + */ + STATIC, + + /** + * @brief At kernel execution time, shape for a tensor is known, thus requried memory capacity + * can be calculated + */ + DYNAMIC +}; + /** * @brief Class to save tensor's shape and type */ @@ -44,19 +62,31 @@ class OperandInfo * @brief Construct a new OperandInfo object * @param[in] shape Tensor shape * @param[in] typeInfo Tensor data type + * + * @todo Deprecated this constructor because setting member var implicitly can cause bug later. + * Please use the third constructor. (This constor needs for now not to break previous code) */ - OperandInfo(const Shape &shape, const TypeInfo &typeInfo) : _shape(shape), _typeInfo(typeInfo) + OperandInfo(const Shape &shape, const TypeInfo &typeInfo) + : _shape(shape), _typeInfo(typeInfo), _alloc_type(MemAllocType::STATIC) { // DO NOTHING } /** * @brief Construct a new OperandInfo object - * @param[in] origin info for copy + * @param[in] shape Tensor shape + * @param[in] typeInfo Tensor data type + * @param[in] alloc_type When the thesor needs memory allocation */ - OperandInfo(const OperandInfo &origin) : _shape(origin.shape()), _typeInfo(origin.typeInfo()) + OperandInfo(const Shape &shape, const TypeInfo &typeInfo, MemAllocType alloc_type) + : _shape(shape), _typeInfo(typeInfo), _alloc_type(alloc_type) { // DO NOTHING } + /** + * @brief Construct a new OperandInfo object + * @param[in] origin info for copy + */ + OperandInfo(const OperandInfo &origin) = default; public: /** @@ -64,6 +94,10 @@ class OperandInfo * @return Tensor shape */ const Shape &shape() const { return _shape; } + /** + * @brief set shape + */ + void shape(const ir::Shape &new_shape) { _shape = new_shape; } /** * @brief Return tensor data type info * @return Tensor data type @@ -79,12 +113,17 @@ class OperandInfo */ size_t total_size() const { return _shape.num_elements() * sizeOfDataType(_typeInfo.type()); } + MemAllocType memAllocType() const { return _alloc_type; } + void memAllocType(MemAllocType alloc_type) { _alloc_type = alloc_type; } + private: Shape _shape; TypeInfo _typeInfo; + + MemAllocType _alloc_type; }; } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERAND_INFO_H__ +#endif // __ONERT_IR_OPERAND_INFO_H__ diff --git a/runtime/neurun/core/include/ir/Operands.h b/runtime/onert/core/include/ir/Operands.h similarity index 88% rename from runtime/neurun/core/include/ir/Operands.h rename to runtime/onert/core/include/ir/Operands.h index 26a4724226e..be7b7061f72 100644 --- a/runtime/neurun/core/include/ir/Operands.h +++ b/runtime/onert/core/include/ir/Operands.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERANDS_H__ -#define __NEURUN_IR_OPERANDS_H__ +#ifndef __ONERT_IR_OPERANDS_H__ +#define __ONERT_IR_OPERANDS_H__ #include #include @@ -24,7 +24,7 @@ #include "ir/Index.h" #include "util/ObjectManager.h" -namespace neurun +namespace onert { namespace ir { @@ -41,6 +41,6 @@ class Operands : public util::ObjectManager }; } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_MODEL_OPERAND_SET_H__ +#endif // __ONERT_MODEL_OPERAND_SET_H__ diff --git a/runtime/neurun/core/include/ir/Operation.h b/runtime/onert/core/include/ir/Operation.h similarity index 93% rename from runtime/neurun/core/include/ir/Operation.h rename to runtime/onert/core/include/ir/Operation.h index 36bb1588745..fb347292387 100644 --- a/runtime/neurun/core/include/ir/Operation.h +++ b/runtime/onert/core/include/ir/Operation.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_H__ -#define __NEURUN_IR_OPERATION_H__ +#ifndef __ONERT_IR_OPERATION_H__ +#define __ONERT_IR_OPERATION_H__ #include @@ -24,7 +24,7 @@ #include "ir/OperandIndexSequence.h" #include "ir/OperandConstraint.h" -namespace neurun +namespace onert { namespace ir { @@ -66,6 +66,6 @@ class Operation }; } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_H__ +#endif // __ONERT_IR_OPERATION_H__ diff --git a/runtime/neurun/core/include/ir/OperationIndexList.h b/runtime/onert/core/include/ir/OperationIndexList.h similarity index 88% rename from runtime/neurun/core/include/ir/OperationIndexList.h rename to runtime/onert/core/include/ir/OperationIndexList.h index bf3ea3d6b23..7863ff29a05 100644 --- a/runtime/neurun/core/include/ir/OperationIndexList.h +++ b/runtime/onert/core/include/ir/OperationIndexList.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_MODEL_OPERATION_INDEX_LIST_H__ -#define __NEURUN_MODEL_OPERATION_INDEX_LIST_H__ +#ifndef __ONERT_MODEL_OPERATION_INDEX_LIST_H__ +#define __ONERT_MODEL_OPERATION_INDEX_LIST_H__ #include #include @@ -24,7 +24,7 @@ #include "ir/Index.h" -namespace neurun +namespace onert { namespace ir { @@ -54,6 +54,6 @@ class OperationIndexList }; } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_MODEL_OPERATION_INDEX_LIST_H__ +#endif // __ONERT_MODEL_OPERATION_INDEX_LIST_H__ diff --git a/runtime/neurun/core/include/ir/OperationIndexMap.h b/runtime/onert/core/include/ir/OperationIndexMap.h similarity index 82% rename from runtime/neurun/core/include/ir/OperationIndexMap.h rename to runtime/onert/core/include/ir/OperationIndexMap.h index 50b1db52791..50c21c0ab5d 100644 --- a/runtime/neurun/core/include/ir/OperationIndexMap.h +++ b/runtime/onert/core/include/ir/OperationIndexMap.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_INDEX_MAP_H__ -#define __NEURUN_IR_OPERATION_INDEX_MAP_H__ +#ifndef __ONERT_IR_OPERATION_INDEX_MAP_H__ +#define __ONERT_IR_OPERATION_INDEX_MAP_H__ #include #include "ir/Index.h" -namespace neurun +namespace onert { namespace ir { @@ -29,6 +29,6 @@ namespace ir template using OperationIndexMap = std::unordered_map; } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_INDEX_MAP_H__ +#endif // __ONERT_IR_OPERATION_INDEX_MAP_H__ diff --git a/runtime/neurun/core/include/ir/OperationVisitor.h b/runtime/onert/core/include/ir/OperationVisitor.h similarity index 88% rename from runtime/neurun/core/include/ir/OperationVisitor.h rename to runtime/onert/core/include/ir/OperationVisitor.h index 0eb6de2d366..b7e66b9355b 100644 --- a/runtime/neurun/core/include/ir/OperationVisitor.h +++ b/runtime/onert/core/include/ir/OperationVisitor.h @@ -14,13 +14,13 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_VISITOR_H__ -#define __NEURUN_IR_OPERATION_VISITOR_H__ +#ifndef __ONERT_IR_OPERATION_VISITOR_H__ +#define __ONERT_IR_OPERATION_VISITOR_H__ #include "ir/Operations.Include.h" #include "ir/OpSequence.h" -namespace neurun +namespace onert { namespace ir { @@ -47,6 +47,6 @@ struct OperationVisitor }; } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_VISITOR_H__ +#endif // __ONERT_IR_OPERATION_VISITOR_H__ diff --git a/runtime/neurun/core/include/ir/Operations.Include.h b/runtime/onert/core/include/ir/Operations.Include.h similarity index 98% rename from runtime/neurun/core/include/ir/Operations.Include.h rename to runtime/onert/core/include/ir/Operations.Include.h index e14e18cc17c..1961bb159db 100644 --- a/runtime/neurun/core/include/ir/Operations.Include.h +++ b/runtime/onert/core/include/ir/Operations.Include.h @@ -81,3 +81,4 @@ #include "ir/operation/Max.h" #include "ir/operation/Custom.h" #include "ir/operation/OneHot.h" +#include "ir/operation/Sin.h" diff --git a/runtime/neurun/core/include/ir/Operations.h b/runtime/onert/core/include/ir/Operations.h similarity index 87% rename from runtime/neurun/core/include/ir/Operations.h rename to runtime/onert/core/include/ir/Operations.h index e047d59f7a9..0b5fbf529ab 100644 --- a/runtime/neurun/core/include/ir/Operations.h +++ b/runtime/onert/core/include/ir/Operations.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATIONS_H__ -#define __NEURUN_IR_OPERATIONS_H__ +#ifndef __ONERT_IR_OPERATIONS_H__ +#define __ONERT_IR_OPERATIONS_H__ #include "ir/Index.h" #include "ir/Operation.h" #include "util/ObjectManager.h" -namespace neurun +namespace onert { namespace ir { @@ -38,6 +38,6 @@ class Operations : public util::ObjectManager }; } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_MODEL_OPERATION_MANAGER_H__ +#endif // __ONERT_MODEL_OPERATION_MANAGER_H__ diff --git a/runtime/neurun/core/include/ir/Operations.lst b/runtime/onert/core/include/ir/Operations.lst similarity index 99% rename from runtime/neurun/core/include/ir/Operations.lst rename to runtime/onert/core/include/ir/Operations.lst index 8c02857d96c..c9d2f6e0752 100644 --- a/runtime/neurun/core/include/ir/Operations.lst +++ b/runtime/onert/core/include/ir/Operations.lst @@ -84,3 +84,4 @@ OP(Permute) OP(Min) OP(Max) OP(OneHot) +OP(Sin) diff --git a/runtime/neurun/core/include/ir/Padding.h b/runtime/onert/core/include/ir/Padding.h similarity index 94% rename from runtime/neurun/core/include/ir/Padding.h rename to runtime/onert/core/include/ir/Padding.h index b2242a6e844..b9053914d08 100644 --- a/runtime/neurun/core/include/ir/Padding.h +++ b/runtime/onert/core/include/ir/Padding.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_PADDIGN_H__ -#define __NEURUN_IR_PADDIGN_H__ +#ifndef __ONERT_IR_PADDIGN_H__ +#define __ONERT_IR_PADDIGN_H__ #include "Shape.h" #include "InternalType.h" @@ -23,7 +23,7 @@ #include #include -namespace neurun +namespace onert { namespace ir { @@ -68,6 +68,6 @@ const ExplicitPadding calculatePadding(const Padding &padding, const FeatureShap uint32_t kw, uint32_t kh); } // namespace ir -} // namespace neurun +} // namespace onert #endif diff --git a/runtime/neurun/core/include/ir/Shape.h b/runtime/onert/core/include/ir/Shape.h similarity index 94% rename from runtime/neurun/core/include/ir/Shape.h rename to runtime/onert/core/include/ir/Shape.h index fc93089bdeb..ebf46c555b3 100644 --- a/runtime/neurun/core/include/ir/Shape.h +++ b/runtime/onert/core/include/ir/Shape.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_SHAPE_H__ -#define __NEURUN_IR_SHAPE_H__ +#ifndef __ONERT_IR_SHAPE_H__ +#define __ONERT_IR_SHAPE_H__ #include "ir/Layout.h" #include "misc/feature/Shape.h" @@ -23,7 +23,7 @@ #include #include -namespace neurun +namespace onert { namespace ir { @@ -81,6 +81,6 @@ inline bool operator!=(const Shape &lhs, const Shape &rhs) { return lhs.dims() ! Shape permuteShape(const Shape &shape, Layout frontend_layout, Layout backend_layout); } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_SHAPE_H__ +#endif // __ONERT_IR_SHAPE_H__ diff --git a/runtime/neurun/core/include/ir/TypeInfo.h b/runtime/onert/core/include/ir/TypeInfo.h similarity index 90% rename from runtime/neurun/core/include/ir/TypeInfo.h rename to runtime/onert/core/include/ir/TypeInfo.h index 5b35046bbb3..07d82b6a7d5 100644 --- a/runtime/neurun/core/include/ir/TypeInfo.h +++ b/runtime/onert/core/include/ir/TypeInfo.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_TYPEINFO_H__ -#define __NEURUN_IR_TYPEINFO_H__ +#ifndef __ONERT_IR_TYPEINFO_H__ +#define __ONERT_IR_TYPEINFO_H__ #include #include "ir/DataType.h" -namespace neurun +namespace onert { namespace ir { @@ -54,6 +54,6 @@ bool operator==(const TypeInfo &lhs, const TypeInfo &rhs); bool operator!=(const TypeInfo &lhs, const TypeInfo &rhs); } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_TYPEINFO_H__ +#endif // __ONERT_IR_TYPEINFO_H__ diff --git a/runtime/neurun/core/include/ir/operand/LowerInfo.h b/runtime/onert/core/include/ir/operand/LowerInfo.h similarity index 88% rename from runtime/neurun/core/include/ir/operand/LowerInfo.h rename to runtime/onert/core/include/ir/operand/LowerInfo.h index bd63b6fd49a..b7f032b0214 100644 --- a/runtime/neurun/core/include/ir/operand/LowerInfo.h +++ b/runtime/onert/core/include/ir/operand/LowerInfo.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERAND_LOWER_INFO_H__ -#define __NEURUN_IR_OPERAND_LOWER_INFO_H__ +#ifndef __ONERT_IR_OPERAND_LOWER_INFO_H__ +#define __ONERT_IR_OPERAND_LOWER_INFO_H__ #include #include @@ -23,15 +23,15 @@ #include "ir/operand/PermuteFactor.h" #include "util/Set.h" -namespace neurun +namespace onert { namespace backend { class Backend; } // namespace backend -} // namespace neurun +} // namespace onert -namespace neurun +namespace onert { namespace ir { @@ -64,6 +64,6 @@ class LowerInfo } // namespace operand } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERAND_LOWER_INFO_H__ +#endif // __ONERT_IR_OPERAND_LOWER_INFO_H__ diff --git a/runtime/neurun/core/include/ir/operand/PermuteFactor.h b/runtime/onert/core/include/ir/operand/PermuteFactor.h similarity index 81% rename from runtime/neurun/core/include/ir/operand/PermuteFactor.h rename to runtime/onert/core/include/ir/operand/PermuteFactor.h index 60d926b2d2f..d0bfed337dc 100644 --- a/runtime/neurun/core/include/ir/operand/PermuteFactor.h +++ b/runtime/onert/core/include/ir/operand/PermuteFactor.h @@ -16,26 +16,26 @@ /** * @file PermuteFactor.h - * @brief This file contains neurun::ir::operand::PermuteFactor class + * @brief This file contains onert::ir::operand::PermuteFactor class * @ingroup COM_AI_RUNTIME */ -#ifndef __NEURUN_IR_OPERAND_PERMUTE_FACTOR_H__ -#define __NEURUN_IR_OPERAND_PERMUTE_FACTOR_H__ +#ifndef __ONERT_IR_OPERAND_PERMUTE_FACTOR_H__ +#define __ONERT_IR_OPERAND_PERMUTE_FACTOR_H__ #include #include "ir/Layout.h" -namespace neurun +namespace onert { namespace backend { class Backend; } // namespace backend -} // namespace neurun +} // namespace onert -namespace neurun +namespace onert { namespace ir { @@ -51,7 +51,7 @@ class PermuteFactor /** * @brief Construct PermuteFactor object. * @param backend The backend factor - * @param backend The layout factor + * @param layout The layout factor */ PermuteFactor(const backend::Backend *backend, Layout layout) : _backend{backend}, _layout{layout} { @@ -107,7 +107,7 @@ class PermuteFactor } // namespace operand } // namespace ir -} // namespace neurun +} // namespace onert namespace std { @@ -115,16 +115,16 @@ namespace std /** * @brief Structure that provides hash value of PermuteFactor */ -template <> struct hash +template <> struct hash { - size_t operator()(const neurun::ir::operand::PermuteFactor &factor) const noexcept + size_t operator()(const onert::ir::operand::PermuteFactor &factor) const noexcept { - hash b_hash{}; - hash l_hash{}; + hash b_hash{}; + hash l_hash{}; return b_hash(factor.backend()) ^ (l_hash(factor.layout()) << 1); } }; } // namespace std -#endif // __NEURUN_IR_OPERAND_PERMUTE_FACTOR_H__ +#endif // __ONERT_IR_OPERAND_PERMUTE_FACTOR_H__ diff --git a/runtime/neurun/core/include/ir/operation/Abs.h b/runtime/onert/core/include/ir/operation/Abs.h similarity index 86% rename from runtime/neurun/core/include/ir/operation/Abs.h rename to runtime/onert/core/include/ir/operation/Abs.h index 97293823b03..9126c0027ae 100644 --- a/runtime/neurun/core/include/ir/operation/Abs.h +++ b/runtime/onert/core/include/ir/operation/Abs.h @@ -14,12 +14,12 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_ABS_H__ -#define __NEURUN_IR_OPERATION_ABS_H__ +#ifndef __ONERT_IR_OPERATION_ABS_H__ +#define __ONERT_IR_OPERATION_ABS_H__ #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -44,6 +44,6 @@ class Abs : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_ABS_H__ +#endif // __ONERT_IR_OPERATION_ABS_H__ diff --git a/runtime/neurun/core/include/ir/operation/Add.h b/runtime/onert/core/include/ir/operation/Add.h similarity index 88% rename from runtime/neurun/core/include/ir/operation/Add.h rename to runtime/onert/core/include/ir/operation/Add.h index fc4d6a7e73b..5f5f4e0feaa 100644 --- a/runtime/neurun/core/include/ir/operation/Add.h +++ b/runtime/onert/core/include/ir/operation/Add.h @@ -14,13 +14,13 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_ADD_H__ -#define __NEURUN_IR_OPERATION_ADD_H__ +#ifndef __ONERT_IR_OPERATION_ADD_H__ +#define __ONERT_IR_OPERATION_ADD_H__ #include "ir/Operation.h" #include "ir/InternalType.h" -namespace neurun +namespace onert { namespace ir { @@ -57,6 +57,6 @@ class Add : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_ADD_H__ +#endif // __ONERT_IR_OPERATION_ADD_H__ diff --git a/runtime/neurun/core/include/ir/operation/ArgMax.h b/runtime/onert/core/include/ir/operation/ArgMax.h similarity index 87% rename from runtime/neurun/core/include/ir/operation/ArgMax.h rename to runtime/onert/core/include/ir/operation/ArgMax.h index 23f52710f1c..b006ea4647d 100644 --- a/runtime/neurun/core/include/ir/operation/ArgMax.h +++ b/runtime/onert/core/include/ir/operation/ArgMax.h @@ -14,12 +14,12 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_ARG_MAX_H__ -#define __NEURUN_IR_OPERATION_ARG_MAX_H__ +#ifndef __ONERT_IR_OPERATION_ARG_MAX_H__ +#define __ONERT_IR_OPERATION_ARG_MAX_H__ #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -57,6 +57,6 @@ class ArgMax : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_ARG_MAX_H__ +#endif // __ONERT_IR_OPERATION_ARG_MAX_H__ diff --git a/runtime/neurun/core/include/ir/operation/AvgPool2D.h b/runtime/onert/core/include/ir/operation/AvgPool2D.h similarity index 88% rename from runtime/neurun/core/include/ir/operation/AvgPool2D.h rename to runtime/onert/core/include/ir/operation/AvgPool2D.h index d53ebe139be..d5b300a3571 100644 --- a/runtime/neurun/core/include/ir/operation/AvgPool2D.h +++ b/runtime/onert/core/include/ir/operation/AvgPool2D.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_AVGPOOL2D_H__ -#define __NEURUN_IR_OPERATION_AVGPOOL2D_H__ +#ifndef __ONERT_IR_OPERATION_AVGPOOL2D_H__ +#define __ONERT_IR_OPERATION_AVGPOOL2D_H__ #include @@ -23,7 +23,7 @@ #include "ir/InternalType.h" #include "ir/Padding.h" -namespace neurun +namespace onert { namespace ir { @@ -65,6 +65,6 @@ class AvgPool2D : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_AVGPOOL2D_H__ +#endif // __ONERT_IR_OPERATION_AVGPOOL2D_H__ diff --git a/runtime/neurun/core/include/ir/operation/BatchToSpaceND.h b/runtime/onert/core/include/ir/operation/BatchToSpaceND.h similarity index 84% rename from runtime/neurun/core/include/ir/operation/BatchToSpaceND.h rename to runtime/onert/core/include/ir/operation/BatchToSpaceND.h index b90d2871daa..bb6be57d7a2 100644 --- a/runtime/neurun/core/include/ir/operation/BatchToSpaceND.h +++ b/runtime/onert/core/include/ir/operation/BatchToSpaceND.h @@ -14,12 +14,12 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_BATCH_TO_SPACE_ND_H__ -#define __NEURUN_IR_OPERATION_BATCH_TO_SPACE_ND_H__ +#ifndef __ONERT_IR_OPERATION_BATCH_TO_SPACE_ND_H__ +#define __ONERT_IR_OPERATION_BATCH_TO_SPACE_ND_H__ #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -45,6 +45,6 @@ class BatchToSpaceND : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_BATCH_TO_SPACE_ND_H__ +#endif // __ONERT_IR_OPERATION_BATCH_TO_SPACE_ND_H__ diff --git a/runtime/neurun/core/include/ir/operation/Cast.h b/runtime/onert/core/include/ir/operation/Cast.h similarity index 86% rename from runtime/neurun/core/include/ir/operation/Cast.h rename to runtime/onert/core/include/ir/operation/Cast.h index a71087dd0d4..6fb8c105be5 100644 --- a/runtime/neurun/core/include/ir/operation/Cast.h +++ b/runtime/onert/core/include/ir/operation/Cast.h @@ -14,12 +14,12 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_CAST_H__ -#define __NEURUN_IR_OPERATION_CAST_H__ +#ifndef __ONERT_IR_OPERATION_CAST_H__ +#define __ONERT_IR_OPERATION_CAST_H__ #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -44,6 +44,6 @@ class Cast : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_CAST_H__ +#endif // __ONERT_IR_OPERATION_CAST_H__ diff --git a/runtime/neurun/core/include/ir/operation/Comparison.h b/runtime/onert/core/include/ir/operation/Comparison.h similarity index 88% rename from runtime/neurun/core/include/ir/operation/Comparison.h rename to runtime/onert/core/include/ir/operation/Comparison.h index 77f9f642f44..8b53f163b96 100644 --- a/runtime/neurun/core/include/ir/operation/Comparison.h +++ b/runtime/onert/core/include/ir/operation/Comparison.h @@ -14,12 +14,12 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_COMPARISON_H__ -#define __NEURUN_IR_OPERATION_COMPARISON_H__ +#ifndef __ONERT_IR_OPERATION_COMPARISON_H__ +#define __ONERT_IR_OPERATION_COMPARISON_H__ #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -67,6 +67,6 @@ class Comparison : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_COMPARISON_H__ +#endif // __ONERT_IR_OPERATION_COMPARISON_H__ diff --git a/runtime/neurun/core/include/ir/operation/Concat.h b/runtime/onert/core/include/ir/operation/Concat.h similarity index 87% rename from runtime/neurun/core/include/ir/operation/Concat.h rename to runtime/onert/core/include/ir/operation/Concat.h index 8628ed39819..42b6fbb5174 100644 --- a/runtime/neurun/core/include/ir/operation/Concat.h +++ b/runtime/onert/core/include/ir/operation/Concat.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_CONCAT_H__ -#define __NEURUN_IR_OPERATION_CONCAT_H__ +#ifndef __ONERT_IR_OPERATION_CONCAT_H__ +#define __ONERT_IR_OPERATION_CONCAT_H__ #include #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -54,6 +54,6 @@ class Concat : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_CONCAT_H__ +#endif // __ONERT_IR_OPERATION_CONCAT_H__ diff --git a/runtime/neurun/core/include/ir/operation/Conv2D.h b/runtime/onert/core/include/ir/operation/Conv2D.h similarity index 89% rename from runtime/neurun/core/include/ir/operation/Conv2D.h rename to runtime/onert/core/include/ir/operation/Conv2D.h index 11a2cfb1e82..e23bf3eb37c 100644 --- a/runtime/neurun/core/include/ir/operation/Conv2D.h +++ b/runtime/onert/core/include/ir/operation/Conv2D.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_CONV2D_H__ -#define __NEURUN_IR_OPERATION_CONV2D_H__ +#ifndef __ONERT_IR_OPERATION_CONV2D_H__ +#define __ONERT_IR_OPERATION_CONV2D_H__ #include @@ -23,7 +23,7 @@ #include "ir/InternalType.h" #include "ir/Padding.h" -namespace neurun +namespace onert { namespace ir { @@ -64,6 +64,6 @@ class Conv2D : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_CONV2D_H__ +#endif // __ONERT_IR_OPERATION_CONV2D_H__ diff --git a/runtime/neurun/core/include/ir/operation/Custom.h b/runtime/onert/core/include/ir/operation/Custom.h similarity index 90% rename from runtime/neurun/core/include/ir/operation/Custom.h rename to runtime/onert/core/include/ir/operation/Custom.h index eee713c0fbd..c2a4b354a7e 100644 --- a/runtime/neurun/core/include/ir/operation/Custom.h +++ b/runtime/onert/core/include/ir/operation/Custom.h @@ -13,14 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_CUSTOM_H__ -#define __NEURUN_IR_OPERATION_CUSTOM_H__ +#ifndef __ONERT_IR_OPERATION_CUSTOM_H__ +#define __ONERT_IR_OPERATION_CUSTOM_H__ #include "ir/Operation.h" #include -namespace neurun +namespace onert { namespace ir { @@ -71,5 +71,5 @@ class Custom : public Operation } // namespace operation } // namespace ir -} // namespace neurun -#endif // __NEURUN_IR_OPERATION_CUSTOM_H__ +} // namespace onert +#endif // __ONERT_IR_OPERATION_CUSTOM_H__ diff --git a/runtime/neurun/core/include/ir/operation/DepthToSpace.h b/runtime/onert/core/include/ir/operation/DepthToSpace.h similarity index 86% rename from runtime/neurun/core/include/ir/operation/DepthToSpace.h rename to runtime/onert/core/include/ir/operation/DepthToSpace.h index 6e7aaf249f2..a5315051dad 100644 --- a/runtime/neurun/core/include/ir/operation/DepthToSpace.h +++ b/runtime/onert/core/include/ir/operation/DepthToSpace.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_DEPTH_TO_SPACE_H__ -#define __NEURUN_IR_OPERATION_DEPTH_TO_SPACE_H__ +#ifndef __ONERT_IR_OPERATION_DEPTH_TO_SPACE_H__ +#define __ONERT_IR_OPERATION_DEPTH_TO_SPACE_H__ #include #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -58,6 +58,6 @@ class DepthToSpace : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_DEPTH_TO_SPACE_H__ +#endif // __ONERT_IR_OPERATION_DEPTH_TO_SPACE_H__ diff --git a/runtime/neurun/core/include/ir/operation/DepthwiseConv2D.h b/runtime/onert/core/include/ir/operation/DepthwiseConv2D.h similarity index 88% rename from runtime/neurun/core/include/ir/operation/DepthwiseConv2D.h rename to runtime/onert/core/include/ir/operation/DepthwiseConv2D.h index e5dd7bfcba8..b10bf708c0d 100644 --- a/runtime/neurun/core/include/ir/operation/DepthwiseConv2D.h +++ b/runtime/onert/core/include/ir/operation/DepthwiseConv2D.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_DEPTHWISECONV2D_H__ -#define __NEURUN_IR_OPERATION_DEPTHWISECONV2D_H__ +#ifndef __ONERT_IR_OPERATION_DEPTHWISECONV2D_H__ +#define __ONERT_IR_OPERATION_DEPTHWISECONV2D_H__ #include @@ -23,7 +23,7 @@ #include "ir/InternalType.h" #include "ir/Padding.h" -namespace neurun +namespace onert { namespace ir { @@ -65,6 +65,6 @@ class DepthwiseConv2D : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_DEPTHWISECONV2D_H__ +#endif // __ONERT_IR_OPERATION_DEPTHWISECONV2D_H__ diff --git a/runtime/neurun/core/include/ir/operation/Dequantize.h b/runtime/onert/core/include/ir/operation/Dequantize.h similarity index 85% rename from runtime/neurun/core/include/ir/operation/Dequantize.h rename to runtime/onert/core/include/ir/operation/Dequantize.h index dfca278cdfa..97a08b33ccf 100644 --- a/runtime/neurun/core/include/ir/operation/Dequantize.h +++ b/runtime/onert/core/include/ir/operation/Dequantize.h @@ -14,12 +14,12 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_DEQUANTIZE_H__ -#define __NEURUN_IR_OPERATION_DEQUANTIZE_H__ +#ifndef __ONERT_IR_OPERATION_DEQUANTIZE_H__ +#define __ONERT_IR_OPERATION_DEQUANTIZE_H__ #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -44,6 +44,6 @@ class Dequantize : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_DEQUANTIZE_H__ +#endif // __ONERT_IR_OPERATION_DEQUANTIZE_H__ diff --git a/runtime/neurun/core/include/ir/operation/Div.h b/runtime/onert/core/include/ir/operation/Div.h similarity index 88% rename from runtime/neurun/core/include/ir/operation/Div.h rename to runtime/onert/core/include/ir/operation/Div.h index d3e74447276..a7ec1c465cc 100644 --- a/runtime/neurun/core/include/ir/operation/Div.h +++ b/runtime/onert/core/include/ir/operation/Div.h @@ -14,13 +14,13 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_DIV_H__ -#define __NEURUN_IR_OPERATION_DIV_H__ +#ifndef __ONERT_IR_OPERATION_DIV_H__ +#define __ONERT_IR_OPERATION_DIV_H__ #include "ir/Operation.h" #include "ir/InternalType.h" -namespace neurun +namespace onert { namespace ir { @@ -57,6 +57,6 @@ class Div : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_DIV_H__ +#endif // __ONERT_IR_OPERATION_DIV_H__ diff --git a/runtime/neurun/core/include/ir/operation/EmbeddingLookup.h b/runtime/onert/core/include/ir/operation/EmbeddingLookup.h similarity index 84% rename from runtime/neurun/core/include/ir/operation/EmbeddingLookup.h rename to runtime/onert/core/include/ir/operation/EmbeddingLookup.h index 968b7b35a0a..54064faf0d0 100644 --- a/runtime/neurun/core/include/ir/operation/EmbeddingLookup.h +++ b/runtime/onert/core/include/ir/operation/EmbeddingLookup.h @@ -14,12 +14,12 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_EMBEDDING_LOOKUP_H__ -#define __NEURUN_IR_OPERATION_EMBEDDING_LOOKUP_H__ +#ifndef __ONERT_IR_OPERATION_EMBEDDING_LOOKUP_H__ +#define __ONERT_IR_OPERATION_EMBEDDING_LOOKUP_H__ #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -45,6 +45,6 @@ class EmbeddingLookup : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_EMBEDDING_LOOKUP_H__ +#endif // __ONERT_IR_OPERATION_EMBEDDING_LOOKUP_H__ diff --git a/runtime/neurun/core/include/ir/operation/Exp.h b/runtime/onert/core/include/ir/operation/Exp.h similarity index 86% rename from runtime/neurun/core/include/ir/operation/Exp.h rename to runtime/onert/core/include/ir/operation/Exp.h index 8e04f3f7f9d..2e68ff07aca 100644 --- a/runtime/neurun/core/include/ir/operation/Exp.h +++ b/runtime/onert/core/include/ir/operation/Exp.h @@ -14,12 +14,12 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_EXP_H__ -#define __NEURUN_IR_OPERATION_EXP_H__ +#ifndef __ONERT_IR_OPERATION_EXP_H__ +#define __ONERT_IR_OPERATION_EXP_H__ #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -44,6 +44,6 @@ class Exp : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_EXP_H__ +#endif // __ONERT_IR_OPERATION_EXP_H__ diff --git a/runtime/neurun/core/include/ir/operation/Floor.h b/runtime/onert/core/include/ir/operation/Floor.h similarity index 86% rename from runtime/neurun/core/include/ir/operation/Floor.h rename to runtime/onert/core/include/ir/operation/Floor.h index ca4cf98810b..b34699c2299 100644 --- a/runtime/neurun/core/include/ir/operation/Floor.h +++ b/runtime/onert/core/include/ir/operation/Floor.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_FLOOR_H__ -#define __NEURUN_IR_OPERATION_FLOOR_H__ +#ifndef __ONERT_IR_OPERATION_FLOOR_H__ +#define __ONERT_IR_OPERATION_FLOOR_H__ #include #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -46,6 +46,6 @@ class Floor : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_FLOOR_H__ +#endif // __ONERT_IR_OPERATION_FLOOR_H__ diff --git a/runtime/neurun/core/include/ir/operation/FullyConnected.h b/runtime/onert/core/include/ir/operation/FullyConnected.h similarity index 87% rename from runtime/neurun/core/include/ir/operation/FullyConnected.h rename to runtime/onert/core/include/ir/operation/FullyConnected.h index 1ffa1318d92..b6484ae4db9 100644 --- a/runtime/neurun/core/include/ir/operation/FullyConnected.h +++ b/runtime/onert/core/include/ir/operation/FullyConnected.h @@ -14,15 +14,15 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_FULLYCONNECTED_H__ -#define __NEURUN_IR_OPERATION_FULLYCONNECTED_H__ +#ifndef __ONERT_IR_OPERATION_FULLYCONNECTED_H__ +#define __ONERT_IR_OPERATION_FULLYCONNECTED_H__ #include #include "ir/Operation.h" #include "ir/InternalType.h" -namespace neurun +namespace onert { namespace ir { @@ -61,6 +61,6 @@ class FullyConnected : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_FULLYCONNECTED_H__ +#endif // __ONERT_IR_OPERATION_FULLYCONNECTED_H__ diff --git a/runtime/neurun/core/include/ir/operation/Gather.h b/runtime/onert/core/include/ir/operation/Gather.h similarity index 88% rename from runtime/neurun/core/include/ir/operation/Gather.h rename to runtime/onert/core/include/ir/operation/Gather.h index 13540d413f6..daa198933c7 100644 --- a/runtime/neurun/core/include/ir/operation/Gather.h +++ b/runtime/onert/core/include/ir/operation/Gather.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_GATHER_H__ -#define __NEURUN_IR_OPERATION_GATHER_H__ +#ifndef __ONERT_IR_OPERATION_GATHER_H__ +#define __ONERT_IR_OPERATION_GATHER_H__ #include #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -60,6 +60,6 @@ class Gather : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_GATHER_H__ +#endif // __ONERT_IR_OPERATION_GATHER_H__ diff --git a/runtime/neurun/core/include/ir/operation/HashtableLookup.h b/runtime/onert/core/include/ir/operation/HashtableLookup.h similarity index 85% rename from runtime/neurun/core/include/ir/operation/HashtableLookup.h rename to runtime/onert/core/include/ir/operation/HashtableLookup.h index fb6c9760731..4b6cf936238 100644 --- a/runtime/neurun/core/include/ir/operation/HashtableLookup.h +++ b/runtime/onert/core/include/ir/operation/HashtableLookup.h @@ -14,12 +14,12 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_HASHTABLE_LOOKUP_H__ -#define __NEURUN_IR_OPERATION_HASHTABLE_LOOKUP_H__ +#ifndef __ONERT_IR_OPERATION_HASHTABLE_LOOKUP_H__ +#define __ONERT_IR_OPERATION_HASHTABLE_LOOKUP_H__ #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -52,6 +52,6 @@ class HashtableLookup : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_HASHTABLE_LOOKUP_H__ +#endif // __ONERT_IR_OPERATION_HASHTABLE_LOOKUP_H__ diff --git a/runtime/neurun/core/include/ir/operation/InstanceNorm.h b/runtime/onert/core/include/ir/operation/InstanceNorm.h similarity index 87% rename from runtime/neurun/core/include/ir/operation/InstanceNorm.h rename to runtime/onert/core/include/ir/operation/InstanceNorm.h index cbd03ad1f9a..6a3bb518996 100644 --- a/runtime/neurun/core/include/ir/operation/InstanceNorm.h +++ b/runtime/onert/core/include/ir/operation/InstanceNorm.h @@ -14,13 +14,13 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_INSTANCE_NORM_H__ -#define __NEURUN_IR_OPERATION_INSTANCE_NORM_H__ +#ifndef __ONERT_IR_OPERATION_INSTANCE_NORM_H__ +#define __ONERT_IR_OPERATION_INSTANCE_NORM_H__ #include "ir/Operation.h" #include "ir/InternalType.h" -namespace neurun +namespace onert { namespace ir { @@ -60,6 +60,6 @@ class InstanceNorm : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_INSTANCE_NORM_H__ +#endif // __ONERT_IR_OPERATION_INSTANCE_NORM_H__ diff --git a/runtime/neurun/core/include/ir/operation/L2Normalization.h b/runtime/onert/core/include/ir/operation/L2Normalization.h similarity index 86% rename from runtime/neurun/core/include/ir/operation/L2Normalization.h rename to runtime/onert/core/include/ir/operation/L2Normalization.h index e2c1f4eeefb..f55301bd62f 100644 --- a/runtime/neurun/core/include/ir/operation/L2Normalization.h +++ b/runtime/onert/core/include/ir/operation/L2Normalization.h @@ -14,12 +14,12 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_L2_NORMALIZATION_H__ -#define __NEURUN_IR_OPERATION_L2_NORMALIZATION_H__ +#ifndef __ONERT_IR_OPERATION_L2_NORMALIZATION_H__ +#define __ONERT_IR_OPERATION_L2_NORMALIZATION_H__ #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -57,6 +57,6 @@ class L2Normalization : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_L2_NORMALIZATION_H__ +#endif // __ONERT_IR_OPERATION_L2_NORMALIZATION_H__ diff --git a/runtime/neurun/core/include/ir/operation/L2Pool2D.h b/runtime/onert/core/include/ir/operation/L2Pool2D.h similarity index 88% rename from runtime/neurun/core/include/ir/operation/L2Pool2D.h rename to runtime/onert/core/include/ir/operation/L2Pool2D.h index f86c4ac9a06..d369fd5fc41 100644 --- a/runtime/neurun/core/include/ir/operation/L2Pool2D.h +++ b/runtime/onert/core/include/ir/operation/L2Pool2D.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_L2_POOL_2D_H__ -#define __NEURUN_IR_OPERATION_L2_POOL_2D_H__ +#ifndef __ONERT_IR_OPERATION_L2_POOL_2D_H__ +#define __ONERT_IR_OPERATION_L2_POOL_2D_H__ #include @@ -23,7 +23,7 @@ #include "ir/InternalType.h" #include "ir/Padding.h" -namespace neurun +namespace onert { namespace ir { @@ -64,6 +64,6 @@ class L2Pool2D : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_L2_POOL_2D_H__ +#endif // __ONERT_IR_OPERATION_L2_POOL_2D_H__ diff --git a/runtime/neurun/core/include/ir/operation/LSTM.h b/runtime/onert/core/include/ir/operation/LSTM.h similarity index 92% rename from runtime/neurun/core/include/ir/operation/LSTM.h rename to runtime/onert/core/include/ir/operation/LSTM.h index 2ea09b1b70a..1e6c00bf355 100644 --- a/runtime/neurun/core/include/ir/operation/LSTM.h +++ b/runtime/onert/core/include/ir/operation/LSTM.h @@ -13,13 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_LSTM_H__ -#define __NEURUN_IR_OPERATION_LSTM_H__ +#ifndef __ONERT_IR_OPERATION_LSTM_H__ +#define __ONERT_IR_OPERATION_LSTM_H__ #include "ir/InternalType.h" #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -84,6 +84,6 @@ class LSTM : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_LSTM_H__ +#endif // __ONERT_IR_OPERATION_LSTM_H__ diff --git a/runtime/neurun/core/include/ir/operation/LocalResponseNormalization.h b/runtime/onert/core/include/ir/operation/LocalResponseNormalization.h similarity index 85% rename from runtime/neurun/core/include/ir/operation/LocalResponseNormalization.h rename to runtime/onert/core/include/ir/operation/LocalResponseNormalization.h index 3fbf2e4ae7e..2946cfbad45 100644 --- a/runtime/neurun/core/include/ir/operation/LocalResponseNormalization.h +++ b/runtime/onert/core/include/ir/operation/LocalResponseNormalization.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_LOCAL_RESPONSE_NORMALIZATION_H__ -#define __NEURUN_IR_OPERATION_LOCAL_RESPONSE_NORMALIZATION_H__ +#ifndef __ONERT_IR_OPERATION_LOCAL_RESPONSE_NORMALIZATION_H__ +#define __ONERT_IR_OPERATION_LOCAL_RESPONSE_NORMALIZATION_H__ #include #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -61,6 +61,6 @@ class LocalResponseNormalization : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_LOCAL_RESPONSE_NORMALIZATION_H__ +#endif // __ONERT_IR_OPERATION_LOCAL_RESPONSE_NORMALIZATION_H__ diff --git a/runtime/neurun/core/include/ir/operation/LogicalAnd.h b/runtime/onert/core/include/ir/operation/LogicalAnd.h similarity index 85% rename from runtime/neurun/core/include/ir/operation/LogicalAnd.h rename to runtime/onert/core/include/ir/operation/LogicalAnd.h index f7b03d62dc6..dc853b6a973 100644 --- a/runtime/neurun/core/include/ir/operation/LogicalAnd.h +++ b/runtime/onert/core/include/ir/operation/LogicalAnd.h @@ -14,12 +14,12 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_LOGICAL_AND_H__ -#define __NEURUN_IR_OPERATION_LOGICAL_AND_H__ +#ifndef __ONERT_IR_OPERATION_LOGICAL_AND_H__ +#define __ONERT_IR_OPERATION_LOGICAL_AND_H__ #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -45,6 +45,6 @@ class LogicalAnd : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_LOGICAL_AND_H__ +#endif // __ONERT_IR_OPERATION_LOGICAL_AND_H__ diff --git a/runtime/neurun/core/include/ir/operation/LogicalNot.h b/runtime/onert/core/include/ir/operation/LogicalNot.h similarity index 85% rename from runtime/neurun/core/include/ir/operation/LogicalNot.h rename to runtime/onert/core/include/ir/operation/LogicalNot.h index e689d57b2ca..9519f6d4704 100644 --- a/runtime/neurun/core/include/ir/operation/LogicalNot.h +++ b/runtime/onert/core/include/ir/operation/LogicalNot.h @@ -14,12 +14,12 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_LOGICAL_NOT_H__ -#define __NEURUN_IR_OPERATION_LOGICAL_NOT_H__ +#ifndef __ONERT_IR_OPERATION_LOGICAL_NOT_H__ +#define __ONERT_IR_OPERATION_LOGICAL_NOT_H__ #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -44,6 +44,6 @@ class LogicalNot : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_LOGICAL_NOT_H__ +#endif // __ONERT_IR_OPERATION_LOGICAL_NOT_H__ diff --git a/runtime/neurun/core/include/ir/operation/LogicalOr.h b/runtime/onert/core/include/ir/operation/LogicalOr.h similarity index 85% rename from runtime/neurun/core/include/ir/operation/LogicalOr.h rename to runtime/onert/core/include/ir/operation/LogicalOr.h index fda6b20d706..c4b658cd975 100644 --- a/runtime/neurun/core/include/ir/operation/LogicalOr.h +++ b/runtime/onert/core/include/ir/operation/LogicalOr.h @@ -14,12 +14,12 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_LOGICAL_OR_H__ -#define __NEURUN_IR_OPERATION_LOGICAL_OR_H__ +#ifndef __ONERT_IR_OPERATION_LOGICAL_OR_H__ +#define __ONERT_IR_OPERATION_LOGICAL_OR_H__ #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -45,6 +45,6 @@ class LogicalOr : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_LOGICAL_OR_H__ +#endif // __ONERT_IR_OPERATION_LOGICAL_OR_H__ diff --git a/runtime/neurun/core/include/ir/operation/Logistic.h b/runtime/onert/core/include/ir/operation/Logistic.h similarity index 86% rename from runtime/neurun/core/include/ir/operation/Logistic.h rename to runtime/onert/core/include/ir/operation/Logistic.h index b23e7ef3ff7..5421e1c840d 100644 --- a/runtime/neurun/core/include/ir/operation/Logistic.h +++ b/runtime/onert/core/include/ir/operation/Logistic.h @@ -14,12 +14,12 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_LOGISTIC_H__ -#define __NEURUN_IR_OPERATION_LOGISTIC_H__ +#ifndef __ONERT_IR_OPERATION_LOGISTIC_H__ +#define __ONERT_IR_OPERATION_LOGISTIC_H__ #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -44,6 +44,6 @@ class Logistic : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_LOGISTIC_H__ +#endif // __ONERT_IR_OPERATION_LOGISTIC_H__ diff --git a/runtime/neurun/core/include/ir/operation/LowerInfo.h b/runtime/onert/core/include/ir/operation/LowerInfo.h similarity index 83% rename from runtime/neurun/core/include/ir/operation/LowerInfo.h rename to runtime/onert/core/include/ir/operation/LowerInfo.h index 856976a0cff..7ef53b8c7b2 100644 --- a/runtime/neurun/core/include/ir/operation/LowerInfo.h +++ b/runtime/onert/core/include/ir/operation/LowerInfo.h @@ -14,22 +14,22 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_LOWER_INFO_H__ -#define __NEURUN_IR_OPERATION_LOWER_INFO_H__ +#ifndef __ONERT_IR_OPERATION_LOWER_INFO_H__ +#define __ONERT_IR_OPERATION_LOWER_INFO_H__ #include #include -namespace neurun +namespace onert { namespace backend { class Backend; } // namespace backend -} // namespace neurun +} // namespace onert -namespace neurun +namespace onert { namespace ir { @@ -49,6 +49,6 @@ class LowerInfo } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_LOWER_INFO_H__ +#endif // __ONERT_IR_OPERATION_LOWER_INFO_H__ diff --git a/runtime/neurun/core/include/ir/operation/Max.h b/runtime/onert/core/include/ir/operation/Max.h similarity index 87% rename from runtime/neurun/core/include/ir/operation/Max.h rename to runtime/onert/core/include/ir/operation/Max.h index 1675f9f72a9..df72d3ae983 100644 --- a/runtime/neurun/core/include/ir/operation/Max.h +++ b/runtime/onert/core/include/ir/operation/Max.h @@ -14,12 +14,12 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_MAX_H__ -#define __NEURUN_IR_OPERATION_MAX_H__ +#ifndef __ONERT_IR_OPERATION_MAX_H__ +#define __ONERT_IR_OPERATION_MAX_H__ #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -45,6 +45,6 @@ class Max : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_MAX_H__ +#endif // __ONERT_IR_OPERATION_MAX_H__ diff --git a/runtime/neurun/core/include/ir/operation/MaxPool2D.h b/runtime/onert/core/include/ir/operation/MaxPool2D.h similarity index 88% rename from runtime/neurun/core/include/ir/operation/MaxPool2D.h rename to runtime/onert/core/include/ir/operation/MaxPool2D.h index 486aac269a3..300f7cb3c85 100644 --- a/runtime/neurun/core/include/ir/operation/MaxPool2D.h +++ b/runtime/onert/core/include/ir/operation/MaxPool2D.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_MAXPOOL2D_H__ -#define __NEURUN_IR_OPERATION_MAXPOOL2D_H__ +#ifndef __ONERT_IR_OPERATION_MAXPOOL2D_H__ +#define __ONERT_IR_OPERATION_MAXPOOL2D_H__ #include @@ -23,7 +23,7 @@ #include "ir/InternalType.h" #include "ir/Padding.h" -namespace neurun +namespace onert { namespace ir { @@ -64,6 +64,6 @@ class MaxPool2D : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_MAXPOOL2D_H__ +#endif // __ONERT_IR_OPERATION_MAXPOOL2D_H__ diff --git a/runtime/neurun/core/include/ir/operation/Mean.h b/runtime/onert/core/include/ir/operation/Mean.h similarity index 88% rename from runtime/neurun/core/include/ir/operation/Mean.h rename to runtime/onert/core/include/ir/operation/Mean.h index cce8de37752..5fe3946d690 100644 --- a/runtime/neurun/core/include/ir/operation/Mean.h +++ b/runtime/onert/core/include/ir/operation/Mean.h @@ -14,12 +14,12 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_MEAN_H__ -#define __NEURUN_IR_OPERATION_MEAN_H__ +#ifndef __ONERT_IR_OPERATION_MEAN_H__ +#define __ONERT_IR_OPERATION_MEAN_H__ #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -57,6 +57,6 @@ class Mean : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_MEAN_H__ +#endif // __ONERT_IR_OPERATION_MEAN_H__ diff --git a/runtime/neurun/core/include/ir/operation/Min.h b/runtime/onert/core/include/ir/operation/Min.h similarity index 87% rename from runtime/neurun/core/include/ir/operation/Min.h rename to runtime/onert/core/include/ir/operation/Min.h index fac901f213d..117301c0060 100644 --- a/runtime/neurun/core/include/ir/operation/Min.h +++ b/runtime/onert/core/include/ir/operation/Min.h @@ -14,12 +14,12 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_MIN_H__ -#define __NEURUN_IR_OPERATION_MIN_H__ +#ifndef __ONERT_IR_OPERATION_MIN_H__ +#define __ONERT_IR_OPERATION_MIN_H__ #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -45,6 +45,6 @@ class Min : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_MIN_H__ +#endif // __ONERT_IR_OPERATION_MIN_H__ diff --git a/runtime/neurun/core/include/ir/operation/Mul.h b/runtime/onert/core/include/ir/operation/Mul.h similarity index 88% rename from runtime/neurun/core/include/ir/operation/Mul.h rename to runtime/onert/core/include/ir/operation/Mul.h index f6cfe2afb59..0f01b0ecf5c 100644 --- a/runtime/neurun/core/include/ir/operation/Mul.h +++ b/runtime/onert/core/include/ir/operation/Mul.h @@ -14,13 +14,13 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_MUL_H__ -#define __NEURUN_IR_OPERATION_MUL_H__ +#ifndef __ONERT_IR_OPERATION_MUL_H__ +#define __ONERT_IR_OPERATION_MUL_H__ #include "ir/Operation.h" #include "ir/InternalType.h" -namespace neurun +namespace onert { namespace ir { @@ -57,6 +57,6 @@ class Mul : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_MUL_H__ +#endif // __ONERT_IR_OPERATION_MUL_H__ diff --git a/runtime/neurun/core/include/ir/operation/Neg.h b/runtime/onert/core/include/ir/operation/Neg.h similarity index 86% rename from runtime/neurun/core/include/ir/operation/Neg.h rename to runtime/onert/core/include/ir/operation/Neg.h index ec364f8ad7d..f8123c4855e 100644 --- a/runtime/neurun/core/include/ir/operation/Neg.h +++ b/runtime/onert/core/include/ir/operation/Neg.h @@ -14,12 +14,12 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_NEG_H__ -#define __NEURUN_IR_OPERATION_NEG_H__ +#ifndef __ONERT_IR_OPERATION_NEG_H__ +#define __ONERT_IR_OPERATION_NEG_H__ #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -44,6 +44,6 @@ class Neg : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_NEG_H__ +#endif // __ONERT_IR_OPERATION_NEG_H__ diff --git a/runtime/neurun/core/include/ir/operation/OneHot.h b/runtime/onert/core/include/ir/operation/OneHot.h similarity index 89% rename from runtime/neurun/core/include/ir/operation/OneHot.h rename to runtime/onert/core/include/ir/operation/OneHot.h index 8e0c3fb93b4..2cb0d23e134 100644 --- a/runtime/neurun/core/include/ir/operation/OneHot.h +++ b/runtime/onert/core/include/ir/operation/OneHot.h @@ -14,12 +14,12 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_ONEHOT_H__ -#define __NEURUN_IR_OPERATION_ONEHOT_H__ +#ifndef __ONERT_IR_OPERATION_ONEHOT_H__ +#define __ONERT_IR_OPERATION_ONEHOT_H__ #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -58,6 +58,6 @@ class OneHot : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_ONEHOT_H__ +#endif // __ONERT_IR_OPERATION_ONEHOT_H__ diff --git a/runtime/neurun/core/include/ir/operation/PReLU.h b/runtime/onert/core/include/ir/operation/PReLU.h similarity index 86% rename from runtime/neurun/core/include/ir/operation/PReLU.h rename to runtime/onert/core/include/ir/operation/PReLU.h index 8c00c46fd3b..2981ffc6a71 100644 --- a/runtime/neurun/core/include/ir/operation/PReLU.h +++ b/runtime/onert/core/include/ir/operation/PReLU.h @@ -14,12 +14,12 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_PRELU_H__ -#define __NEURUN_IR_OPERATION_PRELU_H__ +#ifndef __ONERT_IR_OPERATION_PRELU_H__ +#define __ONERT_IR_OPERATION_PRELU_H__ #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -45,6 +45,6 @@ class PReLU : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_PRELU_H__ +#endif // __ONERT_IR_OPERATION_PRELU_H__ diff --git a/runtime/neurun/core/include/ir/operation/Pack.h b/runtime/onert/core/include/ir/operation/Pack.h similarity index 88% rename from runtime/neurun/core/include/ir/operation/Pack.h rename to runtime/onert/core/include/ir/operation/Pack.h index ccf73fe5c84..39fca49d486 100644 --- a/runtime/neurun/core/include/ir/operation/Pack.h +++ b/runtime/onert/core/include/ir/operation/Pack.h @@ -13,12 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_PACK_H__ -#define __NEURUN_IR_OPERATION_PACK_H__ +#ifndef __ONERT_IR_OPERATION_PACK_H__ +#define __ONERT_IR_OPERATION_PACK_H__ #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -49,5 +49,5 @@ class Pack : public Operation }; } // namespace operation } // namespace ir -} // namespace neurun -#endif // __NEURUN_IR_OPERATION_PACK_H__ +} // namespace onert +#endif // __ONERT_IR_OPERATION_PACK_H__ diff --git a/runtime/neurun/core/include/ir/operation/Pad.h b/runtime/onert/core/include/ir/operation/Pad.h similarity index 88% rename from runtime/neurun/core/include/ir/operation/Pad.h rename to runtime/onert/core/include/ir/operation/Pad.h index 8e8304faef3..18da18bc3ce 100644 --- a/runtime/neurun/core/include/ir/operation/Pad.h +++ b/runtime/onert/core/include/ir/operation/Pad.h @@ -14,12 +14,12 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_PAD_H__ -#define __NEURUN_IR_OPERATION_PAD_H__ +#ifndef __ONERT_IR_OPERATION_PAD_H__ +#define __ONERT_IR_OPERATION_PAD_H__ #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -58,6 +58,6 @@ class Pad : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_PAD_H__ +#endif // __ONERT_IR_OPERATION_PAD_H__ diff --git a/runtime/neurun/core/include/ir/operation/Permute.h b/runtime/onert/core/include/ir/operation/Permute.h similarity index 89% rename from runtime/neurun/core/include/ir/operation/Permute.h rename to runtime/onert/core/include/ir/operation/Permute.h index f91f9571b30..30930d2cc2e 100644 --- a/runtime/neurun/core/include/ir/operation/Permute.h +++ b/runtime/onert/core/include/ir/operation/Permute.h @@ -14,20 +14,20 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_PERMUTE_H__ -#define __NEURUN_IR_OPERATION_PERMUTE_H__ +#ifndef __ONERT_IR_OPERATION_PERMUTE_H__ +#define __ONERT_IR_OPERATION_PERMUTE_H__ #include "ir/Operation.h" -namespace neurun +namespace onert { namespace backend { class BackendContext; } // namespace backend -} // namespace neurun +} // namespace onert -namespace neurun +namespace onert { namespace ir { @@ -73,6 +73,6 @@ class Permute : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_PERMUTE_H__ +#endif // __ONERT_IR_OPERATION_PERMUTE_H__ diff --git a/runtime/neurun/core/include/ir/operation/RNN.h b/runtime/onert/core/include/ir/operation/RNN.h similarity index 89% rename from runtime/neurun/core/include/ir/operation/RNN.h rename to runtime/onert/core/include/ir/operation/RNN.h index d812a6fc3e9..087075da2d6 100644 --- a/runtime/neurun/core/include/ir/operation/RNN.h +++ b/runtime/onert/core/include/ir/operation/RNN.h @@ -13,13 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_RNN_H__ -#define __NEURUN_IR_OPERATION_RNN_H__ +#ifndef __ONERT_IR_OPERATION_RNN_H__ +#define __ONERT_IR_OPERATION_RNN_H__ #include "ir/InternalType.h" #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -65,6 +65,6 @@ class RNN : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_RNN_H__ +#endif // __ONERT_IR_OPERATION_RNN_H__ diff --git a/runtime/neurun/core/include/ir/operation/RSQRT.h b/runtime/onert/core/include/ir/operation/RSQRT.h similarity index 86% rename from runtime/neurun/core/include/ir/operation/RSQRT.h rename to runtime/onert/core/include/ir/operation/RSQRT.h index 33648555a04..64bb4f10a6e 100644 --- a/runtime/neurun/core/include/ir/operation/RSQRT.h +++ b/runtime/onert/core/include/ir/operation/RSQRT.h @@ -14,12 +14,12 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_RSQRT_H__ -#define __NEURUN_IR_OPERATION_RSQRT_H__ +#ifndef __ONERT_IR_OPERATION_RSQRT_H__ +#define __ONERT_IR_OPERATION_RSQRT_H__ #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -44,6 +44,6 @@ class RSQRT : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_RSQRT_H__ +#endif // __ONERT_IR_OPERATION_RSQRT_H__ diff --git a/runtime/neurun/core/include/ir/operation/ReLU.h b/runtime/onert/core/include/ir/operation/ReLU.h similarity index 86% rename from runtime/neurun/core/include/ir/operation/ReLU.h rename to runtime/onert/core/include/ir/operation/ReLU.h index b6c7fdf0181..9eb0c091bfb 100644 --- a/runtime/neurun/core/include/ir/operation/ReLU.h +++ b/runtime/onert/core/include/ir/operation/ReLU.h @@ -14,12 +14,12 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_RELU_H__ -#define __NEURUN_IR_OPERATION_RELU_H__ +#ifndef __ONERT_IR_OPERATION_RELU_H__ +#define __ONERT_IR_OPERATION_RELU_H__ #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -44,6 +44,6 @@ class ReLU : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_RELU_H__ +#endif // __ONERT_IR_OPERATION_RELU_H__ diff --git a/runtime/neurun/core/include/ir/operation/ReLU1.h b/runtime/onert/core/include/ir/operation/ReLU1.h similarity index 86% rename from runtime/neurun/core/include/ir/operation/ReLU1.h rename to runtime/onert/core/include/ir/operation/ReLU1.h index ac45fda0571..134ee573a25 100644 --- a/runtime/neurun/core/include/ir/operation/ReLU1.h +++ b/runtime/onert/core/include/ir/operation/ReLU1.h @@ -14,12 +14,12 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_ReLU1_H__ -#define __NEURUN_IR_OPERATION_ReLU1_H__ +#ifndef __ONERT_IR_OPERATION_ReLU1_H__ +#define __ONERT_IR_OPERATION_ReLU1_H__ #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -44,6 +44,6 @@ class ReLU1 : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_ReLU1_H__ +#endif // __ONERT_IR_OPERATION_ReLU1_H__ diff --git a/runtime/neurun/core/include/ir/operation/ReLU6.h b/runtime/onert/core/include/ir/operation/ReLU6.h similarity index 86% rename from runtime/neurun/core/include/ir/operation/ReLU6.h rename to runtime/onert/core/include/ir/operation/ReLU6.h index 4d98dad5543..e658c4925dd 100644 --- a/runtime/neurun/core/include/ir/operation/ReLU6.h +++ b/runtime/onert/core/include/ir/operation/ReLU6.h @@ -14,12 +14,12 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_ReLU6_H__ -#define __NEURUN_IR_OPERATION_ReLU6_H__ +#ifndef __ONERT_IR_OPERATION_ReLU6_H__ +#define __ONERT_IR_OPERATION_ReLU6_H__ #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -44,6 +44,6 @@ class ReLU6 : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_ReLU6_H__ +#endif // __ONERT_IR_OPERATION_ReLU6_H__ diff --git a/runtime/neurun/core/include/ir/operation/ReduceMax.h b/runtime/onert/core/include/ir/operation/ReduceMax.h similarity index 88% rename from runtime/neurun/core/include/ir/operation/ReduceMax.h rename to runtime/onert/core/include/ir/operation/ReduceMax.h index da4d7c4cc8f..af4bd5a6184 100644 --- a/runtime/neurun/core/include/ir/operation/ReduceMax.h +++ b/runtime/onert/core/include/ir/operation/ReduceMax.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_REDUCEMAX_H__ -#define __NEURUN_IR_OPERATION_REDUCEMAX_H__ +#ifndef __ONERT_IR_OPERATION_REDUCEMAX_H__ +#define __ONERT_IR_OPERATION_REDUCEMAX_H__ #include #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -60,6 +60,6 @@ class ReduceMax : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_REDUCEMAX_H__ +#endif // __ONERT_IR_OPERATION_REDUCEMAX_H__ diff --git a/runtime/neurun/core/include/ir/operation/ReduceMin.h b/runtime/onert/core/include/ir/operation/ReduceMin.h similarity index 88% rename from runtime/neurun/core/include/ir/operation/ReduceMin.h rename to runtime/onert/core/include/ir/operation/ReduceMin.h index f79fdeaea38..46a3e981291 100644 --- a/runtime/neurun/core/include/ir/operation/ReduceMin.h +++ b/runtime/onert/core/include/ir/operation/ReduceMin.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_REDUCEMIN_H__ -#define __NEURUN_IR_OPERATION_REDUCEMIN_H__ +#ifndef __ONERT_IR_OPERATION_REDUCEMIN_H__ +#define __ONERT_IR_OPERATION_REDUCEMIN_H__ #include #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -60,6 +60,6 @@ class ReduceMin : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_REDUCEMIN_H__ +#endif // __ONERT_IR_OPERATION_REDUCEMIN_H__ diff --git a/runtime/neurun/core/include/ir/operation/ReduceSum.h b/runtime/onert/core/include/ir/operation/ReduceSum.h similarity index 87% rename from runtime/neurun/core/include/ir/operation/ReduceSum.h rename to runtime/onert/core/include/ir/operation/ReduceSum.h index b5ab8ee7513..b7374a51d28 100644 --- a/runtime/neurun/core/include/ir/operation/ReduceSum.h +++ b/runtime/onert/core/include/ir/operation/ReduceSum.h @@ -14,12 +14,12 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_REDUCE_SUM_H__ -#define __NEURUN_IR_OPERATION_REDUCE_SUM_H__ +#ifndef __ONERT_IR_OPERATION_REDUCE_SUM_H__ +#define __ONERT_IR_OPERATION_REDUCE_SUM_H__ #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -58,6 +58,6 @@ class ReduceSum : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_REDUCE_SUM_H__ +#endif // __ONERT_IR_OPERATION_REDUCE_SUM_H__ diff --git a/runtime/neurun/core/include/ir/operation/Reshape.h b/runtime/onert/core/include/ir/operation/Reshape.h similarity index 84% rename from runtime/neurun/core/include/ir/operation/Reshape.h rename to runtime/onert/core/include/ir/operation/Reshape.h index e476d7fe170..34c21237606 100644 --- a/runtime/neurun/core/include/ir/operation/Reshape.h +++ b/runtime/onert/core/include/ir/operation/Reshape.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_RESHAPE_H__ -#define __NEURUN_IR_OPERATION_RESHAPE_H__ +#ifndef __ONERT_IR_OPERATION_RESHAPE_H__ +#define __ONERT_IR_OPERATION_RESHAPE_H__ #include #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -33,7 +33,8 @@ class Reshape : public Operation public: enum Input { - INPUT = 0 + INPUT = 0, + SHAPE = 1 }; public: @@ -46,6 +47,6 @@ class Reshape : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_RESHAPE_H__ +#endif // __ONERT_IR_OPERATION_RESHAPE_H__ diff --git a/runtime/neurun/core/include/ir/operation/ResizeBilinear.h b/runtime/onert/core/include/ir/operation/ResizeBilinear.h similarity index 86% rename from runtime/neurun/core/include/ir/operation/ResizeBilinear.h rename to runtime/onert/core/include/ir/operation/ResizeBilinear.h index d937da00c06..2887ed8455f 100644 --- a/runtime/neurun/core/include/ir/operation/ResizeBilinear.h +++ b/runtime/onert/core/include/ir/operation/ResizeBilinear.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_RESIZE_BILINEAR_H__ -#define __NEURUN_IR_OPERATION_RESIZE_BILINEAR_H__ +#ifndef __ONERT_IR_OPERATION_RESIZE_BILINEAR_H__ +#define __ONERT_IR_OPERATION_RESIZE_BILINEAR_H__ #include #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -59,6 +59,6 @@ class ResizeBilinear : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_RESIZE_BILINEAR_H__ +#endif // __ONERT_IR_OPERATION_RESIZE_BILINEAR_H__ diff --git a/runtime/neurun/core/include/ir/operation/SQRT.h b/runtime/onert/core/include/ir/operation/SQRT.h similarity index 86% rename from runtime/neurun/core/include/ir/operation/SQRT.h rename to runtime/onert/core/include/ir/operation/SQRT.h index 5e21315b419..8563b1ab10d 100644 --- a/runtime/neurun/core/include/ir/operation/SQRT.h +++ b/runtime/onert/core/include/ir/operation/SQRT.h @@ -14,12 +14,12 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_SQRT_H__ -#define __NEURUN_IR_OPERATION_SQRT_H__ +#ifndef __ONERT_IR_OPERATION_SQRT_H__ +#define __ONERT_IR_OPERATION_SQRT_H__ #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -44,6 +44,6 @@ class SQRT : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_SQRT_H__ +#endif // __ONERT_IR_OPERATION_SQRT_H__ diff --git a/runtime/onert/core/include/ir/operation/Sin.h b/runtime/onert/core/include/ir/operation/Sin.h new file mode 100644 index 00000000000..aef44ab2e29 --- /dev/null +++ b/runtime/onert/core/include/ir/operation/Sin.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2020 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 __ONERT_IR_OPERATION_SIN_H__ +#define __ONERT_IR_OPERATION_SIN_H__ + +#include "ir/Operation.h" + +namespace onert +{ +namespace ir +{ +namespace operation +{ + +class Sin : public Operation +{ +public: + enum Input + { + INPUT = 0 + }; + +public: + Sin(const OperandIndexSequence &inputs, const OperandIndexSequence &outputs); + +public: + void accept(OperationVisitor &v) const override; + OpCode opcode() const final { return OpCode::Sin; } +}; + +} // namespace operation +} // namespace ir +} // namespace onert + +#endif // __ONERT_IR_OPERATION_SIN_H__ diff --git a/runtime/neurun/core/include/ir/operation/Slice.h b/runtime/onert/core/include/ir/operation/Slice.h similarity index 88% rename from runtime/neurun/core/include/ir/operation/Slice.h rename to runtime/onert/core/include/ir/operation/Slice.h index 4b79f42a6a8..71e117c9c7a 100644 --- a/runtime/neurun/core/include/ir/operation/Slice.h +++ b/runtime/onert/core/include/ir/operation/Slice.h @@ -14,12 +14,12 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_SLICE_H__ -#define __NEURUN_IR_OPERATION_SLICE_H__ +#ifndef __ONERT_IR_OPERATION_SLICE_H__ +#define __ONERT_IR_OPERATION_SLICE_H__ #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -59,6 +59,6 @@ class Slice : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_SLICE_H__ +#endif // __ONERT_IR_OPERATION_SLICE_H__ diff --git a/runtime/neurun/core/include/ir/operation/Softmax.h b/runtime/onert/core/include/ir/operation/Softmax.h similarity index 87% rename from runtime/neurun/core/include/ir/operation/Softmax.h rename to runtime/onert/core/include/ir/operation/Softmax.h index a3e896fedb2..db7ae910e08 100644 --- a/runtime/neurun/core/include/ir/operation/Softmax.h +++ b/runtime/onert/core/include/ir/operation/Softmax.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_SOFTMAX_H__ -#define __NEURUN_IR_OPERATION_SOFTMAX_H__ +#ifndef __ONERT_IR_OPERATION_SOFTMAX_H__ +#define __ONERT_IR_OPERATION_SOFTMAX_H__ #include #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -58,6 +58,6 @@ class Softmax : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_SOFTMAX_H__ +#endif // __ONERT_IR_OPERATION_SOFTMAX_H__ diff --git a/runtime/neurun/core/include/ir/operation/SpaceToBatchND.h b/runtime/onert/core/include/ir/operation/SpaceToBatchND.h similarity index 85% rename from runtime/neurun/core/include/ir/operation/SpaceToBatchND.h rename to runtime/onert/core/include/ir/operation/SpaceToBatchND.h index 4ca0978b025..99928ff24ce 100644 --- a/runtime/neurun/core/include/ir/operation/SpaceToBatchND.h +++ b/runtime/onert/core/include/ir/operation/SpaceToBatchND.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_SPACE_TO_BATCH_ND_H__ -#define __NEURUN_IR_OPERATION_SPACE_TO_BATCH_ND_H__ +#ifndef __ONERT_IR_OPERATION_SPACE_TO_BATCH_ND_H__ +#define __ONERT_IR_OPERATION_SPACE_TO_BATCH_ND_H__ #include #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -48,6 +48,6 @@ class SpaceToBatchND : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_SPACE_TO_BATCH_ND_H__ +#endif // __ONERT_IR_OPERATION_SPACE_TO_BATCH_ND_H__ diff --git a/runtime/neurun/core/include/ir/operation/SpaceToDepth.h b/runtime/onert/core/include/ir/operation/SpaceToDepth.h similarity index 86% rename from runtime/neurun/core/include/ir/operation/SpaceToDepth.h rename to runtime/onert/core/include/ir/operation/SpaceToDepth.h index 9e77bdae0e1..6c8b091302d 100644 --- a/runtime/neurun/core/include/ir/operation/SpaceToDepth.h +++ b/runtime/onert/core/include/ir/operation/SpaceToDepth.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_SPACE_TO_DEPTH_H__ -#define __NEURUN_IR_OPERATION_SPACE_TO_DEPTH_H__ +#ifndef __ONERT_IR_OPERATION_SPACE_TO_DEPTH_H__ +#define __ONERT_IR_OPERATION_SPACE_TO_DEPTH_H__ #include #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -58,6 +58,6 @@ class SpaceToDepth : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_SPACE_TO_DEPTH_H__ +#endif // __ONERT_IR_OPERATION_SPACE_TO_DEPTH_H__ diff --git a/runtime/neurun/core/include/ir/operation/Split.h b/runtime/onert/core/include/ir/operation/Split.h similarity index 88% rename from runtime/neurun/core/include/ir/operation/Split.h rename to runtime/onert/core/include/ir/operation/Split.h index 7a2749e841b..d17a9813c7f 100644 --- a/runtime/neurun/core/include/ir/operation/Split.h +++ b/runtime/onert/core/include/ir/operation/Split.h @@ -13,12 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_SPLIT_H__ -#define __NEURUN_IR_OPERATION_SPLIT_H__ +#ifndef __ONERT_IR_OPERATION_SPLIT_H__ +#define __ONERT_IR_OPERATION_SPLIT_H__ #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -55,5 +55,5 @@ class Split : public Operation }; } // namespace operation } // namespace ir -} // namespace neurun -#endif // __NEURUN_IR_OPERATION_SPLIT_H__ +} // namespace onert +#endif // __ONERT_IR_OPERATION_SPLIT_H__ diff --git a/runtime/neurun/core/include/ir/operation/SquaredDifference.h b/runtime/onert/core/include/ir/operation/SquaredDifference.h similarity index 84% rename from runtime/neurun/core/include/ir/operation/SquaredDifference.h rename to runtime/onert/core/include/ir/operation/SquaredDifference.h index 46df419f57f..392b11448f9 100644 --- a/runtime/neurun/core/include/ir/operation/SquaredDifference.h +++ b/runtime/onert/core/include/ir/operation/SquaredDifference.h @@ -14,12 +14,12 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_SQUARED_DIFFERENCE_H__ -#define __NEURUN_IR_OPERATION_SQUARED_DIFFERENCE_H__ +#ifndef __ONERT_IR_OPERATION_SQUARED_DIFFERENCE_H__ +#define __ONERT_IR_OPERATION_SQUARED_DIFFERENCE_H__ #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -45,6 +45,6 @@ class SquaredDifference : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_SQUARED_DIFFERENCE_H__ +#endif // __ONERT_IR_OPERATION_SQUARED_DIFFERENCE_H__ diff --git a/runtime/neurun/core/include/ir/operation/Squeeze.h b/runtime/onert/core/include/ir/operation/Squeeze.h similarity index 88% rename from runtime/neurun/core/include/ir/operation/Squeeze.h rename to runtime/onert/core/include/ir/operation/Squeeze.h index d27b315b54a..c370472b71c 100644 --- a/runtime/neurun/core/include/ir/operation/Squeeze.h +++ b/runtime/onert/core/include/ir/operation/Squeeze.h @@ -14,12 +14,12 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_SQUEEZE_H__ -#define __NEURUN_IR_OPERATION_SQUEEZE_H__ +#ifndef __ONERT_IR_OPERATION_SQUEEZE_H__ +#define __ONERT_IR_OPERATION_SQUEEZE_H__ #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -57,6 +57,6 @@ class Squeeze : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_SQUEEZE_H__ +#endif // __ONERT_IR_OPERATION_SQUEEZE_H__ diff --git a/runtime/neurun/core/include/ir/operation/StridedSlice.h b/runtime/onert/core/include/ir/operation/StridedSlice.h similarity index 82% rename from runtime/neurun/core/include/ir/operation/StridedSlice.h rename to runtime/onert/core/include/ir/operation/StridedSlice.h index 868bda72c43..8c493b21d83 100644 --- a/runtime/neurun/core/include/ir/operation/StridedSlice.h +++ b/runtime/onert/core/include/ir/operation/StridedSlice.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_STRIDED_SLICE_H__ -#define __NEURUN_IR_OPERATION_STRIDED_SLICE_H__ +#ifndef __ONERT_IR_OPERATION_STRIDED_SLICE_H__ +#define __ONERT_IR_OPERATION_STRIDED_SLICE_H__ #include #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -41,9 +41,9 @@ class StridedSlice : public Operation struct Param { - std::int32_t begin_mask; - std::int32_t end_mask; - std::int32_t shrink_axis_mask; + int32_t begin_mask; + int32_t end_mask; + int32_t shrink_axis_mask; int32_t rank; }; @@ -64,6 +64,6 @@ class StridedSlice : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_STRIDED_SLICE_H__ +#endif // __ONERT_IR_OPERATION_STRIDED_SLICE_H__ diff --git a/runtime/neurun/core/include/ir/operation/Sub.h b/runtime/onert/core/include/ir/operation/Sub.h similarity index 88% rename from runtime/neurun/core/include/ir/operation/Sub.h rename to runtime/onert/core/include/ir/operation/Sub.h index e5850af8c39..0674e6e4da7 100644 --- a/runtime/neurun/core/include/ir/operation/Sub.h +++ b/runtime/onert/core/include/ir/operation/Sub.h @@ -14,13 +14,13 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_SUB_H__ -#define __NEURUN_IR_OPERATION_SUB_H__ +#ifndef __ONERT_IR_OPERATION_SUB_H__ +#define __ONERT_IR_OPERATION_SUB_H__ #include "ir/Operation.h" #include "ir/InternalType.h" -namespace neurun +namespace onert { namespace ir { @@ -57,6 +57,6 @@ class Sub : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_SUB_H__ +#endif // __ONERT_IR_OPERATION_SUB_H__ diff --git a/runtime/neurun/core/include/ir/operation/Tanh.h b/runtime/onert/core/include/ir/operation/Tanh.h similarity index 86% rename from runtime/neurun/core/include/ir/operation/Tanh.h rename to runtime/onert/core/include/ir/operation/Tanh.h index 814ceec5a19..9b8d03bca40 100644 --- a/runtime/neurun/core/include/ir/operation/Tanh.h +++ b/runtime/onert/core/include/ir/operation/Tanh.h @@ -14,12 +14,12 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_TANH_H__ -#define __NEURUN_IR_OPERATION_TANH_H__ +#ifndef __ONERT_IR_OPERATION_TANH_H__ +#define __ONERT_IR_OPERATION_TANH_H__ #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -44,6 +44,6 @@ class Tanh : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_TANH_H__ +#endif // __ONERT_IR_OPERATION_TANH_H__ diff --git a/runtime/neurun/core/include/ir/operation/TopKV2.h b/runtime/onert/core/include/ir/operation/TopKV2.h similarity index 88% rename from runtime/neurun/core/include/ir/operation/TopKV2.h rename to runtime/onert/core/include/ir/operation/TopKV2.h index a6971e8431d..179a599ca20 100644 --- a/runtime/neurun/core/include/ir/operation/TopKV2.h +++ b/runtime/onert/core/include/ir/operation/TopKV2.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_TOPK_V2_H__ -#define __NEURUN_IR_OPERATION_TOPK_V2_H__ +#ifndef __ONERT_IR_OPERATION_TOPK_V2_H__ +#define __ONERT_IR_OPERATION_TOPK_V2_H__ #include #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -64,6 +64,6 @@ class TopKV2 : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_TOPK_V2_H__ +#endif // __ONERT_IR_OPERATION_TOPK_V2_H__ diff --git a/runtime/neurun/core/include/ir/operation/Transpose.h b/runtime/onert/core/include/ir/operation/Transpose.h similarity index 88% rename from runtime/neurun/core/include/ir/operation/Transpose.h rename to runtime/onert/core/include/ir/operation/Transpose.h index b1e08a506cd..b2e04ca33a5 100644 --- a/runtime/neurun/core/include/ir/operation/Transpose.h +++ b/runtime/onert/core/include/ir/operation/Transpose.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_TRANSPOSE_H__ -#define __NEURUN_IR_OPERATION_TRANSPOSE_H__ +#ifndef __ONERT_IR_OPERATION_TRANSPOSE_H__ +#define __ONERT_IR_OPERATION_TRANSPOSE_H__ #include "ir/Operation.h" #include -namespace neurun +namespace onert { namespace ir { @@ -59,6 +59,6 @@ class Transpose : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_TRANSPOSE_H__ +#endif // __ONERT_IR_OPERATION_TRANSPOSE_H__ diff --git a/runtime/neurun/core/include/ir/operation/TransposeConv.h b/runtime/onert/core/include/ir/operation/TransposeConv.h similarity index 87% rename from runtime/neurun/core/include/ir/operation/TransposeConv.h rename to runtime/onert/core/include/ir/operation/TransposeConv.h index 3db48684671..05137ccf890 100644 --- a/runtime/neurun/core/include/ir/operation/TransposeConv.h +++ b/runtime/onert/core/include/ir/operation/TransposeConv.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_TRANSPOSE_CONV_H__ -#define __NEURUN_IR_OPERATION_TRANSPOSE_CONV_H__ +#ifndef __ONERT_IR_OPERATION_TRANSPOSE_CONV_H__ +#define __ONERT_IR_OPERATION_TRANSPOSE_CONV_H__ #include @@ -23,7 +23,7 @@ #include "ir/InternalType.h" #include "ir/Padding.h" -namespace neurun +namespace onert { namespace ir { @@ -63,6 +63,6 @@ class TransposeConv : public Operation } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_TRANSPOSE_CONV_H__ +#endif // __ONERT_IR_OPERATION_TRANSPOSE_CONV_H__ diff --git a/runtime/neurun/core/include/ir/operation/Unpack.h b/runtime/onert/core/include/ir/operation/Unpack.h similarity index 88% rename from runtime/neurun/core/include/ir/operation/Unpack.h rename to runtime/onert/core/include/ir/operation/Unpack.h index fa698d3af63..28e91afdae2 100644 --- a/runtime/neurun/core/include/ir/operation/Unpack.h +++ b/runtime/onert/core/include/ir/operation/Unpack.h @@ -13,12 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_UNPACK_H__ -#define __NEURUN_IR_OPERATION_UNPACK_H__ +#ifndef __ONERT_IR_OPERATION_UNPACK_H__ +#define __ONERT_IR_OPERATION_UNPACK_H__ #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -55,5 +55,5 @@ class Unpack : public Operation }; } // namespace operation } // namespace ir -} // namespace neurun -#endif // __NEURUN_IR_OPERATION_UNPACK_H__ +} // namespace onert +#endif // __ONERT_IR_OPERATION_UNPACK_H__ diff --git a/runtime/neurun/core/include/util/Config.lst b/runtime/onert/core/include/util/Config.lst similarity index 96% rename from runtime/neurun/core/include/util/Config.lst rename to runtime/onert/core/include/util/Config.lst index e09850131d1..75767b8b1e1 100644 --- a/runtime/neurun/core/include/util/Config.lst +++ b/runtime/onert/core/include/util/Config.lst @@ -24,7 +24,7 @@ CONFIG(BACKENDS , std::string , "acl_cl;acl_neon;cpu") CONFIG(OP_BACKEND_ALLOPS , std::string , "") CONFIG(OP_BACKEND_MAP , std::string , "") CONFIG(DISABLE_COMPILE , bool , "0") -CONFIG(NEURUN_LOG_ENABLE , bool , "0") +CONFIG(ONERT_LOG_ENABLE , bool , "0") CONFIG(CPU_MEMORY_PLANNER , std::string , "WIC") CONFIG(EXECUTOR , std::string , "Linear") CONFIG(ACL_LAYOUT , std::string , "none") diff --git a/runtime/neurun/core/include/util/ConfigSource.h b/runtime/onert/core/include/util/ConfigSource.h similarity index 80% rename from runtime/neurun/core/include/util/ConfigSource.h rename to runtime/onert/core/include/util/ConfigSource.h index b1fa9a87d69..b6a8144fda8 100644 --- a/runtime/neurun/core/include/util/ConfigSource.h +++ b/runtime/onert/core/include/util/ConfigSource.h @@ -14,28 +14,31 @@ * limitations under the License. */ -#ifndef __NEURUN_UTIL_CONFIG_SOURCE_H__ -#define __NEURUN_UTIL_CONFIG_SOURCE_H__ +#ifndef __ONERT_UTIL_CONFIG_SOURCE_H__ +#define __ONERT_UTIL_CONFIG_SOURCE_H__ #include #include "IConfigSource.h" -namespace neurun +namespace onert { namespace util { void config_source(std::unique_ptr &&source); +bool toBool(const std::string &val); +int toInt(const std::string &val); + bool getConfigBool(const std::string &key); int getConfigInt(const std::string &key); std::string getConfigString(const std::string &key); } // namespace util -} // namespace neurun +} // namespace onert -namespace neurun +namespace onert { namespace util { @@ -50,6 +53,6 @@ namespace config } // namespace config } // namespace util -} // namespace neurun +} // namespace onert -#endif // __NEURUN_UTIL_CONFIG_SOURCE_H__ +#endif // __ONERT_UTIL_CONFIG_SOURCE_H__ diff --git a/runtime/neurun/core/include/util/EnvConfigSource.h b/runtime/onert/core/include/util/EnvConfigSource.h similarity index 84% rename from runtime/neurun/core/include/util/EnvConfigSource.h rename to runtime/onert/core/include/util/EnvConfigSource.h index 77be15c4ea0..8c5d0e8e9f3 100644 --- a/runtime/neurun/core/include/util/EnvConfigSource.h +++ b/runtime/onert/core/include/util/EnvConfigSource.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_UTIL_ENV_CONFIG_SOURCE_H__ -#define __NEURUN_UTIL_ENV_CONFIG_SOURCE_H__ +#ifndef __ONERT_UTIL_ENV_CONFIG_SOURCE_H__ +#define __ONERT_UTIL_ENV_CONFIG_SOURCE_H__ #include #include "util/GeneralConfigSource.h" -namespace neurun +namespace onert { namespace util { @@ -36,6 +36,6 @@ class EnvConfigSource final : public GeneralConfigSource }; } // namespace util -} // namespace neurun +} // namespace onert -#endif // __NEURUN_UTIL_ENV_CONFIG_SOURCE_H__ +#endif // __ONERT_UTIL_ENV_CONFIG_SOURCE_H__ diff --git a/runtime/neurun/core/include/util/EventCollectorGlobal.h b/runtime/onert/core/include/util/EventCollectorGlobal.h similarity index 89% rename from runtime/neurun/core/include/util/EventCollectorGlobal.h rename to runtime/onert/core/include/util/EventCollectorGlobal.h index 15e40844ec2..1f110d906be 100644 --- a/runtime/neurun/core/include/util/EventCollectorGlobal.h +++ b/runtime/onert/core/include/util/EventCollectorGlobal.h @@ -14,13 +14,13 @@ * limitations under the License. */ -#ifndef __NEURUN_UTIL_EVENT_COLLECTOR_GLOBAL_H__ -#define __NEURUN_UTIL_EVENT_COLLECTOR_GLOBAL_H__ +#ifndef __ONERT_UTIL_EVENT_COLLECTOR_GLOBAL_H__ +#define __ONERT_UTIL_EVENT_COLLECTOR_GLOBAL_H__ #include "misc/EventRecorder.h" #include "misc/EventCollector.h" -namespace neurun +namespace onert { namespace util { @@ -126,7 +126,7 @@ class EventDurationManual }; } // namespace util -} // namespace neurun +} // namespace onert /** * Helper Macro Definitions @@ -147,9 +147,9 @@ class EventDurationManual */ #define EVENT_DURATION_FUNCTION() \ - ::neurun::util::EventDurationBlock __event_duration__##__LINE__ { __FUNCTION__ } + ::onert::util::EventDurationBlock __event_duration__##__LINE__ { __FUNCTION__ } #define EVENT_DURATION_REGION(tag) \ - ::neurun::util::EventDurationBlock __event_duration__##__LINE__ { tag } + ::onert::util::EventDurationBlock __event_duration__##__LINE__ { tag } -#endif // __NEURUN_UTIL_EVENT_COLLECTOR_GLOBAL_H__ +#endif // __ONERT_UTIL_EVENT_COLLECTOR_GLOBAL_H__ diff --git a/runtime/neurun/core/include/util/GeneralConfigSource.h b/runtime/onert/core/include/util/GeneralConfigSource.h similarity index 84% rename from runtime/neurun/core/include/util/GeneralConfigSource.h rename to runtime/onert/core/include/util/GeneralConfigSource.h index 04e3332b35a..dedc820ece9 100644 --- a/runtime/neurun/core/include/util/GeneralConfigSource.h +++ b/runtime/onert/core/include/util/GeneralConfigSource.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_UTIL_GLOBAL_CONFIG_SOURCE_H__ -#define __NEURUN_UTIL_GLOBAL_CONFIG_SOURCE_H__ +#ifndef __ONERT_UTIL_GLOBAL_CONFIG_SOURCE_H__ +#define __ONERT_UTIL_GLOBAL_CONFIG_SOURCE_H__ #include #include "util/IConfigSource.h" -namespace neurun +namespace onert { namespace util { @@ -39,6 +39,6 @@ class GeneralConfigSource : public IConfigSource }; } // namespace util -} // namespace neurun +} // namespace onert -#endif // __NEURUN_UTIL_GLOBAL_CONFIG_SOURCE_H__ +#endif // __ONERT_UTIL_GLOBAL_CONFIG_SOURCE_H__ diff --git a/runtime/neurun/core/include/util/IConfigSource.h b/runtime/onert/core/include/util/IConfigSource.h similarity index 86% rename from runtime/neurun/core/include/util/IConfigSource.h rename to runtime/onert/core/include/util/IConfigSource.h index a52d87097ad..07b09848af4 100644 --- a/runtime/neurun/core/include/util/IConfigSource.h +++ b/runtime/onert/core/include/util/IConfigSource.h @@ -14,12 +14,12 @@ * limitations under the License. */ -#ifndef __NEURUN_UTIL_I_CONFIG_SOURCE_H__ -#define __NEURUN_UTIL_I_CONFIG_SOURCE_H__ +#ifndef __ONERT_UTIL_I_CONFIG_SOURCE_H__ +#define __ONERT_UTIL_I_CONFIG_SOURCE_H__ #include -namespace neurun +namespace onert { namespace util { @@ -41,6 +41,6 @@ struct IConfigSource }; } // namespace util -} // namespace neurun +} // namespace onert -#endif // __NEURUN_UTIL_I_CONFIG_SOURCE_H__ +#endif // __ONERT_UTIL_I_CONFIG_SOURCE_H__ diff --git a/runtime/neurun/core/include/util/ITimer.h b/runtime/onert/core/include/util/ITimer.h similarity index 90% rename from runtime/neurun/core/include/util/ITimer.h rename to runtime/onert/core/include/util/ITimer.h index 79ecdd0ca04..d5a4e1eb080 100644 --- a/runtime/neurun/core/include/util/ITimer.h +++ b/runtime/onert/core/include/util/ITimer.h @@ -14,12 +14,12 @@ * limitations under the License. */ -#ifndef __NEURUN_UTIL_ITIMER_H__ -#define __NEURUN_UTIL_ITIMER_H__ +#ifndef __ONERT_UTIL_ITIMER_H__ +#define __ONERT_UTIL_ITIMER_H__ #include -namespace neurun +namespace onert { namespace util { @@ -54,6 +54,6 @@ class CPUTimer : public ITimer }; } // namespace util -} // namespace neurun +} // namespace onert -#endif // __NEURUN_UTIL_ITIMER_H__ +#endif // __ONERT_UTIL_ITIMER_H__ diff --git a/runtime/neurun/core/include/util/Index.h b/runtime/onert/core/include/util/Index.h similarity index 92% rename from runtime/neurun/core/include/util/Index.h rename to runtime/onert/core/include/util/Index.h index bd8eeb38c7f..d96c0cffef9 100644 --- a/runtime/neurun/core/include/util/Index.h +++ b/runtime/onert/core/include/util/Index.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_UTIL_INDEX_H__ -#define __NEURUN_UTIL_INDEX_H__ +#ifndef __ONERT_UTIL_INDEX_H__ +#define __ONERT_UTIL_INDEX_H__ #include #include #include -namespace neurun +namespace onert { namespace util { @@ -136,14 +136,14 @@ template class Index }; } // namespace util -} // namespace neurun +} // namespace onert namespace std { -template struct hash<::neurun::util::Index> +template struct hash<::onert::util::Index> { - size_t operator()(const ::neurun::util::Index &index) const noexcept + size_t operator()(const ::onert::util::Index &index) const noexcept { return hash()(index.value()); } @@ -151,4 +151,4 @@ template struct hash<::neurun::util::Index> } // namespace std -#endif // __NEURUN_UTIL_INDEX_H__ +#endif // __ONERT_UTIL_INDEX_H__ diff --git a/runtime/neurun/core/include/util/ObjectManager.h b/runtime/onert/core/include/util/ObjectManager.h similarity index 95% rename from runtime/neurun/core/include/util/ObjectManager.h rename to runtime/onert/core/include/util/ObjectManager.h index c07b6cfb5fb..d2dd881a8ca 100644 --- a/runtime/neurun/core/include/util/ObjectManager.h +++ b/runtime/onert/core/include/util/ObjectManager.h @@ -14,17 +14,17 @@ * limitations under the License. */ -#ifndef __NEURUN_UTIL_OBJECT_MANAGER_H__ -#define __NEURUN_UTIL_OBJECT_MANAGER_H__ +#ifndef __ONERT_UTIL_OBJECT_MANAGER_H__ +#define __ONERT_UTIL_OBJECT_MANAGER_H__ #include #include #include #include -#include "memory" +#include -namespace neurun +namespace onert { namespace util { @@ -143,6 +143,6 @@ template class ObjectManager }; } // namespace util -} // namespace neurun +} // namespace onert -#endif // __NEURUN_UTIL_OBJECT_MANAGER_H__ +#endif // __ONERT_UTIL_OBJECT_MANAGER_H__ diff --git a/runtime/neurun/core/include/util/Set.h b/runtime/onert/core/include/util/Set.h similarity index 95% rename from runtime/neurun/core/include/util/Set.h rename to runtime/onert/core/include/util/Set.h index 13213511db6..ee4062d25c5 100644 --- a/runtime/neurun/core/include/util/Set.h +++ b/runtime/onert/core/include/util/Set.h @@ -16,17 +16,17 @@ /** * @file Set.h - * @brief This file contains neurun::util::Set class + * @brief This file contains onert::util::Set class * @ingroup COM_AI_RUNTIME */ -#ifndef __NEURUN_UTIL_SET_H__ -#define __NEURUN_UTIL_SET_H__ +#ifndef __ONERT_UTIL_SET_H__ +#define __ONERT_UTIL_SET_H__ #include #include -namespace neurun +namespace onert { namespace util { @@ -161,6 +161,6 @@ template class Set }; } // namespace util -} // namespace neurun +} // namespace onert -#endif // __NEURUN_UTIL_SET_H__ +#endif // __ONERT_UTIL_SET_H__ diff --git a/runtime/neurun/core/include/util/ShapeInference.h b/runtime/onert/core/include/util/ShapeInference.h similarity index 61% rename from runtime/neurun/core/include/util/ShapeInference.h rename to runtime/onert/core/include/util/ShapeInference.h index 097d6164309..fbd3d19c8c9 100644 --- a/runtime/neurun/core/include/util/ShapeInference.h +++ b/runtime/onert/core/include/util/ShapeInference.h @@ -14,19 +14,21 @@ * limitations under the License. */ -#ifndef __NEURUN_GRAPH_SHAPE_INFERENCE_H__ -#define __NEURUN_GRAPH_SHAPE_INFERENCE_H__ +#ifndef __ONERT_GRAPH_SHAPE_INFERENCE_H__ +#define __ONERT_GRAPH_SHAPE_INFERENCE_H__ #include "ir/operation/AvgPool2D.h" #include "ir/operation/Concat.h" #include "ir/operation/MaxPool2D.h" #include "ir/operation/Conv2D.h" #include "ir/operation/DepthwiseConv2D.h" +#include "ir/operation/Reshape.h" #include "ir/Operands.h" #include "ir/Index.h" #include "ir/Layout.h" +#include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace shape_inference { @@ -53,7 +55,36 @@ Shapes inferDepthwiseConv2DShape(const ir::Shape &in_shape, const ir::Shape &ker Shapes inferFullyConnectedShape(const ir::Shape &in_shape, const ir::Shape &ker_shape); +/** + * @brief Class to infer shape before running kernels. It does the following: + * - re-calculate and set output shape at compile time (before running kernels) + * - if calculation cannot be done at compile time, mark the outputs to be dynamic, meaning + * shapes of outputs will be calculated during running kernels + */ +class StaticInferer : public ir::OperationVisitor +{ +public: + StaticInferer(ir::Operands &operands) : _operands(operands) { /* empty */} + virtual ~StaticInferer() = default; + +public: + /** + * @brief Infer shape of operands beloning to ops and set the output shape. + * If output shape cannot be known without running op, mark it so that it can be allocated + * when running kernel. + * @param op_seq sequence of operations + */ + void infer(const ir::OpSequence &op_seq) { op_seq.accept(*this); }; + +private: + // TODO Define visitors for operations. List them in alphabetic order. + void visit(const ir::operation::Reshape &op); + +private: + ir::Operands &_operands; +}; + } // namespace shape_inference -} // namespace neurun +} // namespace onert -#endif // __NEURUN_GRAPH_SHAPE_INFERENCE_H__ +#endif // __ONERT_GRAPH_SHAPE_INFERENCE_H__ diff --git a/runtime/neurun/core/include/util/Utils.h b/runtime/onert/core/include/util/Utils.h similarity index 88% rename from runtime/neurun/core/include/util/Utils.h rename to runtime/onert/core/include/util/Utils.h index 77ea9b90ba2..847fb697148 100644 --- a/runtime/neurun/core/include/util/Utils.h +++ b/runtime/onert/core/include/util/Utils.h @@ -19,9 +19,9 @@ * @brief This file contains utility macro */ -#ifndef __NEURUN_UTIL_UTILS_H__ -#define __NEURUN_UTIL_UTILS_H__ +#ifndef __ONERT_UTIL_UTILS_H__ +#define __ONERT_UTIL_UTILS_H__ #define UNUSED_RELEASE(a) (void)(a) -#endif // __NEURUN_UTIL_UTILS_H__ +#endif // __ONERT_UTIL_UTILS_H__ diff --git a/runtime/neurun/core/include/util/feature/nchw/Reader.h b/runtime/onert/core/include/util/feature/nchw/Reader.h similarity index 95% rename from runtime/neurun/core/include/util/feature/nchw/Reader.h rename to runtime/onert/core/include/util/feature/nchw/Reader.h index a2071ce6c13..586ba92dd74 100644 --- a/runtime/neurun/core/include/util/feature/nchw/Reader.h +++ b/runtime/onert/core/include/util/feature/nchw/Reader.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_UTIL_FEATURE_NCHW_READER_H__ -#define __NEURUN_UTIL_FEATURE_NCHW_READER_H__ +#ifndef __ONERT_UTIL_FEATURE_NCHW_READER_H__ +#define __ONERT_UTIL_FEATURE_NCHW_READER_H__ #include @@ -23,7 +23,7 @@ #include "misc/feature/Reader.h" #include "misc/feature/Shape.h" -namespace neurun +namespace onert { namespace util { @@ -113,6 +113,6 @@ template class Reader final : public nnfw::misc::feature::Reader } // namespace nchw } // namespace feature } // namespace util -} // namespace neurun +} // namespace onert -#endif // __NEURUN_UTIL_FEATURE_NCHW_READER_H__ +#endif // __ONERT_UTIL_FEATURE_NCHW_READER_H__ diff --git a/runtime/neurun/core/include/util/feature/nchw/View.h b/runtime/onert/core/include/util/feature/nchw/View.h similarity index 94% rename from runtime/neurun/core/include/util/feature/nchw/View.h rename to runtime/onert/core/include/util/feature/nchw/View.h index 77fdcde83c6..28c18d034ff 100644 --- a/runtime/neurun/core/include/util/feature/nchw/View.h +++ b/runtime/onert/core/include/util/feature/nchw/View.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_UTIL_FEATURE_NCHW_VIEW_H__ -#define __NEURUN_UTIL_FEATURE_NCHW_VIEW_H__ +#ifndef __ONERT_UTIL_FEATURE_NCHW_VIEW_H__ +#define __ONERT_UTIL_FEATURE_NCHW_VIEW_H__ #include "misc/feature/Reader.h" #include "misc/feature/Shape.h" @@ -25,7 +25,7 @@ #include -namespace neurun +namespace onert { namespace util { @@ -50,7 +50,7 @@ template class View final : public nnfw::misc::feature::Reader } // Construct for backend tensor - View(::neurun::backend::ITensor *tensor) + View(::onert::backend::ITensor *tensor) : _ptr{tensor->buffer() + tensor->calcOffset({0, 0, 0, 0})}, _len{tensor->total_size()} { assert(tensor->layout() == ir::Layout::NCHW); @@ -132,6 +132,6 @@ template class View final : public nnfw::misc::feature::Reader } // namespace nchw } // namespace feature } // namespace util -} // namespace neurun +} // namespace onert -#endif // __NEURUN_UTIL_FEATURE_NCHW_VIEW_H__ +#endif // __ONERT_UTIL_FEATURE_NCHW_VIEW_H__ diff --git a/runtime/neurun/core/include/util/feature/nhwc/Reader.h b/runtime/onert/core/include/util/feature/nhwc/Reader.h similarity index 95% rename from runtime/neurun/core/include/util/feature/nhwc/Reader.h rename to runtime/onert/core/include/util/feature/nhwc/Reader.h index 4d10d2695c4..f00a864a6c5 100644 --- a/runtime/neurun/core/include/util/feature/nhwc/Reader.h +++ b/runtime/onert/core/include/util/feature/nhwc/Reader.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_UTIL_FEATURE_NHWC_READER_H__ -#define __NEURUN_UTIL_FEATURE_NHWC_READER_H__ +#ifndef __ONERT_UTIL_FEATURE_NHWC_READER_H__ +#define __ONERT_UTIL_FEATURE_NHWC_READER_H__ #include @@ -24,7 +24,7 @@ #include "misc/feature/Shape.h" #include "util/Utils.h" -namespace neurun +namespace onert { namespace util { @@ -115,6 +115,6 @@ template class Reader final : public nnfw::misc::feature::Reader } // namespace nhwc } // namespace feature } // namespace util -} // namespace neurun +} // namespace onert -#endif // __NEURUN_UTIL_FEATURE_NHWC_READER_H__ +#endif // __ONERT_UTIL_FEATURE_NHWC_READER_H__ diff --git a/runtime/neurun/core/include/util/feature/nhwc/View.h b/runtime/onert/core/include/util/feature/nhwc/View.h similarity index 95% rename from runtime/neurun/core/include/util/feature/nhwc/View.h rename to runtime/onert/core/include/util/feature/nhwc/View.h index ef03cb4e760..1dfdfe461bf 100644 --- a/runtime/neurun/core/include/util/feature/nhwc/View.h +++ b/runtime/onert/core/include/util/feature/nhwc/View.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_UTIL_FEATURE_NHWC_VIEW_H__ -#define __NEURUN_UTIL_FEATURE_NHWC_VIEW_H__ +#ifndef __ONERT_UTIL_FEATURE_NHWC_VIEW_H__ +#define __ONERT_UTIL_FEATURE_NHWC_VIEW_H__ #include #include @@ -25,7 +25,7 @@ #include "misc/feature/Shape.h" #include "util/Utils.h" -namespace neurun +namespace onert { namespace util { @@ -134,6 +134,6 @@ template class View final : public nnfw::misc::feature::Reader } // namespace nhwc } // namespace feature } // namespace util -} // namespace neurun +} // namespace onert -#endif // __NEURUN_UTIL_FEATURE_NHWC_VIEW_H__ +#endif // __ONERT_UTIL_FEATURE_NHWC_VIEW_H__ diff --git a/runtime/neurun/core/include/util/logging.h b/runtime/onert/core/include/util/logging.h similarity index 77% rename from runtime/neurun/core/include/util/logging.h rename to runtime/onert/core/include/util/logging.h index 8ecd0ac1246..b8357793ea5 100644 --- a/runtime/neurun/core/include/util/logging.h +++ b/runtime/onert/core/include/util/logging.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_UTIL_LOGGING_H__ -#define __NEURUN_UTIL_LOGGING_H__ +#ifndef __ONERT_UTIL_LOGGING_H__ +#define __ONERT_UTIL_LOGGING_H__ #include #include "util/ConfigSource.h" -namespace neurun +namespace onert { namespace util { @@ -33,7 +33,7 @@ class Context public: Context() noexcept : _enabled{false} { - const auto env = util::getConfigBool(util::config::NEURUN_LOG_ENABLE); + const auto env = util::getConfigBool(util::config::ONERT_LOG_ENABLE); if (env) { @@ -54,10 +54,10 @@ static Context &ctx = Context::get(); } // namespace logging } // namespace util -} // namespace neurun +} // namespace onert -#define VERBOSE(name) \ - if (::neurun::util::logging::ctx.enabled()) \ +#define VERBOSE(name) \ + if (::onert::util::logging::ctx.enabled()) \ std::cout << "[" << #name << "] " -#endif // __NEURUN_UTIL_LOGGING_H__ +#endif // __ONERT_UTIL_LOGGING_H__ diff --git a/runtime/neurun/core/src/backend/BackendContext.cc b/runtime/onert/core/src/backend/BackendContext.cc similarity index 97% rename from runtime/neurun/core/src/backend/BackendContext.cc rename to runtime/onert/core/src/backend/BackendContext.cc index b2c7fb1c913..f2173de44d0 100644 --- a/runtime/neurun/core/src/backend/BackendContext.cc +++ b/runtime/onert/core/src/backend/BackendContext.cc @@ -20,7 +20,7 @@ #include "backend/IShapeFixer.h" #include "backend/IConstantInitializer.h" -namespace neurun +namespace onert { namespace backend { @@ -61,4 +61,4 @@ void BackendContext::initConsts() } } // namespace backend -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/compiler/BackendManager.cc b/runtime/onert/core/src/compiler/BackendManager.cc similarity index 90% rename from runtime/neurun/core/src/compiler/BackendManager.cc rename to runtime/onert/core/src/compiler/BackendManager.cc index 5ce66d13edb..bfed7ff2b42 100644 --- a/runtime/neurun/core/src/compiler/BackendManager.cc +++ b/runtime/onert/core/src/compiler/BackendManager.cc @@ -25,7 +25,7 @@ #include "util/ConfigSource.h" #include "misc/string_helpers.h" -namespace neurun +namespace onert { namespace compiler { @@ -76,19 +76,19 @@ void BackendManager::loadBackend(const std::string &backend) { // load object creator function - auto backend_create = (backend_create_t)dlsym(handle, "neurun_backend_create"); + auto backend_create = (backend_create_t)dlsym(handle, "onert_backend_create"); if (backend_create == nullptr) { - fprintf(stderr, "BackendManager: unable to open function neurun_backend_create : %s\n", + fprintf(stderr, "BackendManager: unable to open function onert_backend_create : %s\n", dlerror()); abort(); } // load object creator function - auto backend_destroy = (backend_destroy_t)dlsym(handle, "neurun_backend_destroy"); + auto backend_destroy = (backend_destroy_t)dlsym(handle, "onert_backend_destroy"); if (backend_destroy == nullptr) { - fprintf(stderr, "BackendManager: unable to open function neurun_backend_destroy : %s\n", + fprintf(stderr, "BackendManager: unable to open function onert_backend_destroy : %s\n", dlerror()); abort(); } @@ -137,4 +137,4 @@ const backend::Backend *BackendManager::get(const std::string &key) const const backend::Backend *BackendManager::getDefault() const { return get("cpu"); } } // namespace compiler -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/compiler/BackendResolver.cc b/runtime/onert/core/src/compiler/BackendResolver.cc similarity index 94% rename from runtime/neurun/core/src/compiler/BackendResolver.cc rename to runtime/onert/core/src/compiler/BackendResolver.cc index 59fb1abfa06..a47d8d2d5ab 100644 --- a/runtime/neurun/core/src/compiler/BackendResolver.cc +++ b/runtime/onert/core/src/compiler/BackendResolver.cc @@ -16,10 +16,10 @@ #include "compiler/BackendResolver.h" -namespace neurun +namespace onert { namespace compiler { } // namespace compiler -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/compiler/CachedDataDeleter.h b/runtime/onert/core/src/compiler/CachedDataDeleter.h similarity index 93% rename from runtime/neurun/core/src/compiler/CachedDataDeleter.h rename to runtime/onert/core/src/compiler/CachedDataDeleter.h index 7c4e9132d37..73f00ced75c 100644 --- a/runtime/neurun/core/src/compiler/CachedDataDeleter.h +++ b/runtime/onert/core/src/compiler/CachedDataDeleter.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_COMPILER_CACHED_DATA_DELETER_H__ -#define __NEURUN_COMPILER_CACHED_DATA_DELETER_H__ +#ifndef __ONERT_COMPILER_CACHED_DATA_DELETER_H__ +#define __ONERT_COMPILER_CACHED_DATA_DELETER_H__ #include "ir/Index.h" #include "ir/OperationVisitor.h" @@ -23,7 +23,7 @@ #include "ir/Operands.h" #include "util/logging.h" -namespace neurun +namespace onert { namespace compiler { @@ -98,6 +98,6 @@ class CachedDataDeleter : public ir::OperationVisitor }; } // namespace compiler -} // namespace neurun +} // namespace onert -#endif // __NEURUN_COMPILER_CACHED_DATA_DELETER_H__ +#endif // __ONERT_COMPILER_CACHED_DATA_DELETER_H__ diff --git a/runtime/neurun/core/src/compiler/Compiler.cc b/runtime/onert/core/src/compiler/Compiler.cc similarity index 96% rename from runtime/neurun/core/src/compiler/Compiler.cc rename to runtime/onert/core/src/compiler/Compiler.cc index d17fc417c0f..d601564927b 100644 --- a/runtime/neurun/core/src/compiler/Compiler.cc +++ b/runtime/onert/core/src/compiler/Compiler.cc @@ -34,7 +34,7 @@ #include "compiler/CachedDataDeleter.h" #include "misc/string_helpers.h" -namespace neurun +namespace onert { namespace compiler @@ -47,7 +47,7 @@ CompilerOptions fetchCompilerOptionsFromGlobalConfig(const ir::Graph &graph) options.backend_list = nnfw::misc::split(util::getConfigString(util::config::BACKENDS), ';'); options.trace_filepath = util::getConfigString(util::config::TRACE_FILEPATH); - options.graph_dump_level = util::getConfigBool(util::config::GRAPH_DOT_DUMP); + options.graph_dump_level = util::getConfigInt(util::config::GRAPH_DOT_DUMP); options.op_seq_max_node = util::getConfigInt(util::config::OP_SEQ_MAX_NODE); options.executor = util::getConfigString(util::config::EXECUTOR); options.he_scheduler = util::getConfigBool(util::config::USE_SCHEDULER); @@ -146,7 +146,7 @@ void Compiler::compile(void) ***************************************************/ auto dump_level = static_cast(_options.graph_dump_level); - neurun::dumper::dot::DotDumper dot_dumper(*_graph, dump_level); + onert::dumper::dot::DotDumper dot_dumper(*_graph, dump_level); dot_dumper.dump("before_lower"); // Lower: Assign backend @@ -170,7 +170,7 @@ void Compiler::compile(void) _state = State::LOWERED; - neurun::dumper::dot::DotDumper dot_dumper_lowered(lowered_graph.get(), dump_level); + onert::dumper::dot::DotDumper dot_dumper_lowered(lowered_graph.get(), dump_level); dot_dumper_lowered.dump("after_lower"); ir::OperationDumper dumper; @@ -210,4 +210,4 @@ bool Compiler::checkCompilable() } // namespace compiler -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/compiler/ExecutorFactory.cc b/runtime/onert/core/src/compiler/ExecutorFactory.cc similarity index 79% rename from runtime/neurun/core/src/compiler/ExecutorFactory.cc rename to runtime/onert/core/src/compiler/ExecutorFactory.cc index d7afbaeaa9b..8d06d6bbe0e 100644 --- a/runtime/neurun/core/src/compiler/ExecutorFactory.cc +++ b/runtime/onert/core/src/compiler/ExecutorFactory.cc @@ -29,10 +29,12 @@ #include "backend/IKernelGenerator.h" #include "backend/IShapeFixer.h" #include "backend/IOptimizer.h" -#include "memory" +#include "backend/ITensorRegister.h" +#include #include "compiler/CachedDataDeleter.h" +#include "util/ShapeInference.h" -namespace neurun +namespace onert { namespace compiler { @@ -96,6 +98,46 @@ void ExecutorFactory::initializeBackendContext(ir::LoweredGraph *lowered_graph) } } +void ExecutorFactory::runTensorRegistration(ir::LoweredGraph *lowered_graph, + const std::vector &order) +{ + for (const auto index : order) + { + const auto &op_seq = lowered_graph->op_seqs().at(index); + const auto backend = lowered_graph->getLowerInfo(index)->backend(); + const auto tensor_register = lowered_graph->backend_contexts().at(backend)->tensor_register; + auto tensor_builder = lowered_graph->backend_contexts().at(backend)->tensor_builder; + if (tensor_register) + { + // Custom registration + tensor_register->registerTensors(op_seq, lowered_graph->getLowerInfo()); + } + else + { + // Default registration + for (const auto elem : op_seq) + { + const auto &op = *elem.node; + for (const auto &index : op.getInputs() + op.getOutputs()) + { + if (!tensor_builder->isRegistered(index)) + { + const auto &operand_lower_info = + lowered_graph->getLowerInfo(index)->def_factors().getOnlyElement(); + const auto &obj = lowered_graph->graph().operands().at(index); + const auto frontend_layout = op_seq.getLayout(); + const auto backend_layout = operand_lower_info.layout(); + ir::OperandInfo backend_info{permuteShape(obj.shape(), frontend_layout, backend_layout), + obj.typeInfo()}; + tensor_builder->registerTensorInfo(index, backend_info, backend_layout, + obj.isConstant()); + } + } + } + } + } +} + exec::IExecutor * ExecutorFactory::createLinearExecutor(std::unique_ptr lowered_graph, const compiler::CompilerOptions &options) @@ -107,6 +149,13 @@ ExecutorFactory::createLinearExecutor(std::unique_ptr lowered_ // linearize assert(!lowered_graph->graph().isBuildingPhase()); + // Shape inference. + { + shape_inference::StaticInferer inferer(lowered_graph->graph().operands()); + lowered_graph->op_seqs().iterate( + [&](const ir::OpSequenceIndex &, const ir::OpSequence &op_seq) { inferer.infer(op_seq); }); + } + for (auto &pair : backend_contexts) { pair.second->fixShapes(); @@ -132,6 +181,7 @@ ExecutorFactory::createLinearExecutor(std::unique_ptr lowered_ ***********************/ auto order = Linear::linearize(*lowered_graph); + runTensorRegistration(lowered_graph.get(), order); Linear::dump(*lowered_graph, order); Linear::planTensors(*lowered_graph, order); @@ -210,7 +260,6 @@ exec::IExecutor * ExecutorFactory::createDataflowExecutor(std::unique_ptr lowered_graph, const compiler::CompilerOptions &options, bool parallel) { - auto &graph = lowered_graph->graph(); const auto &backend_contexts = lowered_graph->backend_contexts(); initializeBackendContext(lowered_graph.get()); @@ -220,24 +269,8 @@ ExecutorFactory::createDataflowExecutor(std::unique_ptr lowere pair.second->fixShapes(); } - // Register tensors - graph.operands().iterate([&](const ir::OperandIndex &ind, const ir::Operand &obj) { - const auto lower_info = lowered_graph->getLowerInfo(ind); - for (auto factor : lower_info->def_factors()) - { - auto backend = factor.backend(); - auto tensor_builder = lowered_graph->backend_contexts().at(backend)->tensor_builder; - - assert(!tensor_builder->isRegistered(ind)); - - const auto info = obj.info(); - const auto backend_layout = lower_info->def_factors().getOnlyElement().layout(); - tensor_builder->registerTensorInfo(ind, info, backend_layout, obj.isConstant()); - - // To make this never be deallocated, this is a workaround to use static memory planner - tensor_builder->notifyFirstUse(ind); - } - }); + auto order = Linear::linearize(*lowered_graph); + runTensorRegistration(lowered_graph.get(), order); backend::TensorBuilderSet tensor_builders; for (const auto &e : lowered_graph->backend_contexts()) @@ -245,6 +278,18 @@ ExecutorFactory::createDataflowExecutor(std::unique_ptr lowere tensor_builders.insert(e.second->tensor_builder); } + // To make tensors never be deallocated, this is a workaround to use static memory planner + for (auto &tensor_builder : tensor_builders) + { + lowered_graph->graph().operands().iterate( + [&](const ir::OperandIndex &ind, const ir::Operand &) { + if (tensor_builder->isRegistered(ind)) + { + tensor_builder->notifyFirstUse(ind); + } + }); + } + for (auto &tensor_builder : tensor_builders) { tensor_builder->prepare(); @@ -331,4 +376,4 @@ ExecutorFactory::createDataflowExecutor(std::unique_ptr lowere } } // namespace compiler -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/compiler/ExecutorFactory.h b/runtime/onert/core/src/compiler/ExecutorFactory.h similarity index 84% rename from runtime/neurun/core/src/compiler/ExecutorFactory.h rename to runtime/onert/core/src/compiler/ExecutorFactory.h index 402da566e8b..deba18d5e15 100644 --- a/runtime/neurun/core/src/compiler/ExecutorFactory.h +++ b/runtime/onert/core/src/compiler/ExecutorFactory.h @@ -14,15 +14,15 @@ * limitations under the License. */ -#ifndef __NEURUN_COMPILER_EXECUTOR_FACTORY_H__ -#define __NEURUN_COMPILER_EXECUTOR_FACTORY_H__ +#ifndef __ONERT_COMPILER_EXECUTOR_FACTORY_H__ +#define __ONERT_COMPILER_EXECUTOR_FACTORY_H__ #include #include "exec/IExecutor.h" #include "ir/LoweredGraph.h" -namespace neurun +namespace onert { namespace compiler { @@ -41,6 +41,8 @@ class ExecutorFactory private: static void initializeBackendContext(ir::LoweredGraph *lowered_graph); + static void runTensorRegistration(ir::LoweredGraph *lowered_graph, + const std::vector &order); static exec::IExecutor *createLinearExecutor(std::unique_ptr lowered_graph, const compiler::CompilerOptions &options); static exec::IExecutor *createDataflowExecutor(std::unique_ptr lowered_graph, @@ -55,6 +57,6 @@ class ExecutorFactory }; } // namespace compiler -} // namespace neurun +} // namespace onert -#endif // __NEURUN_COMPILER_EXECUTOR_FACTORY_H__ +#endif // __ONERT_COMPILER_EXECUTOR_FACTORY_H__ diff --git a/runtime/neurun/core/src/compiler/HEScheduler.cc b/runtime/onert/core/src/compiler/HEScheduler.cc similarity index 99% rename from runtime/neurun/core/src/compiler/HEScheduler.cc rename to runtime/onert/core/src/compiler/HEScheduler.cc index fa31d026e78..f9a2649080f 100644 --- a/runtime/neurun/core/src/compiler/HEScheduler.cc +++ b/runtime/onert/core/src/compiler/HEScheduler.cc @@ -27,7 +27,7 @@ #include #include -namespace neurun +namespace onert { namespace compiler @@ -612,4 +612,4 @@ int64_t HEScheduler::predMaxEFT(const backend::Backend *backend, const ir::Opera } // namespace compiler -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/compiler/HEScheduler.h b/runtime/onert/core/src/compiler/HEScheduler.h similarity index 97% rename from runtime/neurun/core/src/compiler/HEScheduler.h rename to runtime/onert/core/src/compiler/HEScheduler.h index b18db2df543..dbd71d4cb8f 100644 --- a/runtime/neurun/core/src/compiler/HEScheduler.h +++ b/runtime/onert/core/src/compiler/HEScheduler.h @@ -20,8 +20,8 @@ * Scheduler */ -#ifndef __NEURUN_COMPILER_H_E_SCHEDULER_H_ -#define __NEURUN_COMPILER_H_E_SCHEDULER_H_ +#ifndef __ONERT_COMPILER_H_E_SCHEDULER_H_ +#define __ONERT_COMPILER_H_E_SCHEDULER_H_ #include "compiler/IScheduler.h" #include "compiler/BackendManager.h" @@ -29,12 +29,12 @@ #include "ir/Graph.h" #include "exec/ExecTime.h" #include "backend/Backend.h" -#include "memory" +#include #include "ir/OperationIndexMap.h" #include #include -namespace neurun +namespace onert { namespace compiler @@ -181,6 +181,6 @@ class HEScheduler : IScheduler } // namespace compiler -} // namespace neurun +} // namespace onert -#endif // __NEURUN_COMPILER_H_E_SCHEDULER_H_ +#endif // __ONERT_COMPILER_H_E_SCHEDULER_H_ diff --git a/runtime/neurun/core/src/compiler/IScheduler.h b/runtime/onert/core/src/compiler/IScheduler.h similarity index 83% rename from runtime/neurun/core/src/compiler/IScheduler.h rename to runtime/onert/core/src/compiler/IScheduler.h index 295627054f0..5e9b9bd3cde 100644 --- a/runtime/neurun/core/src/compiler/IScheduler.h +++ b/runtime/onert/core/src/compiler/IScheduler.h @@ -14,13 +14,13 @@ * limitations under the License. */ -#ifndef __NEURUN_CORE_COMPILER_I_SCHEDULER_H__ -#define __NEURUN_CORE_COMPILER_I_SCHEDULER_H__ +#ifndef __ONERT_CORE_COMPILER_I_SCHEDULER_H__ +#define __ONERT_CORE_COMPILER_I_SCHEDULER_H__ #include "compiler/BackendResolver.h" #include "ir/Graph.h" -namespace neurun +namespace onert { namespace compiler { @@ -33,6 +33,6 @@ struct IScheduler }; } // namespace compiler -} // namespace neurun +} // namespace onert -#endif // __NEURUN_CORE_COMPILER_I_SCHEDULER_H__ +#endif // __ONERT_CORE_COMPILER_I_SCHEDULER_H__ diff --git a/runtime/neurun/core/src/compiler/Linear.cc b/runtime/onert/core/src/compiler/Linear.cc similarity index 74% rename from runtime/neurun/core/src/compiler/Linear.cc rename to runtime/onert/core/src/compiler/Linear.cc index 2ea2fad775c..7c658de95b5 100644 --- a/runtime/neurun/core/src/compiler/Linear.cc +++ b/runtime/onert/core/src/compiler/Linear.cc @@ -25,7 +25,7 @@ #include "backend/Backend.h" #include "util/logging.h" -namespace neurun +namespace onert { namespace compiler { @@ -37,37 +37,37 @@ std::vector Linear::linearize(const ir::LoweredGraph &lower const ir::Graph &graph = lowered_graph.graph(); const ir::OpSequences &op_seqs = lowered_graph.op_seqs(); const ir::Operands &operands = graph.operands(); - // op_seqs can't access a op_seq by an operand so that input_to_subgs can offer it - std::unordered_map> input_to_subgs; + // op_seqs can't access a op_seq by an operand so that input_to_op_seqs can offer it + std::unordered_map> input_to_op_seqs; // Get the relations between input/op_seq to be used for dfs-post-iter // - // [0] # input -> _input_to_op_seqes[0] = {SUBG0} + // [0] # input -> _input_to_op_seqs[0] = {OP_SEQS0} // | - // [SUBG0] + // [OP_SEQS0] // | - // [1]-----. # input -> _input_to_op_seqes[1] = {SUBG1, SUBG2} - // | | - // [SUBG1] [SUBG2] - // | | - // [2] [3] # input -> _input_to_op_seqes[2] = {SUBG3} - // \ / # input -> _input_to_op_seqes[3] = {SUBG3} - // [SUBG3] - // | - // [4] - op_seqs.iterate([&](const ir::OpSequenceIndex &op_seq_idx, const ir::OpSequence &subg) { - for (auto input : subg.getInputs()) + // [1]---------. # input -> _input_to_op_seqs[1] = {OP_SEQS1, OP_SEQS2} + // | | + // [OP_SEQS1] [OP_SEQS2] + // | | + // [2] [3] # input -> _input_to_op_seqs[2] = {OP_SEQS3} + // \ / # input -> _input_to_op_seqs[3] = {OP_SEQS3} + // [OP_SEQS3] + // | + // [4] + op_seqs.iterate([&](const ir::OpSequenceIndex &op_seq_idx, const ir::OpSequence &op_seq) { + for (auto input : op_seq.getInputs()) { // only valid_inputs const auto &operand = operands.at(input); if (operand.isConstant()) continue; - auto it = input_to_subgs.find(input); - if (it == input_to_subgs.end()) + auto it = input_to_op_seqs.find(input); + if (it == input_to_op_seqs.end()) { std::list list{op_seq_idx}; - input_to_subgs[input] = list; + input_to_op_seqs[input] = list; } else { @@ -81,22 +81,22 @@ std::vector Linear::linearize(const ir::LoweredGraph &lower [&](const ir::OpSequenceIndex &index, const ir::OpSequence &) { visited[index] = false; }); std::function dfs_recursive = - [&](const ir::OpSequenceIndex &index, const ir::OpSequence &subg) -> void { + [&](const ir::OpSequenceIndex &index, const ir::OpSequence &op_seq) -> void { if (visited[index]) return; visited[index] = true; // The outputs should be not constants - for (auto output : subg.getOutputs()) + for (auto output : op_seq.getOutputs()) { - const auto it = input_to_subgs.find(output); - if (it != input_to_subgs.end()) + const auto it = input_to_op_seqs.find(output); + if (it != input_to_op_seqs.end()) { const auto &op_seq_index_list = it->second; for (const auto &index : op_seq_index_list) { - auto &subg = op_seqs.at(index); - dfs_recursive(index, subg); + auto &op_seq = op_seqs.at(index); + dfs_recursive(index, op_seq); } } } @@ -121,14 +121,14 @@ void Linear::dump(const ir::LoweredGraph &lowered_graph, const std::vector &order) { { - const auto &toString = [](const neurun::backend::Backend *backend) { + const auto &toString = [](const onert::backend::Backend *backend) { assert(backend); std::string str; str += backend->config()->id(); return "{" + str + "}"; }; - VERBOSE(Linear) << "Final SubgraphSequence" << std::endl; + VERBOSE(Linear) << "Final OpSequence" << std::endl; for (const auto index : order) { @@ -150,51 +150,15 @@ void Linear::planTensors(const ir::LoweredGraph &lowered_graph, ir::OperandIndexMap def_map; ir::OperandIndexSequence constants; - for (const auto index : order) - { - const auto &op_seq = lowered_graph.op_seqs().at(index); - const auto backend = lowered_graph.getLowerInfo(index)->backend(); - const auto tensor_register = lowered_graph.backend_contexts().at(backend)->tensor_register; - auto tensor_builder = lowered_graph.backend_contexts().at(backend)->tensor_builder; - if (tensor_register) - { - // Custom registration - tensor_register->registerTensors(op_seq, lowered_graph.getLowerInfo()); - } - else - { - // Default registration - for (const auto elem : op_seq) - { - const auto &op = *elem.node; - for (const auto &index : op.getInputs() + op.getOutputs()) - { - if (!tensor_builder->isRegistered(index)) - { - const auto &operand_lower_info = - lowered_graph.getLowerInfo(index)->def_factors().getOnlyElement(); - const auto &obj = graph.operands().at(index); - const auto frontend_layout = op_seq.getLayout(); - const auto backend_layout = operand_lower_info.layout(); - ir::OperandInfo backend_info{permuteShape(obj.shape(), frontend_layout, backend_layout), - obj.typeInfo()}; - tensor_builder->registerTensorInfo(index, backend_info, backend_layout, - obj.isConstant()); - } - } - } - } - } - // Prepare scanning graph.operands().iterate([&](const ir::OperandIndex &ind, const ir::Operand &obj) { const auto lower_info = lowered_graph.getLowerInfo(ind); - // TODO Remove if neurun doesn't support anymore such as + // TODO Remove if onert doesn't support anymore such as // GeneratedTests.reshape_quant8_weights_as_inputs if (lower_info->def_factors().size() == 0 && lower_info->use_factors().size() == 0 && !graph.getInputs().contains(ind)) { - VERBOSE(LINEAR) << "Operand #" << ind.value() << " will be not used. no more process." + VERBOSE(LINEAR) << "Operand #" << ind.value() << " will not be used. no more process." << std::endl; return; } @@ -313,4 +277,4 @@ void Linear::planTensors(const ir::LoweredGraph &lowered_graph, } } // namespace compiler -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/compiler/Linear.h b/runtime/onert/core/src/compiler/Linear.h similarity index 87% rename from runtime/neurun/core/src/compiler/Linear.h rename to runtime/onert/core/src/compiler/Linear.h index 0cd425a2c3b..faeff77f3a9 100644 --- a/runtime/neurun/core/src/compiler/Linear.h +++ b/runtime/onert/core/src/compiler/Linear.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_COMPILER_LINEAR_H__ -#define __NEURUN_COMPILER_LINEAR_H__ +#ifndef __ONERT_COMPILER_LINEAR_H__ +#define __ONERT_COMPILER_LINEAR_H__ #include #include @@ -25,15 +25,15 @@ #include "backend/ITensorBuilder.h" #include "ir/LoweredGraph.h" -namespace neurun +namespace onert { namespace ir { struct OperationVisitor; } // namespace ir -} // namespace neurun +} // namespace onert -namespace neurun +namespace onert { namespace compiler { @@ -49,6 +49,6 @@ class Linear }; } // namespace compiler -} // namespace neurun +} // namespace onert -#endif // __NEURUN_COMPILER_LINEAR_H__ +#endif // __ONERT_COMPILER_LINEAR_H__ diff --git a/runtime/neurun/core/src/compiler/ManualScheduler.cc b/runtime/onert/core/src/compiler/ManualScheduler.cc similarity index 98% rename from runtime/neurun/core/src/compiler/ManualScheduler.cc rename to runtime/onert/core/src/compiler/ManualScheduler.cc index 8ad46701cc8..1937bea5a4a 100644 --- a/runtime/neurun/core/src/compiler/ManualScheduler.cc +++ b/runtime/onert/core/src/compiler/ManualScheduler.cc @@ -24,7 +24,7 @@ #include "util/logging.h" #include "misc/string_helpers.h" -namespace neurun +namespace onert { namespace compiler { @@ -96,4 +96,4 @@ std::unique_ptr ManualScheduler::schedule(const ir::Graph &grap } } // namespace compiler -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/compiler/ManualScheduler.h b/runtime/onert/core/src/compiler/ManualScheduler.h similarity index 83% rename from runtime/neurun/core/src/compiler/ManualScheduler.h rename to runtime/onert/core/src/compiler/ManualScheduler.h index bbcd94c18f9..961dd14b251 100644 --- a/runtime/neurun/core/src/compiler/ManualScheduler.h +++ b/runtime/onert/core/src/compiler/ManualScheduler.h @@ -14,13 +14,13 @@ * limitations under the License. */ -#ifndef __NEURUN_CORE_COMPILER_MANUAL_SCHEDULER_H__ -#define __NEURUN_CORE_COMPILER_MANUAL_SCHEDULER_H__ +#ifndef __ONERT_CORE_COMPILER_MANUAL_SCHEDULER_H__ +#define __ONERT_CORE_COMPILER_MANUAL_SCHEDULER_H__ #include "IScheduler.h" #include "compiler/Compiler.h" -namespace neurun +namespace onert { namespace compiler { @@ -36,6 +36,6 @@ class ManualScheduler : public IScheduler }; } // namespace compiler -} // namespace neurun +} // namespace onert -#endif // __NEURUN_CORE_COMPILER_MANUAL_SCHEDULER_H__ +#endif // __ONERT_CORE_COMPILER_MANUAL_SCHEDULER_H__ diff --git a/runtime/neurun/core/src/compiler/OperandContext.cc b/runtime/onert/core/src/compiler/OperandContext.cc similarity index 96% rename from runtime/neurun/core/src/compiler/OperandContext.cc rename to runtime/onert/core/src/compiler/OperandContext.cc index c8c94093f1c..cce555e336d 100644 --- a/runtime/neurun/core/src/compiler/OperandContext.cc +++ b/runtime/onert/core/src/compiler/OperandContext.cc @@ -18,7 +18,7 @@ #include -namespace neurun +namespace onert { namespace compiler { @@ -42,4 +42,4 @@ void OperandContext::iterate( } } // namespace compiler -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/compiler/OperandContext.h b/runtime/onert/core/src/compiler/OperandContext.h similarity index 88% rename from runtime/neurun/core/src/compiler/OperandContext.h rename to runtime/onert/core/src/compiler/OperandContext.h index cba8d2dd4c9..390b376fe4a 100644 --- a/runtime/neurun/core/src/compiler/OperandContext.h +++ b/runtime/onert/core/src/compiler/OperandContext.h @@ -14,15 +14,15 @@ * limitations under the License. */ -#ifndef __NEURUN_COMPILER_OPERAND_CONTEXT_H__ -#define __NEURUN_COMPILER_OPERAND_CONTEXT_H__ +#ifndef __ONERT_COMPILER_OPERAND_CONTEXT_H__ +#define __ONERT_COMPILER_OPERAND_CONTEXT_H__ #include "backend/ITensor.h" #include "ir/OperandIndexMap.h" #include #include -namespace neurun +namespace onert { namespace compiler { @@ -50,6 +50,6 @@ class OperandContext }; } // namespace compiler -} // namespace neurun +} // namespace onert -#endif // __NEURUN_COMPILER_OPERAND_CONTEXT_H__ +#endif // __ONERT_COMPILER_OPERAND_CONTEXT_H__ diff --git a/runtime/neurun/core/src/compiler/OperationValidator.cc b/runtime/onert/core/src/compiler/OperationValidator.cc similarity index 94% rename from runtime/neurun/core/src/compiler/OperationValidator.cc rename to runtime/onert/core/src/compiler/OperationValidator.cc index 0e6af9bc959..b921e323644 100644 --- a/runtime/neurun/core/src/compiler/OperationValidator.cc +++ b/runtime/onert/core/src/compiler/OperationValidator.cc @@ -24,7 +24,7 @@ #include "util/logging.h" #include "util/Utils.h" -namespace neurun +namespace onert { namespace compiler { @@ -43,6 +43,17 @@ void OperationValidator::operator()() [&](const ir::OperationIndex &, const ir::Operation &node) { node.accept(*this); }); } +void OperationValidator::visit(const ir::operation::Abs &node) +{ + const auto output_index{node.getOutputs().at(0)}; + const auto input_index{node.getInputs().at(0)}; + + UNUSED_RELEASE(output_index); + UNUSED_RELEASE(input_index); + + assert(_ctx.at(output_index).shape() == _ctx.at(input_index).shape()); +} + void OperationValidator::visit(const ir::operation::AvgPool2D &node) { const auto ofm_index{node.getOutputs().at(0)}; @@ -67,6 +78,7 @@ void OperationValidator::visit(const ir::operation::BatchToSpaceND &node) UNUSED_RELEASE(input_shape); UNUSED_RELEASE(output_shape); + UNUSED_RELEASE(block_size_index); // All assertions as per NNAPI specification. assert(_ctx.at(ifm_index).shape().rank() == 4); @@ -334,6 +346,8 @@ void OperationValidator::visit(const ir::operation::SpaceToBatchND &node) UNUSED_RELEASE(input_shape); UNUSED_RELEASE(output_shape); + UNUSED_RELEASE(block_size_index); + UNUSED_RELEASE(paddings_index); // All assertions as per NNAPI specification. assert(_ctx.at(ifm_index).shape().rank() == 4); @@ -992,5 +1006,63 @@ void OperationValidator::visit(const ir::operation::Max &node) assert(_ctx.at(lhs_index).typeInfo().type() == _ctx.at(output_index).typeInfo().type()); } +void OperationValidator::visit(const ir::operation::StridedSlice &node) +{ + const auto output_index{node.getOutputs().at(0)}; + const auto input_index{node.getInputs().at(ir::operation::StridedSlice::Input::INPUT)}; + const auto starts_index{node.getInputs().at(ir::operation::StridedSlice::Input::STARTS)}; + const auto ends_index{node.getInputs().at(ir::operation::StridedSlice::Input::ENDS)}; + const auto strides_index{node.getInputs().at(ir::operation::StridedSlice::Input::STRIDES)}; + + UNUSED_RELEASE(output_index); + UNUSED_RELEASE(input_index); + UNUSED_RELEASE(starts_index); + UNUSED_RELEASE(ends_index); + UNUSED_RELEASE(strides_index); + + assert(_ctx.at(output_index).typeInfo().type() == _ctx.at(input_index).typeInfo().type()); + assert(_ctx.at(input_index).shape().rank() <= 4); +} + +void OperationValidator::visit(const ir::operation::Split &node) +{ + const auto input_index{node.getInputs().at(ir::operation::Split::Input::INPUT)}; + const auto &num_splits = node.param().num_splits; + const auto &input_rank = node.param().rank; + const auto &axis = node.param().axis < 0 ? node.param().axis + input_rank : node.param().axis; + + UNUSED_RELEASE(input_index); + UNUSED_RELEASE(num_splits); + UNUSED_RELEASE(input_rank); + UNUSED_RELEASE(axis); + + assert(num_splits > 0 && num_splits <= 0xFFFF); + assert(axis >= 0 && axis < input_rank); + assert(_ctx.at(input_index).shape().dim(axis) % num_splits == 0); + assert(node.getOutputs().size() == static_cast(num_splits)); +} + +void OperationValidator::visit(const ir::operation::Sin &node) +{ + const auto output_index{node.getOutputs().at(0)}; + const auto input_index{node.getInputs().at(0)}; + + UNUSED_RELEASE(output_index); + UNUSED_RELEASE(input_index); + + assert(_ctx.at(output_index).shape() == _ctx.at(input_index).shape()); +} + +void OperationValidator::visit(const ir::operation::RSQRT &node) +{ + const auto output_index{node.getOutputs().at(0)}; + const auto input_index{node.getInputs().at(0)}; + + UNUSED_RELEASE(output_index); + UNUSED_RELEASE(input_index); + + assert(_ctx.at(output_index).shape() == _ctx.at(input_index).shape()); +} + } // namespace compiler -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/compiler/OperationValidator.h b/runtime/onert/core/src/compiler/OperationValidator.h similarity index 84% rename from runtime/neurun/core/src/compiler/OperationValidator.h rename to runtime/onert/core/src/compiler/OperationValidator.h index 4d18af97f44..84efa10944c 100644 --- a/runtime/neurun/core/src/compiler/OperationValidator.h +++ b/runtime/onert/core/src/compiler/OperationValidator.h @@ -14,22 +14,22 @@ * limitations under the License. */ -#ifndef __NEURUN_COMPILER_OPERATION_VALIDATOR_H__ -#define __NEURUN_COMPILER_OPERATION_VALIDATOR_H__ +#ifndef __ONERT_COMPILER_OPERATION_VALIDATOR_H__ +#define __ONERT_COMPILER_OPERATION_VALIDATOR_H__ #include "ir/Layout.h" #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { class Graph; class Operands; } // namespace ir -} // namespace neurun +} // namespace onert -namespace neurun +namespace onert { namespace compiler { @@ -44,6 +44,7 @@ class OperationValidator : public ir::OperationVisitor void operator()(); public: + void visit(const ir::operation::Abs &node) override; void visit(const ir::operation::AvgPool2D &node) override; void visit(const ir::operation::BatchToSpaceND &node) override; void visit(const ir::operation::Cast &node) override; @@ -73,6 +74,10 @@ class OperationValidator : public ir::OperationVisitor void visit(const ir::operation::Pad &node) override; void visit(const ir::operation::Min &node) override; void visit(const ir::operation::Max &node) override; + void visit(const ir::operation::StridedSlice &node) override; + void visit(const ir::operation::Split &node) override; + void visit(const ir::operation::Sin &node) override; + void visit(const ir::operation::RSQRT &node) override; private: // TODO Remove _ctx field @@ -82,6 +87,6 @@ class OperationValidator : public ir::OperationVisitor }; } // namespace compiler -} // namespace neurun +} // namespace onert -#endif // __NEURUN_COMPILER_OPERATION_VALIDATOR_H__ +#endif // __ONERT_COMPILER_OPERATION_VALIDATOR_H__ diff --git a/runtime/neurun/core/src/compiler/ParamChecker.cc b/runtime/onert/core/src/compiler/ParamChecker.cc similarity index 95% rename from runtime/neurun/core/src/compiler/ParamChecker.cc rename to runtime/onert/core/src/compiler/ParamChecker.cc index bf172b53f38..c4f80f08719 100644 --- a/runtime/neurun/core/src/compiler/ParamChecker.cc +++ b/runtime/onert/core/src/compiler/ParamChecker.cc @@ -18,7 +18,7 @@ #include "ir/Graph.h" -namespace neurun +namespace onert { namespace compiler { @@ -30,4 +30,4 @@ void ParamChecker::operator()() } } // namespace compiler -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/compiler/ParamChecker.h b/runtime/onert/core/src/compiler/ParamChecker.h similarity index 88% rename from runtime/neurun/core/src/compiler/ParamChecker.h rename to runtime/onert/core/src/compiler/ParamChecker.h index 7e88ff18533..61429d521f4 100644 --- a/runtime/neurun/core/src/compiler/ParamChecker.h +++ b/runtime/onert/core/src/compiler/ParamChecker.h @@ -20,20 +20,20 @@ * operations' parameters are compilable at machine independent phase\n * ex) Check param is constant */ -#ifndef __NEURUN_COMPILER_PARAM_CHECKER_H__ -#define __NEURUN_COMPILER_PARAM_CHECKER_H__ +#ifndef __ONERT_COMPILER_PARAM_CHECKER_H__ +#define __ONERT_COMPILER_PARAM_CHECKER_H__ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { class Graph; } // namespace ir -} // namespace neurun +} // namespace onert -namespace neurun +namespace onert { namespace compiler { @@ -68,6 +68,6 @@ class ParamChecker : public ir::OperationVisitor }; } // namespace compiler -} // namespace neurun +} // namespace onert -#endif // __NEURUN_COMPILER_OPERATION_VALIDATOR_H__ +#endif // __ONERT_COMPILER_OPERATION_VALIDATOR_H__ diff --git a/runtime/neurun/core/src/dumper/dot/DotBuilder.cc b/runtime/onert/core/src/dumper/dot/DotBuilder.cc similarity index 82% rename from runtime/neurun/core/src/dumper/dot/DotBuilder.cc rename to runtime/onert/core/src/dumper/dot/DotBuilder.cc index 76d3cab6454..2a3a4af2241 100644 --- a/runtime/neurun/core/src/dumper/dot/DotBuilder.cc +++ b/runtime/onert/core/src/dumper/dot/DotBuilder.cc @@ -16,7 +16,7 @@ #include "DotBuilder.h" -namespace neurun +namespace onert { namespace dumper { @@ -35,18 +35,18 @@ void DotBuilder::update(const Node &node_info) } } -void DotBuilder::addSubgraph(const DotSubgraphInfo &subgraph_info) +void DotBuilder::addOpSequence(const DotOpSequenceInfo &op_sequence_info) { - _dot << "subgraph cluster_" << subgraph_info.index().value() << " {\n"; - _dot << " label=\"" << subgraph_info.label() << "\";\n"; + _dot << "op_sequence cluster_" << op_sequence_info.index().value() << " {\n"; + _dot << " label=\"" << op_sequence_info.label() << "\";\n"; _dot << " style=filled;\n"; _dot << " color=lightgrey;\n"; _dot << " "; - for (auto op : subgraph_info.operations()) + for (auto op : op_sequence_info.operations()) { _dot << "operation" << op.value() << "; "; } - for (auto op : subgraph_info.operands()) + for (auto op : op_sequence_info.operands()) { _dot << "operand" << op.value() << "; "; } @@ -80,4 +80,4 @@ void DotBuilder::addEdge(const Node &node1, const Node &node2) } // namespace dot } // namespace dumper -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/dumper/dot/DotBuilder.h b/runtime/onert/core/src/dumper/dot/DotBuilder.h similarity index 76% rename from runtime/neurun/core/src/dumper/dot/DotBuilder.h rename to runtime/onert/core/src/dumper/dot/DotBuilder.h index c04f6bc52cb..24a76533d86 100644 --- a/runtime/neurun/core/src/dumper/dot/DotBuilder.h +++ b/runtime/onert/core/src/dumper/dot/DotBuilder.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_DUMPER_DOT_DOT_BUILDER_H__ -#define __NEURUN_DUMPER_DOT_DOT_BUILDER_H__ +#ifndef __ONERT_DUMPER_DOT_DOT_BUILDER_H__ +#define __ONERT_DUMPER_DOT_DOT_BUILDER_H__ #include @@ -25,12 +25,12 @@ #include "OperationNode.h" #include "OperandNode.h" -#include "DotSubgraphInfo.h" +#include "DotOpSequenceInfo.h" -using Operation = neurun::ir::Operation; -using Object = neurun::ir::Operand; +using Operation = onert::ir::Operation; +using Object = onert::ir::Operand; -namespace neurun +namespace onert { namespace dumper { @@ -44,7 +44,7 @@ class DotBuilder public: void update(const Node &dotinfo); - void addSubgraph(const DotSubgraphInfo &subgraph_info); + void addOpSequence(const DotOpSequenceInfo &op_sequence_info); void writeDot(std::ostream &os); @@ -57,6 +57,6 @@ class DotBuilder } // namespace dot } // namespace dumper -} // namespace neurun +} // namespace onert -#endif // __NEURUN_DUMPER_DOT_DOT_BUILDER_H__ +#endif // __ONERT_DUMPER_DOT_DOT_BUILDER_H__ diff --git a/runtime/neurun/core/src/dumper/dot/DotDumper.cc b/runtime/onert/core/src/dumper/dot/DotDumper.cc similarity index 92% rename from runtime/neurun/core/src/dumper/dot/DotDumper.cc rename to runtime/onert/core/src/dumper/dot/DotDumper.cc index e0025d05710..9bd8ed0ef97 100644 --- a/runtime/neurun/core/src/dumper/dot/DotDumper.cc +++ b/runtime/onert/core/src/dumper/dot/DotDumper.cc @@ -19,14 +19,14 @@ #include "DotDumper.h" #include "DotBuilder.h" -#include "DotSubgraphInfo.h" +#include "DotOpSequenceInfo.h" #include "ir/OpSequence.h" #include "ir/OperationIndexMap.h" #include "backend/Backend.h" #include "backend/IConfig.h" #include "compiler/BackendManager.h" -namespace neurun +namespace onert { namespace dumper { @@ -40,7 +40,7 @@ void DotDumper::dump(const std::string &tag) return; } - neurun::dumper::dot::DotBuilder dot_builder; + onert::dumper::dot::DotBuilder dot_builder; auto &operations = _graph.operations(); auto &operands = _graph.operands(); @@ -53,7 +53,7 @@ void DotDumper::dump(const std::string &tag) for (auto output : op.getOutputs()) { - using neurun::dumper::dot::Operand; + using onert::dumper::dot::Operand; auto child = std::make_shared(output, Operand::Type::MODEL_OUTPUT); node->addEdge(child); } @@ -105,7 +105,7 @@ void DotDumper::dump(const std::string &tag) shown_operand_set.add(index); auto type = [&]() { - using neurun::dumper::dot::Operand; + using onert::dumper::dot::Operand; if (_graph.getInputs().contains(index)) return Operand::Type::MODEL_INPUT; if (_graph.getOutputs().contains(index)) @@ -155,10 +155,10 @@ void DotDumper::dump(const std::string &tag) auto fillcolor = backend_to_fillcolor(lower_info->backend()); std::string label = std::to_string(index.value()) + " [" + lower_info->backend()->config()->id() + "]"; - DotSubgraphInfo subgraph_info{index, op_seq, shown_operand_set}; - subgraph_info.label(label); - subgraph_info.fillcolor(fillcolor); - dot_builder.addSubgraph(subgraph_info); + DotOpSequenceInfo op_sequence_info{index, op_seq, shown_operand_set}; + op_sequence_info.label(label); + op_sequence_info.fillcolor(fillcolor); + dot_builder.addOpSequence(op_sequence_info); // Set fillcolor of all operations in the op_seq for (const auto &op : op_seq.operations()) @@ -196,4 +196,4 @@ void DotDumper::dump(const std::string &tag) } // namespace dot } // namespace dumper -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/dumper/dot/DotDumper.h b/runtime/onert/core/src/dumper/dot/DotDumper.h similarity index 90% rename from runtime/neurun/core/src/dumper/dot/DotDumper.h rename to runtime/onert/core/src/dumper/dot/DotDumper.h index a9a219a985f..668785a8118 100644 --- a/runtime/neurun/core/src/dumper/dot/DotDumper.h +++ b/runtime/onert/core/src/dumper/dot/DotDumper.h @@ -17,10 +17,10 @@ #include "ir/Graph.h" #include "ir/LoweredGraph.h" -#ifndef __NEURUN_DUMPER_DOT_DOT_DUMPER_H__ -#define __NEURUN_DUMPER_DOT_DOT_DUMPER_H__ +#ifndef __ONERT_DUMPER_DOT_DOT_DUMPER_H__ +#define __ONERT_DUMPER_DOT_DOT_DUMPER_H__ -namespace neurun +namespace onert { namespace dumper { @@ -64,6 +64,6 @@ class DotDumper } // namespace dot } // namespace dumper -} // namespace neurun +} // namespace onert -#endif // __NEURUN_DUMPER_DOT_DOT_DUMPER_H__ +#endif // __ONERT_DUMPER_DOT_DOT_DUMPER_H__ diff --git a/runtime/neurun/core/src/dumper/dot/DotSubgraphInfo.cc b/runtime/onert/core/src/dumper/dot/DotOpSequenceInfo.cc similarity index 83% rename from runtime/neurun/core/src/dumper/dot/DotSubgraphInfo.cc rename to runtime/onert/core/src/dumper/dot/DotOpSequenceInfo.cc index aacd59b8f7c..48dafc8341e 100644 --- a/runtime/neurun/core/src/dumper/dot/DotSubgraphInfo.cc +++ b/runtime/onert/core/src/dumper/dot/DotOpSequenceInfo.cc @@ -14,19 +14,19 @@ * limitations under the License. */ -#include "DotSubgraphInfo.h" +#include "DotOpSequenceInfo.h" #include -namespace neurun +namespace onert { namespace dumper { namespace dot { -DotSubgraphInfo::DotSubgraphInfo(const ir::OpSequenceIndex &index, const ir::OpSequence &op_seq, - const util::Set &shown_operands) +DotOpSequenceInfo::DotOpSequenceInfo(const ir::OpSequenceIndex &index, const ir::OpSequence &op_seq, + const util::Set &shown_operands) : _index{index} { for (const auto &element : op_seq.operations()) @@ -53,4 +53,4 @@ DotSubgraphInfo::DotSubgraphInfo(const ir::OpSequenceIndex &index, const ir::OpS } // namespace dot } // namespace dumper -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/dumper/dot/DotSubgraphInfo.h b/runtime/onert/core/src/dumper/dot/DotOpSequenceInfo.h similarity index 79% rename from runtime/neurun/core/src/dumper/dot/DotSubgraphInfo.h rename to runtime/onert/core/src/dumper/dot/DotOpSequenceInfo.h index 248fcf93863..c30626cbf84 100644 --- a/runtime/neurun/core/src/dumper/dot/DotSubgraphInfo.h +++ b/runtime/onert/core/src/dumper/dot/DotOpSequenceInfo.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_CORE_DUMPER_DOT_DOT_SUBGRAPH_INFO_H__ -#define __NEURUN_CORE_DUMPER_DOT_DOT_SUBGRAPH_INFO_H__ +#ifndef __ONERT_CORE_DUMPER_DOT_DOT_SUBGRAPH_INFO_H__ +#define __ONERT_CORE_DUMPER_DOT_DOT_SUBGRAPH_INFO_H__ #include @@ -23,18 +23,18 @@ #include "ir/OpSequence.h" #include "util/Set.h" -namespace neurun +namespace onert { namespace dumper { namespace dot { -class DotSubgraphInfo +class DotOpSequenceInfo { public: - DotSubgraphInfo(const ir::OpSequenceIndex &index, const ir::OpSequence &op_seq, - const util::Set &shown_operands); + DotOpSequenceInfo(const ir::OpSequenceIndex &index, const ir::OpSequence &op_seq, + const util::Set &shown_operands); ir::OpSequenceIndex index() const { return _index; } std::string label() const { return _label; } @@ -54,6 +54,6 @@ class DotSubgraphInfo } // namespace dot } // namespace dumper -} // namespace neurun +} // namespace onert -#endif // __NEURUN_CORE_DUMPER_DOT_DOT_SUBGRAPH_INFO_H__ +#endif // __ONERT_CORE_DUMPER_DOT_DOT_SUBGRAPH_INFO_H__ diff --git a/runtime/neurun/core/src/dumper/dot/Node.cc b/runtime/onert/core/src/dumper/dot/Node.cc similarity index 97% rename from runtime/neurun/core/src/dumper/dot/Node.cc rename to runtime/onert/core/src/dumper/dot/Node.cc index 166f0f40f3a..85d6e67a4e5 100644 --- a/runtime/neurun/core/src/dumper/dot/Node.cc +++ b/runtime/onert/core/src/dumper/dot/Node.cc @@ -16,7 +16,7 @@ #include "Node.h" -namespace neurun +namespace onert { namespace dumper { @@ -53,4 +53,4 @@ std::string Node::getAttribute(const std::string &key) } // namespace dot } // namespace dumper -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/dumper/dot/Node.h b/runtime/onert/core/src/dumper/dot/Node.h similarity index 93% rename from runtime/neurun/core/src/dumper/dot/Node.h rename to runtime/onert/core/src/dumper/dot/Node.h index 364cb08a4d4..a5d1d51a47f 100644 --- a/runtime/neurun/core/src/dumper/dot/Node.h +++ b/runtime/onert/core/src/dumper/dot/Node.h @@ -21,15 +21,15 @@ * */ -#ifndef __NEURUN_DUMPER_DOT_NODE_H__ -#define __NEURUN_DUMPER_DOT_NODE_H__ +#ifndef __ONERT_DUMPER_DOT_NODE_H__ +#define __ONERT_DUMPER_DOT_NODE_H__ #include #include #include #include -namespace neurun +namespace onert { namespace dumper { @@ -51,7 +51,7 @@ enum BGCOLORS : int /** * @brief Class that represents a Node in "dot" format * -*/ + */ class Node { public: @@ -63,55 +63,55 @@ class Node /** * @brief Destroy the Node object * - */ + */ virtual ~Node() = default; /** * @brief Construct a new Node object * * @param id - */ + */ Node(const std::string &id); /** * @brief return id * * @return id - */ + */ std::string id() const { return _id; } /** * @brief return attributes * * @return const reference of attributes object - */ + */ const std::unordered_map &attributes() const { return _attributes; } /** * @brief Store an attribute with key-value pair * * @param[in] key attribute's key * @param[in] val attribute's value that is associated with the key - */ + */ void setAttribute(const std::string &key, const std::string &val); /** * @brief Get the attributte value that is associated with key * * @param[in] key key of the attribute * @return value that is associated with the key - */ + */ std::string getAttribute(const std::string &key); /** * @brief Add an edge in the graph, which is an outgoing edge * * @param[in] dotinfo A node that the new edge will be connected to - */ + */ void addEdge(std::shared_ptr dotinfo) { _children.emplace_back(dotinfo); } /** * @brief Return list of edges * * @return Edges - */ + */ const std::vector> &edges() const { return _children; } private: @@ -122,6 +122,6 @@ class Node } // namespace dot } // namespace dumper -} // namespace neurun +} // namespace onert -#endif // __NEURUN_DUMPER_DOT_NODE_H__ +#endif // __ONERT_DUMPER_DOT_NODE_H__ diff --git a/runtime/neurun/core/src/dumper/dot/OperandNode.cc b/runtime/onert/core/src/dumper/dot/OperandNode.cc similarity index 97% rename from runtime/neurun/core/src/dumper/dot/OperandNode.cc rename to runtime/onert/core/src/dumper/dot/OperandNode.cc index 76d2c704c8d..5a6015ca9d7 100644 --- a/runtime/neurun/core/src/dumper/dot/OperandNode.cc +++ b/runtime/onert/core/src/dumper/dot/OperandNode.cc @@ -20,7 +20,7 @@ #include "ir/Graph.h" #include "ir/operand/LowerInfo.h" -namespace neurun +namespace onert { namespace dumper { @@ -57,4 +57,4 @@ Operand::Operand(const ir::OperandIndex &index, Type type) } // namespace dot } // namespace dumper -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/dumper/dot/OperandNode.h b/runtime/onert/core/src/dumper/dot/OperandNode.h similarity index 89% rename from runtime/neurun/core/src/dumper/dot/OperandNode.h rename to runtime/onert/core/src/dumper/dot/OperandNode.h index 5ebd651b65d..2e7cc5861b5 100644 --- a/runtime/neurun/core/src/dumper/dot/OperandNode.h +++ b/runtime/onert/core/src/dumper/dot/OperandNode.h @@ -21,8 +21,8 @@ * */ -#ifndef __NEURUN_DUMPER_DOT_DOT_OPERAND_INFO_H__ -#define __NEURUN_DUMPER_DOT_DOT_OPERAND_INFO_H__ +#ifndef __ONERT_DUMPER_DOT_DOT_OPERAND_INFO_H__ +#define __ONERT_DUMPER_DOT_DOT_OPERAND_INFO_H__ #include @@ -30,7 +30,7 @@ #include "ir/Operand.h" #include "ir/Index.h" -namespace neurun +namespace onert { namespace dumper { @@ -74,6 +74,6 @@ class Operand : public Node } // namespace dot } // namespace dumper -} // namespace neurun +} // namespace onert -#endif // __NEURUN_DUMPER_DOT_DOT_OPERAND_INFO_H__ +#endif // __ONERT_DUMPER_DOT_DOT_OPERAND_INFO_H__ diff --git a/runtime/neurun/core/src/dumper/dot/OperationNode.cc b/runtime/onert/core/src/dumper/dot/OperationNode.cc similarity index 97% rename from runtime/neurun/core/src/dumper/dot/OperationNode.cc rename to runtime/onert/core/src/dumper/dot/OperationNode.cc index ca870ba05eb..bee137e7c64 100644 --- a/runtime/neurun/core/src/dumper/dot/OperationNode.cc +++ b/runtime/onert/core/src/dumper/dot/OperationNode.cc @@ -22,7 +22,7 @@ #include "backend/IConfig.h" #include "backend/Backend.h" -namespace neurun +namespace onert { namespace dumper { @@ -43,4 +43,4 @@ Operation::Operation(const ir::OperationIndex &index, const ir::Operation &node) } // namespace dot } // namespace dumper -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/dumper/dot/OperationNode.h b/runtime/onert/core/src/dumper/dot/OperationNode.h similarity index 87% rename from runtime/neurun/core/src/dumper/dot/OperationNode.h rename to runtime/onert/core/src/dumper/dot/OperationNode.h index ba0713790b5..74a37d3fbc4 100644 --- a/runtime/neurun/core/src/dumper/dot/OperationNode.h +++ b/runtime/onert/core/src/dumper/dot/OperationNode.h @@ -21,14 +21,14 @@ * */ -#ifndef __NEURUN_DUMPER_DOT_DOT_NODE_INFO_H__ -#define __NEURUN_DUMPER_DOT_DOT_NODE_INFO_H__ +#ifndef __ONERT_DUMPER_DOT_DOT_NODE_INFO_H__ +#define __ONERT_DUMPER_DOT_DOT_NODE_INFO_H__ #include "Node.h" #include "ir/Operation.h" #include "ir/Index.h" -namespace neurun +namespace onert { namespace dumper { @@ -51,12 +51,12 @@ class Operation : public Node * * @param[in] index operation index * @param[in] node operation object - */ + */ Operation(const ir::OperationIndex &index, const ir::Operation &node); }; } // namespace dot } // namespace dumper -} // namespace neurun +} // namespace onert -#endif // __NEURUN_DUMPER_DOT_DOT_NODE_INFO_H__ +#endif // __ONERT_DUMPER_DOT_DOT_NODE_INFO_H__ diff --git a/runtime/neurun/core/src/exec/DataflowExecutor.cc b/runtime/onert/core/src/exec/DataflowExecutor.cc similarity index 86% rename from runtime/neurun/core/src/exec/DataflowExecutor.cc rename to runtime/onert/core/src/exec/DataflowExecutor.cc index 2c7bbba9068..fbd76d3c5df 100644 --- a/runtime/neurun/core/src/exec/DataflowExecutor.cc +++ b/runtime/onert/core/src/exec/DataflowExecutor.cc @@ -20,7 +20,7 @@ #include "util/logging.h" -namespace neurun +namespace onert { namespace exec { @@ -53,8 +53,8 @@ void DataflowExecutor::emplaceToReadyJobs(const uint32_t &id) { auto &job = _waiting_jobs[id]; assert(job != nullptr); - auto &subg = _lowered_graph->op_seqs().at(_job_to_op_seq[job->index()]); - auto rank = calculateRank(subg.operations()); + auto &op_seq = _lowered_graph->op_seqs().at(_job_to_op_seq[job->index()]); + auto rank = calculateRank(op_seq.operations()); _ready_jobs.emplace(rank, std::move(job)); } @@ -87,36 +87,36 @@ DataflowExecutor::DataflowExecutor(std::unique_ptr lowered_gra const auto &op_seqs = _lowered_graph->op_seqs(); // Assign jobs convert OpSequenceIndex to job index(uint32_t) uint32_t next_job_index = 0; - std::unordered_map subgraph_to_job; + std::unordered_map op_seq_to_job; op_seqs.iterate([&](const ir::OpSequenceIndex &op_seq_index, const ir::OpSequence &) { VERBOSE(DataflowExecutor) << "Create a job #" << next_job_index << " with OpSequenceIndex " << op_seq_index.value() << std::endl; _finished_jobs.emplace_back( std::make_unique(next_job_index, _code_map.at(op_seq_index).fn_seq.get())); - subgraph_to_job[op_seq_index] = next_job_index++; + op_seq_to_job[op_seq_index] = next_job_index++; }); _waiting_jobs.resize(next_job_index); _output_info.resize(next_job_index); _initial_input_info.resize(next_job_index, 0); - op_seqs.iterate([&](const ir::OpSequenceIndex &op_seq_index, const ir::OpSequence &subg) { - auto job_index = subgraph_to_job[op_seq_index]; - for (auto output : subg.getOutputs()) + op_seqs.iterate([&](const ir::OpSequenceIndex &op_seq_index, const ir::OpSequence &op_seq) { + auto job_index = op_seq_to_job[op_seq_index]; + for (auto output : op_seq.getOutputs()) { // Update output and input info op_seqs.iterate( [&](const ir::OpSequenceIndex &op_seq_cur_index, const ir::OpSequence &op_seq_cur) { if (op_seq_cur.getInputs().contains(output)) { - auto dep_index = subgraph_to_job[op_seq_cur_index]; + auto dep_index = op_seq_to_job[op_seq_cur_index]; ++_initial_input_info[dep_index]; _output_info[job_index].push_back(dep_index); } }); } }); - for (const auto &s : subgraph_to_job) + for (const auto &s : op_seq_to_job) _job_to_op_seq.emplace(s.second, s.first); _input_info = _initial_input_info; @@ -147,10 +147,10 @@ void DataflowExecutor::executeImpl() auto job_index = job->index(); VERBOSE(DataflowExecutor) << "Run job #" << job_index << std::endl; - auto subgraph_index = _job_to_op_seq[job_index]; - auto op_seq = &_lowered_graph->op_seqs().at(subgraph_index); + auto op_seq_index = _job_to_op_seq[job_index]; + auto op_seq = &_lowered_graph->op_seqs().at(op_seq_index); const backend::Backend *backend = - _lowered_graph->getLowerInfo()->operation.at(subgraph_index)->backend(); + _lowered_graph->getLowerInfo()->operation.at(op_seq_index)->backend(); _subject.notifyJobBegin(this, op_seq, backend); @@ -172,4 +172,4 @@ void DataflowExecutor::executeImpl() } } // namespace exec -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/exec/DataflowExecutor.h b/runtime/onert/core/src/exec/DataflowExecutor.h similarity index 91% rename from runtime/neurun/core/src/exec/DataflowExecutor.h rename to runtime/onert/core/src/exec/DataflowExecutor.h index 4195d239822..b49df438623 100644 --- a/runtime/neurun/core/src/exec/DataflowExecutor.h +++ b/runtime/onert/core/src/exec/DataflowExecutor.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_EXEC_DATAFLOW_EXECUTOR_H__ -#define __NEURUN_EXEC_DATAFLOW_EXECUTOR_H__ +#ifndef __ONERT_EXEC_DATAFLOW_EXECUTOR_H__ +#define __ONERT_EXEC_DATAFLOW_EXECUTOR_H__ #include #include @@ -25,11 +25,11 @@ #include "Job.h" #include "ir/OperandIndexSequence.h" #include "ir/Index.h" -#include "memory" +#include #include "exec/ExecutorBase.h" #include "compiler/CodeMap.h" -namespace neurun +namespace onert { namespace exec { @@ -47,7 +47,7 @@ class DataflowExecutor : public ExecutorBase * * @param lowered_graph LoweredGraph object * @param tensor_builders Tensor builders that are currently used - * @param code_map Subgraph and its code map + * @param code_map OpSequence and its code map */ DataflowExecutor(std::unique_ptr lowered_graph, const backend::TensorBuilderSet &tensor_builders, compiler::CodeMap &&code_map); @@ -91,6 +91,6 @@ class DataflowExecutor : public ExecutorBase }; } // namespace exec -} // namespace neurun +} // namespace onert -#endif // __NEURUN_EXEC_DATAFLOW_EXECUTOR_H__ +#endif // __ONERT_EXEC_DATAFLOW_EXECUTOR_H__ diff --git a/runtime/neurun/core/src/exec/ExecTime.cc b/runtime/onert/core/src/exec/ExecTime.cc similarity index 99% rename from runtime/neurun/core/src/exec/ExecTime.cc rename to runtime/onert/core/src/exec/ExecTime.cc index 37ac4378406..6bf2744a95f 100644 --- a/runtime/neurun/core/src/exec/ExecTime.cc +++ b/runtime/onert/core/src/exec/ExecTime.cc @@ -21,7 +21,7 @@ #include #include -namespace neurun +namespace onert { namespace exec { @@ -134,4 +134,4 @@ int64_t ExecTime::getPermuteTime(const backend::Backend *from_backend, } } // namespace exec -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/exec/Execution.cc b/runtime/onert/core/src/exec/Execution.cc similarity index 99% rename from runtime/neurun/core/src/exec/Execution.cc rename to runtime/onert/core/src/exec/Execution.cc index b47d642f702..9c66e51e410 100644 --- a/runtime/neurun/core/src/exec/Execution.cc +++ b/runtime/onert/core/src/exec/Execution.cc @@ -18,7 +18,7 @@ #include "util/logging.h" -namespace neurun +namespace onert { namespace exec { @@ -128,4 +128,4 @@ void Execution::waitFinish() bool Execution::isFinished(void) const { return finished; } } // namespace exec -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/exec/ExecutionObservee.cc b/runtime/onert/core/src/exec/ExecutionObservee.cc similarity index 97% rename from runtime/neurun/core/src/exec/ExecutionObservee.cc rename to runtime/onert/core/src/exec/ExecutionObservee.cc index 3b342d703a0..ddb1fb6a0a4 100644 --- a/runtime/neurun/core/src/exec/ExecutionObservee.cc +++ b/runtime/onert/core/src/exec/ExecutionObservee.cc @@ -16,7 +16,7 @@ #include "ExecutionObservee.h" -namespace neurun +namespace onert { namespace exec { @@ -61,4 +61,4 @@ void ExecutionObservee::notifyJobEnd(IExecutor *executor, const ir::OpSequence * } } // namespace exec -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/exec/ExecutionObservee.h b/runtime/onert/core/src/exec/ExecutionObservee.h similarity index 88% rename from runtime/neurun/core/src/exec/ExecutionObservee.h rename to runtime/onert/core/src/exec/ExecutionObservee.h index dafeef55b09..49d409a3a48 100644 --- a/runtime/neurun/core/src/exec/ExecutionObservee.h +++ b/runtime/onert/core/src/exec/ExecutionObservee.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_EXEC_EXECUTION_OBSERVEE_H__ -#define __NEURUN_EXEC_EXECUTION_OBSERVEE_H__ +#ifndef __ONERT_EXEC_EXECUTION_OBSERVEE_H__ +#define __ONERT_EXEC_EXECUTION_OBSERVEE_H__ #include #include "exec/ExecutionObservers.h" -namespace neurun +namespace onert { namespace exec { @@ -51,6 +51,6 @@ class ExecutionObservee }; } // namespace exec -} // namespace neurun +} // namespace onert -#endif // __NEURUN_EXEC_EXECUTION_OBSERVEE__ +#endif // __ONERT_EXEC_EXECUTION_OBSERVEE__ diff --git a/runtime/neurun/core/src/exec/ExecutionObservers.cc b/runtime/onert/core/src/exec/ExecutionObservers.cc similarity index 91% rename from runtime/neurun/core/src/exec/ExecutionObservers.cc rename to runtime/onert/core/src/exec/ExecutionObservers.cc index b09ba1eb7f2..e8fcafa2b51 100644 --- a/runtime/neurun/core/src/exec/ExecutionObservers.cc +++ b/runtime/onert/core/src/exec/ExecutionObservers.cc @@ -24,14 +24,14 @@ #include "misc/polymorphic_downcast.h" #include "ir/OpSequence.h" -namespace neurun +namespace onert { namespace exec { -void ProfileObserver::handleBegin(neurun::exec::IExecutor *, const ir::OpSequence *, - const neurun::backend::Backend *backend) +void ProfileObserver::handleBegin(onert::exec::IExecutor *, const ir::OpSequence *, + const onert::backend::Backend *backend) { _timer = backend->config()->timer(); if (_timer == nullptr) @@ -90,7 +90,7 @@ void ChromeTracingObserver::handleBegin(IExecutor *, const ir::OpSequence *op_se { std::string backend_id = backend->config()->id(); _collector.onEvent( - EventCollector::Event{EventCollector::Edge::BEGIN, backend_id, subgraphTag(op_seq)}); + EventCollector::Event{EventCollector::Edge::BEGIN, backend_id, opSequenceTag(op_seq)}); } void ChromeTracingObserver::handleEnd(IExecutor *, const ir::OpSequence *op_seq, @@ -98,7 +98,7 @@ void ChromeTracingObserver::handleEnd(IExecutor *, const ir::OpSequence *op_seq, { std::string backend_id = backend->config()->id(); _collector.onEvent( - EventCollector::Event{EventCollector::Edge::END, backend_id, subgraphTag(op_seq)}); + EventCollector::Event{EventCollector::Edge::END, backend_id, opSequenceTag(op_seq)}); } void ChromeTracingObserver::handleEnd(IExecutor *) @@ -106,7 +106,7 @@ void ChromeTracingObserver::handleEnd(IExecutor *) _collector.onEvent(EventCollector::Event{EventCollector::Edge::END, "runtime", "Graph"}); } -std::string ChromeTracingObserver::subgraphTag(const ir::OpSequence *op_seq) +std::string ChromeTracingObserver::opSequenceTag(const ir::OpSequence *op_seq) { if (op_seq->size() == 0) return "Empty OpSequence"; @@ -123,4 +123,4 @@ std::string ChromeTracingObserver::subgraphTag(const ir::OpSequence *op_seq) } // namespace exec -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/exec/ExecutorBase.cc b/runtime/onert/core/src/exec/ExecutorBase.cc similarity index 93% rename from runtime/neurun/core/src/exec/ExecutorBase.cc rename to runtime/onert/core/src/exec/ExecutorBase.cc index 96a48b79d7a..dd7e84af854 100644 --- a/runtime/neurun/core/src/exec/ExecutorBase.cc +++ b/runtime/onert/core/src/exec/ExecutorBase.cc @@ -17,7 +17,7 @@ #include "ExecutorBase.h" #include "util/logging.h" -namespace neurun +namespace onert { namespace exec { @@ -26,7 +26,7 @@ ExecutorBase::ExecutorBase(std::unique_ptr &&lowered_graph, const backend::TensorBuilderSet &tensor_builders) : _lowered_graph{std::move(lowered_graph)}, _graph{_lowered_graph->graph()}, _mutex() { - auto build_itensor_list = [&](const neurun::ir::OperandIndexSequence &ind_seq) { + auto build_itensor_list = [&](const onert::ir::OperandIndexSequence &ind_seq) { std::vector> list; for (auto ind : ind_seq) { @@ -135,7 +135,7 @@ void ExecutorBase::execute(const IODescription &desc) sources.at(n) = source(input_index, input.info.typeInfo(), input.buffer, input.size, input.layout); - auto setter = [&](::neurun::backend::ITensor &tensor) { sources.at(n)->push(tensor); }; + auto setter = [&](::onert::backend::ITensor &tensor) { sources.at(n)->push(tensor); }; _input_tensors[n]->access(setter); } @@ -155,12 +155,11 @@ void ExecutorBase::execute(const IODescription &desc) sinks.at(n) = sink(output_index, output.info.typeInfo(), output.buffer, output.size, output.layout); - auto getter = [&](::neurun::backend::ITensor &tensor) { sinks.at(n)->pull(tensor); }; + auto getter = [&](::onert::backend::ITensor &tensor) { sinks.at(n)->pull(tensor); }; - ir::OperandIndex index{_graph.getOutputs().at(output_index)}; _output_tensors[n]->access(getter); } } } // namespace exec -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/exec/ExecutorBase.h b/runtime/onert/core/src/exec/ExecutorBase.h similarity index 96% rename from runtime/neurun/core/src/exec/ExecutorBase.h rename to runtime/onert/core/src/exec/ExecutorBase.h index 5bd96a9cf3e..cb5dde8eb74 100644 --- a/runtime/neurun/core/src/exec/ExecutorBase.h +++ b/runtime/onert/core/src/exec/ExecutorBase.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_EXEC_EXECUTOR_BASE_H__ -#define __NEURUN_EXEC_EXECUTOR_BASE_H__ +#ifndef __ONERT_EXEC_EXECUTOR_BASE_H__ +#define __ONERT_EXEC_EXECUTOR_BASE_H__ #include @@ -35,7 +35,7 @@ #include "exec/ExecutionObservee.h" #include -namespace neurun +namespace onert { namespace exec { @@ -128,6 +128,6 @@ class ExecutorBase : public IExecutor }; } // namespace exec -} // namespace neurun +} // namespace onert -#endif // __NEURUN_EXEC_EXECUTOR_BASE_H__ +#endif // __ONERT_EXEC_EXECUTOR_BASE_H__ diff --git a/runtime/neurun/core/src/exec/FunctionSequence.cc b/runtime/onert/core/src/exec/FunctionSequence.cc similarity index 97% rename from runtime/neurun/core/src/exec/FunctionSequence.cc rename to runtime/onert/core/src/exec/FunctionSequence.cc index 4b65b153022..bf205af80cb 100644 --- a/runtime/neurun/core/src/exec/FunctionSequence.cc +++ b/runtime/onert/core/src/exec/FunctionSequence.cc @@ -16,7 +16,7 @@ #include "exec/FunctionSequence.h" -namespace neurun +namespace onert { namespace exec { @@ -59,4 +59,4 @@ void FunctionSequence::iterate(const std::function &fn) } } // namespace exec -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/exec/JSONExecTime.cc b/runtime/onert/core/src/exec/JSONExecTime.cc similarity index 98% rename from runtime/neurun/core/src/exec/JSONExecTime.cc rename to runtime/onert/core/src/exec/JSONExecTime.cc index 2bc1719077c..72a18def122 100644 --- a/runtime/neurun/core/src/exec/JSONExecTime.cc +++ b/runtime/onert/core/src/exec/JSONExecTime.cc @@ -18,7 +18,7 @@ #include "backend/IConfig.h" #include -namespace neurun +namespace onert { namespace exec { @@ -227,5 +227,5 @@ void JSON::loadOperationsExecTime() } } -} // namespace backend -} // namespace neurun +} // namespace exec +} // namespace onert diff --git a/runtime/neurun/core/src/exec/Job.cc b/runtime/onert/core/src/exec/Job.cc similarity index 95% rename from runtime/neurun/core/src/exec/Job.cc rename to runtime/onert/core/src/exec/Job.cc index ba02daf3014..dc0d140f08f 100644 --- a/runtime/neurun/core/src/exec/Job.cc +++ b/runtime/onert/core/src/exec/Job.cc @@ -20,7 +20,7 @@ #include "util/logging.h" -namespace neurun +namespace onert { namespace exec { @@ -30,4 +30,4 @@ Job::Job(uint32_t index, IFunction *fn) : _index{index}, _fn{fn} {} void Job::run() { _fn->run(); } } // namespace exec -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/exec/Job.h b/runtime/onert/core/src/exec/Job.h similarity index 91% rename from runtime/neurun/core/src/exec/Job.h rename to runtime/onert/core/src/exec/Job.h index 1516b928109..ff08ec8cef0 100644 --- a/runtime/neurun/core/src/exec/Job.h +++ b/runtime/onert/core/src/exec/Job.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_EXEC_JOB_H__ -#define __NEURUN_EXEC_JOB_H__ +#ifndef __ONERT_EXEC_JOB_H__ +#define __ONERT_EXEC_JOB_H__ #include @@ -24,7 +24,7 @@ #include "ir/OperandIndexSequence.h" #include "backend/Backend.h" -namespace neurun +namespace onert { namespace exec { @@ -64,6 +64,6 @@ class Job }; } // namespace exec -} // namespace neurun +} // namespace onert -#endif // __NEURUN_EXEC_JOB_H__ +#endif // __ONERT_EXEC_JOB_H__ diff --git a/runtime/neurun/core/src/exec/LinearExecutor.cc b/runtime/onert/core/src/exec/LinearExecutor.cc similarity index 96% rename from runtime/neurun/core/src/exec/LinearExecutor.cc rename to runtime/onert/core/src/exec/LinearExecutor.cc index 5378abf00cf..188282d4d42 100644 --- a/runtime/neurun/core/src/exec/LinearExecutor.cc +++ b/runtime/onert/core/src/exec/LinearExecutor.cc @@ -16,7 +16,7 @@ #include "LinearExecutor.h" -namespace neurun +namespace onert { namespace exec { @@ -36,4 +36,4 @@ void LinearExecutor::executeImpl() } } // namespace exec -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/exec/LinearExecutor.h b/runtime/onert/core/src/exec/LinearExecutor.h similarity index 90% rename from runtime/neurun/core/src/exec/LinearExecutor.h rename to runtime/onert/core/src/exec/LinearExecutor.h index ed6961be173..f49f51e3e2a 100644 --- a/runtime/neurun/core/src/exec/LinearExecutor.h +++ b/runtime/onert/core/src/exec/LinearExecutor.h @@ -19,8 +19,8 @@ * @brief This file contains LinearExecutor class to define and run execution phase */ -#ifndef __NEURUN_EXEC_EXECUTOR_H_ -#define __NEURUN_EXEC_EXECUTOR_H_ +#ifndef __ONERT_EXEC_EXECUTOR_H_ +#define __ONERT_EXEC_EXECUTOR_H_ #include "ir/Index.h" #include "ExecutorBase.h" @@ -28,7 +28,7 @@ #include "exec/FunctionSequence.h" #include "compiler/CodeMap.h" -namespace neurun +namespace onert { namespace exec { @@ -44,7 +44,7 @@ class LinearExecutor final : public ExecutorBase * @brief Construct a new LinearExecutor object * @param lowered_graph LoweredGraph object * @param tensor_builders Tensor builders that are currently used - * @param code_map Subgraph and its code map + * @param code_map OpSequence and its code map */ LinearExecutor(std::unique_ptr lowered_graph, const backend::TensorBuilderSet &tensor_builders, compiler::CodeMap &&code_map, @@ -65,6 +65,6 @@ class LinearExecutor final : public ExecutorBase }; } // namespace exec -} // namespace neurun +} // namespace onert -#endif // __NEURUN_EXEC_EXECUTOR_H_ +#endif // __ONERT_EXEC_EXECUTOR_H_ diff --git a/runtime/neurun/core/src/exec/ParallelExecutor.cc b/runtime/onert/core/src/exec/ParallelExecutor.cc similarity index 95% rename from runtime/neurun/core/src/exec/ParallelExecutor.cc rename to runtime/onert/core/src/exec/ParallelExecutor.cc index 7a373b20748..f7e5de67d82 100644 --- a/runtime/neurun/core/src/exec/ParallelExecutor.cc +++ b/runtime/onert/core/src/exec/ParallelExecutor.cc @@ -21,7 +21,7 @@ #include "util/logging.h" #include "exec/IFunction.h" -namespace neurun +namespace onert { namespace exec { @@ -119,9 +119,9 @@ void ParallelExecutor::executeImpl() VERBOSE(ParallelExecutor) << "Assigning fn #" << job->index() << std::endl; auto job_index = job->index(); - auto subgraph_index = _job_to_op_seq[job_index]; - auto op_seq = &_lowered_graph->op_seqs().at(subgraph_index); - auto backend = _lowered_graph->getLowerInfo()->operation.at(subgraph_index)->backend(); + auto op_sequence_index = _job_to_op_seq[job_index]; + auto op_seq = &_lowered_graph->op_seqs().at(op_sequence_index); + auto backend = _lowered_graph->getLowerInfo()->operation.at(op_sequence_index)->backend(); auto setup = [&, op_seq, backend]() { _subject.notifyJobBegin(this, op_seq, backend); }; auto teardown = [&, job_index, op_seq, backend]() { _subject.notifyJobEnd(this, op_seq, backend); @@ -143,4 +143,4 @@ void ParallelExecutor::executeImpl() } } // namespace exec -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/exec/ParallelExecutor.h b/runtime/onert/core/src/exec/ParallelExecutor.h similarity index 87% rename from runtime/neurun/core/src/exec/ParallelExecutor.h rename to runtime/onert/core/src/exec/ParallelExecutor.h index f65a9737d41..d9387db5cbe 100644 --- a/runtime/neurun/core/src/exec/ParallelExecutor.h +++ b/runtime/onert/core/src/exec/ParallelExecutor.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_EXEC_PARALLEL_EXECUTOR_H__ -#define __NEURUN_EXEC_PARALLEL_EXECUTOR_H__ +#ifndef __ONERT_EXEC_PARALLEL_EXECUTOR_H__ +#define __ONERT_EXEC_PARALLEL_EXECUTOR_H__ #include #include @@ -25,11 +25,11 @@ #include "Job.h" #include "ir/OperandIndexSequence.h" #include "ir/Index.h" -#include "memory" +#include #include "exec/DataflowExecutor.h" #include "ParallelScheduler.h" -namespace neurun +namespace onert { namespace exec { @@ -48,7 +48,7 @@ class ParallelExecutor : public DataflowExecutor * * @param lowered_graph LoweredGraph object * @param tensor_builders Tensor builders that are currently used - * @param code_map Subgraph and its code map + * @param code_map OpSequence and its code map */ ParallelExecutor(std::unique_ptr lowered_graph, const backend::TensorBuilderSet &tensor_builders, compiler::CodeMap &&code_map); @@ -62,6 +62,6 @@ class ParallelExecutor : public DataflowExecutor }; } // namespace exec -} // namespace neurun +} // namespace onert -#endif // __NEURUN_EXEC_PARALLEL_EXECUTOR_H__ +#endif // __ONERT_EXEC_PARALLEL_EXECUTOR_H__ diff --git a/runtime/neurun/core/src/exec/ParallelScheduler.cc b/runtime/onert/core/src/exec/ParallelScheduler.cc similarity index 95% rename from runtime/neurun/core/src/exec/ParallelScheduler.cc rename to runtime/onert/core/src/exec/ParallelScheduler.cc index 625b5e21d1f..1b2cf80bc42 100644 --- a/runtime/neurun/core/src/exec/ParallelScheduler.cc +++ b/runtime/onert/core/src/exec/ParallelScheduler.cc @@ -18,10 +18,10 @@ #include -#include "memory" +#include #include "util/logging.h" -namespace neurun +namespace onert { namespace exec { @@ -52,4 +52,4 @@ void ParallelScheduler::finish() } } // namespace exec -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/exec/ParallelScheduler.h b/runtime/onert/core/src/exec/ParallelScheduler.h similarity index 88% rename from runtime/neurun/core/src/exec/ParallelScheduler.h rename to runtime/onert/core/src/exec/ParallelScheduler.h index af1103750b7..3a53b6c7f12 100644 --- a/runtime/neurun/core/src/exec/ParallelScheduler.h +++ b/runtime/onert/core/src/exec/ParallelScheduler.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_EXEC_PARALLEL_SCHEDULER_H__ -#define __NEURUN_EXEC_PARALLEL_SCHEDULER_H__ +#ifndef __ONERT_EXEC_PARALLEL_SCHEDULER_H__ +#define __ONERT_EXEC_PARALLEL_SCHEDULER_H__ #include #include @@ -24,7 +24,7 @@ #include "ir/BackendSet.h" #include "ThreadPool.h" -namespace neurun +namespace onert { namespace exec { @@ -55,6 +55,6 @@ class ParallelScheduler }; } // namespace exec -} // namespace neurun +} // namespace onert -#endif // __NEURUN_EXEC_PARALLEL_SCHEDULER_H__ +#endif // __ONERT_EXEC_PARALLEL_SCHEDULER_H__ diff --git a/runtime/neurun/core/src/exec/Sink.h b/runtime/onert/core/src/exec/Sink.h similarity index 91% rename from runtime/neurun/core/src/exec/Sink.h rename to runtime/onert/core/src/exec/Sink.h index daf853a876b..238b0edddc4 100644 --- a/runtime/neurun/core/src/exec/Sink.h +++ b/runtime/onert/core/src/exec/Sink.h @@ -14,12 +14,12 @@ * limitations under the License. */ -#ifndef __NEURUN_EXEC_SINK_H__ -#define __NEURUN_EXEC_SINK_H__ +#ifndef __ONERT_EXEC_SINK_H__ +#define __ONERT_EXEC_SINK_H__ #include -#include "memory" +#include #include "util/feature/nchw/Reader.h" #include "util/feature/nchw/View.h" #include "util/feature/nhwc/Reader.h" @@ -27,7 +27,7 @@ #include "util/Utils.h" #include -namespace neurun +namespace onert { namespace exec { @@ -35,7 +35,7 @@ struct ISink { virtual ~ISink() = default; - virtual void pull(::neurun::backend::ITensor &tensor) const = 0; + virtual void pull(::onert::backend::ITensor &tensor) const = 0; }; // Create second lever inheritance: the first lever is used as a reference type in use-case places @@ -50,7 +50,7 @@ template class ITemplSink : public ISink } protected: - void pullUnif(neurun::backend::ITensor &tensor) const + void pullUnif(onert::backend::ITensor &tensor) const { assert(((_io_layout == ir::Layout::NHWC && tensor.layout() == ir::Layout::NCHW) || (_io_layout == ir::Layout::NCHW && tensor.layout() == ir::Layout::NHWC)) || @@ -153,7 +153,7 @@ template class ITemplSink : public ISink break; } default: - throw std::runtime_error("NYI"); + throw std::runtime_error("NYI: rank > 4"); break; } } @@ -176,7 +176,7 @@ template class PermutateSink final : public ITemplSink } public: - void pull(neurun::backend::ITensor &tensor) const override { ITemplSink::pullUnif(tensor); } + void pull(onert::backend::ITensor &tensor) const override { ITemplSink::pullUnif(tensor); } }; // Only supports NHWC format front-end(NNAPI) now @@ -190,10 +190,10 @@ template class CopySink final : public ITemplSink } public: - void pull(neurun::backend::ITensor &tensor) const override { ITemplSink::pullUnif(tensor); } + void pull(onert::backend::ITensor &tensor) const override { ITemplSink::pullUnif(tensor); } }; } // namespace exec -} // namespace neurun +} // namespace onert -#endif // __NEURUN_EXEC_SINK_H__ +#endif // __ONERT_EXEC_SINK_H__ diff --git a/runtime/neurun/core/src/exec/Source.h b/runtime/onert/core/src/exec/Source.h similarity index 91% rename from runtime/neurun/core/src/exec/Source.h rename to runtime/onert/core/src/exec/Source.h index 36cf6a8c84d..5792d8f2e60 100644 --- a/runtime/neurun/core/src/exec/Source.h +++ b/runtime/onert/core/src/exec/Source.h @@ -14,12 +14,12 @@ * limitations under the License. */ -#ifndef __NEURUN_EXEC_SOURCE_H__ -#define __NEURUN_EXEC_SOURCE_H__ +#ifndef __ONERT_EXEC_SOURCE_H__ +#define __ONERT_EXEC_SOURCE_H__ #include -#include "memory" +#include #include "util/feature/nchw/Reader.h" #include "util/feature/nchw/View.h" #include "util/feature/nhwc/Reader.h" @@ -29,7 +29,7 @@ #include #include "ir/Shape.h" -namespace neurun +namespace onert { namespace exec { @@ -38,7 +38,7 @@ struct ISource { virtual ~ISource() = default; - virtual void push(::neurun::backend::ITensor &tensor) const = 0; + virtual void push(::onert::backend::ITensor &tensor) const = 0; }; // Create second lever inheritance: the first lever is used as a reference type in use-case places @@ -52,10 +52,10 @@ template class ITemplSource : public ISource { } - virtual void push(::neurun::backend::ITensor &tensor) const = 0; + virtual void push(::onert::backend::ITensor &tensor) const = 0; protected: - void pushUnif(neurun::backend::ITensor &tensor) const + void pushUnif(onert::backend::ITensor &tensor) const { assert(((_io_layout == ir::Layout::NHWC && tensor.layout() == ir::Layout::NCHW) || (_io_layout == ir::Layout::NCHW && tensor.layout() == ir::Layout::NHWC)) || @@ -159,7 +159,7 @@ template class ITemplSource : public ISource break; } default: - throw std::runtime_error("NYI"); + throw std::runtime_error("NYI: rank > 4"); break; } } @@ -182,7 +182,7 @@ template class PermutateSource final : public ITemplSource } public: - void push(neurun::backend::ITensor &tensor) const override + void push(onert::backend::ITensor &tensor) const override { // do NHWC_TO_NCHW or NCHW_TO_NHWC permutation ITemplSource::pushUnif(tensor); @@ -199,10 +199,10 @@ template class CopySource final : public ITemplSource } public: - void push(neurun::backend::ITensor &tensor) const override { ITemplSource::pushUnif(tensor); } + void push(onert::backend::ITensor &tensor) const override { ITemplSource::pushUnif(tensor); } }; } // namespace exec -} // namespace neurun +} // namespace onert -#endif // __NEURUN_EXEC_SOURCE_H__ +#endif // __ONERT_EXEC_SOURCE_H__ diff --git a/runtime/neurun/core/src/exec/ThreadPool.cc b/runtime/onert/core/src/exec/ThreadPool.cc similarity index 97% rename from runtime/neurun/core/src/exec/ThreadPool.cc rename to runtime/onert/core/src/exec/ThreadPool.cc index d8c706e3032..c8e0e3265e8 100644 --- a/runtime/neurun/core/src/exec/ThreadPool.cc +++ b/runtime/onert/core/src/exec/ThreadPool.cc @@ -18,7 +18,7 @@ #include -namespace neurun +namespace onert { namespace exec { @@ -62,4 +62,4 @@ void ThreadPool::finish() } } // namespace exec -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/exec/ThreadPool.h b/runtime/onert/core/src/exec/ThreadPool.h similarity index 90% rename from runtime/neurun/core/src/exec/ThreadPool.h rename to runtime/onert/core/src/exec/ThreadPool.h index a1a027617ac..b638bd94cef 100644 --- a/runtime/neurun/core/src/exec/ThreadPool.h +++ b/runtime/onert/core/src/exec/ThreadPool.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_EXEC_THREAD_POOL_H__ -#define __NEURUN_EXEC_THREAD_POOL_H__ +#ifndef __ONERT_EXEC_THREAD_POOL_H__ +#define __ONERT_EXEC_THREAD_POOL_H__ #include #include @@ -23,7 +23,7 @@ #include "WorkQueue.h" -namespace neurun +namespace onert { namespace exec { @@ -68,6 +68,6 @@ class ThreadPool }; } // namespace exec -} // namespace neurun +} // namespace onert -#endif // __NEURUN_EXEC_THREAD_POOL_H__ +#endif // __ONERT_EXEC_THREAD_POOL_H__ diff --git a/runtime/neurun/core/src/exec/WorkQueue.cc b/runtime/onert/core/src/exec/WorkQueue.cc similarity index 98% rename from runtime/neurun/core/src/exec/WorkQueue.cc rename to runtime/onert/core/src/exec/WorkQueue.cc index 6712554acda..b37f6a387dc 100644 --- a/runtime/neurun/core/src/exec/WorkQueue.cc +++ b/runtime/onert/core/src/exec/WorkQueue.cc @@ -18,7 +18,7 @@ #include -namespace neurun +namespace onert { namespace exec { @@ -101,4 +101,4 @@ uint32_t WorkQueue::numJobsInQueue() } } // namespace exec -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/exec/WorkQueue.h b/runtime/onert/core/src/exec/WorkQueue.h similarity index 92% rename from runtime/neurun/core/src/exec/WorkQueue.h rename to runtime/onert/core/src/exec/WorkQueue.h index cdbadfb8f3f..2e56d85e80a 100644 --- a/runtime/neurun/core/src/exec/WorkQueue.h +++ b/runtime/onert/core/src/exec/WorkQueue.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_EXEC_WORK_QUEUE_H__ -#define __NEURUN_EXEC_WORK_QUEUE_H__ +#ifndef __ONERT_EXEC_WORK_QUEUE_H__ +#define __ONERT_EXEC_WORK_QUEUE_H__ #include #include @@ -24,7 +24,7 @@ #include "exec/IFunction.h" -namespace neurun +namespace onert { namespace exec { @@ -82,6 +82,6 @@ class WorkQueue }; } // namespace exec -} // namespace neurun +} // namespace onert -#endif // __NEURUN_EXEC_WORK_QUEUE_H__ +#endif // __ONERT_EXEC_WORK_QUEUE_H__ diff --git a/runtime/neurun/core/src/interp/Buffer.h b/runtime/onert/core/src/interp/Buffer.h similarity index 93% rename from runtime/neurun/core/src/interp/Buffer.h rename to runtime/onert/core/src/interp/Buffer.h index ca5ae54d82e..24938f74f22 100644 --- a/runtime/neurun/core/src/interp/Buffer.h +++ b/runtime/onert/core/src/interp/Buffer.h @@ -18,14 +18,14 @@ * @file Buffer.h * @brief This file contains Buffer interface and InternalBuffer, ExternalBuffer class */ -#ifndef __NEURUN_INTERP_BUFFER_H__ -#define __NEURUN_INTERP_BUFFER_H__ +#ifndef __ONERT_INTERP_BUFFER_H__ +#define __ONERT_INTERP_BUFFER_H__ #include #include "ir/Data.h" -namespace neurun +namespace onert { namespace interp { @@ -86,6 +86,6 @@ class ExternalBuffer final : public Buffer }; } // namespace interp -} // namespace neurun +} // namespace onert -#endif // __NEURUN_INTERP_BUFFER_H__ +#endif // __ONERT_INTERP_BUFFER_H__ diff --git a/runtime/neurun/core/src/interp/ExecEnv.h b/runtime/onert/core/src/interp/ExecEnv.h similarity index 96% rename from runtime/neurun/core/src/interp/ExecEnv.h rename to runtime/onert/core/src/interp/ExecEnv.h index 89e203335c5..20805f1b3a7 100644 --- a/runtime/neurun/core/src/interp/ExecEnv.h +++ b/runtime/onert/core/src/interp/ExecEnv.h @@ -18,15 +18,15 @@ * @file ExecEnv.h * @brief This file contains ExecEnv to access interpreter tensor and execution status */ -#ifndef __NEURUN_INTERP_EXEC_ENV_H_ -#define __NEURUN_INTERP_EXEC_ENV_H_ +#ifndef __ONERT_INTERP_EXEC_ENV_H_ +#define __ONERT_INTERP_EXEC_ENV_H_ #include #include "ir/Graph.h" #include "Tensor.h" -namespace neurun +namespace onert { namespace interp { @@ -157,6 +157,6 @@ class ExecEnv }; } // namespace interp -} // namespace neurun +} // namespace onert -#endif // __NEURUN_INTERP_EXEC_ENV_H_ +#endif // __ONERT_INTERP_EXEC_ENV_H_ diff --git a/runtime/neurun/core/src/interp/InterpExecutor.cc b/runtime/onert/core/src/interp/InterpExecutor.cc similarity index 98% rename from runtime/neurun/core/src/interp/InterpExecutor.cc rename to runtime/onert/core/src/interp/InterpExecutor.cc index adbb84147dc..7a848412fb3 100644 --- a/runtime/neurun/core/src/interp/InterpExecutor.cc +++ b/runtime/onert/core/src/interp/InterpExecutor.cc @@ -22,7 +22,7 @@ #include -namespace neurun +namespace onert { namespace interp { @@ -110,5 +110,5 @@ void InterpExecutor::execute(const exec::IODescription &desc) // 2. Generate new ExecEnv for next interpretation } -} // namespace exec -} // namespace neurun +} // namespace interp +} // namespace onert diff --git a/runtime/neurun/core/src/interp/InterpOps.lst b/runtime/onert/core/src/interp/InterpOps.lst similarity index 100% rename from runtime/neurun/core/src/interp/InterpOps.lst rename to runtime/onert/core/src/interp/InterpOps.lst diff --git a/runtime/neurun/core/src/interp/Interpreter.cc b/runtime/onert/core/src/interp/Interpreter.cc similarity index 99% rename from runtime/neurun/core/src/interp/Interpreter.cc rename to runtime/onert/core/src/interp/Interpreter.cc index 41d2864d03b..e0cb8ce41fe 100644 --- a/runtime/neurun/core/src/interp/Interpreter.cc +++ b/runtime/onert/core/src/interp/Interpreter.cc @@ -25,7 +25,7 @@ #include "util/logging.h" #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace interp { @@ -181,4 +181,4 @@ void Interpreter::run() } } // namespace interp -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/interp/Interpreter.h b/runtime/onert/core/src/interp/Interpreter.h similarity index 89% rename from runtime/neurun/core/src/interp/Interpreter.h rename to runtime/onert/core/src/interp/Interpreter.h index baded933721..d2165f538e0 100644 --- a/runtime/neurun/core/src/interp/Interpreter.h +++ b/runtime/onert/core/src/interp/Interpreter.h @@ -18,12 +18,12 @@ * @file Interpreter.h * @brief This file contains Interpreter class for interpretation */ -#ifndef __NEURUN_INTERP_INTERPRETER_H__ -#define __NEURUN_INTERP_INTERPRETER_H__ +#ifndef __ONERT_INTERP_INTERPRETER_H__ +#define __ONERT_INTERP_INTERPRETER_H__ #include "ExecEnv.h" -namespace neurun +namespace onert { namespace interp { @@ -59,6 +59,6 @@ class Interpreter }; } // namespace interp -} // namespace neurun +} // namespace onert -#endif // __NEURUN_INTERP_INTERPRETER_H__ +#endif // __ONERT_INTERP_INTERPRETER_H__ diff --git a/runtime/neurun/core/src/interp/Registration.h b/runtime/onert/core/src/interp/Registration.h similarity index 86% rename from runtime/neurun/core/src/interp/Registration.h rename to runtime/onert/core/src/interp/Registration.h index 2d0203f53cb..956b92a53ea 100644 --- a/runtime/neurun/core/src/interp/Registration.h +++ b/runtime/onert/core/src/interp/Registration.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_INTERP_REGISTRATION_H__ -#define __NEURUN_INTERP_REGISTRATION_H__ +#ifndef __ONERT_INTERP_REGISTRATION_H__ +#define __ONERT_INTERP_REGISTRATION_H__ #include "ExecEnv.h" #include "ir/Operation.h" -namespace neurun +namespace onert { namespace interp { @@ -38,6 +38,6 @@ struct OpKernel #undef INTERP_OP } // namespace interp -} // namespace neurun +} // namespace onert -#endif // __NEURUN_INTERP_REGISTRATION_H__ +#endif // __ONERT_INTERP_REGISTRATION_H__ diff --git a/runtime/neurun/core/src/interp/Tensor.cc b/runtime/onert/core/src/interp/Tensor.cc similarity index 97% rename from runtime/neurun/core/src/interp/Tensor.cc rename to runtime/onert/core/src/interp/Tensor.cc index 01799f60c66..07f8b75dcbf 100644 --- a/runtime/neurun/core/src/interp/Tensor.cc +++ b/runtime/onert/core/src/interp/Tensor.cc @@ -18,7 +18,7 @@ #define NO_USE(a) (void)(a) -namespace neurun +namespace onert { namespace interp { @@ -50,4 +50,4 @@ ir::Layout Tensor::layout() const } } // namespace interp -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/interp/Tensor.h b/runtime/onert/core/src/interp/Tensor.h similarity index 97% rename from runtime/neurun/core/src/interp/Tensor.h rename to runtime/onert/core/src/interp/Tensor.h index 87ae6737b77..d5cb81738fe 100644 --- a/runtime/neurun/core/src/interp/Tensor.h +++ b/runtime/onert/core/src/interp/Tensor.h @@ -18,8 +18,8 @@ * @file Tensor.h * @brief This file contains ITensor interface, ROTensor class, and Tensor class */ -#ifndef __NEURUN_INTERP_TENSOR_H__ -#define __NEURUN_INTERP_TENSOR_H__ +#ifndef __ONERT_INTERP_TENSOR_H__ +#define __ONERT_INTERP_TENSOR_H__ #include "Buffer.h" @@ -27,7 +27,7 @@ #include "backend/ITensor.h" #include "ir/Layout.h" -namespace neurun +namespace onert { namespace interp { @@ -172,6 +172,6 @@ class Tensor final : public ITensor }; } // namespace interp -} // namespace neurun +} // namespace onert -#endif // __NEURUN_INTERP_TENSOR_H__ +#endif // __ONERT_INTERP_TENSOR_H__ diff --git a/runtime/neurun/core/src/interp/operations/AvgPool2D.cc b/runtime/onert/core/src/interp/operations/AvgPool2D.cc similarity index 99% rename from runtime/neurun/core/src/interp/operations/AvgPool2D.cc rename to runtime/onert/core/src/interp/operations/AvgPool2D.cc index 67734d71bd9..ef653fb2a18 100644 --- a/runtime/neurun/core/src/interp/operations/AvgPool2D.cc +++ b/runtime/onert/core/src/interp/operations/AvgPool2D.cc @@ -24,7 +24,7 @@ #include "util/ShapeInference.h" #include "misc/polymorphic_downcast.h" -namespace neurun +namespace onert { namespace interp { @@ -122,4 +122,4 @@ OpKernel *getAvgPool2D() } } // namespace interp -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/interp/operations/BinaryArithmeticOps.cc b/runtime/onert/core/src/interp/operations/BinaryArithmeticOps.cc similarity index 99% rename from runtime/neurun/core/src/interp/operations/BinaryArithmeticOps.cc rename to runtime/onert/core/src/interp/operations/BinaryArithmeticOps.cc index 771b5a3ff91..8ffc3cd3381 100644 --- a/runtime/neurun/core/src/interp/operations/BinaryArithmeticOps.cc +++ b/runtime/onert/core/src/interp/operations/BinaryArithmeticOps.cc @@ -24,7 +24,7 @@ #include "ir/operation/Mul.h" #include "misc/polymorphic_downcast.h" -namespace neurun +namespace onert { namespace interp { @@ -166,7 +166,7 @@ void invokeAdd(const ExecEnv *env, const ir::Operation &node) throw std::runtime_error{"NYI: Unsupported data type"}; } } -} // namespace add +} // namespace OpKernel *getAdd() { @@ -190,4 +190,4 @@ OpKernel *getMul() } } // namespace interp -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/interp/operations/Concat.cc b/runtime/onert/core/src/interp/operations/Concat.cc similarity index 99% rename from runtime/neurun/core/src/interp/operations/Concat.cc rename to runtime/onert/core/src/interp/operations/Concat.cc index ec16b408496..53715e7901f 100644 --- a/runtime/neurun/core/src/interp/operations/Concat.cc +++ b/runtime/onert/core/src/interp/operations/Concat.cc @@ -22,7 +22,7 @@ #include "ir/operation/Concat.h" #include "misc/polymorphic_downcast.h" -namespace neurun +namespace onert { namespace interp { @@ -144,4 +144,4 @@ OpKernel *getConcat() } } // namespace interp -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/interp/operations/Conv2D.cc b/runtime/onert/core/src/interp/operations/Conv2D.cc similarity index 99% rename from runtime/neurun/core/src/interp/operations/Conv2D.cc rename to runtime/onert/core/src/interp/operations/Conv2D.cc index f10b1061985..3c0087a61fe 100644 --- a/runtime/neurun/core/src/interp/operations/Conv2D.cc +++ b/runtime/onert/core/src/interp/operations/Conv2D.cc @@ -24,7 +24,7 @@ #include "util/ShapeInference.h" #include "misc/polymorphic_downcast.h" -namespace neurun +namespace onert { namespace interp { @@ -147,4 +147,4 @@ OpKernel *getConv2D() } } // namespace interp -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/interp/operations/DepthwiseConv2D.cc b/runtime/onert/core/src/interp/operations/DepthwiseConv2D.cc similarity index 99% rename from runtime/neurun/core/src/interp/operations/DepthwiseConv2D.cc rename to runtime/onert/core/src/interp/operations/DepthwiseConv2D.cc index 9d3d7872f63..2682fbd78b6 100644 --- a/runtime/neurun/core/src/interp/operations/DepthwiseConv2D.cc +++ b/runtime/onert/core/src/interp/operations/DepthwiseConv2D.cc @@ -24,7 +24,7 @@ #include "util/Utils.h" #include "util/ShapeInference.h" -namespace neurun +namespace onert { namespace interp { @@ -152,4 +152,4 @@ OpKernel *getDepthwiseConv2D() } } // namespace interp -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/interp/operations/FullyConnected.cc b/runtime/onert/core/src/interp/operations/FullyConnected.cc similarity index 91% rename from runtime/neurun/core/src/interp/operations/FullyConnected.cc rename to runtime/onert/core/src/interp/operations/FullyConnected.cc index bc93464737d..8dfac43db80 100644 --- a/runtime/neurun/core/src/interp/operations/FullyConnected.cc +++ b/runtime/onert/core/src/interp/operations/FullyConnected.cc @@ -22,7 +22,7 @@ #include "ir/operation/FullyConnected.h" #include "misc/polymorphic_downcast.h" -namespace neurun +namespace onert { namespace interp { @@ -82,12 +82,13 @@ void invoke(const ITensor *ifm_tensor, const ITensor *ker_tensor, const ITensor // Calculate nnfw::cker::FullyConnectedParams cker_param; + cker_param.activation = convertActivationType(param.activation); calculateActivationRange(param.activation, &cker_param.float_activation_min, &cker_param.float_activation_max); - const auto cker_ifm_shape = convertExtendShape(ifm_tensor->tensorInfo().shape()); - const auto cker_ker_shape = convertExtendShape(ker_tensor->tensorInfo().shape()); - const auto cker_bias_shape = convertExtendShape(bias_tensor->tensorInfo().shape()); - const auto cker_ofm_shape = convertExtendShape(ofm_tensor->tensorInfo().shape()); + const auto cker_ifm_shape = convertShape(ifm_tensor->tensorInfo().shape()); + const auto cker_ker_shape = convertShape(ker_tensor->tensorInfo().shape()); + const auto cker_bias_shape = convertShape(bias_tensor->tensorInfo().shape()); + const auto cker_ofm_shape = convertShape(ofm_tensor->tensorInfo().shape()); const float *ifm_ptr = reinterpret_cast(ifm_buffer); const float *ker_ptr = reinterpret_cast(ker_buffer); const float *bias_ptr = reinterpret_cast(bias_buffer); @@ -131,4 +132,4 @@ OpKernel *getFullyConnected() } } // namespace interp -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/interp/operations/Gather.cc b/runtime/onert/core/src/interp/operations/Gather.cc similarity index 98% rename from runtime/neurun/core/src/interp/operations/Gather.cc rename to runtime/onert/core/src/interp/operations/Gather.cc index 700fba6f342..b63e74886af 100644 --- a/runtime/neurun/core/src/interp/operations/Gather.cc +++ b/runtime/onert/core/src/interp/operations/Gather.cc @@ -22,7 +22,7 @@ #include "ir/operation/Gather.h" #include "misc/polymorphic_downcast.h" -namespace neurun +namespace onert { namespace interp { @@ -126,7 +126,7 @@ void invokeGather(const ExecEnv *env, const ir::Operation &node) } } -} // namespace concat +} // namespace OpKernel *getGather() { @@ -135,4 +135,4 @@ OpKernel *getGather() } } // namespace interp -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/interp/operations/InstanceNorm.cc b/runtime/onert/core/src/interp/operations/InstanceNorm.cc similarity index 99% rename from runtime/neurun/core/src/interp/operations/InstanceNorm.cc rename to runtime/onert/core/src/interp/operations/InstanceNorm.cc index f1d01dde4ac..2538bcc394c 100644 --- a/runtime/neurun/core/src/interp/operations/InstanceNorm.cc +++ b/runtime/onert/core/src/interp/operations/InstanceNorm.cc @@ -22,7 +22,7 @@ #include "ir/operation/InstanceNorm.h" #include "misc/polymorphic_downcast.h" -namespace neurun +namespace onert { namespace interp { @@ -118,4 +118,4 @@ OpKernel *getInstanceNorm() } } // namespace interp -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/interp/operations/Logistic.cc b/runtime/onert/core/src/interp/operations/Logistic.cc similarity index 98% rename from runtime/neurun/core/src/interp/operations/Logistic.cc rename to runtime/onert/core/src/interp/operations/Logistic.cc index a5032938eab..c23cbb782e3 100644 --- a/runtime/neurun/core/src/interp/operations/Logistic.cc +++ b/runtime/onert/core/src/interp/operations/Logistic.cc @@ -21,7 +21,7 @@ #include "interp/Registration.h" #include "ir/operation/Logistic.h" -namespace neurun +namespace onert { namespace interp { @@ -96,4 +96,4 @@ OpKernel *getLogistic() } } // namespace interp -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/interp/operations/MaxPool2D.cc b/runtime/onert/core/src/interp/operations/MaxPool2D.cc similarity index 99% rename from runtime/neurun/core/src/interp/operations/MaxPool2D.cc rename to runtime/onert/core/src/interp/operations/MaxPool2D.cc index 6b1adbcab52..d524f356eed 100644 --- a/runtime/neurun/core/src/interp/operations/MaxPool2D.cc +++ b/runtime/onert/core/src/interp/operations/MaxPool2D.cc @@ -24,7 +24,7 @@ #include "util/ShapeInference.h" #include "misc/polymorphic_downcast.h" -namespace neurun +namespace onert { namespace interp { @@ -121,4 +121,4 @@ OpKernel *getMaxPool2D() } } // namespace interp -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/interp/operations/OperationUtil.h b/runtime/onert/core/src/interp/operations/OperationUtil.h similarity index 84% rename from runtime/neurun/core/src/interp/operations/OperationUtil.h rename to runtime/onert/core/src/interp/operations/OperationUtil.h index 58d1e51d2f4..cdabe508d58 100644 --- a/runtime/neurun/core/src/interp/operations/OperationUtil.h +++ b/runtime/onert/core/src/interp/operations/OperationUtil.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_INTERP_OPERATIONS_OPERATION_UTILS_H_ -#define __NEURUN_INTERP_OPERATIONS_OPERATION_UTILS_H_ +#ifndef __ONERT_INTERP_OPERATIONS_OPERATION_UTILS_H_ +#define __ONERT_INTERP_OPERATIONS_OPERATION_UTILS_H_ #include "ir/Shape.h" #include "ir/InternalType.h" @@ -24,7 +24,7 @@ #include #include -namespace neurun +namespace onert { namespace interp { @@ -74,6 +74,24 @@ inline nnfw::cker::Shape convertExtendShape(const ir::Shape &shape) return nnfw::cker::GetShape(raw_shape); } +inline nnfw::cker::FusedActivationFunctionType +convertActivationType(const ir::Activation activation) +{ + switch (activation) + { + case ir::Activation::NONE: + return nnfw::cker::FusedActivationFunctionType::kNone; + case ir::Activation::RELU: + return nnfw::cker::FusedActivationFunctionType::kRelu; + case ir::Activation::RELU1: + return nnfw::cker::FusedActivationFunctionType::kRelu1; + case ir::Activation::RELU6: + return nnfw::cker::FusedActivationFunctionType::kRelu6; + default: + throw std::runtime_error{"CPU backend: Cannot convert activation type"}; + } +} + template void calculateActivationRange(ir::Activation activation, T *activation_min, T *activation_max) { @@ -187,6 +205,6 @@ inline nnfw::cker::PaddingType convertPaddingType(ir::PaddingType ir_padding_typ } } // namespace interp -} // namespace neurun +} // namespace onert -#endif // __NEURUN_INTERP_OPERATIONS_OPERATION_UTILS_H_ +#endif // __ONERT_INTERP_OPERATIONS_OPERATION_UTILS_H_ diff --git a/runtime/neurun/core/src/interp/operations/Pad.cc b/runtime/onert/core/src/interp/operations/Pad.cc similarity index 98% rename from runtime/neurun/core/src/interp/operations/Pad.cc rename to runtime/onert/core/src/interp/operations/Pad.cc index 86bcc8c25f9..d2e3627b403 100644 --- a/runtime/neurun/core/src/interp/operations/Pad.cc +++ b/runtime/onert/core/src/interp/operations/Pad.cc @@ -21,7 +21,7 @@ #include "interp/Registration.h" #include "ir/operation/Pad.h" -namespace neurun +namespace onert { namespace interp { @@ -103,4 +103,4 @@ OpKernel *getPad() } } // namespace interp -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/interp/operations/Reshape.cc b/runtime/onert/core/src/interp/operations/Reshape.cc similarity index 96% rename from runtime/neurun/core/src/interp/operations/Reshape.cc rename to runtime/onert/core/src/interp/operations/Reshape.cc index 8ea4e03a392..3a118456be2 100644 --- a/runtime/neurun/core/src/interp/operations/Reshape.cc +++ b/runtime/onert/core/src/interp/operations/Reshape.cc @@ -16,7 +16,7 @@ #include "interp/Registration.h" -namespace neurun +namespace onert { namespace interp { @@ -51,7 +51,7 @@ void invoke(const ExecEnv *env, const ir::Operation &node) output_info.total_size()); } -} // namespace {anonymous} +} // namespace OpKernel *getReshape() { @@ -60,4 +60,4 @@ OpKernel *getReshape() } } // namespace interp -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/interp/operations/Softmax.cc b/runtime/onert/core/src/interp/operations/Softmax.cc similarity index 99% rename from runtime/neurun/core/src/interp/operations/Softmax.cc rename to runtime/onert/core/src/interp/operations/Softmax.cc index aa094c5fe79..afc4e81f78b 100644 --- a/runtime/neurun/core/src/interp/operations/Softmax.cc +++ b/runtime/onert/core/src/interp/operations/Softmax.cc @@ -22,7 +22,7 @@ #include "ir/operation/Softmax.h" #include "misc/polymorphic_downcast.h" -namespace neurun +namespace onert { namespace interp { @@ -157,4 +157,4 @@ OpKernel *getSoftmax() } } // namespace interp -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/interp/operations/TransposeConv.cc b/runtime/onert/core/src/interp/operations/TransposeConv.cc similarity index 98% rename from runtime/neurun/core/src/interp/operations/TransposeConv.cc rename to runtime/onert/core/src/interp/operations/TransposeConv.cc index db489eade44..cc2ced26bef 100644 --- a/runtime/neurun/core/src/interp/operations/TransposeConv.cc +++ b/runtime/onert/core/src/interp/operations/TransposeConv.cc @@ -22,7 +22,7 @@ #include "interp/Registration.h" #include "ir/operation/TransposeConv.h" -namespace neurun +namespace onert { namespace interp { @@ -129,7 +129,7 @@ void invokeTransposeConv(const ExecEnv *env, const ir::Operation &node) } } -} // namespace transposeconv +} // namespace OpKernel *getTransposeConv() { @@ -138,4 +138,4 @@ OpKernel *getTransposeConv() } } // namespace interp -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/interp/operations/UnaryActivations.cc b/runtime/onert/core/src/interp/operations/UnaryActivations.cc similarity index 99% rename from runtime/neurun/core/src/interp/operations/UnaryActivations.cc rename to runtime/onert/core/src/interp/operations/UnaryActivations.cc index b0c12efe50d..ea5e2417b37 100644 --- a/runtime/neurun/core/src/interp/operations/UnaryActivations.cc +++ b/runtime/onert/core/src/interp/operations/UnaryActivations.cc @@ -25,7 +25,7 @@ #include "ir/operation/ReLU6.h" #include "ir/operation/Tanh.h" -namespace neurun +namespace onert { namespace interp { @@ -150,4 +150,4 @@ OpKernel *getTanh() } } // namespace interp -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/Coordinates.cc b/runtime/onert/core/src/ir/Coordinates.cc similarity index 97% rename from runtime/neurun/core/src/ir/Coordinates.cc rename to runtime/onert/core/src/ir/Coordinates.cc index d3aaadc3e48..a02a56567ef 100644 --- a/runtime/neurun/core/src/ir/Coordinates.cc +++ b/runtime/onert/core/src/ir/Coordinates.cc @@ -18,7 +18,7 @@ #include -namespace neurun +namespace onert { namespace ir { @@ -47,4 +47,4 @@ Coordinates convertCoordinates(const Coordinates &from_coordinates, Layout from_ } } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/Graph.cc b/runtime/onert/core/src/ir/Graph.cc similarity index 98% rename from runtime/neurun/core/src/ir/Graph.cc rename to runtime/onert/core/src/ir/Graph.cc index 53cd522bc37..837a88a6baf 100644 --- a/runtime/neurun/core/src/ir/Graph.cc +++ b/runtime/onert/core/src/ir/Graph.cc @@ -28,7 +28,7 @@ #include "ir/GraphIterator.h" #include "backend/IConfig.h" -namespace neurun +namespace onert { namespace ir { @@ -100,4 +100,4 @@ void Graph::initializeUseDef() } } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/GraphIterator.cc b/runtime/onert/core/src/ir/GraphIterator.cc similarity index 98% rename from runtime/neurun/core/src/ir/GraphIterator.cc rename to runtime/onert/core/src/ir/GraphIterator.cc index ce20787ae93..9e8b3e5335c 100644 --- a/runtime/neurun/core/src/ir/GraphIterator.cc +++ b/runtime/onert/core/src/ir/GraphIterator.cc @@ -19,7 +19,7 @@ #include "ir/OperationIndexMap.h" #include "ir/Graph.h" -namespace neurun +namespace onert { namespace ir { @@ -81,4 +81,4 @@ void PostDfsIterator::iterate(GraphRef graph, const IterFn &fn) const } } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/GraphIterator.h b/runtime/onert/core/src/ir/GraphIterator.h similarity index 92% rename from runtime/neurun/core/src/ir/GraphIterator.h rename to runtime/onert/core/src/ir/GraphIterator.h index a5bf1c32385..42c851895d1 100644 --- a/runtime/neurun/core/src/ir/GraphIterator.h +++ b/runtime/onert/core/src/ir/GraphIterator.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_GRAPH_ITERATOR_H__ -#define __NEURUN_IR_GRAPH_ITERATOR_H__ +#ifndef __ONERT_IR_GRAPH_ITERATOR_H__ +#define __ONERT_IR_GRAPH_ITERATOR_H__ #include #include "ir/Index.h" -namespace neurun +namespace onert { namespace ir { @@ -69,6 +69,6 @@ template class PostDfsIterator final : public Iterator; } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_GRAPH_ITERATOR_H__ +#endif // __ONERT_IR_GRAPH_ITERATOR_H__ diff --git a/runtime/neurun/core/src/ir/LayoutSet.cc b/runtime/onert/core/src/ir/LayoutSet.cc similarity index 97% rename from runtime/neurun/core/src/ir/LayoutSet.cc rename to runtime/onert/core/src/ir/LayoutSet.cc index 025ba45dcda..bd3f438ada4 100644 --- a/runtime/neurun/core/src/ir/LayoutSet.cc +++ b/runtime/onert/core/src/ir/LayoutSet.cc @@ -16,7 +16,7 @@ #include "LayoutSet.h" -namespace neurun +namespace onert { namespace ir { @@ -63,4 +63,4 @@ LayoutSet LayoutSet::operator-(const LayoutSet &other) const } } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/LayoutSet.h b/runtime/onert/core/src/ir/LayoutSet.h similarity index 91% rename from runtime/neurun/core/src/ir/LayoutSet.h rename to runtime/onert/core/src/ir/LayoutSet.h index e38ef3ce26c..6ce4e38c637 100644 --- a/runtime/neurun/core/src/ir/LayoutSet.h +++ b/runtime/onert/core/src/ir/LayoutSet.h @@ -14,15 +14,15 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_LAYOUT_SET_H__ -#define __NEURUN_IR_LAYOUT_SET_H__ +#ifndef __ONERT_IR_LAYOUT_SET_H__ +#define __ONERT_IR_LAYOUT_SET_H__ #include #include #include "ir/Layout.h" -namespace neurun +namespace onert { namespace ir { @@ -53,6 +53,6 @@ class LayoutSet }; } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_LAYOUT_SET_H__ +#endif // __ONERT_IR_LAYOUT_SET_H__ diff --git a/runtime/neurun/core/src/ir/LoweredGraph.cc b/runtime/onert/core/src/ir/LoweredGraph.cc similarity index 98% rename from runtime/neurun/core/src/ir/LoweredGraph.cc rename to runtime/onert/core/src/ir/LoweredGraph.cc index a4411629019..590308544fc 100644 --- a/runtime/neurun/core/src/ir/LoweredGraph.cc +++ b/runtime/onert/core/src/ir/LoweredGraph.cc @@ -30,7 +30,7 @@ #include "compiler/ManualScheduler.h" #include "compiler/HEScheduler.h" -namespace neurun +namespace onert { namespace ir { @@ -44,6 +44,10 @@ LoweredGraph::LoweredGraph(const Graph &graph, const compiler::CompilerOptions & auto &backend_manager = compiler::BackendManager::get(); backend_manager.loadBackend(backend_str); auto backend = backend_manager.get(backend_str); + + if (!backend) + throw std::runtime_error("Cannot get required backend"); + _backend_contexts.emplace(backend, backend->newContext(_graph, _graph.getKernelBuilder(), options.executor == "Linear")); } @@ -166,7 +170,7 @@ void LoweredGraph::removeLowerInfo(const OperandIndex &index) _lower_info_map.operand.erase(index); } -OpSequenceIndex LoweredGraph::appendFreshSingleOpSubgraph(const OperationIndex &node_index, +OpSequenceIndex LoweredGraph::appendFreshSingleOpSequence(const OperationIndex &node_index, const Operation &node, Layout layout) { // Create a fresh op_seq with one operation, and append it to op_seqs @@ -257,7 +261,7 @@ void LoweredGraph::makeOpSequences( // so that we can measure a node separately if (new_op_seq || is_profiling || !mergeable(op_seq_index, node_index, backend_layout)) { - auto new_op_seq_index = appendFreshSingleOpSubgraph(node_index, node, frontend_layout); + auto new_op_seq_index = appendFreshSingleOpSequence(node_index, node, frontend_layout); // OpSequence LowerInfo setLowerInfo(new_op_seq_index, @@ -312,7 +316,7 @@ void LoweredGraph::manipulateLowerInfo( void LoweredGraph::dumpLowerInfo() { - if (::neurun::util::logging::ctx.enabled() == false) + if (::onert::util::logging::ctx.enabled() == false) return; std::map dumps; @@ -482,4 +486,4 @@ bool LoweredGraph::mergeable(const OpSequenceIndex &op_seq_index, const Operatio } } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/OpCode.cc b/runtime/onert/core/src/ir/OpCode.cc similarity index 96% rename from runtime/neurun/core/src/ir/OpCode.cc rename to runtime/onert/core/src/ir/OpCode.cc index e6552a2758b..3f818291659 100644 --- a/runtime/neurun/core/src/ir/OpCode.cc +++ b/runtime/onert/core/src/ir/OpCode.cc @@ -18,7 +18,7 @@ #include -namespace neurun +namespace onert { namespace ir { @@ -34,4 +34,4 @@ const char *toString(OpCode opcode) } } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/OpSequence.cc b/runtime/onert/core/src/ir/OpSequence.cc similarity index 97% rename from runtime/neurun/core/src/ir/OpSequence.cc rename to runtime/onert/core/src/ir/OpSequence.cc index 13a6cbe2740..7635e9de4c1 100644 --- a/runtime/neurun/core/src/ir/OpSequence.cc +++ b/runtime/onert/core/src/ir/OpSequence.cc @@ -18,7 +18,7 @@ #include "ir/OperationVisitor.h" #include -namespace neurun +namespace onert { namespace ir { @@ -80,4 +80,4 @@ bool OpSequence::exist(const OperationIndex &index) const } } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/OpSequences.cc b/runtime/onert/core/src/ir/OpSequences.cc similarity index 76% rename from runtime/neurun/core/src/ir/OpSequences.cc rename to runtime/onert/core/src/ir/OpSequences.cc index 42b7a5aba5c..991e96c9dec 100644 --- a/runtime/neurun/core/src/ir/OpSequences.cc +++ b/runtime/onert/core/src/ir/OpSequences.cc @@ -16,12 +16,12 @@ #include "ir/OpSequences.h" #include "util/logging.h" -#include "memory" +#include #include #include -namespace neurun +namespace onert { namespace ir { @@ -29,14 +29,14 @@ namespace ir OpSequenceIndex OpSequences::emplace(const OperationIndex &index, const Operation &node, Layout layout) { - std::unique_ptr subg = std::make_unique(layout); - subg->appendOperation(index, node); - return push(std::move(subg)); + std::unique_ptr op_seq = std::make_unique(layout); + op_seq->appendOperation(index, node); + return push(std::move(op_seq)); } -OpSequenceIndex OpSequences::emplace(std::unique_ptr &&subg) +OpSequenceIndex OpSequences::emplace(std::unique_ptr &&op_seq) { - return push(std::move(subg)); + return push(std::move(op_seq)); } bool OpSequences::containsOperation(const OperationIndex &operation_index) const @@ -55,17 +55,17 @@ OpSequenceIndex OpSequences::getOperation(const OperationIndex &operation_index) void OpSequences::dump(const std::string &msg) const { VERBOSE(OpSequences) << "OpSequences(" << msg << ")" << std::endl; - iterate([&](const OpSequenceIndex &idx, const OpSequence &subg) { - VERBOSE(OpSequences) << idx.value() << "] " << subg.getStr() << std::endl; + iterate([&](const OpSequenceIndex &idx, const OpSequence &op_seq) { + VERBOSE(OpSequences) << idx.value() << "] " << op_seq.getStr() << std::endl; }); } -void OpSequences::removeFromSubgraph(const OperationIndex &operation_index) +void OpSequences::removeFromOpSequence(const OperationIndex &operation_index) { const auto op_seq_index = findOperation(operation_index); - auto &subg = at(op_seq_index); - subg.remove(operation_index); - if (subg.size() == 0) + auto &op_seq = at(op_seq_index); + op_seq.remove(operation_index); + if (op_seq.size() == 0) { remove(op_seq_index); } @@ -85,4 +85,4 @@ OpSequenceIndex OpSequences::findOperation(const OperationIndex &operation_index } } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/Operand.cc b/runtime/onert/core/src/ir/Operand.cc similarity index 97% rename from runtime/neurun/core/src/ir/Operand.cc rename to runtime/onert/core/src/ir/Operand.cc index 15cf5a06198..39f9d6c90ee 100644 --- a/runtime/neurun/core/src/ir/Operand.cc +++ b/runtime/onert/core/src/ir/Operand.cc @@ -16,7 +16,7 @@ #include "ir/Operand.h" -namespace neurun +namespace onert { namespace ir { @@ -58,4 +58,4 @@ void Operand::removeDef(const OperationIndex &idx) } } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/OperandIndexSequence.cc b/runtime/onert/core/src/ir/OperandIndexSequence.cc similarity index 97% rename from runtime/neurun/core/src/ir/OperandIndexSequence.cc rename to runtime/onert/core/src/ir/OperandIndexSequence.cc index d0a318a5be5..2044310e777 100644 --- a/runtime/neurun/core/src/ir/OperandIndexSequence.cc +++ b/runtime/onert/core/src/ir/OperandIndexSequence.cc @@ -18,7 +18,7 @@ #include -namespace neurun +namespace onert { namespace ir { @@ -62,4 +62,4 @@ OperandIndexSequence OperandIndexSequence::operator+(const OperandIndexSequence } } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/Operands.cc b/runtime/onert/core/src/ir/Operands.cc similarity index 94% rename from runtime/neurun/core/src/ir/Operands.cc rename to runtime/onert/core/src/ir/Operands.cc index ebde3ce2eaf..ab32e478a4a 100644 --- a/runtime/neurun/core/src/ir/Operands.cc +++ b/runtime/onert/core/src/ir/Operands.cc @@ -16,10 +16,10 @@ #include "ir/Operands.h" -#include "memory" +#include #include "util/logging.h" -namespace neurun +namespace onert { namespace ir { @@ -33,4 +33,4 @@ Operands::Operands(const Operands &obj) } } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/Operation.cc b/runtime/onert/core/src/ir/Operation.cc similarity index 97% rename from runtime/neurun/core/src/ir/Operation.cc rename to runtime/onert/core/src/ir/Operation.cc index 3e4b606f201..d2a60747f02 100644 --- a/runtime/neurun/core/src/ir/Operation.cc +++ b/runtime/onert/core/src/ir/Operation.cc @@ -18,7 +18,7 @@ #include -namespace neurun +namespace onert { namespace ir { @@ -52,4 +52,4 @@ void Operation::replaceOutput(const OperandIndex &from, const OperandIndex &to) } } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/OperationCloner.cc b/runtime/onert/core/src/ir/OperationCloner.cc similarity index 96% rename from runtime/neurun/core/src/ir/OperationCloner.cc rename to runtime/onert/core/src/ir/OperationCloner.cc index b06f439c4e3..b4e60f0bc31 100644 --- a/runtime/neurun/core/src/ir/OperationCloner.cc +++ b/runtime/onert/core/src/ir/OperationCloner.cc @@ -18,7 +18,7 @@ #include -namespace neurun +namespace onert { namespace ir { @@ -39,4 +39,4 @@ std::unique_ptr OperationCloner::releaseClone() } } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/OperationCloner.h b/runtime/onert/core/src/ir/OperationCloner.h similarity index 84% rename from runtime/neurun/core/src/ir/OperationCloner.h rename to runtime/onert/core/src/ir/OperationCloner.h index b4883e04ada..0e8cda2a0f4 100644 --- a/runtime/neurun/core/src/ir/OperationCloner.h +++ b/runtime/onert/core/src/ir/OperationCloner.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_OPERATION_CLONER_H__ -#define __NEURUN_IR_OPERATION_CLONER_H__ +#ifndef __ONERT_IR_OPERATION_CLONER_H__ +#define __ONERT_IR_OPERATION_CLONER_H__ -#include "memory" +#include #include "ir/OperationVisitor.h" #include "ir/Operation.h" -namespace neurun +namespace onert { namespace ir { @@ -41,6 +41,6 @@ class OperationCloner : public OperationVisitor }; } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_OPERATION_CLONER_H__ +#endif // __ONERT_IR_OPERATION_CLONER_H__ diff --git a/runtime/neurun/core/src/ir/OperationDumper.cc b/runtime/onert/core/src/ir/OperationDumper.cc similarity index 98% rename from runtime/neurun/core/src/ir/OperationDumper.cc rename to runtime/onert/core/src/ir/OperationDumper.cc index 2dfa4c95e1a..789d2869d21 100644 --- a/runtime/neurun/core/src/ir/OperationDumper.cc +++ b/runtime/onert/core/src/ir/OperationDumper.cc @@ -20,7 +20,7 @@ #include "util/logging.h" -namespace neurun +namespace onert { namespace ir { @@ -432,11 +432,19 @@ void OperationDumper::visit(const ReLU6 &node) void OperationDumper::visit(const Reshape &node) { VERBOSE(LIR) << "* Reshape" << std::endl; - // TODO The shape index should be "node.getInputs().at(1).value()" but not valid for now VERBOSE(LIR) << " - Inputs : Input(" << node.getInputs().at(Reshape::Input::INPUT).value() - << ") Shape(" - << "?" - << ")" << std::endl; + << ")"; + // optional param + if (node.getInputs().size() == 2) + { + VERBOSE(LIR) << " Shape(" << node.getInputs().at(Reshape::Input::SHAPE).value() << ")"; + } + else + { + VERBOSE(LIR) << " Shape(not provided)"; + } + VERBOSE(LIR) << std::endl; + VERBOSE(LIR) << " - Output : Output(" << node.getOutputs().at(0).value() << ")" << std::endl; } @@ -623,4 +631,4 @@ void OperationDumper::visit(const OneHot &node) } } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/OperationDumper.h b/runtime/onert/core/src/ir/OperationDumper.h similarity index 96% rename from runtime/neurun/core/src/ir/OperationDumper.h rename to runtime/onert/core/src/ir/OperationDumper.h index 20441e2aad9..77d100ceef7 100644 --- a/runtime/neurun/core/src/ir/OperationDumper.h +++ b/runtime/onert/core/src/ir/OperationDumper.h @@ -14,12 +14,12 @@ * limitations under the License. */ -#ifndef __NEURUN_OPERATION_DUMPER_H__ -#define __NEURUN_OPERATION_DUMPER_H__ +#ifndef __ONERT_OPERATION_DUMPER_H__ +#define __ONERT_OPERATION_DUMPER_H__ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -94,6 +94,6 @@ class OperationDumper : public OperationVisitor }; } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_OPERATION_DUMPER_H__ +#endif // __ONERT_OPERATION_DUMPER_H__ diff --git a/runtime/neurun/core/src/ir/OperationIndexList.cc b/runtime/onert/core/src/ir/OperationIndexList.cc similarity index 96% rename from runtime/neurun/core/src/ir/OperationIndexList.cc rename to runtime/onert/core/src/ir/OperationIndexList.cc index 261cc5ce6b1..bf51f9abbc1 100644 --- a/runtime/neurun/core/src/ir/OperationIndexList.cc +++ b/runtime/onert/core/src/ir/OperationIndexList.cc @@ -18,7 +18,7 @@ #include -namespace neurun +namespace onert { namespace ir { @@ -34,4 +34,4 @@ bool OperationIndexList::contains(const OperationIndex &index) const } } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/Operations.cc b/runtime/onert/core/src/ir/Operations.cc similarity index 96% rename from runtime/neurun/core/src/ir/Operations.cc rename to runtime/onert/core/src/ir/Operations.cc index 4dc5ed09de5..64d0bd6f078 100644 --- a/runtime/neurun/core/src/ir/Operations.cc +++ b/runtime/onert/core/src/ir/Operations.cc @@ -18,7 +18,7 @@ #include "OperationCloner.h" -namespace neurun +namespace onert { namespace ir { @@ -34,4 +34,4 @@ Operations::Operations(const Operations &obj) } } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/Padding.cc b/runtime/onert/core/src/ir/Padding.cc similarity index 99% rename from runtime/neurun/core/src/ir/Padding.cc rename to runtime/onert/core/src/ir/Padding.cc index 01dad703c6d..31969911f23 100644 --- a/runtime/neurun/core/src/ir/Padding.cc +++ b/runtime/onert/core/src/ir/Padding.cc @@ -21,7 +21,7 @@ #include #include -namespace neurun +namespace onert { namespace ir { @@ -151,4 +151,4 @@ const ExplicitPadding calculatePadding(const Padding &padding, const FeatureShap } } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/Shape.cc b/runtime/onert/core/src/ir/Shape.cc similarity index 98% rename from runtime/neurun/core/src/ir/Shape.cc rename to runtime/onert/core/src/ir/Shape.cc index 4364ec79d97..92999a4fa8e 100644 --- a/runtime/neurun/core/src/ir/Shape.cc +++ b/runtime/onert/core/src/ir/Shape.cc @@ -21,7 +21,7 @@ #include #include -namespace neurun +namespace onert { namespace ir { @@ -101,4 +101,4 @@ Shape permuteShape(const Shape &shape, Layout frontend_layout, Layout backend_la } } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/TypeInfo.cc b/runtime/onert/core/src/ir/TypeInfo.cc similarity index 96% rename from runtime/neurun/core/src/ir/TypeInfo.cc rename to runtime/onert/core/src/ir/TypeInfo.cc index 280146b511d..ab8af287e04 100644 --- a/runtime/neurun/core/src/ir/TypeInfo.cc +++ b/runtime/onert/core/src/ir/TypeInfo.cc @@ -16,7 +16,7 @@ #include "ir/TypeInfo.h" -namespace neurun +namespace onert { namespace ir { @@ -44,4 +44,4 @@ bool operator==(const TypeInfo &lhs, const TypeInfo &rhs) bool operator!=(const TypeInfo &lhs, const TypeInfo &rhs) { return !(lhs == rhs); } } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/Abs.cc b/runtime/onert/core/src/ir/operation/Abs.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/Abs.cc rename to runtime/onert/core/src/ir/operation/Abs.cc index 9506f83d23b..b06705d07e5 100644 --- a/runtime/neurun/core/src/ir/operation/Abs.cc +++ b/runtime/onert/core/src/ir/operation/Abs.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -36,4 +36,4 @@ Abs::Abs(const OperandIndexSequence &inputs, const OperandIndexSequence &outputs } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/Add.cc b/runtime/onert/core/src/ir/operation/Add.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/Add.cc rename to runtime/onert/core/src/ir/operation/Add.cc index a7c40c37a6e..2fa30f8edab 100644 --- a/runtime/neurun/core/src/ir/operation/Add.cc +++ b/runtime/onert/core/src/ir/operation/Add.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -37,4 +37,4 @@ Add::Add(const OperandIndexSequence &inputs, const OperandIndexSequence &outputs } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/ArgMax.cc b/runtime/onert/core/src/ir/operation/ArgMax.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/ArgMax.cc rename to runtime/onert/core/src/ir/operation/ArgMax.cc index 200abc7ddff..1275ae43a7d 100644 --- a/runtime/neurun/core/src/ir/operation/ArgMax.cc +++ b/runtime/onert/core/src/ir/operation/ArgMax.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -37,4 +37,4 @@ ArgMax::ArgMax(const OperandIndexSequence &inputs, const OperandIndexSequence &o } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/AvgPool2D.cc b/runtime/onert/core/src/ir/operation/AvgPool2D.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/AvgPool2D.cc rename to runtime/onert/core/src/ir/operation/AvgPool2D.cc index 21ec052ebf3..28d4fcb541a 100644 --- a/runtime/neurun/core/src/ir/operation/AvgPool2D.cc +++ b/runtime/onert/core/src/ir/operation/AvgPool2D.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -37,4 +37,4 @@ AvgPool2D::AvgPool2D(const OperandIndexSequence &inputs, const OperandIndexSeque } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/BatchToSpaceND.cc b/runtime/onert/core/src/ir/operation/BatchToSpaceND.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/BatchToSpaceND.cc rename to runtime/onert/core/src/ir/operation/BatchToSpaceND.cc index 042144c121f..0b3955c5cb1 100644 --- a/runtime/neurun/core/src/ir/operation/BatchToSpaceND.cc +++ b/runtime/onert/core/src/ir/operation/BatchToSpaceND.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -37,4 +37,4 @@ BatchToSpaceND::BatchToSpaceND(const OperandIndexSequence &inputs, } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/Cast.cc b/runtime/onert/core/src/ir/operation/Cast.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/Cast.cc rename to runtime/onert/core/src/ir/operation/Cast.cc index 095225ecafd..09d9c327e71 100644 --- a/runtime/neurun/core/src/ir/operation/Cast.cc +++ b/runtime/onert/core/src/ir/operation/Cast.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -36,4 +36,4 @@ Cast::Cast(const OperandIndexSequence &inputs, const OperandIndexSequence &outpu } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/Comparison.cc b/runtime/onert/core/src/ir/operation/Comparison.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/Comparison.cc rename to runtime/onert/core/src/ir/operation/Comparison.cc index 995d567640e..2f67754113f 100644 --- a/runtime/neurun/core/src/ir/operation/Comparison.cc +++ b/runtime/onert/core/src/ir/operation/Comparison.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -37,4 +37,4 @@ Comparison::Comparison(const OperandIndexSequence &inputs, const OperandIndexSeq } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/Concat.cc b/runtime/onert/core/src/ir/operation/Concat.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/Concat.cc rename to runtime/onert/core/src/ir/operation/Concat.cc index 1772da1fc6b..608bc29a691 100644 --- a/runtime/neurun/core/src/ir/operation/Concat.cc +++ b/runtime/onert/core/src/ir/operation/Concat.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -37,4 +37,4 @@ Concat::Concat(const OperandIndexSequence &inputs, const OperandIndexSequence &o } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/Conv2D.cc b/runtime/onert/core/src/ir/operation/Conv2D.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/Conv2D.cc rename to runtime/onert/core/src/ir/operation/Conv2D.cc index 505e916a9f0..3a2e1d1fe7e 100644 --- a/runtime/neurun/core/src/ir/operation/Conv2D.cc +++ b/runtime/onert/core/src/ir/operation/Conv2D.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -37,4 +37,4 @@ Conv2D::Conv2D(const OperandIndexSequence &inputs, const OperandIndexSequence &o } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/Custom.cc b/runtime/onert/core/src/ir/operation/Custom.cc similarity index 97% rename from runtime/neurun/core/src/ir/operation/Custom.cc rename to runtime/onert/core/src/ir/operation/Custom.cc index b8acd87a929..25c53e1ba4e 100644 --- a/runtime/neurun/core/src/ir/operation/Custom.cc +++ b/runtime/onert/core/src/ir/operation/Custom.cc @@ -18,7 +18,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -41,4 +41,4 @@ std::string Custom::name() const { return id(); } } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/DepthToSpace.cc b/runtime/onert/core/src/ir/operation/DepthToSpace.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/DepthToSpace.cc rename to runtime/onert/core/src/ir/operation/DepthToSpace.cc index fd1d1f1aab4..f2d6c7c1bc7 100644 --- a/runtime/neurun/core/src/ir/operation/DepthToSpace.cc +++ b/runtime/onert/core/src/ir/operation/DepthToSpace.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -37,4 +37,4 @@ DepthToSpace::DepthToSpace(const OperandIndexSequence &inputs, const OperandInde } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/DepthwiseConv2D.cc b/runtime/onert/core/src/ir/operation/DepthwiseConv2D.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/DepthwiseConv2D.cc rename to runtime/onert/core/src/ir/operation/DepthwiseConv2D.cc index ed76594a360..d587a5591cd 100644 --- a/runtime/neurun/core/src/ir/operation/DepthwiseConv2D.cc +++ b/runtime/onert/core/src/ir/operation/DepthwiseConv2D.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -37,4 +37,4 @@ DepthwiseConv2D::DepthwiseConv2D(const OperandIndexSequence &inputs, } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/Dequantize.cc b/runtime/onert/core/src/ir/operation/Dequantize.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/Dequantize.cc rename to runtime/onert/core/src/ir/operation/Dequantize.cc index e99a59cb7fb..14d6362bd40 100644 --- a/runtime/neurun/core/src/ir/operation/Dequantize.cc +++ b/runtime/onert/core/src/ir/operation/Dequantize.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -36,4 +36,4 @@ Dequantize::Dequantize(const OperandIndexSequence &inputs, const OperandIndexSeq } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/Div.cc b/runtime/onert/core/src/ir/operation/Div.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/Div.cc rename to runtime/onert/core/src/ir/operation/Div.cc index 484406ff32f..b095d981182 100644 --- a/runtime/neurun/core/src/ir/operation/Div.cc +++ b/runtime/onert/core/src/ir/operation/Div.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -37,4 +37,4 @@ Div::Div(const OperandIndexSequence &inputs, const OperandIndexSequence &outputs } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/EmbeddingLookup.cc b/runtime/onert/core/src/ir/operation/EmbeddingLookup.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/EmbeddingLookup.cc rename to runtime/onert/core/src/ir/operation/EmbeddingLookup.cc index 206e6bfaa4e..b300b004ed2 100644 --- a/runtime/neurun/core/src/ir/operation/EmbeddingLookup.cc +++ b/runtime/onert/core/src/ir/operation/EmbeddingLookup.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -37,4 +37,4 @@ EmbeddingLookup::EmbeddingLookup(const OperandIndexSequence &inputs, } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/Exp.cc b/runtime/onert/core/src/ir/operation/Exp.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/Exp.cc rename to runtime/onert/core/src/ir/operation/Exp.cc index 3c0e0cf9b38..0b22e080a55 100644 --- a/runtime/neurun/core/src/ir/operation/Exp.cc +++ b/runtime/onert/core/src/ir/operation/Exp.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -36,4 +36,4 @@ Exp::Exp(const OperandIndexSequence &inputs, const OperandIndexSequence &outputs } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/Floor.cc b/runtime/onert/core/src/ir/operation/Floor.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/Floor.cc rename to runtime/onert/core/src/ir/operation/Floor.cc index 75373cd4118..dc01535ad9d 100644 --- a/runtime/neurun/core/src/ir/operation/Floor.cc +++ b/runtime/onert/core/src/ir/operation/Floor.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -36,4 +36,4 @@ Floor::Floor(const OperandIndexSequence &inputs, const OperandIndexSequence &out } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/FullyConnected.cc b/runtime/onert/core/src/ir/operation/FullyConnected.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/FullyConnected.cc rename to runtime/onert/core/src/ir/operation/FullyConnected.cc index 9560c0593ff..118ae554a75 100644 --- a/runtime/neurun/core/src/ir/operation/FullyConnected.cc +++ b/runtime/onert/core/src/ir/operation/FullyConnected.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -37,4 +37,4 @@ FullyConnected::FullyConnected(const OperandIndexSequence &inputs, } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/Gather.cc b/runtime/onert/core/src/ir/operation/Gather.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/Gather.cc rename to runtime/onert/core/src/ir/operation/Gather.cc index f98cef9ae97..11d46e75ba3 100644 --- a/runtime/neurun/core/src/ir/operation/Gather.cc +++ b/runtime/onert/core/src/ir/operation/Gather.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -37,4 +37,4 @@ Gather::Gather(const OperandIndexSequence &inputs, const OperandIndexSequence &o } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/HashtableLookup.cc b/runtime/onert/core/src/ir/operation/HashtableLookup.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/HashtableLookup.cc rename to runtime/onert/core/src/ir/operation/HashtableLookup.cc index ecb9d31958c..e9a7a82ff38 100644 --- a/runtime/neurun/core/src/ir/operation/HashtableLookup.cc +++ b/runtime/onert/core/src/ir/operation/HashtableLookup.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -37,4 +37,4 @@ HashtableLookup::HashtableLookup(const OperandIndexSequence &inputs, } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/InstanceNorm.cc b/runtime/onert/core/src/ir/operation/InstanceNorm.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/InstanceNorm.cc rename to runtime/onert/core/src/ir/operation/InstanceNorm.cc index 69e47abd4e5..2334560ef05 100644 --- a/runtime/neurun/core/src/ir/operation/InstanceNorm.cc +++ b/runtime/onert/core/src/ir/operation/InstanceNorm.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -37,4 +37,4 @@ InstanceNorm::InstanceNorm(const OperandIndexSequence &inputs, const OperandInde } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/L2Normalization.cc b/runtime/onert/core/src/ir/operation/L2Normalization.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/L2Normalization.cc rename to runtime/onert/core/src/ir/operation/L2Normalization.cc index 67085989ee1..d1c92fa8b9f 100644 --- a/runtime/neurun/core/src/ir/operation/L2Normalization.cc +++ b/runtime/onert/core/src/ir/operation/L2Normalization.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -37,4 +37,4 @@ L2Normalization::L2Normalization(const OperandIndexSequence &inputs, } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/L2Pool2D.cc b/runtime/onert/core/src/ir/operation/L2Pool2D.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/L2Pool2D.cc rename to runtime/onert/core/src/ir/operation/L2Pool2D.cc index 0815cb5abf1..8f21b93e0fd 100644 --- a/runtime/neurun/core/src/ir/operation/L2Pool2D.cc +++ b/runtime/onert/core/src/ir/operation/L2Pool2D.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -37,4 +37,4 @@ L2Pool2D::L2Pool2D(const OperandIndexSequence &inputs, const OperandIndexSequenc } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/LSTM.cc b/runtime/onert/core/src/ir/operation/LSTM.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/LSTM.cc rename to runtime/onert/core/src/ir/operation/LSTM.cc index 58e2aa32e3a..30a865326cd 100644 --- a/runtime/neurun/core/src/ir/operation/LSTM.cc +++ b/runtime/onert/core/src/ir/operation/LSTM.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -37,4 +37,4 @@ LSTM::LSTM(const OperandIndexSequence &inputs, const OperandIndexSequence &outpu } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/LocalResponseNormalization.cc b/runtime/onert/core/src/ir/operation/LocalResponseNormalization.cc similarity index 97% rename from runtime/neurun/core/src/ir/operation/LocalResponseNormalization.cc rename to runtime/onert/core/src/ir/operation/LocalResponseNormalization.cc index dcba7f1cb43..1ae97c14233 100644 --- a/runtime/neurun/core/src/ir/operation/LocalResponseNormalization.cc +++ b/runtime/onert/core/src/ir/operation/LocalResponseNormalization.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -38,4 +38,4 @@ LocalResponseNormalization::LocalResponseNormalization(const OperandIndexSequenc } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/LogicalAnd.cc b/runtime/onert/core/src/ir/operation/LogicalAnd.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/LogicalAnd.cc rename to runtime/onert/core/src/ir/operation/LogicalAnd.cc index 51f4f0ee0a4..0d50706ca52 100644 --- a/runtime/neurun/core/src/ir/operation/LogicalAnd.cc +++ b/runtime/onert/core/src/ir/operation/LogicalAnd.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -36,4 +36,4 @@ LogicalAnd::LogicalAnd(const OperandIndexSequence &inputs, const OperandIndexSeq } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/LogicalNot.cc b/runtime/onert/core/src/ir/operation/LogicalNot.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/LogicalNot.cc rename to runtime/onert/core/src/ir/operation/LogicalNot.cc index 48c25142aff..8f114210247 100644 --- a/runtime/neurun/core/src/ir/operation/LogicalNot.cc +++ b/runtime/onert/core/src/ir/operation/LogicalNot.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -36,4 +36,4 @@ LogicalNot::LogicalNot(const OperandIndexSequence &inputs, const OperandIndexSeq } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/LogicalOr.cc b/runtime/onert/core/src/ir/operation/LogicalOr.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/LogicalOr.cc rename to runtime/onert/core/src/ir/operation/LogicalOr.cc index 663b7deb52d..d75207c4ae6 100644 --- a/runtime/neurun/core/src/ir/operation/LogicalOr.cc +++ b/runtime/onert/core/src/ir/operation/LogicalOr.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -36,4 +36,4 @@ LogicalOr::LogicalOr(const OperandIndexSequence &inputs, const OperandIndexSeque } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/Logistic.cc b/runtime/onert/core/src/ir/operation/Logistic.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/Logistic.cc rename to runtime/onert/core/src/ir/operation/Logistic.cc index 3ed2f3453e5..77d9d17de1f 100644 --- a/runtime/neurun/core/src/ir/operation/Logistic.cc +++ b/runtime/onert/core/src/ir/operation/Logistic.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -36,4 +36,4 @@ Logistic::Logistic(const OperandIndexSequence &inputs, const OperandIndexSequenc } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/LowerInfo.cc b/runtime/onert/core/src/ir/operation/LowerInfo.cc similarity index 95% rename from runtime/neurun/core/src/ir/operation/LowerInfo.cc rename to runtime/onert/core/src/ir/operation/LowerInfo.cc index 6133be3f823..249918bd63e 100644 --- a/runtime/neurun/core/src/ir/operation/LowerInfo.cc +++ b/runtime/onert/core/src/ir/operation/LowerInfo.cc @@ -16,7 +16,7 @@ #include "ir/operation/LowerInfo.h" -namespace neurun +namespace onert { namespace ir { @@ -31,4 +31,4 @@ LowerInfo::LowerInfo(const backend::Backend *backend, Layout layout) } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/Max.cc b/runtime/onert/core/src/ir/operation/Max.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/Max.cc rename to runtime/onert/core/src/ir/operation/Max.cc index be4bdd365a1..281f9d451e5 100644 --- a/runtime/neurun/core/src/ir/operation/Max.cc +++ b/runtime/onert/core/src/ir/operation/Max.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -36,4 +36,4 @@ Max::Max(const OperandIndexSequence &inputs, const OperandIndexSequence &outputs } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/MaxPool2D.cc b/runtime/onert/core/src/ir/operation/MaxPool2D.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/MaxPool2D.cc rename to runtime/onert/core/src/ir/operation/MaxPool2D.cc index 8f1b70cd6da..eac53cc5ea4 100644 --- a/runtime/neurun/core/src/ir/operation/MaxPool2D.cc +++ b/runtime/onert/core/src/ir/operation/MaxPool2D.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -37,4 +37,4 @@ MaxPool2D::MaxPool2D(const OperandIndexSequence &inputs, const OperandIndexSeque } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/Mean.cc b/runtime/onert/core/src/ir/operation/Mean.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/Mean.cc rename to runtime/onert/core/src/ir/operation/Mean.cc index 016b5dd8588..5313a4434af 100644 --- a/runtime/neurun/core/src/ir/operation/Mean.cc +++ b/runtime/onert/core/src/ir/operation/Mean.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -37,4 +37,4 @@ Mean::Mean(const OperandIndexSequence &inputs, const OperandIndexSequence &outpu } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/Min.cc b/runtime/onert/core/src/ir/operation/Min.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/Min.cc rename to runtime/onert/core/src/ir/operation/Min.cc index a864405dc48..8be7f0cc8bd 100644 --- a/runtime/neurun/core/src/ir/operation/Min.cc +++ b/runtime/onert/core/src/ir/operation/Min.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -36,4 +36,4 @@ Min::Min(const OperandIndexSequence &inputs, const OperandIndexSequence &outputs } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/Mul.cc b/runtime/onert/core/src/ir/operation/Mul.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/Mul.cc rename to runtime/onert/core/src/ir/operation/Mul.cc index 0b2d67a9d30..03cdf1b61b7 100644 --- a/runtime/neurun/core/src/ir/operation/Mul.cc +++ b/runtime/onert/core/src/ir/operation/Mul.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -37,4 +37,4 @@ Mul::Mul(const OperandIndexSequence &inputs, const OperandIndexSequence &outputs } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/Neg.cc b/runtime/onert/core/src/ir/operation/Neg.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/Neg.cc rename to runtime/onert/core/src/ir/operation/Neg.cc index 65922d57c45..df623a13b24 100644 --- a/runtime/neurun/core/src/ir/operation/Neg.cc +++ b/runtime/onert/core/src/ir/operation/Neg.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -36,4 +36,4 @@ Neg::Neg(const OperandIndexSequence &inputs, const OperandIndexSequence &outputs } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/OneHot.cc b/runtime/onert/core/src/ir/operation/OneHot.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/OneHot.cc rename to runtime/onert/core/src/ir/operation/OneHot.cc index 0ba3c9d60e5..22935e7d622 100644 --- a/runtime/neurun/core/src/ir/operation/OneHot.cc +++ b/runtime/onert/core/src/ir/operation/OneHot.cc @@ -17,7 +17,7 @@ #include "ir/operation/OneHot.h" #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -34,4 +34,4 @@ OneHot::OneHot(const OperandIndexSequence &inputs, const OperandIndexSequence &o } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/PReLU.cc b/runtime/onert/core/src/ir/operation/PReLU.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/PReLU.cc rename to runtime/onert/core/src/ir/operation/PReLU.cc index b8555ccbd49..a2e37e0ad19 100644 --- a/runtime/neurun/core/src/ir/operation/PReLU.cc +++ b/runtime/onert/core/src/ir/operation/PReLU.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -36,4 +36,4 @@ PReLU::PReLU(const OperandIndexSequence &inputs, const OperandIndexSequence &out } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/Pack.cc b/runtime/onert/core/src/ir/operation/Pack.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/Pack.cc rename to runtime/onert/core/src/ir/operation/Pack.cc index 412c744eab5..f0908a2c693 100644 --- a/runtime/neurun/core/src/ir/operation/Pack.cc +++ b/runtime/onert/core/src/ir/operation/Pack.cc @@ -16,7 +16,7 @@ #include "ir/operation/Pack.h" #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -30,4 +30,4 @@ Pack::Pack(const OperandIndexSequence &inputs, const OperandIndexSequence &outpu } } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/Pad.cc b/runtime/onert/core/src/ir/operation/Pad.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/Pad.cc rename to runtime/onert/core/src/ir/operation/Pad.cc index a08be12a69d..a958b524153 100644 --- a/runtime/neurun/core/src/ir/operation/Pad.cc +++ b/runtime/onert/core/src/ir/operation/Pad.cc @@ -18,7 +18,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -35,4 +35,4 @@ Pad::Pad(const OperandIndexSequence &inputs, const OperandIndexSequence &outputs } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/Permute.cc b/runtime/onert/core/src/ir/operation/Permute.cc similarity index 97% rename from runtime/neurun/core/src/ir/operation/Permute.cc rename to runtime/onert/core/src/ir/operation/Permute.cc index ec3d969c8ad..fd495ed4b38 100644 --- a/runtime/neurun/core/src/ir/operation/Permute.cc +++ b/runtime/onert/core/src/ir/operation/Permute.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -41,4 +41,4 @@ Permute::Permute(const OperandIndex &input, const OperandIndex &output, } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/RNN.cc b/runtime/onert/core/src/ir/operation/RNN.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/RNN.cc rename to runtime/onert/core/src/ir/operation/RNN.cc index 8db5cbceb26..298c5e745e4 100644 --- a/runtime/neurun/core/src/ir/operation/RNN.cc +++ b/runtime/onert/core/src/ir/operation/RNN.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -37,4 +37,4 @@ RNN::RNN(const OperandIndexSequence &inputs, const OperandIndexSequence &outputs } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/RSQRT.cc b/runtime/onert/core/src/ir/operation/RSQRT.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/RSQRT.cc rename to runtime/onert/core/src/ir/operation/RSQRT.cc index ec13b20ece8..2bce1fa28cd 100644 --- a/runtime/neurun/core/src/ir/operation/RSQRT.cc +++ b/runtime/onert/core/src/ir/operation/RSQRT.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -36,4 +36,4 @@ RSQRT::RSQRT(const OperandIndexSequence &inputs, const OperandIndexSequence &out } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/ReLU.cc b/runtime/onert/core/src/ir/operation/ReLU.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/ReLU.cc rename to runtime/onert/core/src/ir/operation/ReLU.cc index 6b3f7e72d21..f0c88478bb5 100644 --- a/runtime/neurun/core/src/ir/operation/ReLU.cc +++ b/runtime/onert/core/src/ir/operation/ReLU.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -36,4 +36,4 @@ ReLU::ReLU(const OperandIndexSequence &inputs, const OperandIndexSequence &outpu } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/ReLU1.cc b/runtime/onert/core/src/ir/operation/ReLU1.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/ReLU1.cc rename to runtime/onert/core/src/ir/operation/ReLU1.cc index d7b4e1b11cc..734f0b65be8 100644 --- a/runtime/neurun/core/src/ir/operation/ReLU1.cc +++ b/runtime/onert/core/src/ir/operation/ReLU1.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -36,4 +36,4 @@ ReLU1::ReLU1(const OperandIndexSequence &inputs, const OperandIndexSequence &out } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/ReLU6.cc b/runtime/onert/core/src/ir/operation/ReLU6.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/ReLU6.cc rename to runtime/onert/core/src/ir/operation/ReLU6.cc index 245eb923f22..5972329af82 100644 --- a/runtime/neurun/core/src/ir/operation/ReLU6.cc +++ b/runtime/onert/core/src/ir/operation/ReLU6.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -36,4 +36,4 @@ ReLU6::ReLU6(const OperandIndexSequence &inputs, const OperandIndexSequence &out } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/ReduceMax.cc b/runtime/onert/core/src/ir/operation/ReduceMax.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/ReduceMax.cc rename to runtime/onert/core/src/ir/operation/ReduceMax.cc index b7ef2c5a946..f7faf874413 100644 --- a/runtime/neurun/core/src/ir/operation/ReduceMax.cc +++ b/runtime/onert/core/src/ir/operation/ReduceMax.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -37,4 +37,4 @@ ReduceMax::ReduceMax(const OperandIndexSequence &inputs, const OperandIndexSeque } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/ReduceMin.cc b/runtime/onert/core/src/ir/operation/ReduceMin.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/ReduceMin.cc rename to runtime/onert/core/src/ir/operation/ReduceMin.cc index 84d7e0cc51b..83cdccb7889 100644 --- a/runtime/neurun/core/src/ir/operation/ReduceMin.cc +++ b/runtime/onert/core/src/ir/operation/ReduceMin.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -37,4 +37,4 @@ ReduceMin::ReduceMin(const OperandIndexSequence &inputs, const OperandIndexSeque } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/ReduceSum.cc b/runtime/onert/core/src/ir/operation/ReduceSum.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/ReduceSum.cc rename to runtime/onert/core/src/ir/operation/ReduceSum.cc index 7e3b19bd604..c25a5ac5c92 100644 --- a/runtime/neurun/core/src/ir/operation/ReduceSum.cc +++ b/runtime/onert/core/src/ir/operation/ReduceSum.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -37,4 +37,4 @@ ReduceSum::ReduceSum(const OperandIndexSequence &inputs, const OperandIndexSeque } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/Reshape.cc b/runtime/onert/core/src/ir/operation/Reshape.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/Reshape.cc rename to runtime/onert/core/src/ir/operation/Reshape.cc index bae37e12f9d..b3a0d30b608 100644 --- a/runtime/neurun/core/src/ir/operation/Reshape.cc +++ b/runtime/onert/core/src/ir/operation/Reshape.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -36,4 +36,4 @@ Reshape::Reshape(const OperandIndexSequence &inputs, const OperandIndexSequence } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/ResizeBilinear.cc b/runtime/onert/core/src/ir/operation/ResizeBilinear.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/ResizeBilinear.cc rename to runtime/onert/core/src/ir/operation/ResizeBilinear.cc index 55ae4815dec..d0d89f45f60 100644 --- a/runtime/neurun/core/src/ir/operation/ResizeBilinear.cc +++ b/runtime/onert/core/src/ir/operation/ResizeBilinear.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -37,4 +37,4 @@ ResizeBilinear::ResizeBilinear(const OperandIndexSequence &inputs, } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/SQRT.cc b/runtime/onert/core/src/ir/operation/SQRT.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/SQRT.cc rename to runtime/onert/core/src/ir/operation/SQRT.cc index 6c6daa3a098..ad887d89aed 100644 --- a/runtime/neurun/core/src/ir/operation/SQRT.cc +++ b/runtime/onert/core/src/ir/operation/SQRT.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -36,4 +36,4 @@ SQRT::SQRT(const OperandIndexSequence &inputs, const OperandIndexSequence &outpu } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/onert/core/src/ir/operation/Sin.cc b/runtime/onert/core/src/ir/operation/Sin.cc new file mode 100644 index 00000000000..631505f3649 --- /dev/null +++ b/runtime/onert/core/src/ir/operation/Sin.cc @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2020 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 "ir/operation/Sin.h" + +#include + +#include "ir/OperationVisitor.h" + +namespace onert +{ +namespace ir +{ +namespace operation +{ + +void Sin::accept(OperationVisitor &v) const { v.visit(*this); } + +Sin::Sin(const OperandIndexSequence &inputs, const OperandIndexSequence &outputs) + : Operation{OperandConstraint::createExact(1u), inputs, outputs} +{ +} + +} // namespace operation +} // namespace ir +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/Slice.cc b/runtime/onert/core/src/ir/operation/Slice.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/Slice.cc rename to runtime/onert/core/src/ir/operation/Slice.cc index 88014d1e465..674bd709324 100644 --- a/runtime/neurun/core/src/ir/operation/Slice.cc +++ b/runtime/onert/core/src/ir/operation/Slice.cc @@ -17,7 +17,7 @@ #include "ir/operation/Slice.h" #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -34,4 +34,4 @@ Slice::Slice(const OperandIndexSequence &inputs, const OperandIndexSequence &out } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/Softmax.cc b/runtime/onert/core/src/ir/operation/Softmax.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/Softmax.cc rename to runtime/onert/core/src/ir/operation/Softmax.cc index 6b3a6b16421..3f1aa0af130 100644 --- a/runtime/neurun/core/src/ir/operation/Softmax.cc +++ b/runtime/onert/core/src/ir/operation/Softmax.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -37,4 +37,4 @@ Softmax::Softmax(const OperandIndexSequence &inputs, const OperandIndexSequence } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/SpaceToBatchND.cc b/runtime/onert/core/src/ir/operation/SpaceToBatchND.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/SpaceToBatchND.cc rename to runtime/onert/core/src/ir/operation/SpaceToBatchND.cc index a07453504cc..53fab4fa95e 100644 --- a/runtime/neurun/core/src/ir/operation/SpaceToBatchND.cc +++ b/runtime/onert/core/src/ir/operation/SpaceToBatchND.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -37,4 +37,4 @@ SpaceToBatchND::SpaceToBatchND(const OperandIndexSequence &inputs, } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/SpaceToDepth.cc b/runtime/onert/core/src/ir/operation/SpaceToDepth.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/SpaceToDepth.cc rename to runtime/onert/core/src/ir/operation/SpaceToDepth.cc index ca16bd92fc8..d8a45aee5b5 100644 --- a/runtime/neurun/core/src/ir/operation/SpaceToDepth.cc +++ b/runtime/onert/core/src/ir/operation/SpaceToDepth.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -37,4 +37,4 @@ SpaceToDepth::SpaceToDepth(const OperandIndexSequence &inputs, const OperandInde } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/Split.cc b/runtime/onert/core/src/ir/operation/Split.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/Split.cc rename to runtime/onert/core/src/ir/operation/Split.cc index a4b15a9b292..244884e4196 100644 --- a/runtime/neurun/core/src/ir/operation/Split.cc +++ b/runtime/onert/core/src/ir/operation/Split.cc @@ -16,7 +16,7 @@ #include "ir/operation/Split.h" #include #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -30,4 +30,4 @@ Split::Split(const OperandIndexSequence &inputs, const OperandIndexSequence &out } } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/SquaredDifference.cc b/runtime/onert/core/src/ir/operation/SquaredDifference.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/SquaredDifference.cc rename to runtime/onert/core/src/ir/operation/SquaredDifference.cc index 141fb7560c4..49e58aaf233 100644 --- a/runtime/neurun/core/src/ir/operation/SquaredDifference.cc +++ b/runtime/onert/core/src/ir/operation/SquaredDifference.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -37,4 +37,4 @@ SquaredDifference::SquaredDifference(const OperandIndexSequence &inputs, } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/Squeeze.cc b/runtime/onert/core/src/ir/operation/Squeeze.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/Squeeze.cc rename to runtime/onert/core/src/ir/operation/Squeeze.cc index 22ee5763d76..8cf928fb4da 100644 --- a/runtime/neurun/core/src/ir/operation/Squeeze.cc +++ b/runtime/onert/core/src/ir/operation/Squeeze.cc @@ -17,7 +17,7 @@ #include "ir/operation/Squeeze.h" #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -34,4 +34,4 @@ Squeeze::Squeeze(const OperandIndexSequence &inputs, const OperandIndexSequence } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/StridedSlice.cc b/runtime/onert/core/src/ir/operation/StridedSlice.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/StridedSlice.cc rename to runtime/onert/core/src/ir/operation/StridedSlice.cc index f764dccc00a..adc8beaa3f9 100644 --- a/runtime/neurun/core/src/ir/operation/StridedSlice.cc +++ b/runtime/onert/core/src/ir/operation/StridedSlice.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -37,4 +37,4 @@ StridedSlice::StridedSlice(const OperandIndexSequence &inputs, const OperandInde } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/Sub.cc b/runtime/onert/core/src/ir/operation/Sub.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/Sub.cc rename to runtime/onert/core/src/ir/operation/Sub.cc index 7d83e3d74dc..d71071686a4 100644 --- a/runtime/neurun/core/src/ir/operation/Sub.cc +++ b/runtime/onert/core/src/ir/operation/Sub.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -37,4 +37,4 @@ Sub::Sub(const OperandIndexSequence &inputs, const OperandIndexSequence &outputs } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/Tanh.cc b/runtime/onert/core/src/ir/operation/Tanh.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/Tanh.cc rename to runtime/onert/core/src/ir/operation/Tanh.cc index a3125e94783..8fab0c0f30a 100644 --- a/runtime/neurun/core/src/ir/operation/Tanh.cc +++ b/runtime/onert/core/src/ir/operation/Tanh.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -36,4 +36,4 @@ Tanh::Tanh(const OperandIndexSequence &inputs, const OperandIndexSequence &outpu } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/TopKV2.cc b/runtime/onert/core/src/ir/operation/TopKV2.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/TopKV2.cc rename to runtime/onert/core/src/ir/operation/TopKV2.cc index 6fabd34a332..a5e6c6a8506 100644 --- a/runtime/neurun/core/src/ir/operation/TopKV2.cc +++ b/runtime/onert/core/src/ir/operation/TopKV2.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -37,4 +37,4 @@ TopKV2::TopKV2(const OperandIndexSequence &inputs, const OperandIndexSequence &o } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/Transpose.cc b/runtime/onert/core/src/ir/operation/Transpose.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/Transpose.cc rename to runtime/onert/core/src/ir/operation/Transpose.cc index 74239b0f624..3a663fbcef0 100644 --- a/runtime/neurun/core/src/ir/operation/Transpose.cc +++ b/runtime/onert/core/src/ir/operation/Transpose.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -37,4 +37,4 @@ Transpose::Transpose(const OperandIndexSequence &inputs, const OperandIndexSeque } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/TransposeConv.cc b/runtime/onert/core/src/ir/operation/TransposeConv.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/TransposeConv.cc rename to runtime/onert/core/src/ir/operation/TransposeConv.cc index 30664e974e0..7f29ca44eb7 100644 --- a/runtime/neurun/core/src/ir/operation/TransposeConv.cc +++ b/runtime/onert/core/src/ir/operation/TransposeConv.cc @@ -20,7 +20,7 @@ #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -37,4 +37,4 @@ TransposeConv::TransposeConv(const OperandIndexSequence &inputs, } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/operation/Unpack.cc b/runtime/onert/core/src/ir/operation/Unpack.cc similarity index 96% rename from runtime/neurun/core/src/ir/operation/Unpack.cc rename to runtime/onert/core/src/ir/operation/Unpack.cc index 7c2c2489228..67aa54ab5f3 100644 --- a/runtime/neurun/core/src/ir/operation/Unpack.cc +++ b/runtime/onert/core/src/ir/operation/Unpack.cc @@ -16,7 +16,7 @@ #include "ir/operation/Unpack.h" #include "ir/OperationVisitor.h" -namespace neurun +namespace onert { namespace ir { @@ -30,4 +30,4 @@ Unpack::Unpack(const OperandIndexSequence &inputs, const OperandIndexSequence &o } } // namespace operation } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/pass/ConstantInsertionPass.cc b/runtime/onert/core/src/ir/pass/ConstantInsertionPass.cc similarity index 88% rename from runtime/neurun/core/src/ir/pass/ConstantInsertionPass.cc rename to runtime/onert/core/src/ir/pass/ConstantInsertionPass.cc index cb112980ace..5f4612d35fa 100644 --- a/runtime/neurun/core/src/ir/pass/ConstantInsertionPass.cc +++ b/runtime/onert/core/src/ir/pass/ConstantInsertionPass.cc @@ -20,7 +20,7 @@ #include #include -namespace neurun +namespace onert { namespace ir { @@ -29,8 +29,8 @@ namespace pass void ConstantInsertionPass::callback(const OperationIndex &node_index, Operation &node) { - const auto &subgraph_index = _lowered_graph.op_seqs().getOperation(node_index); - const auto op_seq_lower_info = _lowered_graph.getLowerInfo(subgraph_index); + const auto &op_sequence_index = _lowered_graph.op_seqs().getOperation(node_index); + const auto op_seq_lower_info = _lowered_graph.getLowerInfo(op_sequence_index); const auto backend = op_seq_lower_info->backend(); const auto layout = op_seq_lower_info->layout(); const auto factor = operand::PermuteFactor{backend, layout}; @@ -57,9 +57,9 @@ void ConstantInsertionPass::callback(const OperationIndex &node_index, Operation const auto replaced_input = _replace_operands_map[key]; // Update op_seq - if (_lowered_graph.op_seqs().at(subgraph_index).getInputs().contains(input)) + if (_lowered_graph.op_seqs().at(op_sequence_index).getInputs().contains(input)) { - _lowered_graph.op_seqs().at(subgraph_index).replaceInput(input, replaced_input); + _lowered_graph.op_seqs().at(op_sequence_index).replaceInput(input, replaced_input); } // Update node @@ -99,4 +99,4 @@ void ConstantInsertionPass::callback(const OperationIndex &node_index, Operation } // namespace pass } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/pass/ConstantInsertionPass.h b/runtime/onert/core/src/ir/pass/ConstantInsertionPass.h similarity index 89% rename from runtime/neurun/core/src/ir/pass/ConstantInsertionPass.h rename to runtime/onert/core/src/ir/pass/ConstantInsertionPass.h index 2ffb40ff437..3ea4dc39738 100644 --- a/runtime/neurun/core/src/ir/pass/ConstantInsertionPass.h +++ b/runtime/onert/core/src/ir/pass/ConstantInsertionPass.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __NEURUN_GRAPH_PASS_CONSTANT_INSERTION_PASS_H__ -#define __NEURUN_GRAPH_PASS_CONSTANT_INSERTION_PASS_H__ +#ifndef __ONERT_GRAPH_PASS_CONSTANT_INSERTION_PASS_H__ +#define __ONERT_GRAPH_PASS_CONSTANT_INSERTION_PASS_H__ #include #include @@ -23,7 +23,7 @@ #include #include -namespace neurun +namespace onert { namespace ir { @@ -70,6 +70,6 @@ class ConstantInsertionPass : public LoweredOperationPass } // namespace pass } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_GRAPH_PASS_CONSTANT_INSERTION_PASS_H__ +#endif // __ONERT_GRAPH_PASS_CONSTANT_INSERTION_PASS_H__ diff --git a/runtime/neurun/core/src/ir/pass/LoweredOperandPass.h b/runtime/onert/core/src/ir/pass/LoweredOperandPass.h similarity index 81% rename from runtime/neurun/core/src/ir/pass/LoweredOperandPass.h rename to runtime/onert/core/src/ir/pass/LoweredOperandPass.h index 1b724e25e88..eefb8ddfbab 100644 --- a/runtime/neurun/core/src/ir/pass/LoweredOperandPass.h +++ b/runtime/onert/core/src/ir/pass/LoweredOperandPass.h @@ -14,13 +14,13 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_PASS_LOWERED_OPERAND_PASS_H__ -#define __NEURUN_IR_PASS_LOWERED_OPERAND_PASS_H__ +#ifndef __ONERT_IR_PASS_LOWERED_OPERAND_PASS_H__ +#define __ONERT_IR_PASS_LOWERED_OPERAND_PASS_H__ #include "OperandPass.h" #include "ir/LoweredGraph.h" -namespace neurun +namespace onert { namespace ir { @@ -39,7 +39,7 @@ class LoweredOperandPass : public OperandPass virtual ~LoweredOperandPass() = default; std::string id() override = 0; - virtual void callback(const OperandIndex &i, Operand &o) = 0; + void callback(const OperandIndex &i, Operand &o) override = 0; protected: ir::LoweredGraph &_lowered_graph; @@ -47,6 +47,6 @@ class LoweredOperandPass : public OperandPass } // namespace pass } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_PASS_LOWERED_OPERAND_PASS_H__ +#endif // __ONERT_IR_PASS_LOWERED_OPERAND_PASS_H__ diff --git a/runtime/neurun/core/src/ir/pass/LoweredOperationPass.h b/runtime/onert/core/src/ir/pass/LoweredOperationPass.h similarity index 80% rename from runtime/neurun/core/src/ir/pass/LoweredOperationPass.h rename to runtime/onert/core/src/ir/pass/LoweredOperationPass.h index 02047d226ba..0138712d704 100644 --- a/runtime/neurun/core/src/ir/pass/LoweredOperationPass.h +++ b/runtime/onert/core/src/ir/pass/LoweredOperationPass.h @@ -14,13 +14,13 @@ * limitations under the License. */ -#ifndef __NEURUN_IR_PASS_LOWERED_OPERATION_PASS_H__ -#define __NEURUN_IR_PASS_LOWERED_OPERATION_PASS_H__ +#ifndef __ONERT_IR_PASS_LOWERED_OPERATION_PASS_H__ +#define __ONERT_IR_PASS_LOWERED_OPERATION_PASS_H__ #include "OperationPass.h" #include "ir/LoweredGraph.h" -namespace neurun +namespace onert { namespace ir { @@ -39,7 +39,7 @@ class LoweredOperationPass : public OperationPass virtual ~LoweredOperationPass() = default; std::string id() override = 0; - virtual void callback(const OperationIndex &i, Operation &o) = 0; + void callback(const OperationIndex &i, Operation &o) override = 0; protected: ir::LoweredGraph &_lowered_graph; @@ -47,6 +47,6 @@ class LoweredOperationPass : public OperationPass } // namespace pass } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_IR_PASS_LOWERED_OPERATION_PASS_H__ +#endif // __ONERT_IR_PASS_LOWERED_OPERATION_PASS_H__ diff --git a/runtime/neurun/core/src/ir/pass/OperandPass.cc b/runtime/onert/core/src/ir/pass/OperandPass.cc similarity index 95% rename from runtime/neurun/core/src/ir/pass/OperandPass.cc rename to runtime/onert/core/src/ir/pass/OperandPass.cc index f31d0d85047..693a0f4937c 100644 --- a/runtime/neurun/core/src/ir/pass/OperandPass.cc +++ b/runtime/onert/core/src/ir/pass/OperandPass.cc @@ -18,7 +18,7 @@ #include "ir/Graph.h" -namespace neurun +namespace onert { namespace ir { @@ -33,4 +33,4 @@ void OperandPass::run() } // namespace pass } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/pass/OperandPass.h b/runtime/onert/core/src/ir/pass/OperandPass.h similarity index 82% rename from runtime/neurun/core/src/ir/pass/OperandPass.h rename to runtime/onert/core/src/ir/pass/OperandPass.h index 1bbc5ba4067..393060741c0 100644 --- a/runtime/neurun/core/src/ir/pass/OperandPass.h +++ b/runtime/onert/core/src/ir/pass/OperandPass.h @@ -14,21 +14,21 @@ * limitations under the License. */ -#ifndef __NEURUN_GRAPH_PASS_OPERAND_PASS_H__ -#define __NEURUN_GRAPH_PASS_OPERAND_PASS_H__ +#ifndef __ONERT_GRAPH_PASS_OPERAND_PASS_H__ +#define __ONERT_GRAPH_PASS_OPERAND_PASS_H__ #include "Pass.h" #include "ir/Index.h" -namespace neurun +namespace onert { namespace ir { class Operand; } // namespace ir -} // namespace neurun +} // namespace onert -namespace neurun +namespace onert { namespace ir { @@ -49,6 +49,6 @@ class OperandPass : public Pass } // namespace pass } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_GRAPH_PASS_OPERAND_PASS_H__ +#endif // __ONERT_GRAPH_PASS_OPERAND_PASS_H__ diff --git a/runtime/neurun/core/src/ir/pass/OperationPass.cc b/runtime/onert/core/src/ir/pass/OperationPass.cc similarity index 96% rename from runtime/neurun/core/src/ir/pass/OperationPass.cc rename to runtime/onert/core/src/ir/pass/OperationPass.cc index c9438ee39ef..84b1da3eee0 100644 --- a/runtime/neurun/core/src/ir/pass/OperationPass.cc +++ b/runtime/onert/core/src/ir/pass/OperationPass.cc @@ -20,7 +20,7 @@ #include "ir/Operation.h" #include "ir/Graph.h" -namespace neurun +namespace onert { namespace ir { @@ -35,4 +35,4 @@ void OperationPass::run() } // namespace pass } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/pass/OperationPass.h b/runtime/onert/core/src/ir/pass/OperationPass.h similarity index 87% rename from runtime/neurun/core/src/ir/pass/OperationPass.h rename to runtime/onert/core/src/ir/pass/OperationPass.h index 75524950266..1733f87ed8b 100644 --- a/runtime/neurun/core/src/ir/pass/OperationPass.h +++ b/runtime/onert/core/src/ir/pass/OperationPass.h @@ -19,21 +19,21 @@ * @brief This file contains OperationPass class */ -#ifndef __NEURUN_GRAPH_PASS_OPERATION_PASS_H__ -#define __NEURUN_GRAPH_PASS_OPERATION_PASS_H__ +#ifndef __ONERT_GRAPH_PASS_OPERATION_PASS_H__ +#define __ONERT_GRAPH_PASS_OPERATION_PASS_H__ #include "Pass.h" #include "ir/Index.h" -namespace neurun +namespace onert { namespace ir { class Operation; } // namespace ir -} // namespace neurun +} // namespace onert -namespace neurun +namespace onert { namespace ir { @@ -72,6 +72,6 @@ class OperationPass : public Pass } // namespace pass } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_GRAPH_PASS_OPERATION_PASS_H__ +#endif // __ONERT_GRAPH_PASS_OPERATION_PASS_H__ diff --git a/runtime/neurun/core/src/ir/pass/Pass.h b/runtime/onert/core/src/ir/pass/Pass.h similarity index 83% rename from runtime/neurun/core/src/ir/pass/Pass.h rename to runtime/onert/core/src/ir/pass/Pass.h index 0aa0f36a6b1..1c6628f6f7c 100644 --- a/runtime/neurun/core/src/ir/pass/Pass.h +++ b/runtime/onert/core/src/ir/pass/Pass.h @@ -14,20 +14,20 @@ * limitations under the License. */ -#ifndef __NEURUN_GRAPH_PASS_PASS_H__ -#define __NEURUN_GRAPH_PASS_PASS_H__ +#ifndef __ONERT_GRAPH_PASS_PASS_H__ +#define __ONERT_GRAPH_PASS_PASS_H__ #include -namespace neurun +namespace onert { namespace ir { class Graph; } // namespace ir -} // namespace neurun +} // namespace onert -namespace neurun +namespace onert { namespace ir { @@ -50,6 +50,6 @@ class Pass } // namespace pass } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_GRAPH_PASS_PASS_H__ +#endif // __ONERT_GRAPH_PASS_PASS_H__ diff --git a/runtime/neurun/core/src/ir/pass/PermutationEliminationPass.cc b/runtime/onert/core/src/ir/pass/PermutationEliminationPass.cc similarity index 99% rename from runtime/neurun/core/src/ir/pass/PermutationEliminationPass.cc rename to runtime/onert/core/src/ir/pass/PermutationEliminationPass.cc index 4acc93965fd..f4793d411ae 100644 --- a/runtime/neurun/core/src/ir/pass/PermutationEliminationPass.cc +++ b/runtime/onert/core/src/ir/pass/PermutationEliminationPass.cc @@ -22,7 +22,7 @@ #include "backend/IConfig.h" #include "util/logging.h" -namespace neurun +namespace onert { namespace ir { @@ -192,4 +192,4 @@ bool PermutationEliminationPass::isPermuteLayerToEliminate(const OperandIndexSeq } // namespace pass } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/pass/PermutationEliminationPass.h b/runtime/onert/core/src/ir/pass/PermutationEliminationPass.h similarity index 91% rename from runtime/neurun/core/src/ir/pass/PermutationEliminationPass.h rename to runtime/onert/core/src/ir/pass/PermutationEliminationPass.h index 46a3f28a4c8..1c843006214 100644 --- a/runtime/neurun/core/src/ir/pass/PermutationEliminationPass.h +++ b/runtime/onert/core/src/ir/pass/PermutationEliminationPass.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef __NEURUN_GRAPH_PASS_PERMUTATION_ELIMINATION_PASS_H__ -#define __NEURUN_GRAPH_PASS_PERMUTATION_ELIMINATION_PASS_H__ +#ifndef __ONERT_GRAPH_PASS_PERMUTATION_ELIMINATION_PASS_H__ +#define __ONERT_GRAPH_PASS_PERMUTATION_ELIMINATION_PASS_H__ #include "LoweredOperandPass.h" #include "ir/Operand.h" #include "ir/OperandIndexSequence.h" -namespace neurun +namespace onert { namespace ir { @@ -81,6 +81,6 @@ class PermutationEliminationPass : public LoweredOperandPass } // namespace pass } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_GRAPH_PASS_PERMUTATION_ELIMINATION_PASS_H__ +#endif // __ONERT_GRAPH_PASS_PERMUTATION_ELIMINATION_PASS_H__ diff --git a/runtime/neurun/core/src/ir/pass/PermutationInsertionPass.cc b/runtime/onert/core/src/ir/pass/PermutationInsertionPass.cc similarity index 97% rename from runtime/neurun/core/src/ir/pass/PermutationInsertionPass.cc rename to runtime/onert/core/src/ir/pass/PermutationInsertionPass.cc index 7710d80a2b2..32db3d87800 100644 --- a/runtime/neurun/core/src/ir/pass/PermutationInsertionPass.cc +++ b/runtime/onert/core/src/ir/pass/PermutationInsertionPass.cc @@ -25,10 +25,10 @@ #include "ir/Graph.h" #include "backend/IConfig.h" #include "util/logging.h" -#include "memory" +#include #include "ir/operation/Permute.h" -namespace neurun +namespace onert { namespace ir { @@ -188,9 +188,9 @@ OperationIndex PermutationInsertionPass::insertPermute(const OperandIndex &opera // OpSequence { auto op_seq_index = _lowered_graph.op_seqs().emplace(node_index, node, permute_node_layout); - auto &subg = _lowered_graph.op_seqs().at(op_seq_index); - subg.setInputs(node.getInputs()); - subg.setOutputs(node.getOutputs()); + auto &op_seq = _lowered_graph.op_seqs().at(op_seq_index); + op_seq.setInputs(node.getInputs()); + op_seq.setOutputs(node.getOutputs()); _lowered_graph.setLowerInfo(op_seq_index, std::make_unique( permute_node_backend, permute_node_layout)); } @@ -204,4 +204,4 @@ OperationIndex PermutationInsertionPass::insertPermute(const OperandIndex &opera } } // namespace pass } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/pass/PermutationInsertionPass.h b/runtime/onert/core/src/ir/pass/PermutationInsertionPass.h similarity index 87% rename from runtime/neurun/core/src/ir/pass/PermutationInsertionPass.h rename to runtime/onert/core/src/ir/pass/PermutationInsertionPass.h index f29ee4ce8ba..314a54c9581 100644 --- a/runtime/neurun/core/src/ir/pass/PermutationInsertionPass.h +++ b/runtime/onert/core/src/ir/pass/PermutationInsertionPass.h @@ -14,15 +14,15 @@ * limitations under the License. */ -#ifndef __NEURUN_GRAPH_PASS_PERMUTATION_INSERTION_PASS_H__ -#define __NEURUN_GRAPH_PASS_PERMUTATION_INSERTION_PASS_H__ +#ifndef __ONERT_GRAPH_PASS_PERMUTATION_INSERTION_PASS_H__ +#define __ONERT_GRAPH_PASS_PERMUTATION_INSERTION_PASS_H__ #include "LoweredOperandPass.h" #include "compiler/BackendManager.h" #include "ir/Operand.h" //for OperationIndex #include "ir/operand/PermuteFactor.h" -namespace neurun +namespace onert { namespace ir { @@ -54,6 +54,6 @@ class PermutationInsertionPass : public LoweredOperandPass } // namespace pass } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_GRAPH_PASS_PERMUTATION_INSERTION_PASS_H__ +#endif // __ONERT_GRAPH_PASS_PERMUTATION_INSERTION_PASS_H__ diff --git a/runtime/neurun/core/src/ir/pass/PermutationOperationPass.cc b/runtime/onert/core/src/ir/pass/PermutationOperationPass.cc similarity index 85% rename from runtime/neurun/core/src/ir/pass/PermutationOperationPass.cc rename to runtime/onert/core/src/ir/pass/PermutationOperationPass.cc index baf7c3e7fac..f2172c4b0d8 100644 --- a/runtime/neurun/core/src/ir/pass/PermutationOperationPass.cc +++ b/runtime/onert/core/src/ir/pass/PermutationOperationPass.cc @@ -20,7 +20,7 @@ #include "backend/IConfig.h" #include "ir/Graph.h" -namespace neurun +namespace onert { namespace ir { @@ -58,40 +58,40 @@ void PermutationOperationPass::changeToKeepLayout(const Operation &node) // Divide op_seq based on target operation { - auto &above_subg = _lowered_graph.op_seqs().at(op_seq_index); + auto &prev_op_seq = _lowered_graph.op_seqs().at(op_seq_index); // Create new op_seq and move information from existing op_seq to new op_seq if target // node is the end of op_seq - auto it = above_subg.begin(); + auto it = prev_op_seq.begin(); // Find iterator of target node in op_seq while ((it++)->index != node_index) ; - if (it != above_subg.end()) + if (it != prev_op_seq.end()) { - const auto &below_op_seq_index = - _lowered_graph.op_seqs().emplace(it->index, *it->node, above_subg.getLayout()); - auto &below_subg = _lowered_graph.op_seqs().at(below_op_seq_index); - below_subg.setInputs(it->node->getInputs()); - below_subg.setOutputs(it->node->getOutputs()); + const auto &next_op_seq_index = + _lowered_graph.op_seqs().emplace(it->index, *it->node, prev_op_seq.getLayout()); + auto &next_op_seq = _lowered_graph.op_seqs().at(next_op_seq_index); + next_op_seq.setInputs(it->node->getInputs()); + next_op_seq.setOutputs(it->node->getOutputs()); std::vector remove_list; remove_list.emplace_back(it->index); - while (++it != above_subg.end()) + while (++it != prev_op_seq.end()) { - below_subg.appendOperation(it->index, *it->node); - below_subg.setOutputs(it->node->getOutputs()); + next_op_seq.appendOperation(it->index, *it->node); + next_op_seq.setOutputs(it->node->getOutputs()); remove_list.emplace_back(it->index); } - above_subg.setOutputs(node.getOutputs()); + prev_op_seq.setOutputs(node.getOutputs()); for (const auto &index : remove_list) { - above_subg.remove(index); + prev_op_seq.remove(index); } const auto op_seq_li = _lowered_graph.getLowerInfo(op_seq_index); _lowered_graph.setLowerInfo( - below_op_seq_index, + next_op_seq_index, std::make_unique(op_seq_li->backend(), op_seq_li->layout())); } } @@ -100,8 +100,8 @@ void PermutationOperationPass::changeToKeepLayout(const Operation &node) { const auto backend = _lowered_graph.getLowerInfo(op_seq_index)->backend(); - // Remove target operation from subraph - _lowered_graph.op_seqs().removeFromSubgraph(node_index); + // Remove target operation from op_sequence + _lowered_graph.op_seqs().removeFromOpSequence(node_index); if (!_lowered_graph.op_seqs().exist(op_seq_index)) { @@ -111,16 +111,16 @@ void PermutationOperationPass::changeToKeepLayout(const Operation &node) else { // Update op_seq of target operation if the op_seq exists - auto &above_subg = _lowered_graph.op_seqs().at(op_seq_index); - const auto last_node = (--above_subg.end())->node; - above_subg.setOutputs(last_node->getOutputs()); + auto &prev_op_seq = _lowered_graph.op_seqs().at(op_seq_index); + const auto last_node = (--prev_op_seq.end())->node; + prev_op_seq.setOutputs(last_node->getOutputs()); } // Create new op_seq and set information to the op_seq auto new_op_seq_index = _lowered_graph.op_seqs().emplace(node_index, node, frontend_layout); - auto &new_subg = _lowered_graph.op_seqs().at(new_op_seq_index); - new_subg.setInputs(node.getInputs()); - new_subg.setOutputs(node.getOutputs()); + auto &new_op_seq = _lowered_graph.op_seqs().at(new_op_seq_index); + new_op_seq.setInputs(node.getInputs()); + new_op_seq.setOutputs(node.getOutputs()); _lowered_graph.setLowerInfo(new_op_seq_index, std::make_unique(backend, frontend_layout)); } @@ -228,4 +228,4 @@ void PermutationOperationPass::visit(const operation::Reshape &node) } // namespace pass } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/pass/PermutationOperationPass.h b/runtime/onert/core/src/ir/pass/PermutationOperationPass.h similarity index 85% rename from runtime/neurun/core/src/ir/pass/PermutationOperationPass.h rename to runtime/onert/core/src/ir/pass/PermutationOperationPass.h index 1f6db9c0633..e68065bfb33 100644 --- a/runtime/neurun/core/src/ir/pass/PermutationOperationPass.h +++ b/runtime/onert/core/src/ir/pass/PermutationOperationPass.h @@ -14,13 +14,13 @@ * limitations under the License. */ -#ifndef __NEURUN_GRAPH_PASS_PERMUTATION_OPERATION_PASS_H__ -#define __NEURUN_GRAPH_PASS_PERMUTATION_OPERATION_PASS_H__ +#ifndef __ONERT_GRAPH_PASS_PERMUTATION_OPERATION_PASS_H__ +#define __ONERT_GRAPH_PASS_PERMUTATION_OPERATION_PASS_H__ #include "ir/OperationVisitor.h" #include "LoweredOperationPass.h" -namespace neurun +namespace onert { namespace ir { @@ -49,6 +49,6 @@ class PermutationOperationPass : public LoweredOperationPass, public OperationVi } // namespace pass } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_GRAPH_PASS_PERMUTATION_OPERATION_PASS_H__ +#endif // __ONERT_GRAPH_PASS_PERMUTATION_OPERATION_PASS_H__ diff --git a/runtime/neurun/core/src/ir/verifier/Verifier.cc b/runtime/onert/core/src/ir/verifier/Verifier.cc similarity index 98% rename from runtime/neurun/core/src/ir/verifier/Verifier.cc rename to runtime/onert/core/src/ir/verifier/Verifier.cc index 7bd8ac51277..c4655ee42e3 100644 --- a/runtime/neurun/core/src/ir/verifier/Verifier.cc +++ b/runtime/onert/core/src/ir/verifier/Verifier.cc @@ -21,7 +21,7 @@ #include "util/logging.h" -namespace neurun +namespace onert { namespace ir { @@ -93,4 +93,4 @@ bool EdgeConsistencyChecker::verify(const Graph &graph) const } // namespace verifier } // namespace ir -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/ir/verifier/Verifier.h b/runtime/onert/core/src/ir/verifier/Verifier.h similarity index 82% rename from runtime/neurun/core/src/ir/verifier/Verifier.h rename to runtime/onert/core/src/ir/verifier/Verifier.h index 0993a239e65..0bc22bc47df 100644 --- a/runtime/neurun/core/src/ir/verifier/Verifier.h +++ b/runtime/onert/core/src/ir/verifier/Verifier.h @@ -14,18 +14,18 @@ * limitations under the License. */ -#ifndef __NEURUN_GRAPH_VERIFIER_VERIFIER_H__ -#define __NEURUN_GRAPH_VERIFIER_VERIFIER_H__ +#ifndef __ONERT_GRAPH_VERIFIER_VERIFIER_H__ +#define __ONERT_GRAPH_VERIFIER_VERIFIER_H__ -namespace neurun +namespace onert { namespace ir { class Graph; } // namespace ir -} // namespace neurun +} // namespace onert -namespace neurun +namespace onert { namespace ir { @@ -40,9 +40,9 @@ struct IVerifier } // namespace verifier } // namespace ir -} // namespace neurun +} // namespace onert -namespace neurun +namespace onert { namespace ir { @@ -63,6 +63,6 @@ class EdgeConsistencyChecker : public IVerifier } // namespace verifier } // namespace ir -} // namespace neurun +} // namespace onert -#endif // __NEURUN_GRAPH_VERIFIER_VERIFIER_H__ +#endif // __ONERT_GRAPH_VERIFIER_VERIFIER_H__ diff --git a/runtime/neurun/core/src/library_info.cc b/runtime/onert/core/src/library_info.cc similarity index 90% rename from runtime/neurun/core/src/library_info.cc rename to runtime/onert/core/src/library_info.cc index 601d09185e2..6d7579cca1d 100644 --- a/runtime/neurun/core/src/library_info.cc +++ b/runtime/onert/core/src/library_info.cc @@ -14,4 +14,4 @@ * limitations under the License. */ -volatile const char info[] = "library information : runtime=neurun"; +volatile const char info[] = "library information : runtime=onert"; diff --git a/runtime/neurun/core/src/util/ConfigSource.cc b/runtime/onert/core/src/util/ConfigSource.cc similarity index 90% rename from runtime/neurun/core/src/util/ConfigSource.cc rename to runtime/onert/core/src/util/ConfigSource.cc index 3977d1a4c86..45cce662e09 100644 --- a/runtime/neurun/core/src/util/ConfigSource.cc +++ b/runtime/onert/core/src/util/ConfigSource.cc @@ -22,9 +22,9 @@ #include #include -#include "memory" +#include -namespace neurun +namespace onert { namespace util { @@ -78,27 +78,33 @@ static std::string getConfigOrDefault(const std::string &key) return ret; } -bool getConfigBool(const std::string &key) +bool toBool(const std::string &val) { - auto raw = getConfigOrDefault(key); static const std::array false_list{"0", "OFF", "FALSE", "N", "NO"}; - auto false_found = std::find(false_list.begin(), false_list.end(), raw); + auto false_found = std::find(false_list.begin(), false_list.end(), val); + return false_found == false_list.end(); +} + +int toInt(const std::string &val) { return std::stoi(val); } - return (false_found == false_list.end()); +bool getConfigBool(const std::string &key) +{ + auto raw = getConfigOrDefault(key); + return toBool(raw); } int getConfigInt(const std::string &key) { auto raw = getConfigOrDefault(key); - return std::stoi(raw); + return toInt(raw); } std::string getConfigString(const std::string &key) { return getConfigOrDefault(key); } } // namespace util -} // namespace neurun +} // namespace onert -namespace neurun +namespace onert { namespace util { @@ -113,4 +119,4 @@ namespace config } // namespace config } // namespace util -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/util/EnvConfigSource.cc b/runtime/onert/core/src/util/EnvConfigSource.cc similarity index 96% rename from runtime/neurun/core/src/util/EnvConfigSource.cc rename to runtime/onert/core/src/util/EnvConfigSource.cc index 52a6bf2a48b..0d25b735330 100644 --- a/runtime/neurun/core/src/util/EnvConfigSource.cc +++ b/runtime/onert/core/src/util/EnvConfigSource.cc @@ -18,7 +18,7 @@ #include -namespace neurun +namespace onert { namespace util { @@ -37,4 +37,4 @@ std::string EnvConfigSource::get(const std::string &key) const } } // namespace util -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/util/EventCollectorGlobal.cc b/runtime/onert/core/src/util/EventCollectorGlobal.cc similarity index 98% rename from runtime/neurun/core/src/util/EventCollectorGlobal.cc rename to runtime/onert/core/src/util/EventCollectorGlobal.cc index eabddde8fa6..ab8ddab60b6 100644 --- a/runtime/neurun/core/src/util/EventCollectorGlobal.cc +++ b/runtime/onert/core/src/util/EventCollectorGlobal.cc @@ -21,7 +21,7 @@ #include "util/ConfigSource.h" -namespace neurun +namespace onert { namespace util { @@ -82,4 +82,4 @@ void EventDurationManual::end() } } // namespace util -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/util/GeneralConfigSource.cc b/runtime/onert/core/src/util/GeneralConfigSource.cc similarity index 96% rename from runtime/neurun/core/src/util/GeneralConfigSource.cc rename to runtime/onert/core/src/util/GeneralConfigSource.cc index 084e4c109a6..7d2757e58b1 100644 --- a/runtime/neurun/core/src/util/GeneralConfigSource.cc +++ b/runtime/onert/core/src/util/GeneralConfigSource.cc @@ -17,7 +17,7 @@ #include "util/GeneralConfigSource.h" #include "util/logging.h" -namespace neurun +namespace onert { namespace util { @@ -42,4 +42,4 @@ void GeneralConfigSource::set(const std::string &key, const std::string &val) } } // namespace util -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/util/ShapeInference.cc b/runtime/onert/core/src/util/ShapeInference.cc similarity index 86% rename from runtime/neurun/core/src/util/ShapeInference.cc rename to runtime/onert/core/src/util/ShapeInference.cc index 6fa29e7d8de..ace16959de4 100644 --- a/runtime/neurun/core/src/util/ShapeInference.cc +++ b/runtime/onert/core/src/util/ShapeInference.cc @@ -21,7 +21,7 @@ #include "ir/operation/MaxPool2D.h" #include "util/ShapeInference.h" -namespace neurun +namespace onert { namespace shape_inference { @@ -196,5 +196,46 @@ Shapes inferFullyConnectedShape(const ir::Shape &in_shape, const ir::Shape &ker_ return {{ir::Shape({static_cast(batch_size), num_units})}}; } +/* + StaticInferer +*/ + +void StaticInferer::visit(const ir::operation::Reshape &op) +{ + const auto input_idx{op.getInputs().at(ir::operation::Reshape::Input::INPUT)}; + const auto &input = _operands.at(input_idx); + + // get mutable output operand + const auto output_idx = op.getOutputs().at(0); + ir::Operand &output = _operands.at(output_idx); + + // if input is dynamic, output also becomes dynamic + if (input.info().memAllocType() == ir::MemAllocType::DYNAMIC) + { + output.info().memAllocType(ir::MemAllocType::DYNAMIC); + return; + } + + if (op.getInputs().size() == 1) + { + // no change on output shape + return; + } + + // Let's check the second input + const auto shape_idx{op.getInputs().at(ir::operation::Reshape::Input::SHAPE)}; + const auto &shape = _operands.at(shape_idx); + + if (shape.isConstant()) + { + // if shape is from Const, TFLC put the shape of output into tensor + // no change on output shape + return; + } + + // if shape is NOT Const, set output shape to be dynamic_ + output.info().memAllocType(ir::MemAllocType::DYNAMIC); +} + } // namespace shape_inference -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/core/src/util/logging.cc b/runtime/onert/core/src/util/logging.cc similarity index 89% rename from runtime/neurun/core/src/util/logging.cc rename to runtime/onert/core/src/util/logging.cc index e68f391f508..6309d25e59a 100644 --- a/runtime/neurun/core/src/util/logging.cc +++ b/runtime/onert/core/src/util/logging.cc @@ -16,7 +16,7 @@ #include "util/logging.h" -neurun::util::logging::Context &neurun::util::logging::Context::get() noexcept +onert::util::logging::Context &onert::util::logging::Context::get() noexcept { static Context ctx; return ctx; diff --git a/runtime/neurun/frontend/CMakeLists.txt b/runtime/onert/frontend/CMakeLists.txt similarity index 100% rename from runtime/neurun/frontend/CMakeLists.txt rename to runtime/onert/frontend/CMakeLists.txt diff --git a/runtime/neurun/frontend/base_loader/CMakeLists.txt b/runtime/onert/frontend/base_loader/CMakeLists.txt similarity index 81% rename from runtime/neurun/frontend/base_loader/CMakeLists.txt rename to runtime/onert/frontend/base_loader/CMakeLists.txt index e614b1e011e..921206c31e3 100644 --- a/runtime/neurun/frontend/base_loader/CMakeLists.txt +++ b/runtime/onert/frontend/base_loader/CMakeLists.txt @@ -4,4 +4,4 @@ endif(NOT BUILD_TFLITE_LOADER AND NOT BUILD_CIRCLE_LOADER) add_library(base_loader INTERFACE) target_include_directories(base_loader INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include) -target_link_libraries(base_loader INTERFACE neurun_core) +target_link_libraries(base_loader INTERFACE onert_core) diff --git a/runtime/neurun/frontend/base_loader/include/base_loader.h b/runtime/onert/frontend/base_loader/include/base_loader.h similarity index 96% rename from runtime/neurun/frontend/base_loader/include/base_loader.h rename to runtime/onert/frontend/base_loader/include/base_loader.h index 41452ef5743..84505f949ca 100644 --- a/runtime/neurun/frontend/base_loader/include/base_loader.h +++ b/runtime/onert/frontend/base_loader/include/base_loader.h @@ -25,7 +25,7 @@ #include #include -namespace neurun +namespace onert { namespace base_loader { @@ -126,6 +126,8 @@ template class BaseLoader void loadCast(const Operator *op); void loadComparison(const Operator *op); void loadOneHot(const Operator *op); + void loadAbs(const Operator *op); + void loadSin(const Operator *op); protected: // Buffer for loading (if needed) @@ -133,7 +135,7 @@ template class BaseLoader // Reference on loadable Graph ir::Graph &_graph; const Model *_model; - // Maps Tensor indices to neurun Operands. + // Maps Tensor indices to onert Operands. std::vector _tensor_to_operand; // Verifier std::unique_ptr _verifier; @@ -216,9 +218,12 @@ ir::OperandIndex BaseLoader::loadOperand(const Ten ir::Shape shape; // Shape const auto *tensor_shape = tensor->shape(); - for (const auto &dim : *tensor_shape) + if (tensor_shape != nullptr) { - shape.append(dim); + for (const auto &dim : *tensor_shape) + { + shape.append(dim); + } } // Type ir::DataType data_type = tensorTypeToDataType(tensor->type()); @@ -949,7 +954,7 @@ void BaseLoader::loadSplit(const Operator *op) param.axis = _graph.operands().at(axis).template asScalar(); const auto *options = op->builtin_options_as_SplitOptions(); param.num_splits = options->num_splits(); - param.rank = _graph.operands().at(inputs.at(0)).shape().rank(); + param.rank = _graph.operands().at(input).shape().rank(); std::unique_ptr new_op(new ir::operation::Split({input}, outputs, param)); _graph.addOperation(std::move(new_op)); @@ -1070,6 +1075,9 @@ void BaseLoader::loadComparison(const Operator *op case BuiltinOperator::BuiltinOperator_EQUAL: param.comparison_type = ir::operation::Comparison::ComparisonType::Equal; break; + case BuiltinOperator::BuiltinOperator_NOT_EQUAL: + param.comparison_type = ir::operation::Comparison::ComparisonType::NotEqual; + break; case BuiltinOperator::BuiltinOperator_GREATER_EQUAL: param.comparison_type = ir::operation::Comparison::ComparisonType::GreaterEqual; break; @@ -1124,6 +1132,30 @@ void BaseLoader::loadOneHot(const Operator *op) _graph.addOperation(std::move(new_op)); } +template +void BaseLoader::loadAbs(const Operator *op) +{ + ir::OperandIndexSequence inputs; + ir::OperandIndexSequence outputs; + + loadOperationIO(op, inputs, outputs); + + std::unique_ptr new_op(new ir::operation::Abs(inputs, outputs)); + _graph.addOperation(std::move(new_op)); +} + +template +void BaseLoader::loadSin(const Operator *op) +{ + ir::OperandIndexSequence inputs; + ir::OperandIndexSequence outputs; + + loadOperationIO(op, inputs, outputs); + + std::unique_ptr new_op(new ir::operation::Sin(inputs, outputs)); + _graph.addOperation(std::move(new_op)); +} + template void BaseLoader::loadOperation(const Operator *op) { @@ -1255,6 +1287,7 @@ void BaseLoader::loadOperation(const Operator *op) loadCast(op); return; case BuiltinOperator::BuiltinOperator_EQUAL: + case BuiltinOperator::BuiltinOperator_NOT_EQUAL: case BuiltinOperator::BuiltinOperator_GREATER_EQUAL: case BuiltinOperator::BuiltinOperator_GREATER: case BuiltinOperator::BuiltinOperator_LESS_EQUAL: @@ -1264,6 +1297,12 @@ void BaseLoader::loadOperation(const Operator *op) case BuiltinOperator::BuiltinOperator_ONE_HOT: loadOneHot(op); return; + case BuiltinOperator::BuiltinOperator_ABS: + loadAbs(op); + return; + case BuiltinOperator::BuiltinOperator_SIN: + loadSin(op); + return; default: throw std::runtime_error( std::string("Unsupported operation: ").append(EnumNameBuiltinOperator(builtin_op))); @@ -1291,6 +1330,6 @@ void BaseLoader::loadModel() } } // namespace base_loader -} // namespace neurun +} // namespace onert #endif //__BASE_LOADER_BASE_LOADER_H__ diff --git a/runtime/neurun/frontend/circle/CMakeLists.txt b/runtime/onert/frontend/circle/CMakeLists.txt similarity index 90% rename from runtime/neurun/frontend/circle/CMakeLists.txt rename to runtime/onert/frontend/circle/CMakeLists.txt index 264eceffbee..b446e694a4e 100644 --- a/runtime/neurun/frontend/circle/CMakeLists.txt +++ b/runtime/onert/frontend/circle/CMakeLists.txt @@ -11,7 +11,7 @@ add_library(circle_loader SHARED ${CIRCLE_LOADER_SOURCES}) target_include_directories(circle_loader PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) target_include_directories(circle_loader PRIVATE ${FlatBuffersSource_DIR}/include) -target_link_libraries(circle_loader PUBLIC neurun_core) +target_link_libraries(circle_loader PUBLIC onert_core) target_link_libraries(circle_loader PRIVATE base_loader nnfw_common nnfw_coverage) install(TARGETS circle_loader DESTINATION lib) diff --git a/runtime/neurun/frontend/circle/include/circle_loader.h b/runtime/onert/frontend/circle/include/circle_loader.h similarity index 95% rename from runtime/neurun/frontend/circle/include/circle_loader.h rename to runtime/onert/frontend/circle/include/circle_loader.h index 898bd32b11b..718bc0b65a0 100644 --- a/runtime/neurun/frontend/circle/include/circle_loader.h +++ b/runtime/onert/frontend/circle/include/circle_loader.h @@ -21,12 +21,12 @@ #include -namespace neurun +namespace onert { namespace circle_loader { std::unique_ptr loadModel(const char *filename); } // namespace circle_loader -} // namespace neurun +} // namespace onert #endif // __CIRCLE_CIRCLE_LOADER_H__ diff --git a/runtime/neurun/frontend/circle/src/circle_loader.cc b/runtime/onert/frontend/circle/src/circle_loader.cc similarity index 98% rename from runtime/neurun/frontend/circle/src/circle_loader.cc rename to runtime/onert/frontend/circle/src/circle_loader.cc index 51c3931d369..bf07d3cb763 100644 --- a/runtime/neurun/frontend/circle/src/circle_loader.cc +++ b/runtime/onert/frontend/circle/src/circle_loader.cc @@ -18,7 +18,7 @@ #include "base_loader.h" #include "circle_schema_generated.h" -namespace neurun +namespace onert { namespace circle_loader { @@ -113,4 +113,4 @@ std::unique_ptr loadModel(const char *filename) } } // namespace circle_loader -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/frontend/circle/src/circle_schema_generated.h b/runtime/onert/frontend/circle/src/circle_schema_generated.h similarity index 76% rename from runtime/neurun/frontend/circle/src/circle_schema_generated.h rename to runtime/onert/frontend/circle/src/circle_schema_generated.h index 1e48d12a112..66fe8ff7417 100644 --- a/runtime/neurun/frontend/circle/src/circle_schema_generated.h +++ b/runtime/onert/frontend/circle/src/circle_schema_generated.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved + * Copyright (c) 2019-2020 Samsung Electronics Co., Ltd. All Rights Reserved * Copyright 2018 The TensorFlow Authors. All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -28,6 +28,16 @@ struct CustomQuantization; struct QuantizationParameters; +struct Int32Vector; + +struct Uint16Vector; + +struct Uint8Vector; + +struct DimensionMetadata; + +struct SparsityParameters; + struct Tensor; struct Conv2DOptions; @@ -88,6 +98,8 @@ struct SkipGramOptions; struct SpaceToDepthOptions; +struct DepthToSpaceOptions; + struct SubOptions; struct DivOptions; @@ -102,6 +114,8 @@ struct TransposeOptions; struct ExpOptions; +struct CosOptions; + struct ReducerOptions; struct SqueezeOptions; @@ -152,6 +166,8 @@ struct NotEqualOptions; struct ShapeOptions; +struct RankOptions; + struct PowOptions; struct FakeQuantOptions; @@ -164,6 +180,8 @@ struct OneHotOptions; struct AbsOptions; +struct HardSwishOptions; + struct LogicalAndOptions; struct LogicalNotOptions; @@ -188,6 +206,42 @@ struct SquaredDifferenceOptions; struct MirrorPadOptions; +struct UniqueOptions; + +struct ReverseV2Options; + +struct AddNOptions; + +struct GatherNdOptions; + +struct WhereOptions; + +struct ReverseSequenceOptions; + +struct MatrixDiagOptions; + +struct QuantizeOptions; + +struct MatrixSetDiagOptions; + +struct IfOptions; + +struct WhileOptions; + +struct NonMaxSuppressionV4Options; + +struct NonMaxSuppressionV5Options; + +struct ScatterNdOptions; + +struct SelectV2Options; + +struct DensifyOptions; + +struct SegmentSumOptions; + +struct BatchMatMulOptions; + struct InstanceNormOptions; struct OperatorCode; @@ -198,6 +252,8 @@ struct SubGraph; struct Buffer; +struct Metadata; + struct Model; enum TensorType @@ -212,23 +268,25 @@ enum TensorType TensorType_INT16 = 7, TensorType_COMPLEX64 = 8, TensorType_INT8 = 9, + TensorType_FLOAT64 = 10, TensorType_MIN = TensorType_FLOAT32, - TensorType_MAX = TensorType_INT8 + TensorType_MAX = TensorType_FLOAT64 }; -inline const TensorType (&EnumValuesTensorType())[10] +inline const TensorType (&EnumValuesTensorType())[11] { static const TensorType values[] = {TensorType_FLOAT32, TensorType_FLOAT16, TensorType_INT32, TensorType_UINT8, TensorType_INT64, TensorType_STRING, TensorType_BOOL, TensorType_INT16, TensorType_COMPLEX64, - TensorType_INT8}; + TensorType_INT8, TensorType_FLOAT64}; return values; } inline const char *const *EnumNamesTensorType() { - static const char *const names[] = {"FLOAT32", "FLOAT16", "INT32", "UINT8", "INT64", "STRING", - "BOOL", "INT16", "COMPLEX64", "INT8", nullptr}; + static const char *const names[] = {"FLOAT32", "FLOAT16", "INT32", "UINT8", + "INT64", "STRING", "BOOL", "INT16", + "COMPLEX64", "INT8", "FLOAT64", nullptr}; return names; } @@ -281,6 +339,89 @@ bool VerifyQuantizationDetailsVector(flatbuffers::Verifier &verifier, const flatbuffers::Vector> *values, const flatbuffers::Vector *types); +enum DimensionType +{ + DimensionType_DENSE = 0, + DimensionType_SPARSE_CSR = 1, + DimensionType_MIN = DimensionType_DENSE, + DimensionType_MAX = DimensionType_SPARSE_CSR +}; + +inline const DimensionType (&EnumValuesDimensionType())[2] +{ + static const DimensionType values[] = {DimensionType_DENSE, DimensionType_SPARSE_CSR}; + return values; +} + +inline const char *const *EnumNamesDimensionType() +{ + static const char *const names[] = {"DENSE", "SPARSE_CSR", nullptr}; + return names; +} + +inline const char *EnumNameDimensionType(DimensionType e) +{ + const size_t index = static_cast(e); + return EnumNamesDimensionType()[index]; +} + +enum SparseIndexVector +{ + SparseIndexVector_NONE = 0, + SparseIndexVector_Int32Vector = 1, + SparseIndexVector_Uint16Vector = 2, + SparseIndexVector_Uint8Vector = 3, + SparseIndexVector_MIN = SparseIndexVector_NONE, + SparseIndexVector_MAX = SparseIndexVector_Uint8Vector +}; + +inline const SparseIndexVector (&EnumValuesSparseIndexVector())[4] +{ + static const SparseIndexVector values[] = {SparseIndexVector_NONE, SparseIndexVector_Int32Vector, + SparseIndexVector_Uint16Vector, + SparseIndexVector_Uint8Vector}; + return values; +} + +inline const char *const *EnumNamesSparseIndexVector() +{ + static const char *const names[] = {"NONE", "Int32Vector", "Uint16Vector", "Uint8Vector", + nullptr}; + return names; +} + +inline const char *EnumNameSparseIndexVector(SparseIndexVector e) +{ + const size_t index = static_cast(e); + return EnumNamesSparseIndexVector()[index]; +} + +template struct SparseIndexVectorTraits +{ + static const SparseIndexVector enum_value = SparseIndexVector_NONE; +}; + +template <> struct SparseIndexVectorTraits +{ + static const SparseIndexVector enum_value = SparseIndexVector_Int32Vector; +}; + +template <> struct SparseIndexVectorTraits +{ + static const SparseIndexVector enum_value = SparseIndexVector_Uint16Vector; +}; + +template <> struct SparseIndexVectorTraits +{ + static const SparseIndexVector enum_value = SparseIndexVector_Uint8Vector; +}; + +bool VerifySparseIndexVector(flatbuffers::Verifier &verifier, const void *obj, + SparseIndexVector type); +bool VerifySparseIndexVectorVector(flatbuffers::Verifier &verifier, + const flatbuffers::Vector> *values, + const flatbuffers::Vector *types); + enum BuiltinOperator { BuiltinOperator_ADD = 0, @@ -288,6 +429,7 @@ enum BuiltinOperator BuiltinOperator_CONCATENATION = 2, BuiltinOperator_CONV_2D = 3, BuiltinOperator_DEPTHWISE_CONV_2D = 4, + BuiltinOperator_DEPTH_TO_SPACE = 5, BuiltinOperator_DEQUANTIZE = 6, BuiltinOperator_EMBEDDING_LOOKUP = 7, BuiltinOperator_FLOOR = 8, @@ -385,18 +527,43 @@ enum BuiltinOperator BuiltinOperator_MIRROR_PAD = 100, BuiltinOperator_ABS = 101, BuiltinOperator_SPLIT_V = 102, + BuiltinOperator_UNIQUE = 103, + BuiltinOperator_CEIL = 104, + BuiltinOperator_REVERSE_V2 = 105, + BuiltinOperator_ADD_N = 106, + BuiltinOperator_GATHER_ND = 107, + BuiltinOperator_COS = 108, + BuiltinOperator_WHERE = 109, + BuiltinOperator_RANK = 110, + BuiltinOperator_ELU = 111, + BuiltinOperator_REVERSE_SEQUENCE = 112, + BuiltinOperator_MATRIX_DIAG = 113, + BuiltinOperator_QUANTIZE = 114, + BuiltinOperator_MATRIX_SET_DIAG = 115, + BuiltinOperator_ROUND = 116, + BuiltinOperator_HARD_SWISH = 117, + BuiltinOperator_IF = 118, + BuiltinOperator_WHILE = 119, + BuiltinOperator_NON_MAX_SUPPRESSION_V4 = 120, + BuiltinOperator_NON_MAX_SUPPRESSION_V5 = 121, + BuiltinOperator_SCATTER_ND = 122, + BuiltinOperator_SELECT_V2 = 123, + BuiltinOperator_DENSIFY = 124, + BuiltinOperator_SEGMENT_SUM = 125, + BuiltinOperator_BATCH_MATMUL = 126, BuiltinOperator_INSTANCE_NORM = 254, BuiltinOperator_MIN = BuiltinOperator_ADD, BuiltinOperator_MAX = BuiltinOperator_INSTANCE_NORM }; -inline const BuiltinOperator (&EnumValuesBuiltinOperator())[103] +inline const BuiltinOperator (&EnumValuesBuiltinOperator())[128] { static const BuiltinOperator values[] = {BuiltinOperator_ADD, BuiltinOperator_AVERAGE_POOL_2D, BuiltinOperator_CONCATENATION, BuiltinOperator_CONV_2D, BuiltinOperator_DEPTHWISE_CONV_2D, + BuiltinOperator_DEPTH_TO_SPACE, BuiltinOperator_DEQUANTIZE, BuiltinOperator_EMBEDDING_LOOKUP, BuiltinOperator_FLOOR, @@ -494,6 +661,30 @@ inline const BuiltinOperator (&EnumValuesBuiltinOperator())[103] BuiltinOperator_MIRROR_PAD, BuiltinOperator_ABS, BuiltinOperator_SPLIT_V, + BuiltinOperator_UNIQUE, + BuiltinOperator_CEIL, + BuiltinOperator_REVERSE_V2, + BuiltinOperator_ADD_N, + BuiltinOperator_GATHER_ND, + BuiltinOperator_COS, + BuiltinOperator_WHERE, + BuiltinOperator_RANK, + BuiltinOperator_ELU, + BuiltinOperator_REVERSE_SEQUENCE, + BuiltinOperator_MATRIX_DIAG, + BuiltinOperator_QUANTIZE, + BuiltinOperator_MATRIX_SET_DIAG, + BuiltinOperator_ROUND, + BuiltinOperator_HARD_SWISH, + BuiltinOperator_IF, + BuiltinOperator_WHILE, + BuiltinOperator_NON_MAX_SUPPRESSION_V4, + BuiltinOperator_NON_MAX_SUPPRESSION_V5, + BuiltinOperator_SCATTER_ND, + BuiltinOperator_SELECT_V2, + BuiltinOperator_DENSIFY, + BuiltinOperator_SEGMENT_SUM, + BuiltinOperator_BATCH_MATMUL, BuiltinOperator_INSTANCE_NORM}; return values; } @@ -505,7 +696,7 @@ inline const char *const *EnumNamesBuiltinOperator() "CONCATENATION", "CONV_2D", "DEPTHWISE_CONV_2D", - "", + "DEPTH_TO_SPACE", "DEQUANTIZE", "EMBEDDING_LOOKUP", "FLOOR", @@ -603,30 +794,30 @@ inline const char *const *EnumNamesBuiltinOperator() "MIRROR_PAD", "ABS", "SPLIT_V", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", + "UNIQUE", + "CEIL", + "REVERSE_V2", + "ADD_N", + "GATHER_ND", + "COS", + "WHERE", + "RANK", + "ELU", + "REVERSE_SEQUENCE", + "MATRIX_DIAG", + "QUANTIZE", + "MATRIX_SET_DIAG", + "ROUND", + "HARD_SWISH", + "IF", + "WHILE", + "NON_MAX_SUPPRESSION_V4", + "NON_MAX_SUPPRESSION_V5", + "SCATTER_ND", + "SELECT_V2", + "DENSIFY", + "SEGMENT_SUM", + "BATCH_MATMUL", "", "", "", @@ -848,11 +1039,33 @@ enum BuiltinOptions BuiltinOptions_AbsOptions = 78, BuiltinOptions_SplitVOptions = 79, BuiltinOptions_InstanceNormOptions = 80, + BuiltinOptions_UniqueOptions = 81, + BuiltinOptions_ReverseV2Options = 82, + BuiltinOptions_AddNOptions = 83, + BuiltinOptions_GatherNdOptions = 84, + BuiltinOptions_CosOptions = 85, + BuiltinOptions_WhereOptions = 86, + BuiltinOptions_RankOptions = 87, + BuiltinOptions_ReverseSequenceOptions = 88, + BuiltinOptions_MatrixDiagOptions = 89, + BuiltinOptions_QuantizeOptions = 90, + BuiltinOptions_MatrixSetDiagOptions = 91, + BuiltinOptions_HardSwishOptions = 92, + BuiltinOptions_IfOptions = 93, + BuiltinOptions_WhileOptions = 94, + BuiltinOptions_DepthToSpaceOptions = 95, + BuiltinOptions_NonMaxSuppressionV4Options = 96, + BuiltinOptions_NonMaxSuppressionV5Options = 97, + BuiltinOptions_ScatterNdOptions = 98, + BuiltinOptions_SelectV2Options = 99, + BuiltinOptions_DensifyOptions = 100, + BuiltinOptions_SegmentSumOptions = 101, + BuiltinOptions_BatchMatMulOptions = 102, BuiltinOptions_MIN = BuiltinOptions_NONE, - BuiltinOptions_MAX = BuiltinOptions_InstanceNormOptions + BuiltinOptions_MAX = BuiltinOptions_BatchMatMulOptions }; -inline const BuiltinOptions (&EnumValuesBuiltinOptions())[81] +inline const BuiltinOptions (&EnumValuesBuiltinOptions())[103] { static const BuiltinOptions values[] = {BuiltinOptions_NONE, BuiltinOptions_Conv2DOptions, @@ -934,7 +1147,29 @@ inline const BuiltinOptions (&EnumValuesBuiltinOptions())[81] BuiltinOptions_MirrorPadOptions, BuiltinOptions_AbsOptions, BuiltinOptions_SplitVOptions, - BuiltinOptions_InstanceNormOptions}; + BuiltinOptions_InstanceNormOptions, + BuiltinOptions_UniqueOptions, + BuiltinOptions_ReverseV2Options, + BuiltinOptions_AddNOptions, + BuiltinOptions_GatherNdOptions, + BuiltinOptions_CosOptions, + BuiltinOptions_WhereOptions, + BuiltinOptions_RankOptions, + BuiltinOptions_ReverseSequenceOptions, + BuiltinOptions_MatrixDiagOptions, + BuiltinOptions_QuantizeOptions, + BuiltinOptions_MatrixSetDiagOptions, + BuiltinOptions_HardSwishOptions, + BuiltinOptions_IfOptions, + BuiltinOptions_WhileOptions, + BuiltinOptions_DepthToSpaceOptions, + BuiltinOptions_NonMaxSuppressionV4Options, + BuiltinOptions_NonMaxSuppressionV5Options, + BuiltinOptions_ScatterNdOptions, + BuiltinOptions_SelectV2Options, + BuiltinOptions_DensifyOptions, + BuiltinOptions_SegmentSumOptions, + BuiltinOptions_BatchMatMulOptions}; return values; } @@ -1021,6 +1256,28 @@ inline const char *const *EnumNamesBuiltinOptions() "AbsOptions", "SplitVOptions", "InstanceNormOptions", + "UniqueOptions", + "ReverseV2Options", + "AddNOptions", + "GatherNdOptions", + "CosOptions", + "WhereOptions", + "RankOptions", + "ReverseSequenceOptions", + "MatrixDiagOptions", + "QuantizeOptions", + "MatrixSetDiagOptions", + "HardSwishOptions", + "IfOptions", + "WhileOptions", + "DepthToSpaceOptions", + "NonMaxSuppressionV4Options", + "NonMaxSuppressionV5Options", + "ScatterNdOptions", + "SelectV2Options", + "DensifyOptions", + "SegmentSumOptions", + "BatchMatMulOptions", nullptr}; return names; } @@ -1436,6 +1693,116 @@ template <> struct BuiltinOptionsTraits static const BuiltinOptions enum_value = BuiltinOptions_InstanceNormOptions; }; +template <> struct BuiltinOptionsTraits +{ + static const BuiltinOptions enum_value = BuiltinOptions_UniqueOptions; +}; + +template <> struct BuiltinOptionsTraits +{ + static const BuiltinOptions enum_value = BuiltinOptions_ReverseV2Options; +}; + +template <> struct BuiltinOptionsTraits +{ + static const BuiltinOptions enum_value = BuiltinOptions_AddNOptions; +}; + +template <> struct BuiltinOptionsTraits +{ + static const BuiltinOptions enum_value = BuiltinOptions_GatherNdOptions; +}; + +template <> struct BuiltinOptionsTraits +{ + static const BuiltinOptions enum_value = BuiltinOptions_CosOptions; +}; + +template <> struct BuiltinOptionsTraits +{ + static const BuiltinOptions enum_value = BuiltinOptions_WhereOptions; +}; + +template <> struct BuiltinOptionsTraits +{ + static const BuiltinOptions enum_value = BuiltinOptions_RankOptions; +}; + +template <> struct BuiltinOptionsTraits +{ + static const BuiltinOptions enum_value = BuiltinOptions_ReverseSequenceOptions; +}; + +template <> struct BuiltinOptionsTraits +{ + static const BuiltinOptions enum_value = BuiltinOptions_MatrixDiagOptions; +}; + +template <> struct BuiltinOptionsTraits +{ + static const BuiltinOptions enum_value = BuiltinOptions_QuantizeOptions; +}; + +template <> struct BuiltinOptionsTraits +{ + static const BuiltinOptions enum_value = BuiltinOptions_MatrixSetDiagOptions; +}; + +template <> struct BuiltinOptionsTraits +{ + static const BuiltinOptions enum_value = BuiltinOptions_HardSwishOptions; +}; + +template <> struct BuiltinOptionsTraits +{ + static const BuiltinOptions enum_value = BuiltinOptions_IfOptions; +}; + +template <> struct BuiltinOptionsTraits +{ + static const BuiltinOptions enum_value = BuiltinOptions_WhileOptions; +}; + +template <> struct BuiltinOptionsTraits +{ + static const BuiltinOptions enum_value = BuiltinOptions_DepthToSpaceOptions; +}; + +template <> struct BuiltinOptionsTraits +{ + static const BuiltinOptions enum_value = BuiltinOptions_NonMaxSuppressionV4Options; +}; + +template <> struct BuiltinOptionsTraits +{ + static const BuiltinOptions enum_value = BuiltinOptions_NonMaxSuppressionV5Options; +}; + +template <> struct BuiltinOptionsTraits +{ + static const BuiltinOptions enum_value = BuiltinOptions_ScatterNdOptions; +}; + +template <> struct BuiltinOptionsTraits +{ + static const BuiltinOptions enum_value = BuiltinOptions_SelectV2Options; +}; + +template <> struct BuiltinOptionsTraits +{ + static const BuiltinOptions enum_value = BuiltinOptions_DensifyOptions; +}; + +template <> struct BuiltinOptionsTraits +{ + static const BuiltinOptions enum_value = BuiltinOptions_SegmentSumOptions; +}; + +template <> struct BuiltinOptionsTraits +{ + static const BuiltinOptions enum_value = BuiltinOptions_BatchMatMulOptions; +}; + bool VerifyBuiltinOptions(flatbuffers::Verifier &verifier, const void *obj, BuiltinOptions type); bool VerifyBuiltinOptionsVector(flatbuffers::Verifier &verifier, const flatbuffers::Vector> *values, @@ -1750,7 +2117,8 @@ struct QuantizationParameters FLATBUFFERS_FINAL_CLASS : private flatbuffers::Tab VT_SCALE = 8, VT_ZERO_POINT = 10, VT_DETAILS_TYPE = 12, - VT_DETAILS = 14 + VT_DETAILS = 14, + VT_QUANTIZED_DIMENSION = 16 }; const flatbuffers::Vector *min() const { @@ -1780,6 +2148,7 @@ struct QuantizationParameters FLATBUFFERS_FINAL_CLASS : private flatbuffers::Tab ? static_cast(details()) : nullptr; } + int32_t quantized_dimension() const { return GetField(VT_QUANTIZED_DIMENSION, 0); } bool Verify(flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && VerifyOffset(verifier, VT_MIN) && @@ -1788,7 +2157,8 @@ struct QuantizationParameters FLATBUFFERS_FINAL_CLASS : private flatbuffers::Tab verifier.VerifyVector(scale()) && VerifyOffset(verifier, VT_ZERO_POINT) && verifier.VerifyVector(zero_point()) && VerifyField(verifier, VT_DETAILS_TYPE) && VerifyOffset(verifier, VT_DETAILS) && - VerifyQuantizationDetails(verifier, details(), details_type()) && verifier.EndTable(); + VerifyQuantizationDetails(verifier, details(), details_type()) && + VerifyField(verifier, VT_QUANTIZED_DIMENSION) && verifier.EndTable(); } }; @@ -1827,6 +2197,11 @@ struct QuantizationParametersBuilder { fbb_.AddOffset(QuantizationParameters::VT_DETAILS, details); } + void add_quantized_dimension(int32_t quantized_dimension) + { + fbb_.AddElement(QuantizationParameters::VT_QUANTIZED_DIMENSION, quantized_dimension, + 0); + } explicit QuantizationParametersBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); @@ -1847,9 +2222,10 @@ CreateQuantizationParameters(flatbuffers::FlatBufferBuilder &_fbb, flatbuffers::Offset> scale = 0, flatbuffers::Offset> zero_point = 0, QuantizationDetails details_type = QuantizationDetails_NONE, - flatbuffers::Offset details = 0) + flatbuffers::Offset details = 0, int32_t quantized_dimension = 0) { QuantizationParametersBuilder builder_(_fbb); + builder_.add_quantized_dimension(quantized_dimension); builder_.add_details(details); builder_.add_zero_point(zero_point); builder_.add_scale(scale); @@ -1864,1499 +2240,3029 @@ inline flatbuffers::Offset CreateQuantizationParametersD const std::vector *max = nullptr, const std::vector *scale = nullptr, const std::vector *zero_point = nullptr, QuantizationDetails details_type = QuantizationDetails_NONE, - flatbuffers::Offset details = 0) + flatbuffers::Offset details = 0, int32_t quantized_dimension = 0) { return circle::CreateQuantizationParameters( _fbb, min ? _fbb.CreateVector(*min) : 0, max ? _fbb.CreateVector(*max) : 0, scale ? _fbb.CreateVector(*scale) : 0, - zero_point ? _fbb.CreateVector(*zero_point) : 0, details_type, details); + zero_point ? _fbb.CreateVector(*zero_point) : 0, details_type, details, + quantized_dimension); } -struct Tensor FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct Int32Vector FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_SHAPE = 4, - VT_TYPE = 6, - VT_BUFFER = 8, - VT_NAME = 10, - VT_QUANTIZATION = 12, - VT_IS_VARIABLE = 14 + VT_VALUES = 4 }; - const flatbuffers::Vector *shape() const - { - return GetPointer *>(VT_SHAPE); - } - TensorType type() const { return static_cast(GetField(VT_TYPE, 0)); } - uint32_t buffer() const { return GetField(VT_BUFFER, 0); } - const flatbuffers::String *name() const - { - return GetPointer(VT_NAME); - } - const QuantizationParameters *quantization() const + const flatbuffers::Vector *values() const { - return GetPointer(VT_QUANTIZATION); + return GetPointer *>(VT_VALUES); } - bool is_variable() const { return GetField(VT_IS_VARIABLE, 0) != 0; } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyOffset(verifier, VT_SHAPE) && - verifier.VerifyVector(shape()) && VerifyField(verifier, VT_TYPE) && - VerifyField(verifier, VT_BUFFER) && VerifyOffset(verifier, VT_NAME) && - verifier.VerifyString(name()) && VerifyOffset(verifier, VT_QUANTIZATION) && - verifier.VerifyTable(quantization()) && VerifyField(verifier, VT_IS_VARIABLE) && - verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyOffset(verifier, VT_VALUES) && + verifier.VerifyVector(values()) && verifier.EndTable(); } }; -struct TensorBuilder +struct Int32VectorBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_shape(flatbuffers::Offset> shape) - { - fbb_.AddOffset(Tensor::VT_SHAPE, shape); - } - void add_type(TensorType type) - { - fbb_.AddElement(Tensor::VT_TYPE, static_cast(type), 0); - } - void add_buffer(uint32_t buffer) { fbb_.AddElement(Tensor::VT_BUFFER, buffer, 0); } - void add_name(flatbuffers::Offset name) - { - fbb_.AddOffset(Tensor::VT_NAME, name); - } - void add_quantization(flatbuffers::Offset quantization) - { - fbb_.AddOffset(Tensor::VT_QUANTIZATION, quantization); - } - void add_is_variable(bool is_variable) + void add_values(flatbuffers::Offset> values) { - fbb_.AddElement(Tensor::VT_IS_VARIABLE, static_cast(is_variable), 0); + fbb_.AddOffset(Int32Vector::VT_VALUES, values); } - explicit TensorBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit Int32VectorBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - TensorBuilder &operator=(const TensorBuilder &); - flatbuffers::Offset Finish() + Int32VectorBuilder &operator=(const Int32VectorBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateTensor(flatbuffers::FlatBufferBuilder &_fbb, - flatbuffers::Offset> shape = 0, - TensorType type = TensorType_FLOAT32, uint32_t buffer = 0, - flatbuffers::Offset name = 0, - flatbuffers::Offset quantization = 0, bool is_variable = false) +inline flatbuffers::Offset +CreateInt32Vector(flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset> values = 0) { - TensorBuilder builder_(_fbb); - builder_.add_quantization(quantization); - builder_.add_name(name); - builder_.add_buffer(buffer); - builder_.add_shape(shape); - builder_.add_is_variable(is_variable); - builder_.add_type(type); + Int32VectorBuilder builder_(_fbb); + builder_.add_values(values); return builder_.Finish(); } -inline flatbuffers::Offset CreateTensorDirect( - flatbuffers::FlatBufferBuilder &_fbb, const std::vector *shape = nullptr, - TensorType type = TensorType_FLOAT32, uint32_t buffer = 0, const char *name = nullptr, - flatbuffers::Offset quantization = 0, bool is_variable = false) +inline flatbuffers::Offset +CreateInt32VectorDirect(flatbuffers::FlatBufferBuilder &_fbb, + const std::vector *values = nullptr) { - return circle::CreateTensor(_fbb, shape ? _fbb.CreateVector(*shape) : 0, type, buffer, - name ? _fbb.CreateString(name) : 0, quantization, is_variable); + return circle::CreateInt32Vector(_fbb, values ? _fbb.CreateVector(*values) : 0); } -struct Conv2DOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct Uint16Vector FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_PADDING = 4, - VT_STRIDE_W = 6, - VT_STRIDE_H = 8, - VT_FUSED_ACTIVATION_FUNCTION = 10, - VT_DILATION_W_FACTOR = 12, - VT_DILATION_H_FACTOR = 14 + VT_VALUES = 4 }; - Padding padding() const { return static_cast(GetField(VT_PADDING, 0)); } - int32_t stride_w() const { return GetField(VT_STRIDE_W, 0); } - int32_t stride_h() const { return GetField(VT_STRIDE_H, 0); } - ActivationFunctionType fused_activation_function() const + const flatbuffers::Vector *values() const { - return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + return GetPointer *>(VT_VALUES); } - int32_t dilation_w_factor() const { return GetField(VT_DILATION_W_FACTOR, 1); } - int32_t dilation_h_factor() const { return GetField(VT_DILATION_H_FACTOR, 1); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_PADDING) && - VerifyField(verifier, VT_STRIDE_W) && - VerifyField(verifier, VT_STRIDE_H) && - VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && - VerifyField(verifier, VT_DILATION_W_FACTOR) && - VerifyField(verifier, VT_DILATION_H_FACTOR) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyOffset(verifier, VT_VALUES) && + verifier.VerifyVector(values()) && verifier.EndTable(); } }; -struct Conv2DOptionsBuilder +struct Uint16VectorBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_padding(Padding padding) + void add_values(flatbuffers::Offset> values) { - fbb_.AddElement(Conv2DOptions::VT_PADDING, static_cast(padding), 0); + fbb_.AddOffset(Uint16Vector::VT_VALUES, values); } - void add_stride_w(int32_t stride_w) + explicit Uint16VectorBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { - fbb_.AddElement(Conv2DOptions::VT_STRIDE_W, stride_w, 0); + start_ = fbb_.StartTable(); } - void add_stride_h(int32_t stride_h) + Uint16VectorBuilder &operator=(const Uint16VectorBuilder &); + flatbuffers::Offset Finish() { - fbb_.AddElement(Conv2DOptions::VT_STRIDE_H, stride_h, 0); + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; } - void add_fused_activation_function(ActivationFunctionType fused_activation_function) +}; + +inline flatbuffers::Offset +CreateUint16Vector(flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset> values = 0) +{ + Uint16VectorBuilder builder_(_fbb); + builder_.add_values(values); + return builder_.Finish(); +} + +inline flatbuffers::Offset +CreateUint16VectorDirect(flatbuffers::FlatBufferBuilder &_fbb, + const std::vector *values = nullptr) +{ + return circle::CreateUint16Vector(_fbb, values ? _fbb.CreateVector(*values) : 0); +} + +struct Uint8Vector FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum { - fbb_.AddElement(Conv2DOptions::VT_FUSED_ACTIVATION_FUNCTION, - static_cast(fused_activation_function), 0); + VT_VALUES = 4 + }; + const flatbuffers::Vector *values() const + { + return GetPointer *>(VT_VALUES); } - void add_dilation_w_factor(int32_t dilation_w_factor) + bool Verify(flatbuffers::Verifier &verifier) const { - fbb_.AddElement(Conv2DOptions::VT_DILATION_W_FACTOR, dilation_w_factor, 1); + return VerifyTableStart(verifier) && VerifyOffset(verifier, VT_VALUES) && + verifier.VerifyVector(values()) && verifier.EndTable(); } - void add_dilation_h_factor(int32_t dilation_h_factor) +}; + +struct Uint8VectorBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_values(flatbuffers::Offset> values) { - fbb_.AddElement(Conv2DOptions::VT_DILATION_H_FACTOR, dilation_h_factor, 1); + fbb_.AddOffset(Uint8Vector::VT_VALUES, values); } - explicit Conv2DOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit Uint8VectorBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - Conv2DOptionsBuilder &operator=(const Conv2DOptionsBuilder &); - flatbuffers::Offset Finish() + Uint8VectorBuilder &operator=(const Uint8VectorBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateConv2DOptions(flatbuffers::FlatBufferBuilder &_fbb, Padding padding = Padding_SAME, - int32_t stride_w = 0, int32_t stride_h = 0, - ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE, - int32_t dilation_w_factor = 1, int32_t dilation_h_factor = 1) +inline flatbuffers::Offset +CreateUint8Vector(flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset> values = 0) { - Conv2DOptionsBuilder builder_(_fbb); - builder_.add_dilation_h_factor(dilation_h_factor); - builder_.add_dilation_w_factor(dilation_w_factor); - builder_.add_stride_h(stride_h); - builder_.add_stride_w(stride_w); - builder_.add_fused_activation_function(fused_activation_function); - builder_.add_padding(padding); + Uint8VectorBuilder builder_(_fbb); + builder_.add_values(values); return builder_.Finish(); } -struct Pool2DOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +inline flatbuffers::Offset +CreateUint8VectorDirect(flatbuffers::FlatBufferBuilder &_fbb, + const std::vector *values = nullptr) +{ + return circle::CreateUint8Vector(_fbb, values ? _fbb.CreateVector(*values) : 0); +} + +struct DimensionMetadata FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_PADDING = 4, - VT_STRIDE_W = 6, - VT_STRIDE_H = 8, - VT_FILTER_WIDTH = 10, - VT_FILTER_HEIGHT = 12, - VT_FUSED_ACTIVATION_FUNCTION = 14 + VT_FORMAT = 4, + VT_DENSE_SIZE = 6, + VT_ARRAY_SEGMENTS_TYPE = 8, + VT_ARRAY_SEGMENTS = 10, + VT_ARRAY_INDICES_TYPE = 12, + VT_ARRAY_INDICES = 14 }; - Padding padding() const { return static_cast(GetField(VT_PADDING, 0)); } - int32_t stride_w() const { return GetField(VT_STRIDE_W, 0); } - int32_t stride_h() const { return GetField(VT_STRIDE_H, 0); } - int32_t filter_width() const { return GetField(VT_FILTER_WIDTH, 0); } - int32_t filter_height() const { return GetField(VT_FILTER_HEIGHT, 0); } - ActivationFunctionType fused_activation_function() const + DimensionType format() const { - return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + return static_cast(GetField(VT_FORMAT, 0)); } - bool Verify(flatbuffers::Verifier &verifier) const + int32_t dense_size() const { return GetField(VT_DENSE_SIZE, 0); } + SparseIndexVector array_segments_type() const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_PADDING) && - VerifyField(verifier, VT_STRIDE_W) && - VerifyField(verifier, VT_STRIDE_H) && - VerifyField(verifier, VT_FILTER_WIDTH) && - VerifyField(verifier, VT_FILTER_HEIGHT) && - VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && verifier.EndTable(); + return static_cast(GetField(VT_ARRAY_SEGMENTS_TYPE, 0)); } -}; - -struct Pool2DOptionsBuilder -{ - flatbuffers::FlatBufferBuilder &fbb_; - flatbuffers::uoffset_t start_; - void add_padding(Padding padding) + const void *array_segments() const { return GetPointer(VT_ARRAY_SEGMENTS); } + template const T *array_segments_as() const; + const Int32Vector *array_segments_as_Int32Vector() const { - fbb_.AddElement(Pool2DOptions::VT_PADDING, static_cast(padding), 0); + return array_segments_type() == SparseIndexVector_Int32Vector + ? static_cast(array_segments()) + : nullptr; } - void add_stride_w(int32_t stride_w) + const Uint16Vector *array_segments_as_Uint16Vector() const { - fbb_.AddElement(Pool2DOptions::VT_STRIDE_W, stride_w, 0); + return array_segments_type() == SparseIndexVector_Uint16Vector + ? static_cast(array_segments()) + : nullptr; } - void add_stride_h(int32_t stride_h) + const Uint8Vector *array_segments_as_Uint8Vector() const { - fbb_.AddElement(Pool2DOptions::VT_STRIDE_H, stride_h, 0); + return array_segments_type() == SparseIndexVector_Uint8Vector + ? static_cast(array_segments()) + : nullptr; } - void add_filter_width(int32_t filter_width) + SparseIndexVector array_indices_type() const { - fbb_.AddElement(Pool2DOptions::VT_FILTER_WIDTH, filter_width, 0); + return static_cast(GetField(VT_ARRAY_INDICES_TYPE, 0)); } - void add_filter_height(int32_t filter_height) + const void *array_indices() const { return GetPointer(VT_ARRAY_INDICES); } + template const T *array_indices_as() const; + const Int32Vector *array_indices_as_Int32Vector() const { - fbb_.AddElement(Pool2DOptions::VT_FILTER_HEIGHT, filter_height, 0); + return array_indices_type() == SparseIndexVector_Int32Vector + ? static_cast(array_indices()) + : nullptr; } - void add_fused_activation_function(ActivationFunctionType fused_activation_function) + const Uint16Vector *array_indices_as_Uint16Vector() const { - fbb_.AddElement(Pool2DOptions::VT_FUSED_ACTIVATION_FUNCTION, - static_cast(fused_activation_function), 0); + return array_indices_type() == SparseIndexVector_Uint16Vector + ? static_cast(array_indices()) + : nullptr; } - explicit Pool2DOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + const Uint8Vector *array_indices_as_Uint8Vector() const { - start_ = fbb_.StartTable(); + return array_indices_type() == SparseIndexVector_Uint8Vector + ? static_cast(array_indices()) + : nullptr; } - Pool2DOptionsBuilder &operator=(const Pool2DOptionsBuilder &); - flatbuffers::Offset Finish() + bool Verify(flatbuffers::Verifier &verifier) const { - const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); - return o; + return VerifyTableStart(verifier) && VerifyField(verifier, VT_FORMAT) && + VerifyField(verifier, VT_DENSE_SIZE) && + VerifyField(verifier, VT_ARRAY_SEGMENTS_TYPE) && + VerifyOffset(verifier, VT_ARRAY_SEGMENTS) && + VerifySparseIndexVector(verifier, array_segments(), array_segments_type()) && + VerifyField(verifier, VT_ARRAY_INDICES_TYPE) && + VerifyOffset(verifier, VT_ARRAY_INDICES) && + VerifySparseIndexVector(verifier, array_indices(), array_indices_type()) && + verifier.EndTable(); } }; -inline flatbuffers::Offset -CreatePool2DOptions(flatbuffers::FlatBufferBuilder &_fbb, Padding padding = Padding_SAME, - int32_t stride_w = 0, int32_t stride_h = 0, int32_t filter_width = 0, - int32_t filter_height = 0, - ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE) +template <> inline const Int32Vector *DimensionMetadata::array_segments_as() const { - Pool2DOptionsBuilder builder_(_fbb); - builder_.add_filter_height(filter_height); - builder_.add_filter_width(filter_width); - builder_.add_stride_h(stride_h); - builder_.add_stride_w(stride_w); - builder_.add_fused_activation_function(fused_activation_function); - builder_.add_padding(padding); - return builder_.Finish(); + return array_segments_as_Int32Vector(); } -struct DepthwiseConv2DOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +template <> inline const Uint16Vector *DimensionMetadata::array_segments_as() const { - enum - { - VT_PADDING = 4, - VT_STRIDE_W = 6, - VT_STRIDE_H = 8, - VT_DEPTH_MULTIPLIER = 10, - VT_FUSED_ACTIVATION_FUNCTION = 12, - VT_DILATION_W_FACTOR = 14, - VT_DILATION_H_FACTOR = 16 - }; - Padding padding() const { return static_cast(GetField(VT_PADDING, 0)); } - int32_t stride_w() const { return GetField(VT_STRIDE_W, 0); } - int32_t stride_h() const { return GetField(VT_STRIDE_H, 0); } - int32_t depth_multiplier() const { return GetField(VT_DEPTH_MULTIPLIER, 0); } - ActivationFunctionType fused_activation_function() const - { - return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); - } - int32_t dilation_w_factor() const { return GetField(VT_DILATION_W_FACTOR, 1); } - int32_t dilation_h_factor() const { return GetField(VT_DILATION_H_FACTOR, 1); } - bool Verify(flatbuffers::Verifier &verifier) const - { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_PADDING) && - VerifyField(verifier, VT_STRIDE_W) && - VerifyField(verifier, VT_STRIDE_H) && - VerifyField(verifier, VT_DEPTH_MULTIPLIER) && - VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && - VerifyField(verifier, VT_DILATION_W_FACTOR) && - VerifyField(verifier, VT_DILATION_H_FACTOR) && verifier.EndTable(); - } -}; + return array_segments_as_Uint16Vector(); +} -struct DepthwiseConv2DOptionsBuilder +template <> inline const Uint8Vector *DimensionMetadata::array_segments_as() const +{ + return array_segments_as_Uint8Vector(); +} + +template <> inline const Int32Vector *DimensionMetadata::array_indices_as() const +{ + return array_indices_as_Int32Vector(); +} + +template <> inline const Uint16Vector *DimensionMetadata::array_indices_as() const +{ + return array_indices_as_Uint16Vector(); +} + +template <> inline const Uint8Vector *DimensionMetadata::array_indices_as() const +{ + return array_indices_as_Uint8Vector(); +} + +struct DimensionMetadataBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_padding(Padding padding) - { - fbb_.AddElement(DepthwiseConv2DOptions::VT_PADDING, static_cast(padding), 0); - } - void add_stride_w(int32_t stride_w) + void add_format(DimensionType format) { - fbb_.AddElement(DepthwiseConv2DOptions::VT_STRIDE_W, stride_w, 0); + fbb_.AddElement(DimensionMetadata::VT_FORMAT, static_cast(format), 0); } - void add_stride_h(int32_t stride_h) + void add_dense_size(int32_t dense_size) { - fbb_.AddElement(DepthwiseConv2DOptions::VT_STRIDE_H, stride_h, 0); + fbb_.AddElement(DimensionMetadata::VT_DENSE_SIZE, dense_size, 0); } - void add_depth_multiplier(int32_t depth_multiplier) + void add_array_segments_type(SparseIndexVector array_segments_type) { - fbb_.AddElement(DepthwiseConv2DOptions::VT_DEPTH_MULTIPLIER, depth_multiplier, 0); + fbb_.AddElement(DimensionMetadata::VT_ARRAY_SEGMENTS_TYPE, + static_cast(array_segments_type), 0); } - void add_fused_activation_function(ActivationFunctionType fused_activation_function) + void add_array_segments(flatbuffers::Offset array_segments) { - fbb_.AddElement(DepthwiseConv2DOptions::VT_FUSED_ACTIVATION_FUNCTION, - static_cast(fused_activation_function), 0); + fbb_.AddOffset(DimensionMetadata::VT_ARRAY_SEGMENTS, array_segments); } - void add_dilation_w_factor(int32_t dilation_w_factor) + void add_array_indices_type(SparseIndexVector array_indices_type) { - fbb_.AddElement(DepthwiseConv2DOptions::VT_DILATION_W_FACTOR, dilation_w_factor, 1); + fbb_.AddElement(DimensionMetadata::VT_ARRAY_INDICES_TYPE, + static_cast(array_indices_type), 0); } - void add_dilation_h_factor(int32_t dilation_h_factor) + void add_array_indices(flatbuffers::Offset array_indices) { - fbb_.AddElement(DepthwiseConv2DOptions::VT_DILATION_H_FACTOR, dilation_h_factor, 1); + fbb_.AddOffset(DimensionMetadata::VT_ARRAY_INDICES, array_indices); } - explicit DepthwiseConv2DOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit DimensionMetadataBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - DepthwiseConv2DOptionsBuilder &operator=(const DepthwiseConv2DOptionsBuilder &); - flatbuffers::Offset Finish() + DimensionMetadataBuilder &operator=(const DimensionMetadataBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateDepthwiseConv2DOptions( - flatbuffers::FlatBufferBuilder &_fbb, Padding padding = Padding_SAME, int32_t stride_w = 0, - int32_t stride_h = 0, int32_t depth_multiplier = 0, - ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE, - int32_t dilation_w_factor = 1, int32_t dilation_h_factor = 1) +inline flatbuffers::Offset +CreateDimensionMetadata(flatbuffers::FlatBufferBuilder &_fbb, + DimensionType format = DimensionType_DENSE, int32_t dense_size = 0, + SparseIndexVector array_segments_type = SparseIndexVector_NONE, + flatbuffers::Offset array_segments = 0, + SparseIndexVector array_indices_type = SparseIndexVector_NONE, + flatbuffers::Offset array_indices = 0) { - DepthwiseConv2DOptionsBuilder builder_(_fbb); - builder_.add_dilation_h_factor(dilation_h_factor); - builder_.add_dilation_w_factor(dilation_w_factor); - builder_.add_depth_multiplier(depth_multiplier); - builder_.add_stride_h(stride_h); - builder_.add_stride_w(stride_w); - builder_.add_fused_activation_function(fused_activation_function); - builder_.add_padding(padding); + DimensionMetadataBuilder builder_(_fbb); + builder_.add_array_indices(array_indices); + builder_.add_array_segments(array_segments); + builder_.add_dense_size(dense_size); + builder_.add_array_indices_type(array_indices_type); + builder_.add_array_segments_type(array_segments_type); + builder_.add_format(format); return builder_.Finish(); } -struct ConcatEmbeddingsOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct SparsityParameters FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_NUM_CHANNELS = 4, - VT_NUM_COLUMNS_PER_CHANNEL = 6, - VT_EMBEDDING_DIM_PER_CHANNEL = 8 + VT_TRAVERSAL_ORDER = 4, + VT_BLOCK_MAP = 6, + VT_DIM_METADATA = 8 }; - int32_t num_channels() const { return GetField(VT_NUM_CHANNELS, 0); } - const flatbuffers::Vector *num_columns_per_channel() const + const flatbuffers::Vector *traversal_order() const { - return GetPointer *>(VT_NUM_COLUMNS_PER_CHANNEL); + return GetPointer *>(VT_TRAVERSAL_ORDER); } - const flatbuffers::Vector *embedding_dim_per_channel() const + const flatbuffers::Vector *block_map() const { - return GetPointer *>(VT_EMBEDDING_DIM_PER_CHANNEL); + return GetPointer *>(VT_BLOCK_MAP); + } + const flatbuffers::Vector> *dim_metadata() const + { + return GetPointer> *>( + VT_DIM_METADATA); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_NUM_CHANNELS) && - VerifyOffset(verifier, VT_NUM_COLUMNS_PER_CHANNEL) && - verifier.VerifyVector(num_columns_per_channel()) && - VerifyOffset(verifier, VT_EMBEDDING_DIM_PER_CHANNEL) && - verifier.VerifyVector(embedding_dim_per_channel()) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyOffset(verifier, VT_TRAVERSAL_ORDER) && + verifier.VerifyVector(traversal_order()) && VerifyOffset(verifier, VT_BLOCK_MAP) && + verifier.VerifyVector(block_map()) && VerifyOffset(verifier, VT_DIM_METADATA) && + verifier.VerifyVector(dim_metadata()) && verifier.VerifyVectorOfTables(dim_metadata()) && + verifier.EndTable(); } }; -struct ConcatEmbeddingsOptionsBuilder +struct SparsityParametersBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_num_channels(int32_t num_channels) + void add_traversal_order(flatbuffers::Offset> traversal_order) { - fbb_.AddElement(ConcatEmbeddingsOptions::VT_NUM_CHANNELS, num_channels, 0); + fbb_.AddOffset(SparsityParameters::VT_TRAVERSAL_ORDER, traversal_order); } - void add_num_columns_per_channel( - flatbuffers::Offset> num_columns_per_channel) + void add_block_map(flatbuffers::Offset> block_map) { - fbb_.AddOffset(ConcatEmbeddingsOptions::VT_NUM_COLUMNS_PER_CHANNEL, num_columns_per_channel); + fbb_.AddOffset(SparsityParameters::VT_BLOCK_MAP, block_map); } - void add_embedding_dim_per_channel( - flatbuffers::Offset> embedding_dim_per_channel) + void add_dim_metadata( + flatbuffers::Offset>> dim_metadata) { - fbb_.AddOffset(ConcatEmbeddingsOptions::VT_EMBEDDING_DIM_PER_CHANNEL, - embedding_dim_per_channel); + fbb_.AddOffset(SparsityParameters::VT_DIM_METADATA, dim_metadata); } - explicit ConcatEmbeddingsOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit SparsityParametersBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - ConcatEmbeddingsOptionsBuilder &operator=(const ConcatEmbeddingsOptionsBuilder &); - flatbuffers::Offset Finish() + SparsityParametersBuilder &operator=(const SparsityParametersBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateConcatEmbeddingsOptions( - flatbuffers::FlatBufferBuilder &_fbb, int32_t num_channels = 0, - flatbuffers::Offset> num_columns_per_channel = 0, - flatbuffers::Offset> embedding_dim_per_channel = 0) -{ - ConcatEmbeddingsOptionsBuilder builder_(_fbb); - builder_.add_embedding_dim_per_channel(embedding_dim_per_channel); - builder_.add_num_columns_per_channel(num_columns_per_channel); - builder_.add_num_channels(num_channels); +inline flatbuffers::Offset CreateSparsityParameters( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset> traversal_order = 0, + flatbuffers::Offset> block_map = 0, + flatbuffers::Offset>> dim_metadata = + 0) +{ + SparsityParametersBuilder builder_(_fbb); + builder_.add_dim_metadata(dim_metadata); + builder_.add_block_map(block_map); + builder_.add_traversal_order(traversal_order); return builder_.Finish(); } -inline flatbuffers::Offset -CreateConcatEmbeddingsOptionsDirect(flatbuffers::FlatBufferBuilder &_fbb, int32_t num_channels = 0, - const std::vector *num_columns_per_channel = nullptr, - const std::vector *embedding_dim_per_channel = nullptr) +inline flatbuffers::Offset CreateSparsityParametersDirect( + flatbuffers::FlatBufferBuilder &_fbb, const std::vector *traversal_order = nullptr, + const std::vector *block_map = nullptr, + const std::vector> *dim_metadata = nullptr) { - return circle::CreateConcatEmbeddingsOptions( - _fbb, num_channels, - num_columns_per_channel ? _fbb.CreateVector(*num_columns_per_channel) : 0, - embedding_dim_per_channel ? _fbb.CreateVector(*embedding_dim_per_channel) : 0); + return circle::CreateSparsityParameters( + _fbb, traversal_order ? _fbb.CreateVector(*traversal_order) : 0, + block_map ? _fbb.CreateVector(*block_map) : 0, + dim_metadata ? _fbb.CreateVector>(*dim_metadata) : 0); } -struct LSHProjectionOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct Tensor FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_TYPE = 4 + VT_SHAPE = 4, + VT_TYPE = 6, + VT_BUFFER = 8, + VT_NAME = 10, + VT_QUANTIZATION = 12, + VT_IS_VARIABLE = 14, + VT_SPARSITY = 16, + VT_SHAPE_SIGNATURE = 18 }; - LSHProjectionType type() const + const flatbuffers::Vector *shape() const { - return static_cast(GetField(VT_TYPE, 0)); + return GetPointer *>(VT_SHAPE); + } + TensorType type() const { return static_cast(GetField(VT_TYPE, 0)); } + uint32_t buffer() const { return GetField(VT_BUFFER, 0); } + const flatbuffers::String *name() const + { + return GetPointer(VT_NAME); + } + const QuantizationParameters *quantization() const + { + return GetPointer(VT_QUANTIZATION); + } + bool is_variable() const { return GetField(VT_IS_VARIABLE, 0) != 0; } + const SparsityParameters *sparsity() const + { + return GetPointer(VT_SPARSITY); + } + const flatbuffers::Vector *shape_signature() const + { + return GetPointer *>(VT_SHAPE_SIGNATURE); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_TYPE) && + return VerifyTableStart(verifier) && VerifyOffset(verifier, VT_SHAPE) && + verifier.VerifyVector(shape()) && VerifyField(verifier, VT_TYPE) && + VerifyField(verifier, VT_BUFFER) && VerifyOffset(verifier, VT_NAME) && + verifier.VerifyString(name()) && VerifyOffset(verifier, VT_QUANTIZATION) && + verifier.VerifyTable(quantization()) && VerifyField(verifier, VT_IS_VARIABLE) && + VerifyOffset(verifier, VT_SPARSITY) && verifier.VerifyTable(sparsity()) && + VerifyOffset(verifier, VT_SHAPE_SIGNATURE) && verifier.VerifyVector(shape_signature()) && verifier.EndTable(); } }; -struct LSHProjectionOptionsBuilder +struct TensorBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_type(LSHProjectionType type) + void add_shape(flatbuffers::Offset> shape) { - fbb_.AddElement(LSHProjectionOptions::VT_TYPE, static_cast(type), 0); + fbb_.AddOffset(Tensor::VT_SHAPE, shape); } - explicit LSHProjectionOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + void add_type(TensorType type) + { + fbb_.AddElement(Tensor::VT_TYPE, static_cast(type), 0); + } + void add_buffer(uint32_t buffer) { fbb_.AddElement(Tensor::VT_BUFFER, buffer, 0); } + void add_name(flatbuffers::Offset name) + { + fbb_.AddOffset(Tensor::VT_NAME, name); + } + void add_quantization(flatbuffers::Offset quantization) + { + fbb_.AddOffset(Tensor::VT_QUANTIZATION, quantization); + } + void add_is_variable(bool is_variable) + { + fbb_.AddElement(Tensor::VT_IS_VARIABLE, static_cast(is_variable), 0); + } + void add_sparsity(flatbuffers::Offset sparsity) + { + fbb_.AddOffset(Tensor::VT_SPARSITY, sparsity); + } + void add_shape_signature(flatbuffers::Offset> shape_signature) + { + fbb_.AddOffset(Tensor::VT_SHAPE_SIGNATURE, shape_signature); + } + explicit TensorBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - LSHProjectionOptionsBuilder &operator=(const LSHProjectionOptionsBuilder &); - flatbuffers::Offset Finish() + TensorBuilder &operator=(const TensorBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateLSHProjectionOptions(flatbuffers::FlatBufferBuilder &_fbb, - LSHProjectionType type = LSHProjectionType_UNKNOWN) +inline flatbuffers::Offset +CreateTensor(flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset> shape = 0, + TensorType type = TensorType_FLOAT32, uint32_t buffer = 0, + flatbuffers::Offset name = 0, + flatbuffers::Offset quantization = 0, bool is_variable = false, + flatbuffers::Offset sparsity = 0, + flatbuffers::Offset> shape_signature = 0) { - LSHProjectionOptionsBuilder builder_(_fbb); + TensorBuilder builder_(_fbb); + builder_.add_shape_signature(shape_signature); + builder_.add_sparsity(sparsity); + builder_.add_quantization(quantization); + builder_.add_name(name); + builder_.add_buffer(buffer); + builder_.add_shape(shape); + builder_.add_is_variable(is_variable); builder_.add_type(type); return builder_.Finish(); } -struct SVDFOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +inline flatbuffers::Offset CreateTensorDirect( + flatbuffers::FlatBufferBuilder &_fbb, const std::vector *shape = nullptr, + TensorType type = TensorType_FLOAT32, uint32_t buffer = 0, const char *name = nullptr, + flatbuffers::Offset quantization = 0, bool is_variable = false, + flatbuffers::Offset sparsity = 0, + const std::vector *shape_signature = nullptr) +{ + return circle::CreateTensor(_fbb, shape ? _fbb.CreateVector(*shape) : 0, type, buffer, + name ? _fbb.CreateString(name) : 0, quantization, is_variable, + sparsity, + shape_signature ? _fbb.CreateVector(*shape_signature) : 0); +} + +struct Conv2DOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_RANK = 4, - VT_FUSED_ACTIVATION_FUNCTION = 6 + VT_PADDING = 4, + VT_STRIDE_W = 6, + VT_STRIDE_H = 8, + VT_FUSED_ACTIVATION_FUNCTION = 10, + VT_DILATION_W_FACTOR = 12, + VT_DILATION_H_FACTOR = 14 }; - int32_t rank() const { return GetField(VT_RANK, 0); } + Padding padding() const { return static_cast(GetField(VT_PADDING, 0)); } + int32_t stride_w() const { return GetField(VT_STRIDE_W, 0); } + int32_t stride_h() const { return GetField(VT_STRIDE_H, 0); } ActivationFunctionType fused_activation_function() const { return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); } + int32_t dilation_w_factor() const { return GetField(VT_DILATION_W_FACTOR, 1); } + int32_t dilation_h_factor() const { return GetField(VT_DILATION_H_FACTOR, 1); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_RANK) && + return VerifyTableStart(verifier) && VerifyField(verifier, VT_PADDING) && + VerifyField(verifier, VT_STRIDE_W) && + VerifyField(verifier, VT_STRIDE_H) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && + VerifyField(verifier, VT_DILATION_W_FACTOR) && + VerifyField(verifier, VT_DILATION_H_FACTOR) && verifier.EndTable(); + } +}; + +struct Conv2DOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_padding(Padding padding) + { + fbb_.AddElement(Conv2DOptions::VT_PADDING, static_cast(padding), 0); + } + void add_stride_w(int32_t stride_w) + { + fbb_.AddElement(Conv2DOptions::VT_STRIDE_W, stride_w, 0); + } + void add_stride_h(int32_t stride_h) + { + fbb_.AddElement(Conv2DOptions::VT_STRIDE_H, stride_h, 0); + } + void add_fused_activation_function(ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(Conv2DOptions::VT_FUSED_ACTIVATION_FUNCTION, + static_cast(fused_activation_function), 0); + } + void add_dilation_w_factor(int32_t dilation_w_factor) + { + fbb_.AddElement(Conv2DOptions::VT_DILATION_W_FACTOR, dilation_w_factor, 1); + } + void add_dilation_h_factor(int32_t dilation_h_factor) + { + fbb_.AddElement(Conv2DOptions::VT_DILATION_H_FACTOR, dilation_h_factor, 1); + } + explicit Conv2DOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + Conv2DOptionsBuilder &operator=(const Conv2DOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset +CreateConv2DOptions(flatbuffers::FlatBufferBuilder &_fbb, Padding padding = Padding_SAME, + int32_t stride_w = 0, int32_t stride_h = 0, + ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE, + int32_t dilation_w_factor = 1, int32_t dilation_h_factor = 1) +{ + Conv2DOptionsBuilder builder_(_fbb); + builder_.add_dilation_h_factor(dilation_h_factor); + builder_.add_dilation_w_factor(dilation_w_factor); + builder_.add_stride_h(stride_h); + builder_.add_stride_w(stride_w); + builder_.add_fused_activation_function(fused_activation_function); + builder_.add_padding(padding); + return builder_.Finish(); +} + +struct Pool2DOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_PADDING = 4, + VT_STRIDE_W = 6, + VT_STRIDE_H = 8, + VT_FILTER_WIDTH = 10, + VT_FILTER_HEIGHT = 12, + VT_FUSED_ACTIVATION_FUNCTION = 14 + }; + Padding padding() const { return static_cast(GetField(VT_PADDING, 0)); } + int32_t stride_w() const { return GetField(VT_STRIDE_W, 0); } + int32_t stride_h() const { return GetField(VT_STRIDE_H, 0); } + int32_t filter_width() const { return GetField(VT_FILTER_WIDTH, 0); } + int32_t filter_height() const { return GetField(VT_FILTER_HEIGHT, 0); } + ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && VerifyField(verifier, VT_PADDING) && + VerifyField(verifier, VT_STRIDE_W) && + VerifyField(verifier, VT_STRIDE_H) && + VerifyField(verifier, VT_FILTER_WIDTH) && + VerifyField(verifier, VT_FILTER_HEIGHT) && VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && verifier.EndTable(); } }; -struct SVDFOptionsBuilder +struct Pool2DOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_padding(Padding padding) + { + fbb_.AddElement(Pool2DOptions::VT_PADDING, static_cast(padding), 0); + } + void add_stride_w(int32_t stride_w) + { + fbb_.AddElement(Pool2DOptions::VT_STRIDE_W, stride_w, 0); + } + void add_stride_h(int32_t stride_h) + { + fbb_.AddElement(Pool2DOptions::VT_STRIDE_H, stride_h, 0); + } + void add_filter_width(int32_t filter_width) + { + fbb_.AddElement(Pool2DOptions::VT_FILTER_WIDTH, filter_width, 0); + } + void add_filter_height(int32_t filter_height) + { + fbb_.AddElement(Pool2DOptions::VT_FILTER_HEIGHT, filter_height, 0); + } + void add_fused_activation_function(ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(Pool2DOptions::VT_FUSED_ACTIVATION_FUNCTION, + static_cast(fused_activation_function), 0); + } + explicit Pool2DOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + Pool2DOptionsBuilder &operator=(const Pool2DOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset +CreatePool2DOptions(flatbuffers::FlatBufferBuilder &_fbb, Padding padding = Padding_SAME, + int32_t stride_w = 0, int32_t stride_h = 0, int32_t filter_width = 0, + int32_t filter_height = 0, + ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE) +{ + Pool2DOptionsBuilder builder_(_fbb); + builder_.add_filter_height(filter_height); + builder_.add_filter_width(filter_width); + builder_.add_stride_h(stride_h); + builder_.add_stride_w(stride_w); + builder_.add_fused_activation_function(fused_activation_function); + builder_.add_padding(padding); + return builder_.Finish(); +} + +struct DepthwiseConv2DOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_PADDING = 4, + VT_STRIDE_W = 6, + VT_STRIDE_H = 8, + VT_DEPTH_MULTIPLIER = 10, + VT_FUSED_ACTIVATION_FUNCTION = 12, + VT_DILATION_W_FACTOR = 14, + VT_DILATION_H_FACTOR = 16 + }; + Padding padding() const { return static_cast(GetField(VT_PADDING, 0)); } + int32_t stride_w() const { return GetField(VT_STRIDE_W, 0); } + int32_t stride_h() const { return GetField(VT_STRIDE_H, 0); } + int32_t depth_multiplier() const { return GetField(VT_DEPTH_MULTIPLIER, 0); } + ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + int32_t dilation_w_factor() const { return GetField(VT_DILATION_W_FACTOR, 1); } + int32_t dilation_h_factor() const { return GetField(VT_DILATION_H_FACTOR, 1); } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && VerifyField(verifier, VT_PADDING) && + VerifyField(verifier, VT_STRIDE_W) && + VerifyField(verifier, VT_STRIDE_H) && + VerifyField(verifier, VT_DEPTH_MULTIPLIER) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && + VerifyField(verifier, VT_DILATION_W_FACTOR) && + VerifyField(verifier, VT_DILATION_H_FACTOR) && verifier.EndTable(); + } +}; + +struct DepthwiseConv2DOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_padding(Padding padding) + { + fbb_.AddElement(DepthwiseConv2DOptions::VT_PADDING, static_cast(padding), 0); + } + void add_stride_w(int32_t stride_w) + { + fbb_.AddElement(DepthwiseConv2DOptions::VT_STRIDE_W, stride_w, 0); + } + void add_stride_h(int32_t stride_h) + { + fbb_.AddElement(DepthwiseConv2DOptions::VT_STRIDE_H, stride_h, 0); + } + void add_depth_multiplier(int32_t depth_multiplier) + { + fbb_.AddElement(DepthwiseConv2DOptions::VT_DEPTH_MULTIPLIER, depth_multiplier, 0); + } + void add_fused_activation_function(ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(DepthwiseConv2DOptions::VT_FUSED_ACTIVATION_FUNCTION, + static_cast(fused_activation_function), 0); + } + void add_dilation_w_factor(int32_t dilation_w_factor) + { + fbb_.AddElement(DepthwiseConv2DOptions::VT_DILATION_W_FACTOR, dilation_w_factor, 1); + } + void add_dilation_h_factor(int32_t dilation_h_factor) + { + fbb_.AddElement(DepthwiseConv2DOptions::VT_DILATION_H_FACTOR, dilation_h_factor, 1); + } + explicit DepthwiseConv2DOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + DepthwiseConv2DOptionsBuilder &operator=(const DepthwiseConv2DOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateDepthwiseConv2DOptions( + flatbuffers::FlatBufferBuilder &_fbb, Padding padding = Padding_SAME, int32_t stride_w = 0, + int32_t stride_h = 0, int32_t depth_multiplier = 0, + ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE, + int32_t dilation_w_factor = 1, int32_t dilation_h_factor = 1) +{ + DepthwiseConv2DOptionsBuilder builder_(_fbb); + builder_.add_dilation_h_factor(dilation_h_factor); + builder_.add_dilation_w_factor(dilation_w_factor); + builder_.add_depth_multiplier(depth_multiplier); + builder_.add_stride_h(stride_h); + builder_.add_stride_w(stride_w); + builder_.add_fused_activation_function(fused_activation_function); + builder_.add_padding(padding); + return builder_.Finish(); +} + +struct ConcatEmbeddingsOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_NUM_CHANNELS = 4, + VT_NUM_COLUMNS_PER_CHANNEL = 6, + VT_EMBEDDING_DIM_PER_CHANNEL = 8 + }; + int32_t num_channels() const { return GetField(VT_NUM_CHANNELS, 0); } + const flatbuffers::Vector *num_columns_per_channel() const + { + return GetPointer *>(VT_NUM_COLUMNS_PER_CHANNEL); + } + const flatbuffers::Vector *embedding_dim_per_channel() const + { + return GetPointer *>(VT_EMBEDDING_DIM_PER_CHANNEL); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && VerifyField(verifier, VT_NUM_CHANNELS) && + VerifyOffset(verifier, VT_NUM_COLUMNS_PER_CHANNEL) && + verifier.VerifyVector(num_columns_per_channel()) && + VerifyOffset(verifier, VT_EMBEDDING_DIM_PER_CHANNEL) && + verifier.VerifyVector(embedding_dim_per_channel()) && verifier.EndTable(); + } +}; + +struct ConcatEmbeddingsOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_num_channels(int32_t num_channels) + { + fbb_.AddElement(ConcatEmbeddingsOptions::VT_NUM_CHANNELS, num_channels, 0); + } + void add_num_columns_per_channel( + flatbuffers::Offset> num_columns_per_channel) + { + fbb_.AddOffset(ConcatEmbeddingsOptions::VT_NUM_COLUMNS_PER_CHANNEL, num_columns_per_channel); + } + void add_embedding_dim_per_channel( + flatbuffers::Offset> embedding_dim_per_channel) + { + fbb_.AddOffset(ConcatEmbeddingsOptions::VT_EMBEDDING_DIM_PER_CHANNEL, + embedding_dim_per_channel); + } + explicit ConcatEmbeddingsOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + ConcatEmbeddingsOptionsBuilder &operator=(const ConcatEmbeddingsOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateConcatEmbeddingsOptions( + flatbuffers::FlatBufferBuilder &_fbb, int32_t num_channels = 0, + flatbuffers::Offset> num_columns_per_channel = 0, + flatbuffers::Offset> embedding_dim_per_channel = 0) +{ + ConcatEmbeddingsOptionsBuilder builder_(_fbb); + builder_.add_embedding_dim_per_channel(embedding_dim_per_channel); + builder_.add_num_columns_per_channel(num_columns_per_channel); + builder_.add_num_channels(num_channels); + return builder_.Finish(); +} + +inline flatbuffers::Offset +CreateConcatEmbeddingsOptionsDirect(flatbuffers::FlatBufferBuilder &_fbb, int32_t num_channels = 0, + const std::vector *num_columns_per_channel = nullptr, + const std::vector *embedding_dim_per_channel = nullptr) +{ + return circle::CreateConcatEmbeddingsOptions( + _fbb, num_channels, + num_columns_per_channel ? _fbb.CreateVector(*num_columns_per_channel) : 0, + embedding_dim_per_channel ? _fbb.CreateVector(*embedding_dim_per_channel) : 0); +} + +struct LSHProjectionOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_TYPE = 4 + }; + LSHProjectionType type() const + { + return static_cast(GetField(VT_TYPE, 0)); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && VerifyField(verifier, VT_TYPE) && + verifier.EndTable(); + } +}; + +struct LSHProjectionOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_type(LSHProjectionType type) + { + fbb_.AddElement(LSHProjectionOptions::VT_TYPE, static_cast(type), 0); + } + explicit LSHProjectionOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + LSHProjectionOptionsBuilder &operator=(const LSHProjectionOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset +CreateLSHProjectionOptions(flatbuffers::FlatBufferBuilder &_fbb, + LSHProjectionType type = LSHProjectionType_UNKNOWN) +{ + LSHProjectionOptionsBuilder builder_(_fbb); + builder_.add_type(type); + return builder_.Finish(); +} + +struct SVDFOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_RANK = 4, + VT_FUSED_ACTIVATION_FUNCTION = 6, + VT_ASYMMETRIC_QUANTIZE_INPUTS = 8 + }; + int32_t rank() const { return GetField(VT_RANK, 0); } + ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + bool asymmetric_quantize_inputs() const + { + return GetField(VT_ASYMMETRIC_QUANTIZE_INPUTS, 0) != 0; + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && VerifyField(verifier, VT_RANK) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && + VerifyField(verifier, VT_ASYMMETRIC_QUANTIZE_INPUTS) && verifier.EndTable(); + } +}; + +struct SVDFOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_rank(int32_t rank) { fbb_.AddElement(SVDFOptions::VT_RANK, rank, 0); } + void add_fused_activation_function(ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(SVDFOptions::VT_FUSED_ACTIVATION_FUNCTION, + static_cast(fused_activation_function), 0); + } + void add_asymmetric_quantize_inputs(bool asymmetric_quantize_inputs) + { + fbb_.AddElement(SVDFOptions::VT_ASYMMETRIC_QUANTIZE_INPUTS, + static_cast(asymmetric_quantize_inputs), 0); + } + explicit SVDFOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + SVDFOptionsBuilder &operator=(const SVDFOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset +CreateSVDFOptions(flatbuffers::FlatBufferBuilder &_fbb, int32_t rank = 0, + ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE, + bool asymmetric_quantize_inputs = false) +{ + SVDFOptionsBuilder builder_(_fbb); + builder_.add_rank(rank); + builder_.add_asymmetric_quantize_inputs(asymmetric_quantize_inputs); + builder_.add_fused_activation_function(fused_activation_function); + return builder_.Finish(); +} + +struct RNNOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_FUSED_ACTIVATION_FUNCTION = 4, + VT_ASYMMETRIC_QUANTIZE_INPUTS = 6 + }; + ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + bool asymmetric_quantize_inputs() const + { + return GetField(VT_ASYMMETRIC_QUANTIZE_INPUTS, 0) != 0; + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && + VerifyField(verifier, VT_ASYMMETRIC_QUANTIZE_INPUTS) && verifier.EndTable(); + } +}; + +struct RNNOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_fused_activation_function(ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(RNNOptions::VT_FUSED_ACTIVATION_FUNCTION, + static_cast(fused_activation_function), 0); + } + void add_asymmetric_quantize_inputs(bool asymmetric_quantize_inputs) + { + fbb_.AddElement(RNNOptions::VT_ASYMMETRIC_QUANTIZE_INPUTS, + static_cast(asymmetric_quantize_inputs), 0); + } + explicit RNNOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + RNNOptionsBuilder &operator=(const RNNOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset +CreateRNNOptions(flatbuffers::FlatBufferBuilder &_fbb, + ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE, + bool asymmetric_quantize_inputs = false) +{ + RNNOptionsBuilder builder_(_fbb); + builder_.add_asymmetric_quantize_inputs(asymmetric_quantize_inputs); + builder_.add_fused_activation_function(fused_activation_function); + return builder_.Finish(); +} + +struct SequenceRNNOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_TIME_MAJOR = 4, + VT_FUSED_ACTIVATION_FUNCTION = 6, + VT_ASYMMETRIC_QUANTIZE_INPUTS = 8 + }; + bool time_major() const { return GetField(VT_TIME_MAJOR, 0) != 0; } + ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + bool asymmetric_quantize_inputs() const + { + return GetField(VT_ASYMMETRIC_QUANTIZE_INPUTS, 0) != 0; + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && VerifyField(verifier, VT_TIME_MAJOR) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && + VerifyField(verifier, VT_ASYMMETRIC_QUANTIZE_INPUTS) && verifier.EndTable(); + } +}; + +struct SequenceRNNOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_time_major(bool time_major) + { + fbb_.AddElement(SequenceRNNOptions::VT_TIME_MAJOR, static_cast(time_major), + 0); + } + void add_fused_activation_function(ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(SequenceRNNOptions::VT_FUSED_ACTIVATION_FUNCTION, + static_cast(fused_activation_function), 0); + } + void add_asymmetric_quantize_inputs(bool asymmetric_quantize_inputs) + { + fbb_.AddElement(SequenceRNNOptions::VT_ASYMMETRIC_QUANTIZE_INPUTS, + static_cast(asymmetric_quantize_inputs), 0); + } + explicit SequenceRNNOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + SequenceRNNOptionsBuilder &operator=(const SequenceRNNOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateSequenceRNNOptions( + flatbuffers::FlatBufferBuilder &_fbb, bool time_major = false, + ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE, + bool asymmetric_quantize_inputs = false) +{ + SequenceRNNOptionsBuilder builder_(_fbb); + builder_.add_asymmetric_quantize_inputs(asymmetric_quantize_inputs); + builder_.add_fused_activation_function(fused_activation_function); + builder_.add_time_major(time_major); + return builder_.Finish(); +} + +struct BidirectionalSequenceRNNOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_TIME_MAJOR = 4, + VT_FUSED_ACTIVATION_FUNCTION = 6, + VT_MERGE_OUTPUTS = 8, + VT_ASYMMETRIC_QUANTIZE_INPUTS = 10 + }; + bool time_major() const { return GetField(VT_TIME_MAJOR, 0) != 0; } + ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + bool merge_outputs() const { return GetField(VT_MERGE_OUTPUTS, 0) != 0; } + bool asymmetric_quantize_inputs() const + { + return GetField(VT_ASYMMETRIC_QUANTIZE_INPUTS, 0) != 0; + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && VerifyField(verifier, VT_TIME_MAJOR) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && + VerifyField(verifier, VT_MERGE_OUTPUTS) && + VerifyField(verifier, VT_ASYMMETRIC_QUANTIZE_INPUTS) && verifier.EndTable(); + } +}; + +struct BidirectionalSequenceRNNOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_time_major(bool time_major) + { + fbb_.AddElement(BidirectionalSequenceRNNOptions::VT_TIME_MAJOR, + static_cast(time_major), 0); + } + void add_fused_activation_function(ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(BidirectionalSequenceRNNOptions::VT_FUSED_ACTIVATION_FUNCTION, + static_cast(fused_activation_function), 0); + } + void add_merge_outputs(bool merge_outputs) + { + fbb_.AddElement(BidirectionalSequenceRNNOptions::VT_MERGE_OUTPUTS, + static_cast(merge_outputs), 0); + } + void add_asymmetric_quantize_inputs(bool asymmetric_quantize_inputs) + { + fbb_.AddElement(BidirectionalSequenceRNNOptions::VT_ASYMMETRIC_QUANTIZE_INPUTS, + static_cast(asymmetric_quantize_inputs), 0); + } + explicit BidirectionalSequenceRNNOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + BidirectionalSequenceRNNOptionsBuilder &operator=(const BidirectionalSequenceRNNOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateBidirectionalSequenceRNNOptions( + flatbuffers::FlatBufferBuilder &_fbb, bool time_major = false, + ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE, + bool merge_outputs = false, bool asymmetric_quantize_inputs = false) +{ + BidirectionalSequenceRNNOptionsBuilder builder_(_fbb); + builder_.add_asymmetric_quantize_inputs(asymmetric_quantize_inputs); + builder_.add_merge_outputs(merge_outputs); + builder_.add_fused_activation_function(fused_activation_function); + builder_.add_time_major(time_major); + return builder_.Finish(); +} + +struct FullyConnectedOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_FUSED_ACTIVATION_FUNCTION = 4, + VT_WEIGHTS_FORMAT = 6, + VT_KEEP_NUM_DIMS = 8, + VT_ASYMMETRIC_QUANTIZE_INPUTS = 10 + }; + ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + FullyConnectedOptionsWeightsFormat weights_format() const + { + return static_cast(GetField(VT_WEIGHTS_FORMAT, 0)); + } + bool keep_num_dims() const { return GetField(VT_KEEP_NUM_DIMS, 0) != 0; } + bool asymmetric_quantize_inputs() const + { + return GetField(VT_ASYMMETRIC_QUANTIZE_INPUTS, 0) != 0; + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && + VerifyField(verifier, VT_WEIGHTS_FORMAT) && + VerifyField(verifier, VT_KEEP_NUM_DIMS) && + VerifyField(verifier, VT_ASYMMETRIC_QUANTIZE_INPUTS) && verifier.EndTable(); + } +}; + +struct FullyConnectedOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_fused_activation_function(ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(FullyConnectedOptions::VT_FUSED_ACTIVATION_FUNCTION, + static_cast(fused_activation_function), 0); + } + void add_weights_format(FullyConnectedOptionsWeightsFormat weights_format) + { + fbb_.AddElement(FullyConnectedOptions::VT_WEIGHTS_FORMAT, + static_cast(weights_format), 0); + } + void add_keep_num_dims(bool keep_num_dims) + { + fbb_.AddElement(FullyConnectedOptions::VT_KEEP_NUM_DIMS, + static_cast(keep_num_dims), 0); + } + void add_asymmetric_quantize_inputs(bool asymmetric_quantize_inputs) + { + fbb_.AddElement(FullyConnectedOptions::VT_ASYMMETRIC_QUANTIZE_INPUTS, + static_cast(asymmetric_quantize_inputs), 0); + } + explicit FullyConnectedOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + FullyConnectedOptionsBuilder &operator=(const FullyConnectedOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateFullyConnectedOptions( + flatbuffers::FlatBufferBuilder &_fbb, + ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE, + FullyConnectedOptionsWeightsFormat weights_format = FullyConnectedOptionsWeightsFormat_DEFAULT, + bool keep_num_dims = false, bool asymmetric_quantize_inputs = false) +{ + FullyConnectedOptionsBuilder builder_(_fbb); + builder_.add_asymmetric_quantize_inputs(asymmetric_quantize_inputs); + builder_.add_keep_num_dims(keep_num_dims); + builder_.add_weights_format(weights_format); + builder_.add_fused_activation_function(fused_activation_function); + return builder_.Finish(); +} + +struct SoftmaxOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_BETA = 4 + }; + float beta() const { return GetField(VT_BETA, 0.0f); } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && VerifyField(verifier, VT_BETA) && + verifier.EndTable(); + } +}; + +struct SoftmaxOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_beta(float beta) { fbb_.AddElement(SoftmaxOptions::VT_BETA, beta, 0.0f); } + explicit SoftmaxOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + SoftmaxOptionsBuilder &operator=(const SoftmaxOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset +CreateSoftmaxOptions(flatbuffers::FlatBufferBuilder &_fbb, float beta = 0.0f) +{ + SoftmaxOptionsBuilder builder_(_fbb); + builder_.add_beta(beta); + return builder_.Finish(); +} + +struct ConcatenationOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_AXIS = 4, + VT_FUSED_ACTIVATION_FUNCTION = 6 + }; + int32_t axis() const { return GetField(VT_AXIS, 0); } + ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && VerifyField(verifier, VT_AXIS) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && verifier.EndTable(); + } +}; + +struct ConcatenationOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_axis(int32_t axis) { fbb_.AddElement(ConcatenationOptions::VT_AXIS, axis, 0); } + void add_fused_activation_function(ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(ConcatenationOptions::VT_FUSED_ACTIVATION_FUNCTION, + static_cast(fused_activation_function), 0); + } + explicit ConcatenationOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + ConcatenationOptionsBuilder &operator=(const ConcatenationOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateConcatenationOptions( + flatbuffers::FlatBufferBuilder &_fbb, int32_t axis = 0, + ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE) +{ + ConcatenationOptionsBuilder builder_(_fbb); + builder_.add_axis(axis); + builder_.add_fused_activation_function(fused_activation_function); + return builder_.Finish(); +} + +struct AddOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_FUSED_ACTIVATION_FUNCTION = 4 + }; + ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && verifier.EndTable(); + } +}; + +struct AddOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_fused_activation_function(ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(AddOptions::VT_FUSED_ACTIVATION_FUNCTION, + static_cast(fused_activation_function), 0); + } + explicit AddOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + AddOptionsBuilder &operator=(const AddOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset +CreateAddOptions(flatbuffers::FlatBufferBuilder &_fbb, + ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE) +{ + AddOptionsBuilder builder_(_fbb); + builder_.add_fused_activation_function(fused_activation_function); + return builder_.Finish(); +} + +struct MulOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_FUSED_ACTIVATION_FUNCTION = 4 + }; + ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && verifier.EndTable(); + } +}; + +struct MulOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_fused_activation_function(ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(MulOptions::VT_FUSED_ACTIVATION_FUNCTION, + static_cast(fused_activation_function), 0); + } + explicit MulOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + MulOptionsBuilder &operator=(const MulOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset +CreateMulOptions(flatbuffers::FlatBufferBuilder &_fbb, + ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE) +{ + MulOptionsBuilder builder_(_fbb); + builder_.add_fused_activation_function(fused_activation_function); + return builder_.Finish(); +} + +struct L2NormOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_FUSED_ACTIVATION_FUNCTION = 4 + }; + ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && verifier.EndTable(); + } +}; + +struct L2NormOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_fused_activation_function(ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(L2NormOptions::VT_FUSED_ACTIVATION_FUNCTION, + static_cast(fused_activation_function), 0); + } + explicit L2NormOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + L2NormOptionsBuilder &operator=(const L2NormOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset +CreateL2NormOptions(flatbuffers::FlatBufferBuilder &_fbb, + ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE) +{ + L2NormOptionsBuilder builder_(_fbb); + builder_.add_fused_activation_function(fused_activation_function); + return builder_.Finish(); +} + +struct LocalResponseNormalizationOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_RADIUS = 4, + VT_BIAS = 6, + VT_ALPHA = 8, + VT_BETA = 10 + }; + int32_t radius() const { return GetField(VT_RADIUS, 0); } + float bias() const { return GetField(VT_BIAS, 0.0f); } + float alpha() const { return GetField(VT_ALPHA, 0.0f); } + float beta() const { return GetField(VT_BETA, 0.0f); } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && VerifyField(verifier, VT_RADIUS) && + VerifyField(verifier, VT_BIAS) && VerifyField(verifier, VT_ALPHA) && + VerifyField(verifier, VT_BETA) && verifier.EndTable(); + } +}; + +struct LocalResponseNormalizationOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_radius(int32_t radius) + { + fbb_.AddElement(LocalResponseNormalizationOptions::VT_RADIUS, radius, 0); + } + void add_bias(float bias) + { + fbb_.AddElement(LocalResponseNormalizationOptions::VT_BIAS, bias, 0.0f); + } + void add_alpha(float alpha) + { + fbb_.AddElement(LocalResponseNormalizationOptions::VT_ALPHA, alpha, 0.0f); + } + void add_beta(float beta) + { + fbb_.AddElement(LocalResponseNormalizationOptions::VT_BETA, beta, 0.0f); + } + explicit LocalResponseNormalizationOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + LocalResponseNormalizationOptionsBuilder & + operator=(const LocalResponseNormalizationOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset +CreateLocalResponseNormalizationOptions(flatbuffers::FlatBufferBuilder &_fbb, int32_t radius = 0, + float bias = 0.0f, float alpha = 0.0f, float beta = 0.0f) +{ + LocalResponseNormalizationOptionsBuilder builder_(_fbb); + builder_.add_beta(beta); + builder_.add_alpha(alpha); + builder_.add_bias(bias); + builder_.add_radius(radius); + return builder_.Finish(); +} + +struct LSTMOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_FUSED_ACTIVATION_FUNCTION = 4, + VT_CELL_CLIP = 6, + VT_PROJ_CLIP = 8, + VT_KERNEL_TYPE = 10, + VT_ASYMMETRIC_QUANTIZE_INPUTS = 12 + }; + ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + float cell_clip() const { return GetField(VT_CELL_CLIP, 0.0f); } + float proj_clip() const { return GetField(VT_PROJ_CLIP, 0.0f); } + LSTMKernelType kernel_type() const + { + return static_cast(GetField(VT_KERNEL_TYPE, 0)); + } + bool asymmetric_quantize_inputs() const + { + return GetField(VT_ASYMMETRIC_QUANTIZE_INPUTS, 0) != 0; + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && + VerifyField(verifier, VT_CELL_CLIP) && + VerifyField(verifier, VT_PROJ_CLIP) && + VerifyField(verifier, VT_KERNEL_TYPE) && + VerifyField(verifier, VT_ASYMMETRIC_QUANTIZE_INPUTS) && verifier.EndTable(); + } +}; + +struct LSTMOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_fused_activation_function(ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(LSTMOptions::VT_FUSED_ACTIVATION_FUNCTION, + static_cast(fused_activation_function), 0); + } + void add_cell_clip(float cell_clip) + { + fbb_.AddElement(LSTMOptions::VT_CELL_CLIP, cell_clip, 0.0f); + } + void add_proj_clip(float proj_clip) + { + fbb_.AddElement(LSTMOptions::VT_PROJ_CLIP, proj_clip, 0.0f); + } + void add_kernel_type(LSTMKernelType kernel_type) + { + fbb_.AddElement(LSTMOptions::VT_KERNEL_TYPE, static_cast(kernel_type), 0); + } + void add_asymmetric_quantize_inputs(bool asymmetric_quantize_inputs) + { + fbb_.AddElement(LSTMOptions::VT_ASYMMETRIC_QUANTIZE_INPUTS, + static_cast(asymmetric_quantize_inputs), 0); + } + explicit LSTMOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + LSTMOptionsBuilder &operator=(const LSTMOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset +CreateLSTMOptions(flatbuffers::FlatBufferBuilder &_fbb, + ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE, + float cell_clip = 0.0f, float proj_clip = 0.0f, + LSTMKernelType kernel_type = LSTMKernelType_FULL, + bool asymmetric_quantize_inputs = false) +{ + LSTMOptionsBuilder builder_(_fbb); + builder_.add_proj_clip(proj_clip); + builder_.add_cell_clip(cell_clip); + builder_.add_asymmetric_quantize_inputs(asymmetric_quantize_inputs); + builder_.add_kernel_type(kernel_type); + builder_.add_fused_activation_function(fused_activation_function); + return builder_.Finish(); +} + +struct UnidirectionalSequenceLSTMOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_FUSED_ACTIVATION_FUNCTION = 4, + VT_CELL_CLIP = 6, + VT_PROJ_CLIP = 8, + VT_TIME_MAJOR = 10, + VT_ASYMMETRIC_QUANTIZE_INPUTS = 12 + }; + ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + float cell_clip() const { return GetField(VT_CELL_CLIP, 0.0f); } + float proj_clip() const { return GetField(VT_PROJ_CLIP, 0.0f); } + bool time_major() const { return GetField(VT_TIME_MAJOR, 0) != 0; } + bool asymmetric_quantize_inputs() const + { + return GetField(VT_ASYMMETRIC_QUANTIZE_INPUTS, 0) != 0; + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && + VerifyField(verifier, VT_CELL_CLIP) && + VerifyField(verifier, VT_PROJ_CLIP) && + VerifyField(verifier, VT_TIME_MAJOR) && + VerifyField(verifier, VT_ASYMMETRIC_QUANTIZE_INPUTS) && verifier.EndTable(); + } +}; + +struct UnidirectionalSequenceLSTMOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_fused_activation_function(ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(UnidirectionalSequenceLSTMOptions::VT_FUSED_ACTIVATION_FUNCTION, + static_cast(fused_activation_function), 0); + } + void add_cell_clip(float cell_clip) + { + fbb_.AddElement(UnidirectionalSequenceLSTMOptions::VT_CELL_CLIP, cell_clip, 0.0f); + } + void add_proj_clip(float proj_clip) + { + fbb_.AddElement(UnidirectionalSequenceLSTMOptions::VT_PROJ_CLIP, proj_clip, 0.0f); + } + void add_time_major(bool time_major) + { + fbb_.AddElement(UnidirectionalSequenceLSTMOptions::VT_TIME_MAJOR, + static_cast(time_major), 0); + } + void add_asymmetric_quantize_inputs(bool asymmetric_quantize_inputs) + { + fbb_.AddElement(UnidirectionalSequenceLSTMOptions::VT_ASYMMETRIC_QUANTIZE_INPUTS, + static_cast(asymmetric_quantize_inputs), 0); + } + explicit UnidirectionalSequenceLSTMOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + UnidirectionalSequenceLSTMOptionsBuilder & + operator=(const UnidirectionalSequenceLSTMOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset +CreateUnidirectionalSequenceLSTMOptions( + flatbuffers::FlatBufferBuilder &_fbb, + ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE, + float cell_clip = 0.0f, float proj_clip = 0.0f, bool time_major = false, + bool asymmetric_quantize_inputs = false) +{ + UnidirectionalSequenceLSTMOptionsBuilder builder_(_fbb); + builder_.add_proj_clip(proj_clip); + builder_.add_cell_clip(cell_clip); + builder_.add_asymmetric_quantize_inputs(asymmetric_quantize_inputs); + builder_.add_time_major(time_major); + builder_.add_fused_activation_function(fused_activation_function); + return builder_.Finish(); +} + +struct BidirectionalSequenceLSTMOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_FUSED_ACTIVATION_FUNCTION = 4, + VT_CELL_CLIP = 6, + VT_PROJ_CLIP = 8, + VT_MERGE_OUTPUTS = 10, + VT_TIME_MAJOR = 12, + VT_ASYMMETRIC_QUANTIZE_INPUTS = 14 + }; + ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + float cell_clip() const { return GetField(VT_CELL_CLIP, 0.0f); } + float proj_clip() const { return GetField(VT_PROJ_CLIP, 0.0f); } + bool merge_outputs() const { return GetField(VT_MERGE_OUTPUTS, 0) != 0; } + bool time_major() const { return GetField(VT_TIME_MAJOR, 1) != 0; } + bool asymmetric_quantize_inputs() const + { + return GetField(VT_ASYMMETRIC_QUANTIZE_INPUTS, 0) != 0; + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && + VerifyField(verifier, VT_CELL_CLIP) && + VerifyField(verifier, VT_PROJ_CLIP) && + VerifyField(verifier, VT_MERGE_OUTPUTS) && + VerifyField(verifier, VT_TIME_MAJOR) && + VerifyField(verifier, VT_ASYMMETRIC_QUANTIZE_INPUTS) && verifier.EndTable(); + } +}; + +struct BidirectionalSequenceLSTMOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_fused_activation_function(ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(BidirectionalSequenceLSTMOptions::VT_FUSED_ACTIVATION_FUNCTION, + static_cast(fused_activation_function), 0); + } + void add_cell_clip(float cell_clip) + { + fbb_.AddElement(BidirectionalSequenceLSTMOptions::VT_CELL_CLIP, cell_clip, 0.0f); + } + void add_proj_clip(float proj_clip) + { + fbb_.AddElement(BidirectionalSequenceLSTMOptions::VT_PROJ_CLIP, proj_clip, 0.0f); + } + void add_merge_outputs(bool merge_outputs) + { + fbb_.AddElement(BidirectionalSequenceLSTMOptions::VT_MERGE_OUTPUTS, + static_cast(merge_outputs), 0); + } + void add_time_major(bool time_major) + { + fbb_.AddElement(BidirectionalSequenceLSTMOptions::VT_TIME_MAJOR, + static_cast(time_major), 1); + } + void add_asymmetric_quantize_inputs(bool asymmetric_quantize_inputs) + { + fbb_.AddElement(BidirectionalSequenceLSTMOptions::VT_ASYMMETRIC_QUANTIZE_INPUTS, + static_cast(asymmetric_quantize_inputs), 0); + } + explicit BidirectionalSequenceLSTMOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + BidirectionalSequenceLSTMOptionsBuilder & + operator=(const BidirectionalSequenceLSTMOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateBidirectionalSequenceLSTMOptions( + flatbuffers::FlatBufferBuilder &_fbb, + ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE, + float cell_clip = 0.0f, float proj_clip = 0.0f, bool merge_outputs = false, + bool time_major = true, bool asymmetric_quantize_inputs = false) +{ + BidirectionalSequenceLSTMOptionsBuilder builder_(_fbb); + builder_.add_proj_clip(proj_clip); + builder_.add_cell_clip(cell_clip); + builder_.add_asymmetric_quantize_inputs(asymmetric_quantize_inputs); + builder_.add_time_major(time_major); + builder_.add_merge_outputs(merge_outputs); + builder_.add_fused_activation_function(fused_activation_function); + return builder_.Finish(); +} + +struct ResizeBilinearOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_ALIGN_CORNERS = 8, + VT_HALF_PIXEL_CENTERS = 10 + }; + bool align_corners() const { return GetField(VT_ALIGN_CORNERS, 0) != 0; } + bool half_pixel_centers() const { return GetField(VT_HALF_PIXEL_CENTERS, 0) != 0; } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && VerifyField(verifier, VT_ALIGN_CORNERS) && + VerifyField(verifier, VT_HALF_PIXEL_CENTERS) && verifier.EndTable(); + } +}; + +struct ResizeBilinearOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_align_corners(bool align_corners) + { + fbb_.AddElement(ResizeBilinearOptions::VT_ALIGN_CORNERS, + static_cast(align_corners), 0); + } + void add_half_pixel_centers(bool half_pixel_centers) + { + fbb_.AddElement(ResizeBilinearOptions::VT_HALF_PIXEL_CENTERS, + static_cast(half_pixel_centers), 0); + } + explicit ResizeBilinearOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + ResizeBilinearOptionsBuilder &operator=(const ResizeBilinearOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset +CreateResizeBilinearOptions(flatbuffers::FlatBufferBuilder &_fbb, bool align_corners = false, + bool half_pixel_centers = false) +{ + ResizeBilinearOptionsBuilder builder_(_fbb); + builder_.add_half_pixel_centers(half_pixel_centers); + builder_.add_align_corners(align_corners); + return builder_.Finish(); +} + +struct ResizeNearestNeighborOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_ALIGN_CORNERS = 4 + }; + bool align_corners() const { return GetField(VT_ALIGN_CORNERS, 0) != 0; } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && VerifyField(verifier, VT_ALIGN_CORNERS) && + verifier.EndTable(); + } +}; + +struct ResizeNearestNeighborOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_align_corners(bool align_corners) + { + fbb_.AddElement(ResizeNearestNeighborOptions::VT_ALIGN_CORNERS, + static_cast(align_corners), 0); + } + explicit ResizeNearestNeighborOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + ResizeNearestNeighborOptionsBuilder &operator=(const ResizeNearestNeighborOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset +CreateResizeNearestNeighborOptions(flatbuffers::FlatBufferBuilder &_fbb, bool align_corners = false) +{ + ResizeNearestNeighborOptionsBuilder builder_(_fbb); + builder_.add_align_corners(align_corners); + return builder_.Finish(); +} + +struct CallOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_SUBGRAPH = 4 + }; + uint32_t subgraph() const { return GetField(VT_SUBGRAPH, 0); } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && VerifyField(verifier, VT_SUBGRAPH) && + verifier.EndTable(); + } +}; + +struct CallOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_subgraph(uint32_t subgraph) + { + fbb_.AddElement(CallOptions::VT_SUBGRAPH, subgraph, 0); + } + explicit CallOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + CallOptionsBuilder &operator=(const CallOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateCallOptions(flatbuffers::FlatBufferBuilder &_fbb, + uint32_t subgraph = 0) +{ + CallOptionsBuilder builder_(_fbb); + builder_.add_subgraph(subgraph); + return builder_.Finish(); +} + +struct PadOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && verifier.EndTable(); + } +}; + +struct PadOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit PadOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + PadOptionsBuilder &operator=(const PadOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreatePadOptions(flatbuffers::FlatBufferBuilder &_fbb) +{ + PadOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +struct PadV2Options FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && verifier.EndTable(); + } +}; + +struct PadV2OptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit PadV2OptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + PadV2OptionsBuilder &operator=(const PadV2OptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreatePadV2Options(flatbuffers::FlatBufferBuilder &_fbb) +{ + PadV2OptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +struct ReshapeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_NEW_SHAPE = 4 + }; + const flatbuffers::Vector *new_shape() const + { + return GetPointer *>(VT_NEW_SHAPE); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && VerifyOffset(verifier, VT_NEW_SHAPE) && + verifier.VerifyVector(new_shape()) && verifier.EndTable(); + } +}; + +struct ReshapeOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_new_shape(flatbuffers::Offset> new_shape) + { + fbb_.AddOffset(ReshapeOptions::VT_NEW_SHAPE, new_shape); + } + explicit ReshapeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + ReshapeOptionsBuilder &operator=(const ReshapeOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset +CreateReshapeOptions(flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset> new_shape = 0) +{ + ReshapeOptionsBuilder builder_(_fbb); + builder_.add_new_shape(new_shape); + return builder_.Finish(); +} + +inline flatbuffers::Offset +CreateReshapeOptionsDirect(flatbuffers::FlatBufferBuilder &_fbb, + const std::vector *new_shape = nullptr) +{ + return circle::CreateReshapeOptions(_fbb, new_shape ? _fbb.CreateVector(*new_shape) : 0); +} + +struct SpaceToBatchNDOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && verifier.EndTable(); + } +}; + +struct SpaceToBatchNDOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit SpaceToBatchNDOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + SpaceToBatchNDOptionsBuilder &operator=(const SpaceToBatchNDOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset +CreateSpaceToBatchNDOptions(flatbuffers::FlatBufferBuilder &_fbb) +{ + SpaceToBatchNDOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +struct BatchToSpaceNDOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && verifier.EndTable(); + } +}; + +struct BatchToSpaceNDOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit BatchToSpaceNDOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + BatchToSpaceNDOptionsBuilder &operator=(const BatchToSpaceNDOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset +CreateBatchToSpaceNDOptions(flatbuffers::FlatBufferBuilder &_fbb) +{ + BatchToSpaceNDOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +struct SkipGramOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_NGRAM_SIZE = 4, + VT_MAX_SKIP_SIZE = 6, + VT_INCLUDE_ALL_NGRAMS = 8 + }; + int32_t ngram_size() const { return GetField(VT_NGRAM_SIZE, 0); } + int32_t max_skip_size() const { return GetField(VT_MAX_SKIP_SIZE, 0); } + bool include_all_ngrams() const { return GetField(VT_INCLUDE_ALL_NGRAMS, 0) != 0; } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && VerifyField(verifier, VT_NGRAM_SIZE) && + VerifyField(verifier, VT_MAX_SKIP_SIZE) && + VerifyField(verifier, VT_INCLUDE_ALL_NGRAMS) && verifier.EndTable(); + } +}; + +struct SkipGramOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_rank(int32_t rank) { fbb_.AddElement(SVDFOptions::VT_RANK, rank, 0); } - void add_fused_activation_function(ActivationFunctionType fused_activation_function) + void add_ngram_size(int32_t ngram_size) { - fbb_.AddElement(SVDFOptions::VT_FUSED_ACTIVATION_FUNCTION, - static_cast(fused_activation_function), 0); + fbb_.AddElement(SkipGramOptions::VT_NGRAM_SIZE, ngram_size, 0); } - explicit SVDFOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + void add_max_skip_size(int32_t max_skip_size) + { + fbb_.AddElement(SkipGramOptions::VT_MAX_SKIP_SIZE, max_skip_size, 0); + } + void add_include_all_ngrams(bool include_all_ngrams) + { + fbb_.AddElement(SkipGramOptions::VT_INCLUDE_ALL_NGRAMS, + static_cast(include_all_ngrams), 0); + } + explicit SkipGramOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - SVDFOptionsBuilder &operator=(const SVDFOptionsBuilder &); - flatbuffers::Offset Finish() + SkipGramOptionsBuilder &operator=(const SkipGramOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateSVDFOptions(flatbuffers::FlatBufferBuilder &_fbb, int32_t rank = 0, - ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE) +inline flatbuffers::Offset +CreateSkipGramOptions(flatbuffers::FlatBufferBuilder &_fbb, int32_t ngram_size = 0, + int32_t max_skip_size = 0, bool include_all_ngrams = false) { - SVDFOptionsBuilder builder_(_fbb); - builder_.add_rank(rank); - builder_.add_fused_activation_function(fused_activation_function); + SkipGramOptionsBuilder builder_(_fbb); + builder_.add_max_skip_size(max_skip_size); + builder_.add_ngram_size(ngram_size); + builder_.add_include_all_ngrams(include_all_ngrams); return builder_.Finish(); } -struct RNNOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct SpaceToDepthOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_FUSED_ACTIVATION_FUNCTION = 4 + VT_BLOCK_SIZE = 4 }; - ActivationFunctionType fused_activation_function() const - { - return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); - } + int32_t block_size() const { return GetField(VT_BLOCK_SIZE, 0); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyField(verifier, VT_BLOCK_SIZE) && + verifier.EndTable(); } }; -struct RNNOptionsBuilder +struct SpaceToDepthOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_fused_activation_function(ActivationFunctionType fused_activation_function) + void add_block_size(int32_t block_size) { - fbb_.AddElement(RNNOptions::VT_FUSED_ACTIVATION_FUNCTION, - static_cast(fused_activation_function), 0); + fbb_.AddElement(SpaceToDepthOptions::VT_BLOCK_SIZE, block_size, 0); } - explicit RNNOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit SpaceToDepthOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - RNNOptionsBuilder &operator=(const RNNOptionsBuilder &); - flatbuffers::Offset Finish() + SpaceToDepthOptionsBuilder &operator=(const SpaceToDepthOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateRNNOptions(flatbuffers::FlatBufferBuilder &_fbb, - ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE) +inline flatbuffers::Offset +CreateSpaceToDepthOptions(flatbuffers::FlatBufferBuilder &_fbb, int32_t block_size = 0) { - RNNOptionsBuilder builder_(_fbb); - builder_.add_fused_activation_function(fused_activation_function); + SpaceToDepthOptionsBuilder builder_(_fbb); + builder_.add_block_size(block_size); return builder_.Finish(); } -struct SequenceRNNOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct DepthToSpaceOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_TIME_MAJOR = 4, - VT_FUSED_ACTIVATION_FUNCTION = 6 + VT_BLOCK_SIZE = 4 }; - bool time_major() const { return GetField(VT_TIME_MAJOR, 0) != 0; } - ActivationFunctionType fused_activation_function() const - { - return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); - } + int32_t block_size() const { return GetField(VT_BLOCK_SIZE, 0); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_TIME_MAJOR) && - VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyField(verifier, VT_BLOCK_SIZE) && + verifier.EndTable(); } }; -struct SequenceRNNOptionsBuilder +struct DepthToSpaceOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_time_major(bool time_major) - { - fbb_.AddElement(SequenceRNNOptions::VT_TIME_MAJOR, static_cast(time_major), - 0); - } - void add_fused_activation_function(ActivationFunctionType fused_activation_function) + void add_block_size(int32_t block_size) { - fbb_.AddElement(SequenceRNNOptions::VT_FUSED_ACTIVATION_FUNCTION, - static_cast(fused_activation_function), 0); + fbb_.AddElement(DepthToSpaceOptions::VT_BLOCK_SIZE, block_size, 0); } - explicit SequenceRNNOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit DepthToSpaceOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - SequenceRNNOptionsBuilder &operator=(const SequenceRNNOptionsBuilder &); - flatbuffers::Offset Finish() + DepthToSpaceOptionsBuilder &operator=(const DepthToSpaceOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateSequenceRNNOptions( - flatbuffers::FlatBufferBuilder &_fbb, bool time_major = false, - ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE) +inline flatbuffers::Offset +CreateDepthToSpaceOptions(flatbuffers::FlatBufferBuilder &_fbb, int32_t block_size = 0) { - SequenceRNNOptionsBuilder builder_(_fbb); - builder_.add_fused_activation_function(fused_activation_function); - builder_.add_time_major(time_major); + DepthToSpaceOptionsBuilder builder_(_fbb); + builder_.add_block_size(block_size); return builder_.Finish(); } -struct BidirectionalSequenceRNNOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct SubOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_TIME_MAJOR = 4, - VT_FUSED_ACTIVATION_FUNCTION = 6, - VT_MERGE_OUTPUTS = 8 + VT_FUSED_ACTIVATION_FUNCTION = 4 }; - bool time_major() const { return GetField(VT_TIME_MAJOR, 0) != 0; } ActivationFunctionType fused_activation_function() const { return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); } - bool merge_outputs() const { return GetField(VT_MERGE_OUTPUTS, 0) != 0; } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_TIME_MAJOR) && - VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && - VerifyField(verifier, VT_MERGE_OUTPUTS) && verifier.EndTable(); + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && verifier.EndTable(); } }; -struct BidirectionalSequenceRNNOptionsBuilder +struct SubOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_time_major(bool time_major) - { - fbb_.AddElement(BidirectionalSequenceRNNOptions::VT_TIME_MAJOR, - static_cast(time_major), 0); - } void add_fused_activation_function(ActivationFunctionType fused_activation_function) { - fbb_.AddElement(BidirectionalSequenceRNNOptions::VT_FUSED_ACTIVATION_FUNCTION, + fbb_.AddElement(SubOptions::VT_FUSED_ACTIVATION_FUNCTION, static_cast(fused_activation_function), 0); } - void add_merge_outputs(bool merge_outputs) - { - fbb_.AddElement(BidirectionalSequenceRNNOptions::VT_MERGE_OUTPUTS, - static_cast(merge_outputs), 0); - } - explicit BidirectionalSequenceRNNOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit SubOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - BidirectionalSequenceRNNOptionsBuilder &operator=(const BidirectionalSequenceRNNOptionsBuilder &); - flatbuffers::Offset Finish() + SubOptionsBuilder &operator=(const SubOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateBidirectionalSequenceRNNOptions( - flatbuffers::FlatBufferBuilder &_fbb, bool time_major = false, - ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE, - bool merge_outputs = false) +inline flatbuffers::Offset +CreateSubOptions(flatbuffers::FlatBufferBuilder &_fbb, + ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE) { - BidirectionalSequenceRNNOptionsBuilder builder_(_fbb); - builder_.add_merge_outputs(merge_outputs); + SubOptionsBuilder builder_(_fbb); builder_.add_fused_activation_function(fused_activation_function); - builder_.add_time_major(time_major); return builder_.Finish(); } -struct FullyConnectedOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct DivOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_FUSED_ACTIVATION_FUNCTION = 4, - VT_WEIGHTS_FORMAT = 6 + VT_FUSED_ACTIVATION_FUNCTION = 4 }; ActivationFunctionType fused_activation_function() const { return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); } - FullyConnectedOptionsWeightsFormat weights_format() const - { - return static_cast(GetField(VT_WEIGHTS_FORMAT, 0)); - } bool Verify(flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && - VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && - VerifyField(verifier, VT_WEIGHTS_FORMAT) && verifier.EndTable(); + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && verifier.EndTable(); } }; -struct FullyConnectedOptionsBuilder +struct DivOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; void add_fused_activation_function(ActivationFunctionType fused_activation_function) { - fbb_.AddElement(FullyConnectedOptions::VT_FUSED_ACTIVATION_FUNCTION, + fbb_.AddElement(DivOptions::VT_FUSED_ACTIVATION_FUNCTION, static_cast(fused_activation_function), 0); } - void add_weights_format(FullyConnectedOptionsWeightsFormat weights_format) - { - fbb_.AddElement(FullyConnectedOptions::VT_WEIGHTS_FORMAT, - static_cast(weights_format), 0); - } - explicit FullyConnectedOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit DivOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - FullyConnectedOptionsBuilder &operator=(const FullyConnectedOptionsBuilder &); - flatbuffers::Offset Finish() + DivOptionsBuilder &operator=(const DivOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateFullyConnectedOptions( - flatbuffers::FlatBufferBuilder &_fbb, - ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE, - FullyConnectedOptionsWeightsFormat weights_format = FullyConnectedOptionsWeightsFormat_DEFAULT) +inline flatbuffers::Offset +CreateDivOptions(flatbuffers::FlatBufferBuilder &_fbb, + ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE) { - FullyConnectedOptionsBuilder builder_(_fbb); - builder_.add_weights_format(weights_format); + DivOptionsBuilder builder_(_fbb); builder_.add_fused_activation_function(fused_activation_function); return builder_.Finish(); } -struct SoftmaxOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct TopKV2Options FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum - { - VT_BETA = 4 - }; - float beta() const { return GetField(VT_BETA, 0.0f); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_BETA) && - verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct SoftmaxOptionsBuilder +struct TopKV2OptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_beta(float beta) { fbb_.AddElement(SoftmaxOptions::VT_BETA, beta, 0.0f); } - explicit SoftmaxOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit TopKV2OptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - SoftmaxOptionsBuilder &operator=(const SoftmaxOptionsBuilder &); - flatbuffers::Offset Finish() + TopKV2OptionsBuilder &operator=(const TopKV2OptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateSoftmaxOptions(flatbuffers::FlatBufferBuilder &_fbb, float beta = 0.0f) +inline flatbuffers::Offset CreateTopKV2Options(flatbuffers::FlatBufferBuilder &_fbb) { - SoftmaxOptionsBuilder builder_(_fbb); - builder_.add_beta(beta); + TopKV2OptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct ConcatenationOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct EmbeddingLookupSparseOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_AXIS = 4, - VT_FUSED_ACTIVATION_FUNCTION = 6 + VT_COMBINER = 4 }; - int32_t axis() const { return GetField(VT_AXIS, 0); } - ActivationFunctionType fused_activation_function() const + CombinerType combiner() const { - return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + return static_cast(GetField(VT_COMBINER, 0)); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_AXIS) && - VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyField(verifier, VT_COMBINER) && + verifier.EndTable(); } }; -struct ConcatenationOptionsBuilder +struct EmbeddingLookupSparseOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_axis(int32_t axis) { fbb_.AddElement(ConcatenationOptions::VT_AXIS, axis, 0); } - void add_fused_activation_function(ActivationFunctionType fused_activation_function) + void add_combiner(CombinerType combiner) { - fbb_.AddElement(ConcatenationOptions::VT_FUSED_ACTIVATION_FUNCTION, - static_cast(fused_activation_function), 0); + fbb_.AddElement(EmbeddingLookupSparseOptions::VT_COMBINER, + static_cast(combiner), 0); } - explicit ConcatenationOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit EmbeddingLookupSparseOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - ConcatenationOptionsBuilder &operator=(const ConcatenationOptionsBuilder &); - flatbuffers::Offset Finish() + EmbeddingLookupSparseOptionsBuilder &operator=(const EmbeddingLookupSparseOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateConcatenationOptions( - flatbuffers::FlatBufferBuilder &_fbb, int32_t axis = 0, - ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE) +inline flatbuffers::Offset +CreateEmbeddingLookupSparseOptions(flatbuffers::FlatBufferBuilder &_fbb, + CombinerType combiner = CombinerType_SUM) { - ConcatenationOptionsBuilder builder_(_fbb); - builder_.add_axis(axis); - builder_.add_fused_activation_function(fused_activation_function); + EmbeddingLookupSparseOptionsBuilder builder_(_fbb); + builder_.add_combiner(combiner); return builder_.Finish(); } -struct AddOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct GatherOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_FUSED_ACTIVATION_FUNCTION = 4 + VT_AXIS = 4 }; - ActivationFunctionType fused_activation_function() const - { - return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); - } + int32_t axis() const { return GetField(VT_AXIS, 0); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyField(verifier, VT_AXIS) && + verifier.EndTable(); } }; -struct AddOptionsBuilder +struct GatherOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_fused_activation_function(ActivationFunctionType fused_activation_function) - { - fbb_.AddElement(AddOptions::VT_FUSED_ACTIVATION_FUNCTION, - static_cast(fused_activation_function), 0); - } - explicit AddOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + void add_axis(int32_t axis) { fbb_.AddElement(GatherOptions::VT_AXIS, axis, 0); } + explicit GatherOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - AddOptionsBuilder &operator=(const AddOptionsBuilder &); - flatbuffers::Offset Finish() + GatherOptionsBuilder &operator=(const GatherOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateAddOptions(flatbuffers::FlatBufferBuilder &_fbb, - ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE) +inline flatbuffers::Offset CreateGatherOptions(flatbuffers::FlatBufferBuilder &_fbb, + int32_t axis = 0) { - AddOptionsBuilder builder_(_fbb); - builder_.add_fused_activation_function(fused_activation_function); + GatherOptionsBuilder builder_(_fbb); + builder_.add_axis(axis); return builder_.Finish(); } -struct MulOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct TransposeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum - { - VT_FUSED_ACTIVATION_FUNCTION = 4 - }; - ActivationFunctionType fused_activation_function() const - { - return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); - } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct MulOptionsBuilder +struct TransposeOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_fused_activation_function(ActivationFunctionType fused_activation_function) - { - fbb_.AddElement(MulOptions::VT_FUSED_ACTIVATION_FUNCTION, - static_cast(fused_activation_function), 0); - } - explicit MulOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit TransposeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - MulOptionsBuilder &operator=(const MulOptionsBuilder &); - flatbuffers::Offset Finish() + TransposeOptionsBuilder &operator=(const TransposeOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateMulOptions(flatbuffers::FlatBufferBuilder &_fbb, - ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE) +inline flatbuffers::Offset +CreateTransposeOptions(flatbuffers::FlatBufferBuilder &_fbb) { - MulOptionsBuilder builder_(_fbb); - builder_.add_fused_activation_function(fused_activation_function); + TransposeOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct L2NormOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct ExpOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum - { - VT_FUSED_ACTIVATION_FUNCTION = 4 - }; - ActivationFunctionType fused_activation_function() const - { - return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); - } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct L2NormOptionsBuilder +struct ExpOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_fused_activation_function(ActivationFunctionType fused_activation_function) - { - fbb_.AddElement(L2NormOptions::VT_FUSED_ACTIVATION_FUNCTION, - static_cast(fused_activation_function), 0); - } - explicit L2NormOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit ExpOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - L2NormOptionsBuilder &operator=(const L2NormOptionsBuilder &); - flatbuffers::Offset Finish() + ExpOptionsBuilder &operator=(const ExpOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateL2NormOptions(flatbuffers::FlatBufferBuilder &_fbb, - ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE) +inline flatbuffers::Offset CreateExpOptions(flatbuffers::FlatBufferBuilder &_fbb) { - L2NormOptionsBuilder builder_(_fbb); - builder_.add_fused_activation_function(fused_activation_function); + ExpOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct LocalResponseNormalizationOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct CosOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum - { - VT_RADIUS = 4, - VT_BIAS = 6, - VT_ALPHA = 8, - VT_BETA = 10 - }; - int32_t radius() const { return GetField(VT_RADIUS, 0); } - float bias() const { return GetField(VT_BIAS, 0.0f); } - float alpha() const { return GetField(VT_ALPHA, 0.0f); } - float beta() const { return GetField(VT_BETA, 0.0f); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_RADIUS) && - VerifyField(verifier, VT_BIAS) && VerifyField(verifier, VT_ALPHA) && - VerifyField(verifier, VT_BETA) && verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct LocalResponseNormalizationOptionsBuilder +struct CosOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_radius(int32_t radius) - { - fbb_.AddElement(LocalResponseNormalizationOptions::VT_RADIUS, radius, 0); - } - void add_bias(float bias) - { - fbb_.AddElement(LocalResponseNormalizationOptions::VT_BIAS, bias, 0.0f); - } - void add_alpha(float alpha) - { - fbb_.AddElement(LocalResponseNormalizationOptions::VT_ALPHA, alpha, 0.0f); - } - void add_beta(float beta) - { - fbb_.AddElement(LocalResponseNormalizationOptions::VT_BETA, beta, 0.0f); - } - explicit LocalResponseNormalizationOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) + explicit CosOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - LocalResponseNormalizationOptionsBuilder & - operator=(const LocalResponseNormalizationOptionsBuilder &); - flatbuffers::Offset Finish() + CosOptionsBuilder &operator=(const CosOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateLocalResponseNormalizationOptions(flatbuffers::FlatBufferBuilder &_fbb, int32_t radius = 0, - float bias = 0.0f, float alpha = 0.0f, float beta = 0.0f) +inline flatbuffers::Offset CreateCosOptions(flatbuffers::FlatBufferBuilder &_fbb) { - LocalResponseNormalizationOptionsBuilder builder_(_fbb); - builder_.add_beta(beta); - builder_.add_alpha(alpha); - builder_.add_bias(bias); - builder_.add_radius(radius); + CosOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct LSTMOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct ReducerOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_FUSED_ACTIVATION_FUNCTION = 4, - VT_CELL_CLIP = 6, - VT_PROJ_CLIP = 8, - VT_KERNEL_TYPE = 10 + VT_KEEP_DIMS = 4 }; - ActivationFunctionType fused_activation_function() const - { - return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); - } - float cell_clip() const { return GetField(VT_CELL_CLIP, 0.0f); } - float proj_clip() const { return GetField(VT_PROJ_CLIP, 0.0f); } - LSTMKernelType kernel_type() const - { - return static_cast(GetField(VT_KERNEL_TYPE, 0)); - } + bool keep_dims() const { return GetField(VT_KEEP_DIMS, 0) != 0; } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && - VerifyField(verifier, VT_CELL_CLIP) && - VerifyField(verifier, VT_PROJ_CLIP) && - VerifyField(verifier, VT_KERNEL_TYPE) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyField(verifier, VT_KEEP_DIMS) && + verifier.EndTable(); } }; -struct LSTMOptionsBuilder +struct ReducerOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_fused_activation_function(ActivationFunctionType fused_activation_function) - { - fbb_.AddElement(LSTMOptions::VT_FUSED_ACTIVATION_FUNCTION, - static_cast(fused_activation_function), 0); - } - void add_cell_clip(float cell_clip) - { - fbb_.AddElement(LSTMOptions::VT_CELL_CLIP, cell_clip, 0.0f); - } - void add_proj_clip(float proj_clip) - { - fbb_.AddElement(LSTMOptions::VT_PROJ_CLIP, proj_clip, 0.0f); - } - void add_kernel_type(LSTMKernelType kernel_type) + void add_keep_dims(bool keep_dims) { - fbb_.AddElement(LSTMOptions::VT_KERNEL_TYPE, static_cast(kernel_type), 0); + fbb_.AddElement(ReducerOptions::VT_KEEP_DIMS, static_cast(keep_dims), 0); } - explicit LSTMOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit ReducerOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - LSTMOptionsBuilder &operator=(const LSTMOptionsBuilder &); - flatbuffers::Offset Finish() + ReducerOptionsBuilder &operator=(const ReducerOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateLSTMOptions(flatbuffers::FlatBufferBuilder &_fbb, - ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE, - float cell_clip = 0.0f, float proj_clip = 0.0f, - LSTMKernelType kernel_type = LSTMKernelType_FULL) +inline flatbuffers::Offset +CreateReducerOptions(flatbuffers::FlatBufferBuilder &_fbb, bool keep_dims = false) { - LSTMOptionsBuilder builder_(_fbb); - builder_.add_proj_clip(proj_clip); - builder_.add_cell_clip(cell_clip); - builder_.add_kernel_type(kernel_type); - builder_.add_fused_activation_function(fused_activation_function); + ReducerOptionsBuilder builder_(_fbb); + builder_.add_keep_dims(keep_dims); return builder_.Finish(); } -struct UnidirectionalSequenceLSTMOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct SqueezeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_FUSED_ACTIVATION_FUNCTION = 4, - VT_CELL_CLIP = 6, - VT_PROJ_CLIP = 8, - VT_TIME_MAJOR = 10 + VT_SQUEEZE_DIMS = 4 }; - ActivationFunctionType fused_activation_function() const + const flatbuffers::Vector *squeeze_dims() const { - return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + return GetPointer *>(VT_SQUEEZE_DIMS); } - float cell_clip() const { return GetField(VT_CELL_CLIP, 0.0f); } - float proj_clip() const { return GetField(VT_PROJ_CLIP, 0.0f); } - bool time_major() const { return GetField(VT_TIME_MAJOR, 0) != 0; } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && - VerifyField(verifier, VT_CELL_CLIP) && - VerifyField(verifier, VT_PROJ_CLIP) && - VerifyField(verifier, VT_TIME_MAJOR) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyOffset(verifier, VT_SQUEEZE_DIMS) && + verifier.VerifyVector(squeeze_dims()) && verifier.EndTable(); } }; -struct UnidirectionalSequenceLSTMOptionsBuilder +struct SqueezeOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_fused_activation_function(ActivationFunctionType fused_activation_function) - { - fbb_.AddElement(UnidirectionalSequenceLSTMOptions::VT_FUSED_ACTIVATION_FUNCTION, - static_cast(fused_activation_function), 0); - } - void add_cell_clip(float cell_clip) - { - fbb_.AddElement(UnidirectionalSequenceLSTMOptions::VT_CELL_CLIP, cell_clip, 0.0f); - } - void add_proj_clip(float proj_clip) - { - fbb_.AddElement(UnidirectionalSequenceLSTMOptions::VT_PROJ_CLIP, proj_clip, 0.0f); - } - void add_time_major(bool time_major) + void add_squeeze_dims(flatbuffers::Offset> squeeze_dims) { - fbb_.AddElement(UnidirectionalSequenceLSTMOptions::VT_TIME_MAJOR, - static_cast(time_major), 0); + fbb_.AddOffset(SqueezeOptions::VT_SQUEEZE_DIMS, squeeze_dims); } - explicit UnidirectionalSequenceLSTMOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) + explicit SqueezeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - UnidirectionalSequenceLSTMOptionsBuilder & - operator=(const UnidirectionalSequenceLSTMOptionsBuilder &); - flatbuffers::Offset Finish() + SqueezeOptionsBuilder &operator=(const SqueezeOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateUnidirectionalSequenceLSTMOptions( - flatbuffers::FlatBufferBuilder &_fbb, - ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE, - float cell_clip = 0.0f, float proj_clip = 0.0f, bool time_major = false) +inline flatbuffers::Offset +CreateSqueezeOptions(flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset> squeeze_dims = 0) { - UnidirectionalSequenceLSTMOptionsBuilder builder_(_fbb); - builder_.add_proj_clip(proj_clip); - builder_.add_cell_clip(cell_clip); - builder_.add_time_major(time_major); - builder_.add_fused_activation_function(fused_activation_function); + SqueezeOptionsBuilder builder_(_fbb); + builder_.add_squeeze_dims(squeeze_dims); return builder_.Finish(); } -struct BidirectionalSequenceLSTMOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +inline flatbuffers::Offset +CreateSqueezeOptionsDirect(flatbuffers::FlatBufferBuilder &_fbb, + const std::vector *squeeze_dims = nullptr) +{ + return circle::CreateSqueezeOptions(_fbb, + squeeze_dims ? _fbb.CreateVector(*squeeze_dims) : 0); +} + +struct SplitOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_FUSED_ACTIVATION_FUNCTION = 4, - VT_CELL_CLIP = 6, - VT_PROJ_CLIP = 8, - VT_MERGE_OUTPUTS = 10 + VT_NUM_SPLITS = 4 }; - ActivationFunctionType fused_activation_function() const - { - return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); - } - float cell_clip() const { return GetField(VT_CELL_CLIP, 0.0f); } - float proj_clip() const { return GetField(VT_PROJ_CLIP, 0.0f); } - bool merge_outputs() const { return GetField(VT_MERGE_OUTPUTS, 0) != 0; } + int32_t num_splits() const { return GetField(VT_NUM_SPLITS, 0); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && - VerifyField(verifier, VT_CELL_CLIP) && - VerifyField(verifier, VT_PROJ_CLIP) && - VerifyField(verifier, VT_MERGE_OUTPUTS) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyField(verifier, VT_NUM_SPLITS) && + verifier.EndTable(); } }; -struct BidirectionalSequenceLSTMOptionsBuilder +struct SplitOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_fused_activation_function(ActivationFunctionType fused_activation_function) - { - fbb_.AddElement(BidirectionalSequenceLSTMOptions::VT_FUSED_ACTIVATION_FUNCTION, - static_cast(fused_activation_function), 0); - } - void add_cell_clip(float cell_clip) - { - fbb_.AddElement(BidirectionalSequenceLSTMOptions::VT_CELL_CLIP, cell_clip, 0.0f); - } - void add_proj_clip(float proj_clip) - { - fbb_.AddElement(BidirectionalSequenceLSTMOptions::VT_PROJ_CLIP, proj_clip, 0.0f); - } - void add_merge_outputs(bool merge_outputs) + void add_num_splits(int32_t num_splits) { - fbb_.AddElement(BidirectionalSequenceLSTMOptions::VT_MERGE_OUTPUTS, - static_cast(merge_outputs), 0); + fbb_.AddElement(SplitOptions::VT_NUM_SPLITS, num_splits, 0); } - explicit BidirectionalSequenceLSTMOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) + explicit SplitOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - BidirectionalSequenceLSTMOptionsBuilder & - operator=(const BidirectionalSequenceLSTMOptionsBuilder &); - flatbuffers::Offset Finish() + SplitOptionsBuilder &operator=(const SplitOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateBidirectionalSequenceLSTMOptions( - flatbuffers::FlatBufferBuilder &_fbb, - ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE, - float cell_clip = 0.0f, float proj_clip = 0.0f, bool merge_outputs = false) +inline flatbuffers::Offset CreateSplitOptions(flatbuffers::FlatBufferBuilder &_fbb, + int32_t num_splits = 0) { - BidirectionalSequenceLSTMOptionsBuilder builder_(_fbb); - builder_.add_proj_clip(proj_clip); - builder_.add_cell_clip(cell_clip); - builder_.add_merge_outputs(merge_outputs); - builder_.add_fused_activation_function(fused_activation_function); + SplitOptionsBuilder builder_(_fbb); + builder_.add_num_splits(num_splits); return builder_.Finish(); } -struct ResizeBilinearOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct SplitVOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_ALIGN_CORNERS = 8 + VT_NUM_SPLITS = 4 }; - bool align_corners() const { return GetField(VT_ALIGN_CORNERS, 0) != 0; } + int32_t num_splits() const { return GetField(VT_NUM_SPLITS, 0); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_ALIGN_CORNERS) && + return VerifyTableStart(verifier) && VerifyField(verifier, VT_NUM_SPLITS) && verifier.EndTable(); } }; -struct ResizeBilinearOptionsBuilder +struct SplitVOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_align_corners(bool align_corners) + void add_num_splits(int32_t num_splits) { - fbb_.AddElement(ResizeBilinearOptions::VT_ALIGN_CORNERS, - static_cast(align_corners), 0); + fbb_.AddElement(SplitVOptions::VT_NUM_SPLITS, num_splits, 0); } - explicit ResizeBilinearOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit SplitVOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - ResizeBilinearOptionsBuilder &operator=(const ResizeBilinearOptionsBuilder &); - flatbuffers::Offset Finish() + SplitVOptionsBuilder &operator=(const SplitVOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateResizeBilinearOptions(flatbuffers::FlatBufferBuilder &_fbb, bool align_corners = false) +inline flatbuffers::Offset CreateSplitVOptions(flatbuffers::FlatBufferBuilder &_fbb, + int32_t num_splits = 0) { - ResizeBilinearOptionsBuilder builder_(_fbb); - builder_.add_align_corners(align_corners); + SplitVOptionsBuilder builder_(_fbb); + builder_.add_num_splits(num_splits); return builder_.Finish(); } -struct ResizeNearestNeighborOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct StridedSliceOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_ALIGN_CORNERS = 4 + VT_BEGIN_MASK = 4, + VT_END_MASK = 6, + VT_ELLIPSIS_MASK = 8, + VT_NEW_AXIS_MASK = 10, + VT_SHRINK_AXIS_MASK = 12 }; - bool align_corners() const { return GetField(VT_ALIGN_CORNERS, 0) != 0; } + int32_t begin_mask() const { return GetField(VT_BEGIN_MASK, 0); } + int32_t end_mask() const { return GetField(VT_END_MASK, 0); } + int32_t ellipsis_mask() const { return GetField(VT_ELLIPSIS_MASK, 0); } + int32_t new_axis_mask() const { return GetField(VT_NEW_AXIS_MASK, 0); } + int32_t shrink_axis_mask() const { return GetField(VT_SHRINK_AXIS_MASK, 0); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_ALIGN_CORNERS) && - verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyField(verifier, VT_BEGIN_MASK) && + VerifyField(verifier, VT_END_MASK) && + VerifyField(verifier, VT_ELLIPSIS_MASK) && + VerifyField(verifier, VT_NEW_AXIS_MASK) && + VerifyField(verifier, VT_SHRINK_AXIS_MASK) && verifier.EndTable(); } }; -struct ResizeNearestNeighborOptionsBuilder +struct StridedSliceOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_align_corners(bool align_corners) + void add_begin_mask(int32_t begin_mask) { - fbb_.AddElement(ResizeNearestNeighborOptions::VT_ALIGN_CORNERS, - static_cast(align_corners), 0); + fbb_.AddElement(StridedSliceOptions::VT_BEGIN_MASK, begin_mask, 0); } - explicit ResizeNearestNeighborOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + void add_end_mask(int32_t end_mask) + { + fbb_.AddElement(StridedSliceOptions::VT_END_MASK, end_mask, 0); + } + void add_ellipsis_mask(int32_t ellipsis_mask) + { + fbb_.AddElement(StridedSliceOptions::VT_ELLIPSIS_MASK, ellipsis_mask, 0); + } + void add_new_axis_mask(int32_t new_axis_mask) + { + fbb_.AddElement(StridedSliceOptions::VT_NEW_AXIS_MASK, new_axis_mask, 0); + } + void add_shrink_axis_mask(int32_t shrink_axis_mask) + { + fbb_.AddElement(StridedSliceOptions::VT_SHRINK_AXIS_MASK, shrink_axis_mask, 0); + } + explicit StridedSliceOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - ResizeNearestNeighborOptionsBuilder &operator=(const ResizeNearestNeighborOptionsBuilder &); - flatbuffers::Offset Finish() + StridedSliceOptionsBuilder &operator=(const StridedSliceOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateResizeNearestNeighborOptions(flatbuffers::FlatBufferBuilder &_fbb, bool align_corners = false) +inline flatbuffers::Offset +CreateStridedSliceOptions(flatbuffers::FlatBufferBuilder &_fbb, int32_t begin_mask = 0, + int32_t end_mask = 0, int32_t ellipsis_mask = 0, + int32_t new_axis_mask = 0, int32_t shrink_axis_mask = 0) { - ResizeNearestNeighborOptionsBuilder builder_(_fbb); - builder_.add_align_corners(align_corners); + StridedSliceOptionsBuilder builder_(_fbb); + builder_.add_shrink_axis_mask(shrink_axis_mask); + builder_.add_new_axis_mask(new_axis_mask); + builder_.add_ellipsis_mask(ellipsis_mask); + builder_.add_end_mask(end_mask); + builder_.add_begin_mask(begin_mask); return builder_.Finish(); } -struct CallOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct LogSoftmaxOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum - { - VT_SUBGRAPH = 4 - }; - uint32_t subgraph() const { return GetField(VT_SUBGRAPH, 0); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_SUBGRAPH) && - verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct CallOptionsBuilder +struct LogSoftmaxOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_subgraph(uint32_t subgraph) - { - fbb_.AddElement(CallOptions::VT_SUBGRAPH, subgraph, 0); - } - explicit CallOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit LogSoftmaxOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - CallOptionsBuilder &operator=(const CallOptionsBuilder &); - flatbuffers::Offset Finish() + LogSoftmaxOptionsBuilder &operator=(const LogSoftmaxOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateCallOptions(flatbuffers::FlatBufferBuilder &_fbb, - uint32_t subgraph = 0) +inline flatbuffers::Offset +CreateLogSoftmaxOptions(flatbuffers::FlatBufferBuilder &_fbb) { - CallOptionsBuilder builder_(_fbb); - builder_.add_subgraph(subgraph); + LogSoftmaxOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct PadOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct CastOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + enum + { + VT_IN_DATA_TYPE = 4, + VT_OUT_DATA_TYPE = 6 + }; + TensorType in_data_type() const + { + return static_cast(GetField(VT_IN_DATA_TYPE, 0)); + } + TensorType out_data_type() const + { + return static_cast(GetField(VT_OUT_DATA_TYPE, 0)); + } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyField(verifier, VT_IN_DATA_TYPE) && + VerifyField(verifier, VT_OUT_DATA_TYPE) && verifier.EndTable(); } }; -struct PadOptionsBuilder +struct CastOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit PadOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + void add_in_data_type(TensorType in_data_type) { - start_ = fbb_.StartTable(); + fbb_.AddElement(CastOptions::VT_IN_DATA_TYPE, static_cast(in_data_type), 0); } - PadOptionsBuilder &operator=(const PadOptionsBuilder &); - flatbuffers::Offset Finish() + void add_out_data_type(TensorType out_data_type) + { + fbb_.AddElement(CastOptions::VT_OUT_DATA_TYPE, static_cast(out_data_type), 0); + } + explicit CastOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + CastOptionsBuilder &operator=(const CastOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreatePadOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateCastOptions(flatbuffers::FlatBufferBuilder &_fbb, + TensorType in_data_type = TensorType_FLOAT32, + TensorType out_data_type = TensorType_FLOAT32) { - PadOptionsBuilder builder_(_fbb); + CastOptionsBuilder builder_(_fbb); + builder_.add_out_data_type(out_data_type); + builder_.add_in_data_type(in_data_type); return builder_.Finish(); } -struct PadV2Options FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct DequantizeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { bool Verify(flatbuffers::Verifier &verifier) const { @@ -3364,84 +5270,63 @@ struct PadV2Options FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table } }; -struct PadV2OptionsBuilder +struct DequantizeOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit PadV2OptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit DequantizeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - PadV2OptionsBuilder &operator=(const PadV2OptionsBuilder &); - flatbuffers::Offset Finish() + DequantizeOptionsBuilder &operator=(const DequantizeOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreatePadV2Options(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateDequantizeOptions(flatbuffers::FlatBufferBuilder &_fbb) { - PadV2OptionsBuilder builder_(_fbb); + DequantizeOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct ReshapeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct MaximumMinimumOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum - { - VT_NEW_SHAPE = 4 - }; - const flatbuffers::Vector *new_shape() const - { - return GetPointer *>(VT_NEW_SHAPE); - } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyOffset(verifier, VT_NEW_SHAPE) && - verifier.VerifyVector(new_shape()) && verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct ReshapeOptionsBuilder +struct MaximumMinimumOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_new_shape(flatbuffers::Offset> new_shape) - { - fbb_.AddOffset(ReshapeOptions::VT_NEW_SHAPE, new_shape); - } - explicit ReshapeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit MaximumMinimumOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - ReshapeOptionsBuilder &operator=(const ReshapeOptionsBuilder &); - flatbuffers::Offset Finish() + MaximumMinimumOptionsBuilder &operator=(const MaximumMinimumOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateReshapeOptions(flatbuffers::FlatBufferBuilder &_fbb, - flatbuffers::Offset> new_shape = 0) +inline flatbuffers::Offset +CreateMaximumMinimumOptions(flatbuffers::FlatBufferBuilder &_fbb) { - ReshapeOptionsBuilder builder_(_fbb); - builder_.add_new_shape(new_shape); + MaximumMinimumOptionsBuilder builder_(_fbb); return builder_.Finish(); } -inline flatbuffers::Offset -CreateReshapeOptionsDirect(flatbuffers::FlatBufferBuilder &_fbb, - const std::vector *new_shape = nullptr) -{ - return circle::CreateReshapeOptions(_fbb, new_shape ? _fbb.CreateVector(*new_shape) : 0); -} - -struct SpaceToBatchNDOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct TileOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { bool Verify(flatbuffers::Verifier &verifier) const { @@ -3449,262 +5334,219 @@ struct SpaceToBatchNDOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Tabl } }; -struct SpaceToBatchNDOptionsBuilder +struct TileOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit SpaceToBatchNDOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit TileOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - SpaceToBatchNDOptionsBuilder &operator=(const SpaceToBatchNDOptionsBuilder &); - flatbuffers::Offset Finish() + TileOptionsBuilder &operator=(const TileOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateSpaceToBatchNDOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset CreateTileOptions(flatbuffers::FlatBufferBuilder &_fbb) { - SpaceToBatchNDOptionsBuilder builder_(_fbb); + TileOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct BatchToSpaceNDOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct ArgMaxOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + enum + { + VT_OUTPUT_TYPE = 4 + }; + TensorType output_type() const + { + return static_cast(GetField(VT_OUTPUT_TYPE, 0)); + } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyField(verifier, VT_OUTPUT_TYPE) && + verifier.EndTable(); } }; -struct BatchToSpaceNDOptionsBuilder +struct ArgMaxOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit BatchToSpaceNDOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + void add_output_type(TensorType output_type) + { + fbb_.AddElement(ArgMaxOptions::VT_OUTPUT_TYPE, static_cast(output_type), 0); + } + explicit ArgMaxOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - BatchToSpaceNDOptionsBuilder &operator=(const BatchToSpaceNDOptionsBuilder &); - flatbuffers::Offset Finish() + ArgMaxOptionsBuilder &operator=(const ArgMaxOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateBatchToSpaceNDOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateArgMaxOptions(flatbuffers::FlatBufferBuilder &_fbb, + TensorType output_type = TensorType_FLOAT32) { - BatchToSpaceNDOptionsBuilder builder_(_fbb); + ArgMaxOptionsBuilder builder_(_fbb); + builder_.add_output_type(output_type); return builder_.Finish(); } -struct SkipGramOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct ArgMinOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_NGRAM_SIZE = 4, - VT_MAX_SKIP_SIZE = 6, - VT_INCLUDE_ALL_NGRAMS = 8 + VT_OUTPUT_TYPE = 4 }; - int32_t ngram_size() const { return GetField(VT_NGRAM_SIZE, 0); } - int32_t max_skip_size() const { return GetField(VT_MAX_SKIP_SIZE, 0); } - bool include_all_ngrams() const { return GetField(VT_INCLUDE_ALL_NGRAMS, 0) != 0; } + TensorType output_type() const + { + return static_cast(GetField(VT_OUTPUT_TYPE, 0)); + } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_NGRAM_SIZE) && - VerifyField(verifier, VT_MAX_SKIP_SIZE) && - VerifyField(verifier, VT_INCLUDE_ALL_NGRAMS) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyField(verifier, VT_OUTPUT_TYPE) && + verifier.EndTable(); } }; -struct SkipGramOptionsBuilder +struct ArgMinOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_ngram_size(int32_t ngram_size) - { - fbb_.AddElement(SkipGramOptions::VT_NGRAM_SIZE, ngram_size, 0); - } - void add_max_skip_size(int32_t max_skip_size) - { - fbb_.AddElement(SkipGramOptions::VT_MAX_SKIP_SIZE, max_skip_size, 0); - } - void add_include_all_ngrams(bool include_all_ngrams) + void add_output_type(TensorType output_type) { - fbb_.AddElement(SkipGramOptions::VT_INCLUDE_ALL_NGRAMS, - static_cast(include_all_ngrams), 0); + fbb_.AddElement(ArgMinOptions::VT_OUTPUT_TYPE, static_cast(output_type), 0); } - explicit SkipGramOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit ArgMinOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - SkipGramOptionsBuilder &operator=(const SkipGramOptionsBuilder &); - flatbuffers::Offset Finish() + ArgMinOptionsBuilder &operator=(const ArgMinOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateSkipGramOptions(flatbuffers::FlatBufferBuilder &_fbb, int32_t ngram_size = 0, - int32_t max_skip_size = 0, bool include_all_ngrams = false) +inline flatbuffers::Offset +CreateArgMinOptions(flatbuffers::FlatBufferBuilder &_fbb, + TensorType output_type = TensorType_FLOAT32) { - SkipGramOptionsBuilder builder_(_fbb); - builder_.add_max_skip_size(max_skip_size); - builder_.add_ngram_size(ngram_size); - builder_.add_include_all_ngrams(include_all_ngrams); + ArgMinOptionsBuilder builder_(_fbb); + builder_.add_output_type(output_type); return builder_.Finish(); } -struct SpaceToDepthOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct GreaterOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum - { - VT_BLOCK_SIZE = 4 - }; - int32_t block_size() const { return GetField(VT_BLOCK_SIZE, 0); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_BLOCK_SIZE) && - verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct SpaceToDepthOptionsBuilder +struct GreaterOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_block_size(int32_t block_size) - { - fbb_.AddElement(SpaceToDepthOptions::VT_BLOCK_SIZE, block_size, 0); - } - explicit SpaceToDepthOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit GreaterOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - SpaceToDepthOptionsBuilder &operator=(const SpaceToDepthOptionsBuilder &); - flatbuffers::Offset Finish() + GreaterOptionsBuilder &operator=(const GreaterOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateSpaceToDepthOptions(flatbuffers::FlatBufferBuilder &_fbb, int32_t block_size = 0) +inline flatbuffers::Offset +CreateGreaterOptions(flatbuffers::FlatBufferBuilder &_fbb) { - SpaceToDepthOptionsBuilder builder_(_fbb); - builder_.add_block_size(block_size); + GreaterOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct SubOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct GreaterEqualOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum - { - VT_FUSED_ACTIVATION_FUNCTION = 4 - }; - ActivationFunctionType fused_activation_function() const - { - return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); - } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct SubOptionsBuilder +struct GreaterEqualOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_fused_activation_function(ActivationFunctionType fused_activation_function) - { - fbb_.AddElement(SubOptions::VT_FUSED_ACTIVATION_FUNCTION, - static_cast(fused_activation_function), 0); - } - explicit SubOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit GreaterEqualOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - SubOptionsBuilder &operator=(const SubOptionsBuilder &); - flatbuffers::Offset Finish() + GreaterEqualOptionsBuilder &operator=(const GreaterEqualOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateSubOptions(flatbuffers::FlatBufferBuilder &_fbb, - ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE) +inline flatbuffers::Offset +CreateGreaterEqualOptions(flatbuffers::FlatBufferBuilder &_fbb) { - SubOptionsBuilder builder_(_fbb); - builder_.add_fused_activation_function(fused_activation_function); + GreaterEqualOptionsBuilder builder_(_fbb); return builder_.Finish(); } - -struct DivOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table -{ - enum - { - VT_FUSED_ACTIVATION_FUNCTION = 4 - }; - ActivationFunctionType fused_activation_function() const - { - return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); - } + +struct LessOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct DivOptionsBuilder +struct LessOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_fused_activation_function(ActivationFunctionType fused_activation_function) - { - fbb_.AddElement(DivOptions::VT_FUSED_ACTIVATION_FUNCTION, - static_cast(fused_activation_function), 0); - } - explicit DivOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit LessOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - DivOptionsBuilder &operator=(const DivOptionsBuilder &); - flatbuffers::Offset Finish() + LessOptionsBuilder &operator=(const LessOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateDivOptions(flatbuffers::FlatBufferBuilder &_fbb, - ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE) +inline flatbuffers::Offset CreateLessOptions(flatbuffers::FlatBufferBuilder &_fbb) { - DivOptionsBuilder builder_(_fbb); - builder_.add_fused_activation_function(fused_activation_function); + LessOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct TopKV2Options FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct LessEqualOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { bool Verify(flatbuffers::Verifier &verifier) const { @@ -3712,118 +5554,93 @@ struct TopKV2Options FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table } }; -struct TopKV2OptionsBuilder +struct LessEqualOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit TopKV2OptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit LessEqualOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - TopKV2OptionsBuilder &operator=(const TopKV2OptionsBuilder &); - flatbuffers::Offset Finish() + LessEqualOptionsBuilder &operator=(const LessEqualOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateTopKV2Options(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateLessEqualOptions(flatbuffers::FlatBufferBuilder &_fbb) { - TopKV2OptionsBuilder builder_(_fbb); + LessEqualOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct EmbeddingLookupSparseOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct NegOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum - { - VT_COMBINER = 4 - }; - CombinerType combiner() const - { - return static_cast(GetField(VT_COMBINER, 0)); - } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_COMBINER) && - verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct EmbeddingLookupSparseOptionsBuilder +struct NegOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_combiner(CombinerType combiner) - { - fbb_.AddElement(EmbeddingLookupSparseOptions::VT_COMBINER, - static_cast(combiner), 0); - } - explicit EmbeddingLookupSparseOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit NegOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - EmbeddingLookupSparseOptionsBuilder &operator=(const EmbeddingLookupSparseOptionsBuilder &); - flatbuffers::Offset Finish() + NegOptionsBuilder &operator=(const NegOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateEmbeddingLookupSparseOptions(flatbuffers::FlatBufferBuilder &_fbb, - CombinerType combiner = CombinerType_SUM) +inline flatbuffers::Offset CreateNegOptions(flatbuffers::FlatBufferBuilder &_fbb) { - EmbeddingLookupSparseOptionsBuilder builder_(_fbb); - builder_.add_combiner(combiner); + NegOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct GatherOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct SelectOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum - { - VT_AXIS = 4 - }; - int32_t axis() const { return GetField(VT_AXIS, 0); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_AXIS) && - verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct GatherOptionsBuilder +struct SelectOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_axis(int32_t axis) { fbb_.AddElement(GatherOptions::VT_AXIS, axis, 0); } - explicit GatherOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit SelectOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - GatherOptionsBuilder &operator=(const GatherOptionsBuilder &); - flatbuffers::Offset Finish() + SelectOptionsBuilder &operator=(const SelectOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateGatherOptions(flatbuffers::FlatBufferBuilder &_fbb, - int32_t axis = 0) +inline flatbuffers::Offset CreateSelectOptions(flatbuffers::FlatBufferBuilder &_fbb) { - GatherOptionsBuilder builder_(_fbb); - builder_.add_axis(axis); + SelectOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct TransposeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct SliceOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { bool Verify(flatbuffers::Verifier &verifier) const { @@ -3831,322 +5648,271 @@ struct TransposeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table } }; -struct TransposeOptionsBuilder +struct SliceOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit TransposeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit SliceOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - TransposeOptionsBuilder &operator=(const TransposeOptionsBuilder &); - flatbuffers::Offset Finish() + SliceOptionsBuilder &operator=(const SliceOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateTransposeOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset CreateSliceOptions(flatbuffers::FlatBufferBuilder &_fbb) { - TransposeOptionsBuilder builder_(_fbb); + SliceOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct ExpOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct TransposeConvOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + enum + { + VT_PADDING = 4, + VT_STRIDE_W = 6, + VT_STRIDE_H = 8 + }; + Padding padding() const { return static_cast(GetField(VT_PADDING, 0)); } + int32_t stride_w() const { return GetField(VT_STRIDE_W, 0); } + int32_t stride_h() const { return GetField(VT_STRIDE_H, 0); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyField(verifier, VT_PADDING) && + VerifyField(verifier, VT_STRIDE_W) && + VerifyField(verifier, VT_STRIDE_H) && verifier.EndTable(); } }; -struct ExpOptionsBuilder +struct TransposeConvOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit ExpOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + void add_padding(Padding padding) + { + fbb_.AddElement(TransposeConvOptions::VT_PADDING, static_cast(padding), 0); + } + void add_stride_w(int32_t stride_w) + { + fbb_.AddElement(TransposeConvOptions::VT_STRIDE_W, stride_w, 0); + } + void add_stride_h(int32_t stride_h) + { + fbb_.AddElement(TransposeConvOptions::VT_STRIDE_H, stride_h, 0); + } + explicit TransposeConvOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - ExpOptionsBuilder &operator=(const ExpOptionsBuilder &); - flatbuffers::Offset Finish() + TransposeConvOptionsBuilder &operator=(const TransposeConvOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateExpOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateTransposeConvOptions(flatbuffers::FlatBufferBuilder &_fbb, Padding padding = Padding_SAME, + int32_t stride_w = 0, int32_t stride_h = 0) { - ExpOptionsBuilder builder_(_fbb); + TransposeConvOptionsBuilder builder_(_fbb); + builder_.add_stride_h(stride_h); + builder_.add_stride_w(stride_w); + builder_.add_padding(padding); return builder_.Finish(); } -struct ReducerOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct ExpandDimsOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum - { - VT_KEEP_DIMS = 4 - }; - bool keep_dims() const { return GetField(VT_KEEP_DIMS, 0) != 0; } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_KEEP_DIMS) && - verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct ReducerOptionsBuilder +struct ExpandDimsOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_keep_dims(bool keep_dims) - { - fbb_.AddElement(ReducerOptions::VT_KEEP_DIMS, static_cast(keep_dims), 0); - } - explicit ReducerOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit ExpandDimsOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - ReducerOptionsBuilder &operator=(const ReducerOptionsBuilder &); - flatbuffers::Offset Finish() + ExpandDimsOptionsBuilder &operator=(const ExpandDimsOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateReducerOptions(flatbuffers::FlatBufferBuilder &_fbb, bool keep_dims = false) +inline flatbuffers::Offset +CreateExpandDimsOptions(flatbuffers::FlatBufferBuilder &_fbb) { - ReducerOptionsBuilder builder_(_fbb); - builder_.add_keep_dims(keep_dims); + ExpandDimsOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct SqueezeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct SparseToDenseOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_SQUEEZE_DIMS = 4 + VT_VALIDATE_INDICES = 4 }; - const flatbuffers::Vector *squeeze_dims() const - { - return GetPointer *>(VT_SQUEEZE_DIMS); - } + bool validate_indices() const { return GetField(VT_VALIDATE_INDICES, 0) != 0; } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyOffset(verifier, VT_SQUEEZE_DIMS) && - verifier.VerifyVector(squeeze_dims()) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyField(verifier, VT_VALIDATE_INDICES) && + verifier.EndTable(); } }; -struct SqueezeOptionsBuilder +struct SparseToDenseOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_squeeze_dims(flatbuffers::Offset> squeeze_dims) + void add_validate_indices(bool validate_indices) { - fbb_.AddOffset(SqueezeOptions::VT_SQUEEZE_DIMS, squeeze_dims); + fbb_.AddElement(SparseToDenseOptions::VT_VALIDATE_INDICES, + static_cast(validate_indices), 0); } - explicit SqueezeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit SparseToDenseOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - SqueezeOptionsBuilder &operator=(const SqueezeOptionsBuilder &); - flatbuffers::Offset Finish() + SparseToDenseOptionsBuilder &operator=(const SparseToDenseOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateSqueezeOptions(flatbuffers::FlatBufferBuilder &_fbb, - flatbuffers::Offset> squeeze_dims = 0) +inline flatbuffers::Offset +CreateSparseToDenseOptions(flatbuffers::FlatBufferBuilder &_fbb, bool validate_indices = false) { - SqueezeOptionsBuilder builder_(_fbb); - builder_.add_squeeze_dims(squeeze_dims); + SparseToDenseOptionsBuilder builder_(_fbb); + builder_.add_validate_indices(validate_indices); return builder_.Finish(); } -inline flatbuffers::Offset -CreateSqueezeOptionsDirect(flatbuffers::FlatBufferBuilder &_fbb, - const std::vector *squeeze_dims = nullptr) -{ - return circle::CreateSqueezeOptions(_fbb, - squeeze_dims ? _fbb.CreateVector(*squeeze_dims) : 0); -} - -struct SplitOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct EqualOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum - { - VT_NUM_SPLITS = 4 - }; - int32_t num_splits() const { return GetField(VT_NUM_SPLITS, 0); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_NUM_SPLITS) && - verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct SplitOptionsBuilder +struct EqualOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_num_splits(int32_t num_splits) - { - fbb_.AddElement(SplitOptions::VT_NUM_SPLITS, num_splits, 0); - } - explicit SplitOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit EqualOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - SplitOptionsBuilder &operator=(const SplitOptionsBuilder &); - flatbuffers::Offset Finish() + EqualOptionsBuilder &operator=(const EqualOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateSplitOptions(flatbuffers::FlatBufferBuilder &_fbb, - int32_t num_splits = 0) +inline flatbuffers::Offset CreateEqualOptions(flatbuffers::FlatBufferBuilder &_fbb) { - SplitOptionsBuilder builder_(_fbb); - builder_.add_num_splits(num_splits); + EqualOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct SplitVOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct NotEqualOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum - { - VT_NUM_SPLITS = 4 - }; - int32_t num_splits() const { return GetField(VT_NUM_SPLITS, 0); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_NUM_SPLITS) && - verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct SplitVOptionsBuilder +struct NotEqualOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_num_splits(int32_t num_splits) - { - fbb_.AddElement(SplitVOptions::VT_NUM_SPLITS, num_splits, 0); - } - explicit SplitVOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit NotEqualOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - SplitVOptionsBuilder &operator=(const SplitVOptionsBuilder &); - flatbuffers::Offset Finish() + NotEqualOptionsBuilder &operator=(const NotEqualOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateSplitVOptions(flatbuffers::FlatBufferBuilder &_fbb, - int32_t num_splits = 0) +inline flatbuffers::Offset +CreateNotEqualOptions(flatbuffers::FlatBufferBuilder &_fbb) { - SplitVOptionsBuilder builder_(_fbb); - builder_.add_num_splits(num_splits); + NotEqualOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct StridedSliceOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct ShapeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_BEGIN_MASK = 4, - VT_END_MASK = 6, - VT_ELLIPSIS_MASK = 8, - VT_NEW_AXIS_MASK = 10, - VT_SHRINK_AXIS_MASK = 12 + VT_OUT_TYPE = 4 }; - int32_t begin_mask() const { return GetField(VT_BEGIN_MASK, 0); } - int32_t end_mask() const { return GetField(VT_END_MASK, 0); } - int32_t ellipsis_mask() const { return GetField(VT_ELLIPSIS_MASK, 0); } - int32_t new_axis_mask() const { return GetField(VT_NEW_AXIS_MASK, 0); } - int32_t shrink_axis_mask() const { return GetField(VT_SHRINK_AXIS_MASK, 0); } + TensorType out_type() const { return static_cast(GetField(VT_OUT_TYPE, 0)); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_BEGIN_MASK) && - VerifyField(verifier, VT_END_MASK) && - VerifyField(verifier, VT_ELLIPSIS_MASK) && - VerifyField(verifier, VT_NEW_AXIS_MASK) && - VerifyField(verifier, VT_SHRINK_AXIS_MASK) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyField(verifier, VT_OUT_TYPE) && + verifier.EndTable(); } }; -struct StridedSliceOptionsBuilder +struct ShapeOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_begin_mask(int32_t begin_mask) - { - fbb_.AddElement(StridedSliceOptions::VT_BEGIN_MASK, begin_mask, 0); - } - void add_end_mask(int32_t end_mask) - { - fbb_.AddElement(StridedSliceOptions::VT_END_MASK, end_mask, 0); - } - void add_ellipsis_mask(int32_t ellipsis_mask) - { - fbb_.AddElement(StridedSliceOptions::VT_ELLIPSIS_MASK, ellipsis_mask, 0); - } - void add_new_axis_mask(int32_t new_axis_mask) - { - fbb_.AddElement(StridedSliceOptions::VT_NEW_AXIS_MASK, new_axis_mask, 0); - } - void add_shrink_axis_mask(int32_t shrink_axis_mask) + void add_out_type(TensorType out_type) { - fbb_.AddElement(StridedSliceOptions::VT_SHRINK_AXIS_MASK, shrink_axis_mask, 0); + fbb_.AddElement(ShapeOptions::VT_OUT_TYPE, static_cast(out_type), 0); } - explicit StridedSliceOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit ShapeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - StridedSliceOptionsBuilder &operator=(const StridedSliceOptionsBuilder &); - flatbuffers::Offset Finish() + ShapeOptionsBuilder &operator=(const ShapeOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateStridedSliceOptions(flatbuffers::FlatBufferBuilder &_fbb, int32_t begin_mask = 0, - int32_t end_mask = 0, int32_t ellipsis_mask = 0, - int32_t new_axis_mask = 0, int32_t shrink_axis_mask = 0) +inline flatbuffers::Offset +CreateShapeOptions(flatbuffers::FlatBufferBuilder &_fbb, TensorType out_type = TensorType_FLOAT32) { - StridedSliceOptionsBuilder builder_(_fbb); - builder_.add_shrink_axis_mask(shrink_axis_mask); - builder_.add_new_axis_mask(new_axis_mask); - builder_.add_ellipsis_mask(ellipsis_mask); - builder_.add_end_mask(end_mask); - builder_.add_begin_mask(begin_mask); + ShapeOptionsBuilder builder_(_fbb); + builder_.add_out_type(out_type); return builder_.Finish(); } -struct LogSoftmaxOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct RankOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { bool Verify(flatbuffers::Verifier &verifier) const { @@ -4154,153 +5920,169 @@ struct LogSoftmaxOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table } }; -struct LogSoftmaxOptionsBuilder +struct RankOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit LogSoftmaxOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit RankOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - LogSoftmaxOptionsBuilder &operator=(const LogSoftmaxOptionsBuilder &); - flatbuffers::Offset Finish() + RankOptionsBuilder &operator=(const RankOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateLogSoftmaxOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset CreateRankOptions(flatbuffers::FlatBufferBuilder &_fbb) { - LogSoftmaxOptionsBuilder builder_(_fbb); + RankOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct CastOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct PowOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum - { - VT_IN_DATA_TYPE = 4, - VT_OUT_DATA_TYPE = 6 - }; - TensorType in_data_type() const - { - return static_cast(GetField(VT_IN_DATA_TYPE, 0)); - } - TensorType out_data_type() const - { - return static_cast(GetField(VT_OUT_DATA_TYPE, 0)); - } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_IN_DATA_TYPE) && - VerifyField(verifier, VT_OUT_DATA_TYPE) && verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct CastOptionsBuilder +struct PowOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_in_data_type(TensorType in_data_type) - { - fbb_.AddElement(CastOptions::VT_IN_DATA_TYPE, static_cast(in_data_type), 0); - } - void add_out_data_type(TensorType out_data_type) - { - fbb_.AddElement(CastOptions::VT_OUT_DATA_TYPE, static_cast(out_data_type), 0); - } - explicit CastOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit PowOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - CastOptionsBuilder &operator=(const CastOptionsBuilder &); - flatbuffers::Offset Finish() + PowOptionsBuilder &operator=(const PowOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateCastOptions(flatbuffers::FlatBufferBuilder &_fbb, - TensorType in_data_type = TensorType_FLOAT32, - TensorType out_data_type = TensorType_FLOAT32) +inline flatbuffers::Offset CreatePowOptions(flatbuffers::FlatBufferBuilder &_fbb) { - CastOptionsBuilder builder_(_fbb); - builder_.add_out_data_type(out_data_type); - builder_.add_in_data_type(in_data_type); + PowOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct DequantizeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct FakeQuantOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + enum + { + VT_MIN = 4, + VT_MAX = 6, + VT_NUM_BITS = 8, + VT_NARROW_RANGE = 10 + }; + float min() const { return GetField(VT_MIN, 0.0f); } + float max() const { return GetField(VT_MAX, 0.0f); } + int32_t num_bits() const { return GetField(VT_NUM_BITS, 0); } + bool narrow_range() const { return GetField(VT_NARROW_RANGE, 0) != 0; } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyField(verifier, VT_MIN) && + VerifyField(verifier, VT_MAX) && VerifyField(verifier, VT_NUM_BITS) && + VerifyField(verifier, VT_NARROW_RANGE) && verifier.EndTable(); } }; -struct DequantizeOptionsBuilder +struct FakeQuantOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit DequantizeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + void add_min(float min) { fbb_.AddElement(FakeQuantOptions::VT_MIN, min, 0.0f); } + void add_max(float max) { fbb_.AddElement(FakeQuantOptions::VT_MAX, max, 0.0f); } + void add_num_bits(int32_t num_bits) + { + fbb_.AddElement(FakeQuantOptions::VT_NUM_BITS, num_bits, 0); + } + void add_narrow_range(bool narrow_range) + { + fbb_.AddElement(FakeQuantOptions::VT_NARROW_RANGE, static_cast(narrow_range), + 0); + } + explicit FakeQuantOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - DequantizeOptionsBuilder &operator=(const DequantizeOptionsBuilder &); - flatbuffers::Offset Finish() + FakeQuantOptionsBuilder &operator=(const FakeQuantOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateDequantizeOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateFakeQuantOptions(flatbuffers::FlatBufferBuilder &_fbb, float min = 0.0f, float max = 0.0f, + int32_t num_bits = 0, bool narrow_range = false) { - DequantizeOptionsBuilder builder_(_fbb); + FakeQuantOptionsBuilder builder_(_fbb); + builder_.add_num_bits(num_bits); + builder_.add_max(max); + builder_.add_min(min); + builder_.add_narrow_range(narrow_range); return builder_.Finish(); } -struct MaximumMinimumOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct PackOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + enum + { + VT_VALUES_COUNT = 4, + VT_AXIS = 6 + }; + int32_t values_count() const { return GetField(VT_VALUES_COUNT, 0); } + int32_t axis() const { return GetField(VT_AXIS, 0); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyField(verifier, VT_VALUES_COUNT) && + VerifyField(verifier, VT_AXIS) && verifier.EndTable(); } }; -struct MaximumMinimumOptionsBuilder +struct PackOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit MaximumMinimumOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + void add_values_count(int32_t values_count) + { + fbb_.AddElement(PackOptions::VT_VALUES_COUNT, values_count, 0); + } + void add_axis(int32_t axis) { fbb_.AddElement(PackOptions::VT_AXIS, axis, 0); } + explicit PackOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - MaximumMinimumOptionsBuilder &operator=(const MaximumMinimumOptionsBuilder &); - flatbuffers::Offset Finish() + PackOptionsBuilder &operator=(const PackOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateMaximumMinimumOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreatePackOptions(flatbuffers::FlatBufferBuilder &_fbb, int32_t values_count = 0, int32_t axis = 0) { - MaximumMinimumOptionsBuilder builder_(_fbb); + PackOptionsBuilder builder_(_fbb); + builder_.add_axis(axis); + builder_.add_values_count(values_count); return builder_.Finish(); } -struct TileOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct LogicalOrOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { bool Verify(flatbuffers::Verifier &verifier) const { @@ -4308,124 +6090,102 @@ struct TileOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table } }; -struct TileOptionsBuilder +struct LogicalOrOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit TileOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit LogicalOrOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - TileOptionsBuilder &operator=(const TileOptionsBuilder &); - flatbuffers::Offset Finish() + LogicalOrOptionsBuilder &operator=(const LogicalOrOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateTileOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateLogicalOrOptions(flatbuffers::FlatBufferBuilder &_fbb) { - TileOptionsBuilder builder_(_fbb); + LogicalOrOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct ArgMaxOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct OneHotOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_OUTPUT_TYPE = 4 + VT_AXIS = 4 }; - TensorType output_type() const - { - return static_cast(GetField(VT_OUTPUT_TYPE, 0)); - } + int32_t axis() const { return GetField(VT_AXIS, 0); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_OUTPUT_TYPE) && + return VerifyTableStart(verifier) && VerifyField(verifier, VT_AXIS) && verifier.EndTable(); } }; -struct ArgMaxOptionsBuilder +struct OneHotOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_output_type(TensorType output_type) - { - fbb_.AddElement(ArgMaxOptions::VT_OUTPUT_TYPE, static_cast(output_type), 0); - } - explicit ArgMaxOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + void add_axis(int32_t axis) { fbb_.AddElement(OneHotOptions::VT_AXIS, axis, 0); } + explicit OneHotOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - ArgMaxOptionsBuilder &operator=(const ArgMaxOptionsBuilder &); - flatbuffers::Offset Finish() + OneHotOptionsBuilder &operator=(const OneHotOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateArgMaxOptions(flatbuffers::FlatBufferBuilder &_fbb, - TensorType output_type = TensorType_FLOAT32) +inline flatbuffers::Offset CreateOneHotOptions(flatbuffers::FlatBufferBuilder &_fbb, + int32_t axis = 0) { - ArgMaxOptionsBuilder builder_(_fbb); - builder_.add_output_type(output_type); + OneHotOptionsBuilder builder_(_fbb); + builder_.add_axis(axis); return builder_.Finish(); } -struct ArgMinOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct AbsOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum - { - VT_OUTPUT_TYPE = 4 - }; - TensorType output_type() const - { - return static_cast(GetField(VT_OUTPUT_TYPE, 0)); - } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_OUTPUT_TYPE) && - verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct ArgMinOptionsBuilder +struct AbsOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_output_type(TensorType output_type) - { - fbb_.AddElement(ArgMinOptions::VT_OUTPUT_TYPE, static_cast(output_type), 0); - } - explicit ArgMinOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit AbsOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - ArgMinOptionsBuilder &operator=(const ArgMinOptionsBuilder &); - flatbuffers::Offset Finish() + AbsOptionsBuilder &operator=(const AbsOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateArgMinOptions(flatbuffers::FlatBufferBuilder &_fbb, - TensorType output_type = TensorType_FLOAT32) +inline flatbuffers::Offset CreateAbsOptions(flatbuffers::FlatBufferBuilder &_fbb) { - ArgMinOptionsBuilder builder_(_fbb); - builder_.add_output_type(output_type); + AbsOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct GreaterOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct HardSwishOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { bool Verify(flatbuffers::Verifier &verifier) const { @@ -4433,31 +6193,31 @@ struct GreaterOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table } }; -struct GreaterOptionsBuilder +struct HardSwishOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit GreaterOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit HardSwishOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - GreaterOptionsBuilder &operator=(const GreaterOptionsBuilder &); - flatbuffers::Offset Finish() + HardSwishOptionsBuilder &operator=(const HardSwishOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateGreaterOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateHardSwishOptions(flatbuffers::FlatBufferBuilder &_fbb) { - GreaterOptionsBuilder builder_(_fbb); + HardSwishOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct GreaterEqualOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct LogicalAndOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { bool Verify(flatbuffers::Verifier &verifier) const { @@ -4465,31 +6225,31 @@ struct GreaterEqualOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table } }; -struct GreaterEqualOptionsBuilder +struct LogicalAndOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit GreaterEqualOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit LogicalAndOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - GreaterEqualOptionsBuilder &operator=(const GreaterEqualOptionsBuilder &); - flatbuffers::Offset Finish() + LogicalAndOptionsBuilder &operator=(const LogicalAndOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateGreaterEqualOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateLogicalAndOptions(flatbuffers::FlatBufferBuilder &_fbb) { - GreaterEqualOptionsBuilder builder_(_fbb); + LogicalAndOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct LessOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct LogicalNotOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { bool Verify(flatbuffers::Verifier &verifier) const { @@ -4497,62 +6257,75 @@ struct LessOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table } }; -struct LessOptionsBuilder +struct LogicalNotOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit LessOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit LogicalNotOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - LessOptionsBuilder &operator=(const LessOptionsBuilder &); - flatbuffers::Offset Finish() + LogicalNotOptionsBuilder &operator=(const LogicalNotOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateLessOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateLogicalNotOptions(flatbuffers::FlatBufferBuilder &_fbb) { - LessOptionsBuilder builder_(_fbb); + LogicalNotOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct LessEqualOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct UnpackOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + enum + { + VT_NUM = 4, + VT_AXIS = 6 + }; + int32_t num() const { return GetField(VT_NUM, 0); } + int32_t axis() const { return GetField(VT_AXIS, 0); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyField(verifier, VT_NUM) && + VerifyField(verifier, VT_AXIS) && verifier.EndTable(); } }; -struct LessEqualOptionsBuilder +struct UnpackOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit LessEqualOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + void add_num(int32_t num) { fbb_.AddElement(UnpackOptions::VT_NUM, num, 0); } + void add_axis(int32_t axis) { fbb_.AddElement(UnpackOptions::VT_AXIS, axis, 0); } + explicit UnpackOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - LessEqualOptionsBuilder &operator=(const LessEqualOptionsBuilder &); - flatbuffers::Offset Finish() + UnpackOptionsBuilder &operator=(const UnpackOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateLessEqualOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset CreateUnpackOptions(flatbuffers::FlatBufferBuilder &_fbb, + int32_t num = 0, int32_t axis = 0) { - LessEqualOptionsBuilder builder_(_fbb); + UnpackOptionsBuilder builder_(_fbb); + builder_.add_axis(axis); + builder_.add_num(num); return builder_.Finish(); } -struct NegOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct FloorDivOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { bool Verify(flatbuffers::Verifier &verifier) const { @@ -4560,30 +6333,31 @@ struct NegOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table } }; -struct NegOptionsBuilder +struct FloorDivOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit NegOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit FloorDivOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - NegOptionsBuilder &operator=(const NegOptionsBuilder &); - flatbuffers::Offset Finish() + FloorDivOptionsBuilder &operator=(const FloorDivOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateNegOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateFloorDivOptions(flatbuffers::FlatBufferBuilder &_fbb) { - NegOptionsBuilder builder_(_fbb); + FloorDivOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct SelectOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct SquareOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { bool Verify(flatbuffers::Verifier &verifier) const { @@ -4591,30 +6365,30 @@ struct SelectOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table } }; -struct SelectOptionsBuilder +struct SquareOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit SelectOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit SquareOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - SelectOptionsBuilder &operator=(const SelectOptionsBuilder &); - flatbuffers::Offset Finish() + SquareOptionsBuilder &operator=(const SquareOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateSelectOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset CreateSquareOptions(flatbuffers::FlatBufferBuilder &_fbb) { - SelectOptionsBuilder builder_(_fbb); + SquareOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct SliceOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct ZerosLikeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { bool Verify(flatbuffers::Verifier &verifier) const { @@ -4622,89 +6396,62 @@ struct SliceOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table } }; -struct SliceOptionsBuilder +struct ZerosLikeOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit SliceOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit ZerosLikeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - SliceOptionsBuilder &operator=(const SliceOptionsBuilder &); - flatbuffers::Offset Finish() + ZerosLikeOptionsBuilder &operator=(const ZerosLikeOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateSliceOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateZerosLikeOptions(flatbuffers::FlatBufferBuilder &_fbb) { - SliceOptionsBuilder builder_(_fbb); + ZerosLikeOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct TransposeConvOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct FillOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum - { - VT_PADDING = 4, - VT_STRIDE_W = 6, - VT_STRIDE_H = 8 - }; - Padding padding() const { return static_cast(GetField(VT_PADDING, 0)); } - int32_t stride_w() const { return GetField(VT_STRIDE_W, 0); } - int32_t stride_h() const { return GetField(VT_STRIDE_H, 0); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_PADDING) && - VerifyField(verifier, VT_STRIDE_W) && - VerifyField(verifier, VT_STRIDE_H) && verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct TransposeConvOptionsBuilder +struct FillOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_padding(Padding padding) - { - fbb_.AddElement(TransposeConvOptions::VT_PADDING, static_cast(padding), 0); - } - void add_stride_w(int32_t stride_w) - { - fbb_.AddElement(TransposeConvOptions::VT_STRIDE_W, stride_w, 0); - } - void add_stride_h(int32_t stride_h) - { - fbb_.AddElement(TransposeConvOptions::VT_STRIDE_H, stride_h, 0); - } - explicit TransposeConvOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit FillOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - TransposeConvOptionsBuilder &operator=(const TransposeConvOptionsBuilder &); - flatbuffers::Offset Finish() + FillOptionsBuilder &operator=(const FillOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; - -inline flatbuffers::Offset -CreateTransposeConvOptions(flatbuffers::FlatBufferBuilder &_fbb, Padding padding = Padding_SAME, - int32_t stride_w = 0, int32_t stride_h = 0) -{ - TransposeConvOptionsBuilder builder_(_fbb); - builder_.add_stride_h(stride_h); - builder_.add_stride_w(stride_w); - builder_.add_padding(padding); + +inline flatbuffers::Offset CreateFillOptions(flatbuffers::FlatBufferBuilder &_fbb) +{ + FillOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct ExpandDimsOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct FloorModOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { bool Verify(flatbuffers::Verifier &verifier) const { @@ -4712,106 +6459,102 @@ struct ExpandDimsOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table } }; -struct ExpandDimsOptionsBuilder +struct FloorModOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit ExpandDimsOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit FloorModOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - ExpandDimsOptionsBuilder &operator=(const ExpandDimsOptionsBuilder &); - flatbuffers::Offset Finish() + FloorModOptionsBuilder &operator=(const FloorModOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateExpandDimsOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateFloorModOptions(flatbuffers::FlatBufferBuilder &_fbb) { - ExpandDimsOptionsBuilder builder_(_fbb); + FloorModOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct SparseToDenseOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct RangeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum - { - VT_VALIDATE_INDICES = 4 - }; - bool validate_indices() const { return GetField(VT_VALIDATE_INDICES, 0) != 0; } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_VALIDATE_INDICES) && - verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct SparseToDenseOptionsBuilder +struct RangeOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_validate_indices(bool validate_indices) - { - fbb_.AddElement(SparseToDenseOptions::VT_VALIDATE_INDICES, - static_cast(validate_indices), 0); - } - explicit SparseToDenseOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit RangeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - SparseToDenseOptionsBuilder &operator=(const SparseToDenseOptionsBuilder &); - flatbuffers::Offset Finish() + RangeOptionsBuilder &operator=(const RangeOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateSparseToDenseOptions(flatbuffers::FlatBufferBuilder &_fbb, bool validate_indices = false) +inline flatbuffers::Offset CreateRangeOptions(flatbuffers::FlatBufferBuilder &_fbb) { - SparseToDenseOptionsBuilder builder_(_fbb); - builder_.add_validate_indices(validate_indices); + RangeOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct EqualOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct LeakyReluOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + enum + { + VT_ALPHA = 4 + }; + float alpha() const { return GetField(VT_ALPHA, 0.0f); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyField(verifier, VT_ALPHA) && + verifier.EndTable(); } }; -struct EqualOptionsBuilder +struct LeakyReluOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit EqualOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + void add_alpha(float alpha) { fbb_.AddElement(LeakyReluOptions::VT_ALPHA, alpha, 0.0f); } + explicit LeakyReluOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - EqualOptionsBuilder &operator=(const EqualOptionsBuilder &); - flatbuffers::Offset Finish() + LeakyReluOptionsBuilder &operator=(const LeakyReluOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateEqualOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateLeakyReluOptions(flatbuffers::FlatBufferBuilder &_fbb, float alpha = 0.0f) { - EqualOptionsBuilder builder_(_fbb); + LeakyReluOptionsBuilder builder_(_fbb); + builder_.add_alpha(alpha); return builder_.Finish(); } -struct NotEqualOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct SquaredDifferenceOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { bool Verify(flatbuffers::Verifier &verifier) const { @@ -4819,213 +6562,185 @@ struct NotEqualOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table } }; -struct NotEqualOptionsBuilder +struct SquaredDifferenceOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit NotEqualOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit SquaredDifferenceOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - NotEqualOptionsBuilder &operator=(const NotEqualOptionsBuilder &); - flatbuffers::Offset Finish() + SquaredDifferenceOptionsBuilder &operator=(const SquaredDifferenceOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateNotEqualOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateSquaredDifferenceOptions(flatbuffers::FlatBufferBuilder &_fbb) { - NotEqualOptionsBuilder builder_(_fbb); + SquaredDifferenceOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct ShapeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct MirrorPadOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_OUT_TYPE = 4 + VT_MODE = 4 }; - TensorType out_type() const { return static_cast(GetField(VT_OUT_TYPE, 0)); } + MirrorPadMode mode() const { return static_cast(GetField(VT_MODE, 0)); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_OUT_TYPE) && + return VerifyTableStart(verifier) && VerifyField(verifier, VT_MODE) && verifier.EndTable(); } }; -struct ShapeOptionsBuilder +struct MirrorPadOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_out_type(TensorType out_type) + void add_mode(MirrorPadMode mode) { - fbb_.AddElement(ShapeOptions::VT_OUT_TYPE, static_cast(out_type), 0); + fbb_.AddElement(MirrorPadOptions::VT_MODE, static_cast(mode), 0); } - explicit ShapeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit MirrorPadOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - ShapeOptionsBuilder &operator=(const ShapeOptionsBuilder &); - flatbuffers::Offset Finish() + MirrorPadOptionsBuilder &operator=(const MirrorPadOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateShapeOptions(flatbuffers::FlatBufferBuilder &_fbb, TensorType out_type = TensorType_FLOAT32) +inline flatbuffers::Offset +CreateMirrorPadOptions(flatbuffers::FlatBufferBuilder &_fbb, + MirrorPadMode mode = MirrorPadMode_REFLECT) { - ShapeOptionsBuilder builder_(_fbb); - builder_.add_out_type(out_type); + MirrorPadOptionsBuilder builder_(_fbb); + builder_.add_mode(mode); return builder_.Finish(); } -struct PowOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct UniqueOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + enum + { + VT_IDX_OUT_TYPE = 4 + }; + TensorType idx_out_type() const + { + return static_cast(GetField(VT_IDX_OUT_TYPE, 2)); + } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyField(verifier, VT_IDX_OUT_TYPE) && + verifier.EndTable(); } }; -struct PowOptionsBuilder +struct UniqueOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit PowOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + void add_idx_out_type(TensorType idx_out_type) + { + fbb_.AddElement(UniqueOptions::VT_IDX_OUT_TYPE, static_cast(idx_out_type), 2); + } + explicit UniqueOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - PowOptionsBuilder &operator=(const PowOptionsBuilder &); - flatbuffers::Offset Finish() + UniqueOptionsBuilder &operator=(const UniqueOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreatePowOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateUniqueOptions(flatbuffers::FlatBufferBuilder &_fbb, + TensorType idx_out_type = TensorType_INT32) { - PowOptionsBuilder builder_(_fbb); + UniqueOptionsBuilder builder_(_fbb); + builder_.add_idx_out_type(idx_out_type); return builder_.Finish(); } -struct FakeQuantOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct ReverseV2Options FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum - { - VT_MIN = 4, - VT_MAX = 6, - VT_NUM_BITS = 8, - VT_NARROW_RANGE = 10 - }; - float min() const { return GetField(VT_MIN, 0.0f); } - float max() const { return GetField(VT_MAX, 0.0f); } - int32_t num_bits() const { return GetField(VT_NUM_BITS, 0); } - bool narrow_range() const { return GetField(VT_NARROW_RANGE, 0) != 0; } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_MIN) && - VerifyField(verifier, VT_MAX) && VerifyField(verifier, VT_NUM_BITS) && - VerifyField(verifier, VT_NARROW_RANGE) && verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct FakeQuantOptionsBuilder +struct ReverseV2OptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_min(float min) { fbb_.AddElement(FakeQuantOptions::VT_MIN, min, 0.0f); } - void add_max(float max) { fbb_.AddElement(FakeQuantOptions::VT_MAX, max, 0.0f); } - void add_num_bits(int32_t num_bits) - { - fbb_.AddElement(FakeQuantOptions::VT_NUM_BITS, num_bits, 0); - } - void add_narrow_range(bool narrow_range) - { - fbb_.AddElement(FakeQuantOptions::VT_NARROW_RANGE, static_cast(narrow_range), - 0); - } - explicit FakeQuantOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit ReverseV2OptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - FakeQuantOptionsBuilder &operator=(const FakeQuantOptionsBuilder &); - flatbuffers::Offset Finish() + ReverseV2OptionsBuilder &operator=(const ReverseV2OptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateFakeQuantOptions(flatbuffers::FlatBufferBuilder &_fbb, float min = 0.0f, float max = 0.0f, - int32_t num_bits = 0, bool narrow_range = false) +inline flatbuffers::Offset +CreateReverseV2Options(flatbuffers::FlatBufferBuilder &_fbb) { - FakeQuantOptionsBuilder builder_(_fbb); - builder_.add_num_bits(num_bits); - builder_.add_max(max); - builder_.add_min(min); - builder_.add_narrow_range(narrow_range); + ReverseV2OptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct PackOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct AddNOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum - { - VT_VALUES_COUNT = 4, - VT_AXIS = 6 - }; - int32_t values_count() const { return GetField(VT_VALUES_COUNT, 0); } - int32_t axis() const { return GetField(VT_AXIS, 0); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_VALUES_COUNT) && - VerifyField(verifier, VT_AXIS) && verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct PackOptionsBuilder +struct AddNOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_values_count(int32_t values_count) - { - fbb_.AddElement(PackOptions::VT_VALUES_COUNT, values_count, 0); - } - void add_axis(int32_t axis) { fbb_.AddElement(PackOptions::VT_AXIS, axis, 0); } - explicit PackOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit AddNOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - PackOptionsBuilder &operator=(const PackOptionsBuilder &); - flatbuffers::Offset Finish() + AddNOptionsBuilder &operator=(const AddNOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreatePackOptions(flatbuffers::FlatBufferBuilder &_fbb, int32_t values_count = 0, int32_t axis = 0) +inline flatbuffers::Offset CreateAddNOptions(flatbuffers::FlatBufferBuilder &_fbb) { - PackOptionsBuilder builder_(_fbb); - builder_.add_axis(axis); - builder_.add_values_count(values_count); + AddNOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct LogicalOrOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct GatherNdOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { bool Verify(flatbuffers::Verifier &verifier) const { @@ -5033,102 +6748,113 @@ struct LogicalOrOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table } }; -struct LogicalOrOptionsBuilder +struct GatherNdOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit LogicalOrOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit GatherNdOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - LogicalOrOptionsBuilder &operator=(const LogicalOrOptionsBuilder &); - flatbuffers::Offset Finish() + GatherNdOptionsBuilder &operator=(const GatherNdOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateLogicalOrOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateGatherNdOptions(flatbuffers::FlatBufferBuilder &_fbb) { - LogicalOrOptionsBuilder builder_(_fbb); + GatherNdOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct OneHotOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct WhereOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum - { - VT_AXIS = 4 - }; - int32_t axis() const { return GetField(VT_AXIS, 0); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_AXIS) && - verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct OneHotOptionsBuilder +struct WhereOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_axis(int32_t axis) { fbb_.AddElement(OneHotOptions::VT_AXIS, axis, 0); } - explicit OneHotOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit WhereOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - OneHotOptionsBuilder &operator=(const OneHotOptionsBuilder &); - flatbuffers::Offset Finish() + WhereOptionsBuilder &operator=(const WhereOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateOneHotOptions(flatbuffers::FlatBufferBuilder &_fbb, - int32_t axis = 0) +inline flatbuffers::Offset CreateWhereOptions(flatbuffers::FlatBufferBuilder &_fbb) { - OneHotOptionsBuilder builder_(_fbb); - builder_.add_axis(axis); + WhereOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct AbsOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct ReverseSequenceOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + enum + { + VT_SEQ_DIM = 4, + VT_BATCH_DIM = 6 + }; + int32_t seq_dim() const { return GetField(VT_SEQ_DIM, 0); } + int32_t batch_dim() const { return GetField(VT_BATCH_DIM, 0); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyField(verifier, VT_SEQ_DIM) && + VerifyField(verifier, VT_BATCH_DIM) && verifier.EndTable(); } }; -struct AbsOptionsBuilder +struct ReverseSequenceOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit AbsOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + void add_seq_dim(int32_t seq_dim) + { + fbb_.AddElement(ReverseSequenceOptions::VT_SEQ_DIM, seq_dim, 0); + } + void add_batch_dim(int32_t batch_dim) + { + fbb_.AddElement(ReverseSequenceOptions::VT_BATCH_DIM, batch_dim, 0); + } + explicit ReverseSequenceOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - AbsOptionsBuilder &operator=(const AbsOptionsBuilder &); - flatbuffers::Offset Finish() + ReverseSequenceOptionsBuilder &operator=(const ReverseSequenceOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateAbsOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateReverseSequenceOptions(flatbuffers::FlatBufferBuilder &_fbb, int32_t seq_dim = 0, + int32_t batch_dim = 0) { - AbsOptionsBuilder builder_(_fbb); + ReverseSequenceOptionsBuilder builder_(_fbb); + builder_.add_batch_dim(batch_dim); + builder_.add_seq_dim(seq_dim); return builder_.Finish(); } -struct LogicalAndOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct MatrixDiagOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { bool Verify(flatbuffers::Verifier &verifier) const { @@ -5136,31 +6862,31 @@ struct LogicalAndOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table } }; -struct LogicalAndOptionsBuilder +struct MatrixDiagOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit LogicalAndOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit MatrixDiagOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - LogicalAndOptionsBuilder &operator=(const LogicalAndOptionsBuilder &); - flatbuffers::Offset Finish() + MatrixDiagOptionsBuilder &operator=(const MatrixDiagOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateLogicalAndOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateMatrixDiagOptions(flatbuffers::FlatBufferBuilder &_fbb) { - LogicalAndOptionsBuilder builder_(_fbb); + MatrixDiagOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct LogicalNotOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct QuantizeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { bool Verify(flatbuffers::Verifier &verifier) const { @@ -5168,138 +6894,165 @@ struct LogicalNotOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table } }; -struct LogicalNotOptionsBuilder +struct QuantizeOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit LogicalNotOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit QuantizeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - LogicalNotOptionsBuilder &operator=(const LogicalNotOptionsBuilder &); - flatbuffers::Offset Finish() + QuantizeOptionsBuilder &operator=(const QuantizeOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateLogicalNotOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateQuantizeOptions(flatbuffers::FlatBufferBuilder &_fbb) { - LogicalNotOptionsBuilder builder_(_fbb); + QuantizeOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct UnpackOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct MatrixSetDiagOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum - { - VT_NUM = 4, - VT_AXIS = 6 - }; - int32_t num() const { return GetField(VT_NUM, 0); } - int32_t axis() const { return GetField(VT_AXIS, 0); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_NUM) && - VerifyField(verifier, VT_AXIS) && verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct UnpackOptionsBuilder +struct MatrixSetDiagOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_num(int32_t num) { fbb_.AddElement(UnpackOptions::VT_NUM, num, 0); } - void add_axis(int32_t axis) { fbb_.AddElement(UnpackOptions::VT_AXIS, axis, 0); } - explicit UnpackOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit MatrixSetDiagOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - UnpackOptionsBuilder &operator=(const UnpackOptionsBuilder &); - flatbuffers::Offset Finish() + MatrixSetDiagOptionsBuilder &operator=(const MatrixSetDiagOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateUnpackOptions(flatbuffers::FlatBufferBuilder &_fbb, - int32_t num = 0, int32_t axis = 0) +inline flatbuffers::Offset +CreateMatrixSetDiagOptions(flatbuffers::FlatBufferBuilder &_fbb) { - UnpackOptionsBuilder builder_(_fbb); - builder_.add_axis(axis); - builder_.add_num(num); + MatrixSetDiagOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct FloorDivOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct IfOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + enum + { + VT_THEN_SUBGRAPH_INDEX = 4, + VT_ELSE_SUBGRAPH_INDEX = 6 + }; + int32_t then_subgraph_index() const { return GetField(VT_THEN_SUBGRAPH_INDEX, 0); } + int32_t else_subgraph_index() const { return GetField(VT_ELSE_SUBGRAPH_INDEX, 0); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyField(verifier, VT_THEN_SUBGRAPH_INDEX) && + VerifyField(verifier, VT_ELSE_SUBGRAPH_INDEX) && verifier.EndTable(); } }; -struct FloorDivOptionsBuilder +struct IfOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit FloorDivOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + void add_then_subgraph_index(int32_t then_subgraph_index) + { + fbb_.AddElement(IfOptions::VT_THEN_SUBGRAPH_INDEX, then_subgraph_index, 0); + } + void add_else_subgraph_index(int32_t else_subgraph_index) + { + fbb_.AddElement(IfOptions::VT_ELSE_SUBGRAPH_INDEX, else_subgraph_index, 0); + } + explicit IfOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - FloorDivOptionsBuilder &operator=(const FloorDivOptionsBuilder &); - flatbuffers::Offset Finish() + IfOptionsBuilder &operator=(const IfOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateFloorDivOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset CreateIfOptions(flatbuffers::FlatBufferBuilder &_fbb, + int32_t then_subgraph_index = 0, + int32_t else_subgraph_index = 0) { - FloorDivOptionsBuilder builder_(_fbb); + IfOptionsBuilder builder_(_fbb); + builder_.add_else_subgraph_index(else_subgraph_index); + builder_.add_then_subgraph_index(then_subgraph_index); return builder_.Finish(); } -struct SquareOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct WhileOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + enum + { + VT_COND_SUBGRAPH_INDEX = 4, + VT_BODY_SUBGRAPH_INDEX = 6 + }; + int32_t cond_subgraph_index() const { return GetField(VT_COND_SUBGRAPH_INDEX, 0); } + int32_t body_subgraph_index() const { return GetField(VT_BODY_SUBGRAPH_INDEX, 0); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyField(verifier, VT_COND_SUBGRAPH_INDEX) && + VerifyField(verifier, VT_BODY_SUBGRAPH_INDEX) && verifier.EndTable(); } }; -struct SquareOptionsBuilder +struct WhileOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit SquareOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + void add_cond_subgraph_index(int32_t cond_subgraph_index) + { + fbb_.AddElement(WhileOptions::VT_COND_SUBGRAPH_INDEX, cond_subgraph_index, 0); + } + void add_body_subgraph_index(int32_t body_subgraph_index) + { + fbb_.AddElement(WhileOptions::VT_BODY_SUBGRAPH_INDEX, body_subgraph_index, 0); + } + explicit WhileOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - SquareOptionsBuilder &operator=(const SquareOptionsBuilder &); - flatbuffers::Offset Finish() + WhileOptionsBuilder &operator=(const WhileOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateSquareOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset CreateWhileOptions(flatbuffers::FlatBufferBuilder &_fbb, + int32_t cond_subgraph_index = 0, + int32_t body_subgraph_index = 0) { - SquareOptionsBuilder builder_(_fbb); + WhileOptionsBuilder builder_(_fbb); + builder_.add_body_subgraph_index(body_subgraph_index); + builder_.add_cond_subgraph_index(cond_subgraph_index); return builder_.Finish(); } -struct ZerosLikeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct NonMaxSuppressionV4Options FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { bool Verify(flatbuffers::Verifier &verifier) const { @@ -5307,31 +7060,31 @@ struct ZerosLikeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table } }; -struct ZerosLikeOptionsBuilder +struct NonMaxSuppressionV4OptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit ZerosLikeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit NonMaxSuppressionV4OptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - ZerosLikeOptionsBuilder &operator=(const ZerosLikeOptionsBuilder &); - flatbuffers::Offset Finish() + NonMaxSuppressionV4OptionsBuilder &operator=(const NonMaxSuppressionV4OptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateZerosLikeOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateNonMaxSuppressionV4Options(flatbuffers::FlatBufferBuilder &_fbb) { - ZerosLikeOptionsBuilder builder_(_fbb); + NonMaxSuppressionV4OptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct FillOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct NonMaxSuppressionV5Options FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { bool Verify(flatbuffers::Verifier &verifier) const { @@ -5339,30 +7092,31 @@ struct FillOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table } }; -struct FillOptionsBuilder +struct NonMaxSuppressionV5OptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit FillOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit NonMaxSuppressionV5OptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - FillOptionsBuilder &operator=(const FillOptionsBuilder &); - flatbuffers::Offset Finish() + NonMaxSuppressionV5OptionsBuilder &operator=(const NonMaxSuppressionV5OptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateFillOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateNonMaxSuppressionV5Options(flatbuffers::FlatBufferBuilder &_fbb) { - FillOptionsBuilder builder_(_fbb); + NonMaxSuppressionV5OptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct FloorModOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct ScatterNdOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { bool Verify(flatbuffers::Verifier &verifier) const { @@ -5370,31 +7124,31 @@ struct FloorModOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table } }; -struct FloorModOptionsBuilder +struct ScatterNdOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit FloorModOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit ScatterNdOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - FloorModOptionsBuilder &operator=(const FloorModOptionsBuilder &); - flatbuffers::Offset Finish() + ScatterNdOptionsBuilder &operator=(const ScatterNdOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateFloorModOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateScatterNdOptions(flatbuffers::FlatBufferBuilder &_fbb) { - FloorModOptionsBuilder builder_(_fbb); + ScatterNdOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct RangeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct SelectV2Options FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { bool Verify(flatbuffers::Verifier &verifier) const { @@ -5402,70 +7156,63 @@ struct RangeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table } }; -struct RangeOptionsBuilder +struct SelectV2OptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit RangeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit SelectV2OptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - RangeOptionsBuilder &operator=(const RangeOptionsBuilder &); - flatbuffers::Offset Finish() + SelectV2OptionsBuilder &operator=(const SelectV2OptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateRangeOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateSelectV2Options(flatbuffers::FlatBufferBuilder &_fbb) { - RangeOptionsBuilder builder_(_fbb); + SelectV2OptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct LeakyReluOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct DensifyOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum - { - VT_ALPHA = 4 - }; - float alpha() const { return GetField(VT_ALPHA, 0.0f); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_ALPHA) && - verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct LeakyReluOptionsBuilder +struct DensifyOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_alpha(float alpha) { fbb_.AddElement(LeakyReluOptions::VT_ALPHA, alpha, 0.0f); } - explicit LeakyReluOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit DensifyOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - LeakyReluOptionsBuilder &operator=(const LeakyReluOptionsBuilder &); - flatbuffers::Offset Finish() + DensifyOptionsBuilder &operator=(const DensifyOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateLeakyReluOptions(flatbuffers::FlatBufferBuilder &_fbb, float alpha = 0.0f) +inline flatbuffers::Offset +CreateDensifyOptions(flatbuffers::FlatBufferBuilder &_fbb) { - LeakyReluOptionsBuilder builder_(_fbb); - builder_.add_alpha(alpha); + DensifyOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct SquaredDifferenceOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct SegmentSumOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { bool Verify(flatbuffers::Verifier &verifier) const { @@ -5473,71 +7220,80 @@ struct SquaredDifferenceOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::T } }; -struct SquaredDifferenceOptionsBuilder +struct SegmentSumOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit SquaredDifferenceOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit SegmentSumOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - SquaredDifferenceOptionsBuilder &operator=(const SquaredDifferenceOptionsBuilder &); - flatbuffers::Offset Finish() + SegmentSumOptionsBuilder &operator=(const SegmentSumOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateSquaredDifferenceOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateSegmentSumOptions(flatbuffers::FlatBufferBuilder &_fbb) { - SquaredDifferenceOptionsBuilder builder_(_fbb); + SegmentSumOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct MirrorPadOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct BatchMatMulOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_MODE = 4 + VT_ADJOINT_LHS = 4, + VT_ADJOINT_RHS = 6 }; - MirrorPadMode mode() const { return static_cast(GetField(VT_MODE, 0)); } + bool adjoint_lhs() const { return GetField(VT_ADJOINT_LHS, 0) != 0; } + bool adjoint_rhs() const { return GetField(VT_ADJOINT_RHS, 0) != 0; } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_MODE) && - verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyField(verifier, VT_ADJOINT_LHS) && + VerifyField(verifier, VT_ADJOINT_RHS) && verifier.EndTable(); } }; -struct MirrorPadOptionsBuilder +struct BatchMatMulOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_mode(MirrorPadMode mode) + void add_adjoint_lhs(bool adjoint_lhs) { - fbb_.AddElement(MirrorPadOptions::VT_MODE, static_cast(mode), 0); + fbb_.AddElement(BatchMatMulOptions::VT_ADJOINT_LHS, static_cast(adjoint_lhs), + 0); } - explicit MirrorPadOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + void add_adjoint_rhs(bool adjoint_rhs) + { + fbb_.AddElement(BatchMatMulOptions::VT_ADJOINT_RHS, static_cast(adjoint_rhs), + 0); + } + explicit BatchMatMulOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - MirrorPadOptionsBuilder &operator=(const MirrorPadOptionsBuilder &); - flatbuffers::Offset Finish() + BatchMatMulOptionsBuilder &operator=(const BatchMatMulOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateMirrorPadOptions(flatbuffers::FlatBufferBuilder &_fbb, - MirrorPadMode mode = MirrorPadMode_REFLECT) +inline flatbuffers::Offset +CreateBatchMatMulOptions(flatbuffers::FlatBufferBuilder &_fbb, bool adjoint_lhs = false, + bool adjoint_rhs = false) { - MirrorPadOptionsBuilder builder_(_fbb); - builder_.add_mode(mode); + BatchMatMulOptionsBuilder builder_(_fbb); + builder_.add_adjoint_rhs(adjoint_rhs); + builder_.add_adjoint_lhs(adjoint_lhs); return builder_.Finish(); } @@ -5682,7 +7438,8 @@ struct Operator FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table VT_BUILTIN_OPTIONS = 12, VT_CUSTOM_OPTIONS = 14, VT_CUSTOM_OPTIONS_FORMAT = 16, - VT_MUTATING_VARIABLE_INPUTS = 18 + VT_MUTATING_VARIABLE_INPUTS = 18, + VT_INTERMEDIATES = 20 }; uint32_t opcode_index() const { return GetField(VT_OPCODE_INDEX, 0); } const flatbuffers::Vector *inputs() const @@ -6117,69 +7874,201 @@ struct Operator FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table } const BidirectionalSequenceRNNOptions *builtin_options_as_BidirectionalSequenceRNNOptions() const { - return builtin_options_type() == BuiltinOptions_BidirectionalSequenceRNNOptions - ? static_cast(builtin_options()) + return builtin_options_type() == BuiltinOptions_BidirectionalSequenceRNNOptions + ? static_cast(builtin_options()) + : nullptr; + } + const UnidirectionalSequenceLSTMOptions * + builtin_options_as_UnidirectionalSequenceLSTMOptions() const + { + return builtin_options_type() == BuiltinOptions_UnidirectionalSequenceLSTMOptions + ? static_cast(builtin_options()) + : nullptr; + } + const FloorModOptions *builtin_options_as_FloorModOptions() const + { + return builtin_options_type() == BuiltinOptions_FloorModOptions + ? static_cast(builtin_options()) + : nullptr; + } + const RangeOptions *builtin_options_as_RangeOptions() const + { + return builtin_options_type() == BuiltinOptions_RangeOptions + ? static_cast(builtin_options()) + : nullptr; + } + const ResizeNearestNeighborOptions *builtin_options_as_ResizeNearestNeighborOptions() const + { + return builtin_options_type() == BuiltinOptions_ResizeNearestNeighborOptions + ? static_cast(builtin_options()) + : nullptr; + } + const LeakyReluOptions *builtin_options_as_LeakyReluOptions() const + { + return builtin_options_type() == BuiltinOptions_LeakyReluOptions + ? static_cast(builtin_options()) + : nullptr; + } + const SquaredDifferenceOptions *builtin_options_as_SquaredDifferenceOptions() const + { + return builtin_options_type() == BuiltinOptions_SquaredDifferenceOptions + ? static_cast(builtin_options()) + : nullptr; + } + const MirrorPadOptions *builtin_options_as_MirrorPadOptions() const + { + return builtin_options_type() == BuiltinOptions_MirrorPadOptions + ? static_cast(builtin_options()) + : nullptr; + } + const AbsOptions *builtin_options_as_AbsOptions() const + { + return builtin_options_type() == BuiltinOptions_AbsOptions + ? static_cast(builtin_options()) + : nullptr; + } + const SplitVOptions *builtin_options_as_SplitVOptions() const + { + return builtin_options_type() == BuiltinOptions_SplitVOptions + ? static_cast(builtin_options()) + : nullptr; + } + const InstanceNormOptions *builtin_options_as_InstanceNormOptions() const + { + return builtin_options_type() == BuiltinOptions_InstanceNormOptions + ? static_cast(builtin_options()) + : nullptr; + } + const UniqueOptions *builtin_options_as_UniqueOptions() const + { + return builtin_options_type() == BuiltinOptions_UniqueOptions + ? static_cast(builtin_options()) + : nullptr; + } + const ReverseV2Options *builtin_options_as_ReverseV2Options() const + { + return builtin_options_type() == BuiltinOptions_ReverseV2Options + ? static_cast(builtin_options()) + : nullptr; + } + const AddNOptions *builtin_options_as_AddNOptions() const + { + return builtin_options_type() == BuiltinOptions_AddNOptions + ? static_cast(builtin_options()) + : nullptr; + } + const GatherNdOptions *builtin_options_as_GatherNdOptions() const + { + return builtin_options_type() == BuiltinOptions_GatherNdOptions + ? static_cast(builtin_options()) + : nullptr; + } + const CosOptions *builtin_options_as_CosOptions() const + { + return builtin_options_type() == BuiltinOptions_CosOptions + ? static_cast(builtin_options()) + : nullptr; + } + const WhereOptions *builtin_options_as_WhereOptions() const + { + return builtin_options_type() == BuiltinOptions_WhereOptions + ? static_cast(builtin_options()) + : nullptr; + } + const RankOptions *builtin_options_as_RankOptions() const + { + return builtin_options_type() == BuiltinOptions_RankOptions + ? static_cast(builtin_options()) + : nullptr; + } + const ReverseSequenceOptions *builtin_options_as_ReverseSequenceOptions() const + { + return builtin_options_type() == BuiltinOptions_ReverseSequenceOptions + ? static_cast(builtin_options()) + : nullptr; + } + const MatrixDiagOptions *builtin_options_as_MatrixDiagOptions() const + { + return builtin_options_type() == BuiltinOptions_MatrixDiagOptions + ? static_cast(builtin_options()) + : nullptr; + } + const QuantizeOptions *builtin_options_as_QuantizeOptions() const + { + return builtin_options_type() == BuiltinOptions_QuantizeOptions + ? static_cast(builtin_options()) + : nullptr; + } + const MatrixSetDiagOptions *builtin_options_as_MatrixSetDiagOptions() const + { + return builtin_options_type() == BuiltinOptions_MatrixSetDiagOptions + ? static_cast(builtin_options()) + : nullptr; + } + const HardSwishOptions *builtin_options_as_HardSwishOptions() const + { + return builtin_options_type() == BuiltinOptions_HardSwishOptions + ? static_cast(builtin_options()) : nullptr; } - const UnidirectionalSequenceLSTMOptions * - builtin_options_as_UnidirectionalSequenceLSTMOptions() const + const IfOptions *builtin_options_as_IfOptions() const { - return builtin_options_type() == BuiltinOptions_UnidirectionalSequenceLSTMOptions - ? static_cast(builtin_options()) + return builtin_options_type() == BuiltinOptions_IfOptions + ? static_cast(builtin_options()) : nullptr; } - const FloorModOptions *builtin_options_as_FloorModOptions() const + const WhileOptions *builtin_options_as_WhileOptions() const { - return builtin_options_type() == BuiltinOptions_FloorModOptions - ? static_cast(builtin_options()) + return builtin_options_type() == BuiltinOptions_WhileOptions + ? static_cast(builtin_options()) : nullptr; } - const RangeOptions *builtin_options_as_RangeOptions() const + const DepthToSpaceOptions *builtin_options_as_DepthToSpaceOptions() const { - return builtin_options_type() == BuiltinOptions_RangeOptions - ? static_cast(builtin_options()) + return builtin_options_type() == BuiltinOptions_DepthToSpaceOptions + ? static_cast(builtin_options()) : nullptr; } - const ResizeNearestNeighborOptions *builtin_options_as_ResizeNearestNeighborOptions() const + const NonMaxSuppressionV4Options *builtin_options_as_NonMaxSuppressionV4Options() const { - return builtin_options_type() == BuiltinOptions_ResizeNearestNeighborOptions - ? static_cast(builtin_options()) + return builtin_options_type() == BuiltinOptions_NonMaxSuppressionV4Options + ? static_cast(builtin_options()) : nullptr; } - const LeakyReluOptions *builtin_options_as_LeakyReluOptions() const + const NonMaxSuppressionV5Options *builtin_options_as_NonMaxSuppressionV5Options() const { - return builtin_options_type() == BuiltinOptions_LeakyReluOptions - ? static_cast(builtin_options()) + return builtin_options_type() == BuiltinOptions_NonMaxSuppressionV5Options + ? static_cast(builtin_options()) : nullptr; } - const SquaredDifferenceOptions *builtin_options_as_SquaredDifferenceOptions() const + const ScatterNdOptions *builtin_options_as_ScatterNdOptions() const { - return builtin_options_type() == BuiltinOptions_SquaredDifferenceOptions - ? static_cast(builtin_options()) + return builtin_options_type() == BuiltinOptions_ScatterNdOptions + ? static_cast(builtin_options()) : nullptr; } - const MirrorPadOptions *builtin_options_as_MirrorPadOptions() const + const SelectV2Options *builtin_options_as_SelectV2Options() const { - return builtin_options_type() == BuiltinOptions_MirrorPadOptions - ? static_cast(builtin_options()) + return builtin_options_type() == BuiltinOptions_SelectV2Options + ? static_cast(builtin_options()) : nullptr; } - const AbsOptions *builtin_options_as_AbsOptions() const + const DensifyOptions *builtin_options_as_DensifyOptions() const { - return builtin_options_type() == BuiltinOptions_AbsOptions - ? static_cast(builtin_options()) + return builtin_options_type() == BuiltinOptions_DensifyOptions + ? static_cast(builtin_options()) : nullptr; } - const SplitVOptions *builtin_options_as_SplitVOptions() const + const SegmentSumOptions *builtin_options_as_SegmentSumOptions() const { - return builtin_options_type() == BuiltinOptions_SplitVOptions - ? static_cast(builtin_options()) + return builtin_options_type() == BuiltinOptions_SegmentSumOptions + ? static_cast(builtin_options()) : nullptr; } - const InstanceNormOptions *builtin_options_as_InstanceNormOptions() const + const BatchMatMulOptions *builtin_options_as_BatchMatMulOptions() const { - return builtin_options_type() == BuiltinOptions_InstanceNormOptions - ? static_cast(builtin_options()) + return builtin_options_type() == BuiltinOptions_BatchMatMulOptions + ? static_cast(builtin_options()) : nullptr; } const flatbuffers::Vector *custom_options() const @@ -6194,6 +8083,10 @@ struct Operator FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { return GetPointer *>(VT_MUTATING_VARIABLE_INPUTS); } + const flatbuffers::Vector *intermediates() const + { + return GetPointer *>(VT_INTERMEDIATES); + } bool Verify(flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && VerifyField(verifier, VT_OPCODE_INDEX) && @@ -6205,7 +8098,9 @@ struct Operator FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table VerifyOffset(verifier, VT_CUSTOM_OPTIONS) && verifier.VerifyVector(custom_options()) && VerifyField(verifier, VT_CUSTOM_OPTIONS_FORMAT) && VerifyOffset(verifier, VT_MUTATING_VARIABLE_INPUTS) && - verifier.VerifyVector(mutating_variable_inputs()) && verifier.EndTable(); + verifier.VerifyVector(mutating_variable_inputs()) && + VerifyOffset(verifier, VT_INTERMEDIATES) && verifier.VerifyVector(intermediates()) && + verifier.EndTable(); } }; @@ -6639,6 +8534,124 @@ inline const InstanceNormOptions *Operator::builtin_options_as inline const UniqueOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_UniqueOptions(); +} + +template <> inline const ReverseV2Options *Operator::builtin_options_as() const +{ + return builtin_options_as_ReverseV2Options(); +} + +template <> inline const AddNOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_AddNOptions(); +} + +template <> inline const GatherNdOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_GatherNdOptions(); +} + +template <> inline const CosOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_CosOptions(); +} + +template <> inline const WhereOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_WhereOptions(); +} + +template <> inline const RankOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_RankOptions(); +} + +template <> +inline const ReverseSequenceOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_ReverseSequenceOptions(); +} + +template <> inline const MatrixDiagOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_MatrixDiagOptions(); +} + +template <> inline const QuantizeOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_QuantizeOptions(); +} + +template <> +inline const MatrixSetDiagOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_MatrixSetDiagOptions(); +} + +template <> inline const HardSwishOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_HardSwishOptions(); +} + +template <> inline const IfOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_IfOptions(); +} + +template <> inline const WhileOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_WhileOptions(); +} + +template <> +inline const DepthToSpaceOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_DepthToSpaceOptions(); +} + +template <> +inline const NonMaxSuppressionV4Options * +Operator::builtin_options_as() const +{ + return builtin_options_as_NonMaxSuppressionV4Options(); +} + +template <> +inline const NonMaxSuppressionV5Options * +Operator::builtin_options_as() const +{ + return builtin_options_as_NonMaxSuppressionV5Options(); +} + +template <> inline const ScatterNdOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_ScatterNdOptions(); +} + +template <> inline const SelectV2Options *Operator::builtin_options_as() const +{ + return builtin_options_as_SelectV2Options(); +} + +template <> inline const DensifyOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_DensifyOptions(); +} + +template <> inline const SegmentSumOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_SegmentSumOptions(); +} + +template <> +inline const BatchMatMulOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_BatchMatMulOptions(); +} + struct OperatorBuilder { flatbuffers::FlatBufferBuilder &fbb_; @@ -6678,6 +8691,10 @@ struct OperatorBuilder { fbb_.AddOffset(Operator::VT_MUTATING_VARIABLE_INPUTS, mutating_variable_inputs); } + void add_intermediates(flatbuffers::Offset> intermediates) + { + fbb_.AddOffset(Operator::VT_INTERMEDIATES, intermediates); + } explicit OperatorBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); @@ -6699,9 +8716,11 @@ CreateOperator(flatbuffers::FlatBufferBuilder &_fbb, uint32_t opcode_index = 0, flatbuffers::Offset builtin_options = 0, flatbuffers::Offset> custom_options = 0, CustomOptionsFormat custom_options_format = CustomOptionsFormat_FLEXBUFFERS, - flatbuffers::Offset> mutating_variable_inputs = 0) + flatbuffers::Offset> mutating_variable_inputs = 0, + flatbuffers::Offset> intermediates = 0) { OperatorBuilder builder_(_fbb); + builder_.add_intermediates(intermediates); builder_.add_mutating_variable_inputs(mutating_variable_inputs); builder_.add_custom_options(custom_options); builder_.add_builtin_options(builtin_options); @@ -6721,13 +8740,15 @@ CreateOperatorDirect(flatbuffers::FlatBufferBuilder &_fbb, uint32_t opcode_index flatbuffers::Offset builtin_options = 0, const std::vector *custom_options = nullptr, CustomOptionsFormat custom_options_format = CustomOptionsFormat_FLEXBUFFERS, - const std::vector *mutating_variable_inputs = nullptr) + const std::vector *mutating_variable_inputs = nullptr, + const std::vector *intermediates = nullptr) { return circle::CreateOperator( _fbb, opcode_index, inputs ? _fbb.CreateVector(*inputs) : 0, outputs ? _fbb.CreateVector(*outputs) : 0, builtin_options_type, builtin_options, custom_options ? _fbb.CreateVector(*custom_options) : 0, custom_options_format, - mutating_variable_inputs ? _fbb.CreateVector(*mutating_variable_inputs) : 0); + mutating_variable_inputs ? _fbb.CreateVector(*mutating_variable_inputs) : 0, + intermediates ? _fbb.CreateVector(*intermediates) : 0); } struct SubGraph FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table @@ -6908,6 +8929,65 @@ inline flatbuffers::Offset CreateBufferDirect(flatbuffers::FlatBufferBui return circle::CreateBuffer(_fbb, data ? _fbb.CreateVector(*data) : 0); } +struct Metadata FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_NAME = 4, + VT_BUFFER = 6 + }; + const flatbuffers::String *name() const + { + return GetPointer(VT_NAME); + } + uint32_t buffer() const { return GetField(VT_BUFFER, 0); } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && VerifyOffset(verifier, VT_NAME) && + verifier.VerifyString(name()) && VerifyField(verifier, VT_BUFFER) && + verifier.EndTable(); + } +}; + +struct MetadataBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_name(flatbuffers::Offset name) + { + fbb_.AddOffset(Metadata::VT_NAME, name); + } + void add_buffer(uint32_t buffer) { fbb_.AddElement(Metadata::VT_BUFFER, buffer, 0); } + explicit MetadataBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + MetadataBuilder &operator=(const MetadataBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset +CreateMetadata(flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset name = 0, uint32_t buffer = 0) +{ + MetadataBuilder builder_(_fbb); + builder_.add_buffer(buffer); + builder_.add_name(name); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreateMetadataDirect(flatbuffers::FlatBufferBuilder &_fbb, + const char *name = nullptr, + uint32_t buffer = 0) +{ + return circle::CreateMetadata(_fbb, name ? _fbb.CreateString(name) : 0, buffer); +} + struct Model FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum @@ -6917,7 +8997,8 @@ struct Model FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table VT_SUBGRAPHS = 8, VT_DESCRIPTION = 10, VT_BUFFERS = 12, - VT_METADATA_BUFFER = 14 + VT_METADATA_BUFFER = 14, + VT_METADATA = 16 }; uint32_t version() const { return GetField(VT_VERSION, 0); } const flatbuffers::Vector> *operator_codes() const @@ -6941,6 +9022,10 @@ struct Model FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { return GetPointer *>(VT_METADATA_BUFFER); } + const flatbuffers::Vector> *metadata() const + { + return GetPointer> *>(VT_METADATA); + } bool Verify(flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && VerifyField(verifier, VT_VERSION) && @@ -6951,7 +9036,8 @@ struct Model FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table verifier.VerifyString(description()) && VerifyOffset(verifier, VT_BUFFERS) && verifier.VerifyVector(buffers()) && verifier.VerifyVectorOfTables(buffers()) && VerifyOffset(verifier, VT_METADATA_BUFFER) && verifier.VerifyVector(metadata_buffer()) && - verifier.EndTable(); + VerifyOffset(verifier, VT_METADATA) && verifier.VerifyVector(metadata()) && + verifier.VerifyVectorOfTables(metadata()) && verifier.EndTable(); } }; @@ -6982,6 +9068,11 @@ struct ModelBuilder { fbb_.AddOffset(Model::VT_METADATA_BUFFER, metadata_buffer); } + void + add_metadata(flatbuffers::Offset>> metadata) + { + fbb_.AddOffset(Model::VT_METADATA, metadata); + } explicit ModelBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); @@ -7001,9 +9092,11 @@ inline flatbuffers::Offset CreateModel( flatbuffers::Offset>> subgraphs = 0, flatbuffers::Offset description = 0, flatbuffers::Offset>> buffers = 0, - flatbuffers::Offset> metadata_buffer = 0) + flatbuffers::Offset> metadata_buffer = 0, + flatbuffers::Offset>> metadata = 0) { ModelBuilder builder_(_fbb); + builder_.add_metadata(metadata); builder_.add_metadata_buffer(metadata_buffer); builder_.add_buffers(buffers); builder_.add_description(description); @@ -7019,7 +9112,8 @@ CreateModelDirect(flatbuffers::FlatBufferBuilder &_fbb, uint32_t version = 0, const std::vector> *subgraphs = nullptr, const char *description = nullptr, const std::vector> *buffers = nullptr, - const std::vector *metadata_buffer = nullptr) + const std::vector *metadata_buffer = nullptr, + const std::vector> *metadata = nullptr) { return circle::CreateModel( _fbb, version, @@ -7027,7 +9121,8 @@ CreateModelDirect(flatbuffers::FlatBufferBuilder &_fbb, uint32_t version = 0, subgraphs ? _fbb.CreateVector>(*subgraphs) : 0, description ? _fbb.CreateString(description) : 0, buffers ? _fbb.CreateVector>(*buffers) : 0, - metadata_buffer ? _fbb.CreateVector(*metadata_buffer) : 0); + metadata_buffer ? _fbb.CreateVector(*metadata_buffer) : 0, + metadata ? _fbb.CreateVector>(*metadata) : 0); } inline bool VerifyQuantizationDetails(flatbuffers::Verifier &verifier, const void *obj, @@ -7069,6 +9164,54 @@ VerifyQuantizationDetailsVector(flatbuffers::Verifier &verifier, return true; } +inline bool VerifySparseIndexVector(flatbuffers::Verifier &verifier, const void *obj, + SparseIndexVector type) +{ + switch (type) + { + case SparseIndexVector_NONE: + { + return true; + } + case SparseIndexVector_Int32Vector: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case SparseIndexVector_Uint16Vector: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case SparseIndexVector_Uint8Vector: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + default: + return false; + } +} + +inline bool +VerifySparseIndexVectorVector(flatbuffers::Verifier &verifier, + const flatbuffers::Vector> *values, + const flatbuffers::Vector *types) +{ + if (!values || !types) + return !values && !types; + if (values->size() != types->size()) + return false; + for (flatbuffers::uoffset_t i = 0; i < values->size(); ++i) + { + if (!VerifySparseIndexVector(verifier, values->Get(i), types->GetEnum(i))) + { + return false; + } + } + return true; +} + inline bool VerifyBuiltinOptions(flatbuffers::Verifier &verifier, const void *obj, BuiltinOptions type) { @@ -7478,6 +9621,116 @@ inline bool VerifyBuiltinOptions(flatbuffers::Verifier &verifier, const void *ob auto ptr = reinterpret_cast(obj); return verifier.VerifyTable(ptr); } + case BuiltinOptions_UniqueOptions: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_ReverseV2Options: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_AddNOptions: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_GatherNdOptions: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_CosOptions: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_WhereOptions: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_RankOptions: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_ReverseSequenceOptions: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_MatrixDiagOptions: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_QuantizeOptions: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_MatrixSetDiagOptions: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_HardSwishOptions: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_IfOptions: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_WhileOptions: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_DepthToSpaceOptions: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_NonMaxSuppressionV4Options: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_NonMaxSuppressionV5Options: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_ScatterNdOptions: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_SelectV2Options: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_DensifyOptions: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_SegmentSumOptions: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_BatchMatMulOptions: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } default: return false; } diff --git a/runtime/neurun/frontend/nnapi/ANeuralNetworksModel.test.cc b/runtime/onert/frontend/nnapi/ANeuralNetworksModel.test.cc similarity index 100% rename from runtime/neurun/frontend/nnapi/ANeuralNetworksModel.test.cc rename to runtime/onert/frontend/nnapi/ANeuralNetworksModel.test.cc diff --git a/runtime/onert/frontend/nnapi/CMakeLists.txt b/runtime/onert/frontend/nnapi/CMakeLists.txt new file mode 100644 index 00000000000..b66b32e8914 --- /dev/null +++ b/runtime/onert/frontend/nnapi/CMakeLists.txt @@ -0,0 +1,27 @@ +file(GLOB_RECURSE SOURCES_FRONTEND "*.cc") +file(GLOB_RECURSE TESTS_FRONTEND "*.test.cc") +list(REMOVE_ITEM SOURCES_FRONTEND ${TESTS_FRONTEND}) + +set(LIB_ONERT onert) + +add_library(${LIB_ONERT} SHARED ${SOURCES_FRONTEND}) +target_link_libraries(${LIB_ONERT} PUBLIC nnfw-nnapi-header) +target_link_libraries(${LIB_ONERT} PUBLIC onert_core) # TODO Link PRIVATE onert_core +target_link_libraries(${LIB_ONERT} PRIVATE nnfw_common) +target_link_libraries(${LIB_ONERT} PRIVATE nnfw_coverage) + +set_target_properties(${LIB_ONERT} PROPERTIES OUTPUT_NAME neuralnetworks) + +install(TARGETS ${LIB_ONERT} DESTINATION lib) + +if(NOT ENABLE_TEST) + return() +endif(NOT ENABLE_TEST) + +add_executable(test_onert_frontend_nnapi ${TESTS_FRONTEND}) + +target_link_libraries(test_onert_frontend_nnapi PRIVATE ${LIB_ONERT} dl) +target_link_libraries(test_onert_frontend_nnapi PRIVATE gtest) +target_link_libraries(test_onert_frontend_nnapi PRIVATE gtest_main) + +install(TARGETS test_onert_frontend_nnapi DESTINATION unittest) diff --git a/runtime/neurun/frontend/nnapi/compilation.cc b/runtime/onert/frontend/nnapi/compilation.cc similarity index 94% rename from runtime/neurun/frontend/nnapi/compilation.cc rename to runtime/onert/frontend/nnapi/compilation.cc index 164158f19ad..0823cb4561e 100644 --- a/runtime/neurun/frontend/nnapi/compilation.cc +++ b/runtime/onert/frontend/nnapi/compilation.cc @@ -40,7 +40,7 @@ int ANeuralNetworksCompilation_create(ANeuralNetworksModel *model, return ANEURALNETWORKS_BAD_STATE; } - std::shared_ptr internal; + std::shared_ptr internal; model->release(internal); @@ -62,7 +62,7 @@ int ANeuralNetworksCompilation_finish(ANeuralNetworksCompilation *compilation) return ANEURALNETWORKS_UNEXPECTED_NULL; } - if (compilation->state() != ::neurun::compiler::State::CREATED) + if (compilation->state() != ::onert::compiler::State::CREATED) { VERBOSE(NNAPI::Compilation) << "finish: Already finished" << std::endl; return ANEURALNETWORKS_BAD_STATE; @@ -91,7 +91,7 @@ int ANeuralNetworksCompilation_setPreference(ANeuralNetworksCompilation *compila return ANEURALNETWORKS_UNEXPECTED_NULL; } - if (compilation->state() != ::neurun::compiler::State::CREATED) + if (compilation->state() != ::onert::compiler::State::CREATED) { VERBOSE(NNAPI::Compilation) << "setPreference: Already finished" << std::endl; return ANEURALNETWORKS_BAD_STATE; diff --git a/runtime/neurun/frontend/nnapi/event.cc b/runtime/onert/frontend/nnapi/event.cc similarity index 100% rename from runtime/neurun/frontend/nnapi/event.cc rename to runtime/onert/frontend/nnapi/event.cc diff --git a/runtime/neurun/frontend/nnapi/execution.cc b/runtime/onert/frontend/nnapi/execution.cc similarity index 99% rename from runtime/neurun/frontend/nnapi/execution.cc rename to runtime/onert/frontend/nnapi/execution.cc index 08f2df4c228..6aaca1b4c34 100644 --- a/runtime/neurun/frontend/nnapi/execution.cc +++ b/runtime/onert/frontend/nnapi/execution.cc @@ -37,7 +37,7 @@ int ANeuralNetworksExecution_create(ANeuralNetworksCompilation *compilation, return ANEURALNETWORKS_UNEXPECTED_NULL; } - std::shared_ptr executor; + std::shared_ptr executor; compilation->publish(executor); diff --git a/runtime/neurun/frontend/nnapi/memory.cc b/runtime/onert/frontend/nnapi/memory.cc similarity index 98% rename from runtime/neurun/frontend/nnapi/memory.cc rename to runtime/onert/frontend/nnapi/memory.cc index 8f255e18327..6e568a926d3 100644 --- a/runtime/neurun/frontend/nnapi/memory.cc +++ b/runtime/onert/frontend/nnapi/memory.cc @@ -19,7 +19,7 @@ #include #include -#include "memory" +#include #include "wrapper/ANeuralNetworksMemory.h" int ANeuralNetworksMemory_createFromFd(size_t size, int protect, int fd, size_t offset, diff --git a/runtime/neurun/frontend/nnapi/model.cc b/runtime/onert/frontend/nnapi/model.cc similarity index 100% rename from runtime/neurun/frontend/nnapi/model.cc rename to runtime/onert/frontend/nnapi/model.cc diff --git a/runtime/neurun/frontend/nnapi/wrapper/ANeuralNetworksCompilation.cc b/runtime/onert/frontend/nnapi/wrapper/ANeuralNetworksCompilation.cc similarity index 89% rename from runtime/neurun/frontend/nnapi/wrapper/ANeuralNetworksCompilation.cc rename to runtime/onert/frontend/nnapi/wrapper/ANeuralNetworksCompilation.cc index 1aa1583aaf9..03518a88a38 100644 --- a/runtime/neurun/frontend/nnapi/wrapper/ANeuralNetworksCompilation.cc +++ b/runtime/onert/frontend/nnapi/wrapper/ANeuralNetworksCompilation.cc @@ -19,8 +19,8 @@ #include "util/logging.h" ANeuralNetworksCompilation::ANeuralNetworksCompilation( - const std::shared_ptr &model) noexcept - : _compiler{new neurun::compiler::Compiler{model}} + const std::shared_ptr &model) noexcept + : _compiler{new onert::compiler::Compiler{model}} { // DO NOTHING } diff --git a/runtime/neurun/frontend/nnapi/wrapper/ANeuralNetworksCompilation.h b/runtime/onert/frontend/nnapi/wrapper/ANeuralNetworksCompilation.h similarity index 75% rename from runtime/neurun/frontend/nnapi/wrapper/ANeuralNetworksCompilation.h rename to runtime/onert/frontend/nnapi/wrapper/ANeuralNetworksCompilation.h index 56b402d16b5..8d72441b292 100644 --- a/runtime/neurun/frontend/nnapi/wrapper/ANeuralNetworksCompilation.h +++ b/runtime/onert/frontend/nnapi/wrapper/ANeuralNetworksCompilation.h @@ -24,19 +24,19 @@ struct ANeuralNetworksCompilation { public: - ANeuralNetworksCompilation(const std::shared_ptr &graph) noexcept; + ANeuralNetworksCompilation(const std::shared_ptr &graph) noexcept; public: bool finish() noexcept; - neurun::compiler::State state(void) noexcept { return _compiler->state(); } - void publish(std::shared_ptr &executor) noexcept + onert::compiler::State state(void) noexcept { return _compiler->state(); } + void publish(std::shared_ptr &executor) noexcept { _compiler->release(executor); } private: - std::shared_ptr _compiler; + std::shared_ptr _compiler; }; #endif diff --git a/runtime/neurun/frontend/nnapi/wrapper/ANeuralNetworksEvent.cc b/runtime/onert/frontend/nnapi/wrapper/ANeuralNetworksEvent.cc similarity index 90% rename from runtime/neurun/frontend/nnapi/wrapper/ANeuralNetworksEvent.cc rename to runtime/onert/frontend/nnapi/wrapper/ANeuralNetworksEvent.cc index b09f9abe699..2bea729be33 100644 --- a/runtime/neurun/frontend/nnapi/wrapper/ANeuralNetworksEvent.cc +++ b/runtime/onert/frontend/nnapi/wrapper/ANeuralNetworksEvent.cc @@ -19,8 +19,7 @@ #include "exec/Execution.h" #include "util/logging.h" -ANeuralNetworksEvent::ANeuralNetworksEvent( - const std::shared_ptr &execution) +ANeuralNetworksEvent::ANeuralNetworksEvent(const std::shared_ptr &execution) : _execution{execution} { // DO NOTHING diff --git a/runtime/neurun/frontend/nnapi/wrapper/ANeuralNetworksEvent.h b/runtime/onert/frontend/nnapi/wrapper/ANeuralNetworksEvent.h similarity index 82% rename from runtime/neurun/frontend/nnapi/wrapper/ANeuralNetworksEvent.h rename to runtime/onert/frontend/nnapi/wrapper/ANeuralNetworksEvent.h index e499bab775f..7b462d3d604 100644 --- a/runtime/neurun/frontend/nnapi/wrapper/ANeuralNetworksEvent.h +++ b/runtime/onert/frontend/nnapi/wrapper/ANeuralNetworksEvent.h @@ -21,24 +21,24 @@ #include -namespace neurun +namespace onert { namespace exec { class Execution; } // namespace exec -} // namespace neurun +} // namespace onert struct ANeuralNetworksEvent { public: - ANeuralNetworksEvent(const std::shared_ptr &execution); + ANeuralNetworksEvent(const std::shared_ptr &execution); public: bool waitFinish(void) noexcept; private: - const std::shared_ptr _execution; + const std::shared_ptr _execution; }; #endif diff --git a/runtime/neurun/frontend/nnapi/wrapper/ANeuralNetworksExecution.cc b/runtime/onert/frontend/nnapi/wrapper/ANeuralNetworksExecution.cc similarity index 86% rename from runtime/neurun/frontend/nnapi/wrapper/ANeuralNetworksExecution.cc rename to runtime/onert/frontend/nnapi/wrapper/ANeuralNetworksExecution.cc index b8e43a691b6..15eb088c678 100644 --- a/runtime/neurun/frontend/nnapi/wrapper/ANeuralNetworksExecution.cc +++ b/runtime/onert/frontend/nnapi/wrapper/ANeuralNetworksExecution.cc @@ -18,50 +18,49 @@ #include "NNAPIConvert.h" #include "util/logging.h" -const neurun::ir::OperandIndex -ANeuralNetworksExecution::getInputOperandIndex(int32_t index) noexcept +const onert::ir::OperandIndex ANeuralNetworksExecution::getInputOperandIndex(int32_t index) noexcept { if (index < 0) { // Negative index: return invalid index - return neurun::ir::OperandIndex{}; + return onert::ir::OperandIndex{}; } uint32_t cast_index = static_cast(index); if (cast_index >= _execution->graph().getInputs().size()) { // Return invalid index - return neurun::ir::OperandIndex{}; + return onert::ir::OperandIndex{}; } - neurun::ir::IOIndex input_index{cast_index}; + onert::ir::IOIndex input_index{cast_index}; const auto operand_index = _execution->graph().getInputs().at(input_index); return operand_index; } -const neurun::ir::OperandIndex +const onert::ir::OperandIndex ANeuralNetworksExecution::getOutputOperandIndex(int32_t index) noexcept { if (index < 0) { // Negative index: return invalid index - return neurun::ir::OperandIndex{}; + return onert::ir::OperandIndex{}; } uint32_t cast_index = static_cast(index); if (cast_index >= _execution->graph().getOutputs().size()) { // Return invalid index - return neurun::ir::OperandIndex{}; + return onert::ir::OperandIndex{}; } - neurun::ir::IOIndex output_index{cast_index}; + onert::ir::IOIndex output_index{cast_index}; const auto operand_index = _execution->graph().getOutputs().at(output_index); return operand_index; } bool ANeuralNetworksExecution::compareDataType(const ANeuralNetworksOperandType *type, - const neurun::ir::OperandIndex index) noexcept + const onert::ir::OperandIndex index) noexcept { try { @@ -85,7 +84,7 @@ bool ANeuralNetworksExecution::compareDataType(const ANeuralNetworksOperandType } bool ANeuralNetworksExecution::compareShape(const ANeuralNetworksOperandType *type, - const neurun::ir::OperandIndex index) noexcept + const onert::ir::OperandIndex index) noexcept { // Passed shape should be specified if (haveUnspecifiedDims(index)) @@ -99,14 +98,14 @@ bool ANeuralNetworksExecution::compareShape(const ANeuralNetworksOperandType *ty return operand_shape == shape_from_type; } -bool ANeuralNetworksExecution::haveUnspecifiedDims(const neurun::ir::OperandIndex index) noexcept +bool ANeuralNetworksExecution::haveUnspecifiedDims(const onert::ir::OperandIndex index) noexcept { const auto operand_shape = _execution->graph().operands().at(index).shape(); return operand_shape.num_elements() == 0; } -size_t ANeuralNetworksExecution::getOperandSize(const neurun::ir::OperandIndex index) noexcept +size_t ANeuralNetworksExecution::getOperandSize(const onert::ir::OperandIndex index) noexcept { try { @@ -125,7 +124,7 @@ bool ANeuralNetworksExecution::setInput(uint32_t index, const ANeuralNetworksOpe { try { - neurun::ir::IOIndex input_index{index}; + onert::ir::IOIndex input_index{index}; const auto operand_index = getInputOperandIndex(index); const auto type_info = _execution->graph().operands().at(operand_index).typeInfo(); @@ -136,7 +135,7 @@ bool ANeuralNetworksExecution::setInput(uint32_t index, const ANeuralNetworksOpe // words, we can assume that io_layout from nnapi always is the same as layout of the used // model. // TODO Set layout of model - _execution->setInput(input_index, type_info, shape, buffer, length, neurun::ir::Layout::NHWC); + _execution->setInput(input_index, type_info, shape, buffer, length, onert::ir::Layout::NHWC); } catch (const std::exception &e) { @@ -153,7 +152,7 @@ bool ANeuralNetworksExecution::setOutput(uint32_t index, const ANeuralNetworksOp { try { - neurun::ir::IOIndex output_index{index}; + onert::ir::IOIndex output_index{index}; const auto operand_index = getOutputOperandIndex(index); const auto type_info = _execution->graph().operands().at(operand_index).typeInfo(); @@ -164,7 +163,7 @@ bool ANeuralNetworksExecution::setOutput(uint32_t index, const ANeuralNetworksOp // words, we can assume that io_layout from nnapi always is the same as layout of the used // model. // TODO Set layout of model - _execution->setOutput(output_index, type_info, shape, buffer, length, neurun::ir::Layout::NHWC); + _execution->setOutput(output_index, type_info, shape, buffer, length, onert::ir::Layout::NHWC); } catch (const std::exception &e) { @@ -208,7 +207,7 @@ bool ANeuralNetworksExecution::execute(void) noexcept return true; } -const std::shared_ptr ANeuralNetworksExecution::instance(void) noexcept +const std::shared_ptr ANeuralNetworksExecution::instance(void) noexcept { return _execution; } @@ -217,7 +216,7 @@ bool ANeuralNetworksExecution::getOutputOperandRank(uint32_t index, uint32_t *ra { try { - neurun::ir::IOIndex output_index{index}; + onert::ir::IOIndex output_index{index}; const auto operand_index = getOutputOperandIndex(index); bool unspecified = haveUnspecifiedDims(operand_index); @@ -250,7 +249,7 @@ bool ANeuralNetworksExecution::getOutputOperandDimensions(uint32_t index, uint32 { try { - neurun::ir::IOIndex output_index{index}; + onert::ir::IOIndex output_index{index}; const auto operand_index = getOutputOperandIndex(index); bool unspecified = haveUnspecifiedDims(operand_index); if (unspecified) diff --git a/runtime/neurun/frontend/nnapi/wrapper/ANeuralNetworksExecution.h b/runtime/onert/frontend/nnapi/wrapper/ANeuralNetworksExecution.h similarity index 74% rename from runtime/neurun/frontend/nnapi/wrapper/ANeuralNetworksExecution.h rename to runtime/onert/frontend/nnapi/wrapper/ANeuralNetworksExecution.h index ecffedc0a8a..af2465a815a 100644 --- a/runtime/neurun/frontend/nnapi/wrapper/ANeuralNetworksExecution.h +++ b/runtime/onert/frontend/nnapi/wrapper/ANeuralNetworksExecution.h @@ -26,8 +26,8 @@ struct ANeuralNetworksExecution { public: - ANeuralNetworksExecution(const std::shared_ptr &executor) - : _execution{std::make_shared(executor)} + ANeuralNetworksExecution(const std::shared_ptr &executor) + : _execution{std::make_shared(executor)} { // DO NOTHING } @@ -40,15 +40,15 @@ struct ANeuralNetworksExecution bool startExecute(void) noexcept; bool execute(void) noexcept; - const neurun::ir::OperandIndex getInputOperandIndex(int32_t index) noexcept; - const neurun::ir::OperandIndex getOutputOperandIndex(int32_t index) noexcept; + const onert::ir::OperandIndex getInputOperandIndex(int32_t index) noexcept; + const onert::ir::OperandIndex getOutputOperandIndex(int32_t index) noexcept; bool compareDataType(const ANeuralNetworksOperandType *type, - const neurun::ir::OperandIndex index) noexcept; + const onert::ir::OperandIndex index) noexcept; bool compareShape(const ANeuralNetworksOperandType *type, - const neurun::ir::OperandIndex index) noexcept; - bool haveUnspecifiedDims(const neurun::ir::OperandIndex index) noexcept; - size_t getOperandSize(const neurun::ir::OperandIndex index) noexcept; - const std::shared_ptr instance(void) noexcept; + const onert::ir::OperandIndex index) noexcept; + bool haveUnspecifiedDims(const onert::ir::OperandIndex index) noexcept; + size_t getOperandSize(const onert::ir::OperandIndex index) noexcept; + const std::shared_ptr instance(void) noexcept; /** * @brief Get output operand's rank @@ -68,7 +68,7 @@ struct ANeuralNetworksExecution bool getOutputOperandDimensions(uint32_t index, uint32_t *dimensions); private: - std::shared_ptr _execution; + std::shared_ptr _execution; }; #endif diff --git a/runtime/neurun/frontend/nnapi/wrapper/ANeuralNetworksMemory.cc b/runtime/onert/frontend/nnapi/wrapper/ANeuralNetworksMemory.cc similarity index 100% rename from runtime/neurun/frontend/nnapi/wrapper/ANeuralNetworksMemory.cc rename to runtime/onert/frontend/nnapi/wrapper/ANeuralNetworksMemory.cc diff --git a/runtime/neurun/frontend/nnapi/wrapper/ANeuralNetworksMemory.h b/runtime/onert/frontend/nnapi/wrapper/ANeuralNetworksMemory.h similarity index 100% rename from runtime/neurun/frontend/nnapi/wrapper/ANeuralNetworksMemory.h rename to runtime/onert/frontend/nnapi/wrapper/ANeuralNetworksMemory.h diff --git a/runtime/neurun/frontend/nnapi/wrapper/ANeuralNetworksModel.cc b/runtime/onert/frontend/nnapi/wrapper/ANeuralNetworksModel.cc similarity index 78% rename from runtime/neurun/frontend/nnapi/wrapper/ANeuralNetworksModel.cc rename to runtime/onert/frontend/nnapi/wrapper/ANeuralNetworksModel.cc index d3a096713a7..d2d699ae102 100644 --- a/runtime/neurun/frontend/nnapi/wrapper/ANeuralNetworksModel.cc +++ b/runtime/onert/frontend/nnapi/wrapper/ANeuralNetworksModel.cc @@ -21,14 +21,14 @@ #include "ir/Operations.Include.h" #include "util/logging.h" -#include "memory" +#include // // ANeuralNetworksModel // ANeuralNetworksModel::ANeuralNetworksModel() noexcept : _optional_operands{}, _operand_usages{} { - _graph = std::make_shared(); + _graph = std::make_shared(); } bool ANeuralNetworksModel::addOperand(const ANeuralNetworksOperandType *type) noexcept @@ -53,7 +53,7 @@ bool ANeuralNetworksModel::addOperand(const ANeuralNetworksOperandType *type) no bool ANeuralNetworksModel::setOperandValue(uint32_t index, const void *buffer, size_t length, bool optional, bool copy) noexcept { - const neurun::ir::OperandIndex ind{index}; + const onert::ir::OperandIndex ind{index}; try { @@ -66,8 +66,8 @@ bool ANeuralNetworksModel::setOperandValue(uint32_t index, const void *buffer, s setOptionalOperand(ind); } - using neurun::ir::CachedData; - using neurun::ir::ExternalData; + using onert::ir::CachedData; + using onert::ir::ExternalData; if (copy) { _graph->operands().at(ind).data( @@ -104,19 +104,19 @@ bool ANeuralNetworksModel::addOperation(ANeuralNetworksOperationType type, uint3 OperationFactory::Param param{inputCount, inputs, outputCount, outputs}; auto node = factory.create(type, param, _graph->operands()); - _graph->addOperation(std::unique_ptr{node}); + _graph->addOperation(std::unique_ptr{node}); // TODO Move these codes to delegate.cpp if (type == ANEURALNETWORKS_FULLY_CONNECTED) { const auto &input_operand = - _graph->operands().at(node->getInputs().at(neurun::ir::operation::FullyConnected::INPUT)); - auto &weights_operand = _graph->operands().at( - node->getInputs().at(neurun::ir::operation::FullyConnected::WEIGHT)); - if (input_operand.typeInfo().type() == neurun::ir::DataType::FLOAT32 && - weights_operand.typeInfo().type() == neurun::ir::DataType::QUANT8_ASYMM) + _graph->operands().at(node->getInputs().at(onert::ir::operation::FullyConnected::INPUT)); + auto &weights_operand = + _graph->operands().at(node->getInputs().at(onert::ir::operation::FullyConnected::WEIGHT)); + if (input_operand.typeInfo().type() == onert::ir::DataType::FLOAT32 && + weights_operand.typeInfo().type() == onert::ir::DataType::QUANT8_ASYMM) { - weights_operand.type(neurun::ir::DataType::QUANT8_SYMM); + weights_operand.type(onert::ir::DataType::QUANT8_SYMM); } } } @@ -145,7 +145,7 @@ bool ANeuralNetworksModel::addOperationEx(ANeuralNetworksOperationTypeEx type, u OperationFactory::Param param{inputCount, inputs, outputCount, outputs}; auto node = factory.create(type, param, _graph->operands()); - _graph->addOperation(std::unique_ptr{node}); + _graph->addOperation(std::unique_ptr{node}); } catch (const std::exception &e) { @@ -160,7 +160,7 @@ bool ANeuralNetworksModel::addModelInput(uint32_t index) noexcept { _operand_usages[index] = OperandUsage::MODEL_INPUT; - const neurun::ir::OperandIndex ind{index}; + const onert::ir::OperandIndex ind{index}; _graph->addInput(ind); } catch (const std::exception &e) @@ -176,7 +176,7 @@ bool ANeuralNetworksModel::addModelOutput(uint32_t index) noexcept { try { - const neurun::ir::OperandIndex ind{index}; + const onert::ir::OperandIndex ind{index}; // Duplicated output is not allowed if (_graph->getOutputs().contains(ind)) @@ -220,14 +220,14 @@ bool ANeuralNetworksModel::isFinished() noexcept { return !_graph->isBuildingPha bool ANeuralNetworksModel::isExistOperand(uint32_t index) noexcept { - return _graph->operands().exist(neurun::ir::OperandIndex{index}); + return _graph->operands().exist(onert::ir::OperandIndex{index}); } size_t ANeuralNetworksModel::operandSize(uint32_t index) noexcept { try { - return _graph->operands().at(neurun::ir::OperandIndex{index}).operandSize(); + return _graph->operands().at(onert::ir::OperandIndex{index}).operandSize(); } catch (const std::exception &e) { @@ -247,22 +247,21 @@ bool ANeuralNetworksModel::isOperationOutput(uint32_t index) noexcept return (_operand_usages[index] == OperandUsage::OPERATION_OUTPUT); } -void ANeuralNetworksModel::setOptionalOperand(const neurun::ir::OperandIndex idx) +void ANeuralNetworksModel::setOptionalOperand(const onert::ir::OperandIndex idx) { _optional_operands.insert(idx); } void ANeuralNetworksModel::fillOptionalOperand(void) { - _graph->operations().iterate( - [&](const neurun::ir::OperationIndex &, neurun::ir::Operation &node) { - for (auto input : node.getInputs()) - { - // TODO fill default value for optional operands - if (_optional_operands.find(input) != _optional_operands.end()) - { - throw std::runtime_error{"Optional operand is not supported yet"}; - } - } - }); + _graph->operations().iterate([&](const onert::ir::OperationIndex &, onert::ir::Operation &node) { + for (auto input : node.getInputs()) + { + // TODO fill default value for optional operands + if (_optional_operands.find(input) != _optional_operands.end()) + { + throw std::runtime_error{"Optional operand is not supported yet"}; + } + } + }); } diff --git a/runtime/neurun/frontend/nnapi/wrapper/ANeuralNetworksModel.h b/runtime/onert/frontend/nnapi/wrapper/ANeuralNetworksModel.h similarity index 87% rename from runtime/neurun/frontend/nnapi/wrapper/ANeuralNetworksModel.h rename to runtime/onert/frontend/nnapi/wrapper/ANeuralNetworksModel.h index d364ee39ede..3ccd941c70a 100644 --- a/runtime/neurun/frontend/nnapi/wrapper/ANeuralNetworksModel.h +++ b/runtime/onert/frontend/nnapi/wrapper/ANeuralNetworksModel.h @@ -50,21 +50,21 @@ struct ANeuralNetworksModel bool addModelOutput(uint32_t index) noexcept; bool finish() noexcept; - neurun::ir::Graph &deref(void) { return *_graph; } + onert::ir::Graph &deref(void) { return *_graph; } bool isFinished() noexcept; bool isExistOperand(uint32_t index) noexcept; size_t operandSize(uint32_t index) noexcept; bool isUsageSet(uint32_t index) noexcept; bool isOperationOutput(uint32_t index) noexcept; - void release(std::shared_ptr &graph) { graph = _graph; } + void release(std::shared_ptr &graph) { graph = _graph; } private: - void setOptionalOperand(const neurun::ir::OperandIndex idx); + void setOptionalOperand(const onert::ir::OperandIndex idx); void fillOptionalOperand(void); private: - std::shared_ptr _graph; - std::unordered_set _optional_operands; + std::shared_ptr _graph; + std::unordered_set _optional_operands; std::vector _operand_usages; }; diff --git a/runtime/neurun/frontend/nnapi/wrapper/NNAPIConvert.cc b/runtime/onert/frontend/nnapi/wrapper/NNAPIConvert.cc similarity index 98% rename from runtime/neurun/frontend/nnapi/wrapper/NNAPIConvert.cc rename to runtime/onert/frontend/nnapi/wrapper/NNAPIConvert.cc index 79589be75c0..e07297241d9 100644 --- a/runtime/neurun/frontend/nnapi/wrapper/NNAPIConvert.cc +++ b/runtime/onert/frontend/nnapi/wrapper/NNAPIConvert.cc @@ -18,7 +18,7 @@ #include -using namespace neurun::ir; +using namespace onert::ir; DataType NNAPIConvert::getDataType(OperandCode type) { diff --git a/runtime/neurun/frontend/nnapi/wrapper/NNAPIConvert.h b/runtime/onert/frontend/nnapi/wrapper/NNAPIConvert.h similarity index 69% rename from runtime/neurun/frontend/nnapi/wrapper/NNAPIConvert.h rename to runtime/onert/frontend/nnapi/wrapper/NNAPIConvert.h index 177e302ed65..4fd985e6e5c 100644 --- a/runtime/neurun/frontend/nnapi/wrapper/NNAPIConvert.h +++ b/runtime/onert/frontend/nnapi/wrapper/NNAPIConvert.h @@ -17,10 +17,10 @@ /** * @file NNAPIConvert.h * @brief This file contains convereter(s)\n - * from NNAPI frontend's struct to neurun's internal struct + * from NNAPI frontend's struct to onert's internal struct */ -#ifndef __NEURUN_NNAPI_CONVERT_H__ -#define __NEURUN_NNAPI_CONVERT_H__ +#ifndef __ONERT_NNAPI_CONVERT_H__ +#define __ONERT_NNAPI_CONVERT_H__ #include @@ -36,23 +36,23 @@ class NNAPIConvert /** * @brief Convert data type from NNAPI to internal data type * @param[in] type NNAPI's data type - * @return neurun's internal data type + * @return onert's internal data type */ - static neurun::ir::DataType getDataType(OperandCode type); + static onert::ir::DataType getDataType(OperandCode type); /** * @brief Convert operand type info from NNAPI to interanl operand type info * @param[in] type NNAPI's operand type - * @return neurun's internal operand type info + * @return onert's internal operand type info */ - static neurun::ir::TypeInfo getTypeInfo(const ANeuralNetworksOperandType *type); + static onert::ir::TypeInfo getTypeInfo(const ANeuralNetworksOperandType *type); /** * @brief Convert operand shape info from NNAPI to internal operand shape * @param[in] type NNAPI's operand type - * @return neurun's internal operand shape + * @return onert's internal operand shape */ - static neurun::ir::Shape getShape(const ANeuralNetworksOperandType *type); + static onert::ir::Shape getShape(const ANeuralNetworksOperandType *type); /** * @brief Calcaulate operand size from NNAPI type @@ -64,16 +64,16 @@ class NNAPIConvert /** * @brief Convert NNAPI FuseCode to internal activation type * @param[in] act NNAPI's FuseCode type - * @return neurun's internal activation type + * @return onert's internal activation type */ - static neurun::ir::Activation getFusedActivation(FuseCode act); + static onert::ir::Activation getFusedActivation(FuseCode act); /** * @brief Convert NNAPI PaddingCode to internal padding type * @param[in] type NNAPI's PaddingCode type - * @return neurun's internal padding type + * @return onert's internal padding type */ - static neurun::ir::PaddingType getPaddingType(PaddingCode type); + static onert::ir::PaddingType getPaddingType(PaddingCode type); }; -#endif // __NEURUN_NNAPI_CONVERT_H__ +#endif // __ONERT_NNAPI_CONVERT_H__ diff --git a/runtime/neurun/frontend/nnapi/wrapper/OperationFactory.cc b/runtime/onert/frontend/nnapi/wrapper/OperationFactory.cc similarity index 99% rename from runtime/neurun/frontend/nnapi/wrapper/OperationFactory.cc rename to runtime/onert/frontend/nnapi/wrapper/OperationFactory.cc index 1c81d0a798c..cc5a048afe1 100644 --- a/runtime/neurun/frontend/nnapi/wrapper/OperationFactory.cc +++ b/runtime/onert/frontend/nnapi/wrapper/OperationFactory.cc @@ -22,7 +22,7 @@ namespace { -using namespace neurun::ir; +using namespace onert::ir; void replaceDataType(Operands &operands, const OperandIndex &index, const DataType type) { @@ -1867,6 +1867,19 @@ OperationFactory::OperationFactory() return new operation::OneHot{inputs, outputs, param}; }; + + _map[ANEURALNETWORKS_SIN] = [](const OperationFactory::Param &init_param, Operands &) { + assert(init_param.input_count == 1 && init_param.output_count == 1); + + OperandIndexSequence outputs{init_param.outputs[0]}; + + // Each input should be interpreted as follows: + // + // 0 -> Input Tensor Index + OperandIndexSequence inputs{init_param.inputs[0]}; + + return new operation::Sin{inputs, outputs}; + }; } Operation *OperationFactory::create(ANeuralNetworksOperationType type, diff --git a/runtime/neurun/frontend/nnapi/wrapper/OperationFactory.h b/runtime/onert/frontend/nnapi/wrapper/OperationFactory.h similarity index 75% rename from runtime/neurun/frontend/nnapi/wrapper/OperationFactory.h rename to runtime/onert/frontend/nnapi/wrapper/OperationFactory.h index 003e4eb7a80..367cf74db45 100644 --- a/runtime/neurun/frontend/nnapi/wrapper/OperationFactory.h +++ b/runtime/onert/frontend/nnapi/wrapper/OperationFactory.h @@ -25,7 +25,7 @@ #include "NeuralNetworksEx.h" /** - * @brief A class to create a neurun operation object from NN API input parameters + * @brief A class to create a onert operation object from NN API input parameters */ class OperationFactory { @@ -39,8 +39,8 @@ class OperationFactory }; public: - using Generator = std::function; + using Generator = + std::function; public: static OperationFactory &get(); @@ -49,8 +49,8 @@ class OperationFactory OperationFactory(); public: - neurun::ir::Operation *create(ANeuralNetworksOperationType, const OperationFactory::Param ¶m, - neurun::ir::Operands &operands); + onert::ir::Operation *create(ANeuralNetworksOperationType, const OperationFactory::Param ¶m, + onert::ir::Operands &operands); // TODO add "register" method for separating registration, possibly supporting custom-ops private: diff --git a/runtime/neurun/frontend/tflite/CMakeLists.txt b/runtime/onert/frontend/tflite/CMakeLists.txt similarity index 90% rename from runtime/neurun/frontend/tflite/CMakeLists.txt rename to runtime/onert/frontend/tflite/CMakeLists.txt index 85c0cafb311..229f04f323a 100644 --- a/runtime/neurun/frontend/tflite/CMakeLists.txt +++ b/runtime/onert/frontend/tflite/CMakeLists.txt @@ -11,7 +11,7 @@ add_library(tflite_loader SHARED ${TFLITE_LOADER_SOURCES}) target_include_directories(tflite_loader PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) target_include_directories(tflite_loader PRIVATE ${FlatBuffersSource_DIR}/include) -target_link_libraries(tflite_loader PUBLIC neurun_core) +target_link_libraries(tflite_loader PUBLIC onert_core) target_link_libraries(tflite_loader PRIVATE base_loader nnfw_common nnfw_coverage) install(TARGETS tflite_loader DESTINATION lib) diff --git a/runtime/neurun/frontend/tflite/include/tflite_loader.h b/runtime/onert/frontend/tflite/include/tflite_loader.h similarity index 95% rename from runtime/neurun/frontend/tflite/include/tflite_loader.h rename to runtime/onert/frontend/tflite/include/tflite_loader.h index 033230b4b58..d1816d47aff 100644 --- a/runtime/neurun/frontend/tflite/include/tflite_loader.h +++ b/runtime/onert/frontend/tflite/include/tflite_loader.h @@ -21,7 +21,7 @@ #include -namespace neurun +namespace onert { namespace tflite_loader { @@ -29,6 +29,6 @@ namespace tflite_loader std::unique_ptr loadModel(const char *filename); } // namespace tflite_loader -} // namespace neurun +} // namespace onert #endif // __TFLITE_TFLITE_LOADER_H__ diff --git a/runtime/neurun/frontend/tflite/src/tflite_loader.cc b/runtime/onert/frontend/tflite/src/tflite_loader.cc similarity index 69% rename from runtime/neurun/frontend/tflite/src/tflite_loader.cc rename to runtime/onert/frontend/tflite/src/tflite_loader.cc index fd8ca9e7e2f..51443fc8bd0 100644 --- a/runtime/neurun/frontend/tflite/src/tflite_loader.cc +++ b/runtime/onert/frontend/tflite/src/tflite_loader.cc @@ -18,7 +18,7 @@ #include "base_loader.h" #include "tflite_schema_generated.h" -namespace neurun +namespace onert { namespace tflite_loader { @@ -29,34 +29,34 @@ namespace struct LoaderDomain { using Verifier = flatbuffers::Verifier; - using ActivationFunctionType = neurun_tflite::ActivationFunctionType; - using Buffer = neurun_tflite::Buffer; - using BuiltinOperator = neurun_tflite::BuiltinOperator; - using CustomOptionsFormat = neurun_tflite::CustomOptionsFormat; - using Model = neurun_tflite::Model; - using Operator = neurun_tflite::Operator; - using Padding = neurun_tflite::Padding; - using Pool2DOptions = neurun_tflite::Pool2DOptions; - using Tensor = neurun_tflite::Tensor; - using TensorType = neurun_tflite::TensorType; - using SubGraph = neurun_tflite::SubGraph; + using ActivationFunctionType = onert_tflite::ActivationFunctionType; + using Buffer = onert_tflite::Buffer; + using BuiltinOperator = onert_tflite::BuiltinOperator; + using CustomOptionsFormat = onert_tflite::CustomOptionsFormat; + using Model = onert_tflite::Model; + using Operator = onert_tflite::Operator; + using Padding = onert_tflite::Padding; + using Pool2DOptions = onert_tflite::Pool2DOptions; + using Tensor = onert_tflite::Tensor; + using TensorType = onert_tflite::TensorType; + using SubGraph = onert_tflite::SubGraph; static const char *EnumNameBuiltinOperator(BuiltinOperator e) { - return neurun_tflite::EnumNameBuiltinOperator(e); + return onert_tflite::EnumNameBuiltinOperator(e); } static const char *EnumNameActivationFunctionType(ActivationFunctionType e) { - return neurun_tflite::EnumNameActivationFunctionType(e); + return onert_tflite::EnumNameActivationFunctionType(e); } static const char *EnumNameTensorType(TensorType e) { - return neurun_tflite::EnumNameTensorType(e); + return onert_tflite::EnumNameTensorType(e); } - static const Model *GetModel(const void *buf) { return neurun_tflite::GetModel(buf); } + static const Model *GetModel(const void *buf) { return onert_tflite::GetModel(buf); } static bool VerifyModelBuffer(Verifier &verifier) { - return neurun_tflite::VerifyModelBuffer(verifier); + return onert_tflite::VerifyModelBuffer(verifier); } }; @@ -65,7 +65,7 @@ class TFLiteLoader final : public base_loader::BaseLoadertensors()->size()); @@ -102,4 +102,4 @@ std::unique_ptr loadModel(const char *filename) } } // namespace tflite_loader -} // namespace neurun +} // namespace onert diff --git a/runtime/neurun/frontend/tflite/src/tflite_schema_generated.h b/runtime/onert/frontend/tflite/src/tflite_schema_generated.h similarity index 74% rename from runtime/neurun/frontend/tflite/src/tflite_schema_generated.h rename to runtime/onert/frontend/tflite/src/tflite_schema_generated.h index b27ee556b2b..c6e9147cd1e 100644 --- a/runtime/neurun/frontend/tflite/src/tflite_schema_generated.h +++ b/runtime/onert/frontend/tflite/src/tflite_schema_generated.h @@ -1,4 +1,5 @@ /* + * Copyright (c) 2019-2020 Samsung Electronics Co., Ltd. All Rights Reserved * Copyright 2018 The TensorFlow Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,20 +14,31 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + // automatically generated by the FlatBuffers compiler, do not modify -#ifndef FLATBUFFERS_GENERATED_SCHEMA_NEURUN_TFLITE_H_ -#define FLATBUFFERS_GENERATED_SCHEMA_NEURUN_TFLITE_H_ +#ifndef FLATBUFFERS_GENERATED_TFLITESCHEMA_ONERT_TFLITE_H_ +#define FLATBUFFERS_GENERATED_TFLITESCHEMA_ONERT_TFLITE_H_ #include "flatbuffers/flatbuffers.h" -namespace neurun_tflite +namespace onert_tflite { struct CustomQuantization; struct QuantizationParameters; +struct Int32Vector; + +struct Uint16Vector; + +struct Uint8Vector; + +struct DimensionMetadata; + +struct SparsityParameters; + struct Tensor; struct Conv2DOptions; @@ -87,6 +99,8 @@ struct SkipGramOptions; struct SpaceToDepthOptions; +struct DepthToSpaceOptions; + struct SubOptions; struct DivOptions; @@ -101,6 +115,8 @@ struct TransposeOptions; struct ExpOptions; +struct CosOptions; + struct ReducerOptions; struct SqueezeOptions; @@ -151,6 +167,8 @@ struct NotEqualOptions; struct ShapeOptions; +struct RankOptions; + struct PowOptions; struct FakeQuantOptions; @@ -163,6 +181,8 @@ struct OneHotOptions; struct AbsOptions; +struct HardSwishOptions; + struct LogicalAndOptions; struct LogicalNotOptions; @@ -187,6 +207,42 @@ struct SquaredDifferenceOptions; struct MirrorPadOptions; +struct UniqueOptions; + +struct ReverseV2Options; + +struct AddNOptions; + +struct GatherNdOptions; + +struct WhereOptions; + +struct ReverseSequenceOptions; + +struct MatrixDiagOptions; + +struct QuantizeOptions; + +struct MatrixSetDiagOptions; + +struct IfOptions; + +struct WhileOptions; + +struct NonMaxSuppressionV4Options; + +struct NonMaxSuppressionV5Options; + +struct ScatterNdOptions; + +struct SelectV2Options; + +struct DensifyOptions; + +struct SegmentSumOptions; + +struct BatchMatMulOptions; + struct OperatorCode; struct Operator; @@ -195,6 +251,8 @@ struct SubGraph; struct Buffer; +struct Metadata; + struct Model; enum TensorType @@ -209,23 +267,25 @@ enum TensorType TensorType_INT16 = 7, TensorType_COMPLEX64 = 8, TensorType_INT8 = 9, + TensorType_FLOAT64 = 10, TensorType_MIN = TensorType_FLOAT32, - TensorType_MAX = TensorType_INT8 + TensorType_MAX = TensorType_FLOAT64 }; -inline const TensorType (&EnumValuesTensorType())[10] +inline const TensorType (&EnumValuesTensorType())[11] { static const TensorType values[] = {TensorType_FLOAT32, TensorType_FLOAT16, TensorType_INT32, TensorType_UINT8, TensorType_INT64, TensorType_STRING, TensorType_BOOL, TensorType_INT16, TensorType_COMPLEX64, - TensorType_INT8}; + TensorType_INT8, TensorType_FLOAT64}; return values; } inline const char *const *EnumNamesTensorType() { - static const char *const names[] = {"FLOAT32", "FLOAT16", "INT32", "UINT8", "INT64", "STRING", - "BOOL", "INT16", "COMPLEX64", "INT8", nullptr}; + static const char *const names[] = {"FLOAT32", "FLOAT16", "INT32", "UINT8", + "INT64", "STRING", "BOOL", "INT16", + "COMPLEX64", "INT8", "FLOAT64", nullptr}; return names; } @@ -278,6 +338,89 @@ bool VerifyQuantizationDetailsVector(flatbuffers::Verifier &verifier, const flatbuffers::Vector> *values, const flatbuffers::Vector *types); +enum DimensionType +{ + DimensionType_DENSE = 0, + DimensionType_SPARSE_CSR = 1, + DimensionType_MIN = DimensionType_DENSE, + DimensionType_MAX = DimensionType_SPARSE_CSR +}; + +inline const DimensionType (&EnumValuesDimensionType())[2] +{ + static const DimensionType values[] = {DimensionType_DENSE, DimensionType_SPARSE_CSR}; + return values; +} + +inline const char *const *EnumNamesDimensionType() +{ + static const char *const names[] = {"DENSE", "SPARSE_CSR", nullptr}; + return names; +} + +inline const char *EnumNameDimensionType(DimensionType e) +{ + const size_t index = static_cast(e); + return EnumNamesDimensionType()[index]; +} + +enum SparseIndexVector +{ + SparseIndexVector_NONE = 0, + SparseIndexVector_Int32Vector = 1, + SparseIndexVector_Uint16Vector = 2, + SparseIndexVector_Uint8Vector = 3, + SparseIndexVector_MIN = SparseIndexVector_NONE, + SparseIndexVector_MAX = SparseIndexVector_Uint8Vector +}; + +inline const SparseIndexVector (&EnumValuesSparseIndexVector())[4] +{ + static const SparseIndexVector values[] = {SparseIndexVector_NONE, SparseIndexVector_Int32Vector, + SparseIndexVector_Uint16Vector, + SparseIndexVector_Uint8Vector}; + return values; +} + +inline const char *const *EnumNamesSparseIndexVector() +{ + static const char *const names[] = {"NONE", "Int32Vector", "Uint16Vector", "Uint8Vector", + nullptr}; + return names; +} + +inline const char *EnumNameSparseIndexVector(SparseIndexVector e) +{ + const size_t index = static_cast(e); + return EnumNamesSparseIndexVector()[index]; +} + +template struct SparseIndexVectorTraits +{ + static const SparseIndexVector enum_value = SparseIndexVector_NONE; +}; + +template <> struct SparseIndexVectorTraits +{ + static const SparseIndexVector enum_value = SparseIndexVector_Int32Vector; +}; + +template <> struct SparseIndexVectorTraits +{ + static const SparseIndexVector enum_value = SparseIndexVector_Uint16Vector; +}; + +template <> struct SparseIndexVectorTraits +{ + static const SparseIndexVector enum_value = SparseIndexVector_Uint8Vector; +}; + +bool VerifySparseIndexVector(flatbuffers::Verifier &verifier, const void *obj, + SparseIndexVector type); +bool VerifySparseIndexVectorVector(flatbuffers::Verifier &verifier, + const flatbuffers::Vector> *values, + const flatbuffers::Vector *types); + enum BuiltinOperator { BuiltinOperator_ADD = 0, @@ -285,6 +428,7 @@ enum BuiltinOperator BuiltinOperator_CONCATENATION = 2, BuiltinOperator_CONV_2D = 3, BuiltinOperator_DEPTHWISE_CONV_2D = 4, + BuiltinOperator_DEPTH_TO_SPACE = 5, BuiltinOperator_DEQUANTIZE = 6, BuiltinOperator_EMBEDDING_LOOKUP = 7, BuiltinOperator_FLOOR = 8, @@ -382,17 +526,42 @@ enum BuiltinOperator BuiltinOperator_MIRROR_PAD = 100, BuiltinOperator_ABS = 101, BuiltinOperator_SPLIT_V = 102, + BuiltinOperator_UNIQUE = 103, + BuiltinOperator_CEIL = 104, + BuiltinOperator_REVERSE_V2 = 105, + BuiltinOperator_ADD_N = 106, + BuiltinOperator_GATHER_ND = 107, + BuiltinOperator_COS = 108, + BuiltinOperator_WHERE = 109, + BuiltinOperator_RANK = 110, + BuiltinOperator_ELU = 111, + BuiltinOperator_REVERSE_SEQUENCE = 112, + BuiltinOperator_MATRIX_DIAG = 113, + BuiltinOperator_QUANTIZE = 114, + BuiltinOperator_MATRIX_SET_DIAG = 115, + BuiltinOperator_ROUND = 116, + BuiltinOperator_HARD_SWISH = 117, + BuiltinOperator_IF = 118, + BuiltinOperator_WHILE = 119, + BuiltinOperator_NON_MAX_SUPPRESSION_V4 = 120, + BuiltinOperator_NON_MAX_SUPPRESSION_V5 = 121, + BuiltinOperator_SCATTER_ND = 122, + BuiltinOperator_SELECT_V2 = 123, + BuiltinOperator_DENSIFY = 124, + BuiltinOperator_SEGMENT_SUM = 125, + BuiltinOperator_BATCH_MATMUL = 126, BuiltinOperator_MIN = BuiltinOperator_ADD, - BuiltinOperator_MAX = BuiltinOperator_SPLIT_V + BuiltinOperator_MAX = BuiltinOperator_BATCH_MATMUL }; -inline const BuiltinOperator (&EnumValuesBuiltinOperator())[102] +inline const BuiltinOperator (&EnumValuesBuiltinOperator())[127] { static const BuiltinOperator values[] = {BuiltinOperator_ADD, BuiltinOperator_AVERAGE_POOL_2D, BuiltinOperator_CONCATENATION, BuiltinOperator_CONV_2D, BuiltinOperator_DEPTHWISE_CONV_2D, + BuiltinOperator_DEPTH_TO_SPACE, BuiltinOperator_DEQUANTIZE, BuiltinOperator_EMBEDDING_LOOKUP, BuiltinOperator_FLOOR, @@ -489,7 +658,31 @@ inline const BuiltinOperator (&EnumValuesBuiltinOperator())[102] BuiltinOperator_SQUARED_DIFFERENCE, BuiltinOperator_MIRROR_PAD, BuiltinOperator_ABS, - BuiltinOperator_SPLIT_V}; + BuiltinOperator_SPLIT_V, + BuiltinOperator_UNIQUE, + BuiltinOperator_CEIL, + BuiltinOperator_REVERSE_V2, + BuiltinOperator_ADD_N, + BuiltinOperator_GATHER_ND, + BuiltinOperator_COS, + BuiltinOperator_WHERE, + BuiltinOperator_RANK, + BuiltinOperator_ELU, + BuiltinOperator_REVERSE_SEQUENCE, + BuiltinOperator_MATRIX_DIAG, + BuiltinOperator_QUANTIZE, + BuiltinOperator_MATRIX_SET_DIAG, + BuiltinOperator_ROUND, + BuiltinOperator_HARD_SWISH, + BuiltinOperator_IF, + BuiltinOperator_WHILE, + BuiltinOperator_NON_MAX_SUPPRESSION_V4, + BuiltinOperator_NON_MAX_SUPPRESSION_V5, + BuiltinOperator_SCATTER_ND, + BuiltinOperator_SELECT_V2, + BuiltinOperator_DENSIFY, + BuiltinOperator_SEGMENT_SUM, + BuiltinOperator_BATCH_MATMUL}; return values; } @@ -500,7 +693,7 @@ inline const char *const *EnumNamesBuiltinOperator() "CONCATENATION", "CONV_2D", "DEPTHWISE_CONV_2D", - "", + "DEPTH_TO_SPACE", "DEQUANTIZE", "EMBEDDING_LOOKUP", "FLOOR", @@ -598,6 +791,30 @@ inline const char *const *EnumNamesBuiltinOperator() "MIRROR_PAD", "ABS", "SPLIT_V", + "UNIQUE", + "CEIL", + "REVERSE_V2", + "ADD_N", + "GATHER_ND", + "COS", + "WHERE", + "RANK", + "ELU", + "REVERSE_SEQUENCE", + "MATRIX_DIAG", + "QUANTIZE", + "MATRIX_SET_DIAG", + "ROUND", + "HARD_SWISH", + "IF", + "WHILE", + "NON_MAX_SUPPRESSION_V4", + "NON_MAX_SUPPRESSION_V5", + "SCATTER_ND", + "SELECT_V2", + "DENSIFY", + "SEGMENT_SUM", + "BATCH_MATMUL", nullptr}; return names; } @@ -690,11 +907,33 @@ enum BuiltinOptions BuiltinOptions_MirrorPadOptions = 77, BuiltinOptions_AbsOptions = 78, BuiltinOptions_SplitVOptions = 79, + BuiltinOptions_UniqueOptions = 80, + BuiltinOptions_ReverseV2Options = 81, + BuiltinOptions_AddNOptions = 82, + BuiltinOptions_GatherNdOptions = 83, + BuiltinOptions_CosOptions = 84, + BuiltinOptions_WhereOptions = 85, + BuiltinOptions_RankOptions = 86, + BuiltinOptions_ReverseSequenceOptions = 87, + BuiltinOptions_MatrixDiagOptions = 88, + BuiltinOptions_QuantizeOptions = 89, + BuiltinOptions_MatrixSetDiagOptions = 90, + BuiltinOptions_HardSwishOptions = 91, + BuiltinOptions_IfOptions = 92, + BuiltinOptions_WhileOptions = 93, + BuiltinOptions_DepthToSpaceOptions = 94, + BuiltinOptions_NonMaxSuppressionV4Options = 95, + BuiltinOptions_NonMaxSuppressionV5Options = 96, + BuiltinOptions_ScatterNdOptions = 97, + BuiltinOptions_SelectV2Options = 98, + BuiltinOptions_DensifyOptions = 99, + BuiltinOptions_SegmentSumOptions = 100, + BuiltinOptions_BatchMatMulOptions = 101, BuiltinOptions_MIN = BuiltinOptions_NONE, - BuiltinOptions_MAX = BuiltinOptions_SplitVOptions + BuiltinOptions_MAX = BuiltinOptions_BatchMatMulOptions }; -inline const BuiltinOptions (&EnumValuesBuiltinOptions())[80] +inline const BuiltinOptions (&EnumValuesBuiltinOptions())[102] { static const BuiltinOptions values[] = {BuiltinOptions_NONE, BuiltinOptions_Conv2DOptions, @@ -775,7 +1014,29 @@ inline const BuiltinOptions (&EnumValuesBuiltinOptions())[80] BuiltinOptions_SquaredDifferenceOptions, BuiltinOptions_MirrorPadOptions, BuiltinOptions_AbsOptions, - BuiltinOptions_SplitVOptions}; + BuiltinOptions_SplitVOptions, + BuiltinOptions_UniqueOptions, + BuiltinOptions_ReverseV2Options, + BuiltinOptions_AddNOptions, + BuiltinOptions_GatherNdOptions, + BuiltinOptions_CosOptions, + BuiltinOptions_WhereOptions, + BuiltinOptions_RankOptions, + BuiltinOptions_ReverseSequenceOptions, + BuiltinOptions_MatrixDiagOptions, + BuiltinOptions_QuantizeOptions, + BuiltinOptions_MatrixSetDiagOptions, + BuiltinOptions_HardSwishOptions, + BuiltinOptions_IfOptions, + BuiltinOptions_WhileOptions, + BuiltinOptions_DepthToSpaceOptions, + BuiltinOptions_NonMaxSuppressionV4Options, + BuiltinOptions_NonMaxSuppressionV5Options, + BuiltinOptions_ScatterNdOptions, + BuiltinOptions_SelectV2Options, + BuiltinOptions_DensifyOptions, + BuiltinOptions_SegmentSumOptions, + BuiltinOptions_BatchMatMulOptions}; return values; } @@ -861,6 +1122,28 @@ inline const char *const *EnumNamesBuiltinOptions() "MirrorPadOptions", "AbsOptions", "SplitVOptions", + "UniqueOptions", + "ReverseV2Options", + "AddNOptions", + "GatherNdOptions", + "CosOptions", + "WhereOptions", + "RankOptions", + "ReverseSequenceOptions", + "MatrixDiagOptions", + "QuantizeOptions", + "MatrixSetDiagOptions", + "HardSwishOptions", + "IfOptions", + "WhileOptions", + "DepthToSpaceOptions", + "NonMaxSuppressionV4Options", + "NonMaxSuppressionV5Options", + "ScatterNdOptions", + "SelectV2Options", + "DensifyOptions", + "SegmentSumOptions", + "BatchMatMulOptions", nullptr}; return names; } @@ -1271,6 +1554,116 @@ template <> struct BuiltinOptionsTraits static const BuiltinOptions enum_value = BuiltinOptions_SplitVOptions; }; +template <> struct BuiltinOptionsTraits +{ + static const BuiltinOptions enum_value = BuiltinOptions_UniqueOptions; +}; + +template <> struct BuiltinOptionsTraits +{ + static const BuiltinOptions enum_value = BuiltinOptions_ReverseV2Options; +}; + +template <> struct BuiltinOptionsTraits +{ + static const BuiltinOptions enum_value = BuiltinOptions_AddNOptions; +}; + +template <> struct BuiltinOptionsTraits +{ + static const BuiltinOptions enum_value = BuiltinOptions_GatherNdOptions; +}; + +template <> struct BuiltinOptionsTraits +{ + static const BuiltinOptions enum_value = BuiltinOptions_CosOptions; +}; + +template <> struct BuiltinOptionsTraits +{ + static const BuiltinOptions enum_value = BuiltinOptions_WhereOptions; +}; + +template <> struct BuiltinOptionsTraits +{ + static const BuiltinOptions enum_value = BuiltinOptions_RankOptions; +}; + +template <> struct BuiltinOptionsTraits +{ + static const BuiltinOptions enum_value = BuiltinOptions_ReverseSequenceOptions; +}; + +template <> struct BuiltinOptionsTraits +{ + static const BuiltinOptions enum_value = BuiltinOptions_MatrixDiagOptions; +}; + +template <> struct BuiltinOptionsTraits +{ + static const BuiltinOptions enum_value = BuiltinOptions_QuantizeOptions; +}; + +template <> struct BuiltinOptionsTraits +{ + static const BuiltinOptions enum_value = BuiltinOptions_MatrixSetDiagOptions; +}; + +template <> struct BuiltinOptionsTraits +{ + static const BuiltinOptions enum_value = BuiltinOptions_HardSwishOptions; +}; + +template <> struct BuiltinOptionsTraits +{ + static const BuiltinOptions enum_value = BuiltinOptions_IfOptions; +}; + +template <> struct BuiltinOptionsTraits +{ + static const BuiltinOptions enum_value = BuiltinOptions_WhileOptions; +}; + +template <> struct BuiltinOptionsTraits +{ + static const BuiltinOptions enum_value = BuiltinOptions_DepthToSpaceOptions; +}; + +template <> struct BuiltinOptionsTraits +{ + static const BuiltinOptions enum_value = BuiltinOptions_NonMaxSuppressionV4Options; +}; + +template <> struct BuiltinOptionsTraits +{ + static const BuiltinOptions enum_value = BuiltinOptions_NonMaxSuppressionV5Options; +}; + +template <> struct BuiltinOptionsTraits +{ + static const BuiltinOptions enum_value = BuiltinOptions_ScatterNdOptions; +}; + +template <> struct BuiltinOptionsTraits +{ + static const BuiltinOptions enum_value = BuiltinOptions_SelectV2Options; +}; + +template <> struct BuiltinOptionsTraits +{ + static const BuiltinOptions enum_value = BuiltinOptions_DensifyOptions; +}; + +template <> struct BuiltinOptionsTraits +{ + static const BuiltinOptions enum_value = BuiltinOptions_SegmentSumOptions; +}; + +template <> struct BuiltinOptionsTraits +{ + static const BuiltinOptions enum_value = BuiltinOptions_BatchMatMulOptions; +}; + bool VerifyBuiltinOptions(flatbuffers::Verifier &verifier, const void *obj, BuiltinOptions type); bool VerifyBuiltinOptionsVector(flatbuffers::Verifier &verifier, const flatbuffers::Vector> *values, @@ -1547,8 +1940,8 @@ inline flatbuffers::Offset CreateCustomQuantizationDirect(flatbuffers::FlatBufferBuilder &_fbb, const std::vector *custom = nullptr) { - return neurun_tflite::CreateCustomQuantization(_fbb, - custom ? _fbb.CreateVector(*custom) : 0); + return onert_tflite::CreateCustomQuantization(_fbb, + custom ? _fbb.CreateVector(*custom) : 0); } struct QuantizationParameters FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table @@ -1560,7 +1953,8 @@ struct QuantizationParameters FLATBUFFERS_FINAL_CLASS : private flatbuffers::Tab VT_SCALE = 8, VT_ZERO_POINT = 10, VT_DETAILS_TYPE = 12, - VT_DETAILS = 14 + VT_DETAILS = 14, + VT_QUANTIZED_DIMENSION = 16 }; const flatbuffers::Vector *min() const { @@ -1590,6 +1984,7 @@ struct QuantizationParameters FLATBUFFERS_FINAL_CLASS : private flatbuffers::Tab ? static_cast(details()) : nullptr; } + int32_t quantized_dimension() const { return GetField(VT_QUANTIZED_DIMENSION, 0); } bool Verify(flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && VerifyOffset(verifier, VT_MIN) && @@ -1598,7 +1993,8 @@ struct QuantizationParameters FLATBUFFERS_FINAL_CLASS : private flatbuffers::Tab verifier.VerifyVector(scale()) && VerifyOffset(verifier, VT_ZERO_POINT) && verifier.VerifyVector(zero_point()) && VerifyField(verifier, VT_DETAILS_TYPE) && VerifyOffset(verifier, VT_DETAILS) && - VerifyQuantizationDetails(verifier, details(), details_type()) && verifier.EndTable(); + VerifyQuantizationDetails(verifier, details(), details_type()) && + VerifyField(verifier, VT_QUANTIZED_DIMENSION) && verifier.EndTable(); } }; @@ -1637,6 +2033,11 @@ struct QuantizationParametersBuilder { fbb_.AddOffset(QuantizationParameters::VT_DETAILS, details); } + void add_quantized_dimension(int32_t quantized_dimension) + { + fbb_.AddElement(QuantizationParameters::VT_QUANTIZED_DIMENSION, quantized_dimension, + 0); + } explicit QuantizationParametersBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); @@ -1657,9 +2058,10 @@ CreateQuantizationParameters(flatbuffers::FlatBufferBuilder &_fbb, flatbuffers::Offset> scale = 0, flatbuffers::Offset> zero_point = 0, QuantizationDetails details_type = QuantizationDetails_NONE, - flatbuffers::Offset details = 0) + flatbuffers::Offset details = 0, int32_t quantized_dimension = 0) { QuantizationParametersBuilder builder_(_fbb); + builder_.add_quantized_dimension(quantized_dimension); builder_.add_details(details); builder_.add_zero_point(zero_point); builder_.add_scale(scale); @@ -1674,1500 +2076,3030 @@ inline flatbuffers::Offset CreateQuantizationParametersD const std::vector *max = nullptr, const std::vector *scale = nullptr, const std::vector *zero_point = nullptr, QuantizationDetails details_type = QuantizationDetails_NONE, - flatbuffers::Offset details = 0) + flatbuffers::Offset details = 0, int32_t quantized_dimension = 0) { - return neurun_tflite::CreateQuantizationParameters( + return onert_tflite::CreateQuantizationParameters( _fbb, min ? _fbb.CreateVector(*min) : 0, max ? _fbb.CreateVector(*max) : 0, scale ? _fbb.CreateVector(*scale) : 0, - zero_point ? _fbb.CreateVector(*zero_point) : 0, details_type, details); + zero_point ? _fbb.CreateVector(*zero_point) : 0, details_type, details, + quantized_dimension); } -struct Tensor FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct Int32Vector FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_SHAPE = 4, - VT_TYPE = 6, - VT_BUFFER = 8, - VT_NAME = 10, - VT_QUANTIZATION = 12, - VT_IS_VARIABLE = 14 + VT_VALUES = 4 }; - const flatbuffers::Vector *shape() const - { - return GetPointer *>(VT_SHAPE); - } - TensorType type() const { return static_cast(GetField(VT_TYPE, 0)); } - uint32_t buffer() const { return GetField(VT_BUFFER, 0); } - const flatbuffers::String *name() const - { - return GetPointer(VT_NAME); - } - const QuantizationParameters *quantization() const + const flatbuffers::Vector *values() const { - return GetPointer(VT_QUANTIZATION); + return GetPointer *>(VT_VALUES); } - bool is_variable() const { return GetField(VT_IS_VARIABLE, 0) != 0; } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyOffset(verifier, VT_SHAPE) && - verifier.VerifyVector(shape()) && VerifyField(verifier, VT_TYPE) && - VerifyField(verifier, VT_BUFFER) && VerifyOffset(verifier, VT_NAME) && - verifier.VerifyString(name()) && VerifyOffset(verifier, VT_QUANTIZATION) && - verifier.VerifyTable(quantization()) && VerifyField(verifier, VT_IS_VARIABLE) && - verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyOffset(verifier, VT_VALUES) && + verifier.VerifyVector(values()) && verifier.EndTable(); } }; -struct TensorBuilder +struct Int32VectorBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_shape(flatbuffers::Offset> shape) + void add_values(flatbuffers::Offset> values) { - fbb_.AddOffset(Tensor::VT_SHAPE, shape); + fbb_.AddOffset(Int32Vector::VT_VALUES, values); } - void add_type(TensorType type) + explicit Int32VectorBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { - fbb_.AddElement(Tensor::VT_TYPE, static_cast(type), 0); + start_ = fbb_.StartTable(); } - void add_buffer(uint32_t buffer) { fbb_.AddElement(Tensor::VT_BUFFER, buffer, 0); } - void add_name(flatbuffers::Offset name) + Int32VectorBuilder &operator=(const Int32VectorBuilder &); + flatbuffers::Offset Finish() { - fbb_.AddOffset(Tensor::VT_NAME, name); + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; } - void add_quantization(flatbuffers::Offset quantization) +}; + +inline flatbuffers::Offset +CreateInt32Vector(flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset> values = 0) +{ + Int32VectorBuilder builder_(_fbb); + builder_.add_values(values); + return builder_.Finish(); +} + +inline flatbuffers::Offset +CreateInt32VectorDirect(flatbuffers::FlatBufferBuilder &_fbb, + const std::vector *values = nullptr) +{ + return onert_tflite::CreateInt32Vector(_fbb, values ? _fbb.CreateVector(*values) : 0); +} + +struct Uint16Vector FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum { - fbb_.AddOffset(Tensor::VT_QUANTIZATION, quantization); + VT_VALUES = 4 + }; + const flatbuffers::Vector *values() const + { + return GetPointer *>(VT_VALUES); } - void add_is_variable(bool is_variable) + bool Verify(flatbuffers::Verifier &verifier) const { - fbb_.AddElement(Tensor::VT_IS_VARIABLE, static_cast(is_variable), 0); + return VerifyTableStart(verifier) && VerifyOffset(verifier, VT_VALUES) && + verifier.VerifyVector(values()) && verifier.EndTable(); } - explicit TensorBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) +}; + +struct Uint16VectorBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_values(flatbuffers::Offset> values) + { + fbb_.AddOffset(Uint16Vector::VT_VALUES, values); + } + explicit Uint16VectorBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - TensorBuilder &operator=(const TensorBuilder &); - flatbuffers::Offset Finish() + Uint16VectorBuilder &operator=(const Uint16VectorBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateTensor(flatbuffers::FlatBufferBuilder &_fbb, - flatbuffers::Offset> shape = 0, - TensorType type = TensorType_FLOAT32, uint32_t buffer = 0, - flatbuffers::Offset name = 0, - flatbuffers::Offset quantization = 0, bool is_variable = false) +inline flatbuffers::Offset +CreateUint16Vector(flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset> values = 0) { - TensorBuilder builder_(_fbb); - builder_.add_quantization(quantization); - builder_.add_name(name); - builder_.add_buffer(buffer); - builder_.add_shape(shape); - builder_.add_is_variable(is_variable); - builder_.add_type(type); + Uint16VectorBuilder builder_(_fbb); + builder_.add_values(values); return builder_.Finish(); } -inline flatbuffers::Offset CreateTensorDirect( - flatbuffers::FlatBufferBuilder &_fbb, const std::vector *shape = nullptr, - TensorType type = TensorType_FLOAT32, uint32_t buffer = 0, const char *name = nullptr, - flatbuffers::Offset quantization = 0, bool is_variable = false) +inline flatbuffers::Offset +CreateUint16VectorDirect(flatbuffers::FlatBufferBuilder &_fbb, + const std::vector *values = nullptr) { - return neurun_tflite::CreateTensor(_fbb, shape ? _fbb.CreateVector(*shape) : 0, type, - buffer, name ? _fbb.CreateString(name) : 0, quantization, - is_variable); + return onert_tflite::CreateUint16Vector(_fbb, values ? _fbb.CreateVector(*values) : 0); } -struct Conv2DOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct Uint8Vector FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_PADDING = 4, - VT_STRIDE_W = 6, - VT_STRIDE_H = 8, - VT_FUSED_ACTIVATION_FUNCTION = 10, - VT_DILATION_W_FACTOR = 12, - VT_DILATION_H_FACTOR = 14 + VT_VALUES = 4 }; - Padding padding() const { return static_cast(GetField(VT_PADDING, 0)); } - int32_t stride_w() const { return GetField(VT_STRIDE_W, 0); } - int32_t stride_h() const { return GetField(VT_STRIDE_H, 0); } - ActivationFunctionType fused_activation_function() const + const flatbuffers::Vector *values() const { - return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + return GetPointer *>(VT_VALUES); } - int32_t dilation_w_factor() const { return GetField(VT_DILATION_W_FACTOR, 1); } - int32_t dilation_h_factor() const { return GetField(VT_DILATION_H_FACTOR, 1); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_PADDING) && - VerifyField(verifier, VT_STRIDE_W) && - VerifyField(verifier, VT_STRIDE_H) && - VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && - VerifyField(verifier, VT_DILATION_W_FACTOR) && - VerifyField(verifier, VT_DILATION_H_FACTOR) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyOffset(verifier, VT_VALUES) && + verifier.VerifyVector(values()) && verifier.EndTable(); } }; -struct Conv2DOptionsBuilder +struct Uint8VectorBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_padding(Padding padding) + void add_values(flatbuffers::Offset> values) { - fbb_.AddElement(Conv2DOptions::VT_PADDING, static_cast(padding), 0); + fbb_.AddOffset(Uint8Vector::VT_VALUES, values); } - void add_stride_w(int32_t stride_w) + explicit Uint8VectorBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { - fbb_.AddElement(Conv2DOptions::VT_STRIDE_W, stride_w, 0); + start_ = fbb_.StartTable(); } - void add_stride_h(int32_t stride_h) + Uint8VectorBuilder &operator=(const Uint8VectorBuilder &); + flatbuffers::Offset Finish() { - fbb_.AddElement(Conv2DOptions::VT_STRIDE_H, stride_h, 0); - } - void add_fused_activation_function(ActivationFunctionType fused_activation_function) - { - fbb_.AddElement(Conv2DOptions::VT_FUSED_ACTIVATION_FUNCTION, - static_cast(fused_activation_function), 0); - } - void add_dilation_w_factor(int32_t dilation_w_factor) - { - fbb_.AddElement(Conv2DOptions::VT_DILATION_W_FACTOR, dilation_w_factor, 1); - } - void add_dilation_h_factor(int32_t dilation_h_factor) - { - fbb_.AddElement(Conv2DOptions::VT_DILATION_H_FACTOR, dilation_h_factor, 1); - } - explicit Conv2DOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) - { - start_ = fbb_.StartTable(); - } - Conv2DOptionsBuilder &operator=(const Conv2DOptionsBuilder &); - flatbuffers::Offset Finish() - { - const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); - return o; + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; } }; -inline flatbuffers::Offset -CreateConv2DOptions(flatbuffers::FlatBufferBuilder &_fbb, Padding padding = Padding_SAME, - int32_t stride_w = 0, int32_t stride_h = 0, - ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE, - int32_t dilation_w_factor = 1, int32_t dilation_h_factor = 1) +inline flatbuffers::Offset +CreateUint8Vector(flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset> values = 0) { - Conv2DOptionsBuilder builder_(_fbb); - builder_.add_dilation_h_factor(dilation_h_factor); - builder_.add_dilation_w_factor(dilation_w_factor); - builder_.add_stride_h(stride_h); - builder_.add_stride_w(stride_w); - builder_.add_fused_activation_function(fused_activation_function); - builder_.add_padding(padding); + Uint8VectorBuilder builder_(_fbb); + builder_.add_values(values); return builder_.Finish(); } -struct Pool2DOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +inline flatbuffers::Offset +CreateUint8VectorDirect(flatbuffers::FlatBufferBuilder &_fbb, + const std::vector *values = nullptr) +{ + return onert_tflite::CreateUint8Vector(_fbb, values ? _fbb.CreateVector(*values) : 0); +} + +struct DimensionMetadata FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_PADDING = 4, - VT_STRIDE_W = 6, - VT_STRIDE_H = 8, - VT_FILTER_WIDTH = 10, - VT_FILTER_HEIGHT = 12, - VT_FUSED_ACTIVATION_FUNCTION = 14 + VT_FORMAT = 4, + VT_DENSE_SIZE = 6, + VT_ARRAY_SEGMENTS_TYPE = 8, + VT_ARRAY_SEGMENTS = 10, + VT_ARRAY_INDICES_TYPE = 12, + VT_ARRAY_INDICES = 14 }; - Padding padding() const { return static_cast(GetField(VT_PADDING, 0)); } - int32_t stride_w() const { return GetField(VT_STRIDE_W, 0); } - int32_t stride_h() const { return GetField(VT_STRIDE_H, 0); } - int32_t filter_width() const { return GetField(VT_FILTER_WIDTH, 0); } - int32_t filter_height() const { return GetField(VT_FILTER_HEIGHT, 0); } - ActivationFunctionType fused_activation_function() const + DimensionType format() const { - return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + return static_cast(GetField(VT_FORMAT, 0)); } - bool Verify(flatbuffers::Verifier &verifier) const + int32_t dense_size() const { return GetField(VT_DENSE_SIZE, 0); } + SparseIndexVector array_segments_type() const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_PADDING) && - VerifyField(verifier, VT_STRIDE_W) && - VerifyField(verifier, VT_STRIDE_H) && - VerifyField(verifier, VT_FILTER_WIDTH) && - VerifyField(verifier, VT_FILTER_HEIGHT) && - VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && verifier.EndTable(); + return static_cast(GetField(VT_ARRAY_SEGMENTS_TYPE, 0)); } -}; - -struct Pool2DOptionsBuilder -{ - flatbuffers::FlatBufferBuilder &fbb_; - flatbuffers::uoffset_t start_; - void add_padding(Padding padding) + const void *array_segments() const { return GetPointer(VT_ARRAY_SEGMENTS); } + template const T *array_segments_as() const; + const Int32Vector *array_segments_as_Int32Vector() const { - fbb_.AddElement(Pool2DOptions::VT_PADDING, static_cast(padding), 0); + return array_segments_type() == SparseIndexVector_Int32Vector + ? static_cast(array_segments()) + : nullptr; } - void add_stride_w(int32_t stride_w) + const Uint16Vector *array_segments_as_Uint16Vector() const { - fbb_.AddElement(Pool2DOptions::VT_STRIDE_W, stride_w, 0); + return array_segments_type() == SparseIndexVector_Uint16Vector + ? static_cast(array_segments()) + : nullptr; } - void add_stride_h(int32_t stride_h) + const Uint8Vector *array_segments_as_Uint8Vector() const { - fbb_.AddElement(Pool2DOptions::VT_STRIDE_H, stride_h, 0); + return array_segments_type() == SparseIndexVector_Uint8Vector + ? static_cast(array_segments()) + : nullptr; } - void add_filter_width(int32_t filter_width) + SparseIndexVector array_indices_type() const { - fbb_.AddElement(Pool2DOptions::VT_FILTER_WIDTH, filter_width, 0); + return static_cast(GetField(VT_ARRAY_INDICES_TYPE, 0)); } - void add_filter_height(int32_t filter_height) + const void *array_indices() const { return GetPointer(VT_ARRAY_INDICES); } + template const T *array_indices_as() const; + const Int32Vector *array_indices_as_Int32Vector() const { - fbb_.AddElement(Pool2DOptions::VT_FILTER_HEIGHT, filter_height, 0); + return array_indices_type() == SparseIndexVector_Int32Vector + ? static_cast(array_indices()) + : nullptr; } - void add_fused_activation_function(ActivationFunctionType fused_activation_function) + const Uint16Vector *array_indices_as_Uint16Vector() const { - fbb_.AddElement(Pool2DOptions::VT_FUSED_ACTIVATION_FUNCTION, - static_cast(fused_activation_function), 0); + return array_indices_type() == SparseIndexVector_Uint16Vector + ? static_cast(array_indices()) + : nullptr; } - explicit Pool2DOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + const Uint8Vector *array_indices_as_Uint8Vector() const { - start_ = fbb_.StartTable(); + return array_indices_type() == SparseIndexVector_Uint8Vector + ? static_cast(array_indices()) + : nullptr; } - Pool2DOptionsBuilder &operator=(const Pool2DOptionsBuilder &); - flatbuffers::Offset Finish() + bool Verify(flatbuffers::Verifier &verifier) const { - const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); - return o; + return VerifyTableStart(verifier) && VerifyField(verifier, VT_FORMAT) && + VerifyField(verifier, VT_DENSE_SIZE) && + VerifyField(verifier, VT_ARRAY_SEGMENTS_TYPE) && + VerifyOffset(verifier, VT_ARRAY_SEGMENTS) && + VerifySparseIndexVector(verifier, array_segments(), array_segments_type()) && + VerifyField(verifier, VT_ARRAY_INDICES_TYPE) && + VerifyOffset(verifier, VT_ARRAY_INDICES) && + VerifySparseIndexVector(verifier, array_indices(), array_indices_type()) && + verifier.EndTable(); } }; -inline flatbuffers::Offset -CreatePool2DOptions(flatbuffers::FlatBufferBuilder &_fbb, Padding padding = Padding_SAME, - int32_t stride_w = 0, int32_t stride_h = 0, int32_t filter_width = 0, - int32_t filter_height = 0, - ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE) +template <> inline const Int32Vector *DimensionMetadata::array_segments_as() const { - Pool2DOptionsBuilder builder_(_fbb); - builder_.add_filter_height(filter_height); - builder_.add_filter_width(filter_width); - builder_.add_stride_h(stride_h); - builder_.add_stride_w(stride_w); - builder_.add_fused_activation_function(fused_activation_function); - builder_.add_padding(padding); - return builder_.Finish(); + return array_segments_as_Int32Vector(); } -struct DepthwiseConv2DOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +template <> inline const Uint16Vector *DimensionMetadata::array_segments_as() const { - enum - { - VT_PADDING = 4, - VT_STRIDE_W = 6, - VT_STRIDE_H = 8, - VT_DEPTH_MULTIPLIER = 10, - VT_FUSED_ACTIVATION_FUNCTION = 12, - VT_DILATION_W_FACTOR = 14, - VT_DILATION_H_FACTOR = 16 - }; - Padding padding() const { return static_cast(GetField(VT_PADDING, 0)); } - int32_t stride_w() const { return GetField(VT_STRIDE_W, 0); } - int32_t stride_h() const { return GetField(VT_STRIDE_H, 0); } - int32_t depth_multiplier() const { return GetField(VT_DEPTH_MULTIPLIER, 0); } - ActivationFunctionType fused_activation_function() const - { - return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); - } - int32_t dilation_w_factor() const { return GetField(VT_DILATION_W_FACTOR, 1); } - int32_t dilation_h_factor() const { return GetField(VT_DILATION_H_FACTOR, 1); } - bool Verify(flatbuffers::Verifier &verifier) const - { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_PADDING) && - VerifyField(verifier, VT_STRIDE_W) && - VerifyField(verifier, VT_STRIDE_H) && - VerifyField(verifier, VT_DEPTH_MULTIPLIER) && - VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && - VerifyField(verifier, VT_DILATION_W_FACTOR) && - VerifyField(verifier, VT_DILATION_H_FACTOR) && verifier.EndTable(); - } -}; + return array_segments_as_Uint16Vector(); +} -struct DepthwiseConv2DOptionsBuilder +template <> inline const Uint8Vector *DimensionMetadata::array_segments_as() const +{ + return array_segments_as_Uint8Vector(); +} + +template <> inline const Int32Vector *DimensionMetadata::array_indices_as() const +{ + return array_indices_as_Int32Vector(); +} + +template <> inline const Uint16Vector *DimensionMetadata::array_indices_as() const +{ + return array_indices_as_Uint16Vector(); +} + +template <> inline const Uint8Vector *DimensionMetadata::array_indices_as() const +{ + return array_indices_as_Uint8Vector(); +} + +struct DimensionMetadataBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_padding(Padding padding) - { - fbb_.AddElement(DepthwiseConv2DOptions::VT_PADDING, static_cast(padding), 0); - } - void add_stride_w(int32_t stride_w) + void add_format(DimensionType format) { - fbb_.AddElement(DepthwiseConv2DOptions::VT_STRIDE_W, stride_w, 0); + fbb_.AddElement(DimensionMetadata::VT_FORMAT, static_cast(format), 0); } - void add_stride_h(int32_t stride_h) + void add_dense_size(int32_t dense_size) { - fbb_.AddElement(DepthwiseConv2DOptions::VT_STRIDE_H, stride_h, 0); + fbb_.AddElement(DimensionMetadata::VT_DENSE_SIZE, dense_size, 0); } - void add_depth_multiplier(int32_t depth_multiplier) + void add_array_segments_type(SparseIndexVector array_segments_type) { - fbb_.AddElement(DepthwiseConv2DOptions::VT_DEPTH_MULTIPLIER, depth_multiplier, 0); + fbb_.AddElement(DimensionMetadata::VT_ARRAY_SEGMENTS_TYPE, + static_cast(array_segments_type), 0); } - void add_fused_activation_function(ActivationFunctionType fused_activation_function) + void add_array_segments(flatbuffers::Offset array_segments) { - fbb_.AddElement(DepthwiseConv2DOptions::VT_FUSED_ACTIVATION_FUNCTION, - static_cast(fused_activation_function), 0); + fbb_.AddOffset(DimensionMetadata::VT_ARRAY_SEGMENTS, array_segments); } - void add_dilation_w_factor(int32_t dilation_w_factor) + void add_array_indices_type(SparseIndexVector array_indices_type) { - fbb_.AddElement(DepthwiseConv2DOptions::VT_DILATION_W_FACTOR, dilation_w_factor, 1); + fbb_.AddElement(DimensionMetadata::VT_ARRAY_INDICES_TYPE, + static_cast(array_indices_type), 0); } - void add_dilation_h_factor(int32_t dilation_h_factor) + void add_array_indices(flatbuffers::Offset array_indices) { - fbb_.AddElement(DepthwiseConv2DOptions::VT_DILATION_H_FACTOR, dilation_h_factor, 1); + fbb_.AddOffset(DimensionMetadata::VT_ARRAY_INDICES, array_indices); } - explicit DepthwiseConv2DOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit DimensionMetadataBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - DepthwiseConv2DOptionsBuilder &operator=(const DepthwiseConv2DOptionsBuilder &); - flatbuffers::Offset Finish() + DimensionMetadataBuilder &operator=(const DimensionMetadataBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateDepthwiseConv2DOptions( - flatbuffers::FlatBufferBuilder &_fbb, Padding padding = Padding_SAME, int32_t stride_w = 0, - int32_t stride_h = 0, int32_t depth_multiplier = 0, - ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE, - int32_t dilation_w_factor = 1, int32_t dilation_h_factor = 1) +inline flatbuffers::Offset +CreateDimensionMetadata(flatbuffers::FlatBufferBuilder &_fbb, + DimensionType format = DimensionType_DENSE, int32_t dense_size = 0, + SparseIndexVector array_segments_type = SparseIndexVector_NONE, + flatbuffers::Offset array_segments = 0, + SparseIndexVector array_indices_type = SparseIndexVector_NONE, + flatbuffers::Offset array_indices = 0) { - DepthwiseConv2DOptionsBuilder builder_(_fbb); - builder_.add_dilation_h_factor(dilation_h_factor); - builder_.add_dilation_w_factor(dilation_w_factor); - builder_.add_depth_multiplier(depth_multiplier); - builder_.add_stride_h(stride_h); - builder_.add_stride_w(stride_w); - builder_.add_fused_activation_function(fused_activation_function); - builder_.add_padding(padding); + DimensionMetadataBuilder builder_(_fbb); + builder_.add_array_indices(array_indices); + builder_.add_array_segments(array_segments); + builder_.add_dense_size(dense_size); + builder_.add_array_indices_type(array_indices_type); + builder_.add_array_segments_type(array_segments_type); + builder_.add_format(format); return builder_.Finish(); } -struct ConcatEmbeddingsOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct SparsityParameters FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_NUM_CHANNELS = 4, - VT_NUM_COLUMNS_PER_CHANNEL = 6, - VT_EMBEDDING_DIM_PER_CHANNEL = 8 + VT_TRAVERSAL_ORDER = 4, + VT_BLOCK_MAP = 6, + VT_DIM_METADATA = 8 }; - int32_t num_channels() const { return GetField(VT_NUM_CHANNELS, 0); } - const flatbuffers::Vector *num_columns_per_channel() const + const flatbuffers::Vector *traversal_order() const { - return GetPointer *>(VT_NUM_COLUMNS_PER_CHANNEL); + return GetPointer *>(VT_TRAVERSAL_ORDER); } - const flatbuffers::Vector *embedding_dim_per_channel() const + const flatbuffers::Vector *block_map() const { - return GetPointer *>(VT_EMBEDDING_DIM_PER_CHANNEL); + return GetPointer *>(VT_BLOCK_MAP); + } + const flatbuffers::Vector> *dim_metadata() const + { + return GetPointer> *>( + VT_DIM_METADATA); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_NUM_CHANNELS) && - VerifyOffset(verifier, VT_NUM_COLUMNS_PER_CHANNEL) && - verifier.VerifyVector(num_columns_per_channel()) && - VerifyOffset(verifier, VT_EMBEDDING_DIM_PER_CHANNEL) && - verifier.VerifyVector(embedding_dim_per_channel()) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyOffset(verifier, VT_TRAVERSAL_ORDER) && + verifier.VerifyVector(traversal_order()) && VerifyOffset(verifier, VT_BLOCK_MAP) && + verifier.VerifyVector(block_map()) && VerifyOffset(verifier, VT_DIM_METADATA) && + verifier.VerifyVector(dim_metadata()) && verifier.VerifyVectorOfTables(dim_metadata()) && + verifier.EndTable(); } }; -struct ConcatEmbeddingsOptionsBuilder +struct SparsityParametersBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_num_channels(int32_t num_channels) + void add_traversal_order(flatbuffers::Offset> traversal_order) { - fbb_.AddElement(ConcatEmbeddingsOptions::VT_NUM_CHANNELS, num_channels, 0); + fbb_.AddOffset(SparsityParameters::VT_TRAVERSAL_ORDER, traversal_order); } - void add_num_columns_per_channel( - flatbuffers::Offset> num_columns_per_channel) + void add_block_map(flatbuffers::Offset> block_map) { - fbb_.AddOffset(ConcatEmbeddingsOptions::VT_NUM_COLUMNS_PER_CHANNEL, num_columns_per_channel); + fbb_.AddOffset(SparsityParameters::VT_BLOCK_MAP, block_map); } - void add_embedding_dim_per_channel( - flatbuffers::Offset> embedding_dim_per_channel) + void add_dim_metadata( + flatbuffers::Offset>> dim_metadata) { - fbb_.AddOffset(ConcatEmbeddingsOptions::VT_EMBEDDING_DIM_PER_CHANNEL, - embedding_dim_per_channel); + fbb_.AddOffset(SparsityParameters::VT_DIM_METADATA, dim_metadata); } - explicit ConcatEmbeddingsOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit SparsityParametersBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - ConcatEmbeddingsOptionsBuilder &operator=(const ConcatEmbeddingsOptionsBuilder &); - flatbuffers::Offset Finish() + SparsityParametersBuilder &operator=(const SparsityParametersBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateConcatEmbeddingsOptions( - flatbuffers::FlatBufferBuilder &_fbb, int32_t num_channels = 0, - flatbuffers::Offset> num_columns_per_channel = 0, - flatbuffers::Offset> embedding_dim_per_channel = 0) -{ - ConcatEmbeddingsOptionsBuilder builder_(_fbb); - builder_.add_embedding_dim_per_channel(embedding_dim_per_channel); - builder_.add_num_columns_per_channel(num_columns_per_channel); - builder_.add_num_channels(num_channels); +inline flatbuffers::Offset CreateSparsityParameters( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset> traversal_order = 0, + flatbuffers::Offset> block_map = 0, + flatbuffers::Offset>> dim_metadata = + 0) +{ + SparsityParametersBuilder builder_(_fbb); + builder_.add_dim_metadata(dim_metadata); + builder_.add_block_map(block_map); + builder_.add_traversal_order(traversal_order); return builder_.Finish(); } -inline flatbuffers::Offset -CreateConcatEmbeddingsOptionsDirect(flatbuffers::FlatBufferBuilder &_fbb, int32_t num_channels = 0, - const std::vector *num_columns_per_channel = nullptr, - const std::vector *embedding_dim_per_channel = nullptr) +inline flatbuffers::Offset CreateSparsityParametersDirect( + flatbuffers::FlatBufferBuilder &_fbb, const std::vector *traversal_order = nullptr, + const std::vector *block_map = nullptr, + const std::vector> *dim_metadata = nullptr) { - return neurun_tflite::CreateConcatEmbeddingsOptions( - _fbb, num_channels, - num_columns_per_channel ? _fbb.CreateVector(*num_columns_per_channel) : 0, - embedding_dim_per_channel ? _fbb.CreateVector(*embedding_dim_per_channel) : 0); + return onert_tflite::CreateSparsityParameters( + _fbb, traversal_order ? _fbb.CreateVector(*traversal_order) : 0, + block_map ? _fbb.CreateVector(*block_map) : 0, + dim_metadata ? _fbb.CreateVector>(*dim_metadata) : 0); } -struct LSHProjectionOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct Tensor FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_TYPE = 4 + VT_SHAPE = 4, + VT_TYPE = 6, + VT_BUFFER = 8, + VT_NAME = 10, + VT_QUANTIZATION = 12, + VT_IS_VARIABLE = 14, + VT_SPARSITY = 16, + VT_SHAPE_SIGNATURE = 18 }; - LSHProjectionType type() const + const flatbuffers::Vector *shape() const { - return static_cast(GetField(VT_TYPE, 0)); + return GetPointer *>(VT_SHAPE); } - bool Verify(flatbuffers::Verifier &verifier) const + TensorType type() const { return static_cast(GetField(VT_TYPE, 0)); } + uint32_t buffer() const { return GetField(VT_BUFFER, 0); } + const flatbuffers::String *name() const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_TYPE) && - verifier.EndTable(); + return GetPointer(VT_NAME); } -}; - -struct LSHProjectionOptionsBuilder -{ - flatbuffers::FlatBufferBuilder &fbb_; - flatbuffers::uoffset_t start_; - void add_type(LSHProjectionType type) + const QuantizationParameters *quantization() const { - fbb_.AddElement(LSHProjectionOptions::VT_TYPE, static_cast(type), 0); + return GetPointer(VT_QUANTIZATION); } - explicit LSHProjectionOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + bool is_variable() const { return GetField(VT_IS_VARIABLE, 0) != 0; } + const SparsityParameters *sparsity() const + { + return GetPointer(VT_SPARSITY); + } + const flatbuffers::Vector *shape_signature() const + { + return GetPointer *>(VT_SHAPE_SIGNATURE); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && VerifyOffset(verifier, VT_SHAPE) && + verifier.VerifyVector(shape()) && VerifyField(verifier, VT_TYPE) && + VerifyField(verifier, VT_BUFFER) && VerifyOffset(verifier, VT_NAME) && + verifier.VerifyString(name()) && VerifyOffset(verifier, VT_QUANTIZATION) && + verifier.VerifyTable(quantization()) && VerifyField(verifier, VT_IS_VARIABLE) && + VerifyOffset(verifier, VT_SPARSITY) && verifier.VerifyTable(sparsity()) && + VerifyOffset(verifier, VT_SHAPE_SIGNATURE) && verifier.VerifyVector(shape_signature()) && + verifier.EndTable(); + } +}; + +struct TensorBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_shape(flatbuffers::Offset> shape) + { + fbb_.AddOffset(Tensor::VT_SHAPE, shape); + } + void add_type(TensorType type) + { + fbb_.AddElement(Tensor::VT_TYPE, static_cast(type), 0); + } + void add_buffer(uint32_t buffer) { fbb_.AddElement(Tensor::VT_BUFFER, buffer, 0); } + void add_name(flatbuffers::Offset name) + { + fbb_.AddOffset(Tensor::VT_NAME, name); + } + void add_quantization(flatbuffers::Offset quantization) + { + fbb_.AddOffset(Tensor::VT_QUANTIZATION, quantization); + } + void add_is_variable(bool is_variable) + { + fbb_.AddElement(Tensor::VT_IS_VARIABLE, static_cast(is_variable), 0); + } + void add_sparsity(flatbuffers::Offset sparsity) + { + fbb_.AddOffset(Tensor::VT_SPARSITY, sparsity); + } + void add_shape_signature(flatbuffers::Offset> shape_signature) + { + fbb_.AddOffset(Tensor::VT_SHAPE_SIGNATURE, shape_signature); + } + explicit TensorBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - LSHProjectionOptionsBuilder &operator=(const LSHProjectionOptionsBuilder &); - flatbuffers::Offset Finish() + TensorBuilder &operator=(const TensorBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateLSHProjectionOptions(flatbuffers::FlatBufferBuilder &_fbb, - LSHProjectionType type = LSHProjectionType_UNKNOWN) +inline flatbuffers::Offset +CreateTensor(flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset> shape = 0, + TensorType type = TensorType_FLOAT32, uint32_t buffer = 0, + flatbuffers::Offset name = 0, + flatbuffers::Offset quantization = 0, bool is_variable = false, + flatbuffers::Offset sparsity = 0, + flatbuffers::Offset> shape_signature = 0) { - LSHProjectionOptionsBuilder builder_(_fbb); + TensorBuilder builder_(_fbb); + builder_.add_shape_signature(shape_signature); + builder_.add_sparsity(sparsity); + builder_.add_quantization(quantization); + builder_.add_name(name); + builder_.add_buffer(buffer); + builder_.add_shape(shape); + builder_.add_is_variable(is_variable); builder_.add_type(type); return builder_.Finish(); } -struct SVDFOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +inline flatbuffers::Offset CreateTensorDirect( + flatbuffers::FlatBufferBuilder &_fbb, const std::vector *shape = nullptr, + TensorType type = TensorType_FLOAT32, uint32_t buffer = 0, const char *name = nullptr, + flatbuffers::Offset quantization = 0, bool is_variable = false, + flatbuffers::Offset sparsity = 0, + const std::vector *shape_signature = nullptr) +{ + return onert_tflite::CreateTensor( + _fbb, shape ? _fbb.CreateVector(*shape) : 0, type, buffer, + name ? _fbb.CreateString(name) : 0, quantization, is_variable, sparsity, + shape_signature ? _fbb.CreateVector(*shape_signature) : 0); +} + +struct Conv2DOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_RANK = 4, - VT_FUSED_ACTIVATION_FUNCTION = 6 + VT_PADDING = 4, + VT_STRIDE_W = 6, + VT_STRIDE_H = 8, + VT_FUSED_ACTIVATION_FUNCTION = 10, + VT_DILATION_W_FACTOR = 12, + VT_DILATION_H_FACTOR = 14 }; - int32_t rank() const { return GetField(VT_RANK, 0); } + Padding padding() const { return static_cast(GetField(VT_PADDING, 0)); } + int32_t stride_w() const { return GetField(VT_STRIDE_W, 0); } + int32_t stride_h() const { return GetField(VT_STRIDE_H, 0); } ActivationFunctionType fused_activation_function() const { return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); } + int32_t dilation_w_factor() const { return GetField(VT_DILATION_W_FACTOR, 1); } + int32_t dilation_h_factor() const { return GetField(VT_DILATION_H_FACTOR, 1); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_RANK) && + return VerifyTableStart(verifier) && VerifyField(verifier, VT_PADDING) && + VerifyField(verifier, VT_STRIDE_W) && + VerifyField(verifier, VT_STRIDE_H) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && + VerifyField(verifier, VT_DILATION_W_FACTOR) && + VerifyField(verifier, VT_DILATION_H_FACTOR) && verifier.EndTable(); + } +}; + +struct Conv2DOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_padding(Padding padding) + { + fbb_.AddElement(Conv2DOptions::VT_PADDING, static_cast(padding), 0); + } + void add_stride_w(int32_t stride_w) + { + fbb_.AddElement(Conv2DOptions::VT_STRIDE_W, stride_w, 0); + } + void add_stride_h(int32_t stride_h) + { + fbb_.AddElement(Conv2DOptions::VT_STRIDE_H, stride_h, 0); + } + void add_fused_activation_function(ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(Conv2DOptions::VT_FUSED_ACTIVATION_FUNCTION, + static_cast(fused_activation_function), 0); + } + void add_dilation_w_factor(int32_t dilation_w_factor) + { + fbb_.AddElement(Conv2DOptions::VT_DILATION_W_FACTOR, dilation_w_factor, 1); + } + void add_dilation_h_factor(int32_t dilation_h_factor) + { + fbb_.AddElement(Conv2DOptions::VT_DILATION_H_FACTOR, dilation_h_factor, 1); + } + explicit Conv2DOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + Conv2DOptionsBuilder &operator=(const Conv2DOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset +CreateConv2DOptions(flatbuffers::FlatBufferBuilder &_fbb, Padding padding = Padding_SAME, + int32_t stride_w = 0, int32_t stride_h = 0, + ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE, + int32_t dilation_w_factor = 1, int32_t dilation_h_factor = 1) +{ + Conv2DOptionsBuilder builder_(_fbb); + builder_.add_dilation_h_factor(dilation_h_factor); + builder_.add_dilation_w_factor(dilation_w_factor); + builder_.add_stride_h(stride_h); + builder_.add_stride_w(stride_w); + builder_.add_fused_activation_function(fused_activation_function); + builder_.add_padding(padding); + return builder_.Finish(); +} + +struct Pool2DOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_PADDING = 4, + VT_STRIDE_W = 6, + VT_STRIDE_H = 8, + VT_FILTER_WIDTH = 10, + VT_FILTER_HEIGHT = 12, + VT_FUSED_ACTIVATION_FUNCTION = 14 + }; + Padding padding() const { return static_cast(GetField(VT_PADDING, 0)); } + int32_t stride_w() const { return GetField(VT_STRIDE_W, 0); } + int32_t stride_h() const { return GetField(VT_STRIDE_H, 0); } + int32_t filter_width() const { return GetField(VT_FILTER_WIDTH, 0); } + int32_t filter_height() const { return GetField(VT_FILTER_HEIGHT, 0); } + ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && VerifyField(verifier, VT_PADDING) && + VerifyField(verifier, VT_STRIDE_W) && + VerifyField(verifier, VT_STRIDE_H) && + VerifyField(verifier, VT_FILTER_WIDTH) && + VerifyField(verifier, VT_FILTER_HEIGHT) && VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && verifier.EndTable(); } }; -struct SVDFOptionsBuilder +struct Pool2DOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_padding(Padding padding) + { + fbb_.AddElement(Pool2DOptions::VT_PADDING, static_cast(padding), 0); + } + void add_stride_w(int32_t stride_w) + { + fbb_.AddElement(Pool2DOptions::VT_STRIDE_W, stride_w, 0); + } + void add_stride_h(int32_t stride_h) + { + fbb_.AddElement(Pool2DOptions::VT_STRIDE_H, stride_h, 0); + } + void add_filter_width(int32_t filter_width) + { + fbb_.AddElement(Pool2DOptions::VT_FILTER_WIDTH, filter_width, 0); + } + void add_filter_height(int32_t filter_height) + { + fbb_.AddElement(Pool2DOptions::VT_FILTER_HEIGHT, filter_height, 0); + } + void add_fused_activation_function(ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(Pool2DOptions::VT_FUSED_ACTIVATION_FUNCTION, + static_cast(fused_activation_function), 0); + } + explicit Pool2DOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + Pool2DOptionsBuilder &operator=(const Pool2DOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset +CreatePool2DOptions(flatbuffers::FlatBufferBuilder &_fbb, Padding padding = Padding_SAME, + int32_t stride_w = 0, int32_t stride_h = 0, int32_t filter_width = 0, + int32_t filter_height = 0, + ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE) +{ + Pool2DOptionsBuilder builder_(_fbb); + builder_.add_filter_height(filter_height); + builder_.add_filter_width(filter_width); + builder_.add_stride_h(stride_h); + builder_.add_stride_w(stride_w); + builder_.add_fused_activation_function(fused_activation_function); + builder_.add_padding(padding); + return builder_.Finish(); +} + +struct DepthwiseConv2DOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_PADDING = 4, + VT_STRIDE_W = 6, + VT_STRIDE_H = 8, + VT_DEPTH_MULTIPLIER = 10, + VT_FUSED_ACTIVATION_FUNCTION = 12, + VT_DILATION_W_FACTOR = 14, + VT_DILATION_H_FACTOR = 16 + }; + Padding padding() const { return static_cast(GetField(VT_PADDING, 0)); } + int32_t stride_w() const { return GetField(VT_STRIDE_W, 0); } + int32_t stride_h() const { return GetField(VT_STRIDE_H, 0); } + int32_t depth_multiplier() const { return GetField(VT_DEPTH_MULTIPLIER, 0); } + ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + int32_t dilation_w_factor() const { return GetField(VT_DILATION_W_FACTOR, 1); } + int32_t dilation_h_factor() const { return GetField(VT_DILATION_H_FACTOR, 1); } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && VerifyField(verifier, VT_PADDING) && + VerifyField(verifier, VT_STRIDE_W) && + VerifyField(verifier, VT_STRIDE_H) && + VerifyField(verifier, VT_DEPTH_MULTIPLIER) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && + VerifyField(verifier, VT_DILATION_W_FACTOR) && + VerifyField(verifier, VT_DILATION_H_FACTOR) && verifier.EndTable(); + } +}; + +struct DepthwiseConv2DOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_padding(Padding padding) + { + fbb_.AddElement(DepthwiseConv2DOptions::VT_PADDING, static_cast(padding), 0); + } + void add_stride_w(int32_t stride_w) + { + fbb_.AddElement(DepthwiseConv2DOptions::VT_STRIDE_W, stride_w, 0); + } + void add_stride_h(int32_t stride_h) + { + fbb_.AddElement(DepthwiseConv2DOptions::VT_STRIDE_H, stride_h, 0); + } + void add_depth_multiplier(int32_t depth_multiplier) + { + fbb_.AddElement(DepthwiseConv2DOptions::VT_DEPTH_MULTIPLIER, depth_multiplier, 0); + } + void add_fused_activation_function(ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(DepthwiseConv2DOptions::VT_FUSED_ACTIVATION_FUNCTION, + static_cast(fused_activation_function), 0); + } + void add_dilation_w_factor(int32_t dilation_w_factor) + { + fbb_.AddElement(DepthwiseConv2DOptions::VT_DILATION_W_FACTOR, dilation_w_factor, 1); + } + void add_dilation_h_factor(int32_t dilation_h_factor) + { + fbb_.AddElement(DepthwiseConv2DOptions::VT_DILATION_H_FACTOR, dilation_h_factor, 1); + } + explicit DepthwiseConv2DOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + DepthwiseConv2DOptionsBuilder &operator=(const DepthwiseConv2DOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateDepthwiseConv2DOptions( + flatbuffers::FlatBufferBuilder &_fbb, Padding padding = Padding_SAME, int32_t stride_w = 0, + int32_t stride_h = 0, int32_t depth_multiplier = 0, + ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE, + int32_t dilation_w_factor = 1, int32_t dilation_h_factor = 1) +{ + DepthwiseConv2DOptionsBuilder builder_(_fbb); + builder_.add_dilation_h_factor(dilation_h_factor); + builder_.add_dilation_w_factor(dilation_w_factor); + builder_.add_depth_multiplier(depth_multiplier); + builder_.add_stride_h(stride_h); + builder_.add_stride_w(stride_w); + builder_.add_fused_activation_function(fused_activation_function); + builder_.add_padding(padding); + return builder_.Finish(); +} + +struct ConcatEmbeddingsOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_NUM_CHANNELS = 4, + VT_NUM_COLUMNS_PER_CHANNEL = 6, + VT_EMBEDDING_DIM_PER_CHANNEL = 8 + }; + int32_t num_channels() const { return GetField(VT_NUM_CHANNELS, 0); } + const flatbuffers::Vector *num_columns_per_channel() const + { + return GetPointer *>(VT_NUM_COLUMNS_PER_CHANNEL); + } + const flatbuffers::Vector *embedding_dim_per_channel() const + { + return GetPointer *>(VT_EMBEDDING_DIM_PER_CHANNEL); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && VerifyField(verifier, VT_NUM_CHANNELS) && + VerifyOffset(verifier, VT_NUM_COLUMNS_PER_CHANNEL) && + verifier.VerifyVector(num_columns_per_channel()) && + VerifyOffset(verifier, VT_EMBEDDING_DIM_PER_CHANNEL) && + verifier.VerifyVector(embedding_dim_per_channel()) && verifier.EndTable(); + } +}; + +struct ConcatEmbeddingsOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_num_channels(int32_t num_channels) + { + fbb_.AddElement(ConcatEmbeddingsOptions::VT_NUM_CHANNELS, num_channels, 0); + } + void add_num_columns_per_channel( + flatbuffers::Offset> num_columns_per_channel) + { + fbb_.AddOffset(ConcatEmbeddingsOptions::VT_NUM_COLUMNS_PER_CHANNEL, num_columns_per_channel); + } + void add_embedding_dim_per_channel( + flatbuffers::Offset> embedding_dim_per_channel) + { + fbb_.AddOffset(ConcatEmbeddingsOptions::VT_EMBEDDING_DIM_PER_CHANNEL, + embedding_dim_per_channel); + } + explicit ConcatEmbeddingsOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + ConcatEmbeddingsOptionsBuilder &operator=(const ConcatEmbeddingsOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateConcatEmbeddingsOptions( + flatbuffers::FlatBufferBuilder &_fbb, int32_t num_channels = 0, + flatbuffers::Offset> num_columns_per_channel = 0, + flatbuffers::Offset> embedding_dim_per_channel = 0) +{ + ConcatEmbeddingsOptionsBuilder builder_(_fbb); + builder_.add_embedding_dim_per_channel(embedding_dim_per_channel); + builder_.add_num_columns_per_channel(num_columns_per_channel); + builder_.add_num_channels(num_channels); + return builder_.Finish(); +} + +inline flatbuffers::Offset +CreateConcatEmbeddingsOptionsDirect(flatbuffers::FlatBufferBuilder &_fbb, int32_t num_channels = 0, + const std::vector *num_columns_per_channel = nullptr, + const std::vector *embedding_dim_per_channel = nullptr) +{ + return onert_tflite::CreateConcatEmbeddingsOptions( + _fbb, num_channels, + num_columns_per_channel ? _fbb.CreateVector(*num_columns_per_channel) : 0, + embedding_dim_per_channel ? _fbb.CreateVector(*embedding_dim_per_channel) : 0); +} + +struct LSHProjectionOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_TYPE = 4 + }; + LSHProjectionType type() const + { + return static_cast(GetField(VT_TYPE, 0)); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && VerifyField(verifier, VT_TYPE) && + verifier.EndTable(); + } +}; + +struct LSHProjectionOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_type(LSHProjectionType type) + { + fbb_.AddElement(LSHProjectionOptions::VT_TYPE, static_cast(type), 0); + } + explicit LSHProjectionOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + LSHProjectionOptionsBuilder &operator=(const LSHProjectionOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset +CreateLSHProjectionOptions(flatbuffers::FlatBufferBuilder &_fbb, + LSHProjectionType type = LSHProjectionType_UNKNOWN) +{ + LSHProjectionOptionsBuilder builder_(_fbb); + builder_.add_type(type); + return builder_.Finish(); +} + +struct SVDFOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_RANK = 4, + VT_FUSED_ACTIVATION_FUNCTION = 6, + VT_ASYMMETRIC_QUANTIZE_INPUTS = 8 + }; + int32_t rank() const { return GetField(VT_RANK, 0); } + ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + bool asymmetric_quantize_inputs() const + { + return GetField(VT_ASYMMETRIC_QUANTIZE_INPUTS, 0) != 0; + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && VerifyField(verifier, VT_RANK) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && + VerifyField(verifier, VT_ASYMMETRIC_QUANTIZE_INPUTS) && verifier.EndTable(); + } +}; + +struct SVDFOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_rank(int32_t rank) { fbb_.AddElement(SVDFOptions::VT_RANK, rank, 0); } + void add_fused_activation_function(ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(SVDFOptions::VT_FUSED_ACTIVATION_FUNCTION, + static_cast(fused_activation_function), 0); + } + void add_asymmetric_quantize_inputs(bool asymmetric_quantize_inputs) + { + fbb_.AddElement(SVDFOptions::VT_ASYMMETRIC_QUANTIZE_INPUTS, + static_cast(asymmetric_quantize_inputs), 0); + } + explicit SVDFOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + SVDFOptionsBuilder &operator=(const SVDFOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset +CreateSVDFOptions(flatbuffers::FlatBufferBuilder &_fbb, int32_t rank = 0, + ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE, + bool asymmetric_quantize_inputs = false) +{ + SVDFOptionsBuilder builder_(_fbb); + builder_.add_rank(rank); + builder_.add_asymmetric_quantize_inputs(asymmetric_quantize_inputs); + builder_.add_fused_activation_function(fused_activation_function); + return builder_.Finish(); +} + +struct RNNOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_FUSED_ACTIVATION_FUNCTION = 4, + VT_ASYMMETRIC_QUANTIZE_INPUTS = 6 + }; + ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + bool asymmetric_quantize_inputs() const + { + return GetField(VT_ASYMMETRIC_QUANTIZE_INPUTS, 0) != 0; + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && + VerifyField(verifier, VT_ASYMMETRIC_QUANTIZE_INPUTS) && verifier.EndTable(); + } +}; + +struct RNNOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_fused_activation_function(ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(RNNOptions::VT_FUSED_ACTIVATION_FUNCTION, + static_cast(fused_activation_function), 0); + } + void add_asymmetric_quantize_inputs(bool asymmetric_quantize_inputs) + { + fbb_.AddElement(RNNOptions::VT_ASYMMETRIC_QUANTIZE_INPUTS, + static_cast(asymmetric_quantize_inputs), 0); + } + explicit RNNOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + RNNOptionsBuilder &operator=(const RNNOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset +CreateRNNOptions(flatbuffers::FlatBufferBuilder &_fbb, + ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE, + bool asymmetric_quantize_inputs = false) +{ + RNNOptionsBuilder builder_(_fbb); + builder_.add_asymmetric_quantize_inputs(asymmetric_quantize_inputs); + builder_.add_fused_activation_function(fused_activation_function); + return builder_.Finish(); +} + +struct SequenceRNNOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_TIME_MAJOR = 4, + VT_FUSED_ACTIVATION_FUNCTION = 6, + VT_ASYMMETRIC_QUANTIZE_INPUTS = 8 + }; + bool time_major() const { return GetField(VT_TIME_MAJOR, 0) != 0; } + ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + bool asymmetric_quantize_inputs() const + { + return GetField(VT_ASYMMETRIC_QUANTIZE_INPUTS, 0) != 0; + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && VerifyField(verifier, VT_TIME_MAJOR) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && + VerifyField(verifier, VT_ASYMMETRIC_QUANTIZE_INPUTS) && verifier.EndTable(); + } +}; + +struct SequenceRNNOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_time_major(bool time_major) + { + fbb_.AddElement(SequenceRNNOptions::VT_TIME_MAJOR, static_cast(time_major), + 0); + } + void add_fused_activation_function(ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(SequenceRNNOptions::VT_FUSED_ACTIVATION_FUNCTION, + static_cast(fused_activation_function), 0); + } + void add_asymmetric_quantize_inputs(bool asymmetric_quantize_inputs) + { + fbb_.AddElement(SequenceRNNOptions::VT_ASYMMETRIC_QUANTIZE_INPUTS, + static_cast(asymmetric_quantize_inputs), 0); + } + explicit SequenceRNNOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + SequenceRNNOptionsBuilder &operator=(const SequenceRNNOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateSequenceRNNOptions( + flatbuffers::FlatBufferBuilder &_fbb, bool time_major = false, + ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE, + bool asymmetric_quantize_inputs = false) +{ + SequenceRNNOptionsBuilder builder_(_fbb); + builder_.add_asymmetric_quantize_inputs(asymmetric_quantize_inputs); + builder_.add_fused_activation_function(fused_activation_function); + builder_.add_time_major(time_major); + return builder_.Finish(); +} + +struct BidirectionalSequenceRNNOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_TIME_MAJOR = 4, + VT_FUSED_ACTIVATION_FUNCTION = 6, + VT_MERGE_OUTPUTS = 8, + VT_ASYMMETRIC_QUANTIZE_INPUTS = 10 + }; + bool time_major() const { return GetField(VT_TIME_MAJOR, 0) != 0; } + ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + bool merge_outputs() const { return GetField(VT_MERGE_OUTPUTS, 0) != 0; } + bool asymmetric_quantize_inputs() const + { + return GetField(VT_ASYMMETRIC_QUANTIZE_INPUTS, 0) != 0; + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && VerifyField(verifier, VT_TIME_MAJOR) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && + VerifyField(verifier, VT_MERGE_OUTPUTS) && + VerifyField(verifier, VT_ASYMMETRIC_QUANTIZE_INPUTS) && verifier.EndTable(); + } +}; + +struct BidirectionalSequenceRNNOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_time_major(bool time_major) + { + fbb_.AddElement(BidirectionalSequenceRNNOptions::VT_TIME_MAJOR, + static_cast(time_major), 0); + } + void add_fused_activation_function(ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(BidirectionalSequenceRNNOptions::VT_FUSED_ACTIVATION_FUNCTION, + static_cast(fused_activation_function), 0); + } + void add_merge_outputs(bool merge_outputs) + { + fbb_.AddElement(BidirectionalSequenceRNNOptions::VT_MERGE_OUTPUTS, + static_cast(merge_outputs), 0); + } + void add_asymmetric_quantize_inputs(bool asymmetric_quantize_inputs) + { + fbb_.AddElement(BidirectionalSequenceRNNOptions::VT_ASYMMETRIC_QUANTIZE_INPUTS, + static_cast(asymmetric_quantize_inputs), 0); + } + explicit BidirectionalSequenceRNNOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + BidirectionalSequenceRNNOptionsBuilder &operator=(const BidirectionalSequenceRNNOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateBidirectionalSequenceRNNOptions( + flatbuffers::FlatBufferBuilder &_fbb, bool time_major = false, + ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE, + bool merge_outputs = false, bool asymmetric_quantize_inputs = false) +{ + BidirectionalSequenceRNNOptionsBuilder builder_(_fbb); + builder_.add_asymmetric_quantize_inputs(asymmetric_quantize_inputs); + builder_.add_merge_outputs(merge_outputs); + builder_.add_fused_activation_function(fused_activation_function); + builder_.add_time_major(time_major); + return builder_.Finish(); +} + +struct FullyConnectedOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_FUSED_ACTIVATION_FUNCTION = 4, + VT_WEIGHTS_FORMAT = 6, + VT_KEEP_NUM_DIMS = 8, + VT_ASYMMETRIC_QUANTIZE_INPUTS = 10 + }; + ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + FullyConnectedOptionsWeightsFormat weights_format() const + { + return static_cast(GetField(VT_WEIGHTS_FORMAT, 0)); + } + bool keep_num_dims() const { return GetField(VT_KEEP_NUM_DIMS, 0) != 0; } + bool asymmetric_quantize_inputs() const + { + return GetField(VT_ASYMMETRIC_QUANTIZE_INPUTS, 0) != 0; + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && + VerifyField(verifier, VT_WEIGHTS_FORMAT) && + VerifyField(verifier, VT_KEEP_NUM_DIMS) && + VerifyField(verifier, VT_ASYMMETRIC_QUANTIZE_INPUTS) && verifier.EndTable(); + } +}; + +struct FullyConnectedOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_fused_activation_function(ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(FullyConnectedOptions::VT_FUSED_ACTIVATION_FUNCTION, + static_cast(fused_activation_function), 0); + } + void add_weights_format(FullyConnectedOptionsWeightsFormat weights_format) + { + fbb_.AddElement(FullyConnectedOptions::VT_WEIGHTS_FORMAT, + static_cast(weights_format), 0); + } + void add_keep_num_dims(bool keep_num_dims) + { + fbb_.AddElement(FullyConnectedOptions::VT_KEEP_NUM_DIMS, + static_cast(keep_num_dims), 0); + } + void add_asymmetric_quantize_inputs(bool asymmetric_quantize_inputs) + { + fbb_.AddElement(FullyConnectedOptions::VT_ASYMMETRIC_QUANTIZE_INPUTS, + static_cast(asymmetric_quantize_inputs), 0); + } + explicit FullyConnectedOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + FullyConnectedOptionsBuilder &operator=(const FullyConnectedOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateFullyConnectedOptions( + flatbuffers::FlatBufferBuilder &_fbb, + ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE, + FullyConnectedOptionsWeightsFormat weights_format = FullyConnectedOptionsWeightsFormat_DEFAULT, + bool keep_num_dims = false, bool asymmetric_quantize_inputs = false) +{ + FullyConnectedOptionsBuilder builder_(_fbb); + builder_.add_asymmetric_quantize_inputs(asymmetric_quantize_inputs); + builder_.add_keep_num_dims(keep_num_dims); + builder_.add_weights_format(weights_format); + builder_.add_fused_activation_function(fused_activation_function); + return builder_.Finish(); +} + +struct SoftmaxOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_BETA = 4 + }; + float beta() const { return GetField(VT_BETA, 0.0f); } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && VerifyField(verifier, VT_BETA) && + verifier.EndTable(); + } +}; + +struct SoftmaxOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_beta(float beta) { fbb_.AddElement(SoftmaxOptions::VT_BETA, beta, 0.0f); } + explicit SoftmaxOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + SoftmaxOptionsBuilder &operator=(const SoftmaxOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset +CreateSoftmaxOptions(flatbuffers::FlatBufferBuilder &_fbb, float beta = 0.0f) +{ + SoftmaxOptionsBuilder builder_(_fbb); + builder_.add_beta(beta); + return builder_.Finish(); +} + +struct ConcatenationOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_AXIS = 4, + VT_FUSED_ACTIVATION_FUNCTION = 6 + }; + int32_t axis() const { return GetField(VT_AXIS, 0); } + ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && VerifyField(verifier, VT_AXIS) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && verifier.EndTable(); + } +}; + +struct ConcatenationOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_axis(int32_t axis) { fbb_.AddElement(ConcatenationOptions::VT_AXIS, axis, 0); } + void add_fused_activation_function(ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(ConcatenationOptions::VT_FUSED_ACTIVATION_FUNCTION, + static_cast(fused_activation_function), 0); + } + explicit ConcatenationOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + ConcatenationOptionsBuilder &operator=(const ConcatenationOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateConcatenationOptions( + flatbuffers::FlatBufferBuilder &_fbb, int32_t axis = 0, + ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE) +{ + ConcatenationOptionsBuilder builder_(_fbb); + builder_.add_axis(axis); + builder_.add_fused_activation_function(fused_activation_function); + return builder_.Finish(); +} + +struct AddOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_FUSED_ACTIVATION_FUNCTION = 4 + }; + ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && verifier.EndTable(); + } +}; + +struct AddOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_fused_activation_function(ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(AddOptions::VT_FUSED_ACTIVATION_FUNCTION, + static_cast(fused_activation_function), 0); + } + explicit AddOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + AddOptionsBuilder &operator=(const AddOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset +CreateAddOptions(flatbuffers::FlatBufferBuilder &_fbb, + ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE) +{ + AddOptionsBuilder builder_(_fbb); + builder_.add_fused_activation_function(fused_activation_function); + return builder_.Finish(); +} + +struct MulOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_FUSED_ACTIVATION_FUNCTION = 4 + }; + ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && verifier.EndTable(); + } +}; + +struct MulOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_fused_activation_function(ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(MulOptions::VT_FUSED_ACTIVATION_FUNCTION, + static_cast(fused_activation_function), 0); + } + explicit MulOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + MulOptionsBuilder &operator=(const MulOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset +CreateMulOptions(flatbuffers::FlatBufferBuilder &_fbb, + ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE) +{ + MulOptionsBuilder builder_(_fbb); + builder_.add_fused_activation_function(fused_activation_function); + return builder_.Finish(); +} + +struct L2NormOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_FUSED_ACTIVATION_FUNCTION = 4 + }; + ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && verifier.EndTable(); + } +}; + +struct L2NormOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_fused_activation_function(ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(L2NormOptions::VT_FUSED_ACTIVATION_FUNCTION, + static_cast(fused_activation_function), 0); + } + explicit L2NormOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + L2NormOptionsBuilder &operator=(const L2NormOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset +CreateL2NormOptions(flatbuffers::FlatBufferBuilder &_fbb, + ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE) +{ + L2NormOptionsBuilder builder_(_fbb); + builder_.add_fused_activation_function(fused_activation_function); + return builder_.Finish(); +} + +struct LocalResponseNormalizationOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_RADIUS = 4, + VT_BIAS = 6, + VT_ALPHA = 8, + VT_BETA = 10 + }; + int32_t radius() const { return GetField(VT_RADIUS, 0); } + float bias() const { return GetField(VT_BIAS, 0.0f); } + float alpha() const { return GetField(VT_ALPHA, 0.0f); } + float beta() const { return GetField(VT_BETA, 0.0f); } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && VerifyField(verifier, VT_RADIUS) && + VerifyField(verifier, VT_BIAS) && VerifyField(verifier, VT_ALPHA) && + VerifyField(verifier, VT_BETA) && verifier.EndTable(); + } +}; + +struct LocalResponseNormalizationOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_radius(int32_t radius) + { + fbb_.AddElement(LocalResponseNormalizationOptions::VT_RADIUS, radius, 0); + } + void add_bias(float bias) + { + fbb_.AddElement(LocalResponseNormalizationOptions::VT_BIAS, bias, 0.0f); + } + void add_alpha(float alpha) + { + fbb_.AddElement(LocalResponseNormalizationOptions::VT_ALPHA, alpha, 0.0f); + } + void add_beta(float beta) + { + fbb_.AddElement(LocalResponseNormalizationOptions::VT_BETA, beta, 0.0f); + } + explicit LocalResponseNormalizationOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + LocalResponseNormalizationOptionsBuilder & + operator=(const LocalResponseNormalizationOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset +CreateLocalResponseNormalizationOptions(flatbuffers::FlatBufferBuilder &_fbb, int32_t radius = 0, + float bias = 0.0f, float alpha = 0.0f, float beta = 0.0f) +{ + LocalResponseNormalizationOptionsBuilder builder_(_fbb); + builder_.add_beta(beta); + builder_.add_alpha(alpha); + builder_.add_bias(bias); + builder_.add_radius(radius); + return builder_.Finish(); +} + +struct LSTMOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_FUSED_ACTIVATION_FUNCTION = 4, + VT_CELL_CLIP = 6, + VT_PROJ_CLIP = 8, + VT_KERNEL_TYPE = 10, + VT_ASYMMETRIC_QUANTIZE_INPUTS = 12 + }; + ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + float cell_clip() const { return GetField(VT_CELL_CLIP, 0.0f); } + float proj_clip() const { return GetField(VT_PROJ_CLIP, 0.0f); } + LSTMKernelType kernel_type() const + { + return static_cast(GetField(VT_KERNEL_TYPE, 0)); + } + bool asymmetric_quantize_inputs() const + { + return GetField(VT_ASYMMETRIC_QUANTIZE_INPUTS, 0) != 0; + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && + VerifyField(verifier, VT_CELL_CLIP) && + VerifyField(verifier, VT_PROJ_CLIP) && + VerifyField(verifier, VT_KERNEL_TYPE) && + VerifyField(verifier, VT_ASYMMETRIC_QUANTIZE_INPUTS) && verifier.EndTable(); + } +}; + +struct LSTMOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_fused_activation_function(ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(LSTMOptions::VT_FUSED_ACTIVATION_FUNCTION, + static_cast(fused_activation_function), 0); + } + void add_cell_clip(float cell_clip) + { + fbb_.AddElement(LSTMOptions::VT_CELL_CLIP, cell_clip, 0.0f); + } + void add_proj_clip(float proj_clip) + { + fbb_.AddElement(LSTMOptions::VT_PROJ_CLIP, proj_clip, 0.0f); + } + void add_kernel_type(LSTMKernelType kernel_type) + { + fbb_.AddElement(LSTMOptions::VT_KERNEL_TYPE, static_cast(kernel_type), 0); + } + void add_asymmetric_quantize_inputs(bool asymmetric_quantize_inputs) + { + fbb_.AddElement(LSTMOptions::VT_ASYMMETRIC_QUANTIZE_INPUTS, + static_cast(asymmetric_quantize_inputs), 0); + } + explicit LSTMOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + LSTMOptionsBuilder &operator=(const LSTMOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset +CreateLSTMOptions(flatbuffers::FlatBufferBuilder &_fbb, + ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE, + float cell_clip = 0.0f, float proj_clip = 0.0f, + LSTMKernelType kernel_type = LSTMKernelType_FULL, + bool asymmetric_quantize_inputs = false) +{ + LSTMOptionsBuilder builder_(_fbb); + builder_.add_proj_clip(proj_clip); + builder_.add_cell_clip(cell_clip); + builder_.add_asymmetric_quantize_inputs(asymmetric_quantize_inputs); + builder_.add_kernel_type(kernel_type); + builder_.add_fused_activation_function(fused_activation_function); + return builder_.Finish(); +} + +struct UnidirectionalSequenceLSTMOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_FUSED_ACTIVATION_FUNCTION = 4, + VT_CELL_CLIP = 6, + VT_PROJ_CLIP = 8, + VT_TIME_MAJOR = 10, + VT_ASYMMETRIC_QUANTIZE_INPUTS = 12 + }; + ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + float cell_clip() const { return GetField(VT_CELL_CLIP, 0.0f); } + float proj_clip() const { return GetField(VT_PROJ_CLIP, 0.0f); } + bool time_major() const { return GetField(VT_TIME_MAJOR, 0) != 0; } + bool asymmetric_quantize_inputs() const + { + return GetField(VT_ASYMMETRIC_QUANTIZE_INPUTS, 0) != 0; + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && + VerifyField(verifier, VT_CELL_CLIP) && + VerifyField(verifier, VT_PROJ_CLIP) && + VerifyField(verifier, VT_TIME_MAJOR) && + VerifyField(verifier, VT_ASYMMETRIC_QUANTIZE_INPUTS) && verifier.EndTable(); + } +}; + +struct UnidirectionalSequenceLSTMOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_fused_activation_function(ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(UnidirectionalSequenceLSTMOptions::VT_FUSED_ACTIVATION_FUNCTION, + static_cast(fused_activation_function), 0); + } + void add_cell_clip(float cell_clip) + { + fbb_.AddElement(UnidirectionalSequenceLSTMOptions::VT_CELL_CLIP, cell_clip, 0.0f); + } + void add_proj_clip(float proj_clip) + { + fbb_.AddElement(UnidirectionalSequenceLSTMOptions::VT_PROJ_CLIP, proj_clip, 0.0f); + } + void add_time_major(bool time_major) + { + fbb_.AddElement(UnidirectionalSequenceLSTMOptions::VT_TIME_MAJOR, + static_cast(time_major), 0); + } + void add_asymmetric_quantize_inputs(bool asymmetric_quantize_inputs) + { + fbb_.AddElement(UnidirectionalSequenceLSTMOptions::VT_ASYMMETRIC_QUANTIZE_INPUTS, + static_cast(asymmetric_quantize_inputs), 0); + } + explicit UnidirectionalSequenceLSTMOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + UnidirectionalSequenceLSTMOptionsBuilder & + operator=(const UnidirectionalSequenceLSTMOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset +CreateUnidirectionalSequenceLSTMOptions( + flatbuffers::FlatBufferBuilder &_fbb, + ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE, + float cell_clip = 0.0f, float proj_clip = 0.0f, bool time_major = false, + bool asymmetric_quantize_inputs = false) +{ + UnidirectionalSequenceLSTMOptionsBuilder builder_(_fbb); + builder_.add_proj_clip(proj_clip); + builder_.add_cell_clip(cell_clip); + builder_.add_asymmetric_quantize_inputs(asymmetric_quantize_inputs); + builder_.add_time_major(time_major); + builder_.add_fused_activation_function(fused_activation_function); + return builder_.Finish(); +} + +struct BidirectionalSequenceLSTMOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_FUSED_ACTIVATION_FUNCTION = 4, + VT_CELL_CLIP = 6, + VT_PROJ_CLIP = 8, + VT_MERGE_OUTPUTS = 10, + VT_TIME_MAJOR = 12, + VT_ASYMMETRIC_QUANTIZE_INPUTS = 14 + }; + ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + float cell_clip() const { return GetField(VT_CELL_CLIP, 0.0f); } + float proj_clip() const { return GetField(VT_PROJ_CLIP, 0.0f); } + bool merge_outputs() const { return GetField(VT_MERGE_OUTPUTS, 0) != 0; } + bool time_major() const { return GetField(VT_TIME_MAJOR, 1) != 0; } + bool asymmetric_quantize_inputs() const + { + return GetField(VT_ASYMMETRIC_QUANTIZE_INPUTS, 0) != 0; + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && + VerifyField(verifier, VT_CELL_CLIP) && + VerifyField(verifier, VT_PROJ_CLIP) && + VerifyField(verifier, VT_MERGE_OUTPUTS) && + VerifyField(verifier, VT_TIME_MAJOR) && + VerifyField(verifier, VT_ASYMMETRIC_QUANTIZE_INPUTS) && verifier.EndTable(); + } +}; + +struct BidirectionalSequenceLSTMOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_fused_activation_function(ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(BidirectionalSequenceLSTMOptions::VT_FUSED_ACTIVATION_FUNCTION, + static_cast(fused_activation_function), 0); + } + void add_cell_clip(float cell_clip) + { + fbb_.AddElement(BidirectionalSequenceLSTMOptions::VT_CELL_CLIP, cell_clip, 0.0f); + } + void add_proj_clip(float proj_clip) + { + fbb_.AddElement(BidirectionalSequenceLSTMOptions::VT_PROJ_CLIP, proj_clip, 0.0f); + } + void add_merge_outputs(bool merge_outputs) + { + fbb_.AddElement(BidirectionalSequenceLSTMOptions::VT_MERGE_OUTPUTS, + static_cast(merge_outputs), 0); + } + void add_time_major(bool time_major) + { + fbb_.AddElement(BidirectionalSequenceLSTMOptions::VT_TIME_MAJOR, + static_cast(time_major), 1); + } + void add_asymmetric_quantize_inputs(bool asymmetric_quantize_inputs) + { + fbb_.AddElement(BidirectionalSequenceLSTMOptions::VT_ASYMMETRIC_QUANTIZE_INPUTS, + static_cast(asymmetric_quantize_inputs), 0); + } + explicit BidirectionalSequenceLSTMOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + BidirectionalSequenceLSTMOptionsBuilder & + operator=(const BidirectionalSequenceLSTMOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateBidirectionalSequenceLSTMOptions( + flatbuffers::FlatBufferBuilder &_fbb, + ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE, + float cell_clip = 0.0f, float proj_clip = 0.0f, bool merge_outputs = false, + bool time_major = true, bool asymmetric_quantize_inputs = false) +{ + BidirectionalSequenceLSTMOptionsBuilder builder_(_fbb); + builder_.add_proj_clip(proj_clip); + builder_.add_cell_clip(cell_clip); + builder_.add_asymmetric_quantize_inputs(asymmetric_quantize_inputs); + builder_.add_time_major(time_major); + builder_.add_merge_outputs(merge_outputs); + builder_.add_fused_activation_function(fused_activation_function); + return builder_.Finish(); +} + +struct ResizeBilinearOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_ALIGN_CORNERS = 8, + VT_HALF_PIXEL_CENTERS = 10 + }; + bool align_corners() const { return GetField(VT_ALIGN_CORNERS, 0) != 0; } + bool half_pixel_centers() const { return GetField(VT_HALF_PIXEL_CENTERS, 0) != 0; } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && VerifyField(verifier, VT_ALIGN_CORNERS) && + VerifyField(verifier, VT_HALF_PIXEL_CENTERS) && verifier.EndTable(); + } +}; + +struct ResizeBilinearOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_align_corners(bool align_corners) + { + fbb_.AddElement(ResizeBilinearOptions::VT_ALIGN_CORNERS, + static_cast(align_corners), 0); + } + void add_half_pixel_centers(bool half_pixel_centers) + { + fbb_.AddElement(ResizeBilinearOptions::VT_HALF_PIXEL_CENTERS, + static_cast(half_pixel_centers), 0); + } + explicit ResizeBilinearOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + ResizeBilinearOptionsBuilder &operator=(const ResizeBilinearOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset +CreateResizeBilinearOptions(flatbuffers::FlatBufferBuilder &_fbb, bool align_corners = false, + bool half_pixel_centers = false) +{ + ResizeBilinearOptionsBuilder builder_(_fbb); + builder_.add_half_pixel_centers(half_pixel_centers); + builder_.add_align_corners(align_corners); + return builder_.Finish(); +} + +struct ResizeNearestNeighborOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_ALIGN_CORNERS = 4 + }; + bool align_corners() const { return GetField(VT_ALIGN_CORNERS, 0) != 0; } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && VerifyField(verifier, VT_ALIGN_CORNERS) && + verifier.EndTable(); + } +}; + +struct ResizeNearestNeighborOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_align_corners(bool align_corners) + { + fbb_.AddElement(ResizeNearestNeighborOptions::VT_ALIGN_CORNERS, + static_cast(align_corners), 0); + } + explicit ResizeNearestNeighborOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + ResizeNearestNeighborOptionsBuilder &operator=(const ResizeNearestNeighborOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset +CreateResizeNearestNeighborOptions(flatbuffers::FlatBufferBuilder &_fbb, bool align_corners = false) +{ + ResizeNearestNeighborOptionsBuilder builder_(_fbb); + builder_.add_align_corners(align_corners); + return builder_.Finish(); +} + +struct CallOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_SUBGRAPH = 4 + }; + uint32_t subgraph() const { return GetField(VT_SUBGRAPH, 0); } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && VerifyField(verifier, VT_SUBGRAPH) && + verifier.EndTable(); + } +}; + +struct CallOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_subgraph(uint32_t subgraph) + { + fbb_.AddElement(CallOptions::VT_SUBGRAPH, subgraph, 0); + } + explicit CallOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + CallOptionsBuilder &operator=(const CallOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateCallOptions(flatbuffers::FlatBufferBuilder &_fbb, + uint32_t subgraph = 0) +{ + CallOptionsBuilder builder_(_fbb); + builder_.add_subgraph(subgraph); + return builder_.Finish(); +} + +struct PadOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && verifier.EndTable(); + } +}; + +struct PadOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit PadOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + PadOptionsBuilder &operator=(const PadOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreatePadOptions(flatbuffers::FlatBufferBuilder &_fbb) +{ + PadOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +struct PadV2Options FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && verifier.EndTable(); + } +}; + +struct PadV2OptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit PadV2OptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + PadV2OptionsBuilder &operator=(const PadV2OptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreatePadV2Options(flatbuffers::FlatBufferBuilder &_fbb) +{ + PadV2OptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +struct ReshapeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_NEW_SHAPE = 4 + }; + const flatbuffers::Vector *new_shape() const + { + return GetPointer *>(VT_NEW_SHAPE); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && VerifyOffset(verifier, VT_NEW_SHAPE) && + verifier.VerifyVector(new_shape()) && verifier.EndTable(); + } +}; + +struct ReshapeOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_new_shape(flatbuffers::Offset> new_shape) + { + fbb_.AddOffset(ReshapeOptions::VT_NEW_SHAPE, new_shape); + } + explicit ReshapeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + ReshapeOptionsBuilder &operator=(const ReshapeOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset +CreateReshapeOptions(flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset> new_shape = 0) +{ + ReshapeOptionsBuilder builder_(_fbb); + builder_.add_new_shape(new_shape); + return builder_.Finish(); +} + +inline flatbuffers::Offset +CreateReshapeOptionsDirect(flatbuffers::FlatBufferBuilder &_fbb, + const std::vector *new_shape = nullptr) +{ + return onert_tflite::CreateReshapeOptions(_fbb, + new_shape ? _fbb.CreateVector(*new_shape) : 0); +} + +struct SpaceToBatchNDOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && verifier.EndTable(); + } +}; + +struct SpaceToBatchNDOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit SpaceToBatchNDOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + SpaceToBatchNDOptionsBuilder &operator=(const SpaceToBatchNDOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset +CreateSpaceToBatchNDOptions(flatbuffers::FlatBufferBuilder &_fbb) +{ + SpaceToBatchNDOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +struct BatchToSpaceNDOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && verifier.EndTable(); + } +}; + +struct BatchToSpaceNDOptionsBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit BatchToSpaceNDOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + BatchToSpaceNDOptionsBuilder &operator=(const BatchToSpaceNDOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset +CreateBatchToSpaceNDOptions(flatbuffers::FlatBufferBuilder &_fbb) +{ + BatchToSpaceNDOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +struct SkipGramOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_NGRAM_SIZE = 4, + VT_MAX_SKIP_SIZE = 6, + VT_INCLUDE_ALL_NGRAMS = 8 + }; + int32_t ngram_size() const { return GetField(VT_NGRAM_SIZE, 0); } + int32_t max_skip_size() const { return GetField(VT_MAX_SKIP_SIZE, 0); } + bool include_all_ngrams() const { return GetField(VT_INCLUDE_ALL_NGRAMS, 0) != 0; } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && VerifyField(verifier, VT_NGRAM_SIZE) && + VerifyField(verifier, VT_MAX_SKIP_SIZE) && + VerifyField(verifier, VT_INCLUDE_ALL_NGRAMS) && verifier.EndTable(); + } +}; + +struct SkipGramOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_rank(int32_t rank) { fbb_.AddElement(SVDFOptions::VT_RANK, rank, 0); } - void add_fused_activation_function(ActivationFunctionType fused_activation_function) + void add_ngram_size(int32_t ngram_size) { - fbb_.AddElement(SVDFOptions::VT_FUSED_ACTIVATION_FUNCTION, - static_cast(fused_activation_function), 0); + fbb_.AddElement(SkipGramOptions::VT_NGRAM_SIZE, ngram_size, 0); } - explicit SVDFOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + void add_max_skip_size(int32_t max_skip_size) + { + fbb_.AddElement(SkipGramOptions::VT_MAX_SKIP_SIZE, max_skip_size, 0); + } + void add_include_all_ngrams(bool include_all_ngrams) + { + fbb_.AddElement(SkipGramOptions::VT_INCLUDE_ALL_NGRAMS, + static_cast(include_all_ngrams), 0); + } + explicit SkipGramOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - SVDFOptionsBuilder &operator=(const SVDFOptionsBuilder &); - flatbuffers::Offset Finish() + SkipGramOptionsBuilder &operator=(const SkipGramOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateSVDFOptions(flatbuffers::FlatBufferBuilder &_fbb, int32_t rank = 0, - ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE) +inline flatbuffers::Offset +CreateSkipGramOptions(flatbuffers::FlatBufferBuilder &_fbb, int32_t ngram_size = 0, + int32_t max_skip_size = 0, bool include_all_ngrams = false) { - SVDFOptionsBuilder builder_(_fbb); - builder_.add_rank(rank); - builder_.add_fused_activation_function(fused_activation_function); + SkipGramOptionsBuilder builder_(_fbb); + builder_.add_max_skip_size(max_skip_size); + builder_.add_ngram_size(ngram_size); + builder_.add_include_all_ngrams(include_all_ngrams); return builder_.Finish(); } -struct RNNOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct SpaceToDepthOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_FUSED_ACTIVATION_FUNCTION = 4 + VT_BLOCK_SIZE = 4 }; - ActivationFunctionType fused_activation_function() const - { - return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); - } + int32_t block_size() const { return GetField(VT_BLOCK_SIZE, 0); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyField(verifier, VT_BLOCK_SIZE) && + verifier.EndTable(); } }; -struct RNNOptionsBuilder +struct SpaceToDepthOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_fused_activation_function(ActivationFunctionType fused_activation_function) + void add_block_size(int32_t block_size) { - fbb_.AddElement(RNNOptions::VT_FUSED_ACTIVATION_FUNCTION, - static_cast(fused_activation_function), 0); + fbb_.AddElement(SpaceToDepthOptions::VT_BLOCK_SIZE, block_size, 0); } - explicit RNNOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit SpaceToDepthOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - RNNOptionsBuilder &operator=(const RNNOptionsBuilder &); - flatbuffers::Offset Finish() + SpaceToDepthOptionsBuilder &operator=(const SpaceToDepthOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateRNNOptions(flatbuffers::FlatBufferBuilder &_fbb, - ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE) +inline flatbuffers::Offset +CreateSpaceToDepthOptions(flatbuffers::FlatBufferBuilder &_fbb, int32_t block_size = 0) { - RNNOptionsBuilder builder_(_fbb); - builder_.add_fused_activation_function(fused_activation_function); + SpaceToDepthOptionsBuilder builder_(_fbb); + builder_.add_block_size(block_size); return builder_.Finish(); } -struct SequenceRNNOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct DepthToSpaceOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_TIME_MAJOR = 4, - VT_FUSED_ACTIVATION_FUNCTION = 6 + VT_BLOCK_SIZE = 4 }; - bool time_major() const { return GetField(VT_TIME_MAJOR, 0) != 0; } - ActivationFunctionType fused_activation_function() const - { - return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); - } + int32_t block_size() const { return GetField(VT_BLOCK_SIZE, 0); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_TIME_MAJOR) && - VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyField(verifier, VT_BLOCK_SIZE) && + verifier.EndTable(); } }; -struct SequenceRNNOptionsBuilder +struct DepthToSpaceOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_time_major(bool time_major) - { - fbb_.AddElement(SequenceRNNOptions::VT_TIME_MAJOR, static_cast(time_major), - 0); - } - void add_fused_activation_function(ActivationFunctionType fused_activation_function) + void add_block_size(int32_t block_size) { - fbb_.AddElement(SequenceRNNOptions::VT_FUSED_ACTIVATION_FUNCTION, - static_cast(fused_activation_function), 0); + fbb_.AddElement(DepthToSpaceOptions::VT_BLOCK_SIZE, block_size, 0); } - explicit SequenceRNNOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit DepthToSpaceOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - SequenceRNNOptionsBuilder &operator=(const SequenceRNNOptionsBuilder &); - flatbuffers::Offset Finish() + DepthToSpaceOptionsBuilder &operator=(const DepthToSpaceOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateSequenceRNNOptions( - flatbuffers::FlatBufferBuilder &_fbb, bool time_major = false, - ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE) +inline flatbuffers::Offset +CreateDepthToSpaceOptions(flatbuffers::FlatBufferBuilder &_fbb, int32_t block_size = 0) { - SequenceRNNOptionsBuilder builder_(_fbb); - builder_.add_fused_activation_function(fused_activation_function); - builder_.add_time_major(time_major); + DepthToSpaceOptionsBuilder builder_(_fbb); + builder_.add_block_size(block_size); return builder_.Finish(); } -struct BidirectionalSequenceRNNOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct SubOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_TIME_MAJOR = 4, - VT_FUSED_ACTIVATION_FUNCTION = 6, - VT_MERGE_OUTPUTS = 8 + VT_FUSED_ACTIVATION_FUNCTION = 4 }; - bool time_major() const { return GetField(VT_TIME_MAJOR, 0) != 0; } ActivationFunctionType fused_activation_function() const { return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); } - bool merge_outputs() const { return GetField(VT_MERGE_OUTPUTS, 0) != 0; } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_TIME_MAJOR) && - VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && - VerifyField(verifier, VT_MERGE_OUTPUTS) && verifier.EndTable(); + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && verifier.EndTable(); } }; -struct BidirectionalSequenceRNNOptionsBuilder +struct SubOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_time_major(bool time_major) - { - fbb_.AddElement(BidirectionalSequenceRNNOptions::VT_TIME_MAJOR, - static_cast(time_major), 0); - } void add_fused_activation_function(ActivationFunctionType fused_activation_function) { - fbb_.AddElement(BidirectionalSequenceRNNOptions::VT_FUSED_ACTIVATION_FUNCTION, + fbb_.AddElement(SubOptions::VT_FUSED_ACTIVATION_FUNCTION, static_cast(fused_activation_function), 0); } - void add_merge_outputs(bool merge_outputs) - { - fbb_.AddElement(BidirectionalSequenceRNNOptions::VT_MERGE_OUTPUTS, - static_cast(merge_outputs), 0); - } - explicit BidirectionalSequenceRNNOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit SubOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - BidirectionalSequenceRNNOptionsBuilder &operator=(const BidirectionalSequenceRNNOptionsBuilder &); - flatbuffers::Offset Finish() + SubOptionsBuilder &operator=(const SubOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateBidirectionalSequenceRNNOptions( - flatbuffers::FlatBufferBuilder &_fbb, bool time_major = false, - ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE, - bool merge_outputs = false) +inline flatbuffers::Offset +CreateSubOptions(flatbuffers::FlatBufferBuilder &_fbb, + ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE) { - BidirectionalSequenceRNNOptionsBuilder builder_(_fbb); - builder_.add_merge_outputs(merge_outputs); + SubOptionsBuilder builder_(_fbb); builder_.add_fused_activation_function(fused_activation_function); - builder_.add_time_major(time_major); return builder_.Finish(); } -struct FullyConnectedOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct DivOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_FUSED_ACTIVATION_FUNCTION = 4, - VT_WEIGHTS_FORMAT = 6 + VT_FUSED_ACTIVATION_FUNCTION = 4 }; ActivationFunctionType fused_activation_function() const { return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); } - FullyConnectedOptionsWeightsFormat weights_format() const - { - return static_cast(GetField(VT_WEIGHTS_FORMAT, 0)); - } bool Verify(flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && - VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && - VerifyField(verifier, VT_WEIGHTS_FORMAT) && verifier.EndTable(); + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && verifier.EndTable(); } }; -struct FullyConnectedOptionsBuilder +struct DivOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; void add_fused_activation_function(ActivationFunctionType fused_activation_function) { - fbb_.AddElement(FullyConnectedOptions::VT_FUSED_ACTIVATION_FUNCTION, + fbb_.AddElement(DivOptions::VT_FUSED_ACTIVATION_FUNCTION, static_cast(fused_activation_function), 0); } - void add_weights_format(FullyConnectedOptionsWeightsFormat weights_format) - { - fbb_.AddElement(FullyConnectedOptions::VT_WEIGHTS_FORMAT, - static_cast(weights_format), 0); - } - explicit FullyConnectedOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit DivOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - FullyConnectedOptionsBuilder &operator=(const FullyConnectedOptionsBuilder &); - flatbuffers::Offset Finish() + DivOptionsBuilder &operator=(const DivOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateFullyConnectedOptions( - flatbuffers::FlatBufferBuilder &_fbb, - ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE, - FullyConnectedOptionsWeightsFormat weights_format = FullyConnectedOptionsWeightsFormat_DEFAULT) +inline flatbuffers::Offset +CreateDivOptions(flatbuffers::FlatBufferBuilder &_fbb, + ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE) { - FullyConnectedOptionsBuilder builder_(_fbb); - builder_.add_weights_format(weights_format); + DivOptionsBuilder builder_(_fbb); builder_.add_fused_activation_function(fused_activation_function); return builder_.Finish(); } -struct SoftmaxOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct TopKV2Options FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum - { - VT_BETA = 4 - }; - float beta() const { return GetField(VT_BETA, 0.0f); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_BETA) && - verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct SoftmaxOptionsBuilder +struct TopKV2OptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_beta(float beta) { fbb_.AddElement(SoftmaxOptions::VT_BETA, beta, 0.0f); } - explicit SoftmaxOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit TopKV2OptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - SoftmaxOptionsBuilder &operator=(const SoftmaxOptionsBuilder &); - flatbuffers::Offset Finish() + TopKV2OptionsBuilder &operator=(const TopKV2OptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateSoftmaxOptions(flatbuffers::FlatBufferBuilder &_fbb, float beta = 0.0f) +inline flatbuffers::Offset CreateTopKV2Options(flatbuffers::FlatBufferBuilder &_fbb) { - SoftmaxOptionsBuilder builder_(_fbb); - builder_.add_beta(beta); + TopKV2OptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct ConcatenationOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct EmbeddingLookupSparseOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_AXIS = 4, - VT_FUSED_ACTIVATION_FUNCTION = 6 + VT_COMBINER = 4 }; - int32_t axis() const { return GetField(VT_AXIS, 0); } - ActivationFunctionType fused_activation_function() const + CombinerType combiner() const { - return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + return static_cast(GetField(VT_COMBINER, 0)); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_AXIS) && - VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyField(verifier, VT_COMBINER) && + verifier.EndTable(); } }; -struct ConcatenationOptionsBuilder +struct EmbeddingLookupSparseOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_axis(int32_t axis) { fbb_.AddElement(ConcatenationOptions::VT_AXIS, axis, 0); } - void add_fused_activation_function(ActivationFunctionType fused_activation_function) + void add_combiner(CombinerType combiner) { - fbb_.AddElement(ConcatenationOptions::VT_FUSED_ACTIVATION_FUNCTION, - static_cast(fused_activation_function), 0); + fbb_.AddElement(EmbeddingLookupSparseOptions::VT_COMBINER, + static_cast(combiner), 0); } - explicit ConcatenationOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit EmbeddingLookupSparseOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - ConcatenationOptionsBuilder &operator=(const ConcatenationOptionsBuilder &); - flatbuffers::Offset Finish() + EmbeddingLookupSparseOptionsBuilder &operator=(const EmbeddingLookupSparseOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateConcatenationOptions( - flatbuffers::FlatBufferBuilder &_fbb, int32_t axis = 0, - ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE) +inline flatbuffers::Offset +CreateEmbeddingLookupSparseOptions(flatbuffers::FlatBufferBuilder &_fbb, + CombinerType combiner = CombinerType_SUM) { - ConcatenationOptionsBuilder builder_(_fbb); - builder_.add_axis(axis); - builder_.add_fused_activation_function(fused_activation_function); + EmbeddingLookupSparseOptionsBuilder builder_(_fbb); + builder_.add_combiner(combiner); return builder_.Finish(); } -struct AddOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct GatherOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_FUSED_ACTIVATION_FUNCTION = 4 + VT_AXIS = 4 }; - ActivationFunctionType fused_activation_function() const - { - return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); - } + int32_t axis() const { return GetField(VT_AXIS, 0); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyField(verifier, VT_AXIS) && + verifier.EndTable(); } }; -struct AddOptionsBuilder +struct GatherOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_fused_activation_function(ActivationFunctionType fused_activation_function) - { - fbb_.AddElement(AddOptions::VT_FUSED_ACTIVATION_FUNCTION, - static_cast(fused_activation_function), 0); - } - explicit AddOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + void add_axis(int32_t axis) { fbb_.AddElement(GatherOptions::VT_AXIS, axis, 0); } + explicit GatherOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - AddOptionsBuilder &operator=(const AddOptionsBuilder &); - flatbuffers::Offset Finish() + GatherOptionsBuilder &operator=(const GatherOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateAddOptions(flatbuffers::FlatBufferBuilder &_fbb, - ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE) +inline flatbuffers::Offset CreateGatherOptions(flatbuffers::FlatBufferBuilder &_fbb, + int32_t axis = 0) { - AddOptionsBuilder builder_(_fbb); - builder_.add_fused_activation_function(fused_activation_function); + GatherOptionsBuilder builder_(_fbb); + builder_.add_axis(axis); return builder_.Finish(); } -struct MulOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct TransposeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum - { - VT_FUSED_ACTIVATION_FUNCTION = 4 - }; - ActivationFunctionType fused_activation_function() const - { - return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); - } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct MulOptionsBuilder +struct TransposeOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_fused_activation_function(ActivationFunctionType fused_activation_function) - { - fbb_.AddElement(MulOptions::VT_FUSED_ACTIVATION_FUNCTION, - static_cast(fused_activation_function), 0); - } - explicit MulOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit TransposeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - MulOptionsBuilder &operator=(const MulOptionsBuilder &); - flatbuffers::Offset Finish() + TransposeOptionsBuilder &operator=(const TransposeOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateMulOptions(flatbuffers::FlatBufferBuilder &_fbb, - ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE) +inline flatbuffers::Offset +CreateTransposeOptions(flatbuffers::FlatBufferBuilder &_fbb) { - MulOptionsBuilder builder_(_fbb); - builder_.add_fused_activation_function(fused_activation_function); + TransposeOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct L2NormOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct ExpOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum - { - VT_FUSED_ACTIVATION_FUNCTION = 4 - }; - ActivationFunctionType fused_activation_function() const - { - return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); - } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct L2NormOptionsBuilder +struct ExpOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_fused_activation_function(ActivationFunctionType fused_activation_function) - { - fbb_.AddElement(L2NormOptions::VT_FUSED_ACTIVATION_FUNCTION, - static_cast(fused_activation_function), 0); - } - explicit L2NormOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit ExpOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - L2NormOptionsBuilder &operator=(const L2NormOptionsBuilder &); - flatbuffers::Offset Finish() + ExpOptionsBuilder &operator=(const ExpOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateL2NormOptions(flatbuffers::FlatBufferBuilder &_fbb, - ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE) +inline flatbuffers::Offset CreateExpOptions(flatbuffers::FlatBufferBuilder &_fbb) { - L2NormOptionsBuilder builder_(_fbb); - builder_.add_fused_activation_function(fused_activation_function); + ExpOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct LocalResponseNormalizationOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct CosOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum - { - VT_RADIUS = 4, - VT_BIAS = 6, - VT_ALPHA = 8, - VT_BETA = 10 - }; - int32_t radius() const { return GetField(VT_RADIUS, 0); } - float bias() const { return GetField(VT_BIAS, 0.0f); } - float alpha() const { return GetField(VT_ALPHA, 0.0f); } - float beta() const { return GetField(VT_BETA, 0.0f); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_RADIUS) && - VerifyField(verifier, VT_BIAS) && VerifyField(verifier, VT_ALPHA) && - VerifyField(verifier, VT_BETA) && verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct LocalResponseNormalizationOptionsBuilder +struct CosOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_radius(int32_t radius) - { - fbb_.AddElement(LocalResponseNormalizationOptions::VT_RADIUS, radius, 0); - } - void add_bias(float bias) - { - fbb_.AddElement(LocalResponseNormalizationOptions::VT_BIAS, bias, 0.0f); - } - void add_alpha(float alpha) - { - fbb_.AddElement(LocalResponseNormalizationOptions::VT_ALPHA, alpha, 0.0f); - } - void add_beta(float beta) - { - fbb_.AddElement(LocalResponseNormalizationOptions::VT_BETA, beta, 0.0f); - } - explicit LocalResponseNormalizationOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) + explicit CosOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - LocalResponseNormalizationOptionsBuilder & - operator=(const LocalResponseNormalizationOptionsBuilder &); - flatbuffers::Offset Finish() + CosOptionsBuilder &operator=(const CosOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateLocalResponseNormalizationOptions(flatbuffers::FlatBufferBuilder &_fbb, int32_t radius = 0, - float bias = 0.0f, float alpha = 0.0f, float beta = 0.0f) +inline flatbuffers::Offset CreateCosOptions(flatbuffers::FlatBufferBuilder &_fbb) { - LocalResponseNormalizationOptionsBuilder builder_(_fbb); - builder_.add_beta(beta); - builder_.add_alpha(alpha); - builder_.add_bias(bias); - builder_.add_radius(radius); + CosOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct LSTMOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct ReducerOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_FUSED_ACTIVATION_FUNCTION = 4, - VT_CELL_CLIP = 6, - VT_PROJ_CLIP = 8, - VT_KERNEL_TYPE = 10 + VT_KEEP_DIMS = 4 }; - ActivationFunctionType fused_activation_function() const - { - return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); - } - float cell_clip() const { return GetField(VT_CELL_CLIP, 0.0f); } - float proj_clip() const { return GetField(VT_PROJ_CLIP, 0.0f); } - LSTMKernelType kernel_type() const - { - return static_cast(GetField(VT_KERNEL_TYPE, 0)); - } + bool keep_dims() const { return GetField(VT_KEEP_DIMS, 0) != 0; } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && - VerifyField(verifier, VT_CELL_CLIP) && - VerifyField(verifier, VT_PROJ_CLIP) && - VerifyField(verifier, VT_KERNEL_TYPE) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyField(verifier, VT_KEEP_DIMS) && + verifier.EndTable(); } }; -struct LSTMOptionsBuilder +struct ReducerOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_fused_activation_function(ActivationFunctionType fused_activation_function) - { - fbb_.AddElement(LSTMOptions::VT_FUSED_ACTIVATION_FUNCTION, - static_cast(fused_activation_function), 0); - } - void add_cell_clip(float cell_clip) - { - fbb_.AddElement(LSTMOptions::VT_CELL_CLIP, cell_clip, 0.0f); - } - void add_proj_clip(float proj_clip) - { - fbb_.AddElement(LSTMOptions::VT_PROJ_CLIP, proj_clip, 0.0f); - } - void add_kernel_type(LSTMKernelType kernel_type) + void add_keep_dims(bool keep_dims) { - fbb_.AddElement(LSTMOptions::VT_KERNEL_TYPE, static_cast(kernel_type), 0); + fbb_.AddElement(ReducerOptions::VT_KEEP_DIMS, static_cast(keep_dims), 0); } - explicit LSTMOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit ReducerOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - LSTMOptionsBuilder &operator=(const LSTMOptionsBuilder &); - flatbuffers::Offset Finish() + ReducerOptionsBuilder &operator=(const ReducerOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateLSTMOptions(flatbuffers::FlatBufferBuilder &_fbb, - ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE, - float cell_clip = 0.0f, float proj_clip = 0.0f, - LSTMKernelType kernel_type = LSTMKernelType_FULL) +inline flatbuffers::Offset +CreateReducerOptions(flatbuffers::FlatBufferBuilder &_fbb, bool keep_dims = false) { - LSTMOptionsBuilder builder_(_fbb); - builder_.add_proj_clip(proj_clip); - builder_.add_cell_clip(cell_clip); - builder_.add_kernel_type(kernel_type); - builder_.add_fused_activation_function(fused_activation_function); + ReducerOptionsBuilder builder_(_fbb); + builder_.add_keep_dims(keep_dims); return builder_.Finish(); } -struct UnidirectionalSequenceLSTMOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct SqueezeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_FUSED_ACTIVATION_FUNCTION = 4, - VT_CELL_CLIP = 6, - VT_PROJ_CLIP = 8, - VT_TIME_MAJOR = 10 + VT_SQUEEZE_DIMS = 4 }; - ActivationFunctionType fused_activation_function() const + const flatbuffers::Vector *squeeze_dims() const { - return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + return GetPointer *>(VT_SQUEEZE_DIMS); } - float cell_clip() const { return GetField(VT_CELL_CLIP, 0.0f); } - float proj_clip() const { return GetField(VT_PROJ_CLIP, 0.0f); } - bool time_major() const { return GetField(VT_TIME_MAJOR, 0) != 0; } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && - VerifyField(verifier, VT_CELL_CLIP) && - VerifyField(verifier, VT_PROJ_CLIP) && - VerifyField(verifier, VT_TIME_MAJOR) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyOffset(verifier, VT_SQUEEZE_DIMS) && + verifier.VerifyVector(squeeze_dims()) && verifier.EndTable(); } }; -struct UnidirectionalSequenceLSTMOptionsBuilder +struct SqueezeOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_fused_activation_function(ActivationFunctionType fused_activation_function) - { - fbb_.AddElement(UnidirectionalSequenceLSTMOptions::VT_FUSED_ACTIVATION_FUNCTION, - static_cast(fused_activation_function), 0); - } - void add_cell_clip(float cell_clip) - { - fbb_.AddElement(UnidirectionalSequenceLSTMOptions::VT_CELL_CLIP, cell_clip, 0.0f); - } - void add_proj_clip(float proj_clip) - { - fbb_.AddElement(UnidirectionalSequenceLSTMOptions::VT_PROJ_CLIP, proj_clip, 0.0f); - } - void add_time_major(bool time_major) + void add_squeeze_dims(flatbuffers::Offset> squeeze_dims) { - fbb_.AddElement(UnidirectionalSequenceLSTMOptions::VT_TIME_MAJOR, - static_cast(time_major), 0); + fbb_.AddOffset(SqueezeOptions::VT_SQUEEZE_DIMS, squeeze_dims); } - explicit UnidirectionalSequenceLSTMOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) + explicit SqueezeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - UnidirectionalSequenceLSTMOptionsBuilder & - operator=(const UnidirectionalSequenceLSTMOptionsBuilder &); - flatbuffers::Offset Finish() + SqueezeOptionsBuilder &operator=(const SqueezeOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateUnidirectionalSequenceLSTMOptions( - flatbuffers::FlatBufferBuilder &_fbb, - ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE, - float cell_clip = 0.0f, float proj_clip = 0.0f, bool time_major = false) +inline flatbuffers::Offset +CreateSqueezeOptions(flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset> squeeze_dims = 0) { - UnidirectionalSequenceLSTMOptionsBuilder builder_(_fbb); - builder_.add_proj_clip(proj_clip); - builder_.add_cell_clip(cell_clip); - builder_.add_time_major(time_major); - builder_.add_fused_activation_function(fused_activation_function); + SqueezeOptionsBuilder builder_(_fbb); + builder_.add_squeeze_dims(squeeze_dims); return builder_.Finish(); } -struct BidirectionalSequenceLSTMOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +inline flatbuffers::Offset +CreateSqueezeOptionsDirect(flatbuffers::FlatBufferBuilder &_fbb, + const std::vector *squeeze_dims = nullptr) +{ + return onert_tflite::CreateSqueezeOptions( + _fbb, squeeze_dims ? _fbb.CreateVector(*squeeze_dims) : 0); +} + +struct SplitOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_FUSED_ACTIVATION_FUNCTION = 4, - VT_CELL_CLIP = 6, - VT_PROJ_CLIP = 8, - VT_MERGE_OUTPUTS = 10 + VT_NUM_SPLITS = 4 }; - ActivationFunctionType fused_activation_function() const - { - return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); - } - float cell_clip() const { return GetField(VT_CELL_CLIP, 0.0f); } - float proj_clip() const { return GetField(VT_PROJ_CLIP, 0.0f); } - bool merge_outputs() const { return GetField(VT_MERGE_OUTPUTS, 0) != 0; } + int32_t num_splits() const { return GetField(VT_NUM_SPLITS, 0); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && - VerifyField(verifier, VT_CELL_CLIP) && - VerifyField(verifier, VT_PROJ_CLIP) && - VerifyField(verifier, VT_MERGE_OUTPUTS) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyField(verifier, VT_NUM_SPLITS) && + verifier.EndTable(); } }; -struct BidirectionalSequenceLSTMOptionsBuilder +struct SplitOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_fused_activation_function(ActivationFunctionType fused_activation_function) - { - fbb_.AddElement(BidirectionalSequenceLSTMOptions::VT_FUSED_ACTIVATION_FUNCTION, - static_cast(fused_activation_function), 0); - } - void add_cell_clip(float cell_clip) - { - fbb_.AddElement(BidirectionalSequenceLSTMOptions::VT_CELL_CLIP, cell_clip, 0.0f); - } - void add_proj_clip(float proj_clip) - { - fbb_.AddElement(BidirectionalSequenceLSTMOptions::VT_PROJ_CLIP, proj_clip, 0.0f); - } - void add_merge_outputs(bool merge_outputs) + void add_num_splits(int32_t num_splits) { - fbb_.AddElement(BidirectionalSequenceLSTMOptions::VT_MERGE_OUTPUTS, - static_cast(merge_outputs), 0); + fbb_.AddElement(SplitOptions::VT_NUM_SPLITS, num_splits, 0); } - explicit BidirectionalSequenceLSTMOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) + explicit SplitOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - BidirectionalSequenceLSTMOptionsBuilder & - operator=(const BidirectionalSequenceLSTMOptionsBuilder &); - flatbuffers::Offset Finish() + SplitOptionsBuilder &operator=(const SplitOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateBidirectionalSequenceLSTMOptions( - flatbuffers::FlatBufferBuilder &_fbb, - ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE, - float cell_clip = 0.0f, float proj_clip = 0.0f, bool merge_outputs = false) +inline flatbuffers::Offset CreateSplitOptions(flatbuffers::FlatBufferBuilder &_fbb, + int32_t num_splits = 0) { - BidirectionalSequenceLSTMOptionsBuilder builder_(_fbb); - builder_.add_proj_clip(proj_clip); - builder_.add_cell_clip(cell_clip); - builder_.add_merge_outputs(merge_outputs); - builder_.add_fused_activation_function(fused_activation_function); + SplitOptionsBuilder builder_(_fbb); + builder_.add_num_splits(num_splits); return builder_.Finish(); } -struct ResizeBilinearOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct SplitVOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_ALIGN_CORNERS = 8 + VT_NUM_SPLITS = 4 }; - bool align_corners() const { return GetField(VT_ALIGN_CORNERS, 0) != 0; } + int32_t num_splits() const { return GetField(VT_NUM_SPLITS, 0); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_ALIGN_CORNERS) && + return VerifyTableStart(verifier) && VerifyField(verifier, VT_NUM_SPLITS) && verifier.EndTable(); } }; -struct ResizeBilinearOptionsBuilder +struct SplitVOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_align_corners(bool align_corners) + void add_num_splits(int32_t num_splits) { - fbb_.AddElement(ResizeBilinearOptions::VT_ALIGN_CORNERS, - static_cast(align_corners), 0); + fbb_.AddElement(SplitVOptions::VT_NUM_SPLITS, num_splits, 0); } - explicit ResizeBilinearOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit SplitVOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - ResizeBilinearOptionsBuilder &operator=(const ResizeBilinearOptionsBuilder &); - flatbuffers::Offset Finish() + SplitVOptionsBuilder &operator=(const SplitVOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateResizeBilinearOptions(flatbuffers::FlatBufferBuilder &_fbb, bool align_corners = false) +inline flatbuffers::Offset CreateSplitVOptions(flatbuffers::FlatBufferBuilder &_fbb, + int32_t num_splits = 0) { - ResizeBilinearOptionsBuilder builder_(_fbb); - builder_.add_align_corners(align_corners); + SplitVOptionsBuilder builder_(_fbb); + builder_.add_num_splits(num_splits); return builder_.Finish(); } -struct ResizeNearestNeighborOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct StridedSliceOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_ALIGN_CORNERS = 4 + VT_BEGIN_MASK = 4, + VT_END_MASK = 6, + VT_ELLIPSIS_MASK = 8, + VT_NEW_AXIS_MASK = 10, + VT_SHRINK_AXIS_MASK = 12 }; - bool align_corners() const { return GetField(VT_ALIGN_CORNERS, 0) != 0; } + int32_t begin_mask() const { return GetField(VT_BEGIN_MASK, 0); } + int32_t end_mask() const { return GetField(VT_END_MASK, 0); } + int32_t ellipsis_mask() const { return GetField(VT_ELLIPSIS_MASK, 0); } + int32_t new_axis_mask() const { return GetField(VT_NEW_AXIS_MASK, 0); } + int32_t shrink_axis_mask() const { return GetField(VT_SHRINK_AXIS_MASK, 0); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_ALIGN_CORNERS) && - verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyField(verifier, VT_BEGIN_MASK) && + VerifyField(verifier, VT_END_MASK) && + VerifyField(verifier, VT_ELLIPSIS_MASK) && + VerifyField(verifier, VT_NEW_AXIS_MASK) && + VerifyField(verifier, VT_SHRINK_AXIS_MASK) && verifier.EndTable(); } }; -struct ResizeNearestNeighborOptionsBuilder +struct StridedSliceOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_align_corners(bool align_corners) + void add_begin_mask(int32_t begin_mask) { - fbb_.AddElement(ResizeNearestNeighborOptions::VT_ALIGN_CORNERS, - static_cast(align_corners), 0); + fbb_.AddElement(StridedSliceOptions::VT_BEGIN_MASK, begin_mask, 0); } - explicit ResizeNearestNeighborOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + void add_end_mask(int32_t end_mask) + { + fbb_.AddElement(StridedSliceOptions::VT_END_MASK, end_mask, 0); + } + void add_ellipsis_mask(int32_t ellipsis_mask) + { + fbb_.AddElement(StridedSliceOptions::VT_ELLIPSIS_MASK, ellipsis_mask, 0); + } + void add_new_axis_mask(int32_t new_axis_mask) + { + fbb_.AddElement(StridedSliceOptions::VT_NEW_AXIS_MASK, new_axis_mask, 0); + } + void add_shrink_axis_mask(int32_t shrink_axis_mask) + { + fbb_.AddElement(StridedSliceOptions::VT_SHRINK_AXIS_MASK, shrink_axis_mask, 0); + } + explicit StridedSliceOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - ResizeNearestNeighborOptionsBuilder &operator=(const ResizeNearestNeighborOptionsBuilder &); - flatbuffers::Offset Finish() + StridedSliceOptionsBuilder &operator=(const StridedSliceOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateResizeNearestNeighborOptions(flatbuffers::FlatBufferBuilder &_fbb, bool align_corners = false) +inline flatbuffers::Offset +CreateStridedSliceOptions(flatbuffers::FlatBufferBuilder &_fbb, int32_t begin_mask = 0, + int32_t end_mask = 0, int32_t ellipsis_mask = 0, + int32_t new_axis_mask = 0, int32_t shrink_axis_mask = 0) { - ResizeNearestNeighborOptionsBuilder builder_(_fbb); - builder_.add_align_corners(align_corners); + StridedSliceOptionsBuilder builder_(_fbb); + builder_.add_shrink_axis_mask(shrink_axis_mask); + builder_.add_new_axis_mask(new_axis_mask); + builder_.add_ellipsis_mask(ellipsis_mask); + builder_.add_end_mask(end_mask); + builder_.add_begin_mask(begin_mask); return builder_.Finish(); } -struct CallOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct LogSoftmaxOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum - { - VT_SUBGRAPH = 4 - }; - uint32_t subgraph() const { return GetField(VT_SUBGRAPH, 0); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_SUBGRAPH) && - verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct CallOptionsBuilder +struct LogSoftmaxOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_subgraph(uint32_t subgraph) - { - fbb_.AddElement(CallOptions::VT_SUBGRAPH, subgraph, 0); - } - explicit CallOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit LogSoftmaxOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - CallOptionsBuilder &operator=(const CallOptionsBuilder &); - flatbuffers::Offset Finish() + LogSoftmaxOptionsBuilder &operator=(const LogSoftmaxOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateCallOptions(flatbuffers::FlatBufferBuilder &_fbb, - uint32_t subgraph = 0) +inline flatbuffers::Offset +CreateLogSoftmaxOptions(flatbuffers::FlatBufferBuilder &_fbb) { - CallOptionsBuilder builder_(_fbb); - builder_.add_subgraph(subgraph); + LogSoftmaxOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct PadOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct CastOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + enum + { + VT_IN_DATA_TYPE = 4, + VT_OUT_DATA_TYPE = 6 + }; + TensorType in_data_type() const + { + return static_cast(GetField(VT_IN_DATA_TYPE, 0)); + } + TensorType out_data_type() const + { + return static_cast(GetField(VT_OUT_DATA_TYPE, 0)); + } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyField(verifier, VT_IN_DATA_TYPE) && + VerifyField(verifier, VT_OUT_DATA_TYPE) && verifier.EndTable(); } }; -struct PadOptionsBuilder +struct CastOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit PadOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + void add_in_data_type(TensorType in_data_type) { - start_ = fbb_.StartTable(); + fbb_.AddElement(CastOptions::VT_IN_DATA_TYPE, static_cast(in_data_type), 0); } - PadOptionsBuilder &operator=(const PadOptionsBuilder &); - flatbuffers::Offset Finish() + void add_out_data_type(TensorType out_data_type) + { + fbb_.AddElement(CastOptions::VT_OUT_DATA_TYPE, static_cast(out_data_type), 0); + } + explicit CastOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + CastOptionsBuilder &operator=(const CastOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreatePadOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateCastOptions(flatbuffers::FlatBufferBuilder &_fbb, + TensorType in_data_type = TensorType_FLOAT32, + TensorType out_data_type = TensorType_FLOAT32) { - PadOptionsBuilder builder_(_fbb); + CastOptionsBuilder builder_(_fbb); + builder_.add_out_data_type(out_data_type); + builder_.add_in_data_type(in_data_type); return builder_.Finish(); } -struct PadV2Options FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct DequantizeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { bool Verify(flatbuffers::Verifier &verifier) const { @@ -3175,85 +5107,63 @@ struct PadV2Options FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table } }; -struct PadV2OptionsBuilder +struct DequantizeOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit PadV2OptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit DequantizeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - PadV2OptionsBuilder &operator=(const PadV2OptionsBuilder &); - flatbuffers::Offset Finish() + DequantizeOptionsBuilder &operator=(const DequantizeOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreatePadV2Options(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateDequantizeOptions(flatbuffers::FlatBufferBuilder &_fbb) { - PadV2OptionsBuilder builder_(_fbb); + DequantizeOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct ReshapeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct MaximumMinimumOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum - { - VT_NEW_SHAPE = 4 - }; - const flatbuffers::Vector *new_shape() const - { - return GetPointer *>(VT_NEW_SHAPE); - } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyOffset(verifier, VT_NEW_SHAPE) && - verifier.VerifyVector(new_shape()) && verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct ReshapeOptionsBuilder +struct MaximumMinimumOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_new_shape(flatbuffers::Offset> new_shape) - { - fbb_.AddOffset(ReshapeOptions::VT_NEW_SHAPE, new_shape); - } - explicit ReshapeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit MaximumMinimumOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - ReshapeOptionsBuilder &operator=(const ReshapeOptionsBuilder &); - flatbuffers::Offset Finish() + MaximumMinimumOptionsBuilder &operator=(const MaximumMinimumOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateReshapeOptions(flatbuffers::FlatBufferBuilder &_fbb, - flatbuffers::Offset> new_shape = 0) +inline flatbuffers::Offset +CreateMaximumMinimumOptions(flatbuffers::FlatBufferBuilder &_fbb) { - ReshapeOptionsBuilder builder_(_fbb); - builder_.add_new_shape(new_shape); + MaximumMinimumOptionsBuilder builder_(_fbb); return builder_.Finish(); } -inline flatbuffers::Offset -CreateReshapeOptionsDirect(flatbuffers::FlatBufferBuilder &_fbb, - const std::vector *new_shape = nullptr) -{ - return neurun_tflite::CreateReshapeOptions( - _fbb, new_shape ? _fbb.CreateVector(*new_shape) : 0); -} - -struct SpaceToBatchNDOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct TileOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { bool Verify(flatbuffers::Verifier &verifier) const { @@ -3261,262 +5171,219 @@ struct SpaceToBatchNDOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Tabl } }; -struct SpaceToBatchNDOptionsBuilder +struct TileOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit SpaceToBatchNDOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit TileOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - SpaceToBatchNDOptionsBuilder &operator=(const SpaceToBatchNDOptionsBuilder &); - flatbuffers::Offset Finish() + TileOptionsBuilder &operator=(const TileOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateSpaceToBatchNDOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset CreateTileOptions(flatbuffers::FlatBufferBuilder &_fbb) { - SpaceToBatchNDOptionsBuilder builder_(_fbb); + TileOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct BatchToSpaceNDOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct ArgMaxOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + enum + { + VT_OUTPUT_TYPE = 4 + }; + TensorType output_type() const + { + return static_cast(GetField(VT_OUTPUT_TYPE, 0)); + } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyField(verifier, VT_OUTPUT_TYPE) && + verifier.EndTable(); } }; -struct BatchToSpaceNDOptionsBuilder +struct ArgMaxOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit BatchToSpaceNDOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + void add_output_type(TensorType output_type) + { + fbb_.AddElement(ArgMaxOptions::VT_OUTPUT_TYPE, static_cast(output_type), 0); + } + explicit ArgMaxOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - BatchToSpaceNDOptionsBuilder &operator=(const BatchToSpaceNDOptionsBuilder &); - flatbuffers::Offset Finish() + ArgMaxOptionsBuilder &operator=(const ArgMaxOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateBatchToSpaceNDOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateArgMaxOptions(flatbuffers::FlatBufferBuilder &_fbb, + TensorType output_type = TensorType_FLOAT32) { - BatchToSpaceNDOptionsBuilder builder_(_fbb); + ArgMaxOptionsBuilder builder_(_fbb); + builder_.add_output_type(output_type); return builder_.Finish(); } -struct SkipGramOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct ArgMinOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_NGRAM_SIZE = 4, - VT_MAX_SKIP_SIZE = 6, - VT_INCLUDE_ALL_NGRAMS = 8 + VT_OUTPUT_TYPE = 4 }; - int32_t ngram_size() const { return GetField(VT_NGRAM_SIZE, 0); } - int32_t max_skip_size() const { return GetField(VT_MAX_SKIP_SIZE, 0); } - bool include_all_ngrams() const { return GetField(VT_INCLUDE_ALL_NGRAMS, 0) != 0; } + TensorType output_type() const + { + return static_cast(GetField(VT_OUTPUT_TYPE, 0)); + } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_NGRAM_SIZE) && - VerifyField(verifier, VT_MAX_SKIP_SIZE) && - VerifyField(verifier, VT_INCLUDE_ALL_NGRAMS) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyField(verifier, VT_OUTPUT_TYPE) && + verifier.EndTable(); } }; -struct SkipGramOptionsBuilder +struct ArgMinOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_ngram_size(int32_t ngram_size) - { - fbb_.AddElement(SkipGramOptions::VT_NGRAM_SIZE, ngram_size, 0); - } - void add_max_skip_size(int32_t max_skip_size) - { - fbb_.AddElement(SkipGramOptions::VT_MAX_SKIP_SIZE, max_skip_size, 0); - } - void add_include_all_ngrams(bool include_all_ngrams) + void add_output_type(TensorType output_type) { - fbb_.AddElement(SkipGramOptions::VT_INCLUDE_ALL_NGRAMS, - static_cast(include_all_ngrams), 0); + fbb_.AddElement(ArgMinOptions::VT_OUTPUT_TYPE, static_cast(output_type), 0); } - explicit SkipGramOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit ArgMinOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - SkipGramOptionsBuilder &operator=(const SkipGramOptionsBuilder &); - flatbuffers::Offset Finish() + ArgMinOptionsBuilder &operator=(const ArgMinOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateSkipGramOptions(flatbuffers::FlatBufferBuilder &_fbb, int32_t ngram_size = 0, - int32_t max_skip_size = 0, bool include_all_ngrams = false) +inline flatbuffers::Offset +CreateArgMinOptions(flatbuffers::FlatBufferBuilder &_fbb, + TensorType output_type = TensorType_FLOAT32) { - SkipGramOptionsBuilder builder_(_fbb); - builder_.add_max_skip_size(max_skip_size); - builder_.add_ngram_size(ngram_size); - builder_.add_include_all_ngrams(include_all_ngrams); + ArgMinOptionsBuilder builder_(_fbb); + builder_.add_output_type(output_type); return builder_.Finish(); } -struct SpaceToDepthOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct GreaterOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum - { - VT_BLOCK_SIZE = 4 - }; - int32_t block_size() const { return GetField(VT_BLOCK_SIZE, 0); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_BLOCK_SIZE) && - verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct SpaceToDepthOptionsBuilder +struct GreaterOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_block_size(int32_t block_size) - { - fbb_.AddElement(SpaceToDepthOptions::VT_BLOCK_SIZE, block_size, 0); - } - explicit SpaceToDepthOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit GreaterOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - SpaceToDepthOptionsBuilder &operator=(const SpaceToDepthOptionsBuilder &); - flatbuffers::Offset Finish() + GreaterOptionsBuilder &operator=(const GreaterOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateSpaceToDepthOptions(flatbuffers::FlatBufferBuilder &_fbb, int32_t block_size = 0) +inline flatbuffers::Offset +CreateGreaterOptions(flatbuffers::FlatBufferBuilder &_fbb) { - SpaceToDepthOptionsBuilder builder_(_fbb); - builder_.add_block_size(block_size); + GreaterOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct SubOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct GreaterEqualOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum - { - VT_FUSED_ACTIVATION_FUNCTION = 4 - }; - ActivationFunctionType fused_activation_function() const - { - return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); - } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct SubOptionsBuilder +struct GreaterEqualOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_fused_activation_function(ActivationFunctionType fused_activation_function) - { - fbb_.AddElement(SubOptions::VT_FUSED_ACTIVATION_FUNCTION, - static_cast(fused_activation_function), 0); - } - explicit SubOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit GreaterEqualOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - SubOptionsBuilder &operator=(const SubOptionsBuilder &); - flatbuffers::Offset Finish() + GreaterEqualOptionsBuilder &operator=(const GreaterEqualOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateSubOptions(flatbuffers::FlatBufferBuilder &_fbb, - ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE) +inline flatbuffers::Offset +CreateGreaterEqualOptions(flatbuffers::FlatBufferBuilder &_fbb) { - SubOptionsBuilder builder_(_fbb); - builder_.add_fused_activation_function(fused_activation_function); + GreaterEqualOptionsBuilder builder_(_fbb); return builder_.Finish(); -} - -struct DivOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table -{ - enum - { - VT_FUSED_ACTIVATION_FUNCTION = 4 - }; - ActivationFunctionType fused_activation_function() const - { - return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); - } +} + +struct LessOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct DivOptionsBuilder +struct LessOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_fused_activation_function(ActivationFunctionType fused_activation_function) - { - fbb_.AddElement(DivOptions::VT_FUSED_ACTIVATION_FUNCTION, - static_cast(fused_activation_function), 0); - } - explicit DivOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit LessOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - DivOptionsBuilder &operator=(const DivOptionsBuilder &); - flatbuffers::Offset Finish() + LessOptionsBuilder &operator=(const LessOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateDivOptions(flatbuffers::FlatBufferBuilder &_fbb, - ActivationFunctionType fused_activation_function = ActivationFunctionType_NONE) +inline flatbuffers::Offset CreateLessOptions(flatbuffers::FlatBufferBuilder &_fbb) { - DivOptionsBuilder builder_(_fbb); - builder_.add_fused_activation_function(fused_activation_function); + LessOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct TopKV2Options FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct LessEqualOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { bool Verify(flatbuffers::Verifier &verifier) const { @@ -3524,118 +5391,93 @@ struct TopKV2Options FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table } }; -struct TopKV2OptionsBuilder +struct LessEqualOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit TopKV2OptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit LessEqualOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - TopKV2OptionsBuilder &operator=(const TopKV2OptionsBuilder &); - flatbuffers::Offset Finish() + LessEqualOptionsBuilder &operator=(const LessEqualOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateTopKV2Options(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateLessEqualOptions(flatbuffers::FlatBufferBuilder &_fbb) { - TopKV2OptionsBuilder builder_(_fbb); + LessEqualOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct EmbeddingLookupSparseOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct NegOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum - { - VT_COMBINER = 4 - }; - CombinerType combiner() const - { - return static_cast(GetField(VT_COMBINER, 0)); - } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_COMBINER) && - verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct EmbeddingLookupSparseOptionsBuilder +struct NegOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_combiner(CombinerType combiner) - { - fbb_.AddElement(EmbeddingLookupSparseOptions::VT_COMBINER, - static_cast(combiner), 0); - } - explicit EmbeddingLookupSparseOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit NegOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - EmbeddingLookupSparseOptionsBuilder &operator=(const EmbeddingLookupSparseOptionsBuilder &); - flatbuffers::Offset Finish() + NegOptionsBuilder &operator=(const NegOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateEmbeddingLookupSparseOptions(flatbuffers::FlatBufferBuilder &_fbb, - CombinerType combiner = CombinerType_SUM) +inline flatbuffers::Offset CreateNegOptions(flatbuffers::FlatBufferBuilder &_fbb) { - EmbeddingLookupSparseOptionsBuilder builder_(_fbb); - builder_.add_combiner(combiner); + NegOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct GatherOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct SelectOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum - { - VT_AXIS = 4 - }; - int32_t axis() const { return GetField(VT_AXIS, 0); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_AXIS) && - verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct GatherOptionsBuilder +struct SelectOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_axis(int32_t axis) { fbb_.AddElement(GatherOptions::VT_AXIS, axis, 0); } - explicit GatherOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit SelectOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - GatherOptionsBuilder &operator=(const GatherOptionsBuilder &); - flatbuffers::Offset Finish() + SelectOptionsBuilder &operator=(const SelectOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateGatherOptions(flatbuffers::FlatBufferBuilder &_fbb, - int32_t axis = 0) +inline flatbuffers::Offset CreateSelectOptions(flatbuffers::FlatBufferBuilder &_fbb) { - GatherOptionsBuilder builder_(_fbb); - builder_.add_axis(axis); + SelectOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct TransposeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct SliceOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { bool Verify(flatbuffers::Verifier &verifier) const { @@ -3643,322 +5485,271 @@ struct TransposeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table } }; -struct TransposeOptionsBuilder +struct SliceOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit TransposeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit SliceOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - TransposeOptionsBuilder &operator=(const TransposeOptionsBuilder &); - flatbuffers::Offset Finish() + SliceOptionsBuilder &operator=(const SliceOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateTransposeOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset CreateSliceOptions(flatbuffers::FlatBufferBuilder &_fbb) { - TransposeOptionsBuilder builder_(_fbb); + SliceOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct ExpOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct TransposeConvOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + enum + { + VT_PADDING = 4, + VT_STRIDE_W = 6, + VT_STRIDE_H = 8 + }; + Padding padding() const { return static_cast(GetField(VT_PADDING, 0)); } + int32_t stride_w() const { return GetField(VT_STRIDE_W, 0); } + int32_t stride_h() const { return GetField(VT_STRIDE_H, 0); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyField(verifier, VT_PADDING) && + VerifyField(verifier, VT_STRIDE_W) && + VerifyField(verifier, VT_STRIDE_H) && verifier.EndTable(); } }; -struct ExpOptionsBuilder +struct TransposeConvOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit ExpOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + void add_padding(Padding padding) + { + fbb_.AddElement(TransposeConvOptions::VT_PADDING, static_cast(padding), 0); + } + void add_stride_w(int32_t stride_w) + { + fbb_.AddElement(TransposeConvOptions::VT_STRIDE_W, stride_w, 0); + } + void add_stride_h(int32_t stride_h) + { + fbb_.AddElement(TransposeConvOptions::VT_STRIDE_H, stride_h, 0); + } + explicit TransposeConvOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - ExpOptionsBuilder &operator=(const ExpOptionsBuilder &); - flatbuffers::Offset Finish() + TransposeConvOptionsBuilder &operator=(const TransposeConvOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateExpOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateTransposeConvOptions(flatbuffers::FlatBufferBuilder &_fbb, Padding padding = Padding_SAME, + int32_t stride_w = 0, int32_t stride_h = 0) { - ExpOptionsBuilder builder_(_fbb); + TransposeConvOptionsBuilder builder_(_fbb); + builder_.add_stride_h(stride_h); + builder_.add_stride_w(stride_w); + builder_.add_padding(padding); return builder_.Finish(); } -struct ReducerOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct ExpandDimsOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum - { - VT_KEEP_DIMS = 4 - }; - bool keep_dims() const { return GetField(VT_KEEP_DIMS, 0) != 0; } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_KEEP_DIMS) && - verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct ReducerOptionsBuilder +struct ExpandDimsOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_keep_dims(bool keep_dims) - { - fbb_.AddElement(ReducerOptions::VT_KEEP_DIMS, static_cast(keep_dims), 0); - } - explicit ReducerOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit ExpandDimsOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - ReducerOptionsBuilder &operator=(const ReducerOptionsBuilder &); - flatbuffers::Offset Finish() + ExpandDimsOptionsBuilder &operator=(const ExpandDimsOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateReducerOptions(flatbuffers::FlatBufferBuilder &_fbb, bool keep_dims = false) +inline flatbuffers::Offset +CreateExpandDimsOptions(flatbuffers::FlatBufferBuilder &_fbb) { - ReducerOptionsBuilder builder_(_fbb); - builder_.add_keep_dims(keep_dims); + ExpandDimsOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct SqueezeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct SparseToDenseOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_SQUEEZE_DIMS = 4 + VT_VALIDATE_INDICES = 4 }; - const flatbuffers::Vector *squeeze_dims() const - { - return GetPointer *>(VT_SQUEEZE_DIMS); - } + bool validate_indices() const { return GetField(VT_VALIDATE_INDICES, 0) != 0; } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyOffset(verifier, VT_SQUEEZE_DIMS) && - verifier.VerifyVector(squeeze_dims()) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyField(verifier, VT_VALIDATE_INDICES) && + verifier.EndTable(); } }; -struct SqueezeOptionsBuilder +struct SparseToDenseOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_squeeze_dims(flatbuffers::Offset> squeeze_dims) + void add_validate_indices(bool validate_indices) { - fbb_.AddOffset(SqueezeOptions::VT_SQUEEZE_DIMS, squeeze_dims); + fbb_.AddElement(SparseToDenseOptions::VT_VALIDATE_INDICES, + static_cast(validate_indices), 0); } - explicit SqueezeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit SparseToDenseOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - SqueezeOptionsBuilder &operator=(const SqueezeOptionsBuilder &); - flatbuffers::Offset Finish() + SparseToDenseOptionsBuilder &operator=(const SparseToDenseOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateSqueezeOptions(flatbuffers::FlatBufferBuilder &_fbb, - flatbuffers::Offset> squeeze_dims = 0) +inline flatbuffers::Offset +CreateSparseToDenseOptions(flatbuffers::FlatBufferBuilder &_fbb, bool validate_indices = false) { - SqueezeOptionsBuilder builder_(_fbb); - builder_.add_squeeze_dims(squeeze_dims); + SparseToDenseOptionsBuilder builder_(_fbb); + builder_.add_validate_indices(validate_indices); return builder_.Finish(); } -inline flatbuffers::Offset -CreateSqueezeOptionsDirect(flatbuffers::FlatBufferBuilder &_fbb, - const std::vector *squeeze_dims = nullptr) -{ - return neurun_tflite::CreateSqueezeOptions( - _fbb, squeeze_dims ? _fbb.CreateVector(*squeeze_dims) : 0); -} - -struct SplitOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct EqualOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum - { - VT_NUM_SPLITS = 4 - }; - int32_t num_splits() const { return GetField(VT_NUM_SPLITS, 0); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_NUM_SPLITS) && - verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct SplitOptionsBuilder +struct EqualOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_num_splits(int32_t num_splits) - { - fbb_.AddElement(SplitOptions::VT_NUM_SPLITS, num_splits, 0); - } - explicit SplitOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit EqualOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - SplitOptionsBuilder &operator=(const SplitOptionsBuilder &); - flatbuffers::Offset Finish() + EqualOptionsBuilder &operator=(const EqualOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateSplitOptions(flatbuffers::FlatBufferBuilder &_fbb, - int32_t num_splits = 0) +inline flatbuffers::Offset CreateEqualOptions(flatbuffers::FlatBufferBuilder &_fbb) { - SplitOptionsBuilder builder_(_fbb); - builder_.add_num_splits(num_splits); + EqualOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct SplitVOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct NotEqualOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum - { - VT_NUM_SPLITS = 4 - }; - int32_t num_splits() const { return GetField(VT_NUM_SPLITS, 0); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_NUM_SPLITS) && - verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct SplitVOptionsBuilder +struct NotEqualOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_num_splits(int32_t num_splits) - { - fbb_.AddElement(SplitVOptions::VT_NUM_SPLITS, num_splits, 0); - } - explicit SplitVOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit NotEqualOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - SplitVOptionsBuilder &operator=(const SplitVOptionsBuilder &); - flatbuffers::Offset Finish() + NotEqualOptionsBuilder &operator=(const NotEqualOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateSplitVOptions(flatbuffers::FlatBufferBuilder &_fbb, - int32_t num_splits = 0) +inline flatbuffers::Offset +CreateNotEqualOptions(flatbuffers::FlatBufferBuilder &_fbb) { - SplitVOptionsBuilder builder_(_fbb); - builder_.add_num_splits(num_splits); + NotEqualOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct StridedSliceOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct ShapeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_BEGIN_MASK = 4, - VT_END_MASK = 6, - VT_ELLIPSIS_MASK = 8, - VT_NEW_AXIS_MASK = 10, - VT_SHRINK_AXIS_MASK = 12 + VT_OUT_TYPE = 4 }; - int32_t begin_mask() const { return GetField(VT_BEGIN_MASK, 0); } - int32_t end_mask() const { return GetField(VT_END_MASK, 0); } - int32_t ellipsis_mask() const { return GetField(VT_ELLIPSIS_MASK, 0); } - int32_t new_axis_mask() const { return GetField(VT_NEW_AXIS_MASK, 0); } - int32_t shrink_axis_mask() const { return GetField(VT_SHRINK_AXIS_MASK, 0); } + TensorType out_type() const { return static_cast(GetField(VT_OUT_TYPE, 0)); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_BEGIN_MASK) && - VerifyField(verifier, VT_END_MASK) && - VerifyField(verifier, VT_ELLIPSIS_MASK) && - VerifyField(verifier, VT_NEW_AXIS_MASK) && - VerifyField(verifier, VT_SHRINK_AXIS_MASK) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyField(verifier, VT_OUT_TYPE) && + verifier.EndTable(); } }; -struct StridedSliceOptionsBuilder +struct ShapeOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_begin_mask(int32_t begin_mask) - { - fbb_.AddElement(StridedSliceOptions::VT_BEGIN_MASK, begin_mask, 0); - } - void add_end_mask(int32_t end_mask) - { - fbb_.AddElement(StridedSliceOptions::VT_END_MASK, end_mask, 0); - } - void add_ellipsis_mask(int32_t ellipsis_mask) - { - fbb_.AddElement(StridedSliceOptions::VT_ELLIPSIS_MASK, ellipsis_mask, 0); - } - void add_new_axis_mask(int32_t new_axis_mask) - { - fbb_.AddElement(StridedSliceOptions::VT_NEW_AXIS_MASK, new_axis_mask, 0); - } - void add_shrink_axis_mask(int32_t shrink_axis_mask) + void add_out_type(TensorType out_type) { - fbb_.AddElement(StridedSliceOptions::VT_SHRINK_AXIS_MASK, shrink_axis_mask, 0); + fbb_.AddElement(ShapeOptions::VT_OUT_TYPE, static_cast(out_type), 0); } - explicit StridedSliceOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit ShapeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - StridedSliceOptionsBuilder &operator=(const StridedSliceOptionsBuilder &); - flatbuffers::Offset Finish() + ShapeOptionsBuilder &operator=(const ShapeOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateStridedSliceOptions(flatbuffers::FlatBufferBuilder &_fbb, int32_t begin_mask = 0, - int32_t end_mask = 0, int32_t ellipsis_mask = 0, - int32_t new_axis_mask = 0, int32_t shrink_axis_mask = 0) +inline flatbuffers::Offset +CreateShapeOptions(flatbuffers::FlatBufferBuilder &_fbb, TensorType out_type = TensorType_FLOAT32) { - StridedSliceOptionsBuilder builder_(_fbb); - builder_.add_shrink_axis_mask(shrink_axis_mask); - builder_.add_new_axis_mask(new_axis_mask); - builder_.add_ellipsis_mask(ellipsis_mask); - builder_.add_end_mask(end_mask); - builder_.add_begin_mask(begin_mask); + ShapeOptionsBuilder builder_(_fbb); + builder_.add_out_type(out_type); return builder_.Finish(); } -struct LogSoftmaxOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct RankOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { bool Verify(flatbuffers::Verifier &verifier) const { @@ -3966,153 +5757,169 @@ struct LogSoftmaxOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table } }; -struct LogSoftmaxOptionsBuilder +struct RankOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit LogSoftmaxOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit RankOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - LogSoftmaxOptionsBuilder &operator=(const LogSoftmaxOptionsBuilder &); - flatbuffers::Offset Finish() + RankOptionsBuilder &operator=(const RankOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateLogSoftmaxOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset CreateRankOptions(flatbuffers::FlatBufferBuilder &_fbb) { - LogSoftmaxOptionsBuilder builder_(_fbb); + RankOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct CastOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct PowOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum - { - VT_IN_DATA_TYPE = 4, - VT_OUT_DATA_TYPE = 6 - }; - TensorType in_data_type() const - { - return static_cast(GetField(VT_IN_DATA_TYPE, 0)); - } - TensorType out_data_type() const - { - return static_cast(GetField(VT_OUT_DATA_TYPE, 0)); - } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_IN_DATA_TYPE) && - VerifyField(verifier, VT_OUT_DATA_TYPE) && verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct CastOptionsBuilder +struct PowOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_in_data_type(TensorType in_data_type) - { - fbb_.AddElement(CastOptions::VT_IN_DATA_TYPE, static_cast(in_data_type), 0); - } - void add_out_data_type(TensorType out_data_type) - { - fbb_.AddElement(CastOptions::VT_OUT_DATA_TYPE, static_cast(out_data_type), 0); - } - explicit CastOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit PowOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - CastOptionsBuilder &operator=(const CastOptionsBuilder &); - flatbuffers::Offset Finish() + PowOptionsBuilder &operator=(const PowOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateCastOptions(flatbuffers::FlatBufferBuilder &_fbb, - TensorType in_data_type = TensorType_FLOAT32, - TensorType out_data_type = TensorType_FLOAT32) +inline flatbuffers::Offset CreatePowOptions(flatbuffers::FlatBufferBuilder &_fbb) { - CastOptionsBuilder builder_(_fbb); - builder_.add_out_data_type(out_data_type); - builder_.add_in_data_type(in_data_type); + PowOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct DequantizeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct FakeQuantOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + enum + { + VT_MIN = 4, + VT_MAX = 6, + VT_NUM_BITS = 8, + VT_NARROW_RANGE = 10 + }; + float min() const { return GetField(VT_MIN, 0.0f); } + float max() const { return GetField(VT_MAX, 0.0f); } + int32_t num_bits() const { return GetField(VT_NUM_BITS, 0); } + bool narrow_range() const { return GetField(VT_NARROW_RANGE, 0) != 0; } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyField(verifier, VT_MIN) && + VerifyField(verifier, VT_MAX) && VerifyField(verifier, VT_NUM_BITS) && + VerifyField(verifier, VT_NARROW_RANGE) && verifier.EndTable(); } }; -struct DequantizeOptionsBuilder +struct FakeQuantOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit DequantizeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + void add_min(float min) { fbb_.AddElement(FakeQuantOptions::VT_MIN, min, 0.0f); } + void add_max(float max) { fbb_.AddElement(FakeQuantOptions::VT_MAX, max, 0.0f); } + void add_num_bits(int32_t num_bits) + { + fbb_.AddElement(FakeQuantOptions::VT_NUM_BITS, num_bits, 0); + } + void add_narrow_range(bool narrow_range) + { + fbb_.AddElement(FakeQuantOptions::VT_NARROW_RANGE, static_cast(narrow_range), + 0); + } + explicit FakeQuantOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - DequantizeOptionsBuilder &operator=(const DequantizeOptionsBuilder &); - flatbuffers::Offset Finish() + FakeQuantOptionsBuilder &operator=(const FakeQuantOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateDequantizeOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateFakeQuantOptions(flatbuffers::FlatBufferBuilder &_fbb, float min = 0.0f, float max = 0.0f, + int32_t num_bits = 0, bool narrow_range = false) { - DequantizeOptionsBuilder builder_(_fbb); + FakeQuantOptionsBuilder builder_(_fbb); + builder_.add_num_bits(num_bits); + builder_.add_max(max); + builder_.add_min(min); + builder_.add_narrow_range(narrow_range); return builder_.Finish(); } -struct MaximumMinimumOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct PackOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + enum + { + VT_VALUES_COUNT = 4, + VT_AXIS = 6 + }; + int32_t values_count() const { return GetField(VT_VALUES_COUNT, 0); } + int32_t axis() const { return GetField(VT_AXIS, 0); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyField(verifier, VT_VALUES_COUNT) && + VerifyField(verifier, VT_AXIS) && verifier.EndTable(); } }; -struct MaximumMinimumOptionsBuilder +struct PackOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit MaximumMinimumOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + void add_values_count(int32_t values_count) + { + fbb_.AddElement(PackOptions::VT_VALUES_COUNT, values_count, 0); + } + void add_axis(int32_t axis) { fbb_.AddElement(PackOptions::VT_AXIS, axis, 0); } + explicit PackOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - MaximumMinimumOptionsBuilder &operator=(const MaximumMinimumOptionsBuilder &); - flatbuffers::Offset Finish() + PackOptionsBuilder &operator=(const PackOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateMaximumMinimumOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreatePackOptions(flatbuffers::FlatBufferBuilder &_fbb, int32_t values_count = 0, int32_t axis = 0) { - MaximumMinimumOptionsBuilder builder_(_fbb); + PackOptionsBuilder builder_(_fbb); + builder_.add_axis(axis); + builder_.add_values_count(values_count); return builder_.Finish(); } -struct TileOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct LogicalOrOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { bool Verify(flatbuffers::Verifier &verifier) const { @@ -4120,124 +5927,102 @@ struct TileOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table } }; -struct TileOptionsBuilder +struct LogicalOrOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit TileOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit LogicalOrOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - TileOptionsBuilder &operator=(const TileOptionsBuilder &); - flatbuffers::Offset Finish() + LogicalOrOptionsBuilder &operator=(const LogicalOrOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateTileOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateLogicalOrOptions(flatbuffers::FlatBufferBuilder &_fbb) { - TileOptionsBuilder builder_(_fbb); + LogicalOrOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct ArgMaxOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct OneHotOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_OUTPUT_TYPE = 4 + VT_AXIS = 4 }; - TensorType output_type() const - { - return static_cast(GetField(VT_OUTPUT_TYPE, 0)); - } + int32_t axis() const { return GetField(VT_AXIS, 0); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_OUTPUT_TYPE) && + return VerifyTableStart(verifier) && VerifyField(verifier, VT_AXIS) && verifier.EndTable(); } }; -struct ArgMaxOptionsBuilder +struct OneHotOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_output_type(TensorType output_type) - { - fbb_.AddElement(ArgMaxOptions::VT_OUTPUT_TYPE, static_cast(output_type), 0); - } - explicit ArgMaxOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + void add_axis(int32_t axis) { fbb_.AddElement(OneHotOptions::VT_AXIS, axis, 0); } + explicit OneHotOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - ArgMaxOptionsBuilder &operator=(const ArgMaxOptionsBuilder &); - flatbuffers::Offset Finish() + OneHotOptionsBuilder &operator=(const OneHotOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateArgMaxOptions(flatbuffers::FlatBufferBuilder &_fbb, - TensorType output_type = TensorType_FLOAT32) +inline flatbuffers::Offset CreateOneHotOptions(flatbuffers::FlatBufferBuilder &_fbb, + int32_t axis = 0) { - ArgMaxOptionsBuilder builder_(_fbb); - builder_.add_output_type(output_type); + OneHotOptionsBuilder builder_(_fbb); + builder_.add_axis(axis); return builder_.Finish(); } -struct ArgMinOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct AbsOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum - { - VT_OUTPUT_TYPE = 4 - }; - TensorType output_type() const - { - return static_cast(GetField(VT_OUTPUT_TYPE, 0)); - } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_OUTPUT_TYPE) && - verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct ArgMinOptionsBuilder +struct AbsOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_output_type(TensorType output_type) - { - fbb_.AddElement(ArgMinOptions::VT_OUTPUT_TYPE, static_cast(output_type), 0); - } - explicit ArgMinOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit AbsOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - ArgMinOptionsBuilder &operator=(const ArgMinOptionsBuilder &); - flatbuffers::Offset Finish() + AbsOptionsBuilder &operator=(const AbsOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateArgMinOptions(flatbuffers::FlatBufferBuilder &_fbb, - TensorType output_type = TensorType_FLOAT32) +inline flatbuffers::Offset CreateAbsOptions(flatbuffers::FlatBufferBuilder &_fbb) { - ArgMinOptionsBuilder builder_(_fbb); - builder_.add_output_type(output_type); + AbsOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct GreaterOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct HardSwishOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { bool Verify(flatbuffers::Verifier &verifier) const { @@ -4245,31 +6030,31 @@ struct GreaterOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table } }; -struct GreaterOptionsBuilder +struct HardSwishOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit GreaterOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit HardSwishOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - GreaterOptionsBuilder &operator=(const GreaterOptionsBuilder &); - flatbuffers::Offset Finish() + HardSwishOptionsBuilder &operator=(const HardSwishOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateGreaterOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateHardSwishOptions(flatbuffers::FlatBufferBuilder &_fbb) { - GreaterOptionsBuilder builder_(_fbb); + HardSwishOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct GreaterEqualOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct LogicalAndOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { bool Verify(flatbuffers::Verifier &verifier) const { @@ -4277,31 +6062,31 @@ struct GreaterEqualOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table } }; -struct GreaterEqualOptionsBuilder +struct LogicalAndOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit GreaterEqualOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit LogicalAndOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - GreaterEqualOptionsBuilder &operator=(const GreaterEqualOptionsBuilder &); - flatbuffers::Offset Finish() + LogicalAndOptionsBuilder &operator=(const LogicalAndOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateGreaterEqualOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateLogicalAndOptions(flatbuffers::FlatBufferBuilder &_fbb) { - GreaterEqualOptionsBuilder builder_(_fbb); + LogicalAndOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct LessOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct LogicalNotOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { bool Verify(flatbuffers::Verifier &verifier) const { @@ -4309,62 +6094,75 @@ struct LessOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table } }; -struct LessOptionsBuilder +struct LogicalNotOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit LessOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit LogicalNotOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - LessOptionsBuilder &operator=(const LessOptionsBuilder &); - flatbuffers::Offset Finish() + LogicalNotOptionsBuilder &operator=(const LogicalNotOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateLessOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateLogicalNotOptions(flatbuffers::FlatBufferBuilder &_fbb) { - LessOptionsBuilder builder_(_fbb); + LogicalNotOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct LessEqualOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct UnpackOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + enum + { + VT_NUM = 4, + VT_AXIS = 6 + }; + int32_t num() const { return GetField(VT_NUM, 0); } + int32_t axis() const { return GetField(VT_AXIS, 0); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyField(verifier, VT_NUM) && + VerifyField(verifier, VT_AXIS) && verifier.EndTable(); } }; -struct LessEqualOptionsBuilder +struct UnpackOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit LessEqualOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + void add_num(int32_t num) { fbb_.AddElement(UnpackOptions::VT_NUM, num, 0); } + void add_axis(int32_t axis) { fbb_.AddElement(UnpackOptions::VT_AXIS, axis, 0); } + explicit UnpackOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - LessEqualOptionsBuilder &operator=(const LessEqualOptionsBuilder &); - flatbuffers::Offset Finish() + UnpackOptionsBuilder &operator=(const UnpackOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateLessEqualOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset CreateUnpackOptions(flatbuffers::FlatBufferBuilder &_fbb, + int32_t num = 0, int32_t axis = 0) { - LessEqualOptionsBuilder builder_(_fbb); + UnpackOptionsBuilder builder_(_fbb); + builder_.add_axis(axis); + builder_.add_num(num); return builder_.Finish(); } -struct NegOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct FloorDivOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { bool Verify(flatbuffers::Verifier &verifier) const { @@ -4372,30 +6170,31 @@ struct NegOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table } }; -struct NegOptionsBuilder +struct FloorDivOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit NegOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit FloorDivOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - NegOptionsBuilder &operator=(const NegOptionsBuilder &); - flatbuffers::Offset Finish() + FloorDivOptionsBuilder &operator=(const FloorDivOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateNegOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateFloorDivOptions(flatbuffers::FlatBufferBuilder &_fbb) { - NegOptionsBuilder builder_(_fbb); + FloorDivOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct SelectOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct SquareOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { bool Verify(flatbuffers::Verifier &verifier) const { @@ -4403,30 +6202,30 @@ struct SelectOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table } }; -struct SelectOptionsBuilder +struct SquareOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit SelectOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit SquareOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - SelectOptionsBuilder &operator=(const SelectOptionsBuilder &); - flatbuffers::Offset Finish() + SquareOptionsBuilder &operator=(const SquareOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateSelectOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset CreateSquareOptions(flatbuffers::FlatBufferBuilder &_fbb) { - SelectOptionsBuilder builder_(_fbb); + SquareOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct SliceOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct ZerosLikeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { bool Verify(flatbuffers::Verifier &verifier) const { @@ -4434,89 +6233,62 @@ struct SliceOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table } }; -struct SliceOptionsBuilder +struct ZerosLikeOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit SliceOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit ZerosLikeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - SliceOptionsBuilder &operator=(const SliceOptionsBuilder &); - flatbuffers::Offset Finish() + ZerosLikeOptionsBuilder &operator=(const ZerosLikeOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateSliceOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateZerosLikeOptions(flatbuffers::FlatBufferBuilder &_fbb) { - SliceOptionsBuilder builder_(_fbb); + ZerosLikeOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct TransposeConvOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct FillOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum - { - VT_PADDING = 4, - VT_STRIDE_W = 6, - VT_STRIDE_H = 8 - }; - Padding padding() const { return static_cast(GetField(VT_PADDING, 0)); } - int32_t stride_w() const { return GetField(VT_STRIDE_W, 0); } - int32_t stride_h() const { return GetField(VT_STRIDE_H, 0); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_PADDING) && - VerifyField(verifier, VT_STRIDE_W) && - VerifyField(verifier, VT_STRIDE_H) && verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct TransposeConvOptionsBuilder +struct FillOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_padding(Padding padding) - { - fbb_.AddElement(TransposeConvOptions::VT_PADDING, static_cast(padding), 0); - } - void add_stride_w(int32_t stride_w) - { - fbb_.AddElement(TransposeConvOptions::VT_STRIDE_W, stride_w, 0); - } - void add_stride_h(int32_t stride_h) - { - fbb_.AddElement(TransposeConvOptions::VT_STRIDE_H, stride_h, 0); - } - explicit TransposeConvOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit FillOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - TransposeConvOptionsBuilder &operator=(const TransposeConvOptionsBuilder &); - flatbuffers::Offset Finish() + FillOptionsBuilder &operator=(const FillOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; - -inline flatbuffers::Offset -CreateTransposeConvOptions(flatbuffers::FlatBufferBuilder &_fbb, Padding padding = Padding_SAME, - int32_t stride_w = 0, int32_t stride_h = 0) -{ - TransposeConvOptionsBuilder builder_(_fbb); - builder_.add_stride_h(stride_h); - builder_.add_stride_w(stride_w); - builder_.add_padding(padding); + +inline flatbuffers::Offset CreateFillOptions(flatbuffers::FlatBufferBuilder &_fbb) +{ + FillOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct ExpandDimsOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct FloorModOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { bool Verify(flatbuffers::Verifier &verifier) const { @@ -4524,106 +6296,102 @@ struct ExpandDimsOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table } }; -struct ExpandDimsOptionsBuilder +struct FloorModOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit ExpandDimsOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit FloorModOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - ExpandDimsOptionsBuilder &operator=(const ExpandDimsOptionsBuilder &); - flatbuffers::Offset Finish() + FloorModOptionsBuilder &operator=(const FloorModOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateExpandDimsOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateFloorModOptions(flatbuffers::FlatBufferBuilder &_fbb) { - ExpandDimsOptionsBuilder builder_(_fbb); + FloorModOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct SparseToDenseOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct RangeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum - { - VT_VALIDATE_INDICES = 4 - }; - bool validate_indices() const { return GetField(VT_VALIDATE_INDICES, 0) != 0; } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_VALIDATE_INDICES) && - verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct SparseToDenseOptionsBuilder +struct RangeOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_validate_indices(bool validate_indices) - { - fbb_.AddElement(SparseToDenseOptions::VT_VALIDATE_INDICES, - static_cast(validate_indices), 0); - } - explicit SparseToDenseOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit RangeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - SparseToDenseOptionsBuilder &operator=(const SparseToDenseOptionsBuilder &); - flatbuffers::Offset Finish() + RangeOptionsBuilder &operator=(const RangeOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateSparseToDenseOptions(flatbuffers::FlatBufferBuilder &_fbb, bool validate_indices = false) +inline flatbuffers::Offset CreateRangeOptions(flatbuffers::FlatBufferBuilder &_fbb) { - SparseToDenseOptionsBuilder builder_(_fbb); - builder_.add_validate_indices(validate_indices); + RangeOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct EqualOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct LeakyReluOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + enum + { + VT_ALPHA = 4 + }; + float alpha() const { return GetField(VT_ALPHA, 0.0f); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyField(verifier, VT_ALPHA) && + verifier.EndTable(); } }; -struct EqualOptionsBuilder +struct LeakyReluOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit EqualOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + void add_alpha(float alpha) { fbb_.AddElement(LeakyReluOptions::VT_ALPHA, alpha, 0.0f); } + explicit LeakyReluOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - EqualOptionsBuilder &operator=(const EqualOptionsBuilder &); - flatbuffers::Offset Finish() + LeakyReluOptionsBuilder &operator=(const LeakyReluOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateEqualOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateLeakyReluOptions(flatbuffers::FlatBufferBuilder &_fbb, float alpha = 0.0f) { - EqualOptionsBuilder builder_(_fbb); + LeakyReluOptionsBuilder builder_(_fbb); + builder_.add_alpha(alpha); return builder_.Finish(); } -struct NotEqualOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct SquaredDifferenceOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { bool Verify(flatbuffers::Verifier &verifier) const { @@ -4631,213 +6399,185 @@ struct NotEqualOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table } }; -struct NotEqualOptionsBuilder +struct SquaredDifferenceOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit NotEqualOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit SquaredDifferenceOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - NotEqualOptionsBuilder &operator=(const NotEqualOptionsBuilder &); - flatbuffers::Offset Finish() + SquaredDifferenceOptionsBuilder &operator=(const SquaredDifferenceOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateNotEqualOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateSquaredDifferenceOptions(flatbuffers::FlatBufferBuilder &_fbb) { - NotEqualOptionsBuilder builder_(_fbb); + SquaredDifferenceOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct ShapeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct MirrorPadOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_OUT_TYPE = 4 + VT_MODE = 4 }; - TensorType out_type() const { return static_cast(GetField(VT_OUT_TYPE, 0)); } + MirrorPadMode mode() const { return static_cast(GetField(VT_MODE, 0)); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_OUT_TYPE) && + return VerifyTableStart(verifier) && VerifyField(verifier, VT_MODE) && verifier.EndTable(); } }; -struct ShapeOptionsBuilder +struct MirrorPadOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_out_type(TensorType out_type) + void add_mode(MirrorPadMode mode) { - fbb_.AddElement(ShapeOptions::VT_OUT_TYPE, static_cast(out_type), 0); + fbb_.AddElement(MirrorPadOptions::VT_MODE, static_cast(mode), 0); } - explicit ShapeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit MirrorPadOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - ShapeOptionsBuilder &operator=(const ShapeOptionsBuilder &); - flatbuffers::Offset Finish() + MirrorPadOptionsBuilder &operator=(const MirrorPadOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateShapeOptions(flatbuffers::FlatBufferBuilder &_fbb, TensorType out_type = TensorType_FLOAT32) +inline flatbuffers::Offset +CreateMirrorPadOptions(flatbuffers::FlatBufferBuilder &_fbb, + MirrorPadMode mode = MirrorPadMode_REFLECT) { - ShapeOptionsBuilder builder_(_fbb); - builder_.add_out_type(out_type); + MirrorPadOptionsBuilder builder_(_fbb); + builder_.add_mode(mode); return builder_.Finish(); } -struct PowOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct UniqueOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + enum + { + VT_IDX_OUT_TYPE = 4 + }; + TensorType idx_out_type() const + { + return static_cast(GetField(VT_IDX_OUT_TYPE, 2)); + } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyField(verifier, VT_IDX_OUT_TYPE) && + verifier.EndTable(); } }; -struct PowOptionsBuilder +struct UniqueOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit PowOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + void add_idx_out_type(TensorType idx_out_type) + { + fbb_.AddElement(UniqueOptions::VT_IDX_OUT_TYPE, static_cast(idx_out_type), 2); + } + explicit UniqueOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - PowOptionsBuilder &operator=(const PowOptionsBuilder &); - flatbuffers::Offset Finish() + UniqueOptionsBuilder &operator=(const UniqueOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreatePowOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateUniqueOptions(flatbuffers::FlatBufferBuilder &_fbb, + TensorType idx_out_type = TensorType_INT32) { - PowOptionsBuilder builder_(_fbb); + UniqueOptionsBuilder builder_(_fbb); + builder_.add_idx_out_type(idx_out_type); return builder_.Finish(); } -struct FakeQuantOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct ReverseV2Options FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum - { - VT_MIN = 4, - VT_MAX = 6, - VT_NUM_BITS = 8, - VT_NARROW_RANGE = 10 - }; - float min() const { return GetField(VT_MIN, 0.0f); } - float max() const { return GetField(VT_MAX, 0.0f); } - int32_t num_bits() const { return GetField(VT_NUM_BITS, 0); } - bool narrow_range() const { return GetField(VT_NARROW_RANGE, 0) != 0; } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_MIN) && - VerifyField(verifier, VT_MAX) && VerifyField(verifier, VT_NUM_BITS) && - VerifyField(verifier, VT_NARROW_RANGE) && verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct FakeQuantOptionsBuilder +struct ReverseV2OptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_min(float min) { fbb_.AddElement(FakeQuantOptions::VT_MIN, min, 0.0f); } - void add_max(float max) { fbb_.AddElement(FakeQuantOptions::VT_MAX, max, 0.0f); } - void add_num_bits(int32_t num_bits) - { - fbb_.AddElement(FakeQuantOptions::VT_NUM_BITS, num_bits, 0); - } - void add_narrow_range(bool narrow_range) - { - fbb_.AddElement(FakeQuantOptions::VT_NARROW_RANGE, static_cast(narrow_range), - 0); - } - explicit FakeQuantOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit ReverseV2OptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - FakeQuantOptionsBuilder &operator=(const FakeQuantOptionsBuilder &); - flatbuffers::Offset Finish() + ReverseV2OptionsBuilder &operator=(const ReverseV2OptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateFakeQuantOptions(flatbuffers::FlatBufferBuilder &_fbb, float min = 0.0f, float max = 0.0f, - int32_t num_bits = 0, bool narrow_range = false) +inline flatbuffers::Offset +CreateReverseV2Options(flatbuffers::FlatBufferBuilder &_fbb) { - FakeQuantOptionsBuilder builder_(_fbb); - builder_.add_num_bits(num_bits); - builder_.add_max(max); - builder_.add_min(min); - builder_.add_narrow_range(narrow_range); + ReverseV2OptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct PackOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct AddNOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum - { - VT_VALUES_COUNT = 4, - VT_AXIS = 6 - }; - int32_t values_count() const { return GetField(VT_VALUES_COUNT, 0); } - int32_t axis() const { return GetField(VT_AXIS, 0); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_VALUES_COUNT) && - VerifyField(verifier, VT_AXIS) && verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct PackOptionsBuilder +struct AddNOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_values_count(int32_t values_count) - { - fbb_.AddElement(PackOptions::VT_VALUES_COUNT, values_count, 0); - } - void add_axis(int32_t axis) { fbb_.AddElement(PackOptions::VT_AXIS, axis, 0); } - explicit PackOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit AddNOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - PackOptionsBuilder &operator=(const PackOptionsBuilder &); - flatbuffers::Offset Finish() + AddNOptionsBuilder &operator=(const AddNOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreatePackOptions(flatbuffers::FlatBufferBuilder &_fbb, int32_t values_count = 0, int32_t axis = 0) +inline flatbuffers::Offset CreateAddNOptions(flatbuffers::FlatBufferBuilder &_fbb) { - PackOptionsBuilder builder_(_fbb); - builder_.add_axis(axis); - builder_.add_values_count(values_count); + AddNOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct LogicalOrOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct GatherNdOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { bool Verify(flatbuffers::Verifier &verifier) const { @@ -4845,102 +6585,113 @@ struct LogicalOrOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table } }; -struct LogicalOrOptionsBuilder +struct GatherNdOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit LogicalOrOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit GatherNdOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - LogicalOrOptionsBuilder &operator=(const LogicalOrOptionsBuilder &); - flatbuffers::Offset Finish() + GatherNdOptionsBuilder &operator=(const GatherNdOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateLogicalOrOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateGatherNdOptions(flatbuffers::FlatBufferBuilder &_fbb) { - LogicalOrOptionsBuilder builder_(_fbb); + GatherNdOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct OneHotOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct WhereOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum - { - VT_AXIS = 4 - }; - int32_t axis() const { return GetField(VT_AXIS, 0); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_AXIS) && - verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct OneHotOptionsBuilder +struct WhereOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_axis(int32_t axis) { fbb_.AddElement(OneHotOptions::VT_AXIS, axis, 0); } - explicit OneHotOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit WhereOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - OneHotOptionsBuilder &operator=(const OneHotOptionsBuilder &); - flatbuffers::Offset Finish() + WhereOptionsBuilder &operator=(const WhereOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateOneHotOptions(flatbuffers::FlatBufferBuilder &_fbb, - int32_t axis = 0) +inline flatbuffers::Offset CreateWhereOptions(flatbuffers::FlatBufferBuilder &_fbb) { - OneHotOptionsBuilder builder_(_fbb); - builder_.add_axis(axis); + WhereOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct AbsOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct ReverseSequenceOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + enum + { + VT_SEQ_DIM = 4, + VT_BATCH_DIM = 6 + }; + int32_t seq_dim() const { return GetField(VT_SEQ_DIM, 0); } + int32_t batch_dim() const { return GetField(VT_BATCH_DIM, 0); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyField(verifier, VT_SEQ_DIM) && + VerifyField(verifier, VT_BATCH_DIM) && verifier.EndTable(); } }; -struct AbsOptionsBuilder +struct ReverseSequenceOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit AbsOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + void add_seq_dim(int32_t seq_dim) + { + fbb_.AddElement(ReverseSequenceOptions::VT_SEQ_DIM, seq_dim, 0); + } + void add_batch_dim(int32_t batch_dim) + { + fbb_.AddElement(ReverseSequenceOptions::VT_BATCH_DIM, batch_dim, 0); + } + explicit ReverseSequenceOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - AbsOptionsBuilder &operator=(const AbsOptionsBuilder &); - flatbuffers::Offset Finish() + ReverseSequenceOptionsBuilder &operator=(const ReverseSequenceOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateAbsOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateReverseSequenceOptions(flatbuffers::FlatBufferBuilder &_fbb, int32_t seq_dim = 0, + int32_t batch_dim = 0) { - AbsOptionsBuilder builder_(_fbb); + ReverseSequenceOptionsBuilder builder_(_fbb); + builder_.add_batch_dim(batch_dim); + builder_.add_seq_dim(seq_dim); return builder_.Finish(); } -struct LogicalAndOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct MatrixDiagOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { bool Verify(flatbuffers::Verifier &verifier) const { @@ -4948,31 +6699,31 @@ struct LogicalAndOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table } }; -struct LogicalAndOptionsBuilder +struct MatrixDiagOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit LogicalAndOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit MatrixDiagOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - LogicalAndOptionsBuilder &operator=(const LogicalAndOptionsBuilder &); - flatbuffers::Offset Finish() + MatrixDiagOptionsBuilder &operator=(const MatrixDiagOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateLogicalAndOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateMatrixDiagOptions(flatbuffers::FlatBufferBuilder &_fbb) { - LogicalAndOptionsBuilder builder_(_fbb); + MatrixDiagOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct LogicalNotOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct QuantizeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { bool Verify(flatbuffers::Verifier &verifier) const { @@ -4980,138 +6731,165 @@ struct LogicalNotOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table } }; -struct LogicalNotOptionsBuilder +struct QuantizeOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit LogicalNotOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit QuantizeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - LogicalNotOptionsBuilder &operator=(const LogicalNotOptionsBuilder &); - flatbuffers::Offset Finish() + QuantizeOptionsBuilder &operator=(const QuantizeOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateLogicalNotOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateQuantizeOptions(flatbuffers::FlatBufferBuilder &_fbb) { - LogicalNotOptionsBuilder builder_(_fbb); + QuantizeOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct UnpackOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct MatrixSetDiagOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum - { - VT_NUM = 4, - VT_AXIS = 6 - }; - int32_t num() const { return GetField(VT_NUM, 0); } - int32_t axis() const { return GetField(VT_AXIS, 0); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_NUM) && - VerifyField(verifier, VT_AXIS) && verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct UnpackOptionsBuilder +struct MatrixSetDiagOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_num(int32_t num) { fbb_.AddElement(UnpackOptions::VT_NUM, num, 0); } - void add_axis(int32_t axis) { fbb_.AddElement(UnpackOptions::VT_AXIS, axis, 0); } - explicit UnpackOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit MatrixSetDiagOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - UnpackOptionsBuilder &operator=(const UnpackOptionsBuilder &); - flatbuffers::Offset Finish() + MatrixSetDiagOptionsBuilder &operator=(const MatrixSetDiagOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateUnpackOptions(flatbuffers::FlatBufferBuilder &_fbb, - int32_t num = 0, int32_t axis = 0) +inline flatbuffers::Offset +CreateMatrixSetDiagOptions(flatbuffers::FlatBufferBuilder &_fbb) { - UnpackOptionsBuilder builder_(_fbb); - builder_.add_axis(axis); - builder_.add_num(num); + MatrixSetDiagOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct FloorDivOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct IfOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + enum + { + VT_THEN_SUBGRAPH_INDEX = 4, + VT_ELSE_SUBGRAPH_INDEX = 6 + }; + int32_t then_subgraph_index() const { return GetField(VT_THEN_SUBGRAPH_INDEX, 0); } + int32_t else_subgraph_index() const { return GetField(VT_ELSE_SUBGRAPH_INDEX, 0); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyField(verifier, VT_THEN_SUBGRAPH_INDEX) && + VerifyField(verifier, VT_ELSE_SUBGRAPH_INDEX) && verifier.EndTable(); } }; -struct FloorDivOptionsBuilder +struct IfOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit FloorDivOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + void add_then_subgraph_index(int32_t then_subgraph_index) + { + fbb_.AddElement(IfOptions::VT_THEN_SUBGRAPH_INDEX, then_subgraph_index, 0); + } + void add_else_subgraph_index(int32_t else_subgraph_index) + { + fbb_.AddElement(IfOptions::VT_ELSE_SUBGRAPH_INDEX, else_subgraph_index, 0); + } + explicit IfOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - FloorDivOptionsBuilder &operator=(const FloorDivOptionsBuilder &); - flatbuffers::Offset Finish() + IfOptionsBuilder &operator=(const IfOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateFloorDivOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset CreateIfOptions(flatbuffers::FlatBufferBuilder &_fbb, + int32_t then_subgraph_index = 0, + int32_t else_subgraph_index = 0) { - FloorDivOptionsBuilder builder_(_fbb); + IfOptionsBuilder builder_(_fbb); + builder_.add_else_subgraph_index(else_subgraph_index); + builder_.add_then_subgraph_index(then_subgraph_index); return builder_.Finish(); } -struct SquareOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct WhileOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + enum + { + VT_COND_SUBGRAPH_INDEX = 4, + VT_BODY_SUBGRAPH_INDEX = 6 + }; + int32_t cond_subgraph_index() const { return GetField(VT_COND_SUBGRAPH_INDEX, 0); } + int32_t body_subgraph_index() const { return GetField(VT_BODY_SUBGRAPH_INDEX, 0); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyField(verifier, VT_COND_SUBGRAPH_INDEX) && + VerifyField(verifier, VT_BODY_SUBGRAPH_INDEX) && verifier.EndTable(); } }; -struct SquareOptionsBuilder +struct WhileOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit SquareOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + void add_cond_subgraph_index(int32_t cond_subgraph_index) + { + fbb_.AddElement(WhileOptions::VT_COND_SUBGRAPH_INDEX, cond_subgraph_index, 0); + } + void add_body_subgraph_index(int32_t body_subgraph_index) + { + fbb_.AddElement(WhileOptions::VT_BODY_SUBGRAPH_INDEX, body_subgraph_index, 0); + } + explicit WhileOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - SquareOptionsBuilder &operator=(const SquareOptionsBuilder &); - flatbuffers::Offset Finish() + WhileOptionsBuilder &operator=(const WhileOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateSquareOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset CreateWhileOptions(flatbuffers::FlatBufferBuilder &_fbb, + int32_t cond_subgraph_index = 0, + int32_t body_subgraph_index = 0) { - SquareOptionsBuilder builder_(_fbb); + WhileOptionsBuilder builder_(_fbb); + builder_.add_body_subgraph_index(body_subgraph_index); + builder_.add_cond_subgraph_index(cond_subgraph_index); return builder_.Finish(); } -struct ZerosLikeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct NonMaxSuppressionV4Options FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { bool Verify(flatbuffers::Verifier &verifier) const { @@ -5119,31 +6897,31 @@ struct ZerosLikeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table } }; -struct ZerosLikeOptionsBuilder +struct NonMaxSuppressionV4OptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit ZerosLikeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit NonMaxSuppressionV4OptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - ZerosLikeOptionsBuilder &operator=(const ZerosLikeOptionsBuilder &); - flatbuffers::Offset Finish() + NonMaxSuppressionV4OptionsBuilder &operator=(const NonMaxSuppressionV4OptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateZerosLikeOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateNonMaxSuppressionV4Options(flatbuffers::FlatBufferBuilder &_fbb) { - ZerosLikeOptionsBuilder builder_(_fbb); + NonMaxSuppressionV4OptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct FillOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct NonMaxSuppressionV5Options FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { bool Verify(flatbuffers::Verifier &verifier) const { @@ -5151,30 +6929,31 @@ struct FillOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table } }; -struct FillOptionsBuilder +struct NonMaxSuppressionV5OptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit FillOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit NonMaxSuppressionV5OptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - FillOptionsBuilder &operator=(const FillOptionsBuilder &); - flatbuffers::Offset Finish() + NonMaxSuppressionV5OptionsBuilder &operator=(const NonMaxSuppressionV5OptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateFillOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateNonMaxSuppressionV5Options(flatbuffers::FlatBufferBuilder &_fbb) { - FillOptionsBuilder builder_(_fbb); + NonMaxSuppressionV5OptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct FloorModOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct ScatterNdOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { bool Verify(flatbuffers::Verifier &verifier) const { @@ -5182,31 +6961,31 @@ struct FloorModOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table } }; -struct FloorModOptionsBuilder +struct ScatterNdOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit FloorModOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit ScatterNdOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - FloorModOptionsBuilder &operator=(const FloorModOptionsBuilder &); - flatbuffers::Offset Finish() + ScatterNdOptionsBuilder &operator=(const ScatterNdOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateFloorModOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateScatterNdOptions(flatbuffers::FlatBufferBuilder &_fbb) { - FloorModOptionsBuilder builder_(_fbb); + ScatterNdOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct RangeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct SelectV2Options FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { bool Verify(flatbuffers::Verifier &verifier) const { @@ -5214,70 +6993,63 @@ struct RangeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table } }; -struct RangeOptionsBuilder +struct SelectV2OptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit RangeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit SelectV2OptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - RangeOptionsBuilder &operator=(const RangeOptionsBuilder &); - flatbuffers::Offset Finish() + SelectV2OptionsBuilder &operator=(const SelectV2OptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateRangeOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateSelectV2Options(flatbuffers::FlatBufferBuilder &_fbb) { - RangeOptionsBuilder builder_(_fbb); + SelectV2OptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct LeakyReluOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct DensifyOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum - { - VT_ALPHA = 4 - }; - float alpha() const { return GetField(VT_ALPHA, 0.0f); } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_ALPHA) && - verifier.EndTable(); + return VerifyTableStart(verifier) && verifier.EndTable(); } }; -struct LeakyReluOptionsBuilder +struct DensifyOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_alpha(float alpha) { fbb_.AddElement(LeakyReluOptions::VT_ALPHA, alpha, 0.0f); } - explicit LeakyReluOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit DensifyOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - LeakyReluOptionsBuilder &operator=(const LeakyReluOptionsBuilder &); - flatbuffers::Offset Finish() + DensifyOptionsBuilder &operator=(const DensifyOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateLeakyReluOptions(flatbuffers::FlatBufferBuilder &_fbb, float alpha = 0.0f) +inline flatbuffers::Offset +CreateDensifyOptions(flatbuffers::FlatBufferBuilder &_fbb) { - LeakyReluOptionsBuilder builder_(_fbb); - builder_.add_alpha(alpha); + DensifyOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct SquaredDifferenceOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct SegmentSumOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { bool Verify(flatbuffers::Verifier &verifier) const { @@ -5285,71 +7057,80 @@ struct SquaredDifferenceOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::T } }; -struct SquaredDifferenceOptionsBuilder +struct SegmentSumOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - explicit SquaredDifferenceOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + explicit SegmentSumOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - SquaredDifferenceOptionsBuilder &operator=(const SquaredDifferenceOptionsBuilder &); - flatbuffers::Offset Finish() + SegmentSumOptionsBuilder &operator=(const SegmentSumOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateSquaredDifferenceOptions(flatbuffers::FlatBufferBuilder &_fbb) +inline flatbuffers::Offset +CreateSegmentSumOptions(flatbuffers::FlatBufferBuilder &_fbb) { - SquaredDifferenceOptionsBuilder builder_(_fbb); + SegmentSumOptionsBuilder builder_(_fbb); return builder_.Finish(); } -struct MirrorPadOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +struct BatchMatMulOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_MODE = 4 + VT_ADJOINT_LHS = 4, + VT_ADJOINT_RHS = 6 }; - MirrorPadMode mode() const { return static_cast(GetField(VT_MODE, 0)); } + bool adjoint_lhs() const { return GetField(VT_ADJOINT_LHS, 0) != 0; } + bool adjoint_rhs() const { return GetField(VT_ADJOINT_RHS, 0) != 0; } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && VerifyField(verifier, VT_MODE) && - verifier.EndTable(); + return VerifyTableStart(verifier) && VerifyField(verifier, VT_ADJOINT_LHS) && + VerifyField(verifier, VT_ADJOINT_RHS) && verifier.EndTable(); } }; -struct MirrorPadOptionsBuilder +struct BatchMatMulOptionsBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_mode(MirrorPadMode mode) + void add_adjoint_lhs(bool adjoint_lhs) { - fbb_.AddElement(MirrorPadOptions::VT_MODE, static_cast(mode), 0); + fbb_.AddElement(BatchMatMulOptions::VT_ADJOINT_LHS, static_cast(adjoint_lhs), + 0); } - explicit MirrorPadOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + void add_adjoint_rhs(bool adjoint_rhs) + { + fbb_.AddElement(BatchMatMulOptions::VT_ADJOINT_RHS, static_cast(adjoint_rhs), + 0); + } + explicit BatchMatMulOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - MirrorPadOptionsBuilder &operator=(const MirrorPadOptionsBuilder &); - flatbuffers::Offset Finish() + BatchMatMulOptionsBuilder &operator=(const BatchMatMulOptionsBuilder &); + flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset -CreateMirrorPadOptions(flatbuffers::FlatBufferBuilder &_fbb, - MirrorPadMode mode = MirrorPadMode_REFLECT) +inline flatbuffers::Offset +CreateBatchMatMulOptions(flatbuffers::FlatBufferBuilder &_fbb, bool adjoint_lhs = false, + bool adjoint_rhs = false) { - MirrorPadOptionsBuilder builder_(_fbb); - builder_.add_mode(mode); + BatchMatMulOptionsBuilder builder_(_fbb); + builder_.add_adjoint_rhs(adjoint_rhs); + builder_.add_adjoint_lhs(adjoint_lhs); return builder_.Finish(); } @@ -5424,7 +7205,7 @@ CreateOperatorCodeDirect(flatbuffers::FlatBufferBuilder &_fbb, BuiltinOperator builtin_code = BuiltinOperator_ADD, const char *custom_code = nullptr, int32_t version = 1) { - return neurun_tflite::CreateOperatorCode( + return onert_tflite::CreateOperatorCode( _fbb, builtin_code, custom_code ? _fbb.CreateString(custom_code) : 0, version); } @@ -5439,7 +7220,8 @@ struct Operator FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table VT_BUILTIN_OPTIONS = 12, VT_CUSTOM_OPTIONS = 14, VT_CUSTOM_OPTIONS_FORMAT = 16, - VT_MUTATING_VARIABLE_INPUTS = 18 + VT_MUTATING_VARIABLE_INPUTS = 18, + VT_INTERMEDIATES = 20 }; uint32_t opcode_index() const { return GetField(VT_OPCODE_INDEX, 0); } const flatbuffers::Vector *inputs() const @@ -5868,69 +7650,201 @@ struct Operator FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table const BidirectionalSequenceLSTMOptions * builtin_options_as_BidirectionalSequenceLSTMOptions() const { - return builtin_options_type() == BuiltinOptions_BidirectionalSequenceLSTMOptions - ? static_cast(builtin_options()) + return builtin_options_type() == BuiltinOptions_BidirectionalSequenceLSTMOptions + ? static_cast(builtin_options()) + : nullptr; + } + const BidirectionalSequenceRNNOptions *builtin_options_as_BidirectionalSequenceRNNOptions() const + { + return builtin_options_type() == BuiltinOptions_BidirectionalSequenceRNNOptions + ? static_cast(builtin_options()) + : nullptr; + } + const UnidirectionalSequenceLSTMOptions * + builtin_options_as_UnidirectionalSequenceLSTMOptions() const + { + return builtin_options_type() == BuiltinOptions_UnidirectionalSequenceLSTMOptions + ? static_cast(builtin_options()) + : nullptr; + } + const FloorModOptions *builtin_options_as_FloorModOptions() const + { + return builtin_options_type() == BuiltinOptions_FloorModOptions + ? static_cast(builtin_options()) + : nullptr; + } + const RangeOptions *builtin_options_as_RangeOptions() const + { + return builtin_options_type() == BuiltinOptions_RangeOptions + ? static_cast(builtin_options()) + : nullptr; + } + const ResizeNearestNeighborOptions *builtin_options_as_ResizeNearestNeighborOptions() const + { + return builtin_options_type() == BuiltinOptions_ResizeNearestNeighborOptions + ? static_cast(builtin_options()) + : nullptr; + } + const LeakyReluOptions *builtin_options_as_LeakyReluOptions() const + { + return builtin_options_type() == BuiltinOptions_LeakyReluOptions + ? static_cast(builtin_options()) + : nullptr; + } + const SquaredDifferenceOptions *builtin_options_as_SquaredDifferenceOptions() const + { + return builtin_options_type() == BuiltinOptions_SquaredDifferenceOptions + ? static_cast(builtin_options()) + : nullptr; + } + const MirrorPadOptions *builtin_options_as_MirrorPadOptions() const + { + return builtin_options_type() == BuiltinOptions_MirrorPadOptions + ? static_cast(builtin_options()) + : nullptr; + } + const AbsOptions *builtin_options_as_AbsOptions() const + { + return builtin_options_type() == BuiltinOptions_AbsOptions + ? static_cast(builtin_options()) + : nullptr; + } + const SplitVOptions *builtin_options_as_SplitVOptions() const + { + return builtin_options_type() == BuiltinOptions_SplitVOptions + ? static_cast(builtin_options()) + : nullptr; + } + const UniqueOptions *builtin_options_as_UniqueOptions() const + { + return builtin_options_type() == BuiltinOptions_UniqueOptions + ? static_cast(builtin_options()) + : nullptr; + } + const ReverseV2Options *builtin_options_as_ReverseV2Options() const + { + return builtin_options_type() == BuiltinOptions_ReverseV2Options + ? static_cast(builtin_options()) + : nullptr; + } + const AddNOptions *builtin_options_as_AddNOptions() const + { + return builtin_options_type() == BuiltinOptions_AddNOptions + ? static_cast(builtin_options()) + : nullptr; + } + const GatherNdOptions *builtin_options_as_GatherNdOptions() const + { + return builtin_options_type() == BuiltinOptions_GatherNdOptions + ? static_cast(builtin_options()) + : nullptr; + } + const CosOptions *builtin_options_as_CosOptions() const + { + return builtin_options_type() == BuiltinOptions_CosOptions + ? static_cast(builtin_options()) + : nullptr; + } + const WhereOptions *builtin_options_as_WhereOptions() const + { + return builtin_options_type() == BuiltinOptions_WhereOptions + ? static_cast(builtin_options()) + : nullptr; + } + const RankOptions *builtin_options_as_RankOptions() const + { + return builtin_options_type() == BuiltinOptions_RankOptions + ? static_cast(builtin_options()) + : nullptr; + } + const ReverseSequenceOptions *builtin_options_as_ReverseSequenceOptions() const + { + return builtin_options_type() == BuiltinOptions_ReverseSequenceOptions + ? static_cast(builtin_options()) + : nullptr; + } + const MatrixDiagOptions *builtin_options_as_MatrixDiagOptions() const + { + return builtin_options_type() == BuiltinOptions_MatrixDiagOptions + ? static_cast(builtin_options()) + : nullptr; + } + const QuantizeOptions *builtin_options_as_QuantizeOptions() const + { + return builtin_options_type() == BuiltinOptions_QuantizeOptions + ? static_cast(builtin_options()) + : nullptr; + } + const MatrixSetDiagOptions *builtin_options_as_MatrixSetDiagOptions() const + { + return builtin_options_type() == BuiltinOptions_MatrixSetDiagOptions + ? static_cast(builtin_options()) + : nullptr; + } + const HardSwishOptions *builtin_options_as_HardSwishOptions() const + { + return builtin_options_type() == BuiltinOptions_HardSwishOptions + ? static_cast(builtin_options()) : nullptr; } - const BidirectionalSequenceRNNOptions *builtin_options_as_BidirectionalSequenceRNNOptions() const + const IfOptions *builtin_options_as_IfOptions() const { - return builtin_options_type() == BuiltinOptions_BidirectionalSequenceRNNOptions - ? static_cast(builtin_options()) + return builtin_options_type() == BuiltinOptions_IfOptions + ? static_cast(builtin_options()) : nullptr; } - const UnidirectionalSequenceLSTMOptions * - builtin_options_as_UnidirectionalSequenceLSTMOptions() const + const WhileOptions *builtin_options_as_WhileOptions() const { - return builtin_options_type() == BuiltinOptions_UnidirectionalSequenceLSTMOptions - ? static_cast(builtin_options()) + return builtin_options_type() == BuiltinOptions_WhileOptions + ? static_cast(builtin_options()) : nullptr; } - const FloorModOptions *builtin_options_as_FloorModOptions() const + const DepthToSpaceOptions *builtin_options_as_DepthToSpaceOptions() const { - return builtin_options_type() == BuiltinOptions_FloorModOptions - ? static_cast(builtin_options()) + return builtin_options_type() == BuiltinOptions_DepthToSpaceOptions + ? static_cast(builtin_options()) : nullptr; } - const RangeOptions *builtin_options_as_RangeOptions() const + const NonMaxSuppressionV4Options *builtin_options_as_NonMaxSuppressionV4Options() const { - return builtin_options_type() == BuiltinOptions_RangeOptions - ? static_cast(builtin_options()) + return builtin_options_type() == BuiltinOptions_NonMaxSuppressionV4Options + ? static_cast(builtin_options()) : nullptr; } - const ResizeNearestNeighborOptions *builtin_options_as_ResizeNearestNeighborOptions() const + const NonMaxSuppressionV5Options *builtin_options_as_NonMaxSuppressionV5Options() const { - return builtin_options_type() == BuiltinOptions_ResizeNearestNeighborOptions - ? static_cast(builtin_options()) + return builtin_options_type() == BuiltinOptions_NonMaxSuppressionV5Options + ? static_cast(builtin_options()) : nullptr; } - const LeakyReluOptions *builtin_options_as_LeakyReluOptions() const + const ScatterNdOptions *builtin_options_as_ScatterNdOptions() const { - return builtin_options_type() == BuiltinOptions_LeakyReluOptions - ? static_cast(builtin_options()) + return builtin_options_type() == BuiltinOptions_ScatterNdOptions + ? static_cast(builtin_options()) : nullptr; } - const SquaredDifferenceOptions *builtin_options_as_SquaredDifferenceOptions() const + const SelectV2Options *builtin_options_as_SelectV2Options() const { - return builtin_options_type() == BuiltinOptions_SquaredDifferenceOptions - ? static_cast(builtin_options()) + return builtin_options_type() == BuiltinOptions_SelectV2Options + ? static_cast(builtin_options()) : nullptr; } - const MirrorPadOptions *builtin_options_as_MirrorPadOptions() const + const DensifyOptions *builtin_options_as_DensifyOptions() const { - return builtin_options_type() == BuiltinOptions_MirrorPadOptions - ? static_cast(builtin_options()) + return builtin_options_type() == BuiltinOptions_DensifyOptions + ? static_cast(builtin_options()) : nullptr; } - const AbsOptions *builtin_options_as_AbsOptions() const + const SegmentSumOptions *builtin_options_as_SegmentSumOptions() const { - return builtin_options_type() == BuiltinOptions_AbsOptions - ? static_cast(builtin_options()) + return builtin_options_type() == BuiltinOptions_SegmentSumOptions + ? static_cast(builtin_options()) : nullptr; } - const SplitVOptions *builtin_options_as_SplitVOptions() const + const BatchMatMulOptions *builtin_options_as_BatchMatMulOptions() const { - return builtin_options_type() == BuiltinOptions_SplitVOptions - ? static_cast(builtin_options()) + return builtin_options_type() == BuiltinOptions_BatchMatMulOptions + ? static_cast(builtin_options()) : nullptr; } const flatbuffers::Vector *custom_options() const @@ -5945,6 +7859,10 @@ struct Operator FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { return GetPointer *>(VT_MUTATING_VARIABLE_INPUTS); } + const flatbuffers::Vector *intermediates() const + { + return GetPointer *>(VT_INTERMEDIATES); + } bool Verify(flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && VerifyField(verifier, VT_OPCODE_INDEX) && @@ -5956,7 +7874,9 @@ struct Operator FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table VerifyOffset(verifier, VT_CUSTOM_OPTIONS) && verifier.VerifyVector(custom_options()) && VerifyField(verifier, VT_CUSTOM_OPTIONS_FORMAT) && VerifyOffset(verifier, VT_MUTATING_VARIABLE_INPUTS) && - verifier.VerifyVector(mutating_variable_inputs()) && verifier.EndTable(); + verifier.VerifyVector(mutating_variable_inputs()) && + VerifyOffset(verifier, VT_INTERMEDIATES) && verifier.VerifyVector(intermediates()) && + verifier.EndTable(); } }; @@ -6384,6 +8304,124 @@ template <> inline const SplitVOptions *Operator::builtin_options_as inline const UniqueOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_UniqueOptions(); +} + +template <> inline const ReverseV2Options *Operator::builtin_options_as() const +{ + return builtin_options_as_ReverseV2Options(); +} + +template <> inline const AddNOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_AddNOptions(); +} + +template <> inline const GatherNdOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_GatherNdOptions(); +} + +template <> inline const CosOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_CosOptions(); +} + +template <> inline const WhereOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_WhereOptions(); +} + +template <> inline const RankOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_RankOptions(); +} + +template <> +inline const ReverseSequenceOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_ReverseSequenceOptions(); +} + +template <> inline const MatrixDiagOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_MatrixDiagOptions(); +} + +template <> inline const QuantizeOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_QuantizeOptions(); +} + +template <> +inline const MatrixSetDiagOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_MatrixSetDiagOptions(); +} + +template <> inline const HardSwishOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_HardSwishOptions(); +} + +template <> inline const IfOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_IfOptions(); +} + +template <> inline const WhileOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_WhileOptions(); +} + +template <> +inline const DepthToSpaceOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_DepthToSpaceOptions(); +} + +template <> +inline const NonMaxSuppressionV4Options * +Operator::builtin_options_as() const +{ + return builtin_options_as_NonMaxSuppressionV4Options(); +} + +template <> +inline const NonMaxSuppressionV5Options * +Operator::builtin_options_as() const +{ + return builtin_options_as_NonMaxSuppressionV5Options(); +} + +template <> inline const ScatterNdOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_ScatterNdOptions(); +} + +template <> inline const SelectV2Options *Operator::builtin_options_as() const +{ + return builtin_options_as_SelectV2Options(); +} + +template <> inline const DensifyOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_DensifyOptions(); +} + +template <> inline const SegmentSumOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_SegmentSumOptions(); +} + +template <> +inline const BatchMatMulOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_BatchMatMulOptions(); +} + struct OperatorBuilder { flatbuffers::FlatBufferBuilder &fbb_; @@ -6423,6 +8461,10 @@ struct OperatorBuilder { fbb_.AddOffset(Operator::VT_MUTATING_VARIABLE_INPUTS, mutating_variable_inputs); } + void add_intermediates(flatbuffers::Offset> intermediates) + { + fbb_.AddOffset(Operator::VT_INTERMEDIATES, intermediates); + } explicit OperatorBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); @@ -6444,9 +8486,11 @@ CreateOperator(flatbuffers::FlatBufferBuilder &_fbb, uint32_t opcode_index = 0, flatbuffers::Offset builtin_options = 0, flatbuffers::Offset> custom_options = 0, CustomOptionsFormat custom_options_format = CustomOptionsFormat_FLEXBUFFERS, - flatbuffers::Offset> mutating_variable_inputs = 0) + flatbuffers::Offset> mutating_variable_inputs = 0, + flatbuffers::Offset> intermediates = 0) { OperatorBuilder builder_(_fbb); + builder_.add_intermediates(intermediates); builder_.add_mutating_variable_inputs(mutating_variable_inputs); builder_.add_custom_options(custom_options); builder_.add_builtin_options(builtin_options); @@ -6466,13 +8510,15 @@ CreateOperatorDirect(flatbuffers::FlatBufferBuilder &_fbb, uint32_t opcode_index flatbuffers::Offset builtin_options = 0, const std::vector *custom_options = nullptr, CustomOptionsFormat custom_options_format = CustomOptionsFormat_FLEXBUFFERS, - const std::vector *mutating_variable_inputs = nullptr) + const std::vector *mutating_variable_inputs = nullptr, + const std::vector *intermediates = nullptr) { - return neurun_tflite::CreateOperator( + return onert_tflite::CreateOperator( _fbb, opcode_index, inputs ? _fbb.CreateVector(*inputs) : 0, outputs ? _fbb.CreateVector(*outputs) : 0, builtin_options_type, builtin_options, custom_options ? _fbb.CreateVector(*custom_options) : 0, custom_options_format, - mutating_variable_inputs ? _fbb.CreateVector(*mutating_variable_inputs) : 0); + mutating_variable_inputs ? _fbb.CreateVector(*mutating_variable_inputs) : 0, + intermediates ? _fbb.CreateVector(*intermediates) : 0); } struct SubGraph FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table @@ -6580,7 +8626,7 @@ CreateSubGraphDirect(flatbuffers::FlatBufferBuilder &_fbb, const std::vector> *operators = nullptr, const char *name = nullptr) { - return neurun_tflite::CreateSubGraph( + return onert_tflite::CreateSubGraph( _fbb, tensors ? _fbb.CreateVector>(*tensors) : 0, inputs ? _fbb.CreateVector(*inputs) : 0, outputs ? _fbb.CreateVector(*outputs) : 0, @@ -6638,7 +8684,66 @@ CreateBuffer(flatbuffers::FlatBufferBuilder &_fbb, inline flatbuffers::Offset CreateBufferDirect(flatbuffers::FlatBufferBuilder &_fbb, const std::vector *data = nullptr) { - return neurun_tflite::CreateBuffer(_fbb, data ? _fbb.CreateVector(*data) : 0); + return onert_tflite::CreateBuffer(_fbb, data ? _fbb.CreateVector(*data) : 0); +} + +struct Metadata FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table +{ + enum + { + VT_NAME = 4, + VT_BUFFER = 6 + }; + const flatbuffers::String *name() const + { + return GetPointer(VT_NAME); + } + uint32_t buffer() const { return GetField(VT_BUFFER, 0); } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && VerifyOffset(verifier, VT_NAME) && + verifier.VerifyString(name()) && VerifyField(verifier, VT_BUFFER) && + verifier.EndTable(); + } +}; + +struct MetadataBuilder +{ + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_name(flatbuffers::Offset name) + { + fbb_.AddOffset(Metadata::VT_NAME, name); + } + void add_buffer(uint32_t buffer) { fbb_.AddElement(Metadata::VT_BUFFER, buffer, 0); } + explicit MetadataBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + MetadataBuilder &operator=(const MetadataBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset +CreateMetadata(flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset name = 0, uint32_t buffer = 0) +{ + MetadataBuilder builder_(_fbb); + builder_.add_buffer(buffer); + builder_.add_name(name); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreateMetadataDirect(flatbuffers::FlatBufferBuilder &_fbb, + const char *name = nullptr, + uint32_t buffer = 0) +{ + return onert_tflite::CreateMetadata(_fbb, name ? _fbb.CreateString(name) : 0, buffer); } struct Model FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table @@ -6650,7 +8755,8 @@ struct Model FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table VT_SUBGRAPHS = 8, VT_DESCRIPTION = 10, VT_BUFFERS = 12, - VT_METADATA_BUFFER = 14 + VT_METADATA_BUFFER = 14, + VT_METADATA = 16 }; uint32_t version() const { return GetField(VT_VERSION, 0); } const flatbuffers::Vector> *operator_codes() const @@ -6674,6 +8780,10 @@ struct Model FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { return GetPointer *>(VT_METADATA_BUFFER); } + const flatbuffers::Vector> *metadata() const + { + return GetPointer> *>(VT_METADATA); + } bool Verify(flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && VerifyField(verifier, VT_VERSION) && @@ -6684,7 +8794,8 @@ struct Model FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table verifier.VerifyString(description()) && VerifyOffset(verifier, VT_BUFFERS) && verifier.VerifyVector(buffers()) && verifier.VerifyVectorOfTables(buffers()) && VerifyOffset(verifier, VT_METADATA_BUFFER) && verifier.VerifyVector(metadata_buffer()) && - verifier.EndTable(); + VerifyOffset(verifier, VT_METADATA) && verifier.VerifyVector(metadata()) && + verifier.VerifyVectorOfTables(metadata()) && verifier.EndTable(); } }; @@ -6715,6 +8826,11 @@ struct ModelBuilder { fbb_.AddOffset(Model::VT_METADATA_BUFFER, metadata_buffer); } + void + add_metadata(flatbuffers::Offset>> metadata) + { + fbb_.AddOffset(Model::VT_METADATA, metadata); + } explicit ModelBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); @@ -6734,9 +8850,11 @@ inline flatbuffers::Offset CreateModel( flatbuffers::Offset>> subgraphs = 0, flatbuffers::Offset description = 0, flatbuffers::Offset>> buffers = 0, - flatbuffers::Offset> metadata_buffer = 0) + flatbuffers::Offset> metadata_buffer = 0, + flatbuffers::Offset>> metadata = 0) { ModelBuilder builder_(_fbb); + builder_.add_metadata(metadata); builder_.add_metadata_buffer(metadata_buffer); builder_.add_buffers(buffers); builder_.add_description(description); @@ -6752,15 +8870,17 @@ CreateModelDirect(flatbuffers::FlatBufferBuilder &_fbb, uint32_t version = 0, const std::vector> *subgraphs = nullptr, const char *description = nullptr, const std::vector> *buffers = nullptr, - const std::vector *metadata_buffer = nullptr) + const std::vector *metadata_buffer = nullptr, + const std::vector> *metadata = nullptr) { - return neurun_tflite::CreateModel( + return onert_tflite::CreateModel( _fbb, version, operator_codes ? _fbb.CreateVector>(*operator_codes) : 0, subgraphs ? _fbb.CreateVector>(*subgraphs) : 0, description ? _fbb.CreateString(description) : 0, buffers ? _fbb.CreateVector>(*buffers) : 0, - metadata_buffer ? _fbb.CreateVector(*metadata_buffer) : 0); + metadata_buffer ? _fbb.CreateVector(*metadata_buffer) : 0, + metadata ? _fbb.CreateVector>(*metadata) : 0); } inline bool VerifyQuantizationDetails(flatbuffers::Verifier &verifier, const void *obj, @@ -6802,6 +8922,54 @@ VerifyQuantizationDetailsVector(flatbuffers::Verifier &verifier, return true; } +inline bool VerifySparseIndexVector(flatbuffers::Verifier &verifier, const void *obj, + SparseIndexVector type) +{ + switch (type) + { + case SparseIndexVector_NONE: + { + return true; + } + case SparseIndexVector_Int32Vector: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case SparseIndexVector_Uint16Vector: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case SparseIndexVector_Uint8Vector: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + default: + return false; + } +} + +inline bool +VerifySparseIndexVectorVector(flatbuffers::Verifier &verifier, + const flatbuffers::Vector> *values, + const flatbuffers::Vector *types) +{ + if (!values || !types) + return !values && !types; + if (values->size() != types->size()) + return false; + for (flatbuffers::uoffset_t i = 0; i < values->size(); ++i) + { + if (!VerifySparseIndexVector(verifier, values->Get(i), types->GetEnum(i))) + { + return false; + } + } + return true; +} + inline bool VerifyBuiltinOptions(flatbuffers::Verifier &verifier, const void *obj, BuiltinOptions type) { @@ -7206,6 +9374,116 @@ inline bool VerifyBuiltinOptions(flatbuffers::Verifier &verifier, const void *ob auto ptr = reinterpret_cast(obj); return verifier.VerifyTable(ptr); } + case BuiltinOptions_UniqueOptions: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_ReverseV2Options: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_AddNOptions: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_GatherNdOptions: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_CosOptions: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_WhereOptions: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_RankOptions: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_ReverseSequenceOptions: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_MatrixDiagOptions: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_QuantizeOptions: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_MatrixSetDiagOptions: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_HardSwishOptions: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_IfOptions: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_WhileOptions: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_DepthToSpaceOptions: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_NonMaxSuppressionV4Options: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_NonMaxSuppressionV5Options: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_ScatterNdOptions: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_SelectV2Options: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_DensifyOptions: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_SegmentSumOptions: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_BatchMatMulOptions: + { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } default: return false; } @@ -7229,14 +9507,14 @@ inline bool VerifyBuiltinOptionsVector(flatbuffers::Verifier &verifier, return true; } -inline const neurun_tflite::Model *GetModel(const void *buf) +inline const onert_tflite::Model *GetModel(const void *buf) { - return flatbuffers::GetRoot(buf); + return flatbuffers::GetRoot(buf); } -inline const neurun_tflite::Model *GetSizePrefixedModel(const void *buf) +inline const onert_tflite::Model *GetSizePrefixedModel(const void *buf) { - return flatbuffers::GetSizePrefixedRoot(buf); + return flatbuffers::GetSizePrefixedRoot(buf); } inline const char *ModelIdentifier() { return "TFL3"; } @@ -7248,28 +9526,28 @@ inline bool ModelBufferHasIdentifier(const void *buf) inline bool VerifyModelBuffer(flatbuffers::Verifier &verifier) { - return verifier.VerifyBuffer(ModelIdentifier()); + return verifier.VerifyBuffer(ModelIdentifier()); } inline bool VerifySizePrefixedModelBuffer(flatbuffers::Verifier &verifier) { - return verifier.VerifySizePrefixedBuffer(ModelIdentifier()); + return verifier.VerifySizePrefixedBuffer(ModelIdentifier()); } inline const char *ModelExtension() { return "tflite"; } inline void FinishModelBuffer(flatbuffers::FlatBufferBuilder &fbb, - flatbuffers::Offset root) + flatbuffers::Offset root) { fbb.Finish(root, ModelIdentifier()); } inline void FinishSizePrefixedModelBuffer(flatbuffers::FlatBufferBuilder &fbb, - flatbuffers::Offset root) + flatbuffers::Offset root) { fbb.FinishSizePrefixed(root, ModelIdentifier()); } -} // namespace neurun_tflite +} // namespace onert_tflite -#endif // FLATBUFFERS_GENERATED_SCHEMA_NEURUN_TFLITE_H_ +#endif // FLATBUFFERS_GENERATED_TFLITESCHEMA_ONERT_TFLITE_H_ diff --git a/runtime/onert/frontend/tflite/tflite_schema-1.13.1.fbs b/runtime/onert/frontend/tflite/tflite_schema-1.13.1.fbs new file mode 100644 index 00000000000..ae6b5230f09 --- /dev/null +++ b/runtime/onert/frontend/tflite/tflite_schema-1.13.1.fbs @@ -0,0 +1,795 @@ +// Copyright 2017 The TensorFlow Authors. 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. + +// Revision History +// Version 0: Initial version. +// Version 1: Add subgraphs to schema. +// Version 2: Rename operators to conform to NN API. +// Version 3: Move buffer data from Model.Subgraph.Tensors to Model.Buffers. + +// Change namespace to onert_tflite +namespace onert_tflite; + +// This corresponds to the version. +file_identifier "TFL3"; +// File extension of any written files. +file_extension "tflite"; + +// IMPORTANT: All new members of tables, enums and unions must be added at the +// end to ensure backwards compatibility. + +// The type of data stored in a tensor. +enum TensorType : byte { + FLOAT32 = 0, + FLOAT16 = 1, + INT32 = 2, + UINT8 = 3, + INT64 = 4, + STRING = 5, + BOOL = 6, + INT16 = 7, + COMPLEX64 = 8, + INT8 = 9, +} + +// Custom quantization parameters for experimenting with new quantization +// techniques. +table CustomQuantization { + custom:[ubyte] (force_align: 16); +} + +// Represents a specific quantization technique's parameters. +union QuantizationDetails { + CustomQuantization, +} + +// Parameters for converting a quantized tensor back to float. +table QuantizationParameters { + // These four parameters are the asymmetric linear quantization parameters. + // Given a quantized value q, the corresponding float value f should be: + // f = scale * (q - zero_point) + // For other quantization types, the QuantizationDetails below is used. + min:[float]; // For importing back into tensorflow. + max:[float]; // For importing back into tensorflow. + scale:[float]; // For dequantizing the tensor's values. + zero_point:[long]; + + // If this is not none, the quantization parameters above are ignored and the + // value of the QuantizationDetails union below should be used. + details:QuantizationDetails; +} + +table Tensor { + // The tensor shape. The meaning of each entry is operator-specific but + // builtin ops use: [batch size, height, width, number of channels] (That's + // Tensorflow's NHWC). + shape:[int]; + type:TensorType; + // An index that refers to the buffers table at the root of the model. Or, + // if there is no data buffer associated (i.e. intermediate results), then + // this is 0 (which refers to an always existent empty buffer). + // + // The data_buffer itself is an opaque container, with the assumption that the + // target device is little-endian. In addition, all builtin operators assume + // the memory is ordered such that if `shape` is [4, 3, 2], then index + // [i, j, k] maps to data_buffer[i*3*2 + j*2 + k]. + buffer:uint; + name:string; // For debugging and importing back into tensorflow. + quantization:QuantizationParameters; // Optional. + + is_variable:bool = false; +} + +// A list of builtin operators. Builtin operators are slightly faster than custom +// ones, but not by much. Moreover, while custom operators accept an opaque +// object containing configuration parameters, builtins have a predetermined +// set of acceptable options. +enum BuiltinOperator : byte { + ADD = 0, + AVERAGE_POOL_2D = 1, + CONCATENATION = 2, + CONV_2D = 3, + DEPTHWISE_CONV_2D = 4, + // DEPTH_TO_SPACE = 5, + DEQUANTIZE = 6, + EMBEDDING_LOOKUP = 7, + FLOOR = 8, + FULLY_CONNECTED = 9, + HASHTABLE_LOOKUP = 10, + L2_NORMALIZATION = 11, + L2_POOL_2D = 12, + LOCAL_RESPONSE_NORMALIZATION = 13, + LOGISTIC = 14, + LSH_PROJECTION = 15, + LSTM = 16, + MAX_POOL_2D = 17, + MUL = 18, + RELU = 19, + // NOTE(aselle): RELU_N1_TO_1 used to be called RELU1, but it was renamed + // since different model developers use RELU1 in different ways. Never + // create another op called RELU1. + RELU_N1_TO_1 = 20, + RELU6 = 21, + RESHAPE = 22, + RESIZE_BILINEAR = 23, + RNN = 24, + SOFTMAX = 25, + SPACE_TO_DEPTH = 26, + SVDF = 27, + TANH = 28, + // TODO(aselle): Consider rename to CONCATENATE_EMBEDDINGS + CONCAT_EMBEDDINGS = 29, + SKIP_GRAM = 30, + CALL = 31, + CUSTOM = 32, + EMBEDDING_LOOKUP_SPARSE = 33, + PAD = 34, + UNIDIRECTIONAL_SEQUENCE_RNN = 35, + GATHER = 36, + BATCH_TO_SPACE_ND = 37, + SPACE_TO_BATCH_ND = 38, + TRANSPOSE = 39, + MEAN = 40, + SUB = 41, + DIV = 42, + SQUEEZE = 43, + UNIDIRECTIONAL_SEQUENCE_LSTM = 44, + STRIDED_SLICE = 45, + BIDIRECTIONAL_SEQUENCE_RNN = 46, + EXP = 47, + TOPK_V2 = 48, + SPLIT = 49, + LOG_SOFTMAX = 50, + // DELEGATE is a special op type for the operations which are delegated to + // other backends. + // WARNING: Experimental interface, subject to change + DELEGATE = 51, + BIDIRECTIONAL_SEQUENCE_LSTM = 52, + CAST = 53, + PRELU = 54, + MAXIMUM = 55, + ARG_MAX = 56, + MINIMUM = 57, + LESS = 58, + NEG = 59, + PADV2 = 60, + GREATER = 61, + GREATER_EQUAL = 62, + LESS_EQUAL = 63, + SELECT = 64, + SLICE = 65, + SIN = 66, + TRANSPOSE_CONV = 67, + SPARSE_TO_DENSE = 68, + TILE = 69, + EXPAND_DIMS = 70, + EQUAL = 71, + NOT_EQUAL = 72, + LOG = 73, + SUM = 74, + SQRT = 75, + RSQRT = 76, + SHAPE = 77, + POW = 78, + ARG_MIN = 79, + FAKE_QUANT = 80, + REDUCE_PROD = 81, + REDUCE_MAX = 82, + PACK = 83, + LOGICAL_OR = 84, + ONE_HOT = 85, + LOGICAL_AND = 86, + LOGICAL_NOT = 87, + UNPACK = 88, + REDUCE_MIN = 89, + FLOOR_DIV = 90, + REDUCE_ANY = 91, + SQUARE = 92, + ZEROS_LIKE = 93, + FILL = 94, + FLOOR_MOD = 95, + RANGE = 96, + RESIZE_NEAREST_NEIGHBOR = 97, + LEAKY_RELU = 98, + SQUARED_DIFFERENCE = 99, + MIRROR_PAD = 100, + ABS = 101, + SPLIT_V = 102, +} + +// Options for the builtin operators. +union BuiltinOptions { + Conv2DOptions, + DepthwiseConv2DOptions, + ConcatEmbeddingsOptions, + LSHProjectionOptions, + Pool2DOptions, + SVDFOptions, + RNNOptions, + FullyConnectedOptions, + SoftmaxOptions, + ConcatenationOptions, + AddOptions, + L2NormOptions, + LocalResponseNormalizationOptions, + LSTMOptions, + ResizeBilinearOptions, + CallOptions, + ReshapeOptions, + SkipGramOptions, + SpaceToDepthOptions, + EmbeddingLookupSparseOptions, + MulOptions, + PadOptions, + GatherOptions, + BatchToSpaceNDOptions, + SpaceToBatchNDOptions, + TransposeOptions, + ReducerOptions, + SubOptions, + DivOptions, + SqueezeOptions, + SequenceRNNOptions, + StridedSliceOptions, + ExpOptions, + TopKV2Options, + SplitOptions, + LogSoftmaxOptions, + CastOptions, + DequantizeOptions, + MaximumMinimumOptions, + ArgMaxOptions, + LessOptions, + NegOptions, + PadV2Options, + GreaterOptions, + GreaterEqualOptions, + LessEqualOptions, + SelectOptions, + SliceOptions, + TransposeConvOptions, + SparseToDenseOptions, + TileOptions, + ExpandDimsOptions, + EqualOptions, + NotEqualOptions, + ShapeOptions, + PowOptions, + ArgMinOptions, + FakeQuantOptions, + PackOptions, + LogicalOrOptions, + OneHotOptions, + LogicalAndOptions, + LogicalNotOptions, + UnpackOptions, + FloorDivOptions, + SquareOptions, + ZerosLikeOptions, + FillOptions, + BidirectionalSequenceLSTMOptions, + BidirectionalSequenceRNNOptions, + UnidirectionalSequenceLSTMOptions, + FloorModOptions, + RangeOptions, + ResizeNearestNeighborOptions, + LeakyReluOptions, + SquaredDifferenceOptions, + MirrorPadOptions, + AbsOptions, + SplitVOptions, +} + +enum Padding : byte { SAME, VALID } + +enum ActivationFunctionType : byte { + NONE = 0, + RELU = 1, + RELU_N1_TO_1 = 2, + RELU6 = 3, + TANH = 4, + SIGN_BIT = 5, +} + +table Conv2DOptions { + padding:Padding; + stride_w:int; + stride_h:int; + fused_activation_function:ActivationFunctionType; + dilation_w_factor:int = 1; + dilation_h_factor:int = 1; +} + +table Pool2DOptions { + padding:Padding; + stride_w:int; + stride_h:int; + filter_width:int; + filter_height:int; + fused_activation_function:ActivationFunctionType; +} + +table DepthwiseConv2DOptions { + // Parameters for DepthwiseConv version 1 or above. + padding:Padding; + stride_w:int; + stride_h:int; + depth_multiplier:int; + fused_activation_function:ActivationFunctionType; + // Parameters for DepthwiseConv version 2 or above. + dilation_w_factor:int = 1; + dilation_h_factor:int = 1; +} + +table ConcatEmbeddingsOptions { + num_channels:int; + num_columns_per_channel:[int]; + embedding_dim_per_channel:[int]; // This could be inferred from parameters. +} + +enum LSHProjectionType: byte { + UNKNOWN = 0, + SPARSE = 1, + DENSE = 2, +} + +table LSHProjectionOptions { + type: LSHProjectionType; +} + +table SVDFOptions { + rank:int; + fused_activation_function:ActivationFunctionType; +} + +// An implementation of TensorFlow RNNCell. +table RNNOptions { + fused_activation_function:ActivationFunctionType; +} + +// An implementation of TensorFlow dynamic_rnn with RNNCell. +table SequenceRNNOptions { + time_major:bool; + fused_activation_function:ActivationFunctionType; +} + +// An implementation of TensorFlow bidrectional_dynamic_rnn with RNNCell. +table BidirectionalSequenceRNNOptions { + time_major:bool; + fused_activation_function:ActivationFunctionType; + merge_outputs: bool; +} + +enum FullyConnectedOptionsWeightsFormat: byte { + DEFAULT = 0, + SHUFFLED4x16INT8 = 1, +} + +// An implementation of TensorFlow fully_connected (a.k.a Dense) layer. +table FullyConnectedOptions { + // Parameters for FullyConnected version 1 or above. + fused_activation_function:ActivationFunctionType; + + // Parameters for FullyConnected version 2 or above. + weights_format:FullyConnectedOptionsWeightsFormat = DEFAULT; +} + +table SoftmaxOptions { + beta: float; +} + +// An implementation of TensorFlow concat. +table ConcatenationOptions { + axis:int; + fused_activation_function:ActivationFunctionType; +} + +table AddOptions { + fused_activation_function:ActivationFunctionType; +} + +table MulOptions { + fused_activation_function:ActivationFunctionType; +} + +table L2NormOptions { + fused_activation_function:ActivationFunctionType; +} + +table LocalResponseNormalizationOptions { + radius:int; + bias:float; + alpha:float; + beta:float; +} + +enum LSTMKernelType : byte { + // Full LSTM kernel which supports peephole and projection. + FULL = 0, + // Basic LSTM kernels. Equivalent to TensorFlow BasicLSTMCell. + BASIC = 1, +} + +// An implementation of TensorFlow LSTMCell and CoupledInputForgetGateLSTMCell +table LSTMOptions { + // Parameters for LSTM version 1 or above. + fused_activation_function:ActivationFunctionType; + cell_clip: float; // Optional, 0.0 means no clipping + proj_clip: float; // Optional, 0.0 means no clipping + + // Parameters for LSTM version 2 or above. + // Basic kernel is only supported in version 2 or above. + kernel_type: LSTMKernelType = FULL; +} + +// An implementation of TensorFlow dynamic_rnn with LSTMCell. +table UnidirectionalSequenceLSTMOptions { + fused_activation_function:ActivationFunctionType; + cell_clip: float; // Optional, 0.0 means no clipping + proj_clip: float; // Optional, 0.0 means no clipping + + // If true then first dimension is sequence, otherwise batch. + time_major:bool; +} + +table BidirectionalSequenceLSTMOptions { + fused_activation_function:ActivationFunctionType; + cell_clip: float; // Optional, 0.0 means no clipping + proj_clip: float; // Optional, 0.0 means no clipping + + // If true, store the outputs of both directions into the first output. + merge_outputs: bool; +} + +table ResizeBilinearOptions { + new_height: int (deprecated); + new_width: int (deprecated); + align_corners: bool; +} + +table ResizeNearestNeighborOptions { + align_corners: bool; +} + +// A call operation options +table CallOptions { + // The subgraph index that needs to be called. + subgraph:uint; +} + +table PadOptions { +} + +table PadV2Options { +} + +table ReshapeOptions { + new_shape:[int]; +} + +table SpaceToBatchNDOptions { +} + +table BatchToSpaceNDOptions { +} + +table SkipGramOptions { + ngram_size: int; + max_skip_size: int; + include_all_ngrams: bool; +} + +table SpaceToDepthOptions { + block_size: int; +} + +table SubOptions { + fused_activation_function:ActivationFunctionType; +} + +table DivOptions { + fused_activation_function:ActivationFunctionType; +} + +table TopKV2Options { +} + +enum CombinerType : byte { + SUM = 0, + MEAN = 1, + SQRTN = 2, +} + +table EmbeddingLookupSparseOptions { + combiner:CombinerType; +} + +table GatherOptions { + axis: int; +} + +table TransposeOptions { +} + +table ExpOptions { +} + +table ReducerOptions { + keep_dims: bool; +} + +table SqueezeOptions { + squeeze_dims:[int]; +} + +table SplitOptions { + num_splits: int; +} + +table SplitVOptions { + num_splits: int; +} + +table StridedSliceOptions { + begin_mask: int; + end_mask: int; + ellipsis_mask: int; + new_axis_mask: int; + shrink_axis_mask: int; +} + +table LogSoftmaxOptions { +} + +table CastOptions { + in_data_type: TensorType; + out_data_type: TensorType; +} + +table DequantizeOptions { +} + +table MaximumMinimumOptions { +} + +table TileOptions { +} + +table ArgMaxOptions { + output_type : TensorType; +} + +table ArgMinOptions { + output_type : TensorType; +} + +table GreaterOptions { +} + +table GreaterEqualOptions { +} + +table LessOptions { +} + +table LessEqualOptions { +} + +table NegOptions { +} + +table SelectOptions { +} + +table SliceOptions { +} + +table TransposeConvOptions { + padding:Padding; + stride_w:int; + stride_h:int; +} + +table ExpandDimsOptions { +} + +table SparseToDenseOptions { + validate_indices:bool; +} + +table EqualOptions { +} + +table NotEqualOptions { +} + +table ShapeOptions { + // Optional output type of the operation (int32 or int64). Defaults to int32. + out_type : TensorType; +} + +table PowOptions { +} + +table FakeQuantOptions { + // Parameters supported by version 1: + min:float; + max:float; + num_bits:int; + + // Parameters supported by version 2: + narrow_range:bool; +} + +table PackOptions { + values_count:int; + axis:int; +} + +table LogicalOrOptions { +} + +table OneHotOptions { + axis:int; +} + +table AbsOptions { +} + + +table LogicalAndOptions { +} + +table LogicalNotOptions { +} + +table UnpackOptions { + num:int; + axis:int; +} + +table FloorDivOptions { +} + +table SquareOptions { +} + +table ZerosLikeOptions { +} + +table FillOptions { +} + +table FloorModOptions { +} + +table RangeOptions { +} + +table LeakyReluOptions { + alpha:float; +} + +table SquaredDifferenceOptions { +} + +enum MirrorPadMode : byte { + // Doesn't include borders. + REFLECT = 0, + // Includes borders. + SYMMETRIC = 1, +} + +table MirrorPadOptions { + mode:MirrorPadMode; +} + +// An OperatorCode can be an enum value (BuiltinOperator) if the operator is a +// builtin, or a string if the operator is custom. +table OperatorCode { + builtin_code:BuiltinOperator; + custom_code:string; + + // The version of the operator. The version need to be bumped whenever new + // parameters are introduced into an op. + version:int = 1; +} + +enum CustomOptionsFormat : byte { + FLEXBUFFERS = 0, +} + +// An operator takes tensors as inputs and outputs. The type of operation being +// performed is determined by an index into the list of valid OperatorCodes, +// while the specifics of each operations is configured using builtin_options +// or custom_options. +table Operator { + // Index into the operator_codes array. Using an integer here avoids + // complicate map lookups. + opcode_index:uint; + + // Optional input and output tensors are indicated by -1. + inputs:[int]; + outputs:[int]; + + builtin_options:BuiltinOptions; + custom_options:[ubyte]; + custom_options_format:CustomOptionsFormat; + + // A list of booleans indicating the input tensors which are being mutated by + // this operator.(e.g. used by RNN and LSTM). + // For example, if the "inputs" array refers to 5 tensors and the second and + // fifth are mutable variables, then this list will contain + // [false, true, false, false, true]. + // + // If the list is empty, no variable is mutated in this operator. + // The list either has the same length as `inputs`, or is empty. + mutating_variable_inputs:[bool]; +} + +// The root type, defining a subgraph, which typically represents an entire +// model. +table SubGraph { + // A list of all tensors used in this subgraph. + tensors:[Tensor]; + + // Indices of the tensors that are inputs into this subgraph. Note this is + // the list of non-static tensors that feed into the subgraph for inference. + inputs:[int]; + + // Indices of the tensors that are outputs out of this subgraph. Note this is + // the list of output tensors that are considered the product of the + // subgraph's inference. + outputs:[int]; + + // All operators, in execution order. + operators:[Operator]; + + // Name of this subgraph (used for debugging). + name:string; +} + +// Table of raw data buffers (used for constant tensors). Referenced by tensors +// by index. The generous alignment accommodates mmap-friendly data structures. +table Buffer { + data:[ubyte] (force_align: 16); +} + +table Model { + // Version of the schema. + version:uint; + + // A list of all operator codes used in this model. This is + // kept in order because operators carry an index into this + // vector. + operator_codes:[OperatorCode]; + + // All the subgraphs of the model. The 0th is assumed to be the main + // model. + subgraphs:[SubGraph]; + + // A description of the model. + description:string; + + // Buffers of the model. + // Note the 0th entry of this array must be an empty buffer (sentinel). + // This is a convention so that tensors without a buffer can provide 0 as + // their buffer. + buffers:[Buffer]; + + // Metadata about the model. Indirects into the existings buffers list. + metadata_buffer:[int]; +} + +root_type Model; diff --git a/runtime/onert/frontend/tflite/tflite_schema.fbs b/runtime/onert/frontend/tflite/tflite_schema.fbs new file mode 100644 index 00000000000..9bffb4f3c08 --- /dev/null +++ b/runtime/onert/frontend/tflite/tflite_schema.fbs @@ -0,0 +1,1095 @@ +// Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved +// Copyright 2017 The TensorFlow Authors. 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. + +// Revision History +// Version 0: Initial version. +// Version 1: Add subgraphs to schema. +// Version 2: Rename operators to conform to NN API. +// Version 3: Move buffer data from Model.Subgraph.Tensors to Model.Buffers. + +// Change namespace to onert_tflite +namespace onert_tflite; + +// This corresponds to the version. +file_identifier "TFL3"; +// File extension of any written files. +file_extension "tflite"; + +// IMPORTANT: All new members of tables, enums and unions must be added at the +// end to ensure backwards compatibility. + +// The type of data stored in a tensor. +enum TensorType : byte { + FLOAT32 = 0, + FLOAT16 = 1, + INT32 = 2, + UINT8 = 3, + INT64 = 4, + STRING = 5, + BOOL = 6, + INT16 = 7, + COMPLEX64 = 8, + INT8 = 9, + FLOAT64 = 10, +} + +// Custom quantization parameters for experimenting with new quantization +// techniques. +table CustomQuantization { + custom:[ubyte] (force_align: 16); +} + +// Represents a specific quantization technique's parameters. +union QuantizationDetails { + CustomQuantization, +} + +// Parameters for converting a quantized tensor back to float. +table QuantizationParameters { + // These four parameters are the asymmetric linear quantization parameters. + // Given a quantized value q, the corresponding float value f should be: + // f = scale * (q - zero_point) + // For other quantization types, the QuantizationDetails below is used. + min:[float]; // For importing back into tensorflow. + max:[float]; // For importing back into tensorflow. + scale:[float]; // For dequantizing the tensor's values. + zero_point:[long]; + + // If this is not none, the other quantization parameters (i.e. min, max, + // scale, zero_point fields above) are ignored and the value of the + // QuantizationDetails union should be used. + details:QuantizationDetails; + + // Specifies the dimension of the Tensor's shape that the scales and + // zero_points correspond to. For example, a tensor t, with dims=[4, 3, 2, 1] + // with quantization params: + // scale=[1.0, 2.0, 3.0], zero_point=[1, 2, 3], quantization_dimension=1 + // will be quantized across the second dimension of t. + // t[:, 0, :, :] will have scale[0]=1.0, zero_point[0]=1 + // t[:, 1, :, :] will have scale[1]=2.0, zero_point[0]=2 + // t[:, 2, :, :] will have scale[2]=3.0, zero_point[0]=3 + quantized_dimension:int; +} + +// Sparse tensors. +// We use a modification of the TACO format. +// Reference: http://tensor-compiler.org/kjolstad-oopsla17-tensor-compiler.pdf +// +// To encode a conceptual n-dimensional dense tensor with dims (d0, ..., dn-1), +// potentially with a k-dimensional block (0 <= k <= n) with dims +// (dn, ..., dn+k-1), the format needs to specify: +// 1. In what order to traverse these dimensions. For example, to store a 2-D +// matrix in row major order, the traversal order would be (d0, d1), +// whereas to store it in column major order, the traversal order would be +// (d1, d0). If the 2-D matrix has a 2-D inner block, the traversal order +// could be (d0, d1, d2, d3). +// 2. How each block dimension in (dn, ..., dn+k-1) maps to the original +// tensor dimension in (d0, ..., dn-1). +// 3. In the traversal order defined above, the format (dense vs. sparse) and +// index metadata for each dimension. For a dense dimension, this is just +// the size of that dimension. For a sparse dimension, it's the same as +// the compressed index defined in the Compressed Sparse Row (CSR) format. +// (http://scipy-lectures.org/advanced/scipy_sparse/csr_matrix.html) + +// The storage type for a dimension. Currently we support: +// 1. DENSE: each coordinate in this dimension is stored implicitly. +// 2. SPARSE_CSR: only the coordinates with non-zero elements are stored. The +// compression technique is the same what CSR uses. +// More types like a sparse dimension with a different compression technique +// could be added to the list in the future. +enum DimensionType : byte { + DENSE = 0, + SPARSE_CSR = 1, +} + +table Int32Vector { + values:[int]; +} + +table Uint16Vector { + values:[ushort] (force_align: 4); +} + +table Uint8Vector { + values:[ubyte] (force_align: 4); +} + +// Variable-typed buffer to store the index metadata for a sparse dimension. +// The widest type is Int32 instead of UInt32 because tensor's shape is a int32 +// vector. We don't want the per-dimensional index to overflow that range. +union SparseIndexVector { + Int32Vector, + Uint16Vector, + Uint8Vector +} + +table DimensionMetadata { + // Whether a dimension is dense or sparse. + format:DimensionType; + // Index metadata used for a dimension. + // - If format is DimensionType.DENSE then we use the dense_size field to + // store the size of that dimension. Each index in that dimension is + // stored implicitly. + // - If format is DimensionType.SPARSE_CSR then we use array_segments and + // array_indices to encode that dimension. array_segments represents how + // to segment the indices array, each segment corresponds to one element + // in the previous dimension. array_indices represents the index of the + // non-zero elements within this dimension (as those in the CSR matrix + // format, where the first array is row pointers and the second array is + // column indices). + dense_size:int; + array_segments:SparseIndexVector; + array_indices:SparseIndexVector; +} + +// Parameters to encode a sparse TfLite tensor. +table SparsityParameters { + // The traversal order of the dimensions defined in the `shape` field of the + // conceptual dense tensor. For a n-dimensional tensors with dims (d0, d1, + // ..., dn-1), + // - if not block sparse, the traversal_order is just a permutation of (d0, + // ..., dn-1). For example, a 2-D matrix stored in row-major order would + // have traversal_order = (d0, d1). + // - if block sparse with a k-dimensional block (0 <= k <= n), the + // traversal_order has n + k elements. The first n elements are still a + // permutation of (d0, ..., dn-1). The lask k elements are a permutation + // of (dn, ..., dn+k-1), defining how to traverse a block internally. For + // example, a 2-D matrix with 2-D blocks, both stored in row-major order + // would have traversal_order = (d0, d1, d2, d3). + traversal_order:[int]; + // For an n-dimensional tensor with a k-dimensional block (0 <= k <= n), + // stores how a block dimension in (dn, ..., dn+k-1) maps to the original + // tensor dimension in (d0, ..., dn). + // It's stored in the order of (dn, ..., dn+k-1). + // If not block-sparse, this field is NULL. + block_map:[int]; + // In the traversal order defined above, the metadata needed for + // each dimension to locate the non-zero values in the original dense tensor. + // The size of the dim_metadata array = the size of the traversal_order array + // = n + k. + dim_metadata:[DimensionMetadata]; +} + +table Tensor { + // The tensor shape. The meaning of each entry is operator-specific but + // builtin ops use: [batch size, height, width, number of channels] (That's + // Tensorflow's NHWC). + shape:[int]; + type:TensorType; + // An index that refers to the buffers table at the root of the model. Or, + // if there is no data buffer associated (i.e. intermediate results), then + // this is 0 (which refers to an always existent empty buffer). + // + // The data_buffer itself is an opaque container, with the assumption that the + // target device is little-endian. In addition, all builtin operators assume + // the memory is ordered such that if `shape` is [4, 3, 2], then index + // [i, j, k] maps to data_buffer[i*3*2 + j*2 + k]. + buffer:uint; + name:string; // For debugging and importing back into tensorflow. + quantization:QuantizationParameters; // Optional. + + is_variable:bool = false; + + // Parameters to encode a sparse tensor. See the example in + // tensorflow/lite/testdata/sparse_tensor.json. + sparsity:SparsityParameters; // Optional. + + // Encodes `shape` with unknown dimensions. Unknown dimensions are + // represented with -1. + shape_signature:[int]; // Optional. +} + +// A list of builtin operators. Builtin operators are slightly faster than custom +// ones, but not by much. Moreover, while custom operators accept an opaque +// object containing configuration parameters, builtins have a predetermined +// set of acceptable options. + +enum BuiltinOperator : byte { + ADD = 0, + AVERAGE_POOL_2D = 1, + CONCATENATION = 2, + CONV_2D = 3, + DEPTHWISE_CONV_2D = 4, + DEPTH_TO_SPACE = 5, + DEQUANTIZE = 6, + EMBEDDING_LOOKUP = 7, + FLOOR = 8, + FULLY_CONNECTED = 9, + HASHTABLE_LOOKUP = 10, + L2_NORMALIZATION = 11, + L2_POOL_2D = 12, + LOCAL_RESPONSE_NORMALIZATION = 13, + LOGISTIC = 14, + LSH_PROJECTION = 15, + LSTM = 16, + MAX_POOL_2D = 17, + MUL = 18, + RELU = 19, + // NOTE(aselle): RELU_N1_TO_1 used to be called RELU1, but it was renamed + // since different model developers use RELU1 in different ways. Never + // create another op called RELU1. + RELU_N1_TO_1 = 20, + RELU6 = 21, + RESHAPE = 22, + RESIZE_BILINEAR = 23, + RNN = 24, + SOFTMAX = 25, + SPACE_TO_DEPTH = 26, + SVDF = 27, + TANH = 28, + // TODO(aselle): Consider rename to CONCATENATE_EMBEDDINGS + CONCAT_EMBEDDINGS = 29, + SKIP_GRAM = 30, + CALL = 31, + CUSTOM = 32, + EMBEDDING_LOOKUP_SPARSE = 33, + PAD = 34, + UNIDIRECTIONAL_SEQUENCE_RNN = 35, + GATHER = 36, + BATCH_TO_SPACE_ND = 37, + SPACE_TO_BATCH_ND = 38, + TRANSPOSE = 39, + MEAN = 40, + SUB = 41, + DIV = 42, + SQUEEZE = 43, + UNIDIRECTIONAL_SEQUENCE_LSTM = 44, + STRIDED_SLICE = 45, + BIDIRECTIONAL_SEQUENCE_RNN = 46, + EXP = 47, + TOPK_V2 = 48, + SPLIT = 49, + LOG_SOFTMAX = 50, + // DELEGATE is a special op type for the operations which are delegated to + // other backends. + // WARNING: Experimental interface, subject to change + DELEGATE = 51, + BIDIRECTIONAL_SEQUENCE_LSTM = 52, + CAST = 53, + PRELU = 54, + MAXIMUM = 55, + ARG_MAX = 56, + MINIMUM = 57, + LESS = 58, + NEG = 59, + PADV2 = 60, + GREATER = 61, + GREATER_EQUAL = 62, + LESS_EQUAL = 63, + SELECT = 64, + SLICE = 65, + SIN = 66, + TRANSPOSE_CONV = 67, + SPARSE_TO_DENSE = 68, + TILE = 69, + EXPAND_DIMS = 70, + EQUAL = 71, + NOT_EQUAL = 72, + LOG = 73, + SUM = 74, + SQRT = 75, + RSQRT = 76, + SHAPE = 77, + POW = 78, + ARG_MIN = 79, + FAKE_QUANT = 80, + REDUCE_PROD = 81, + REDUCE_MAX = 82, + PACK = 83, + LOGICAL_OR = 84, + ONE_HOT = 85, + LOGICAL_AND = 86, + LOGICAL_NOT = 87, + UNPACK = 88, + REDUCE_MIN = 89, + FLOOR_DIV = 90, + REDUCE_ANY = 91, + SQUARE = 92, + ZEROS_LIKE = 93, + FILL = 94, + FLOOR_MOD = 95, + RANGE = 96, + RESIZE_NEAREST_NEIGHBOR = 97, + LEAKY_RELU = 98, + SQUARED_DIFFERENCE = 99, + MIRROR_PAD = 100, + ABS = 101, + SPLIT_V = 102, + UNIQUE = 103, + CEIL = 104, + REVERSE_V2 = 105, + ADD_N = 106, + GATHER_ND = 107, + COS = 108, + WHERE = 109, + RANK = 110, + ELU = 111, + REVERSE_SEQUENCE = 112, + MATRIX_DIAG = 113, + QUANTIZE = 114, + MATRIX_SET_DIAG = 115, + ROUND = 116, + HARD_SWISH = 117, + IF = 118, + WHILE = 119, + NON_MAX_SUPPRESSION_V4 = 120, + NON_MAX_SUPPRESSION_V5 = 121, + SCATTER_ND = 122, + SELECT_V2 = 123, + DENSIFY = 124, + SEGMENT_SUM = 125, + BATCH_MATMUL = 126 +} + + +// Options for the builtin operators. +union BuiltinOptions { + Conv2DOptions, + DepthwiseConv2DOptions, + ConcatEmbeddingsOptions, + LSHProjectionOptions, + Pool2DOptions, + SVDFOptions, + RNNOptions, + FullyConnectedOptions, + SoftmaxOptions, + ConcatenationOptions, + AddOptions, + L2NormOptions, + LocalResponseNormalizationOptions, + LSTMOptions, + ResizeBilinearOptions, + CallOptions, + ReshapeOptions, + SkipGramOptions, + SpaceToDepthOptions, + EmbeddingLookupSparseOptions, + MulOptions, + PadOptions, + GatherOptions, + BatchToSpaceNDOptions, + SpaceToBatchNDOptions, + TransposeOptions, + ReducerOptions, + SubOptions, + DivOptions, + SqueezeOptions, + SequenceRNNOptions, + StridedSliceOptions, + ExpOptions, + TopKV2Options, + SplitOptions, + LogSoftmaxOptions, + CastOptions, + DequantizeOptions, + MaximumMinimumOptions, + ArgMaxOptions, + LessOptions, + NegOptions, + PadV2Options, + GreaterOptions, + GreaterEqualOptions, + LessEqualOptions, + SelectOptions, + SliceOptions, + TransposeConvOptions, + SparseToDenseOptions, + TileOptions, + ExpandDimsOptions, + EqualOptions, + NotEqualOptions, + ShapeOptions, + PowOptions, + ArgMinOptions, + FakeQuantOptions, + PackOptions, + LogicalOrOptions, + OneHotOptions, + LogicalAndOptions, + LogicalNotOptions, + UnpackOptions, + FloorDivOptions, + SquareOptions, + ZerosLikeOptions, + FillOptions, + BidirectionalSequenceLSTMOptions, + BidirectionalSequenceRNNOptions, + UnidirectionalSequenceLSTMOptions, + FloorModOptions, + RangeOptions, + ResizeNearestNeighborOptions, + LeakyReluOptions, + SquaredDifferenceOptions, + MirrorPadOptions, + AbsOptions, + SplitVOptions, + UniqueOptions, + ReverseV2Options, + AddNOptions, + GatherNdOptions, + CosOptions, + WhereOptions, + RankOptions, + ReverseSequenceOptions, + MatrixDiagOptions, + QuantizeOptions, + MatrixSetDiagOptions, + HardSwishOptions, + IfOptions, + WhileOptions, + DepthToSpaceOptions, + NonMaxSuppressionV4Options, + NonMaxSuppressionV5Options, + ScatterNdOptions, + SelectV2Options, + DensifyOptions, + SegmentSumOptions, + BatchMatMulOptions +} + +enum Padding : byte { SAME, VALID } + +enum ActivationFunctionType : byte { + NONE = 0, + RELU = 1, + RELU_N1_TO_1 = 2, + RELU6 = 3, + TANH = 4, + SIGN_BIT = 5, +} + +table Conv2DOptions { + padding:Padding; + stride_w:int; + stride_h:int; + fused_activation_function:ActivationFunctionType; + dilation_w_factor:int = 1; + dilation_h_factor:int = 1; +} + +table Pool2DOptions { + padding:Padding; + stride_w:int; + stride_h:int; + filter_width:int; + filter_height:int; + fused_activation_function:ActivationFunctionType; +} + +table DepthwiseConv2DOptions { + // Parameters for DepthwiseConv version 1 or above. + padding:Padding; + stride_w:int; + stride_h:int; + // `depth_multiplier` is redundant. It's used by CPU kernels in + // TensorFlow 2.0 or below, but ignored in versions above. + // See comments in lite/c/builtin_op_data.h for more details. + depth_multiplier:int; + fused_activation_function:ActivationFunctionType; + // Parameters for DepthwiseConv version 2 or above. + dilation_w_factor:int = 1; + dilation_h_factor:int = 1; +} + +table ConcatEmbeddingsOptions { + num_channels:int; + num_columns_per_channel:[int]; + embedding_dim_per_channel:[int]; // This could be inferred from parameters. +} + +enum LSHProjectionType: byte { + UNKNOWN = 0, + SPARSE = 1, + DENSE = 2, +} + +table LSHProjectionOptions { + type: LSHProjectionType; +} + +table SVDFOptions { + rank:int; + fused_activation_function:ActivationFunctionType; + // For weights-only quantization, use asymmetric quantization for non + // constant inputs at evaluation time. + asymmetric_quantize_inputs:bool; +} + +// An implementation of TensorFlow RNNCell. +table RNNOptions { + fused_activation_function:ActivationFunctionType; + asymmetric_quantize_inputs:bool; +} + +// An implementation of TensorFlow dynamic_rnn with RNNCell. +table SequenceRNNOptions { + time_major:bool; + fused_activation_function:ActivationFunctionType; + asymmetric_quantize_inputs:bool; +} + +// An implementation of TensorFlow bidrectional_dynamic_rnn with RNNCell. +table BidirectionalSequenceRNNOptions { + time_major:bool; + fused_activation_function:ActivationFunctionType; + merge_outputs: bool; + asymmetric_quantize_inputs:bool; +} + +enum FullyConnectedOptionsWeightsFormat: byte { + DEFAULT = 0, + SHUFFLED4x16INT8 = 1, +} + +// An implementation of TensorFlow fully_connected (a.k.a Dense) layer. +table FullyConnectedOptions { + // Parameters for FullyConnected version 1 or above. + fused_activation_function:ActivationFunctionType; + + // Parameters for FullyConnected version 2 or above. + weights_format:FullyConnectedOptionsWeightsFormat = DEFAULT; + + // Parameters for FullyConnected version 5 or above. + // If set to true, then the number of dimension is preserved. Furthermore, + // all but the last dimension of the input and output shapes will be equal. + keep_num_dims: bool; + + // Parameters for FullyConnected version 7 or above. + // If set to true, then weights-only op will use asymmetric quantization for + // inputs. + asymmetric_quantize_inputs: bool; +} + +table SoftmaxOptions { + beta: float; +} + +// An implementation of TensorFlow concat. +table ConcatenationOptions { + axis:int; + fused_activation_function:ActivationFunctionType; +} + +table AddOptions { + fused_activation_function:ActivationFunctionType; +} + +table MulOptions { + fused_activation_function:ActivationFunctionType; +} + +table L2NormOptions { + fused_activation_function:ActivationFunctionType; +} + +table LocalResponseNormalizationOptions { + radius:int; + bias:float; + alpha:float; + beta:float; +} + +enum LSTMKernelType : byte { + // Full LSTM kernel which supports peephole and projection. + FULL = 0, + // Basic LSTM kernels. Equivalent to TensorFlow BasicLSTMCell. + BASIC = 1, +} + +// An implementation of TensorFlow LSTMCell and CoupledInputForgetGateLSTMCell +table LSTMOptions { + // Parameters for LSTM version 1 or above. + fused_activation_function:ActivationFunctionType; + cell_clip: float; // Optional, 0.0 means no clipping + proj_clip: float; // Optional, 0.0 means no clipping + + // Parameters for LSTM version 2 or above. + // Basic kernel is only supported in version 2 or above. + kernel_type: LSTMKernelType = FULL; + + // Parameters for LSTM version 4 or above. + asymmetric_quantize_inputs: bool; +} + +// An implementation of TensorFlow dynamic_rnn with LSTMCell. +table UnidirectionalSequenceLSTMOptions { + fused_activation_function:ActivationFunctionType; + cell_clip: float; // Optional, 0.0 means no clipping + proj_clip: float; // Optional, 0.0 means no clipping + + // If true then first dimension is sequence, otherwise batch. + time_major:bool; + + // Parameter for Unidirectional Sequence LSTM version 4. + asymmetric_quantize_inputs:bool; +} + +table BidirectionalSequenceLSTMOptions { + // Parameters supported by version 1: + fused_activation_function:ActivationFunctionType; + cell_clip: float; // Optional, 0.0 means no clipping + proj_clip: float; // Optional, 0.0 means no clipping + + // If true, store the outputs of both directions into the first output. + merge_outputs: bool; + + // Parameters supported by version 2: + // If true then first dimension is sequence, otherwise batch. + // Version 1 implementations assumed time_major to be true, so this default + // value should never change. + time_major: bool = true; + + // Parameters for version 3 or above. + asymmetric_quantize_inputs:bool; +} + +table ResizeBilinearOptions { + new_height: int (deprecated); + new_width: int (deprecated); + align_corners: bool; + half_pixel_centers: bool; +} + +table ResizeNearestNeighborOptions { + align_corners: bool; +} + +// A call operation options +table CallOptions { + // The subgraph index that needs to be called. + subgraph:uint; +} + +table PadOptions { +} + +table PadV2Options { +} + +table ReshapeOptions { + new_shape:[int]; +} + +table SpaceToBatchNDOptions { +} + +table BatchToSpaceNDOptions { +} + +table SkipGramOptions { + ngram_size: int; + max_skip_size: int; + include_all_ngrams: bool; +} + +table SpaceToDepthOptions { + block_size: int; +} + +table DepthToSpaceOptions { + block_size: int; +} + +table SubOptions { + fused_activation_function:ActivationFunctionType; +} + +table DivOptions { + fused_activation_function:ActivationFunctionType; +} + +table TopKV2Options { +} + +enum CombinerType : byte { + SUM = 0, + MEAN = 1, + SQRTN = 2, +} + +table EmbeddingLookupSparseOptions { + combiner:CombinerType; +} + +table GatherOptions { + axis: int; +} + +table TransposeOptions { +} + +table ExpOptions { +} + +table CosOptions { +} + +table ReducerOptions { + keep_dims: bool; +} + +table SqueezeOptions { + squeeze_dims:[int]; +} + +table SplitOptions { + num_splits: int; +} + +table SplitVOptions { + num_splits: int; +} + +table StridedSliceOptions { + begin_mask: int; + end_mask: int; + ellipsis_mask: int; + new_axis_mask: int; + shrink_axis_mask: int; +} + +table LogSoftmaxOptions { +} + +table CastOptions { + in_data_type: TensorType; + out_data_type: TensorType; +} + +table DequantizeOptions { +} + +table MaximumMinimumOptions { +} + +table TileOptions { +} + +table ArgMaxOptions { + output_type : TensorType; +} + +table ArgMinOptions { + output_type : TensorType; +} + +table GreaterOptions { +} + +table GreaterEqualOptions { +} + +table LessOptions { +} + +table LessEqualOptions { +} + +table NegOptions { +} + +table SelectOptions { +} + +table SliceOptions { +} + +table TransposeConvOptions { + padding:Padding; + stride_w:int; + stride_h:int; +} + +table ExpandDimsOptions { +} + +table SparseToDenseOptions { + validate_indices:bool; +} + +table EqualOptions { +} + +table NotEqualOptions { +} + +table ShapeOptions { + // Optional output type of the operation (int32 or int64). Defaults to int32. + out_type : TensorType; +} + +table RankOptions { +} + +table PowOptions { +} + +table FakeQuantOptions { + // Parameters supported by version 1: + min:float; + max:float; + num_bits:int; + + // Parameters supported by version 2: + narrow_range:bool; +} + +table PackOptions { + values_count:int; + axis:int; +} + +table LogicalOrOptions { +} + +table OneHotOptions { + axis:int; +} + +table AbsOptions { +} + + +table HardSwishOptions { +} + +table LogicalAndOptions { +} + +table LogicalNotOptions { +} + +table UnpackOptions { + num:int; + axis:int; +} + +table FloorDivOptions { +} + +table SquareOptions { +} + +table ZerosLikeOptions { +} + +table FillOptions { +} + +table FloorModOptions { +} + +table RangeOptions { +} + +table LeakyReluOptions { + alpha:float; +} + +table SquaredDifferenceOptions { +} + +enum MirrorPadMode : byte { + // Doesn't include borders. + REFLECT = 0, + // Includes borders. + SYMMETRIC = 1, +} + +table MirrorPadOptions { + mode:MirrorPadMode; +} + +table UniqueOptions { + idx_out_type:TensorType = INT32; +} + +table ReverseV2Options { +} + +table AddNOptions { +} + +table GatherNdOptions { +} + +table WhereOptions { +} + +table ReverseSequenceOptions { + seq_dim:int; + batch_dim:int = 0; +} + +table MatrixDiagOptions { +} + +table QuantizeOptions { +} + +table MatrixSetDiagOptions { +} + +table IfOptions { + then_subgraph_index:int; + else_subgraph_index:int; +} + +table WhileOptions { + cond_subgraph_index:int; + body_subgraph_index:int; +} + +table NonMaxSuppressionV4Options { +} + +table NonMaxSuppressionV5Options { +} + +table ScatterNdOptions { +} + +table SelectV2Options { +} + +table DensifyOptions { +} + +table SegmentSumOptions { +} + +table BatchMatMulOptions { + adjoint_lhs:bool; + adjoint_rhs:bool; +} + +// An OperatorCode can be an enum value (BuiltinOperator) if the operator is a +// builtin, or a string if the operator is custom. +table OperatorCode { + builtin_code:BuiltinOperator; + custom_code:string; + + // The version of the operator. The version need to be bumped whenever new + // parameters are introduced into an op. + version:int = 1; +} + +enum CustomOptionsFormat : byte { + FLEXBUFFERS = 0, +} + +// An operator takes tensors as inputs and outputs. The type of operation being +// performed is determined by an index into the list of valid OperatorCodes, +// while the specifics of each operations is configured using builtin_options +// or custom_options. +table Operator { + // Index into the operator_codes array. Using an integer here avoids + // complicate map lookups. + opcode_index:uint; + + // Optional input are indicated by -1. + inputs:[int]; + outputs:[int]; + + builtin_options:BuiltinOptions; + custom_options:[ubyte]; + custom_options_format:CustomOptionsFormat; + + // A list of booleans indicating the input tensors which are being mutated by + // this operator.(e.g. used by RNN and LSTM). + // For example, if the "inputs" array refers to 5 tensors and the second and + // fifth are mutable variables, then this list will contain + // [false, true, false, false, true]. + // + // If the list is empty, no variable is mutated in this operator. + // The list either has the same length as `inputs`, or is empty. + mutating_variable_inputs:[bool]; + + // A list of indices to the subgraph's "tensors" that are internal to an Op. + // Internal tensors are those that do not flow in or out of the operation, + // but instead are part of internal computation. As such, the operation's + // implementation may manage its memory more efficiently. They are needed + // however (i.e. not just an implementation detail) since they are part of the + // computation, which may require relevant metadata such as quantization + // parameters. + intermediates:[int]; +} + +// The root type, defining a subgraph, which typically represents an entire +// model. +table SubGraph { + // A list of all tensors used in this subgraph. + tensors:[Tensor]; + + // Indices of the tensors that are inputs into this subgraph. Note this is + // the list of non-static tensors that feed into the subgraph for inference. + inputs:[int]; + + // Indices of the tensors that are outputs out of this subgraph. Note this is + // the list of output tensors that are considered the product of the + // subgraph's inference. + outputs:[int]; + + // All operators, in execution order. + operators:[Operator]; + + // Name of this subgraph (used for debugging). + name:string; +} + +// Table of raw data buffers (used for constant tensors). Referenced by tensors +// by index. The generous alignment accommodates mmap-friendly data structures. +table Buffer { + data:[ubyte] (force_align: 16); +} + +table Metadata { + // A human readable string to uniquely identify a Metadata. + name:string; + // An index to the buffers table. + buffer:uint; +} + +table Model { + // Version of the schema. + version:uint; + + // A list of all operator codes used in this model. This is + // kept in order because operators carry an index into this + // vector. + operator_codes:[OperatorCode]; + + // All the subgraphs of the model. The 0th is assumed to be the main + // model. + subgraphs:[SubGraph]; + + // A description of the model. + description:string; + + // Buffers of the model. + // Note the 0th entry of this array must be an empty buffer (sentinel). + // This is a convention so that tensors without a buffer can provide 0 as + // their buffer. + buffers:[Buffer]; + + // Metadata about the model. Indirects into the existings buffers list. + // Deprecated, prefer to use metadata field. + metadata_buffer:[int]; + + // Metadata about the model. + metadata:[Metadata]; +} + +root_type Model; diff --git a/runtime/neurun/sample/CMakeLists.txt b/runtime/onert/sample/CMakeLists.txt similarity index 100% rename from runtime/neurun/sample/CMakeLists.txt rename to runtime/onert/sample/CMakeLists.txt diff --git a/runtime/neurun/sample/minimal/CMakeLists.txt b/runtime/onert/sample/minimal/CMakeLists.txt similarity index 100% rename from runtime/neurun/sample/minimal/CMakeLists.txt rename to runtime/onert/sample/minimal/CMakeLists.txt diff --git a/runtime/neurun/sample/minimal/README.md b/runtime/onert/sample/minimal/README.md similarity index 100% rename from runtime/neurun/sample/minimal/README.md rename to runtime/onert/sample/minimal/README.md diff --git a/runtime/neurun/sample/minimal/src/minimal.cc b/runtime/onert/sample/minimal/src/minimal.cc similarity index 98% rename from runtime/neurun/sample/minimal/src/minimal.cc rename to runtime/onert/sample/minimal/src/minimal.cc index 003c8a3238c..d55569ba2b1 100644 --- a/runtime/neurun/sample/minimal/src/minimal.cc +++ b/runtime/onert/sample/minimal/src/minimal.cc @@ -63,5 +63,7 @@ int main(const int argc, char **argv) // TODO: Please print or compare the output value in your way. + nnfw_close_session(session); + return 0; } diff --git a/runtime/onert/test/CMakeLists.txt b/runtime/onert/test/CMakeLists.txt new file mode 100644 index 00000000000..0abdd48800d --- /dev/null +++ b/runtime/onert/test/CMakeLists.txt @@ -0,0 +1,15 @@ +set(TEST_ONERT test_onert) + +file(GLOB_RECURSE TESTS "*.cc") + +add_executable(${TEST_ONERT} ${TESTS}) + +target_include_directories(${TEST_ONERT} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../core/src) + +target_link_libraries(${TEST_ONERT} onert_core) +target_link_libraries(${TEST_ONERT} gtest) +target_link_libraries(${TEST_ONERT} gtest_main) +target_link_libraries(${TEST_ONERT} ${LIB_PTHREAD} dl) +add_test(${TEST_ONERT} ${TEST_ONERT}) + +install(TARGETS ${TEST_ONERT} DESTINATION unittest) diff --git a/runtime/neurun/test/core/compiler/Scheduler.cc b/runtime/onert/test/core/compiler/Scheduler.cc similarity index 99% rename from runtime/neurun/test/core/compiler/Scheduler.cc rename to runtime/onert/test/core/compiler/Scheduler.cc index 3857a7d991a..029c9e46c65 100644 --- a/runtime/neurun/test/core/compiler/Scheduler.cc +++ b/runtime/onert/test/core/compiler/Scheduler.cc @@ -32,7 +32,7 @@ namespace { -using namespace neurun; +using namespace onert; using namespace ir; using namespace backend; using namespace operation; diff --git a/runtime/neurun/test/core/exec/ExecInstance.cc b/runtime/onert/test/core/exec/ExecInstance.cc similarity index 92% rename from runtime/neurun/test/core/exec/ExecInstance.cc rename to runtime/onert/test/core/exec/ExecInstance.cc index 1421b0a978f..7242486a029 100644 --- a/runtime/neurun/test/core/exec/ExecInstance.cc +++ b/runtime/onert/test/core/exec/ExecInstance.cc @@ -25,7 +25,7 @@ namespace { -using namespace neurun::ir; +using namespace onert::ir; class CompiledMockUpModel { @@ -71,7 +71,7 @@ class CompiledMockUpModel graph->finishBuilding(); // Compile - auto compiler = new neurun::compiler::Compiler{graph}; + auto compiler = new onert::compiler::Compiler{graph}; compiler->compile(); compiler->release(executor); delete compiler; @@ -79,7 +79,7 @@ class CompiledMockUpModel public: std::shared_ptr graph; - std::shared_ptr executor; + std::shared_ptr executor; }; TEST(ExecInstance, simple) @@ -97,7 +97,7 @@ TEST(ExecInstance, simple) float output_buffer[4] = {}; const float output_expected[4] = {5, -2, 0, -1}; - auto execution = new neurun::exec::Execution(executor); + auto execution = new onert::exec::Execution(executor); execution->setInput(input1, reinterpret_cast(input1_buffer), 16); execution->setInput(input2, reinterpret_cast(input2_buffer), 16); @@ -117,7 +117,7 @@ TEST(ExecInstance, twoCompile) auto mockup = CompiledMockUpModel(); auto graph = mockup.graph; auto executor1 = mockup.executor; - auto execution1 = new neurun::exec::Execution(executor1); + auto execution1 = new onert::exec::Execution(executor1); auto input1 = IOIndex{0}; auto input2 = IOIndex{1}; @@ -133,11 +133,11 @@ TEST(ExecInstance, twoCompile) execution1->setOutput(output, reinterpret_cast(exe1_output_buffer), 16); // Make new executor: compile again - auto compiler = new neurun::compiler::Compiler{graph}; + auto compiler = new onert::compiler::Compiler{graph}; compiler->compile(); - std::shared_ptr executor2; + std::shared_ptr executor2; compiler->release(executor2); - auto execution2 = new neurun::exec::Execution(executor2); + auto execution2 = new onert::exec::Execution(executor2); const float exe2_input1_buffer[4] = {2, 1, -2, 0}; const float exe2_input2_buffer[4] = {-3, 3, 1, 2}; @@ -177,7 +177,7 @@ TEST(ExecInstance, twoExecution) const float exe1_output_expected[4] = {5, -2, 0, -1}; const float exe2_output_expected[4] = {2, 5, -2, 7}; - auto execution1 = new neurun::exec::Execution(executor); + auto execution1 = new onert::exec::Execution(executor); execution1->setInput(input1, reinterpret_cast(exe1_input1_buffer), 16); execution1->setInput(input2, reinterpret_cast(exe1_input2_buffer), 16); execution1->setOutput(output1, reinterpret_cast(exe1_output_buffer), 16); @@ -187,7 +187,7 @@ TEST(ExecInstance, twoExecution) float exe2_output_buffer[4] = {}; // Make new execution - auto execution2 = new neurun::exec::Execution(executor); + auto execution2 = new onert::exec::Execution(executor); execution2->setInput(input1, reinterpret_cast(exe2_input1_buffer), 16); execution2->setInput(input2, reinterpret_cast(exe2_input2_buffer), 16); execution2->setOutput(output1, reinterpret_cast(exe2_output_buffer), 16); @@ -209,7 +209,7 @@ class Inference { public: Inference(const float (&input1)[4], const float (&input2)[4], float (&output)[4], - std::shared_ptr &executor) + std::shared_ptr &executor) : _input1{input1}, _input2{input2}, _output{output}, _executor{executor} { // DO NOTHING @@ -221,7 +221,7 @@ class Inference auto input2 = IOIndex{1}; auto output1 = IOIndex{0}; - auto execution = new neurun::exec::Execution(_executor); + auto execution = new onert::exec::Execution(_executor); execution->setInput(input1, reinterpret_cast(_input1), 16); execution->setInput(input2, reinterpret_cast(_input2), 16); execution->setOutput(output1, reinterpret_cast(_output), 16); @@ -235,7 +235,7 @@ class Inference const float (&_input1)[4]; const float (&_input2)[4]; float (&_output)[4]; - std::shared_ptr &_executor; + std::shared_ptr &_executor; }; // Support multi-thread execution @@ -287,7 +287,7 @@ TEST(ExecInstance, async) float output_buffer[4] = {}; const float output_expected[4] = {5, -2, 0, -1}; - auto execution = new neurun::exec::Execution(executor); + auto execution = new onert::exec::Execution(executor); execution->setInput(input1, reinterpret_cast(input1_buffer), 16); execution->setInput(input2, reinterpret_cast(input2_buffer), 16); diff --git a/runtime/neurun/test/core/exec/ExecTime.test.cc b/runtime/onert/test/core/exec/ExecTime.test.cc similarity index 94% rename from runtime/neurun/test/core/exec/ExecTime.test.cc rename to runtime/onert/test/core/exec/ExecTime.test.cc index d1cfd1eff5f..ab8b7993560 100644 --- a/runtime/neurun/test/core/exec/ExecTime.test.cc +++ b/runtime/onert/test/core/exec/ExecTime.test.cc @@ -22,7 +22,7 @@ namespace { -using namespace neurun; +using namespace onert; using namespace exec; using namespace backend; @@ -33,9 +33,9 @@ struct MockConfig : public IConfig bool SupportPermutation() override { return false; } }; -struct MockBackend : public ::neurun::backend::Backend +struct MockBackend : public ::onert::backend::Backend { - std::shared_ptr config() const override + std::shared_ptr config() const override { return std::make_shared(); } diff --git a/runtime/neurun/test/core/interp/ExecManager.cc b/runtime/onert/test/core/interp/ExecManager.cc similarity index 98% rename from runtime/neurun/test/core/interp/ExecManager.cc rename to runtime/onert/test/core/interp/ExecManager.cc index cc4d6925fc6..2b56357c2db 100644 --- a/runtime/neurun/test/core/interp/ExecManager.cc +++ b/runtime/onert/test/core/interp/ExecManager.cc @@ -26,9 +26,9 @@ namespace { -using namespace neurun::ir; -using InterpExecutor = neurun::interp::InterpExecutor; -using Execution = neurun::exec::Execution; +using namespace onert::ir; +using InterpExecutor = onert::interp::InterpExecutor; +using Execution = onert::exec::Execution; class InterpExecutorTest : public ::testing::Test { diff --git a/runtime/neurun/test/graph/Graph.cc b/runtime/onert/test/graph/Graph.cc similarity index 78% rename from runtime/neurun/test/graph/Graph.cc rename to runtime/onert/test/graph/Graph.cc index faf84df9c37..34e9fe0028e 100644 --- a/runtime/neurun/test/graph/Graph.cc +++ b/runtime/onert/test/graph/Graph.cc @@ -20,17 +20,17 @@ TEST(Graph, inputs_and_outputs) { - neurun::ir::Graph graph; + onert::ir::Graph graph; - neurun::ir::OperandIndex index0{0u}; - neurun::ir::OperandIndex index1{1u}; + onert::ir::OperandIndex index0{0u}; + onert::ir::OperandIndex index1{1u}; graph.addInput({index0}); graph.addInput({index1}); - neurun::ir::OperandIndex index10{10u}; - neurun::ir::OperandIndex index11{11u}; - neurun::ir::OperandIndex index12{12u}; + onert::ir::OperandIndex index10{10u}; + onert::ir::OperandIndex index11{11u}; + onert::ir::OperandIndex index12{12u}; graph.addOutput({index10}); graph.addOutput({index11}); @@ -39,9 +39,9 @@ TEST(Graph, inputs_and_outputs) ASSERT_EQ(graph.getInputs().size(), 2); ASSERT_EQ(graph.getOutputs().size(), 3); - neurun::ir::IOIndex io_index0{0}; - neurun::ir::IOIndex io_index1{1}; - neurun::ir::IOIndex io_index2{2}; + onert::ir::IOIndex io_index0{0}; + onert::ir::IOIndex io_index1{1}; + onert::ir::IOIndex io_index2{2}; ASSERT_EQ(graph.getInputs().at(io_index0), 0); ASSERT_EQ(graph.getInputs().at(io_index1), 1); diff --git a/runtime/neurun/test/graph/Index.cc b/runtime/onert/test/graph/Index.cc similarity index 93% rename from runtime/neurun/test/graph/Index.cc rename to runtime/onert/test/graph/Index.cc index c24c2dd5e6b..358e64c82e6 100644 --- a/runtime/neurun/test/graph/Index.cc +++ b/runtime/onert/test/graph/Index.cc @@ -18,7 +18,7 @@ #include "util/Index.h" -using Index = ::neurun::util::Index; +using Index = ::onert::util::Index; TEST(Index, index_test) { diff --git a/runtime/neurun/test/graph/MockNode.h b/runtime/onert/test/graph/MockNode.h similarity index 62% rename from runtime/neurun/test/graph/MockNode.h rename to runtime/onert/test/graph/MockNode.h index 67f4c049d27..60b4719ed2a 100644 --- a/runtime/neurun/test/graph/MockNode.h +++ b/runtime/onert/test/graph/MockNode.h @@ -14,34 +14,34 @@ * limitations under the License. */ -#ifndef __NEURUN_TEST_GRAPH_MOCK_NODE_H__ -#define __NEURUN_TEST_GRAPH_MOCK_NODE_H__ +#ifndef __ONERT_TEST_GRAPH_MOCK_NODE_H__ +#define __ONERT_TEST_GRAPH_MOCK_NODE_H__ #include "ir/Operation.h" #include "ir/OperandIndexSequence.h" -namespace neurun_test +namespace onert_test { namespace ir { -class SimpleMock : public neurun::ir::Operation +class SimpleMock : public onert::ir::Operation { public: - SimpleMock(const neurun::ir::OperandIndexSequence &inputs, - const neurun::ir::OperandIndexSequence &outputs) - : Operation{neurun::ir::OperandConstraint::createAny()} + SimpleMock(const onert::ir::OperandIndexSequence &inputs, + const onert::ir::OperandIndexSequence &outputs) + : Operation{onert::ir::OperandConstraint::createAny()} { setInputs(inputs); setOutputs(outputs); } public: - void accept(neurun::ir::OperationVisitor &) const override {} - neurun::ir::OpCode opcode() const final { return neurun::ir::OpCode::Invalid; } + void accept(onert::ir::OperationVisitor &) const override {} + onert::ir::OpCode opcode() const final { return onert::ir::OpCode::Invalid; } }; } // namespace ir -} // namespace neurun_test +} // namespace onert_test -#endif // __NEURUN_TEST_GRAPH_MOCK_NODE_H__ +#endif // __ONERT_TEST_GRAPH_MOCK_NODE_H__ diff --git a/runtime/neurun/test/graph/operand/IndexSet.cc b/runtime/onert/test/graph/operand/IndexSet.cc similarity index 90% rename from runtime/neurun/test/graph/operand/IndexSet.cc rename to runtime/onert/test/graph/operand/IndexSet.cc index 969290fe115..6215e0d240b 100644 --- a/runtime/neurun/test/graph/operand/IndexSet.cc +++ b/runtime/onert/test/graph/operand/IndexSet.cc @@ -18,8 +18,8 @@ #include "ir/OperandIndexSequence.h" -using neurun::ir::OperandIndex; -using neurun::ir::OperandIndexSequence; +using onert::ir::OperandIndex; +using onert::ir::OperandIndexSequence; TEST(graph_OperandIndexSequence, append) { @@ -31,8 +31,8 @@ TEST(graph_OperandIndexSequence, append) ASSERT_EQ(iset.size(), 5); - neurun::ir::IOIndex index1{1}; - neurun::ir::IOIndex index2{4}; + onert::ir::IOIndex index1{1}; + onert::ir::IOIndex index2{4}; ASSERT_EQ(iset.at(index1), 2); ASSERT_EQ(iset.at(index2), 10); diff --git a/runtime/neurun/test/graph/operand/LayoutSet.cc b/runtime/onert/test/graph/operand/LayoutSet.cc similarity index 96% rename from runtime/neurun/test/graph/operand/LayoutSet.cc rename to runtime/onert/test/graph/operand/LayoutSet.cc index 7b0dcc9f71e..e35bddd8b0b 100644 --- a/runtime/neurun/test/graph/operand/LayoutSet.cc +++ b/runtime/onert/test/graph/operand/LayoutSet.cc @@ -18,8 +18,8 @@ #include "ir/LayoutSet.h" -using neurun::ir::Layout; -using neurun::ir::LayoutSet; +using onert::ir::Layout; +using onert::ir::LayoutSet; TEST(graph_operand_LayoutSet, layout_set_operators) { diff --git a/runtime/neurun/test/graph/operand/Set.cc b/runtime/onert/test/graph/operand/Set.cc similarity index 61% rename from runtime/neurun/test/graph/operand/Set.cc rename to runtime/onert/test/graph/operand/Set.cc index e30a5b7f77a..0d35b5581a1 100644 --- a/runtime/neurun/test/graph/operand/Set.cc +++ b/runtime/onert/test/graph/operand/Set.cc @@ -20,26 +20,26 @@ TEST(graph_operand_Set, set_test) { - neurun::ir::Operands set; + onert::ir::Operands set; - neurun::ir::Shape shape0{1, 2, 3}; + onert::ir::Shape shape0{1, 2, 3}; - neurun::ir::Shape shape1(4); + onert::ir::Shape shape1(4); shape1.dim(0) = 10; shape1.dim(1) = 20; shape1.dim(2) = 30; shape1.dim(3) = 40; - neurun::ir::TypeInfo type{neurun::ir::DataType::INT32}; + onert::ir::TypeInfo type{onert::ir::DataType::INT32}; set.emplace(shape0, type); set.emplace(shape1, type); - ASSERT_EQ(set.exist(neurun::ir::OperandIndex{0u}), true); - ASSERT_EQ(set.exist(neurun::ir::OperandIndex{1u}), true); - ASSERT_EQ(set.exist(neurun::ir::OperandIndex{2u}), false); + ASSERT_EQ(set.exist(onert::ir::OperandIndex{0u}), true); + ASSERT_EQ(set.exist(onert::ir::OperandIndex{1u}), true); + ASSERT_EQ(set.exist(onert::ir::OperandIndex{2u}), false); - ASSERT_EQ(set.at(neurun::ir::OperandIndex{0u}).shape().dim(0), 1); - ASSERT_EQ(set.at(neurun::ir::OperandIndex{0u}).shape().dim(1), 2); - ASSERT_EQ(set.at(neurun::ir::OperandIndex{0u}).shape().dim(2), 3); + ASSERT_EQ(set.at(onert::ir::OperandIndex{0u}).shape().dim(0), 1); + ASSERT_EQ(set.at(onert::ir::OperandIndex{0u}).shape().dim(1), 2); + ASSERT_EQ(set.at(onert::ir::OperandIndex{0u}).shape().dim(2), 3); } diff --git a/runtime/neurun/test/graph/operand/UseDef.cc b/runtime/onert/test/graph/operand/UseDef.cc similarity index 90% rename from runtime/neurun/test/graph/operand/UseDef.cc rename to runtime/onert/test/graph/operand/UseDef.cc index a598fbff34b..3e8b14b8b21 100644 --- a/runtime/neurun/test/graph/operand/UseDef.cc +++ b/runtime/onert/test/graph/operand/UseDef.cc @@ -18,7 +18,7 @@ #include "ir/Graph.h" #include "ir/verifier/Verifier.h" -#include "memory" +#include #include "../MockNode.h" #include @@ -26,18 +26,18 @@ namespace { -using IndexSet = neurun::ir::OperandIndexSequence; -using Mock = neurun_test::ir::SimpleMock; +using IndexSet = onert::ir::OperandIndexSequence; +using Mock = onert_test::ir::SimpleMock; -} // namespace anonymous +} // namespace TEST(graph_operand_usedef, usedef_test) { - neurun::ir::Graph graph; - neurun::ir::verifier::DAGChecker verifier; + onert::ir::Graph graph; + onert::ir::verifier::DAGChecker verifier; - neurun::ir::Shape shape(3); - neurun::ir::TypeInfo type{neurun::ir::DataType::INT32}; + onert::ir::Shape shape(3); + onert::ir::TypeInfo type{onert::ir::DataType::INT32}; // Model Input/Output auto input_operand = graph.addOperand(shape, type); diff --git a/runtime/neurun/test/graph/operation/Set.cc b/runtime/onert/test/graph/operation/Set.cc similarity index 82% rename from runtime/neurun/test/graph/operation/Set.cc rename to runtime/onert/test/graph/operation/Set.cc index fb3d5429882..088c44b8cd8 100644 --- a/runtime/neurun/test/graph/operation/Set.cc +++ b/runtime/onert/test/graph/operation/Set.cc @@ -19,14 +19,14 @@ #include "../MockNode.h" #include "ir/Operations.h" -using neurun::ir::Operations; -using neurun::ir::Operation; -using neurun::ir::OperationIndex; +using onert::ir::Operation; +using onert::ir::OperationIndex; +using onert::ir::Operations; TEST(graph_operation_Set, operation_test) { Operations ops; - ops.push(std::unique_ptr(new neurun_test::ir::SimpleMock({1, 2, 3, 4}, {5, 6, 7}))); + ops.push(std::unique_ptr(new onert_test::ir::SimpleMock({1, 2, 3, 4}, {5, 6, 7}))); OperationIndex idx{0u}; ASSERT_EQ(ops.at(idx).getInputs().size(), 4); ASSERT_EQ(ops.at(idx).getOutputs().size(), 3); diff --git a/runtime/neurun/test/graph/operation/SetIO.cc b/runtime/onert/test/graph/operation/SetIO.cc similarity index 83% rename from runtime/neurun/test/graph/operation/SetIO.cc rename to runtime/onert/test/graph/operation/SetIO.cc index 872fd58d580..378c5b4b9f5 100644 --- a/runtime/neurun/test/graph/operation/SetIO.cc +++ b/runtime/onert/test/graph/operation/SetIO.cc @@ -26,18 +26,18 @@ #include -using Index = neurun::ir::IOIndex; -using IndexSet = neurun::ir::OperandIndexSequence; +using Index = onert::ir::IOIndex; +using IndexSet = onert::ir::OperandIndexSequence; TEST(graph_operation_setIO, operation_setIO_conv) { - neurun::ir::Graph graph; + onert::ir::Graph graph; - neurun::ir::Shape shape{3}; - neurun::ir::TypeInfo type{neurun::ir::DataType::INT32}; + onert::ir::Shape shape{3}; + onert::ir::TypeInfo type{onert::ir::DataType::INT32}; // Add Conv - using Graph = neurun::ir::operation::Conv2D; + using Graph = onert::ir::operation::Conv2D; auto input_operand = graph.addOperand(shape, type); auto kernel_operand = graph.addOperand(shape, type); @@ -45,10 +45,10 @@ TEST(graph_operation_setIO, operation_setIO_conv) IndexSet inputs{input_operand, kernel_operand, bias_operand}; Graph::Param conv_params; - conv_params.padding.type = neurun::ir::PaddingType::SAME; + conv_params.padding.type = onert::ir::PaddingType::SAME; conv_params.stride.horizontal = 1; conv_params.stride.vertical = 1; - conv_params.activation = neurun::ir::Activation::NONE; + conv_params.activation = onert::ir::Activation::NONE; auto output_operand = graph.addOperand(shape, type).value(); IndexSet outputs{output_operand}; @@ -64,13 +64,13 @@ TEST(graph_operation_setIO, operation_setIO_conv) TEST(graph_operation_setIO, operation_setIO_concat) { - neurun::ir::Graph graph; + onert::ir::Graph graph; - neurun::ir::Shape shape{3}; + onert::ir::Shape shape{3}; - neurun::ir::TypeInfo type{neurun::ir::DataType::INT32}; + onert::ir::TypeInfo type{onert::ir::DataType::INT32}; - using Graph = neurun::ir::operation::Concat; + using Graph = onert::ir::operation::Concat; // Add Concat IndexSet inputs; diff --git a/runtime/neurun/test/graph/verifier/Verifier.cc b/runtime/onert/test/graph/verifier/Verifier.cc similarity index 80% rename from runtime/neurun/test/graph/verifier/Verifier.cc rename to runtime/onert/test/graph/verifier/Verifier.cc index 5e915777dc2..f8c7557e3e7 100644 --- a/runtime/neurun/test/graph/verifier/Verifier.cc +++ b/runtime/onert/test/graph/verifier/Verifier.cc @@ -19,19 +19,19 @@ #include "ir/Operation.h" #include "ir/Graph.h" #include "ir/verifier/Verifier.h" -#include "memory" +#include #include "ir/Operand.h" #include "../MockNode.h" -using IndexSet = neurun::ir::OperandIndexSequence; -using Mock = neurun_test::ir::SimpleMock; +using IndexSet = onert::ir::OperandIndexSequence; +using Mock = onert_test::ir::SimpleMock; TEST(Verifier, dag_checker) { - neurun::ir::Graph graph; + onert::ir::Graph graph; - neurun::ir::Shape shape{3}; - neurun::ir::TypeInfo type{neurun::ir::DataType::INT32}; + onert::ir::Shape shape{3}; + onert::ir::TypeInfo type{onert::ir::DataType::INT32}; auto operand1 = graph.addOperand(shape, type); auto operand2 = graph.addOperand(shape, type); @@ -43,7 +43,7 @@ TEST(Verifier, dag_checker) graph.finishBuilding(); - neurun::ir::verifier::DAGChecker verifier; + onert::ir::verifier::DAGChecker verifier; ASSERT_EQ(verifier.verify(graph), true); } diff --git a/runtime/neurun/test/util/ObjectManager.cc b/runtime/onert/test/util/ObjectManager.cc similarity index 99% rename from runtime/neurun/test/util/ObjectManager.cc rename to runtime/onert/test/util/ObjectManager.cc index cfc35d1027d..5051bcfa655 100644 --- a/runtime/neurun/test/util/ObjectManager.cc +++ b/runtime/onert/test/util/ObjectManager.cc @@ -19,7 +19,7 @@ #include "util/ObjectManager.h" #include "util/Index.h" -using namespace neurun; +using namespace onert; struct TestTag; using Index = typename util::Index; diff --git a/runtime/neurun/test/util/ShapeInference.cc b/runtime/onert/test/util/ShapeInference.cc similarity index 83% rename from runtime/neurun/test/util/ShapeInference.cc rename to runtime/onert/test/util/ShapeInference.cc index 2edf4c41c43..053b635f2ff 100644 --- a/runtime/neurun/test/util/ShapeInference.cc +++ b/runtime/onert/test/util/ShapeInference.cc @@ -19,13 +19,13 @@ #include "ir/Layout.h" #include "util/ShapeInference.h" -using namespace neurun::ir; +using namespace onert::ir; TEST(ShapeInference, Elementwise) { Shape lhs_shape{1, 299, 299, 3}; Shape rhs_shape{3}; - auto infered_shapes = neurun::shape_inference::inferEltwiseShape(lhs_shape, rhs_shape); + auto infered_shapes = onert::shape_inference::inferEltwiseShape(lhs_shape, rhs_shape); auto infered_out_shape = infered_shapes[0]; ASSERT_EQ(infered_out_shape.rank(), 4); @@ -39,8 +39,7 @@ TEST(ShapeInference, IncorrectElementwise) { Shape lhs_shape{1, 299, 299, 3}; Shape rhs_shape{5, 3}; - ASSERT_THROW(neurun::shape_inference::inferEltwiseShape(lhs_shape, rhs_shape), - std::runtime_error); + ASSERT_THROW(onert::shape_inference::inferEltwiseShape(lhs_shape, rhs_shape), std::runtime_error); } TEST(ShapeInference, Pool2DNodeSame) @@ -50,7 +49,7 @@ TEST(ShapeInference, Pool2DNodeSame) Padding padding{PaddingType::SAME}; operation::AvgPool2D::Param avg_pool_param{3, 6, stride, padding, Activation::NONE}; - auto infered_shapes = neurun::shape_inference::inferAvgPoolShape(in_shape, avg_pool_param); + auto infered_shapes = onert::shape_inference::inferAvgPoolShape(in_shape, avg_pool_param); auto infered_out_shape = infered_shapes[0]; ASSERT_EQ(infered_out_shape.rank(), 4); @@ -60,7 +59,7 @@ TEST(ShapeInference, Pool2DNodeSame) ASSERT_EQ(infered_out_shape.asFeature(Layout::NHWC).C, 20); operation::MaxPool2D::Param max_pool_param{3, 6, stride, padding, Activation::NONE}; - infered_shapes = neurun::shape_inference::inferMaxPoolShape(in_shape, max_pool_param); + infered_shapes = onert::shape_inference::inferMaxPoolShape(in_shape, max_pool_param); infered_out_shape = infered_shapes[0]; ASSERT_EQ(infered_out_shape.rank(), 4); @@ -77,7 +76,7 @@ TEST(ShapeInference, Pool2DNodeValid) Padding padding{PaddingType::VALID}; operation::AvgPool2D::Param avg_pool_param{3, 6, stride, padding, Activation::NONE}; - auto infered_shapes = neurun::shape_inference::inferAvgPoolShape(in_shape, avg_pool_param); + auto infered_shapes = onert::shape_inference::inferAvgPoolShape(in_shape, avg_pool_param); auto infered_out_shape = infered_shapes[0]; ASSERT_EQ(infered_out_shape.rank(), 4); @@ -87,7 +86,7 @@ TEST(ShapeInference, Pool2DNodeValid) ASSERT_EQ(infered_out_shape.asFeature(Layout::NHWC).C, 20); operation::MaxPool2D::Param max_pool_param{3, 6, stride, padding, Activation::NONE}; - infered_shapes = neurun::shape_inference::inferMaxPoolShape(in_shape, max_pool_param); + infered_shapes = onert::shape_inference::inferMaxPoolShape(in_shape, max_pool_param); infered_out_shape = infered_shapes[0]; ASSERT_EQ(infered_out_shape.rank(), 4); @@ -105,7 +104,7 @@ TEST(ShapeInference, Pool2DNodeExplicit) Padding padding{4, 3, 2, 1}; operation::AvgPool2D::Param avg_pool_param{3, 6, stride, padding, Activation::NONE}; - auto infered_shapes = neurun::shape_inference::inferAvgPoolShape(in_shape, avg_pool_param); + auto infered_shapes = onert::shape_inference::inferAvgPoolShape(in_shape, avg_pool_param); auto infered_out_shape = infered_shapes[0]; ASSERT_EQ(infered_out_shape.rank(), 4); @@ -115,7 +114,7 @@ TEST(ShapeInference, Pool2DNodeExplicit) ASSERT_EQ(infered_out_shape.asFeature(Layout::NHWC).C, 20); operation::MaxPool2D::Param max_pool_param{3, 6, stride, padding, Activation::NONE}; - infered_shapes = neurun::shape_inference::inferMaxPoolShape(in_shape, max_pool_param); + infered_shapes = onert::shape_inference::inferMaxPoolShape(in_shape, max_pool_param); infered_out_shape = infered_shapes[0]; ASSERT_EQ(infered_out_shape.rank(), 4); @@ -131,7 +130,7 @@ TEST(ShapeInference, Conv2D) Shape ker_shape{30, 3, 6, 20}; operation::Conv2D::Param param{Stride{3, 7}, Padding{PaddingType::VALID}, Activation::NONE}; - auto infered_shapes = neurun::shape_inference::inferConv2DShape(in_shape, ker_shape, param); + auto infered_shapes = onert::shape_inference::inferConv2DShape(in_shape, ker_shape, param); auto infered_out_shape = infered_shapes[0]; ASSERT_EQ(infered_out_shape.rank(), 4); @@ -141,7 +140,7 @@ TEST(ShapeInference, Conv2D) ASSERT_EQ(infered_out_shape.asFeature(Layout::NHWC).C, 30); param = operation::Conv2D::Param{Stride{3, 7}, Padding{PaddingType::SAME}, Activation::NONE}; - infered_shapes = neurun::shape_inference::inferConv2DShape(in_shape, ker_shape, param); + infered_shapes = onert::shape_inference::inferConv2DShape(in_shape, ker_shape, param); infered_out_shape = infered_shapes[0]; ASSERT_EQ(infered_out_shape.rank(), 4); @@ -151,7 +150,7 @@ TEST(ShapeInference, Conv2D) ASSERT_EQ(infered_out_shape.asFeature(Layout::NHWC).C, 30); param = operation::Conv2D::Param{Stride{3, 7}, Padding{4, 3, 2, 1}, Activation::NONE}; - infered_shapes = neurun::shape_inference::inferConv2DShape(in_shape, ker_shape, param); + infered_shapes = onert::shape_inference::inferConv2DShape(in_shape, ker_shape, param); infered_out_shape = infered_shapes[0]; ASSERT_EQ(infered_out_shape.rank(), 4); @@ -169,7 +168,7 @@ TEST(ShapeInference, DepthwiseConv2D) operation::DepthwiseConv2D::Param param{Stride{3, 7}, Padding{PaddingType::VALID}, 3, Activation::NONE}; auto infered_shapes = - neurun::shape_inference::inferDepthwiseConv2DShape(in_shape, ker_shape, param); + onert::shape_inference::inferDepthwiseConv2DShape(in_shape, ker_shape, param); auto infered_out_shape = infered_shapes[0]; ASSERT_EQ(infered_out_shape.rank(), 4); @@ -180,7 +179,7 @@ TEST(ShapeInference, DepthwiseConv2D) param = operation::DepthwiseConv2D::Param{Stride{3, 7}, Padding{PaddingType::SAME}, 3, Activation::NONE}; - infered_shapes = neurun::shape_inference::inferDepthwiseConv2DShape(in_shape, ker_shape, param); + infered_shapes = onert::shape_inference::inferDepthwiseConv2DShape(in_shape, ker_shape, param); infered_out_shape = infered_shapes[0]; ASSERT_EQ(infered_out_shape.rank(), 4); @@ -190,7 +189,7 @@ TEST(ShapeInference, DepthwiseConv2D) ASSERT_EQ(infered_out_shape.asFeature(Layout::NHWC).C, 60); param = operation::DepthwiseConv2D::Param{Stride{3, 7}, Padding{4, 3, 2, 1}, 3, Activation::NONE}; - infered_shapes = neurun::shape_inference::inferDepthwiseConv2DShape(in_shape, ker_shape, param); + infered_shapes = onert::shape_inference::inferDepthwiseConv2DShape(in_shape, ker_shape, param); infered_out_shape = infered_shapes[0]; ASSERT_EQ(infered_out_shape.rank(), 4); @@ -207,7 +206,7 @@ TEST(ShapeInference, Concat) Shape in3{10, 20, 30, 2, 50}; operation::Concat::Param param{3}; - auto infered_shapes = neurun::shape_inference::inferConcatShape({in1, in2, in3}, param); + auto infered_shapes = onert::shape_inference::inferConcatShape({in1, in2, in3}, param); auto infered_out_shape = infered_shapes[0]; ASSERT_EQ(infered_out_shape.rank(), 5); @@ -222,7 +221,7 @@ TEST(ShapeInference, FullyConnected) { Shape in_shape{3, 4, 5, 6}; Shape ker_shape{3, 10}; - auto infered_shapes = neurun::shape_inference::inferFullyConnectedShape(in_shape, ker_shape); + auto infered_shapes = onert::shape_inference::inferFullyConnectedShape(in_shape, ker_shape); auto infered_out_shape = infered_shapes[0]; ASSERT_EQ(infered_out_shape.rank(), 2); diff --git a/tests/custom_op/CMakeLists.txt b/tests/custom_op/CMakeLists.txt index 8030aeecc63..8fd8e8af064 100644 --- a/tests/custom_op/CMakeLists.txt +++ b/tests/custom_op/CMakeLists.txt @@ -1,6 +1,6 @@ -if(NOT BUILD_NEURUN) +if(NOT BUILD_ONERT) return() -endif(NOT BUILD_NEURUN) +endif(NOT BUILD_ONERT) nnfw_find_package(FlatBuffers QUIET) if(NOT FlatBuffers_FOUND) diff --git a/tests/nnapi/CMakeLists.txt b/tests/nnapi/CMakeLists.txt index fa310d01983..b1215d867b4 100644 --- a/tests/nnapi/CMakeLists.txt +++ b/tests/nnapi/CMakeLists.txt @@ -2,10 +2,10 @@ if (NOT BUILD_RUNTIME_NNAPI_TEST) return() endif(NOT BUILD_RUNTIME_NNAPI_TEST) -if (NOT BUILD_NEURUN) +if (NOT BUILD_ONERT) message(STATUS "Skip build NNAPI test: no runtime build") return() -endif(NOT BUILD_NEURUN) +endif(NOT BUILD_ONERT) nnfw_find_package(GTest) diff --git a/tests/nnapi/include/NeuralNetworksWrapper.h b/tests/nnapi/include/NeuralNetworksWrapper.h index 960d3fe37fa..af19008fe81 100644 --- a/tests/nnapi/include/NeuralNetworksWrapper.h +++ b/tests/nnapi/include/NeuralNetworksWrapper.h @@ -20,15 +20,15 @@ #ifndef __NNFW_RT_NEURAL_NETWORKS_WRAPPER_H__ #define __NNFW_RT_NEURAL_NETWORKS_WRAPPER_H__ -// Fix for neurun: +// Fix for onert: // NeuralNetworks.h => NeuralNetworksShim.h // Additional include NeuralNetworksExShim.h #include "NeuralNetworksShim.h" #include "NeuralNetworksExShim.h" #include -// Fix for neurun: use boost::optional instead of std::optional -// TODO in neurun: introduce and use internal optional library +// Fix for onert: use boost::optional instead of std::optional +// TODO in onert: introduce and use internal optional library #include #include #include @@ -104,7 +104,7 @@ struct SymmPerChannelQuantParams { struct OperandType { ANeuralNetworksOperandType operandType; std::vector dimensions; - // Fix for neurun: + // Fix for onert: // Use boost::optional instead of std::optional // Default value: std::nullopt -> boost::none boost::optional channelQuant; @@ -275,7 +275,7 @@ class Model { } } - // Fix for neurun: addOperationEx for operation support extension (NeuralNetworksEx.h) + // Fix for onert: addOperationEx for operation support extension (NeuralNetworksEx.h) void addOperationEx(ANeuralNetworksOperationTypeEx type, const std::vector& inputs, const std::vector& outputs) { if (ANeuralNetworksModel_addOperationEx(mModel, type, static_cast(inputs.size()), diff --git a/tests/nnapi/include/TestHarness.h b/tests/nnapi/include/TestHarness.h index 94c8f978371..ca7ad15e72c 100644 --- a/tests/nnapi/include/TestHarness.h +++ b/tests/nnapi/include/TestHarness.h @@ -29,17 +29,25 @@ #include #include +// Fix for onert: define _Float16 for gnu compiler +#if __GNUC__ && !__clang__ +#if __ARM_FP16_FORMAT_IEEE || __ARM_FP16_FORMAT_ALTERNATIVE +#define _Float16 __fp16 +#else // __ARM_FP16_FORMAT_IEEE || __ARM_FP16_FORMAT_ALTERNATIVE +#define _Float16 float +#endif // __ARM_FP16_FORMAT_IEEE || __ARM_FP16_FORMAT_ALTERNATIVE +#endif // __GNUC__ && !__clang__ + namespace test_helper { constexpr const size_t gMaximumNumberOfErrorMessages = 10; // TODO: Figure out the build dependency to make including "CpuOperationUtils.h" work. -// Fix for neurun: comment out convertFloat16ToFloat32 -//inline void convertFloat16ToFloat32(const _Float16* input, std::vector* output) { -// for (size_t i = 0; i < output->size(); ++i) { -// (*output)[i] = static_cast(input[i]); -// } -//} +inline void convertFloat16ToFloat32(const _Float16* input, std::vector* output) { + for (size_t i = 0; i < output->size(); ++i) { + (*output)[i] = static_cast(input[i]); + } +} // This class is a workaround for two issues our code relies on: // 1. sizeof(bool) is implementation defined. @@ -61,8 +69,7 @@ typedef std::map> Float32Operands; typedef std::map> Int32Operands; typedef std::map> Quant8AsymmOperands; typedef std::map> Quant16SymmOperands; -// Fix for neurun: comment out Float16Operands -//typedef std::map> Float16Operands; +typedef std::map> Float16Operands; typedef std::map> Bool8Operands; typedef std::map> Quant8ChannelOperands; typedef std::map> Quant16AsymmOperands; @@ -74,8 +81,7 @@ struct MixedTyped { Int32Operands int32Operands; Quant8AsymmOperands quant8AsymmOperands; Quant16SymmOperands quant16SymmOperands; - // Fix for neurun comment out Float16Operands - //Float16Operands float16Operands; + Float16Operands float16Operands; Bool8Operands bool8Operands; Quant8ChannelOperands quant8ChannelOperands; Quant16AsymmOperands quant16AsymmOperands; @@ -89,9 +95,7 @@ typedef struct { // Specifies the RANDOM_MULTINOMIAL distribution tolerance. // If set to greater than zero, the input is compared as log-probabilities // to the output and must be within this tolerance to pass. - // Fix for neurun: Remove default value - c++11 don't support yet - //float expectedMultinomialDistributionTolerance = 0.0; - float expectedMultinomialDistributionTolerance; + float expectedMultinomialDistributionTolerance = 0.0; } MixedTypedExample; // Go through all index-value pairs of a given input type @@ -152,8 +156,7 @@ inline void for_all(MixedTyped& idx_and_data, for_all_internal(idx_and_data.int32Operands, execute_this); for_all_internal(idx_and_data.quant8AsymmOperands, execute_this); for_all_internal(idx_and_data.quant16SymmOperands, execute_this); - // Fix for neurun: comment out float16Operands field - //for_all_internal(idx_and_data.float16Operands, execute_this); + for_all_internal(idx_and_data.float16Operands, execute_this); for_all_internal(idx_and_data.bool8Operands, execute_this); for_all_internal(idx_and_data.quant8ChannelOperands, execute_this); for_all_internal(idx_and_data.quant16AsymmOperands, execute_this); @@ -179,8 +182,7 @@ inline void for_all(const MixedTyped& idx_and_data, for_all_internal(idx_and_data.int32Operands, execute_this); for_all_internal(idx_and_data.quant8AsymmOperands, execute_this); for_all_internal(idx_and_data.quant16SymmOperands, execute_this); - // Fix for neurun: comment out float16Operands field - //for_all_internal(idx_and_data.float16Operands, execute_this); + for_all_internal(idx_and_data.float16Operands, execute_this); for_all_internal(idx_and_data.bool8Operands, execute_this); for_all_internal(idx_and_data.quant8ChannelOperands, execute_this); for_all_internal(idx_and_data.quant16AsymmOperands, execute_this); @@ -212,8 +214,7 @@ inline void resize_accordingly(const MixedTyped& golden, MixedTyped& test) { resize_accordingly_(golden.int32Operands, test.int32Operands); resize_accordingly_(golden.quant8AsymmOperands, test.quant8AsymmOperands); resize_accordingly_(golden.quant16SymmOperands, test.quant16SymmOperands); - //Fix for neurun: comment out float16Operands field - //resize_accordingly_(golden.float16Operands, test.float16Operands); + resize_accordingly_(golden.float16Operands, test.float16Operands); resize_accordingly_(golden.bool8Operands, test.bool8Operands); resize_accordingly_(golden.quant8ChannelOperands, test.quant8ChannelOperands); resize_accordingly_(golden.quant16AsymmOperands, test.quant16AsymmOperands); @@ -240,8 +241,7 @@ inline MixedTyped filter(const MixedTyped& golden, filter_internal(golden.int32Operands, &filtered.int32Operands, is_ignored); filter_internal(golden.quant8AsymmOperands, &filtered.quant8AsymmOperands, is_ignored); filter_internal(golden.quant16SymmOperands, &filtered.quant16SymmOperands, is_ignored); - // Fix for neurun: comment out float16Operands field - //filter_internal(golden.float16Operands, &filtered.float16Operands, is_ignored); + filter_internal(golden.float16Operands, &filtered.float16Operands, is_ignored); filter_internal(golden.bool8Operands, &filtered.bool8Operands, is_ignored); filter_internal(golden.quant8ChannelOperands, &filtered.quant8ChannelOperands, is_ignored); filter_internal(golden.quant16AsymmOperands, &filtered.quant16AsymmOperands, is_ignored); @@ -333,19 +333,18 @@ inline void compare(const MixedTyped& golden, const MixedTyped& test, totalNumberOfErrors++; } }); - // Fix for neurun: comment out _Float16 compare - //compare_<_Float16>(golden.float16Operands, test.float16Operands, - // [&totalNumberOfErrors, fpAtol, fpRtol](_Float16 expected, _Float16 actual) { - // // Compute the range based on both absolute tolerance and relative - // // tolerance - // float fpRange = fpAtol + fpRtol * std::abs(static_cast(expected)); - // if (totalNumberOfErrors < gMaximumNumberOfErrorMessages) { - // EXPECT_NEAR(expected, actual, fpRange); - // } - // if (std::abs(static_cast(expected - actual)) > fpRange) { - // totalNumberOfErrors++; - // } - // }); + compare_<_Float16>(golden.float16Operands, test.float16Operands, + [&totalNumberOfErrors, fpAtol, fpRtol](_Float16 expected, _Float16 actual) { + // Compute the range based on both absolute tolerance and relative + // tolerance + float fpRange = fpAtol + fpRtol * std::abs(static_cast(expected)); + if (totalNumberOfErrors < gMaximumNumberOfErrorMessages) { + EXPECT_NEAR(expected, actual, fpRange); + } + if (std::abs(static_cast(expected - actual)) > fpRange) { + totalNumberOfErrors++; + } + }); compare_(golden.bool8Operands, test.bool8Operands, [&totalNumberOfErrors](bool expected, bool actual) { if (totalNumberOfErrors < gMaximumNumberOfErrorMessages) { @@ -410,12 +409,11 @@ inline void expectMultinomialDistributionWithinTolerance(const MixedTyped& test, Float32Operands float32Operands = example.operands.first.float32Operands; if (!float32Operands.empty()) { input = example.operands.first.float32Operands.at(0); - } /*else { - // Fix for neurun: comment out convertFloat16ToFloat32 + } else { std::vector<_Float16> inputFloat16 = example.operands.first.float16Operands.at(0); input.resize(inputFloat16.size()); convertFloat16ToFloat32(inputFloat16.data(), &input); - }*/ + } for (int b = 0; b < kBatchSize; ++b) { float probability_sum = 0; const int batch_index = kBatchSize * b; diff --git a/tests/nnapi/nnapi_gtest.skip.aarch64-linux.acl_cl b/tests/nnapi/nnapi_gtest.skip.aarch64-linux.acl_cl index d2700944f84..a366dc0976a 100644 --- a/tests/nnapi/nnapi_gtest.skip.aarch64-linux.acl_cl +++ b/tests/nnapi/nnapi_gtest.skip.aarch64-linux.acl_cl @@ -26,6 +26,7 @@ GeneratedTests.neg_relaxed GeneratedTests.rnn* GeneratedTests.rsqrt GeneratedTests.rsqrt_relaxed +GeneratedTests.sin* GeneratedTests.slice* GeneratedTests.sqrt_ GeneratedTests.sqrt__relaxed diff --git a/tests/nnapi/nnapi_gtest.skip.aarch64-linux.acl_neon b/tests/nnapi/nnapi_gtest.skip.aarch64-linux.acl_neon index 076e0991fd1..2f4fb3bfef1 100644 --- a/tests/nnapi/nnapi_gtest.skip.aarch64-linux.acl_neon +++ b/tests/nnapi/nnapi_gtest.skip.aarch64-linux.acl_neon @@ -40,6 +40,7 @@ GeneratedTests.reshape_*weights_as_inputs GeneratedTests.rnn* GeneratedTests.rsqrt GeneratedTests.rsqrt_relaxed +GeneratedTests.sin* GeneratedTests.slice* GeneratedTests.space_to_batch* GeneratedTests.sqrt_ diff --git a/tests/nnapi/nnapi_gtest.skip.aarch64-linux.cpu b/tests/nnapi/nnapi_gtest.skip.aarch64-linux.cpu index 917dc0ead13..12fdcbf622f 100644 --- a/tests/nnapi/nnapi_gtest.skip.aarch64-linux.cpu +++ b/tests/nnapi/nnapi_gtest.skip.aarch64-linux.cpu @@ -62,7 +62,8 @@ GeneratedTests.relu1* GeneratedTests.relu6* GeneratedTests.resize_bilinear* GeneratedTests.rnn* -GeneratedTests.rsqrt* +GeneratedTests.rsqrt +GeneratedTests.rsqrt_relaxed GeneratedTests.slice* GeneratedTests.space_to_batch* GeneratedTests.space_to_depth* diff --git a/tests/nnapi/nnapi_gtest.skip.aarch64-linux.srcn b/tests/nnapi/nnapi_gtest.skip.aarch64-linux.srcn index f076311881f..b17fd8f219e 100644 --- a/tests/nnapi/nnapi_gtest.skip.aarch64-linux.srcn +++ b/tests/nnapi/nnapi_gtest.skip.aarch64-linux.srcn @@ -53,6 +53,7 @@ GeneratedTests.reshape* GeneratedTests.resize_bilinear* GeneratedTests.rnn* GeneratedTests.rsqrt* +GeneratedTests.sin* GeneratedTests.slice* GeneratedTests.softmax* GeneratedTests.space_to_batch* diff --git a/tests/nnapi/nnapi_gtest.skip.armv7l-linux.acl_cl b/tests/nnapi/nnapi_gtest.skip.armv7l-linux.acl_cl index d2700944f84..a366dc0976a 100644 --- a/tests/nnapi/nnapi_gtest.skip.armv7l-linux.acl_cl +++ b/tests/nnapi/nnapi_gtest.skip.armv7l-linux.acl_cl @@ -26,6 +26,7 @@ GeneratedTests.neg_relaxed GeneratedTests.rnn* GeneratedTests.rsqrt GeneratedTests.rsqrt_relaxed +GeneratedTests.sin* GeneratedTests.slice* GeneratedTests.sqrt_ GeneratedTests.sqrt__relaxed diff --git a/tests/nnapi/nnapi_gtest.skip.armv7l-linux.acl_neon b/tests/nnapi/nnapi_gtest.skip.armv7l-linux.acl_neon index 07f8c5f8564..2ec10d2672a 100644 --- a/tests/nnapi/nnapi_gtest.skip.armv7l-linux.acl_neon +++ b/tests/nnapi/nnapi_gtest.skip.armv7l-linux.acl_neon @@ -39,6 +39,7 @@ GeneratedTests.reshape_*weights_as_inputs GeneratedTests.rnn* GeneratedTests.rsqrt GeneratedTests.rsqrt_relaxed +GeneratedTests.sin* GeneratedTests.slice* GeneratedTests.sqrt_ GeneratedTests.sqrt__relaxed diff --git a/tests/nnapi/nnapi_gtest.skip.armv7l-linux.cpu b/tests/nnapi/nnapi_gtest.skip.armv7l-linux.cpu index 8e4845c9468..044510d20a1 100644 --- a/tests/nnapi/nnapi_gtest.skip.armv7l-linux.cpu +++ b/tests/nnapi/nnapi_gtest.skip.armv7l-linux.cpu @@ -56,7 +56,8 @@ GeneratedTests.relu1* GeneratedTests.relu6* GeneratedTests.resize_bilinear* GeneratedTests.rnn* -GeneratedTests.rsqrt* +GeneratedTests.rsqrt +GeneratedTests.rsqrt_relaxed GeneratedTests.slice_5 GeneratedTests.slice_6 GeneratedTests.slice_7 @@ -64,10 +65,11 @@ GeneratedTests.slice_8 GeneratedTests.slice_zero_sized* GeneratedTests.space_to_batch* GeneratedTests.space_to_depth* -GeneratedTests.split* +GeneratedTests.split_*nt* GeneratedTests.sqrt* GeneratedTests.squared_difference_ex* -GeneratedTests.strided_slice* +GeneratedTests.strided_slice_*quant* +GeneratedTests.strided_slice_*qaunt* GeneratedTests.strided_slice_ex* GeneratedTests.sub_quant* GeneratedTests.sub_v1_2_broadcast_quant8 diff --git a/tests/nnapi/nnapi_gtest.skip.armv7l-linux.srcn b/tests/nnapi/nnapi_gtest.skip.armv7l-linux.srcn index f076311881f..b17fd8f219e 100644 --- a/tests/nnapi/nnapi_gtest.skip.armv7l-linux.srcn +++ b/tests/nnapi/nnapi_gtest.skip.armv7l-linux.srcn @@ -53,6 +53,7 @@ GeneratedTests.reshape* GeneratedTests.resize_bilinear* GeneratedTests.rnn* GeneratedTests.rsqrt* +GeneratedTests.sin* GeneratedTests.slice* GeneratedTests.softmax* GeneratedTests.space_to_batch* diff --git a/tests/nnapi/nnapi_gtest.skip.armv7l-tizen.acl_cl b/tests/nnapi/nnapi_gtest.skip.armv7l-tizen.acl_cl index 89d48f177cc..a85a31fa1b6 100644 --- a/tests/nnapi/nnapi_gtest.skip.armv7l-tizen.acl_cl +++ b/tests/nnapi/nnapi_gtest.skip.armv7l-tizen.acl_cl @@ -29,6 +29,7 @@ GeneratedTests.pack* GeneratedTests.rnn* GeneratedTests.rsqrt GeneratedTests.rsqrt_relaxed +GeneratedTests.sin* GeneratedTests.slice* GeneratedTests.space_to_batch* GeneratedTests.sqrt_ diff --git a/tests/nnapi/nnapi_gtest.skip.noarch.interp b/tests/nnapi/nnapi_gtest.skip.noarch.interp index 0fa51866f57..81a0c17c188 100644 --- a/tests/nnapi/nnapi_gtest.skip.noarch.interp +++ b/tests/nnapi/nnapi_gtest.skip.noarch.interp @@ -52,6 +52,7 @@ GeneratedTests.relu_quant* GeneratedTests.resize_bilinear* GeneratedTests.rnn* GeneratedTests.rsqrt* +GeneratedTests.sin* GeneratedTests.slice* GeneratedTests.softmax_quant* GeneratedTests.space_to_batch* diff --git a/tests/nnapi/nnapi_gtest.skip.x86_64-linux.cpu b/tests/nnapi/nnapi_gtest.skip.x86_64-linux.cpu index 5057d9d3f66..462cb9dc0ea 100644 --- a/tests/nnapi/nnapi_gtest.skip.x86_64-linux.cpu +++ b/tests/nnapi/nnapi_gtest.skip.x86_64-linux.cpu @@ -57,7 +57,7 @@ GeneratedTests.rsqrt* GeneratedTests.slice* GeneratedTests.space_to_batch* GeneratedTests.space_to_depth* -GeneratedTests.split* +GeneratedTests.split_*nt* GeneratedTests.sqrt* GeneratedTests.squared_difference_ex* GeneratedTests.strided_slice* diff --git a/tests/nnapi/nnapi_test_generator/android-10/README.md b/tests/nnapi/nnapi_test_generator/android-10/README.md index 766b431a330..3de818b6963 100644 --- a/tests/nnapi/nnapi_test_generator/android-10/README.md +++ b/tests/nnapi/nnapi_test_generator/android-10/README.md @@ -2,9 +2,9 @@ Original code is at https://android.googlesource.com/platform/frameworks/ml/+/refs/tags/android-10.0.0_r2/nn/tools/test_generator/ -### Fix for neurun +### Fix for onert -- Update path in this `README.md` file for neurun NNAPI frontend test +- Update path in this `README.md` file for onert NNAPI frontend test - `nn/runtime/test/specs/` => `tests/nnapi/specs/` - $ANDROID_BUILD_TOP/frameworks/ml/nn/runtime/test/specs => $NNAS_PROJECT_PATH/tests/nnapi/specs - Rebuild with mm afterwards => Rebuild afterwards (mm is not supported) @@ -16,12 +16,9 @@ Original code is at https://android.googlesource.com/platform/frameworks/ml/+/re - path for regular expression: `((frameworks/ml/nn/(runtime/test/)?)|(vendor/google/[a-z]*/test/))` => `(tests/nnapi/src/)` - Support EX operation - - Fix c++14 feature: change to c++11 constructor - Comment out `TEST_AVAILABLE_SINCE()` macro generation - - Comment out unsupported `FLOAT16` on armv7 32bit architecture - Update `test_generator.py` - Comment out dynamic shape output test generation - - Skip test generation for float16 type variation --- diff --git a/tests/nnapi/nnapi_test_generator/android-10/cts_generator.py b/tests/nnapi/nnapi_test_generator/android-10/cts_generator.py index eb18c562790..de55e39ba3e 100755 --- a/tests/nnapi/nnapi_test_generator/android-10/cts_generator.py +++ b/tests/nnapi/nnapi_test_generator/android-10/cts_generator.py @@ -106,7 +106,7 @@ def InitializeFiles(model_fd, example_fd, test_fd): #include "{model_file}" }} // namespace {spec_name}\n""" # This regex is to remove prefix and get relative path for #include - # Fix for neurun: update path + # Fix for onert: update path pathRegex = r".*(tests/nnapi/src/)" specFileBase = os.path.basename(tg.FileNames.specFile) print(fileHeader.format(spec_file=specFileBase), file=model_fd) @@ -162,7 +162,7 @@ def DumpCtsModel(model, model_fd): p.initializer, p.type.GetCppTypeString(), p.type.GetNumberOfElements()) IndentedPrint(paramDef, file=model_fd) for op in model.operations: - # Fix for neurun: EX operation + # Fix for onert: EX operation if re.search('_EX$', op.optype): IndentedPrint("model->addOperationEx(ANEURALNETWORKS_%s, {%s}, {%s});"%( op.optype, tg.GetJointStr(op.ins), tg.GetJointStr(op.outs)), file=model_fd) @@ -210,30 +210,28 @@ def DumpMixedType(operands, feedDict): except KeyError as e: traceback.print_exc() sys.exit("Cannot dump tensor of type {}".format(operand.type.type)) - # NFix for neurun: fix designated initializer (not supported on c++11) - # comment out FLOAT16 type mixedTypeTemplate = """\ {{ // See tools/test_generator/include/TestHarness.h:MixedTyped // int -> Dimensions map - {{{dimensions_map}}}, + .operandDimensions = {{{dimensions_map}}}, // int -> FLOAT32 map - {{{float32_map}}}, + .float32Operands = {{{float32_map}}}, // int -> INT32 map - {{{int32_map}}}, + .int32Operands = {{{int32_map}}}, // int -> QUANT8_ASYMM map - {{{uint8_map}}}, + .quant8AsymmOperands = {{{uint8_map}}}, // int -> QUANT16_SYMM map - {{{int16_map}}}, + .quant16SymmOperands = {{{int16_map}}}, // int -> FLOAT16 map - //{{{float16_map}}}, + .float16Operands = {{{float16_map}}}, // int -> BOOL8 map - {{{bool8_map}}}, + .bool8Operands = {{{bool8_map}}}, // int -> QUANT8_SYMM_PER_CHANNEL map - {{{int8_map}}}, + .quant8ChannelOperands = {{{int8_map}}}, // int -> QUANT16_ASYMM map - {{{uint16_map}}}, + .quant16AsymmOperands = {{{uint16_map}}}, // int -> QUANT8_SYMM map - {{{quant8_symm_map}}}, + .quant8SymmOperands = {{{quant8_symm_map}}}, }}""" return mixedTypeTemplate.format( dimensions_map=tg.GetJointStr(typedMap.get("DIMENSIONS", [])), @@ -254,20 +252,16 @@ def DumpCtsExample(example, example_fd): print("std::vector& get_%s() {" % (example.examplesName), file=example_fd) print("static std::vector %s = {" % (example.examplesName), file=example_fd) for inputFeedDict, outputFeedDict in example.feedDicts: - # Fix designated initializer (c++11 don't support yet) print ('// Begin of an example', file = example_fd) - print ('{\n {', file = example_fd) + print ('{\n.operands = {', file = example_fd) inputs = DumpMixedType(example.model.GetInputs(), inputFeedDict) outputs = DumpMixedType(example.model.GetOutputs(), outputFeedDict) print ('//Input(s)\n%s,' % inputs , file = example_fd) print ('//Output(s)\n%s' % outputs, file = example_fd) print ('},', file = example_fd) - # Fix designated initializer (c++11 don't support yet) if example.expectedMultinomialDistributionTolerance is not None: - print ('%f' % + print ('.expectedMultinomialDistributionTolerance = %f' % example.expectedMultinomialDistributionTolerance, file = example_fd) - else: - print ('0.0', file = example_fd) print ('}, // End of an example', file = example_fd) print("};", file=example_fd) print("return %s;" % (example.examplesName), file=example_fd) @@ -280,7 +274,7 @@ def DumpCtsTest(example, test_fd): execute({namespace}::{create_model_name}, {namespace}::{is_ignored_name}, {namespace}::get_{examples_name}(){log_file});\n}}\n""" - # Fix for neurun: Remove version check + # Fix for onert: Remove version check #if example.model.version is not None: #testTemplate += """\ #TEST_AVAILABLE_SINCE({version}, {test_name}, {namespace}::{create_model_name})\n""" diff --git a/tests/nnapi/nnapi_test_generator/android-10/test_generator.py b/tests/nnapi/nnapi_test_generator/android-10/test_generator.py index 9d0913ad08f..b4b07cbda99 100755 --- a/tests/nnapi/nnapi_test_generator/android-10/test_generator.py +++ b/tests/nnapi/nnapi_test_generator/android-10/test_generator.py @@ -989,7 +989,7 @@ def __init__(self, *args, model=None, name=None): )) else: assert False - # Fix for neurun: disable dynamic shape test generation + # Fix for onert: disable dynamic shape test generation #if Configuration.test_dynamic_output_shape: #self.variations = [[DefaultVariation(), DynamicOutputShapeConverter()]] #else: diff --git a/tests/nnapi/specs/Ex/fully_connected_float_2_weights_as_inputs.mod.py b/tests/nnapi/specs/Ex/fully_connected_float_2_weights_as_inputs.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/Ex/pack_ex_2D_float_1.mod.py b/tests/nnapi/specs/Ex/pack_ex_2D_float_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/Ex/pack_ex_2D_float_2.mod.py b/tests/nnapi/specs/Ex/pack_ex_2D_float_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/Ex/pack_ex_2D_int_1.mod.py b/tests/nnapi/specs/Ex/pack_ex_2D_int_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/Ex/pack_ex_2D_int_2.mod.py b/tests/nnapi/specs/Ex/pack_ex_2D_int_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/Ex/squared_difference_ex_1D_float.mod.py b/tests/nnapi/specs/Ex/squared_difference_ex_1D_float.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/Ex/squared_difference_ex_2D_float.mod.py b/tests/nnapi/specs/Ex/squared_difference_ex_2D_float.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/Ex/squared_difference_ex_3D_float.mod.py b/tests/nnapi/specs/Ex/squared_difference_ex_3D_float.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/Ex/squared_difference_ex_4D_float.mod.py b/tests/nnapi/specs/Ex/squared_difference_ex_4D_float.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/Ex/squared_difference_ex_broadcast_4D_2D_float.mod.py b/tests/nnapi/specs/Ex/squared_difference_ex_broadcast_4D_2D_float.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/Ex/squared_difference_ex_broadcast_float.mod.py b/tests/nnapi/specs/Ex/squared_difference_ex_broadcast_float.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/Ex/transpose_conv_ex_float_1.mod.py b/tests/nnapi/specs/Ex/transpose_conv_ex_float_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/Ex/transpose_conv_ex_float_2.mod.py b/tests/nnapi/specs/Ex/transpose_conv_ex_float_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/Ex/transpose_conv_ex_float_3.mod.py b/tests/nnapi/specs/Ex/transpose_conv_ex_float_3.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/Ex/transpose_conv_ex_float_4.mod.py b/tests/nnapi/specs/Ex/transpose_conv_ex_float_4.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/Ex/unpack_ex_3D_float_1.mod.py b/tests/nnapi/specs/Ex/unpack_ex_3D_float_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/Ex/unpack_ex_3D_float_2.mod.py b/tests/nnapi/specs/Ex/unpack_ex_3D_float_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/Ex/unpack_ex_3D_int_1.mod.py b/tests/nnapi/specs/Ex/unpack_ex_3D_int_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/Ex/unpack_ex_3D_int_2.mod.py b/tests/nnapi/specs/Ex/unpack_ex_3D_int_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/add.mod.py b/tests/nnapi/specs/V1_0/add.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/add_broadcast_4D_2D_after_nops_float_nnfw.mod.py b/tests/nnapi/specs/V1_0/add_broadcast_4D_2D_after_nops_float_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/add_broadcast_quant8.mod.py b/tests/nnapi/specs/V1_0/add_broadcast_quant8.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/add_quant8.mod.py b/tests/nnapi/specs/V1_0/add_quant8.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/avg_pool_float_1.mod.py b/tests/nnapi/specs/V1_0/avg_pool_float_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/avg_pool_float_2.mod.py b/tests/nnapi/specs/V1_0/avg_pool_float_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/avg_pool_float_3.mod.py b/tests/nnapi/specs/V1_0/avg_pool_float_3.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/avg_pool_float_4.mod.py b/tests/nnapi/specs/V1_0/avg_pool_float_4.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/avg_pool_float_5.mod.py b/tests/nnapi/specs/V1_0/avg_pool_float_5.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/avg_pool_quant8_1.mod.py b/tests/nnapi/specs/V1_0/avg_pool_quant8_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/avg_pool_quant8_2.mod.py b/tests/nnapi/specs/V1_0/avg_pool_quant8_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/avg_pool_quant8_3.mod.py b/tests/nnapi/specs/V1_0/avg_pool_quant8_3.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/avg_pool_quant8_4.mod.py b/tests/nnapi/specs/V1_0/avg_pool_quant8_4.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/avg_pool_quant8_5.mod.py b/tests/nnapi/specs/V1_0/avg_pool_quant8_5.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/concat_float_1.mod.py b/tests/nnapi/specs/V1_0/concat_float_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/concat_float_2.mod.py b/tests/nnapi/specs/V1_0/concat_float_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/concat_float_3.mod.py b/tests/nnapi/specs/V1_0/concat_float_3.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/concat_float_4D_axis3_1_nnfw.mod.py b/tests/nnapi/specs/V1_0/concat_float_4D_axis3_1_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/concat_quant8_1.mod.py b/tests/nnapi/specs/V1_0/concat_quant8_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/concat_quant8_2.mod.py b/tests/nnapi/specs/V1_0/concat_quant8_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/concat_quant8_3.mod.py b/tests/nnapi/specs/V1_0/concat_quant8_3.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/conv_1_h3_w2_SAME.mod.py b/tests/nnapi/specs/V1_0/conv_1_h3_w2_SAME.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/conv_1_h3_w2_VALID.mod.py b/tests/nnapi/specs/V1_0/conv_1_h3_w2_VALID.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/conv_3_h3_w2_SAME.mod.py b/tests/nnapi/specs/V1_0/conv_3_h3_w2_SAME.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/conv_3_h3_w2_VALID.mod.py b/tests/nnapi/specs/V1_0/conv_3_h3_w2_VALID.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/conv_float.mod.py b/tests/nnapi/specs/V1_0/conv_float.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/conv_float_2.mod.py b/tests/nnapi/specs/V1_0/conv_float_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/conv_float_channels.mod.py b/tests/nnapi/specs/V1_0/conv_float_channels.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/conv_float_channels_weights_as_inputs.mod.py b/tests/nnapi/specs/V1_0/conv_float_channels_weights_as_inputs.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/conv_float_large.mod.py b/tests/nnapi/specs/V1_0/conv_float_large.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/conv_float_large_weights_as_inputs.mod.py b/tests/nnapi/specs/V1_0/conv_float_large_weights_as_inputs.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/conv_float_weights_as_inputs.mod.py b/tests/nnapi/specs/V1_0/conv_float_weights_as_inputs.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/conv_quant8.mod.py b/tests/nnapi/specs/V1_0/conv_quant8.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/conv_quant8_2.mod.py b/tests/nnapi/specs/V1_0/conv_quant8_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/conv_quant8_channels.mod.py b/tests/nnapi/specs/V1_0/conv_quant8_channels.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/conv_quant8_channels_weights_as_inputs.mod.py b/tests/nnapi/specs/V1_0/conv_quant8_channels_weights_as_inputs.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/conv_quant8_large.mod.py b/tests/nnapi/specs/V1_0/conv_quant8_large.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/conv_quant8_large_weights_as_inputs.mod.py b/tests/nnapi/specs/V1_0/conv_quant8_large_weights_as_inputs.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/conv_quant8_overflow.mod.py b/tests/nnapi/specs/V1_0/conv_quant8_overflow.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/conv_quant8_overflow_weights_as_inputs.mod.py b/tests/nnapi/specs/V1_0/conv_quant8_overflow_weights_as_inputs.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/conv_quant8_weights_as_inputs.mod.py b/tests/nnapi/specs/V1_0/conv_quant8_weights_as_inputs.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/depth_to_space_float_1.mod.py b/tests/nnapi/specs/V1_0/depth_to_space_float_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/depth_to_space_float_2.mod.py b/tests/nnapi/specs/V1_0/depth_to_space_float_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/depth_to_space_float_3.mod.py b/tests/nnapi/specs/V1_0/depth_to_space_float_3.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/depth_to_space_quant8_1.mod.py b/tests/nnapi/specs/V1_0/depth_to_space_quant8_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/depth_to_space_quant8_2.mod.py b/tests/nnapi/specs/V1_0/depth_to_space_quant8_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/depthwise_conv.mod.py b/tests/nnapi/specs/V1_0/depthwise_conv.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/depthwise_conv2d_float.mod.py b/tests/nnapi/specs/V1_0/depthwise_conv2d_float.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/depthwise_conv2d_float_2.mod.py b/tests/nnapi/specs/V1_0/depthwise_conv2d_float_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/depthwise_conv2d_float_large.mod.py b/tests/nnapi/specs/V1_0/depthwise_conv2d_float_large.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/depthwise_conv2d_float_large_2.mod.py b/tests/nnapi/specs/V1_0/depthwise_conv2d_float_large_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/depthwise_conv2d_float_large_2_weights_as_inputs.mod.py b/tests/nnapi/specs/V1_0/depthwise_conv2d_float_large_2_weights_as_inputs.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/depthwise_conv2d_float_large_weights_as_inputs.mod.py b/tests/nnapi/specs/V1_0/depthwise_conv2d_float_large_weights_as_inputs.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/depthwise_conv2d_float_weights_as_inputs.mod.py b/tests/nnapi/specs/V1_0/depthwise_conv2d_float_weights_as_inputs.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/depthwise_conv2d_quant8.mod.py b/tests/nnapi/specs/V1_0/depthwise_conv2d_quant8.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/depthwise_conv2d_quant8_2.mod.py b/tests/nnapi/specs/V1_0/depthwise_conv2d_quant8_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/depthwise_conv2d_quant8_large.mod.py b/tests/nnapi/specs/V1_0/depthwise_conv2d_quant8_large.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/depthwise_conv2d_quant8_large_weights_as_inputs.mod.py b/tests/nnapi/specs/V1_0/depthwise_conv2d_quant8_large_weights_as_inputs.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/depthwise_conv2d_quant8_weights_as_inputs.mod.py b/tests/nnapi/specs/V1_0/depthwise_conv2d_quant8_weights_as_inputs.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/dequantize.mod.py b/tests/nnapi/specs/V1_0/dequantize.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/embedding_lookup.mod.py b/tests/nnapi/specs/V1_0/embedding_lookup.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/embedding_lookup_2d_nnfw.mod.py b/tests/nnapi/specs/V1_0/embedding_lookup_2d_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/embedding_lookup_4d_nnfw.mod.py b/tests/nnapi/specs/V1_0/embedding_lookup_4d_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/floor_.mod.py b/tests/nnapi/specs/V1_0/floor_.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/fully_connected_float.mod.py b/tests/nnapi/specs/V1_0/fully_connected_float.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/fully_connected_float_1_nnfw.mod.py b/tests/nnapi/specs/V1_0/fully_connected_float_1_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/fully_connected_float_2.mod.py b/tests/nnapi/specs/V1_0/fully_connected_float_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/fully_connected_float_3.mod.py b/tests/nnapi/specs/V1_0/fully_connected_float_3.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/fully_connected_float_large.mod.py b/tests/nnapi/specs/V1_0/fully_connected_float_large.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/fully_connected_float_large_weights_as_inputs.mod.py b/tests/nnapi/specs/V1_0/fully_connected_float_large_weights_as_inputs.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/fully_connected_float_weights_as_inputs.mod.py b/tests/nnapi/specs/V1_0/fully_connected_float_weights_as_inputs.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/fully_connected_hybrid_1_nnfw.mod.py b/tests/nnapi/specs/V1_0/fully_connected_hybrid_1_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/fully_connected_hybrid_2_nnfw.mod.py b/tests/nnapi/specs/V1_0/fully_connected_hybrid_2_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/fully_connected_quant8.mod.py b/tests/nnapi/specs/V1_0/fully_connected_quant8.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/fully_connected_quant8_2.mod.py b/tests/nnapi/specs/V1_0/fully_connected_quant8_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/fully_connected_quant8_large.mod.py b/tests/nnapi/specs/V1_0/fully_connected_quant8_large.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/fully_connected_quant8_large_weights_as_inputs.mod.py b/tests/nnapi/specs/V1_0/fully_connected_quant8_large_weights_as_inputs.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/fully_connected_quant8_weights_as_inputs.mod.py b/tests/nnapi/specs/V1_0/fully_connected_quant8_weights_as_inputs.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/hashtable_lookup_float.mod.py b/tests/nnapi/specs/V1_0/hashtable_lookup_float.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/hashtable_lookup_float_4D_nnfw.mod.py b/tests/nnapi/specs/V1_0/hashtable_lookup_float_4D_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/hashtable_lookup_quant8.mod.py b/tests/nnapi/specs/V1_0/hashtable_lookup_quant8.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/l2_normalization.mod.py b/tests/nnapi/specs/V1_0/l2_normalization.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/l2_normalization_2.mod.py b/tests/nnapi/specs/V1_0/l2_normalization_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/l2_normalization_large.mod.py b/tests/nnapi/specs/V1_0/l2_normalization_large.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/l2_pool_float.mod.py b/tests/nnapi/specs/V1_0/l2_pool_float.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/l2_pool_float_2.mod.py b/tests/nnapi/specs/V1_0/l2_pool_float_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/l2_pool_float_large.mod.py b/tests/nnapi/specs/V1_0/l2_pool_float_large.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/local_response_norm_float_1.mod.py b/tests/nnapi/specs/V1_0/local_response_norm_float_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/local_response_norm_float_2.mod.py b/tests/nnapi/specs/V1_0/local_response_norm_float_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/local_response_norm_float_3.mod.py b/tests/nnapi/specs/V1_0/local_response_norm_float_3.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/local_response_norm_float_4.mod.py b/tests/nnapi/specs/V1_0/local_response_norm_float_4.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/logistic_float_1.mod.py b/tests/nnapi/specs/V1_0/logistic_float_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/logistic_float_2.mod.py b/tests/nnapi/specs/V1_0/logistic_float_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/logistic_quant8_1.mod.py b/tests/nnapi/specs/V1_0/logistic_quant8_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/logistic_quant8_2.mod.py b/tests/nnapi/specs/V1_0/logistic_quant8_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/lsh_projection.mod.py b/tests/nnapi/specs/V1_0/lsh_projection.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/lsh_projection_2.mod.py b/tests/nnapi/specs/V1_0/lsh_projection_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/lsh_projection_weights_as_inputs.mod.py b/tests/nnapi/specs/V1_0/lsh_projection_weights_as_inputs.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/lstm.mod.py b/tests/nnapi/specs/V1_0/lstm.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/lstm2.mod.py b/tests/nnapi/specs/V1_0/lstm2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/lstm2_state.mod.py b/tests/nnapi/specs/V1_0/lstm2_state.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/lstm2_state2.mod.py b/tests/nnapi/specs/V1_0/lstm2_state2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/lstm3.mod.py b/tests/nnapi/specs/V1_0/lstm3.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/lstm3_state.mod.py b/tests/nnapi/specs/V1_0/lstm3_state.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/lstm3_state2.mod.py b/tests/nnapi/specs/V1_0/lstm3_state2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/lstm3_state3.mod.py b/tests/nnapi/specs/V1_0/lstm3_state3.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/lstm_state.mod.py b/tests/nnapi/specs/V1_0/lstm_state.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/lstm_state2.mod.py b/tests/nnapi/specs/V1_0/lstm_state2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/max_pool_float_1.mod.py b/tests/nnapi/specs/V1_0/max_pool_float_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/max_pool_float_2.mod.py b/tests/nnapi/specs/V1_0/max_pool_float_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/max_pool_float_3.mod.py b/tests/nnapi/specs/V1_0/max_pool_float_3.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/max_pool_float_4.mod.py b/tests/nnapi/specs/V1_0/max_pool_float_4.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/max_pool_quant8_1.mod.py b/tests/nnapi/specs/V1_0/max_pool_quant8_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/max_pool_quant8_2.mod.py b/tests/nnapi/specs/V1_0/max_pool_quant8_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/max_pool_quant8_3.mod.py b/tests/nnapi/specs/V1_0/max_pool_quant8_3.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/max_pool_quant8_4.mod.py b/tests/nnapi/specs/V1_0/max_pool_quant8_4.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/mul.mod.py b/tests/nnapi/specs/V1_0/mul.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/mul_4D_nnfw.mod.py b/tests/nnapi/specs/V1_0/mul_4D_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/mul_broadcast_3D_1D_1_nnfw.mod.py b/tests/nnapi/specs/V1_0/mul_broadcast_3D_1D_1_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/mul_broadcast_3D_1D_2_nnfw.mod.py b/tests/nnapi/specs/V1_0/mul_broadcast_3D_1D_2_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/mul_broadcast_quant8.mod.py b/tests/nnapi/specs/V1_0/mul_broadcast_quant8.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/mul_float_square_nnfw.mod.py b/tests/nnapi/specs/V1_0/mul_float_square_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/mul_quant8.mod.py b/tests/nnapi/specs/V1_0/mul_quant8.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/mul_relu.mod.py b/tests/nnapi/specs/V1_0/mul_relu.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/relu1_float_1.mod.py b/tests/nnapi/specs/V1_0/relu1_float_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/relu1_float_2.mod.py b/tests/nnapi/specs/V1_0/relu1_float_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/relu1_quant8_1.mod.py b/tests/nnapi/specs/V1_0/relu1_quant8_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/relu1_quant8_2.mod.py b/tests/nnapi/specs/V1_0/relu1_quant8_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/relu6_float_1.mod.py b/tests/nnapi/specs/V1_0/relu6_float_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/relu6_float_2.mod.py b/tests/nnapi/specs/V1_0/relu6_float_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/relu6_quant8_1.mod.py b/tests/nnapi/specs/V1_0/relu6_quant8_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/relu6_quant8_2.mod.py b/tests/nnapi/specs/V1_0/relu6_quant8_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/relu_float_1.mod.py b/tests/nnapi/specs/V1_0/relu_float_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/relu_float_2.mod.py b/tests/nnapi/specs/V1_0/relu_float_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/relu_quant8_1.mod.py b/tests/nnapi/specs/V1_0/relu_quant8_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/relu_quant8_2.mod.py b/tests/nnapi/specs/V1_0/relu_quant8_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/reshape.mod.py b/tests/nnapi/specs/V1_0/reshape.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/reshape_quant8.mod.py b/tests/nnapi/specs/V1_0/reshape_quant8.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/reshape_quant8_weights_as_inputs.mod.py b/tests/nnapi/specs/V1_0/reshape_quant8_weights_as_inputs.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/reshape_weights_as_inputs.mod.py b/tests/nnapi/specs/V1_0/reshape_weights_as_inputs.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/resize_bilinear.mod.py b/tests/nnapi/specs/V1_0/resize_bilinear.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/resize_bilinear_2.mod.py b/tests/nnapi/specs/V1_0/resize_bilinear_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/rnn.mod.py b/tests/nnapi/specs/V1_0/rnn.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/rnn_state.mod.py b/tests/nnapi/specs/V1_0/rnn_state.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/softmax_float_1.mod.py b/tests/nnapi/specs/V1_0/softmax_float_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/softmax_float_2.mod.py b/tests/nnapi/specs/V1_0/softmax_float_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/softmax_quant8_1.mod.py b/tests/nnapi/specs/V1_0/softmax_quant8_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/softmax_quant8_2.mod.py b/tests/nnapi/specs/V1_0/softmax_quant8_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/space_to_depth_float_1.mod.py b/tests/nnapi/specs/V1_0/space_to_depth_float_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/space_to_depth_float_2.mod.py b/tests/nnapi/specs/V1_0/space_to_depth_float_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/space_to_depth_float_3.mod.py b/tests/nnapi/specs/V1_0/space_to_depth_float_3.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/space_to_depth_quant8_1.mod.py b/tests/nnapi/specs/V1_0/space_to_depth_quant8_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/space_to_depth_quant8_2.mod.py b/tests/nnapi/specs/V1_0/space_to_depth_quant8_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/svdf.mod.py b/tests/nnapi/specs/V1_0/svdf.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/svdf2.mod.py b/tests/nnapi/specs/V1_0/svdf2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/svdf_bias_present.mod.py b/tests/nnapi/specs/V1_0/svdf_bias_present.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/svdf_state.mod.py b/tests/nnapi/specs/V1_0/svdf_state.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_0/tanh_.mod.py b/tests/nnapi/specs/V1_0/tanh_.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/batch_to_space.mod.py b/tests/nnapi/specs/V1_1/batch_to_space.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/batch_to_space_float_1.mod.py b/tests/nnapi/specs/V1_1/batch_to_space_float_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/batch_to_space_quant8_1.mod.py b/tests/nnapi/specs/V1_1/batch_to_space_quant8_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/div_.mod.py b/tests/nnapi/specs/V1_1/div_.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/div_broadcast_float.mod.py b/tests/nnapi/specs/V1_1/div_broadcast_float.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/div_broadcast_float_4D_2D_nnfw.mod.py b/tests/nnapi/specs/V1_1/div_broadcast_float_4D_2D_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/fully_connected_float_4d_simple.mod.py b/tests/nnapi/specs/V1_1/fully_connected_float_4d_simple.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/mean.mod.py b/tests/nnapi/specs/V1_1/mean.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/mean_4D_float_reducing_C_nnfw.mod.py b/tests/nnapi/specs/V1_1/mean_4D_float_reducing_C_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/mean_4D_float_reducing_HW_nnfw.mod.py b/tests/nnapi/specs/V1_1/mean_4D_float_reducing_HW_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/mean_axis01_1_nnfw.mod.py b/tests/nnapi/specs/V1_1/mean_axis01_1_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/mean_axis01_2_nnfw.mod.py b/tests/nnapi/specs/V1_1/mean_axis01_2_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/mean_float_1.mod.py b/tests/nnapi/specs/V1_1/mean_float_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/mean_float_2.mod.py b/tests/nnapi/specs/V1_1/mean_float_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/mean_quant8_1.mod.py b/tests/nnapi/specs/V1_1/mean_quant8_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/mean_quant8_2.mod.py b/tests/nnapi/specs/V1_1/mean_quant8_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/pad.mod.py b/tests/nnapi/specs/V1_1/pad.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/pad_2D_HW_nnfw.mod.py b/tests/nnapi/specs/V1_1/pad_2D_HW_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/pad_3D_HWC_nnfw.mod.py b/tests/nnapi/specs/V1_1/pad_3D_HWC_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/pad_BHWC_nnfw.mod.py b/tests/nnapi/specs/V1_1/pad_BHWC_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/pad_BHW_nnfw.mod.py b/tests/nnapi/specs/V1_1/pad_BHW_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/pad_HWD_nnfw.mod.py b/tests/nnapi/specs/V1_1/pad_HWD_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/pad_float_1.mod.py b/tests/nnapi/specs/V1_1/pad_float_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/pad_quant8_nnfw.mod.py b/tests/nnapi/specs/V1_1/pad_quant8_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/space_to_batch.mod.py b/tests/nnapi/specs/V1_1/space_to_batch.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/space_to_batch_float_1.mod.py b/tests/nnapi/specs/V1_1/space_to_batch_float_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/space_to_batch_float_1_nnfw.mod.py b/tests/nnapi/specs/V1_1/space_to_batch_float_1_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/space_to_batch_float_2.mod.py b/tests/nnapi/specs/V1_1/space_to_batch_float_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/space_to_batch_float_3.mod.py b/tests/nnapi/specs/V1_1/space_to_batch_float_3.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/space_to_batch_quant8_1.mod.py b/tests/nnapi/specs/V1_1/space_to_batch_quant8_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/space_to_batch_quant8_1_nnfw.mod.py b/tests/nnapi/specs/V1_1/space_to_batch_quant8_1_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/space_to_batch_quant8_2.mod.py b/tests/nnapi/specs/V1_1/space_to_batch_quant8_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/space_to_batch_quant8_2_nnfw.mod.py b/tests/nnapi/specs/V1_1/space_to_batch_quant8_2_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/space_to_batch_quant8_3.mod.py b/tests/nnapi/specs/V1_1/space_to_batch_quant8_3.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/squeeze.mod.py b/tests/nnapi/specs/V1_1/squeeze.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/squeeze_2D_float_1_nnfw.mod.py b/tests/nnapi/specs/V1_1/squeeze_2D_float_1_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/squeeze_float_1.mod.py b/tests/nnapi/specs/V1_1/squeeze_float_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/squeeze_quant8_1.mod.py b/tests/nnapi/specs/V1_1/squeeze_quant8_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/strided_slice.mod.py b/tests/nnapi/specs/V1_1/strided_slice.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/strided_slice_float_1.mod.py b/tests/nnapi/specs/V1_1/strided_slice_float_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/strided_slice_float_10.mod.py b/tests/nnapi/specs/V1_1/strided_slice_float_10.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/strided_slice_float_11.mod.py b/tests/nnapi/specs/V1_1/strided_slice_float_11.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/strided_slice_float_2.mod.py b/tests/nnapi/specs/V1_1/strided_slice_float_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/strided_slice_float_3.mod.py b/tests/nnapi/specs/V1_1/strided_slice_float_3.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/strided_slice_float_4.mod.py b/tests/nnapi/specs/V1_1/strided_slice_float_4.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/strided_slice_float_5.mod.py b/tests/nnapi/specs/V1_1/strided_slice_float_5.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/strided_slice_float_6.mod.py b/tests/nnapi/specs/V1_1/strided_slice_float_6.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/strided_slice_float_7.mod.py b/tests/nnapi/specs/V1_1/strided_slice_float_7.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/strided_slice_float_8.mod.py b/tests/nnapi/specs/V1_1/strided_slice_float_8.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/strided_slice_float_9.mod.py b/tests/nnapi/specs/V1_1/strided_slice_float_9.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/strided_slice_qaunt8_10.mod.py b/tests/nnapi/specs/V1_1/strided_slice_qaunt8_10.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/strided_slice_qaunt8_11.mod.py b/tests/nnapi/specs/V1_1/strided_slice_qaunt8_11.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/strided_slice_quant8_1.mod.py b/tests/nnapi/specs/V1_1/strided_slice_quant8_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/strided_slice_quant8_2.mod.py b/tests/nnapi/specs/V1_1/strided_slice_quant8_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/strided_slice_quant8_3.mod.py b/tests/nnapi/specs/V1_1/strided_slice_quant8_3.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/strided_slice_quant8_4.mod.py b/tests/nnapi/specs/V1_1/strided_slice_quant8_4.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/strided_slice_quant8_5.mod.py b/tests/nnapi/specs/V1_1/strided_slice_quant8_5.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/strided_slice_quant8_6.mod.py b/tests/nnapi/specs/V1_1/strided_slice_quant8_6.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/strided_slice_quant8_7.mod.py b/tests/nnapi/specs/V1_1/strided_slice_quant8_7.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/strided_slice_quant8_8.mod.py b/tests/nnapi/specs/V1_1/strided_slice_quant8_8.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/strided_slice_quant8_9.mod.py b/tests/nnapi/specs/V1_1/strided_slice_quant8_9.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/sub.mod.py b/tests/nnapi/specs/V1_1/sub.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/sub_broadcast_4D_2D_float_nnfw.mod.py b/tests/nnapi/specs/V1_1/sub_broadcast_4D_2D_float_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/sub_broadcast_float.mod.py b/tests/nnapi/specs/V1_1/sub_broadcast_float.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/transpose.mod.py b/tests/nnapi/specs/V1_1/transpose.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/transpose_2D_nnfw.mod.py b/tests/nnapi/specs/V1_1/transpose_2D_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/transpose_3D_nnfw.mod.py b/tests/nnapi/specs/V1_1/transpose_3D_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/transpose_float_1.mod.py b/tests/nnapi/specs/V1_1/transpose_float_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_1/transpose_quant8_1.mod.py b/tests/nnapi/specs/V1_1/transpose_quant8_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/abs_.mod.py b/tests/nnapi/specs/V1_2/abs_.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/abs_1D_float_nnfw.mod.py b/tests/nnapi/specs/V1_2/abs_1D_float_nnfw.mod.py new file mode 100755 index 00000000000..6366f6e049c --- /dev/null +++ b/tests/nnapi/specs/V1_2/abs_1D_float_nnfw.mod.py @@ -0,0 +1,20 @@ +# model +model = Model() + +i1 = Input("input", "TENSOR_FLOAT32", "{10}") +i2 = Output("output", "TENSOR_FLOAT32", "{10}") +model = model.Operation("ABS", i1).To(i2) + +# Example 1. Input in operand 0, +input0 = {i1: # input 0 + [0.778, -0.48, -241, 0.9118, -0.466, + -30.29, -0.4951, -0.4460, 0.555, + 0.11310]} + +output0 = {i2: # output 0 + [0.778, 0.48, 241, 0.9118, 0.466, + 30.29, 0.4951, 0.4460, 0.555, + 0.11310]} + +# Instantiate an example +Example((input0, output0)) diff --git a/tests/nnapi/specs/V1_2/abs_2D_float_nnfw.mod.py b/tests/nnapi/specs/V1_2/abs_2D_float_nnfw.mod.py new file mode 100755 index 00000000000..901127b8da0 --- /dev/null +++ b/tests/nnapi/specs/V1_2/abs_2D_float_nnfw.mod.py @@ -0,0 +1,20 @@ +# model +model = Model() + +i1 = Input("input", "TENSOR_FLOAT32", "{5, 2}") +i2 = Output("output", "TENSOR_FLOAT32", "{5, 2}") +model = model.Operation("ABS", i1).To(i2) + +# Example 1. Input in operand 0, +input0 = {i1: # input 0 + [0.735078, -0.46738, -241, 0.9118, -0.46686, + -3150.219, -0.495291, -0.42874460, 0.5005046655, + 0.1131106620]} + +output0 = {i2: # output 0 + [0.735078, 0.46738, 241, 0.9118, 0.46686, + 3150.219, 0.495291, 0.42874460, 0.5005046655, + 0.1131106620]} + +# Instantiate an example +Example((input0, output0)) diff --git a/tests/nnapi/specs/V1_2/abs_3D_float_nnfw.mod.py b/tests/nnapi/specs/V1_2/abs_3D_float_nnfw.mod.py new file mode 100755 index 00000000000..b5ab3948246 --- /dev/null +++ b/tests/nnapi/specs/V1_2/abs_3D_float_nnfw.mod.py @@ -0,0 +1,20 @@ +# model +model = Model() + +i1 = Input("input", "TENSOR_FLOAT32", "{2, 3, 2}") +i2 = Output("output", "TENSOR_FLOAT32", "{2, 3, 2}") +model = model.Operation("ABS", i1).To(i2) + +# Example 1. Input in operand 0, +input0 = {i1: # input 0 + [0.735078, -0.46738, -241, 0.9118, -0.46686, + -3150.219, -0.495291, -0.42874460, 0.5005046655, + 0.1131106620, -40.0, 15.0]} + +output0 = {i2: # output 0 + [0.735078, 0.46738, 241, 0.9118, 0.46686, + 3150.219, 0.495291, 0.42874460, 0.5005046655, + 0.1131106620, 40.0, 15.0]} + +# Instantiate an example +Example((input0, output0)) diff --git a/tests/nnapi/specs/V1_2/abs_4D_float_nnfw.mod.py b/tests/nnapi/specs/V1_2/abs_4D_float_nnfw.mod.py new file mode 100755 index 00000000000..b7e749f5dde --- /dev/null +++ b/tests/nnapi/specs/V1_2/abs_4D_float_nnfw.mod.py @@ -0,0 +1,18 @@ +# model +model = Model() + +i1 = Input("input", "TENSOR_FLOAT32", "{2, 2, 2, 2}") +i2 = Output("output", "TENSOR_FLOAT32", "{2, 2, 2, 2}") +model = model.Operation("ABS", i1).To(i2) + +# Example 1. Input in operand 0, +input0 = {i1: # input 0 + [1.0, 1.99, -1.4, 0.0001, 0.0002, 16.0, 25.0, 100.0, + 23.0, 19.0, -40.0, 15.0, 4.0, -43.0, -0.35355339059, 0.35355339059]} + +output0 = {i2: # output 0 + [1.0, 1.99, 1.4, 0.0001, 0.0002, 16.0, 25.0, 100.0, + 23.0, 19.0, 40.0, 15.0, 4.0, 43.0, 0.35355339059, 0.35355339059]} + +# Instantiate an example +Example((input0, output0)) diff --git a/tests/nnapi/specs/V1_2/argmax_1.mod.py b/tests/nnapi/specs/V1_2/argmax_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/argmax_2.mod.py b/tests/nnapi/specs/V1_2/argmax_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/argmax_3.mod.py b/tests/nnapi/specs/V1_2/argmax_3.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/argmax_float_1_nnfw.mod.py b/tests/nnapi/specs/V1_2/argmax_float_1_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/argmax_float_2_nnfw.mod.py b/tests/nnapi/specs/V1_2/argmax_float_2_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/argmax_int32_nnfw.mod.py b/tests/nnapi/specs/V1_2/argmax_int32_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/argmax_neg_axis_float_nnfw.mod.py b/tests/nnapi/specs/V1_2/argmax_neg_axis_float_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/argmax_neg_axis_int32_nnfw.mod.py b/tests/nnapi/specs/V1_2/argmax_neg_axis_int32_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/argmax_quant8_neg_axis_nnfw.mod.py b/tests/nnapi/specs/V1_2/argmax_quant8_neg_axis_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/argmax_quant8_nnfw.mod.py b/tests/nnapi/specs/V1_2/argmax_quant8_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/cast.mod.py b/tests/nnapi/specs/V1_2/cast.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/cast_float32_to_int32_nnfw.mod.py b/tests/nnapi/specs/V1_2/cast_float32_to_int32_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/cast_int32_to_float32_nnfw.mod.py b/tests/nnapi/specs/V1_2/cast_int32_to_float32_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/equal.mod.py b/tests/nnapi/specs/V1_2/equal.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/equal_1D_float_nnfw.mod.py b/tests/nnapi/specs/V1_2/equal_1D_float_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/equal_4D_float_nnfw.mod.py b/tests/nnapi/specs/V1_2/equal_4D_float_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/equal_broadcast_4D_2D_float_nnfw.mod.py b/tests/nnapi/specs/V1_2/equal_broadcast_4D_2D_float_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/equal_broadcast_float_nnfw.mod.py b/tests/nnapi/specs/V1_2/equal_broadcast_float_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/equal_quant8_nnfw.mod.py b/tests/nnapi/specs/V1_2/equal_quant8_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/exp_.mod.py b/tests/nnapi/specs/V1_2/exp_.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/exp_1D_float_nnfw.mod.py b/tests/nnapi/specs/V1_2/exp_1D_float_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/exp_2D_float_nnfw.mod.py b/tests/nnapi/specs/V1_2/exp_2D_float_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/exp_3D_float_nnfw.mod.py b/tests/nnapi/specs/V1_2/exp_3D_float_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/exp_4D_float_nnfw.mod.py b/tests/nnapi/specs/V1_2/exp_4D_float_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/gather.mod.py b/tests/nnapi/specs/V1_2/gather.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/gather_1D_float_nnfw.mod.py b/tests/nnapi/specs/V1_2/gather_1D_float_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/gather_1D_int32_nnfw.mod.py b/tests/nnapi/specs/V1_2/gather_1D_int32_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/gather_1D_quant8_nnfw.mod.py b/tests/nnapi/specs/V1_2/gather_1D_quant8_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/gather_2D_2D_float_1_nnfw.mod.py b/tests/nnapi/specs/V1_2/gather_2D_2D_float_1_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/gather_2D_2D_float_2_nnfw.mod.py b/tests/nnapi/specs/V1_2/gather_2D_2D_float_2_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/gather_2D_3D_float_1_nnfw.mod.py b/tests/nnapi/specs/V1_2/gather_2D_3D_float_1_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/gather_2D_3D_float_2_nnfw.mod.py b/tests/nnapi/specs/V1_2/gather_2D_3D_float_2_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/gather_2D_float_nnfw.mod.py b/tests/nnapi/specs/V1_2/gather_2D_float_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/gather_2D_int32_nnfw.mod.py b/tests/nnapi/specs/V1_2/gather_2D_int32_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/gather_2D_quant8_nnfw.mod.py b/tests/nnapi/specs/V1_2/gather_2D_quant8_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/gather_3D_2D_float_1_nnfw.mod.py b/tests/nnapi/specs/V1_2/gather_3D_2D_float_1_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/gather_3D_2D_float_2_nnfw.mod.py b/tests/nnapi/specs/V1_2/gather_3D_2D_float_2_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/gather_3D_2D_float_3_nnfw.mod.py b/tests/nnapi/specs/V1_2/gather_3D_2D_float_3_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/gather_4D_float_nnfw.mod.py b/tests/nnapi/specs/V1_2/gather_4D_float_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/gather_higher_rank.mod.py b/tests/nnapi/specs/V1_2/gather_higher_rank.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/greater_equal.mod.py b/tests/nnapi/specs/V1_2/greater_equal.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/greater_equal_nnfw.mod.py b/tests/nnapi/specs/V1_2/greater_equal_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/less.mod.py b/tests/nnapi/specs/V1_2/less.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/less_nnfw.mod.py b/tests/nnapi/specs/V1_2/less_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/logical_and.mod.py b/tests/nnapi/specs/V1_2/logical_and.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/logical_and_1D_nnfw.mod.py b/tests/nnapi/specs/V1_2/logical_and_1D_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/logical_and_2D_nnfw.mod.py b/tests/nnapi/specs/V1_2/logical_and_2D_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/logical_and_3D_nnfw.mod.py b/tests/nnapi/specs/V1_2/logical_and_3D_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/logical_and_4D_nnfw.mod.py b/tests/nnapi/specs/V1_2/logical_and_4D_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/logical_and_broadcast_4D_2D_nnfw.mod.py b/tests/nnapi/specs/V1_2/logical_and_broadcast_4D_2D_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/logical_and_broadcast_nnfw.mod.py b/tests/nnapi/specs/V1_2/logical_and_broadcast_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/logical_not.mod.py b/tests/nnapi/specs/V1_2/logical_not.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/logical_not_1D_nnfw.mod.py b/tests/nnapi/specs/V1_2/logical_not_1D_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/logical_not_4D_nnfw.mod.py b/tests/nnapi/specs/V1_2/logical_not_4D_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/logical_or.mod.py b/tests/nnapi/specs/V1_2/logical_or.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/logical_or_1D_nnfw.mod.py b/tests/nnapi/specs/V1_2/logical_or_1D_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/logical_or_2D_nnfw.mod.py b/tests/nnapi/specs/V1_2/logical_or_2D_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/logical_or_3D_nnfw.mod.py b/tests/nnapi/specs/V1_2/logical_or_3D_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/logical_or_4D_nnfw.mod.py b/tests/nnapi/specs/V1_2/logical_or_4D_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/logical_or_broadcast_4D_2D_nnfw.mod.py b/tests/nnapi/specs/V1_2/logical_or_broadcast_4D_2D_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/logical_or_broadcast_nnfw.mod.py b/tests/nnapi/specs/V1_2/logical_or_broadcast_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/maximum.mod.py b/tests/nnapi/specs/V1_2/maximum.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/minimum.mod.py b/tests/nnapi/specs/V1_2/minimum.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/neg.mod.py b/tests/nnapi/specs/V1_2/neg.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/neg_1D_float_nnfw.mod.py b/tests/nnapi/specs/V1_2/neg_1D_float_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/neg_2D_float_nnfw.mod.py b/tests/nnapi/specs/V1_2/neg_2D_float_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/neg_3D_float_nnfw.mod.py b/tests/nnapi/specs/V1_2/neg_3D_float_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/neg_3D_int_nnfw.mod.py b/tests/nnapi/specs/V1_2/neg_3D_int_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/neg_4D_float_nnfw.mod.py b/tests/nnapi/specs/V1_2/neg_4D_float_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/neg_4D_int_nnfw.mod.py b/tests/nnapi/specs/V1_2/neg_4D_int_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/not_equal.mod.py b/tests/nnapi/specs/V1_2/not_equal.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/not_equal_broadcast_4D_2D_float_nnfw.mod.py b/tests/nnapi/specs/V1_2/not_equal_broadcast_4D_2D_float_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/not_equal_broadcast_float_nnfw.mod.py b/tests/nnapi/specs/V1_2/not_equal_broadcast_float_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/not_equal_float_nnfw.mod.py b/tests/nnapi/specs/V1_2/not_equal_float_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/not_equal_quant8_nnfw.mod.py b/tests/nnapi/specs/V1_2/not_equal_quant8_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/prelu.mod.py b/tests/nnapi/specs/V1_2/prelu.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/prelu_broadcast_float_1_nnfw.mod.py b/tests/nnapi/specs/V1_2/prelu_broadcast_float_1_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/prelu_broadcast_quant8_1_nnfw.mod.py b/tests/nnapi/specs/V1_2/prelu_broadcast_quant8_1_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/prelu_float_1_nnfw.mod.py b/tests/nnapi/specs/V1_2/prelu_float_1_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/prelu_quant8_1_nnfw.mod.py b/tests/nnapi/specs/V1_2/prelu_quant8_1_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/reduce_max.mod.py b/tests/nnapi/specs/V1_2/reduce_max.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/reduce_max_2D_float_nnfw.mod.py b/tests/nnapi/specs/V1_2/reduce_max_2D_float_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/reduce_max_2D_int32_nnfw.mod.py b/tests/nnapi/specs/V1_2/reduce_max_2D_int32_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/reduce_max_4D_float_reducing_C_nnfw.mod.py b/tests/nnapi/specs/V1_2/reduce_max_4D_float_reducing_C_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/reduce_max_4D_float_reducing_HW_nnfw.mod.py b/tests/nnapi/specs/V1_2/reduce_max_4D_float_reducing_HW_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/reduce_max_float_1_nnfw.mod.py b/tests/nnapi/specs/V1_2/reduce_max_float_1_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/reduce_max_float_2_nnfw.mod.py b/tests/nnapi/specs/V1_2/reduce_max_float_2_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/reduce_max_float_nnfw.mod.py b/tests/nnapi/specs/V1_2/reduce_max_float_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/reduce_max_quant8_1_nnfw.mod.py b/tests/nnapi/specs/V1_2/reduce_max_quant8_1_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/reduce_max_quant8_2_nnfw.mod.py b/tests/nnapi/specs/V1_2/reduce_max_quant8_2_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/reduce_min.mod.py b/tests/nnapi/specs/V1_2/reduce_min.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/reduce_min_float_1_nnfw.mod.py b/tests/nnapi/specs/V1_2/reduce_min_float_1_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/reduce_min_float_2_nnfw.mod.py b/tests/nnapi/specs/V1_2/reduce_min_float_2_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/reduce_min_float_nnfw.mod.py b/tests/nnapi/specs/V1_2/reduce_min_float_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/reduce_sum.mod.py b/tests/nnapi/specs/V1_2/reduce_sum.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/reduce_sum_2D_float_nnfw.mod.py b/tests/nnapi/specs/V1_2/reduce_sum_2D_float_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/reduce_sum_4D_float_nnfw.mod.py b/tests/nnapi/specs/V1_2/reduce_sum_4D_float_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/reduce_sum_4D_float_reducing_C_nnfw.mod.py b/tests/nnapi/specs/V1_2/reduce_sum_4D_float_reducing_C_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/reduce_sum_4D_float_reducing_HW_nnfw.mod.py b/tests/nnapi/specs/V1_2/reduce_sum_4D_float_reducing_HW_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/rsqrt.mod.py b/tests/nnapi/specs/V1_2/rsqrt.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/rsqrt_1D_float_nnfw.mod.py b/tests/nnapi/specs/V1_2/rsqrt_1D_float_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/rsqrt_2D_float_nnfw.mod.py b/tests/nnapi/specs/V1_2/rsqrt_2D_float_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/rsqrt_3D_float_nnfw.mod.py b/tests/nnapi/specs/V1_2/rsqrt_3D_float_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/rsqrt_4D_float_nnfw.mod.py b/tests/nnapi/specs/V1_2/rsqrt_4D_float_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/sin_1D_float_nnfw.mod.py b/tests/nnapi/specs/V1_2/sin_1D_float_nnfw.mod.py new file mode 100755 index 00000000000..695ad491a86 --- /dev/null +++ b/tests/nnapi/specs/V1_2/sin_1D_float_nnfw.mod.py @@ -0,0 +1,13 @@ +# model +model = Model() +i1 = Input("op1", "TENSOR_FLOAT32", "{4}") #A vector of inputs +i2 = Output("op2", "TENSOR_FLOAT32", "{4}") #A vector of outputs +model = model.Operation("SIN", i1).To(i2) + +# Example 1. Input in operand 0, +input0 = {i1: # input 0 + [2.0, 90.0, 1.0, 0.012]} +output0 = {i2: # output 0 + [0.909297427, 0.893996664, 0.841470985, 0.011999712]} +# Instantiate an example +Example((input0, output0)) diff --git a/tests/nnapi/specs/V1_2/sin_4D_float_nnfw.mod.py b/tests/nnapi/specs/V1_2/sin_4D_float_nnfw.mod.py new file mode 100755 index 00000000000..87877df4c38 --- /dev/null +++ b/tests/nnapi/specs/V1_2/sin_4D_float_nnfw.mod.py @@ -0,0 +1,18 @@ +# model +model = Model() + +i1 = Input("op1", "TENSOR_FLOAT32", "{2, 1, 2, 2}") +i3 = Output("op3", "TENSOR_FLOAT32", "{2, 1, 2, 2}") +model = model.Operation("SIN", i1).To(i3) + +# Example 1. Input in operand 0, +input0 = {i1: # input 0 + [12.0, 36.1, 2.0, 90, 1.0, 0.012, 0.001, 5]} + +output0 = {i3: # output 0 + [-0.536572918, -0.999599143, 0.909297427, 0.893996664, + 0.841470985, 0.011999712, 0.001, -0.958924275]} + + +# Instantiate an example +Example((input0, output0)) diff --git a/tests/nnapi/specs/V1_2/slice.mod.py b/tests/nnapi/specs/V1_2/slice.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/split_1D_float_nnfw.mod.py b/tests/nnapi/specs/V1_2/split_1D_float_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/split_1D_int32_nnfw.mod.py b/tests/nnapi/specs/V1_2/split_1D_int32_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/split_4D_float_1_nnfw.mod.py b/tests/nnapi/specs/V1_2/split_4D_float_1_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/split_4D_float_2_nnfw.mod.py b/tests/nnapi/specs/V1_2/split_4D_float_2_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/split_4D_float_3_nnfw.mod.py b/tests/nnapi/specs/V1_2/split_4D_float_3_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/split_4D_int32_1_nnfw.mod.py b/tests/nnapi/specs/V1_2/split_4D_int32_1_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/split_4D_int32_2_nnfw.mod.py b/tests/nnapi/specs/V1_2/split_4D_int32_2_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/split_4D_int32_3_nnfw.mod.py b/tests/nnapi/specs/V1_2/split_4D_int32_3_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/split_4D_int32_4_nnfw.mod.py b/tests/nnapi/specs/V1_2/split_4D_int32_4_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/split_4D_int32_5_nnfw.mod.py b/tests/nnapi/specs/V1_2/split_4D_int32_5_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/split_4D_quant8_nnfw.mod.py b/tests/nnapi/specs/V1_2/split_4D_quant8_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/split_float_1.mod.py b/tests/nnapi/specs/V1_2/split_float_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/split_float_2.mod.py b/tests/nnapi/specs/V1_2/split_float_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/split_float_3.mod.py b/tests/nnapi/specs/V1_2/split_float_3.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/split_float_4.mod.py b/tests/nnapi/specs/V1_2/split_float_4.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/split_float_5.mod.py b/tests/nnapi/specs/V1_2/split_float_5.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/split_int32_1.mod.py b/tests/nnapi/specs/V1_2/split_int32_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/split_int32_2.mod.py b/tests/nnapi/specs/V1_2/split_int32_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/split_int32_3.mod.py b/tests/nnapi/specs/V1_2/split_int32_3.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/split_int32_4.mod.py b/tests/nnapi/specs/V1_2/split_int32_4.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/split_quant8_1.mod.py b/tests/nnapi/specs/V1_2/split_quant8_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/split_quant8_2.mod.py b/tests/nnapi/specs/V1_2/split_quant8_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/split_quant8_3.mod.py b/tests/nnapi/specs/V1_2/split_quant8_3.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/split_quant8_4.mod.py b/tests/nnapi/specs/V1_2/split_quant8_4.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/sqrt_.mod.py b/tests/nnapi/specs/V1_2/sqrt_.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/sqrt_1D_float_nnfw.mod.py b/tests/nnapi/specs/V1_2/sqrt_1D_float_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/sqrt_2D_float_nnfw.mod.py b/tests/nnapi/specs/V1_2/sqrt_2D_float_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/sqrt_3D_float_nnfw.mod.py b/tests/nnapi/specs/V1_2/sqrt_3D_float_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/sqrt_4D_float_nnfw.mod.py b/tests/nnapi/specs/V1_2/sqrt_4D_float_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/sub_v1_2.mod.py b/tests/nnapi/specs/V1_2/sub_v1_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/sub_v1_2_broadcast.mod.py b/tests/nnapi/specs/V1_2/sub_v1_2_broadcast.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/tanh_v1_2.mod.py b/tests/nnapi/specs/V1_2/tanh_v1_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/topk_v2.mod.py b/tests/nnapi/specs/V1_2/topk_v2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/topk_v2_1D_float_nnfw.mod.py b/tests/nnapi/specs/V1_2/topk_v2_1D_float_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/topk_v2_1D_int32_nnfw.mod.py b/tests/nnapi/specs/V1_2/topk_v2_1D_int32_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/topk_v2_1D_quant8_nnfw.mod.py b/tests/nnapi/specs/V1_2/topk_v2_1D_quant8_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/topk_v2_2D_float_nnfw.mod.py b/tests/nnapi/specs/V1_2/topk_v2_2D_float_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/topk_v2_2D_int32_nnfw.mod.py b/tests/nnapi/specs/V1_2/topk_v2_2D_int32_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/topk_v2_2D_quant8_nnfw.mod.py b/tests/nnapi/specs/V1_2/topk_v2_2D_quant8_nnfw.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/V1_2/transpose_v1_2.mod.py b/tests/nnapi/specs/V1_2/transpose_v1_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_0/mobilenet_224_gender_basic_fixed.mod.py b/tests/nnapi/specs/skip/V1_0/mobilenet_224_gender_basic_fixed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_0/mobilenet_quantized.mod.py b/tests/nnapi/specs/skip/V1_0/mobilenet_quantized.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/add_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/add_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/avg_pool_float_1_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/avg_pool_float_1_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/avg_pool_float_2_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/avg_pool_float_2_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/avg_pool_float_3_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/avg_pool_float_3_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/avg_pool_float_4_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/avg_pool_float_4_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/avg_pool_float_5_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/avg_pool_float_5_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/batch_to_space_float_1_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/batch_to_space_float_1_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/batch_to_space_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/batch_to_space_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/concat_float_1_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/concat_float_1_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/concat_float_2_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/concat_float_2_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/concat_float_3_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/concat_float_3_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/conv_1_h3_w2_SAME_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/conv_1_h3_w2_SAME_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/conv_1_h3_w2_VALID_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/conv_1_h3_w2_VALID_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/conv_3_h3_w2_SAME_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/conv_3_h3_w2_SAME_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/conv_3_h3_w2_VALID_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/conv_3_h3_w2_VALID_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/conv_float_2_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/conv_float_2_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/conv_float_channels_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/conv_float_channels_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/conv_float_channels_weights_as_inputs_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/conv_float_channels_weights_as_inputs_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/conv_float_large_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/conv_float_large_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/conv_float_large_weights_as_inputs_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/conv_float_large_weights_as_inputs_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/conv_float_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/conv_float_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/conv_float_weights_as_inputs_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/conv_float_weights_as_inputs_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/depth_to_space_float_1_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/depth_to_space_float_1_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/depth_to_space_float_2_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/depth_to_space_float_2_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/depth_to_space_float_3_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/depth_to_space_float_3_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/depthwise_conv2d_float_2_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/depthwise_conv2d_float_2_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/depthwise_conv2d_float_large_2_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/depthwise_conv2d_float_large_2_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/depthwise_conv2d_float_large_2_weights_as_inputs_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/depthwise_conv2d_float_large_2_weights_as_inputs_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/depthwise_conv2d_float_large_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/depthwise_conv2d_float_large_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/depthwise_conv2d_float_large_weights_as_inputs_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/depthwise_conv2d_float_large_weights_as_inputs_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/depthwise_conv2d_float_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/depthwise_conv2d_float_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/depthwise_conv2d_float_weights_as_inputs_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/depthwise_conv2d_float_weights_as_inputs_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/depthwise_conv_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/depthwise_conv_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/dequantize_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/dequantize_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/div_broadcast_float_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/div_broadcast_float_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/div_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/div_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/embedding_lookup_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/embedding_lookup_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/floor_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/floor_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/fully_connected_float_2_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/fully_connected_float_2_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/fully_connected_float_4d_simple_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/fully_connected_float_4d_simple_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/fully_connected_float_large_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/fully_connected_float_large_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/fully_connected_float_large_weights_as_inputs_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/fully_connected_float_large_weights_as_inputs_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/fully_connected_float_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/fully_connected_float_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/fully_connected_float_weights_as_inputs_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/fully_connected_float_weights_as_inputs_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/hashtable_lookup_float_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/hashtable_lookup_float_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/l2_normalization_2_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/l2_normalization_2_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/l2_normalization_large_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/l2_normalization_large_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/l2_normalization_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/l2_normalization_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/l2_pool_float_2_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/l2_pool_float_2_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/l2_pool_float_large_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/l2_pool_float_large_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/l2_pool_float_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/l2_pool_float_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/local_response_norm_float_1_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/local_response_norm_float_1_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/local_response_norm_float_2_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/local_response_norm_float_2_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/local_response_norm_float_3_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/local_response_norm_float_3_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/local_response_norm_float_4_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/local_response_norm_float_4_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/logistic_float_1_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/logistic_float_1_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/logistic_float_2_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/logistic_float_2_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/lsh_projection_2_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/lsh_projection_2_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/lsh_projection_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/lsh_projection_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/lsh_projection_weights_as_inputs_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/lsh_projection_weights_as_inputs_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/lstm2_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/lstm2_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/lstm2_state2_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/lstm2_state2_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/lstm2_state_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/lstm2_state_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/lstm3_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/lstm3_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/lstm3_state2_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/lstm3_state2_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/lstm3_state3_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/lstm3_state3_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/lstm3_state_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/lstm3_state_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/lstm_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/lstm_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/lstm_state2_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/lstm_state2_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/lstm_state_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/lstm_state_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/max_pool_float_1_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/max_pool_float_1_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/max_pool_float_2_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/max_pool_float_2_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/max_pool_float_3_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/max_pool_float_3_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/max_pool_float_4_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/max_pool_float_4_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/mean_float_1_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/mean_float_1_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/mean_float_2_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/mean_float_2_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/mean_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/mean_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/mobilenet_224_gender_basic_fixed_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/mobilenet_224_gender_basic_fixed_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/mul_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/mul_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/mul_relu_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/mul_relu_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/pad_float_1_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/pad_float_1_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/pad_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/pad_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/relu1_float_1_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/relu1_float_1_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/relu1_float_2_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/relu1_float_2_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/relu6_float_1_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/relu6_float_1_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/relu6_float_2_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/relu6_float_2_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/relu_float_1_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/relu_float_1_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/relu_float_2_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/relu_float_2_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/reshape_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/reshape_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/reshape_weights_as_inputs_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/reshape_weights_as_inputs_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/resize_bilinear_2_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/resize_bilinear_2_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/resize_bilinear_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/resize_bilinear_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/rnn_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/rnn_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/rnn_state_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/rnn_state_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/softmax_float_1_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/softmax_float_1_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/softmax_float_2_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/softmax_float_2_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/space_to_batch_float_1_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/space_to_batch_float_1_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/space_to_batch_float_2_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/space_to_batch_float_2_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/space_to_batch_float_3_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/space_to_batch_float_3_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/space_to_batch_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/space_to_batch_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/space_to_depth_float_1_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/space_to_depth_float_1_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/space_to_depth_float_2_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/space_to_depth_float_2_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/space_to_depth_float_3_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/space_to_depth_float_3_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/squeeze_float_1_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/squeeze_float_1_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/squeeze_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/squeeze_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/strided_slice_float_10_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/strided_slice_float_10_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/strided_slice_float_11_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/strided_slice_float_11_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/strided_slice_float_1_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/strided_slice_float_1_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/strided_slice_float_2_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/strided_slice_float_2_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/strided_slice_float_3_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/strided_slice_float_3_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/strided_slice_float_4_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/strided_slice_float_4_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/strided_slice_float_5_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/strided_slice_float_5_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/strided_slice_float_6_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/strided_slice_float_6_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/strided_slice_float_7_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/strided_slice_float_7_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/strided_slice_float_8_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/strided_slice_float_8_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/strided_slice_float_9_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/strided_slice_float_9_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/strided_slice_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/strided_slice_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/sub_broadcast_float_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/sub_broadcast_float_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/sub_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/sub_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/svdf2_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/svdf2_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/svdf_bias_present_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/svdf_bias_present_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/svdf_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/svdf_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/svdf_state_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/svdf_state_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/tanh_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/tanh_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/transpose_float_1_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/transpose_float_1_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_1/transpose_relaxed.mod.py b/tests/nnapi/specs/skip/V1_1/transpose_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/add_v1_2.mod.py b/tests/nnapi/specs/skip/V1_2/add_v1_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/argmin_1.mod.py b/tests/nnapi/specs/skip/V1_2/argmin_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/argmin_2.mod.py b/tests/nnapi/specs/skip/V1_2/argmin_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/argmin_3.mod.py b/tests/nnapi/specs/skip/V1_2/argmin_3.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/avg_pool_v1_2.mod.py b/tests/nnapi/specs/skip/V1_2/avg_pool_v1_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/axis_aligned_bbox_transform.mod.py b/tests/nnapi/specs/skip/V1_2/axis_aligned_bbox_transform.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/batch_to_space_v1_2.mod.py b/tests/nnapi/specs/skip/V1_2/batch_to_space_v1_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/bbox_graph.mod.py b/tests/nnapi/specs/skip/V1_2/bbox_graph.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/bidirectional_sequence_lstm.mod.py b/tests/nnapi/specs/skip/V1_2/bidirectional_sequence_lstm.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/bidirectional_sequence_lstm_aux_input.mod.py b/tests/nnapi/specs/skip/V1_2/bidirectional_sequence_lstm_aux_input.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/bidirectional_sequence_lstm_cifg_peephole.mod.py b/tests/nnapi/specs/skip/V1_2/bidirectional_sequence_lstm_cifg_peephole.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/bidirectional_sequence_lstm_float16_batch_major.mod.py b/tests/nnapi/specs/skip/V1_2/bidirectional_sequence_lstm_float16_batch_major.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/bidirectional_sequence_lstm_float16_batch_major_aux_input.mod.py b/tests/nnapi/specs/skip/V1_2/bidirectional_sequence_lstm_float16_batch_major_aux_input.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/bidirectional_sequence_lstm_float16_batch_major_merge_outputs.mod.py b/tests/nnapi/specs/skip/V1_2/bidirectional_sequence_lstm_float16_batch_major_merge_outputs.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/bidirectional_sequence_lstm_merge_outputs.mod.py b/tests/nnapi/specs/skip/V1_2/bidirectional_sequence_lstm_merge_outputs.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/bidirectional_sequence_lstm_norm_fw_output.mod.py b/tests/nnapi/specs/skip/V1_2/bidirectional_sequence_lstm_norm_fw_output.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/bidirectional_sequence_rnn.mod.py b/tests/nnapi/specs/skip/V1_2/bidirectional_sequence_rnn.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/box_with_nms_limit_gaussian.mod.py b/tests/nnapi/specs/skip/V1_2/box_with_nms_limit_gaussian.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/box_with_nms_limit_hard.mod.py b/tests/nnapi/specs/skip/V1_2/box_with_nms_limit_hard.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/box_with_nms_limit_linear.mod.py b/tests/nnapi/specs/skip/V1_2/box_with_nms_limit_linear.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/channel_shuffle.mod.py b/tests/nnapi/specs/skip/V1_2/channel_shuffle.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/concat_float16_1.mod.py b/tests/nnapi/specs/skip/V1_2/concat_float16_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/concat_float16_2.mod.py b/tests/nnapi/specs/skip/V1_2/concat_float16_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/concat_float16_3.mod.py b/tests/nnapi/specs/skip/V1_2/concat_float16_3.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/concat_mixed_quant.mod.py b/tests/nnapi/specs/skip/V1_2/concat_mixed_quant.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/concat_zero_sized.mod.py b/tests/nnapi/specs/skip/V1_2/concat_zero_sized.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/conv2d_dilation.mod.py b/tests/nnapi/specs/skip/V1_2/conv2d_dilation.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/conv2d_per_channel.mod.py b/tests/nnapi/specs/skip/V1_2/conv2d_per_channel.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/conv2d_v1_2.mod.py b/tests/nnapi/specs/skip/V1_2/conv2d_v1_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/depth_to_space_v1_2.mod.py b/tests/nnapi/specs/skip/V1_2/depth_to_space_v1_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/depthwise_conv2d_dilation.mod.py b/tests/nnapi/specs/skip/V1_2/depthwise_conv2d_dilation.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/depthwise_conv2d_per_channel.mod.py b/tests/nnapi/specs/skip/V1_2/depthwise_conv2d_per_channel.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/depthwise_conv2d_v1_2.mod.py b/tests/nnapi/specs/skip/V1_2/depthwise_conv2d_v1_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/dequantize_v1_2.mod.py b/tests/nnapi/specs/skip/V1_2/dequantize_v1_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/detection_postprocess.mod.py b/tests/nnapi/specs/skip/V1_2/detection_postprocess.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/div_v1_2.mod.py b/tests/nnapi/specs/skip/V1_2/div_v1_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/expand_dims.mod.py b/tests/nnapi/specs/skip/V1_2/expand_dims.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/floor_float16.mod.py b/tests/nnapi/specs/skip/V1_2/floor_float16.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/fully_connected_v1_2.mod.py b/tests/nnapi/specs/skip/V1_2/fully_connected_v1_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/generate_proposals.mod.py b/tests/nnapi/specs/skip/V1_2/generate_proposals.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/greater.mod.py b/tests/nnapi/specs/skip/V1_2/greater.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/grouped_conv2d.mod.py b/tests/nnapi/specs/skip/V1_2/grouped_conv2d.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/heatmap_max_keypoint.mod.py b/tests/nnapi/specs/skip/V1_2/heatmap_max_keypoint.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/instance_normalization.mod.py b/tests/nnapi/specs/skip/V1_2/instance_normalization.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/l2_normalization_axis.mod.py b/tests/nnapi/specs/skip/V1_2/l2_normalization_axis.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/l2_normalization_v1_2.mod.py b/tests/nnapi/specs/skip/V1_2/l2_normalization_v1_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/l2_pool_v1_2.mod.py b/tests/nnapi/specs/skip/V1_2/l2_pool_v1_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/layer_norm_lstm.mod.py b/tests/nnapi/specs/skip/V1_2/layer_norm_lstm.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/less_equal.mod.py b/tests/nnapi/specs/skip/V1_2/less_equal.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/local_response_normalization_v1_2.mod.py b/tests/nnapi/specs/skip/V1_2/local_response_normalization_v1_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/log.mod.py b/tests/nnapi/specs/skip/V1_2/log.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/log_softmax.mod.py b/tests/nnapi/specs/skip/V1_2/log_softmax.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/logistic_v1_2.mod.py b/tests/nnapi/specs/skip/V1_2/logistic_v1_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/lsh_projection_3_relaxed.mod.py b/tests/nnapi/specs/skip/V1_2/lsh_projection_3_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/lsh_projection_4_relaxed.mod.py b/tests/nnapi/specs/skip/V1_2/lsh_projection_4_relaxed.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/lsh_projection_deprecated.mod.py b/tests/nnapi/specs/skip/V1_2/lsh_projection_deprecated.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/lsh_projection_float16.mod.py b/tests/nnapi/specs/skip/V1_2/lsh_projection_float16.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/lstm2_float16.mod.py b/tests/nnapi/specs/skip/V1_2/lstm2_float16.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/lstm2_state2_float16.mod.py b/tests/nnapi/specs/skip/V1_2/lstm2_state2_float16.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/lstm2_state_float16.mod.py b/tests/nnapi/specs/skip/V1_2/lstm2_state_float16.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/lstm3_float16.mod.py b/tests/nnapi/specs/skip/V1_2/lstm3_float16.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/lstm3_state2_float16.mod.py b/tests/nnapi/specs/skip/V1_2/lstm3_state2_float16.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/lstm3_state3_float16.mod.py b/tests/nnapi/specs/skip/V1_2/lstm3_state3_float16.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/lstm3_state_float16.mod.py b/tests/nnapi/specs/skip/V1_2/lstm3_state_float16.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/lstm_float16.mod.py b/tests/nnapi/specs/skip/V1_2/lstm_float16.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/lstm_state2_float16.mod.py b/tests/nnapi/specs/skip/V1_2/lstm_state2_float16.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/lstm_state_float16.mod.py b/tests/nnapi/specs/skip/V1_2/lstm_state_float16.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/max_pool_v1_2.mod.py b/tests/nnapi/specs/skip/V1_2/max_pool_v1_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/mean_float16.mod.py b/tests/nnapi/specs/skip/V1_2/mean_float16.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/mul_v1_2.mod.py b/tests/nnapi/specs/skip/V1_2/mul_v1_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/pad_all_dims.mod.py b/tests/nnapi/specs/skip/V1_2/pad_all_dims.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/pad_float16.mod.py b/tests/nnapi/specs/skip/V1_2/pad_float16.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/pad_low_rank.mod.py b/tests/nnapi/specs/skip/V1_2/pad_low_rank.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/pad_low_rank_quant8.mod.py b/tests/nnapi/specs/skip/V1_2/pad_low_rank_quant8.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/pad_quant8.mod.py b/tests/nnapi/specs/skip/V1_2/pad_quant8.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/pad_quant8_nonzero.mod.py b/tests/nnapi/specs/skip/V1_2/pad_quant8_nonzero.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/pad_v2_1_float.mod.py b/tests/nnapi/specs/skip/V1_2/pad_v2_1_float.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/pad_v2_1_quant8.mod.py b/tests/nnapi/specs/skip/V1_2/pad_v2_1_quant8.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/pad_v2_all_dims.mod.py b/tests/nnapi/specs/skip/V1_2/pad_v2_all_dims.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/pad_v2_all_dims_quant8.mod.py b/tests/nnapi/specs/skip/V1_2/pad_v2_all_dims_quant8.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/pad_v2_low_rank.mod.py b/tests/nnapi/specs/skip/V1_2/pad_v2_low_rank.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/pad_v2_low_rank_quant8.mod.py b/tests/nnapi/specs/skip/V1_2/pad_v2_low_rank_quant8.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/pow.mod.py b/tests/nnapi/specs/skip/V1_2/pow.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/quantize.mod.py b/tests/nnapi/specs/skip/V1_2/quantize.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/quantized_lstm.mod.py b/tests/nnapi/specs/skip/V1_2/quantized_lstm.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/random_multinomial.mod.py b/tests/nnapi/specs/skip/V1_2/random_multinomial.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/random_multinomial_float16.mod.py b/tests/nnapi/specs/skip/V1_2/random_multinomial_float16.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/reduce_all.mod.py b/tests/nnapi/specs/skip/V1_2/reduce_all.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/reduce_any.mod.py b/tests/nnapi/specs/skip/V1_2/reduce_any.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/reduce_prod.mod.py b/tests/nnapi/specs/skip/V1_2/reduce_prod.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/relu1_v1_2.mod.py b/tests/nnapi/specs/skip/V1_2/relu1_v1_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/relu6_v1_2.mod.py b/tests/nnapi/specs/skip/V1_2/relu6_v1_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/relu_v1_2.mod.py b/tests/nnapi/specs/skip/V1_2/relu_v1_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/reshape_float16.mod.py b/tests/nnapi/specs/skip/V1_2/reshape_float16.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/resize_bilinear_v1_2.mod.py b/tests/nnapi/specs/skip/V1_2/resize_bilinear_v1_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/resize_nearest_neighbor.mod.py b/tests/nnapi/specs/skip/V1_2/resize_nearest_neighbor.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/rnn_float16.mod.py b/tests/nnapi/specs/skip/V1_2/rnn_float16.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/roi_align.mod.py b/tests/nnapi/specs/skip/V1_2/roi_align.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/roi_pooling.mod.py b/tests/nnapi/specs/skip/V1_2/roi_pooling.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/select_v1_2.mod.py b/tests/nnapi/specs/skip/V1_2/select_v1_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/sin.mod.py b/tests/nnapi/specs/skip/V1_2/sin.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/softmax_v1_2.mod.py b/tests/nnapi/specs/skip/V1_2/softmax_v1_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/space_to_batch_quant8_nonzero.mod.py b/tests/nnapi/specs/skip/V1_2/space_to_batch_quant8_nonzero.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/space_to_batch_v1_2.mod.py b/tests/nnapi/specs/skip/V1_2/space_to_batch_v1_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/space_to_depth_v1_2.mod.py b/tests/nnapi/specs/skip/V1_2/space_to_depth_v1_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/squeeze_float16.mod.py b/tests/nnapi/specs/skip/V1_2/squeeze_float16.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/strided_slice_float16.mod.py b/tests/nnapi/specs/skip/V1_2/strided_slice_float16.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/sub_quantized_different_scales.mod.py b/tests/nnapi/specs/skip/V1_2/sub_quantized_different_scales.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/svdf_bias_present_float16.mod.py b/tests/nnapi/specs/skip/V1_2/svdf_bias_present_float16.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/svdf_float16.mod.py b/tests/nnapi/specs/skip/V1_2/svdf_float16.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/svdf_state_float16.mod.py b/tests/nnapi/specs/skip/V1_2/svdf_state_float16.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/tile_1.mod.py b/tests/nnapi/specs/skip/V1_2/tile_1.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/tile_2.mod.py b/tests/nnapi/specs/skip/V1_2/tile_2.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/tile_3.mod.py b/tests/nnapi/specs/skip/V1_2/tile_3.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/transpose_conv2d.mod.py b/tests/nnapi/specs/skip/V1_2/transpose_conv2d.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/transpose_conv2d_large.mod.py b/tests/nnapi/specs/skip/V1_2/transpose_conv2d_large.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/transpose_float16.mod.py b/tests/nnapi/specs/skip/V1_2/transpose_float16.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/unidirectional_sequence_lstm_1step.mod.py b/tests/nnapi/specs/skip/V1_2/unidirectional_sequence_lstm_1step.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/unidirectional_sequence_lstm_batch_major_norm_peephole_projection.mod.py b/tests/nnapi/specs/skip/V1_2/unidirectional_sequence_lstm_batch_major_norm_peephole_projection.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/unidirectional_sequence_lstm_batch_major_peephole_projection_bias.mod.py b/tests/nnapi/specs/skip/V1_2/unidirectional_sequence_lstm_batch_major_peephole_projection_bias.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/unidirectional_sequence_lstm_cifg_peephole.mod.py b/tests/nnapi/specs/skip/V1_2/unidirectional_sequence_lstm_cifg_peephole.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/unidirectional_sequence_lstm_f16_batch_major.mod.py b/tests/nnapi/specs/skip/V1_2/unidirectional_sequence_lstm_f16_batch_major.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/unidirectional_sequence_lstm_f16_norm_peephole_projection.mod.py b/tests/nnapi/specs/skip/V1_2/unidirectional_sequence_lstm_f16_norm_peephole_projection.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/unidirectional_sequence_lstm_layer_norm_cifg_peephole.mod.py b/tests/nnapi/specs/skip/V1_2/unidirectional_sequence_lstm_layer_norm_cifg_peephole.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/unidirectional_sequence_lstm_norm_peephole_projection.mod.py b/tests/nnapi/specs/skip/V1_2/unidirectional_sequence_lstm_norm_peephole_projection.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/specs/skip/V1_2/unidirectional_sequence_rnn.mod.py b/tests/nnapi/specs/skip/V1_2/unidirectional_sequence_rnn.mod.py old mode 100644 new mode 100755 diff --git a/tests/nnapi/src/TestGenerated.cpp b/tests/nnapi/src/TestGenerated.cpp index a4148cf87d5..234735354f1 100644 --- a/tests/nnapi/src/TestGenerated.cpp +++ b/tests/nnapi/src/TestGenerated.cpp @@ -59,25 +59,23 @@ void print(std::ostream& os, const std::map>& test) { } // Specialized for _Float16 because it requires explicit conversion. -// Fix for neurun: comment out -//template <> -//void print<_Float16>(std::ostream& os, const std::map>& test) { -// for_each<_Float16>(test, [&os](int idx, const std::vector<_Float16>& f) { -// os << " aliased_output" << idx << ": ["; -// for (size_t i = 0; i < f.size(); ++i) { -// os << (i == 0 ? "" : ", ") << +static_cast(f[i]); -// } -// os << "],\n"; -// }); -//} +template <> +void print<_Float16>(std::ostream& os, const std::map>& test) { + for_each<_Float16>(test, [&os](int idx, const std::vector<_Float16>& f) { + os << " aliased_output" << idx << ": ["; + for (size_t i = 0; i < f.size(); ++i) { + os << (i == 0 ? "" : ", ") << +static_cast(f[i]); + } + os << "],\n"; + }); +} void printAll(std::ostream& os, const MixedTyped& test) { print(os, test.float32Operands); print(os, test.int32Operands); print(os, test.quant8AsymmOperands); print(os, test.quant16SymmOperands); - // Fix for neurun: comment out - //print(os, test.float16Operands); + print(os, test.float16Operands); print(os, test.bool8Operands); print(os, test.quant8ChannelOperands); print(os, test.quant16AsymmOperands); @@ -244,7 +242,7 @@ void GeneratedTests::execute(std::function createModel, }; mTestCompilationCaching = false; -// Fix for neurun: Not supported feature - copmilation caching +// Fix for onert: Not supported feature - copmilation caching // TODO Enable this #if 0 executeInternal(dumpFile); @@ -257,7 +255,7 @@ void GeneratedTests::SetUp() { #ifdef NNTEST_COMPUTE_MODE mOldComputeMode = Execution::setComputeMode(GetParam()); #endif - // Fix for neurun: Fix file path for linux + // Fix for onert: Fix file path for linux char cacheDirTemp[] = "/tmp/TestCompilationCachingXXXXXX"; //char cacheDirTemp[] = "/data/local/tmp/TestCompilationCachingXXXXXX"; char* cacheDir = mkdtemp(cacheDirTemp); diff --git a/tests/nnapi/src/TestMain.cpp b/tests/nnapi/src/TestMain.cpp index 317f2f3f9eb..725d77c1c18 100644 --- a/tests/nnapi/src/TestMain.cpp +++ b/tests/nnapi/src/TestMain.cpp @@ -22,7 +22,7 @@ #include "Utils.h" #endif -// FIX for neurun: comment out include android-base/logging.h +// FIX for onert: comment out include android-base/logging.h //#include #include #include @@ -77,7 +77,7 @@ static int test(bool useCpuOnly, Execution::ComputeMode computeMode, bool allowS return ""; }; - // FIX for neurun: comment out android logging + // FIX for onert: comment out android logging //LOG(INFO) << "test(useCpuOnly = " << useCpuOnly << ", computeMode = " << computeModeText() // << ", allowSyncExecHal = " << allowSyncExecHal << ") // pass " << passIndex; std::cout << "[**********] useCpuOnly = " << useCpuOnly @@ -86,7 +86,7 @@ static int test(bool useCpuOnly, Execution::ComputeMode computeMode, bool allowS << std::endl; if (!((uint64_t(1) << passIndex) & allowedPasses)) { - // FIX for neurun: comment out android logging + // FIX for onert: comment out android logging //LOG(INFO) << "SKIPPED PASS"; std::cout << "SKIPPED PASS" << std::endl; return 0; @@ -134,7 +134,7 @@ int main(int argc, char** argv) { // The burst path is off by default in these tests. This is the first case // where it is turned on. Both "useCpuOnly" and "allowSyncExecHal" are // irrelevant here because the burst path is separate from both. - // Fix for neurun: disable burst mode + // Fix for onert: disable burst mode //n |= test(/*useCpuOnly=*/false, Execution::ComputeMode::BURST); return n; diff --git a/tests/nnapi/src/TestNeuralNetworksWrapper.h b/tests/nnapi/src/TestNeuralNetworksWrapper.h index 693311f451b..022f3fade9a 100644 --- a/tests/nnapi/src/TestNeuralNetworksWrapper.h +++ b/tests/nnapi/src/TestNeuralNetworksWrapper.h @@ -23,12 +23,12 @@ #include "NeuralNetworks.h" #include "NeuralNetworksWrapper.h" -// Fix for neurun: comment out include NeuralNetworksWrapperExtensions.h +// Fix for onert: comment out include NeuralNetworksWrapperExtensions.h //#include "NeuralNetworksWrapperExtensions.h" #include -// Fix for neurun: use boost::optional instead of std::optional -// TODO in neurun: introduce and use internal optional library +// Fix for onert: use boost::optional instead of std::optional +// TODO in onert: introduce and use internal optional library #include #include #include @@ -39,7 +39,7 @@ namespace test_wrapper { using wrapper::Event; using wrapper::ExecutePreference; -// Fix for neurun: comment out ExtensionModel, ExtensionOperandParams and ExtensionOperandType +// Fix for onert: comment out ExtensionModel, ExtensionOperandParams and ExtensionOperandType //using wrapper::ExtensionModel; //using wrapper::ExtensionOperandParams; //using wrapper::ExtensionOperandType; diff --git a/tests/nnapi/src/TestValidation.cpp b/tests/nnapi/src/TestValidation.cpp index 19db43800c1..1a2e146dc80 100644 --- a/tests/nnapi/src/TestValidation.cpp +++ b/tests/nnapi/src/TestValidation.cpp @@ -23,7 +23,7 @@ #include #include #include -// Note: neurun is allow to set activation operand constant only, +// Note: onert is allow to set activation operand constant only, // so we change test to set operand #2 to constant. (ANEURALNETWORKS_FUSED_NONE) // And model's input is changed: [0, 1, 2] -> [0, 1] // This file tests all the validations done by the Neural Networks API. @@ -87,7 +87,7 @@ class ValidationTestIdentify : public ValidationTestModel { ASSERT_EQ(ANeuralNetworksModel_addOperand(mModel, &tensorType), ANEURALNETWORKS_NO_ERROR); ASSERT_EQ(ANeuralNetworksModel_addOperand(mModel, &scalarType), ANEURALNETWORKS_NO_ERROR); ASSERT_EQ(ANeuralNetworksModel_addOperand(mModel, &tensorType), ANEURALNETWORKS_NO_ERROR); - // neurun is allow to set activation operand constant only + // onert is allow to set activation operand constant only int32_t act = ANEURALNETWORKS_FUSED_NONE; ASSERT_EQ(ANeuralNetworksModel_setOperandValue(mModel, 2, &act, sizeof(act)), ANEURALNETWORKS_NO_ERROR); uint32_t inList[3]{0, 1, 2}; @@ -118,7 +118,7 @@ class ValidationTestCompilation : public ValidationTestModel { ASSERT_EQ(ANeuralNetworksModel_addOperand(mModel, &tensorType), ANEURALNETWORKS_NO_ERROR); ASSERT_EQ(ANeuralNetworksModel_addOperand(mModel, &scalarType), ANEURALNETWORKS_NO_ERROR); ASSERT_EQ(ANeuralNetworksModel_addOperand(mModel, &tensorType), ANEURALNETWORKS_NO_ERROR); - // neurun is allow to set activation operand constant only + // onert is allow to set activation operand constant only int32_t act = ANEURALNETWORKS_FUSED_NONE; ASSERT_EQ(ANeuralNetworksModel_setOperandValue(mModel, 2, &act, sizeof(act)), ANEURALNETWORKS_NO_ERROR); uint32_t inList[3]{0, 1, 2}; diff --git a/tests/nnfw_api/CMakeLists.txt b/tests/nnfw_api/CMakeLists.txt index d9ec60bafc4..0bb332dc644 100644 --- a/tests/nnfw_api/CMakeLists.txt +++ b/tests/nnfw_api/CMakeLists.txt @@ -2,10 +2,10 @@ if (NOT BUILD_RUNTIME_NNFW_API_TEST) return() endif(NOT BUILD_RUNTIME_NNFW_API_TEST) -if (NOT BUILD_NEURUN) +if (NOT BUILD_ONERT) message(STATUS "Skip build NNFW API test: no runtime build") return() -endif(NOT BUILD_NEURUN) +endif(NOT BUILD_ONERT) nnfw_find_package(GTest) @@ -24,14 +24,9 @@ target_link_libraries(${RUNTIME_NNFW_API_TEST} ${LIB_PTHREAD} dl) install(TARGETS ${RUNTIME_NNFW_API_TEST} DESTINATION unittest) -#set(SKIPLIST_FILE_NAME ${RUNTIME_NNFW_API_TEST}.skip.${TARGET_PLATFORM}) -#install(FILES ${SKIPLIST_FILE_NAME} -# DESTINATION unittest -# RENAME ${RUNTIME_NNFW_API_TEST}.skip -# OPTIONAL) - -# Install skiplist file for target as backup -#FILE(GLOB SKIPLIST_TARGET ${CMAKE_CURRENT_SOURCE_DIR}/${RUNTIME_NNFW_API_TEST}.skip.${TARGET_PLATFORM}*) -#FILE(GLOB SKIPLIST_NOARCH ${CMAKE_CURRENT_SOURCE_DIR}/${RUNTIME_NNFW_API_TEST}.skip.noarch.*) -#list(APPEND SKIPLIST_ALL_RUNTIME ${SKIPLIST_TARGET} ${SKIPLIST_NOARCH}) -#install(FILES ${SKIPLIST_ALL_RUNTIME} DESTINATION unittest OPTIONAL) +# Install sample models for test +set(RUNTIME_NNFW_API_TEST_MODEL_DIR "${RUNTIME_NNFW_API_TEST}_models") +file(MAKE_DIRECTORY ${RUNTIME_NNFW_API_TEST_MODEL_DIR}) +install(DIRECTORY ../../nnpackage/examples/one_op_in_tflite + DESTINATION unittest/${RUNTIME_NNFW_API_TEST_MODEL_DIR} + OPTIONAL) diff --git a/tests/nnfw_api/src/create_session.cc b/tests/nnfw_api/src/create_session.cc index 8e56276d19c..3d775be060d 100644 --- a/tests/nnfw_api/src/create_session.cc +++ b/tests/nnfw_api/src/create_session.cc @@ -21,4 +21,10 @@ TEST(nnfw_create_session, Test_001) { nnfw_session *session = nullptr; ASSERT_EQ(nnfw_create_session(&session), NNFW_STATUS_NO_ERROR); + ASSERT_EQ(nnfw_close_session(session), NNFW_STATUS_NO_ERROR); +} + +TEST(nnfw_create_session, Negative_001) +{ + ASSERT_EQ(nnfw_create_session(nullptr), NNFW_STATUS_ERROR); } diff --git a/tests/nnfw_api/src/fixtures.h b/tests/nnfw_api/src/fixtures.h new file mode 100644 index 00000000000..d15dac09fc7 --- /dev/null +++ b/tests/nnfw_api/src/fixtures.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2020 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 __NNFW_API_TEST_FIXTURES_H__ +#define __NNFW_API_TEST_FIXTURES_H__ + +#include +#include + +#include "model_path.h" + +class ValidationTest : public ::testing::Test +{ +protected: + void SetUp() override {} +}; + +class ValidationTestSessionCreated : public ValidationTest +{ +protected: + void SetUp() override + { + ValidationTest::SetUp(); + ASSERT_EQ(nnfw_create_session(&_session), NNFW_STATUS_NO_ERROR); + } + + void TearDown() override + { + ASSERT_EQ(nnfw_close_session(_session), NNFW_STATUS_NO_ERROR); + ValidationTest::TearDown(); + } + +protected: + nnfw_session *_session = nullptr; +}; + +class ValidationTestOneOpModelLoaded : public ValidationTestSessionCreated +{ +protected: + void SetUp() override + { + ValidationTestSessionCreated::SetUp(); + ASSERT_EQ(nnfw_load_model_from_file( + _session, ModelPath::get().getModelAbsolutePath(MODEL_ONE_OP_IN_TFLITE).c_str()), + NNFW_STATUS_NO_ERROR); + ASSERT_NE(_session, nullptr); + } + + void TearDown() override { ValidationTestSessionCreated::TearDown(); } +}; + +#endif // __NNFW_API_TEST_FIXTURES_H__ diff --git a/tests/nnfw_api/src/load_model.cc b/tests/nnfw_api/src/load_model.cc new file mode 100644 index 00000000000..77a7a720a72 --- /dev/null +++ b/tests/nnfw_api/src/load_model.cc @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2020 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 "model_path.h" +#include "fixtures.h" + +TEST_F(ValidationTestSessionCreated, load_session_001) +{ + // Existing model must + ASSERT_EQ(nnfw_load_model_from_file( + _session, ModelPath::get().getModelAbsolutePath(MODEL_ONE_OP_IN_TFLITE).c_str()), + NNFW_STATUS_NO_ERROR); +} + +TEST_F(ValidationTestSessionCreated, neg_load_session_001) +{ + ASSERT_EQ(nnfw_load_model_from_file( + _session, ModelPath::get().getModelAbsolutePath("nonexisting_directory").c_str()), + NNFW_STATUS_ERROR); +} diff --git a/tests/nnfw_api/src/main.cc b/tests/nnfw_api/src/main.cc index e7c88a8970d..523faf969c0 100644 --- a/tests/nnfw_api/src/main.cc +++ b/tests/nnfw_api/src/main.cc @@ -14,12 +14,42 @@ * limitations under the License. */ +#include +#include +#include +#include #include +#include "model_path.h" + +/** + * @brief Function to check if test model directories exist before it actually performs the test + * + */ +void checkModels() +{ + std::string absolute_path = ModelPath::get().getModelAbsolutePath(MODEL_ONE_OP_IN_TFLITE); + DIR *dir = opendir(absolute_path.c_str()); + if (!dir) + { + throw std::runtime_error{"Please install the nnpackge for testing: " + absolute_path}; + } + closedir(dir); +} int main(int argc, char **argv) { + ModelPath::get().init(argv[0]); ::testing::InitGoogleTest(&argc, argv); - std::cout << "Execption caught : ClassUniqueToAlwaysTrue" << std::endl; + + try + { + checkModels(); + } + catch (std::runtime_error &e) + { + std::cerr << e.what() << std::endl; + return -1; + } return RUN_ALL_TESTS(); } diff --git a/tests/nnfw_api/src/model_path.cc b/tests/nnfw_api/src/model_path.cc new file mode 100644 index 00000000000..7aa5e497b77 --- /dev/null +++ b/tests/nnfw_api/src/model_path.cc @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2020 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 "model_path.h" + +#include +#include +#include + +const char *MODEL_ONE_OP_IN_TFLITE = "one_op_in_tflite"; + +ModelPath &ModelPath::get() +{ + static ModelPath instance; + return instance; +} + +void ModelPath::init(const char *argv0) +{ + char raw_dir[1024]; + char cwd[1024]; + strncpy(raw_dir, argv0, sizeof(raw_dir) - 1); + dirname(raw_dir); + if (raw_dir[0] == '/') + { + // If it is an absolute path, just use it + _base_path = raw_dir; + } + else + { + // If it is a relative path, prepend CWD + getcwd(cwd, sizeof(cwd)); + _base_path = cwd; + _base_path += "/"; + _base_path += raw_dir; + } +} + +std::string ModelPath::getModelAbsolutePath(const char *model_dir) +{ + return _base_path + "/nnfw_api_gtest_models/" + model_dir; +} diff --git a/tests/nnfw_api/src/model_path.h b/tests/nnfw_api/src/model_path.h new file mode 100644 index 00000000000..adff3c511d7 --- /dev/null +++ b/tests/nnfw_api/src/model_path.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2020 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 __NNFW_API_TEST_MODEL_PATH_H__ +#define __NNFW_API_TEST_MODEL_PATH_H__ + +#include + +extern const char *MODEL_ONE_OP_IN_TFLITE; + +/** + * @brief A helper class to find models for testing + */ +class ModelPath +{ +public: + static ModelPath &get(); + + /** + * @brief Get the Absolute of the model to find + * + * @param model_dir A relative model directory + * @return std::string The absolute path of model directory + */ + std::string getModelAbsolutePath(const char *model_dir); + /** + * @brief Save the current executable's directory based on argv[0] and CWD + * + * @param argv0 0th command line argument of the current process + */ + void init(const char *argv0); + +private: + ModelPath() = default; + +private: + std::string _base_path; +}; + +#endif // __NNFW_API_TEST_MODEL_PATH_H__ diff --git a/tests/nnfw_api/src/prepare.cc b/tests/nnfw_api/src/prepare.cc new file mode 100644 index 00000000000..c9df5eb31b6 --- /dev/null +++ b/tests/nnfw_api/src/prepare.cc @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2020 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 "fixtures.h" + +TEST_F(ValidationTestOneOpModelLoaded, prepare_001) +{ + ASSERT_EQ(nnfw_prepare(_session), NNFW_STATUS_NO_ERROR); +} + +TEST_F(ValidationTest, neg_prepare_001) { ASSERT_EQ(nnfw_prepare(nullptr), NNFW_STATUS_ERROR); } diff --git a/tests/scripts/README.md b/tests/scripts/README.md index fcd8efc3b5a..8e7e8085f3d 100644 --- a/tests/scripts/README.md +++ b/tests/scripts/README.md @@ -50,7 +50,7 @@ $ ./tests/scripts/test-driver.sh \ ### Run nnapi_test with various tflite models - `nnapi_test` runs tflite in two ways and compares the result: 1. tflite interpreter - 2. `libneuralnetworks.so`, which could be PureACL or neurun depending on linked to nnapi_test + 2. `libneuralnetworks.so`, which could be PureACL or onert depending on linked to nnapi_test - Driver : `nnapi_test` - Driver source location : `tools/nnapi_test/` - Usage : diff --git a/tests/scripts/benchmark_nnapi.sh b/tests/scripts/benchmark_nnapi.sh index e16fbf67c05..48120ad9874 100755 --- a/tests/scripts/benchmark_nnapi.sh +++ b/tests/scripts/benchmark_nnapi.sh @@ -96,7 +96,7 @@ function profile_for_he_shed() export USE_SCHEDULER=1 export PROFILING_MODE=1 export EXECUTOR="Dataflow" - export NEURUN_LOG_ENABLE=1 + export ONERT_LOG_ENABLE=1 rm "exec_time.json" 2>/dev/null for ((j = 1 ; j <= $PROFILING_RUN_CNT ; j++)); do @@ -115,7 +115,7 @@ function profile_for_he_shed() # Save the exec_time.json of each run cp "exec_time.json" $REPORT_MODEL_DIR/"exec_time_$j.json" done - unset USE_SCHEDULER PROFILING_MODE EXECUTOR NEURUN_LOG_ENABLE + unset USE_SCHEDULER PROFILING_MODE EXECUTOR ONERT_LOG_ENABLE } function run_with_he_scheduler() @@ -126,22 +126,22 @@ function run_with_he_scheduler() local MODEL=$4 local EXECUTOR=$5 - LOG_FILE=$REPORT_MODEL_DIR/tflite_neurun_with_he_scheduler_in_$EXECUTOR.txt + LOG_FILE=$REPORT_MODEL_DIR/tflite_onert_with_he_scheduler_in_$EXECUTOR.txt export EXECUTOR=$EXECUTOR export GRAPH_DOT_DUMP=1 export USE_SCHEDULER=1 - export NEURUN_LOG_ENABLE=1 + export ONERT_LOG_ENABLE=1 - print_with_dots "TFLite neurun $EXECUTOR with HEScheduler" + print_with_dots "TFLite onert $EXECUTOR with HEScheduler" RESULT=$(get_result_of_benchmark_test $RUN_TEST_SH $BENCHMARK_DRIVER_BIN $MODEL $LOG_FILE) echo "$RESULT ms" mv "after_lower.dot" $REPORT_MODEL_DIR/"after_lower_$EXECUTOR.dot" - unset EXECUTOR GRAPH_DOT_DUMP USE_SCHEDULER NEURUN_LOG_ENABLE + unset EXECUTOR GRAPH_DOT_DUMP USE_SCHEDULER ONERT_LOG_ENABLE } -function run_neurun_with_all_config() +function run_onert_with_all_config() { local MODEL=$1 local REPORT_MODEL_DIR=$2 @@ -173,7 +173,7 @@ function run_neurun_with_all_config() fi for backend in $BACKEND_LIST; do export OP_BACKEND_ALLOPS=$backend - run_benchmark_and_print "tflite_neurun_"$executor"_executor_$backend" "TFLite neurun $executor Executor $backend"\ + run_benchmark_and_print "tflite_onert_"$executor"_executor_$backend" "TFLite onert $executor Executor $backend"\ $MODEL $REPORT_MODEL_DIR 0 $BENCHMARK_DRIVER_BIN $BENCHMARK_RUN_TEST_SH done done @@ -188,7 +188,7 @@ function run_benchmark_test() local REPORT_MODEL_DIR= export COUNT=5 - export NEURUN_LOG_ENABLE=1 + export ONERT_LOG_ENABLE=1 echo echo "============================================" echo @@ -217,12 +217,12 @@ function run_benchmark_test() unset USE_NNAPI run_benchmark_and_print "tflite_cpu" "TFLite CPU" $MODEL $REPORT_MODEL_DIR 0 $BENCHMARK_DRIVER_BIN $BENCHMARK_RUN_TEST_SH - # run neurun + # run onert if [ "$TEST_OP" == "true" ]; then # Operation test don't need to test each scheduler - run_neurun_with_all_config $MODEL $REPORT_MODEL_DIR 0 $BENCHMARK_DRIVER_BIN $BENCHMARK_RUN_TEST_SH "Linear" "$BACKEND_LIST" + run_onert_with_all_config $MODEL $REPORT_MODEL_DIR 0 $BENCHMARK_DRIVER_BIN $BENCHMARK_RUN_TEST_SH "Linear" "$BACKEND_LIST" else - run_neurun_with_all_config $MODEL $REPORT_MODEL_DIR 0 $BENCHMARK_DRIVER_BIN $BENCHMARK_RUN_TEST_SH "$EXECUTORS" "$BACKEND_LIST" + run_onert_with_all_config $MODEL $REPORT_MODEL_DIR 0 $BENCHMARK_DRIVER_BIN $BENCHMARK_RUN_TEST_SH "$EXECUTORS" "$BACKEND_LIST" fi if [[ $i -ne $(echo $BENCHMARK_MODEL_LIST | wc -w)-1 ]]; then @@ -246,5 +246,5 @@ rm -rf $BENCHMARK_MODELS_FILE echo "" # print the result AND append to log file -run_benchmark_test 2>&1 | tee -a neurun_benchmarks.txt +run_benchmark_test 2>&1 | tee -a onert_benchmarks.txt echo "" diff --git a/tests/scripts/benchmark_nnpkg.sh b/tests/scripts/benchmark_nnpkg.sh index ce593a8e54f..dd701bf5c91 100755 --- a/tests/scripts/benchmark_nnpkg.sh +++ b/tests/scripts/benchmark_nnpkg.sh @@ -105,7 +105,7 @@ for i in "${model_lists[@]}"; do CPU_CMD="BACKENDS=cpu ${CMD}" echo "${CPU_CMD}" echo "" >> ${outfile} - echo "neurun cpu" >> ${outfile} + echo "onert cpu" >> ${outfile} eval "${CPU_CMD}" sleep 10 # for avoiding cpu overheated @@ -114,7 +114,7 @@ for i in "${model_lists[@]}"; do NEON_CMD="BACKENDS=acl_neon ${CMD}" echo "${NEON_CMD}" echo "" >> ${outfile} - echo "neurun acl_neon" >> ${outfile} + echo "onert acl_neon" >> ${outfile} eval "${NEON_CMD}" sleep 10 # for avoiding cpu overheated @@ -123,7 +123,7 @@ for i in "${model_lists[@]}"; do CL_CMD="BACKENDS=acl_cl ${CMD}" echo "${CL_CMD}" echo "" >> ${outfile} - echo "neurun acl_cl" >> ${outfile} + echo "onert acl_cl" >> ${outfile} eval "${CL_CMD}" echo "" >> ${outfile} diff --git a/tests/scripts/framework/tests/MODELS/inception_module/config.sh b/tests/scripts/framework/tests/MODELS/inception_module/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/MODELS/inception_nonslim/config.sh b/tests/scripts/framework/tests/MODELS/inception_nonslim/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/MODELS/inception_slim/config.sh b/tests/scripts/framework/tests/MODELS/inception_slim/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/MODELS/mobilenet/config.sh b/tests/scripts/framework/tests/MODELS/mobilenet/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/abs/config.sh b/tests/scripts/framework/tests/abs/config.sh new file mode 100755 index 00000000000..7acdefa5a61 --- /dev/null +++ b/tests/scripts/framework/tests/abs/config.sh @@ -0,0 +1 @@ +MODELFILE_NAME="abs_4d.tflite" diff --git a/tests/scripts/framework/tests/add/1D/config.sh b/tests/scripts/framework/tests/add/1D/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/add/4D/config.sh b/tests/scripts/framework/tests/add/4D/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/average_pool_2d/aligned/config.sh b/tests/scripts/framework/tests/average_pool_2d/aligned/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/average_pool_2d/avgpool1/config.sh b/tests/scripts/framework/tests/average_pool_2d/avgpool1/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/average_pool_2d/avgpool2/config.sh b/tests/scripts/framework/tests/average_pool_2d/avgpool2/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/batch_to_space_nd2/config.sh b/tests/scripts/framework/tests/batch_to_space_nd2/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/cast/config.sh b/tests/scripts/framework/tests/cast/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/concat/2D/config.sh b/tests/scripts/framework/tests/concat/2D/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/concat/concat1/config.sh b/tests/scripts/framework/tests/concat/concat1/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/concat/concat2/config.sh b/tests/scripts/framework/tests/concat/concat2/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/conv_2d/convolution1/config.sh b/tests/scripts/framework/tests/conv_2d/convolution1/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/conv_2d/convolution2/config.sh b/tests/scripts/framework/tests/conv_2d/convolution2/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/custom/squared_difference/config.sh b/tests/scripts/framework/tests/custom/squared_difference/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/depthwise_conv_2d/depthconv1/config.sh b/tests/scripts/framework/tests/depthwise_conv_2d/depthconv1/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/depthwise_conv_2d/depthconv2/config.sh b/tests/scripts/framework/tests/depthwise_conv_2d/depthconv2/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/depthwise_conv_2d_no_fuse/config.sh b/tests/scripts/framework/tests/depthwise_conv_2d_no_fuse/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/div/broadcast/config.sh b/tests/scripts/framework/tests/div/broadcast/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/embedding_lookup/config.sh b/tests/scripts/framework/tests/embedding_lookup/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/equal/config.sh b/tests/scripts/framework/tests/equal/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/exp/config.sh b/tests/scripts/framework/tests/exp/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/floor/floor1/config.sh b/tests/scripts/framework/tests/floor/floor1/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/floor/floor2/config.sh b/tests/scripts/framework/tests/floor/floor2/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/fullyconnected/fc1/config.sh b/tests/scripts/framework/tests/fullyconnected/fc1/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/fullyconnected/hybrid/config.sh b/tests/scripts/framework/tests/fullyconnected/hybrid/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/fullyconnected/matmul2x2/config.sh b/tests/scripts/framework/tests/fullyconnected/matmul2x2/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/fullyconnected/weights_as_input/config.sh b/tests/scripts/framework/tests/fullyconnected/weights_as_input/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/gather/config.sh b/tests/scripts/framework/tests/gather/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/greater/config.sh b/tests/scripts/framework/tests/greater/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/greater_equal/config.sh b/tests/scripts/framework/tests/greater_equal/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/hashtable_lookup/config.sh b/tests/scripts/framework/tests/hashtable_lookup/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/l2_normalization/config.sh b/tests/scripts/framework/tests/l2_normalization/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/l2_pool_2d/config.sh b/tests/scripts/framework/tests/l2_pool_2d/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/less/config.sh b/tests/scripts/framework/tests/less/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/less_equal/config.sh b/tests/scripts/framework/tests/less_equal/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/logistic/config.sh b/tests/scripts/framework/tests/logistic/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/max/config.sh b/tests/scripts/framework/tests/max/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/max_pool_2d/maxpool1/config.sh b/tests/scripts/framework/tests/max_pool_2d/maxpool1/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/max_pool_2d/maxpool2/config.sh b/tests/scripts/framework/tests/max_pool_2d/maxpool2/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/mean/config.sh b/tests/scripts/framework/tests/mean/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/min/config.sh b/tests/scripts/framework/tests/min/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/mul/broadcast/config.sh b/tests/scripts/framework/tests/mul/broadcast/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/neg/config.sh b/tests/scripts/framework/tests/neg/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/not_equal/config.sh b/tests/scripts/framework/tests/not_equal/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/one_hot/config.sh b/tests/scripts/framework/tests/one_hot/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/pack/config.sh b/tests/scripts/framework/tests/pack/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/pad/4D_2D/config.sh b/tests/scripts/framework/tests/pad/4D_2D/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/pad/pad1/config.sh b/tests/scripts/framework/tests/pad/pad1/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/pad/pad2/config.sh b/tests/scripts/framework/tests/pad/pad2/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/reduce_max/config.sh b/tests/scripts/framework/tests/reduce_max/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/reduce_mean/test1/config.sh b/tests/scripts/framework/tests/reduce_mean/test1/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/reduce_mean/test2/config.sh b/tests/scripts/framework/tests/reduce_mean/test2/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/reduce_sum/config.sh b/tests/scripts/framework/tests/reduce_sum/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/relu/config.sh b/tests/scripts/framework/tests/relu/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/relu6/config.sh b/tests/scripts/framework/tests/relu6/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/reshape/3D/config.sh b/tests/scripts/framework/tests/reshape/3D/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/reshape/reshape1/config.sh b/tests/scripts/framework/tests/reshape/reshape1/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/reshape/reshape2/config.sh b/tests/scripts/framework/tests/reshape/reshape2/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/resize_bilinear/config.sh b/tests/scripts/framework/tests/resize_bilinear/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/rnn/config.sh b/tests/scripts/framework/tests/rnn/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/rsqrt/config.sh b/tests/scripts/framework/tests/rsqrt/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/sin/config.sh b/tests/scripts/framework/tests/sin/config.sh new file mode 100755 index 00000000000..dcf1959d84e --- /dev/null +++ b/tests/scripts/framework/tests/sin/config.sh @@ -0,0 +1 @@ +MODELFILE_NAME="sin_4d.tflite" diff --git a/tests/scripts/framework/tests/slice/config.sh b/tests/scripts/framework/tests/slice/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/softmax/config.sh b/tests/scripts/framework/tests/softmax/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/space_to_batch_nd2/config.sh b/tests/scripts/framework/tests/space_to_batch_nd2/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/space_to_depth/config.sh b/tests/scripts/framework/tests/space_to_depth/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/sqrt/config.sh b/tests/scripts/framework/tests/sqrt/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/squeeze/config.sh b/tests/scripts/framework/tests/squeeze/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/strided_slice/config.sh b/tests/scripts/framework/tests/strided_slice/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/sub/broadcast/config.sh b/tests/scripts/framework/tests/sub/broadcast/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/tanh/config.sh b/tests/scripts/framework/tests/tanh/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/topk_v2/config.sh b/tests/scripts/framework/tests/topk_v2/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/transpose/config.sh b/tests/scripts/framework/tests/transpose/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/transpose_conv/same/config.sh b/tests/scripts/framework/tests/transpose_conv/same/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/framework/tests/transpose_conv/valid/config.sh b/tests/scripts/framework/tests/transpose_conv/valid/config.sh old mode 100644 new mode 100755 diff --git a/tests/scripts/list/neurun_frameworktest_list.aarch64.acl_cl.txt b/tests/scripts/list/frameworktest_list.aarch64.acl_cl.txt similarity index 100% rename from tests/scripts/list/neurun_frameworktest_list.aarch64.acl_cl.txt rename to tests/scripts/list/frameworktest_list.aarch64.acl_cl.txt diff --git a/tests/scripts/list/neurun_frameworktest_list.aarch64.acl_neon.txt b/tests/scripts/list/frameworktest_list.aarch64.acl_neon.txt similarity index 100% rename from tests/scripts/list/neurun_frameworktest_list.aarch64.acl_neon.txt rename to tests/scripts/list/frameworktest_list.aarch64.acl_neon.txt diff --git a/tests/scripts/list/neurun_frameworktest_list.aarch64.cpu.txt b/tests/scripts/list/frameworktest_list.aarch64.cpu.txt similarity index 100% rename from tests/scripts/list/neurun_frameworktest_list.aarch64.cpu.txt rename to tests/scripts/list/frameworktest_list.aarch64.cpu.txt diff --git a/tests/scripts/list/neurun_frameworktest_list.armv7l.acl_cl.txt b/tests/scripts/list/frameworktest_list.armv7l.acl_cl.txt similarity index 100% rename from tests/scripts/list/neurun_frameworktest_list.armv7l.acl_cl.txt rename to tests/scripts/list/frameworktest_list.armv7l.acl_cl.txt diff --git a/tests/scripts/list/neurun_frameworktest_list.armv7l.acl_neon.txt b/tests/scripts/list/frameworktest_list.armv7l.acl_neon.txt similarity index 100% rename from tests/scripts/list/neurun_frameworktest_list.armv7l.acl_neon.txt rename to tests/scripts/list/frameworktest_list.armv7l.acl_neon.txt diff --git a/tests/scripts/list/neurun_frameworktest_list.armv7l.cpu.txt b/tests/scripts/list/frameworktest_list.armv7l.cpu.txt similarity index 91% rename from tests/scripts/list/neurun_frameworktest_list.armv7l.cpu.txt rename to tests/scripts/list/frameworktest_list.armv7l.cpu.txt index 7473296a31e..871b13c9970 100644 --- a/tests/scripts/list/neurun_frameworktest_list.armv7l.cpu.txt +++ b/tests/scripts/list/frameworktest_list.armv7l.cpu.txt @@ -1,5 +1,6 @@ MODELS/inception_module MODELS/mobilenet +abs add average_pool_2d cast @@ -25,7 +26,10 @@ pack reduce_max reduce_sum reshape/reshape1 +rsqrt +sin slice +strided_slice softmax squeeze sub diff --git a/tests/scripts/list/neurun_frameworktest_list.noarch.interp.txt b/tests/scripts/list/frameworktest_list.noarch.interp.txt similarity index 100% rename from tests/scripts/list/neurun_frameworktest_list.noarch.interp.txt rename to tests/scripts/list/frameworktest_list.noarch.interp.txt diff --git a/tests/scripts/list/neurun_frameworktest_list.x86_64.cpu.txt b/tests/scripts/list/frameworktest_list.x86_64.cpu.txt similarity index 100% rename from tests/scripts/list/neurun_frameworktest_list.x86_64.cpu.txt rename to tests/scripts/list/frameworktest_list.x86_64.cpu.txt diff --git a/tests/scripts/list/neurun_frameworktest_list.aarch64.srcn.txt b/tests/scripts/list/neurun_frameworktest_list.aarch64.srcn.txt deleted file mode 100644 index ab72563c147..00000000000 --- a/tests/scripts/list/neurun_frameworktest_list.aarch64.srcn.txt +++ /dev/null @@ -1,3 +0,0 @@ -add -average_pool_2d/aligned -transpose_conv diff --git a/tests/scripts/list/neurun_frameworktest_list.armv7l.srcn.txt b/tests/scripts/list/neurun_frameworktest_list.armv7l.srcn.txt deleted file mode 100644 index 6f4cf2adbe3..00000000000 --- a/tests/scripts/list/neurun_frameworktest_list.armv7l.srcn.txt +++ /dev/null @@ -1,4 +0,0 @@ -add -average_pool_2d/aligned -depthwise_conv_2d_no_fuse -transpose_conv diff --git a/tests/scripts/test-driver.sh b/tests/scripts/test-driver.sh index d211070e511..319370de1cf 100755 --- a/tests/scripts/test-driver.sh +++ b/tests/scripts/test-driver.sh @@ -33,7 +33,7 @@ function Usage() echo "--frameworktest_list_file - filepath of model list for test" echo "" echo "Following option is only needed when you want to test benchmark." - echo "--benchmark_neurun_op - (default=off) run benchmark per operation on neurun" + echo "--benchmark_onert_op - (default=off) run benchmark per operation on onert" echo "" echo "etc." echo "--framework_driverbin - (default=../../Product/out/bin/tflite_run) runner for runnning framework tests" @@ -57,7 +57,7 @@ ALLTEST_ON="true" UNITTEST_ON="false" FRAMEWORKTEST_ON="false" VERIFICATION_ON="false" -BENCHMARK_NEURUN_OP_ON="false" +BENCHMARK_ONERT_OP_ON="false" REPORT_DIR="" for i in "$@" @@ -104,9 +104,9 @@ do ALLTEST_ON="false" VERIFICATION_ON="true" ;; - --benchmark_neurun_op) + --benchmark_onert_op) ALLTEST_ON="false" - BENCHMARK_NEURUN_OP_ON="true" + BENCHMARK_ONERT_OP_ON="true" ;; --reportdir=*) REPORT_DIR=${i#*=} @@ -180,7 +180,7 @@ if [ "$ALLTEST_ON" == "true" ] || [ "$VERIFICATION_ON" == "true" ]; then --frameworktest_list_file=${FRAMEWORKTEST_LIST_FILE:-} fi -if [ "$BENCHMARK_NEURUN_OP_ON" == "true" ]; then +if [ "$BENCHMARK_ONERT_OP_ON" == "true" ]; then if [ -z "$BENCHMARK_DRIVER_BIN" ]; then DRIVER_BIN=$ARTIFACT_PATH/Product/out/bin/tflite_benchmark else @@ -196,10 +196,10 @@ if [ "$BENCHMARK_NEURUN_OP_ON" == "true" ]; then fi # Make json file. Actually, this process is only needed on CI. That's why it is in test-driver.sh. -if [ "$BENCHMARK_NEURUN_OP_ON" == "true" ]; then +if [ "$BENCHMARK_ONERT_OP_ON" == "true" ]; then # functions to fill json with benchmark results source $ARTIFACT_PATH/tests/scripts/print_to_json.sh - if [ "$BENCHMARK_NEURUN_OP_ON" == "true" ]; then + if [ "$BENCHMARK_ONERT_OP_ON" == "true" ]; then print_to_json $REPORT_DIR/benchmark_op $REPORT_DIR "benchmark_op_result.json" else print_to_json $REPORT_DIR/benchmark $REPORT_DIR "benchmark_result.json" diff --git a/tests/scripts/test_framework.sh b/tests/scripts/test_framework.sh index f824a455314..1d9751562ee 100755 --- a/tests/scripts/test_framework.sh +++ b/tests/scripts/test_framework.sh @@ -27,7 +27,7 @@ function Usage() echo "./$0 \\" echo " --runtestsh=tests/scripts/framework/run_test.sh \\ # Test runner script path" echo " --driverbin=Product/out/bin/tflite_run \\ # Test driver path" - echo " --frameworktest_list_file=tests/scripts/list/neurun_frameworktest_list.armv7l.cpu.txt \\" + echo " --frameworktest_list_file=tests/scripts/list/frameworktest_list.armv7l.cpu.txt \\" echo " --reportdir=report \\ # Directory for the report files will be saved" echo " --tapname=framework_test.tap \\ # Tap file name" echo " --logname=framework_test.log \\ # Log file name" diff --git a/tests/scripts/test_scheduler_with_profiling.sh b/tests/scripts/test_scheduler_with_profiling.sh index 0e63d82ad39..61b2a4f4c96 100755 --- a/tests/scripts/test_scheduler_with_profiling.sh +++ b/tests/scripts/test_scheduler_with_profiling.sh @@ -72,7 +72,7 @@ function run_benchmark_test() export USE_SCHEDULER=1 export PROFILING_MODE=1 export EXECUTOR="Dataflow" - export NEURUN_LOG_ENABLE=1 + export ONERT_LOG_ENABLE=1 for ((j = 1 ; j <= $PROFILING_RUN_CNT ; j++)); do # Save the verbose log of each run LOG_FILE=$REPORT_MODEL_DIR/tflite_profiling_$j.txt @@ -89,7 +89,7 @@ function run_benchmark_test() # Save the exec_time.json of each run cp "exec_time.json" $REPORT_MODEL_DIR/"exec_time_$j.json" done - unset NEURUN_LOG_ENABLE + unset ONERT_LOG_ENABLE ################################################################################## diff --git a/tests/scripts/unittest.sh b/tests/scripts/unittest.sh index 54a01913bdc..6c84b101aee 100755 --- a/tests/scripts/unittest.sh +++ b/tests/scripts/unittest.sh @@ -29,8 +29,8 @@ get_gtest_option() { local output_option="--gtest_output=xml:$UNITTEST_REPORT_DIR/$TEST_BIN.xml" local filter_option - if [ -r "$UNITTEST_TEST_DIR/$TEST_BIN.skip" ]; then - filter_option="--gtest_filter=-$(grep -v '#' "$UNITTEST_TEST_DIR/$TEST_BIN.skip" | tr '\n' ':')" + if [ -r "$TEST_BIN.skip" ]; then + filter_option="--gtest_filter=-$(grep -v '#' "$TEST_BIN.skip" | tr '\n' ':')" fi echo "$output_option $filter_option" } @@ -66,7 +66,8 @@ echo "Unittest start" echo "============================================" num_unittest=0 -for TEST_BIN in `ls $UNITTEST_TEST_DIR --hide=*.skip*`; do +# Run all executables in unit test directory +for TEST_BIN in `find $UNITTEST_TEST_DIR -maxdepth 1 -type f -executable`; do num_unittest=$((num_unittest+1)) echo "============================================" echo "Starting set $num_unittest: $TEST_BIN..." @@ -74,16 +75,16 @@ for TEST_BIN in `ls $UNITTEST_TEST_DIR --hide=*.skip*`; do TEMP_UNITTEST_RESULT=0 if [ "$UNITTEST_RUN_ALL" == "true" ]; then - for TEST_LIST_VERBOSE_LINE in $($UNITTEST_TEST_DIR/$TEST_BIN --gtest_list_tests); do + for TEST_LIST_VERBOSE_LINE in $($TEST_BIN --gtest_list_tests); do if [[ $TEST_LIST_VERBOSE_LINE == *\. ]]; then TEST_LIST_CATEGORY=$TEST_LIST_VERBOSE_LINE else TEST_LIST_ITEM="$TEST_LIST_CATEGORY""$TEST_LIST_VERBOSE_LINE" - $UNITTEST_TEST_DIR/$TEST_BIN --gtest_filter=$TEST_LIST_ITEM --gtest_output="xml:$UNITTEST_REPORT_DIR/$TEST_LIST_ITEM.xml" + $TEST_BIN --gtest_filter=$TEST_LIST_ITEM --gtest_output="xml:$UNITTEST_REPORT_DIR/$TEST_LIST_ITEM.xml" fi done else - $UNITTEST_TEST_DIR/$TEST_BIN $(get_gtest_option) + $TEST_BIN $(get_gtest_option) TEMP_UNITTEST_RESULT=$? fi diff --git a/tests/tools/nnapi_test/src/nnapi_test.cc b/tests/tools/nnapi_test/src/nnapi_test.cc index 799188f66c0..d925831f166 100644 --- a/tests/tools/nnapi_test/src/nnapi_test.cc +++ b/tests/tools/nnapi_test/src/nnapi_test.cc @@ -41,6 +41,12 @@ int main(const int argc, char **argv) auto model = FlatBufferModel::BuildFromFile(filename, &error_reporter); + if (model == nullptr) + { + // error_reporter must have shown the error message already + return 1; + } + const nnfw::tflite::FlatBufferBuilder builder(*model); try diff --git a/tests/tools/nnpackage_run/CMakeLists.txt b/tests/tools/nnpackage_run/CMakeLists.txt index ce4ddaf4aa6..7b0d874da26 100644 --- a/tests/tools/nnpackage_run/CMakeLists.txt +++ b/tests/tools/nnpackage_run/CMakeLists.txt @@ -2,9 +2,9 @@ if(NOT BUILD_NNPACKAGE_RUN) return() endif(NOT BUILD_NNPACKAGE_RUN) -if(NOT BUILD_NEURUN) +if(NOT BUILD_ONERT) return() -endif(NOT BUILD_NEURUN) +endif(NOT BUILD_ONERT) find_package(HDF5 COMPONENTS CXX QUIET) if(NOT HDF5_FOUND) @@ -27,7 +27,7 @@ target_include_directories(nnpackage_run PRIVATE src) target_include_directories(nnpackage_run PRIVATE ${Boost_INCLUDE_DIRS}) target_include_directories(nnpackage_run PRIVATE ${HDF5_INCLUDE_DIRS}) -target_link_libraries(nnpackage_run neurun_core neurun tflite_loader) +target_link_libraries(nnpackage_run onert_core onert tflite_loader) target_link_libraries(nnpackage_run tensorflow-lite ${LIB_PTHREAD} dl nnfw_lib_tflite) target_link_libraries(nnpackage_run nnfw-dev) target_link_libraries(nnpackage_run boost_program_options) diff --git a/tests/tools/tflite_loader/CMakeLists.txt b/tests/tools/tflite_loader/CMakeLists.txt index d17f35979aa..ece39161f28 100644 --- a/tests/tools/tflite_loader/CMakeLists.txt +++ b/tests/tools/tflite_loader/CMakeLists.txt @@ -3,10 +3,10 @@ if(NOT BUILD_TFLITE_LOADER_TEST_TOOL) return() endif(NOT BUILD_TFLITE_LOADER_TEST_TOOL) -if(NOT BUILD_NEURUN) - message("skipping tflite loader tool build: neurun is not built") +if(NOT BUILD_ONERT) + message("skipping tflite loader tool build: onert is not built") return() -endif(NOT BUILD_NEURUN) +endif(NOT BUILD_ONERT) list(APPEND SOURCES "src/tflite_loader.cc") list(APPEND SOURCES "src/args.cc") @@ -16,7 +16,7 @@ nnas_find_package(Boost REQUIRED) add_executable(tflite_loader_test_tool ${SOURCES}) target_include_directories(tflite_loader_test_tool PRIVATE ${Boost_INCLUDE_DIRS}) -target_link_libraries(tflite_loader_test_tool neurun_core neurun tflite_loader) +target_link_libraries(tflite_loader_test_tool onert_core onert tflite_loader) target_link_libraries(tflite_loader_test_tool nnfw_lib_tflite tensorflow-lite ${LIB_PTHREAD} dl nnfw_lib_misc) target_link_libraries(tflite_loader_test_tool boost_program_options boost_system boost_filesystem) diff --git a/tests/tools/tflite_loader/src/tflite_loader.cc b/tests/tools/tflite_loader/src/tflite_loader.cc index b8a9f69a185..1270eb66010 100644 --- a/tests/tools/tflite_loader/src/tflite_loader.cc +++ b/tests/tools/tflite_loader/src/tflite_loader.cc @@ -31,7 +31,7 @@ #include "tflite_loader.h" -#include "memory" +#include const int RUN_FAILED = 1; @@ -73,11 +73,11 @@ std::vector randomData(RandomGenerator &randgen, const uint64_t size) return vec; } -void executeGraph(const std::shared_ptr &g, +void executeGraph(const std::shared_ptr &g, const std::vector> &inputs, std::vector> &outputs) { - auto compiler = new neurun::compiler::Compiler(g); + auto compiler = new onert::compiler::Compiler(g); // Compilation try { @@ -92,9 +92,9 @@ void executeGraph(const std::shared_ptr &g, std::cout << "[Execution] Graph compiled!" << std::endl; - std::shared_ptr executor; + std::shared_ptr executor; compiler->release(executor); - auto execution = std::make_shared(executor); + auto execution = std::make_shared(executor); // Setting IO try @@ -119,10 +119,10 @@ void executeGraph(const std::shared_ptr &g, } for (size_t i = 0; i < num_inputs; i++) - execution->setInput(neurun::ir::IOIndex(i), inputs[i].data(), + execution->setInput(onert::ir::IOIndex(i), inputs[i].data(), inputs[i].size() * sizeof(float)); for (uint32_t i = 0; i < num_outputs; i++) - execution->setOutput(neurun::ir::IOIndex(i), outputs[i].data(), + execution->setOutput(onert::ir::IOIndex(i), outputs[i].data(), outputs[i].size() * sizeof(float)); } catch (const std::exception &e) @@ -162,11 +162,11 @@ int main(const int argc, char **argv) } std::cout << "[Execution] Stage start!" << std::endl; - std::shared_ptr test_graph; + std::shared_ptr test_graph; // Loading try { - test_graph = neurun::tflite_loader::loadModel(tflite_file.c_str()); + test_graph = onert::tflite_loader::loadModel(tflite_file.c_str()); } catch (std::exception &e) { @@ -180,12 +180,12 @@ int main(const int argc, char **argv) for (const auto &input_idx : test_graph->getInputs()) { const auto input_type = test_graph->operands().at(input_idx).typeInfo().type(); - assert(input_type == neurun::ir::DataType::FLOAT32 && "Only FLOAT32 inputs are supported"); + assert(input_type == onert::ir::DataType::FLOAT32 && "Only FLOAT32 inputs are supported"); } for (const auto &output_idx : test_graph->getOutputs()) { const auto output_type = test_graph->operands().at(output_idx).typeInfo().type(); - assert(output_type == neurun::ir::DataType::FLOAT32 && "Only FLOAT32 outputs are supported"); + assert(output_type == onert::ir::DataType::FLOAT32 && "Only FLOAT32 outputs are supported"); } std::cout << "[Execution] Model is deserialized!" << std::endl; diff --git a/tools/cross/install_android_sdk.sh b/tools/cross/install_android_sdk.sh new file mode 100755 index 00000000000..0cefa4ad185 --- /dev/null +++ b/tools/cross/install_android_sdk.sh @@ -0,0 +1,167 @@ +#!/usr/bin/env bash +# +# Copyright (c) 2020 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. + +# Setup Android Cross-Build Environment (ANDROID SDK) +SCRIPT_HOME=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) # absolute path to directory where script is +INSTALL_PATH=$SCRIPT_HOME/android_sdk # path to directory where android sdk will be installed +PLATFORMS_PACKAGE_VERSION="28" # version of platfroms package which will be installed +BUILD_TOOLS_PACKAGE_VERSION="28.0.0" # version of build-tools package which will be installed +COMMAND_LINE_TOOLS_ARCHIVE="commandlinetools-linux-6200805_latest.zip" # command line tools archive name from site https://developer.android.com/studio/#downloads + + +usage() { + printf "usage: ./build_android_sdk.sh [--option [option_value]]\n" + printf " --install-dir - absolute path to directory where android sdk will be installed, by default: $INSTALL_PATH\n" + printf " --platforms-package-version - version of platforms package which will be installed, by default: $PLATFORMS_PACKAGE_VERSION\n" + printf " --build-tools-package-version - version of build-tools package which will be installed, by default: $BUILD_TOOLS_PACKAGE_VERSION\n" + printf " --command-line-tools-archive - name of command line tools archive from site https://developer.android.com/studio/#downloads, by default: $COMMAND_LINE_TOOLS_ARCHIVE\n" + printf " --help - show this text\n" +} + +check_that_available() { + local util_name=${1} + local possible_util_alias=${2} + if ! [ -x "$(command -v $util_name)" ]; then + printf "ERROR: this script uses $util_name utility, " + printf "please install it and repeat try (e.g. for ubuntu execute command: sudo apt install $possible_util_alias)" + exit 1 + fi +} + +check_preconditions() { + check_that_available wget wget + check_that_available unzip unzip + check_that_available java default-jdk +} + +check_that_android_sdk_have_not_been_installed_yet() { + local root=${1} + + if [ -d $root ]; then + echo "Directory '$root', where android sdk should be installed, exists. Please remove it or define another path" + exit 1 + fi +} + +make_environment() { + local root=${1} + check_that_android_sdk_have_not_been_installed_yet $root + mkdir -p $root + + pushd $root + export ANDROID_HOME=$root + export PATH=$PATH:/$ANDROID_HOME/tools/bin + export PATH=$PATH:/$ANDROID_HOME/platform-tools + export JAVA_OPTS='-XX:+IgnoreUnrecognizedVMOptions' + popd +} + +download_command_line_tools() { + local root=${1} + local download_url=https://dl.google.com/android/repository + + pushd $root + wget $download_url/$COMMAND_LINE_TOOLS_ARCHIVE + if [ ${?} -ne 0 ]; then + echo "seems like '$COMMAND_LINE_TOOLS_ARCHIVE' not found. Please, go to https://developer.android.com/studio/#downloads " + echo "and check name and version of command line tools archive for linux in the table 'Command line tools only' " + echo "and put it as --command-line-tools-archive-name parameter value" + exit 1 + fi + popd +} + +extract_command_line_tools() { + local root=${1} + + pushd $root + unzip $COMMAND_LINE_TOOLS_ARCHIVE + rm $COMMAND_LINE_TOOLS_ARCHIVE + popd +} + +install_command_line_tools() { + local root=${1} + + download_command_line_tools $root + extract_command_line_tools $root +} + +check_that_given_version_of_package_available() { + # this function assumes that current working directory is directory where android sdk will be installed + local package_base_name=${1} + local package_version=${2} + + sdkmanager --sdk_root=${ANDROID_HOME} --list | grep ${package_base_name}${package_version} > /dev/null + if [ ${?} -ne 0 ]; then + echo "package '${package_base_name}${package_version}' is not available" + exit 1 + fi +} + +install_android_sdk() { + local root=${1} + + pushd $root + yes | sdkmanager --sdk_root=${ANDROID_HOME} --licenses > /dev/null + check_that_given_version_of_package_available "platforms;android-" ${PLATFORMS_PACKAGE_VERSION} + check_that_given_version_of_package_available "build-tools;" ${BUILD_TOOLS_PACKAGE_VERSION} + sdkmanager --sdk_root=${ANDROID_HOME} "platform-tools" + sdkmanager --sdk_root=${ANDROID_HOME} "platforms;android-$PLATFORMS_PACKAGE_VERSION" + sdkmanager --sdk_root=${ANDROID_HOME} "build-tools;$BUILD_TOOLS_PACKAGE_VERSION" + popd +} + + +while [[ $# -gt 0 ]]; do + key="$(echo $1 | awk '{print tolower($0)}')" + case "$key" in + --help) + usage + exit 0 + ;; + --install-dir) + shift + INSTALL_PATH=${1} + shift + ;; + --platforms-package-version) + shift + PLATFORMS_PACKAGE_VERSION=${1} + shift + ;; + --build-tools-package-version) + shift + BUILD_TOOLS_PACKAGE_VERSION=${1} + shift + ;; + --command-line-tools-archive) + shift + COMMAND_LINE_TOOLS_ARCHIVE=${1} + shift + ;; + *) + echo "Invalid option '$1'" + usage + exit 1 + ;; + esac +done + +check_preconditions +make_environment $INSTALL_PATH +install_command_line_tools $INSTALL_PATH +install_android_sdk $INSTALL_PATH diff --git a/tools/kernel_report/kernel_report.py b/tools/kernel_report/kernel_report.py new file mode 100755 index 00000000000..0be5b82d58f --- /dev/null +++ b/tools/kernel_report/kernel_report.py @@ -0,0 +1,171 @@ +#!/usr/bin/python + +# Copyright (c) 2020 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. + +import os +import argparse + + +class Backend: + def __init__(self): + self.backends = {} + self.backends["acl_cl"] = False + self.backends["acl_neon"] = False + self.backends["cpu"] = False + self.backends["srcn"] = False + + +class KernelReporter(object): + def __init__(self, args): + # TODO: Remove os defendency - '/' + if args.base[0] != '/': + self.onertBase = os.getcwd() + '/' + args.base + else: + self.onertBase = args.base + self.opListFile = "core/include/ir/Operations.lst" + self.operations = [] + self.kernelGeneratorFile = "KernelGenerator.h" + self.kernelMap = {} + + def parseOpList(self): + #buf = open(self.onertBase + '/' + self.opListFile, "r") + + # Parsing line and get op list + skipLine = False + for line in open(self.onertBase + '/' + self.opListFile, "r"): + # Skip license + # TODO : Change to skip general comment + if skipLine: + if line.startswith(" */"): + skipLine = False + continue + continue + if line.startswith("/*"): + skipLine = True + continue + + # Skip comment + if line.startswith("//"): + continue + + # Skip macro + if line.startswith("#"): + continue + + lineStripped = line.strip() + if len(lineStripped) == 0: + continue + + op = lineStripped[3:-1] + self.operations.append(op) + self.operations.sort() + + def generateKernelMap(self): + for op in self.operations: + self.kernelMap[op] = Backend() + + backendLists = ["acl_cl", "acl_neon", "cpu", "srcn"] + + for backend in backendLists: + buf = open( + self.onertBase + '/backend/' + backend + '/' + self.kernelGeneratorFile, + "r") + + for line in buf: + words = line.split() + if len(words) < 3: + continue + if words[1] != "visit(const": + continue + + opName = words[2].split("::") + if len(opName) < 3: + continue + + if opName[2] in self.operations: + self.kernelMap[opName[2]].backends[backend] = True + + buf.close() + + def printResult(self): + print() + backendLists = ["acl_cl", "acl_neon", "cpu", "srcn"] + line = "" + for backend in backendLists: + line = line + "{0:^9}".format(backend) + print('{0:30}{1}'.format("", line)) + + counts = [0, 0, 0, 0] + + for op in self.operations: + line = "" + for i in range(0, 4, 1): + support = self.kernelMap[op].backends[backendLists[i]] + if support: + line = line + "{0:^9}".format("O") + counts[i] += 1 + else: + line = line + "{0:^9}".format("-") + print('{0:30}{1}'.format(op, line)) + + line = "" + for count in counts: + line = line + "{0:^9}".format(count) + print('{0:30}{1}'.format("TOTAL COUNT", line)) + + def printMDFormat(self): + print() + backendLists = ["acl_cl", "acl_neon", "cpu", "srcn"] + line = "" + for backend in backendLists: + line = line + "|" + backend + print("|" + line) + print("-|-|-|-|-") + + counts = [0, 0, 0, 0] + + for op in self.operations: + line = "" + for i in range(0, 4, 1): + support = self.kernelMap[op].backends[backendLists[i]] + if support: + line = line + "|" + "O" + counts[i] += 1 + else: + line = line + "|" + "-" + print(op + line) + + line = "" + for count in counts: + line = line + "|" + str(count) + + print("-|-|-|-|-") + print("TOTAL COUNT" + line) + + def run(self): + self.parseOpList() + self.generateKernelMap() + self.printResult() + + self.printMDFormat() + + +if __name__ == '__main__': + arg_parser = argparse.ArgumentParser() + arg_parser.add_argument("base", type=str, help="onert base directory") + args = arg_parser.parse_args() + + report = KernelReporter(args) + report.run() diff --git a/tools/nnpackage_tool/tf2tfliteV2/README.md b/tools/nnpackage_tool/tf2tfliteV2/README.md new file mode 100644 index 00000000000..836740a5c51 --- /dev/null +++ b/tools/nnpackage_tool/tf2tfliteV2/README.md @@ -0,0 +1,47 @@ +# tf2tfliteV2 + +_tf2tfliteV2_ is a TensorFlow to TensorFlow Lite model Converter. + +## Where does V2 come from? +Even though we alreay have _tf2tflite_, we cannot cover all opeartors in TensorFlow. To expand coverage, we introduce _tf2tfliteV2_ which uses `TensorFlow Lite Converter`(by Google) internally. + +## Prerequisite +- Frozen graph from TensorFlow 1.13.1 +- Desired version of TensorFlow(You can use python virtualenv, docker, etc.) + +## Example +``` +python tf2tfliteV2.py \ +> --v1 \ +> --input_path=frozen_graph.pb \ +> --output_path=converted.tflite \ +> --input_arrays=model_inputs \ +> --output_arrays=model_outputs + +``` +``` +python tf2tfliteV2.py \ +> --v2 \ +> --input_path=frozen_graph.pb \ +> --output_path=converted.tflite \ +> --input_arrays=model_inputs \ +> --output_arrays=model_outputs +``` + +## optional argument +``` + -h, --help show this help message and exit + --v1 Use TensorFlow Lite Converter 1.x + --v2 Use TensorFlow Lite Converter 2.x + --input_path INPUT_PATH + Full filepath of the input file. + --output_path OUTPUT_PATH + Full filepath of the output file. + --input_arrays INPUT_ARRAYS + Names of the input arrays, comma-separated. + --input_shapes INPUT_SHAPES + Shapes corresponding to --input_arrays, colon- + separated. + --output_arrays OUTPUT_ARRAYS + Names of the output arrays, comma-separated. +``` diff --git a/tools/nnpackage_tool/tf2tfliteV2/tf2tfliteV2.py b/tools/nnpackage_tool/tf2tfliteV2/tf2tfliteV2.py new file mode 100755 index 00000000000..ebd5a3afaac --- /dev/null +++ b/tools/nnpackage_tool/tf2tfliteV2/tf2tfliteV2.py @@ -0,0 +1,173 @@ +# Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved +# Copyright (C) 2018 The TensorFlow Authors +# +# 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. + +import tensorflow as tf +import argparse +import sys + + +def wrap_frozen_graph(graph_def, inputs, outputs): + def _imports_graph_def(): + tf.compat.v1.import_graph_def(graph_def, name="") + + wrapped_import = tf.compat.v1.wrap_function(_imports_graph_def, []) + import_graph = wrapped_import.graph + return wrapped_import.prune( + tf.nest.map_structure(import_graph.as_graph_element, inputs), + tf.nest.map_structure(import_graph.as_graph_element, outputs)) + + +def _get_parser(): + """ + Returns an ArgumentParser for TensorFlow Lite Converter. + """ + parser = argparse.ArgumentParser( + description=("Command line tool to run TensorFlow Lite Converter.")) + + # Converter version. + converter_version = parser.add_mutually_exclusive_group(required=True) + converter_version.add_argument( + "--v1", action="store_true", help="Use TensorFlow Lite Converter 1.x") + converter_version.add_argument( + "--v2", action="store_true", help="Use TensorFlow Lite Converter 2.x") + + # Input and output path. + parser.add_argument( + "--input_path", type=str, help="Full filepath of the input file.", required=True) + parser.add_argument( + "--output_path", + type=str, + help="Full filepath of the output file.", + required=True) + + # Input and output arrays. + parser.add_argument( + "--input_arrays", + type=str, + help="Names of the input arrays, comma-separated.", + required=True) + parser.add_argument( + "--input_shapes", + type=str, + help="Shapes corresponding to --input_arrays, colon-separated.") + parser.add_argument( + "--output_arrays", + type=str, + help="Names of the output arrays, comma-separated.", + required=True) + + return parser + + +def _check_flags(flags): + """ + Checks the parsed flags to ensure they are valid. + """ + if flags.v1: + invalid = "" + # To be filled + + if invalid: + raise ValueError(invalid + " options must be used with v2") + + if flags.v2: + if tf.__version__.find("2.") != 0: + raise ValueError( + "Imported TensorFlow should have version >= 2.0 but you have " + + tf.__version__) + + invalid = "" + # To be filled + + if invalid: + raise ValueError(invalid + " options must be used with v1") + + if flags.input_shapes: + if not flags.input_arrays: + raise ValueError("--input_shapes must be used with --input_arrays") + if flags.input_shapes.count(":") != flags.input_arrays.count(","): + raise ValueError("--input_shapes and --input_arrays must have the same " + "number of items") + + +def _parse_array(arrays, type_fn=str): + return list(map(type_fn, arrays.split(","))) + + +def _v1_convert(flags): + input_shapes = None + if flags.input_shapes: + input_arrays = _parse_array(flags.input_arrays) + input_shapes_list = [ + _parse_array(shape, type_fn=int) for shape in flags.input_shapes.split(":") + ] + input_shapes = dict(list(zip(input_arrays, input_shapes_list))) + + converter = tf.compat.v1.lite.TFLiteConverter.from_frozen_graph( + flags.input_path, _parse_array(flags.input_arrays), + _parse_array(flags.output_arrays), input_shapes) + + converter.allow_custom_ops = True + + tflite_model = converter.convert() + open(flags.output_path, "wb").write(tflite_model) + + +def _v2_convert(flags): + graph_def = tf.compat.v1.GraphDef() + graph_def.ParseFromString(open(flags.input_path, 'rb').read()) + + wrap_func = wrap_frozen_graph( + graph_def, + inputs=[_str + ":0" for _str in _parse_array(flags.input_arrays)], + # TODO What if multiple outputs come in? + outputs=[_str + ":0" for _str in _parse_array(flags.output_arrays)]) + converter = tf.lite.TFLiteConverter.from_concrete_functions([wrap_func]) + + converter.allow_custom_ops = True + converter.experimental_new_converter = True + + converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS] + + tflite_model = converter.convert() + open(flags.output_path, "wb").write(tflite_model) + + +def _convert(flags): + if (flags.v1): + _v1_convert(flags) + else: + _v2_convert(flags) + + +""" +Input frozen graph must be from TensorFlow 1.13.1 +""" + + +def main(): + # Parse argument. + parser = _get_parser() + + # Check if the flags are valid. + flags = parser.parse_known_args(args=sys.argv[1:]) + _check_flags(flags[0]) + + # Convert + _convert(flags[0]) + + +if __name__ == "__main__": + main() diff --git a/tools/pbfile_tool/convert_ckpt_to_pb.py b/tools/pbfile_tool/convert_ckpt_to_pb.py old mode 100644 new mode 100755 diff --git a/tools/pbfile_tool/convert_pb_to_pbtxt.py b/tools/pbfile_tool/convert_pb_to_pbtxt.py old mode 100644 new mode 100755 diff --git a/tools/pbfile_tool/extract_subgraph.py b/tools/pbfile_tool/extract_subgraph.py old mode 100644 new mode 100755 diff --git a/tools/tensorflow_model_freezer/__init__.py b/tools/tensorflow_model_freezer/__init__.py old mode 100644 new mode 100755 diff --git a/tools/tensorflow_model_freezer/base_freezer.py b/tools/tensorflow_model_freezer/base_freezer.py old mode 100644 new mode 100755 diff --git a/tools/tensorflow_model_freezer/model_freezer_util.py b/tools/tensorflow_model_freezer/model_freezer_util.py old mode 100644 new mode 100755 diff --git a/tools/tensorflow_model_freezer/sample/Operation_gen.py b/tools/tensorflow_model_freezer/sample/Operation_gen.py old mode 100644 new mode 100755 diff --git a/tools/tensorflow_model_freezer/sample/UNSTACK_gen.py b/tools/tensorflow_model_freezer/sample/UNSTACK_gen.py old mode 100644 new mode 100755 diff --git a/tools/tensorflow_model_freezer/sample/__init__.py b/tools/tensorflow_model_freezer/sample/__init__.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/config_saver.py b/tools/tflitefile_tool/config_saver.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/graph_stats.py b/tools/tflitefile_tool/graph_stats.py new file mode 100755 index 00000000000..c6590a3a4cb --- /dev/null +++ b/tools/tflitefile_tool/graph_stats.py @@ -0,0 +1,120 @@ +#!/usr/bin/python + +# Copyright (c) 2020 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. + + +class GraphStats(): + def __init__(self): + from collections import Counter + from collections import defaultdict + self.op_counts = Counter() + # `op_instrs` could have None as well as int so we can't use `Counter` + self.op_instrs = defaultdict(int) + self.filled_memory = 0 + self.total_memory = 0 + + def accumulate_op_count(self, op_str, count): + self.op_counts[op_str] += count + + def accumulate_op_instr(self, op_str, count): + if self.op_instrs[op_str] == None or count == None: + self.op_instrs[op_str] = None + else: + self.op_instrs[op_str] += count + + def accumulate_filled_memory(self, size): + self.filled_memory += size + + def accumulate_total_memory(self, size): + self.total_memory += size + + def __iadd__(self, other): + self.op_counts += other.op_counts + for key in other.op_instrs.keys(): + if self.op_instrs[key] == None or other.op_instrs[key] == None: + self.op_instrs[key] = None + else: + self.op_instrs[key] += other.op_instrs[key] + self.filled_memory += other.filled_memory + self.total_memory += other.total_memory + return self + + +def PrintGraphStats(stats, verbose): + def instrs_to_str(val): + if val == None: + return '???' + else: + return '{:,}'.format(val) + + print("Number of all operator types: {0}".format(len(stats.op_counts))) + + # Print op type stats + for op_name in sorted(stats.op_counts.keys()): + occur = stats.op_counts[op_name] + optype_info_str = "\t{:38}: {:4}".format(op_name, occur) + + if verbose == 2: + instrs = instrs_to_str(stats.op_instrs[op_name]) + optype_info_str = optype_info_str + " \t (instrs: {})".format(instrs) + + print(optype_info_str) + + summary_str = "{0:46}: {1:4}".format("Number of all operators", + sum(stats.op_counts.values())) + if verbose == 2: + values = stats.op_instrs.values() + instrs_sum = None if any(x == None for x in values) else sum(values) + instrs_str = instrs_to_str(instrs_sum) + summary_str = summary_str + " \t (total instrs: {0})".format(instrs_str) + + print(summary_str) + print('') + + # Print memory stats + from tensor_printer import ConvertBytesToHuman + print("Expected TOTAL memory: {0}".format(ConvertBytesToHuman(stats.total_memory))) + print("Expected FILLED memory: {0}".format(ConvertBytesToHuman(stats.filled_memory))) + print('') + + +def CalcGraphStats(op_parser): + stats = GraphStats() + + for type_str, oper_list in op_parser.operators_per_type.items(): + # number of occurrence of this operator type + occur = len(oper_list) + stats.accumulate_op_count(type_str, occur) + + # this operator type can be computed? + can_compute = oper_list[0].operation.can_compute + + # total number of instructions of the same operator types + if can_compute: + instrs = sum(operator.operation.TotalInstrNum() for operator in oper_list) + else: + instrs = None + stats.accumulate_op_instr(type_str, instrs) + + total_memory = 0 + filled_memory = 0 # only memory for constant + for tensor in op_parser.GetAllTensors(): + if tensor.tf_buffer.DataLength() != 0: + filled_memory += tensor.memory_size + total_memory += tensor.memory_size + stats.accumulate_filled_memory(filled_memory) + stats.accumulate_total_memory(total_memory) + + return stats diff --git a/tools/tflitefile_tool/model_parser.py b/tools/tflitefile_tool/model_parser.py index 6f9e1c61615..8be1e553403 100755 --- a/tools/tflitefile_tool/model_parser.py +++ b/tools/tflitefile_tool/model_parser.py @@ -27,8 +27,9 @@ import tflite.Model import tflite.SubGraph import argparse +import graph_stats from operator_parser import OperatorParser -from model_printer import ModelPrinter +from subgraph_printer import SubgraphPrinter from model_saver import ModelSaver from perf_predictor import PerfPredictor @@ -73,7 +74,7 @@ def __init__(self, args): self.save_prefix = args.prefix def PrintModel(self, model_name, op_parser): - printer = ModelPrinter(self.print_level, op_parser, model_name) + printer = SubgraphPrinter(self.print_level, op_parser, model_name) if self.print_all_tensor == False: printer.SetPrintSpecificTensors(self.print_tensor_index) @@ -95,18 +96,21 @@ def main(self): buf = bytearray(buf) tf_model = tflite.Model.Model.GetRootAsModel(buf, 0) + stats = graph_stats.GraphStats() # Model file can have many models - # 1st subgraph is main model - model_name = "Main_model" for subgraph_index in range(tf_model.SubgraphsLength()): tf_subgraph = tf_model.Subgraphs(subgraph_index) - if (subgraph_index != 0): - model_name = "Model_#" + str(subgraph_index) + model_name = "#{0} {1}".format(subgraph_index, tf_subgraph.Name()) + # 0th subgraph is main subgraph + if (subgraph_index == 0): + model_name += " (MAIN)" # Parse Operators op_parser = OperatorParser(tf_model, tf_subgraph, PerfPredictor()) op_parser.Parse() + stats += graph_stats.CalcGraphStats(op_parser) + if self.save == False: # print all of operators or requested objects self.PrintModel(model_name, op_parser) @@ -114,6 +118,10 @@ def main(self): # save all of operators in this model self.SaveModel(model_name, op_parser) + print('==== Model Stats ({} Subgraphs) ===='.format(tf_model.SubgraphsLength())) + print('') + graph_stats.PrintGraphStats(stats, self.print_level) + if __name__ == '__main__': # Define argument and read diff --git a/tools/tflitefile_tool/model_saver.py b/tools/tflitefile_tool/model_saver.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/operator_printer.py b/tools/tflitefile_tool/operator_printer.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/option_printer.py b/tools/tflitefile_tool/option_printer.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/model_printer.py b/tools/tflitefile_tool/subgraph_printer.py old mode 100644 new mode 100755 similarity index 57% rename from tools/tflitefile_tool/model_printer.py rename to tools/tflitefile_tool/subgraph_printer.py index 0c11d01bda9..4eb310ba044 --- a/tools/tflitefile_tool/model_printer.py +++ b/tools/tflitefile_tool/subgraph_printer.py @@ -16,9 +16,10 @@ from operator_printer import OperatorPrinter from tensor_printer import TensorPrinter +import graph_stats -class ModelPrinter(object): +class SubgraphPrinter(object): def __init__(self, verbose, op_parser, model_name): self.verbose = verbose self.op_parser = op_parser @@ -42,8 +43,8 @@ def PrintInfo(self): if self.print_all_tensor == True and self.print_all_operator == True: self.PrintModelInfo() self.PrintAllOperatorsInList() - self.PrintAllTypesInfo() - self.PrintTotalMemory() + graph_stats.PrintGraphStats( + graph_stats.CalcGraphStats(self.op_parser), self.verbose) if self.print_all_tensor == False: print('') @@ -73,48 +74,6 @@ def PrintAllOperatorsInList(self): print('') - def PrintAllTypesInfo(self): - print("Number of all operator types: {0}".format( - len(self.op_parser.operators_per_type))) - - # number of instructions of all operator types to print if verbose level is 2 - total_instrs = 0 - - # (a string of the operator type, a list of operators which are the same operator type) - for type_str, oper_list in self.op_parser.operators_per_type.items(): - # number of occurrence of this operator type - occur = len(oper_list) - - optype_info_str = "\t{type_str:38}: {occur:4}".format( - type_str=type_str, occur=occur) - - if self.verbose == 2: - # this operator type can be computed? - can_compute = oper_list[0].operation.can_compute - - # total number of instructions of the same operator types - if can_compute: - instrs = sum( - operator.operation.TotalInstrNum() for operator in oper_list) - total_instrs = total_instrs + instrs - instrs = "{:,}".format(instrs) - else: - instrs = "???" - - optype_info_str = optype_info_str + " \t (instrs: {instrs})".format( - instrs=instrs) - - print(optype_info_str) - - summary_str = "{0:46}: {1:4}".format("Number of all operators", - len(self.op_parser.operators_in_list)) - if self.verbose == 2: - total_instrs = "{:,}".format(total_instrs) - summary_str = summary_str + " \t (total instrs: {0})".format(total_instrs) - - print(summary_str) - print('') - def PrintSpecificTensors(self): for tensor in self.op_parser.GetAllTensors(): if tensor.tensor_idx in self.print_tensor_index_list: @@ -131,16 +90,3 @@ def PrintSpecificOperators(self): print('') print('') - - def PrintTotalMemory(self): - total_memory = 0 - filled_memory = 0 # only memory for constant - for tensor in self.op_parser.GetAllTensors(): - if tensor.tf_buffer.DataLength() != 0: - filled_memory += tensor.memory_size - total_memory += tensor.memory_size - - from tensor_printer import ConvertBytesToHuman - print("Expected TOTAL memory: {0}".format(ConvertBytesToHuman(total_memory))) - print("Expected FILLED memory: {0}".format(ConvertBytesToHuman(filled_memory))) - print('') diff --git a/tools/tflitefile_tool/tensor_printer.py b/tools/tflitefile_tool/tensor_printer.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/AbsOptions.py b/tools/tflitefile_tool/tflite/AbsOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/ActivationFunctionType.py b/tools/tflitefile_tool/tflite/ActivationFunctionType.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/AddNOptions.py b/tools/tflitefile_tool/tflite/AddNOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/AddOptions.py b/tools/tflitefile_tool/tflite/AddOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/ArgMaxOptions.py b/tools/tflitefile_tool/tflite/ArgMaxOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/ArgMinOptions.py b/tools/tflitefile_tool/tflite/ArgMinOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/BatchToSpaceNDOptions.py b/tools/tflitefile_tool/tflite/BatchToSpaceNDOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/BidirectionalSequenceLSTMOptions.py b/tools/tflitefile_tool/tflite/BidirectionalSequenceLSTMOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/BidirectionalSequenceRNNOptions.py b/tools/tflitefile_tool/tflite/BidirectionalSequenceRNNOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/Buffer.py b/tools/tflitefile_tool/tflite/Buffer.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/BuiltinOperator.py b/tools/tflitefile_tool/tflite/BuiltinOperator.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/BuiltinOptions.py b/tools/tflitefile_tool/tflite/BuiltinOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/CallOptions.py b/tools/tflitefile_tool/tflite/CallOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/CastOptions.py b/tools/tflitefile_tool/tflite/CastOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/CombinerType.py b/tools/tflitefile_tool/tflite/CombinerType.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/ConcatEmbeddingsOptions.py b/tools/tflitefile_tool/tflite/ConcatEmbeddingsOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/ConcatenationOptions.py b/tools/tflitefile_tool/tflite/ConcatenationOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/Conv2DOptions.py b/tools/tflitefile_tool/tflite/Conv2DOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/CosOptions.py b/tools/tflitefile_tool/tflite/CosOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/CustomOptionsFormat.py b/tools/tflitefile_tool/tflite/CustomOptionsFormat.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/CustomQuantization.py b/tools/tflitefile_tool/tflite/CustomQuantization.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/DepthToSpaceOptions.py b/tools/tflitefile_tool/tflite/DepthToSpaceOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/DepthwiseConv2DOptions.py b/tools/tflitefile_tool/tflite/DepthwiseConv2DOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/DequantizeOptions.py b/tools/tflitefile_tool/tflite/DequantizeOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/DivOptions.py b/tools/tflitefile_tool/tflite/DivOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/EmbeddingLookupSparseOptions.py b/tools/tflitefile_tool/tflite/EmbeddingLookupSparseOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/EqualOptions.py b/tools/tflitefile_tool/tflite/EqualOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/ExpOptions.py b/tools/tflitefile_tool/tflite/ExpOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/ExpandDimsOptions.py b/tools/tflitefile_tool/tflite/ExpandDimsOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/FakeQuantOptions.py b/tools/tflitefile_tool/tflite/FakeQuantOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/FillOptions.py b/tools/tflitefile_tool/tflite/FillOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/FloorDivOptions.py b/tools/tflitefile_tool/tflite/FloorDivOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/FloorModOptions.py b/tools/tflitefile_tool/tflite/FloorModOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/FullyConnectedOptions.py b/tools/tflitefile_tool/tflite/FullyConnectedOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/FullyConnectedOptionsWeightsFormat.py b/tools/tflitefile_tool/tflite/FullyConnectedOptionsWeightsFormat.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/GatherNdOptions.py b/tools/tflitefile_tool/tflite/GatherNdOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/GatherOptions.py b/tools/tflitefile_tool/tflite/GatherOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/GreaterEqualOptions.py b/tools/tflitefile_tool/tflite/GreaterEqualOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/GreaterOptions.py b/tools/tflitefile_tool/tflite/GreaterOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/HardSwishOptions.py b/tools/tflitefile_tool/tflite/HardSwishOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/IfOptions.py b/tools/tflitefile_tool/tflite/IfOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/L2NormOptions.py b/tools/tflitefile_tool/tflite/L2NormOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/LSHProjectionOptions.py b/tools/tflitefile_tool/tflite/LSHProjectionOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/LSHProjectionType.py b/tools/tflitefile_tool/tflite/LSHProjectionType.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/LSTMKernelType.py b/tools/tflitefile_tool/tflite/LSTMKernelType.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/LSTMOptions.py b/tools/tflitefile_tool/tflite/LSTMOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/LeakyReluOptions.py b/tools/tflitefile_tool/tflite/LeakyReluOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/LessEqualOptions.py b/tools/tflitefile_tool/tflite/LessEqualOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/LessOptions.py b/tools/tflitefile_tool/tflite/LessOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/LocalResponseNormalizationOptions.py b/tools/tflitefile_tool/tflite/LocalResponseNormalizationOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/LogSoftmaxOptions.py b/tools/tflitefile_tool/tflite/LogSoftmaxOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/LogicalAndOptions.py b/tools/tflitefile_tool/tflite/LogicalAndOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/LogicalNotOptions.py b/tools/tflitefile_tool/tflite/LogicalNotOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/LogicalOrOptions.py b/tools/tflitefile_tool/tflite/LogicalOrOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/MatrixDiagOptions.py b/tools/tflitefile_tool/tflite/MatrixDiagOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/MatrixSetDiagOptions.py b/tools/tflitefile_tool/tflite/MatrixSetDiagOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/MaximumMinimumOptions.py b/tools/tflitefile_tool/tflite/MaximumMinimumOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/Metadata.py b/tools/tflitefile_tool/tflite/Metadata.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/MirrorPadMode.py b/tools/tflitefile_tool/tflite/MirrorPadMode.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/MirrorPadOptions.py b/tools/tflitefile_tool/tflite/MirrorPadOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/Model.py b/tools/tflitefile_tool/tflite/Model.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/MulOptions.py b/tools/tflitefile_tool/tflite/MulOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/NegOptions.py b/tools/tflitefile_tool/tflite/NegOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/NonMaxSuppressionV4Options.py b/tools/tflitefile_tool/tflite/NonMaxSuppressionV4Options.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/NonMaxSuppressionV5Options.py b/tools/tflitefile_tool/tflite/NonMaxSuppressionV5Options.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/NotEqualOptions.py b/tools/tflitefile_tool/tflite/NotEqualOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/OneHotOptions.py b/tools/tflitefile_tool/tflite/OneHotOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/Operator.py b/tools/tflitefile_tool/tflite/Operator.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/OperatorCode.py b/tools/tflitefile_tool/tflite/OperatorCode.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/PackOptions.py b/tools/tflitefile_tool/tflite/PackOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/PadOptions.py b/tools/tflitefile_tool/tflite/PadOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/PadV2Options.py b/tools/tflitefile_tool/tflite/PadV2Options.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/Padding.py b/tools/tflitefile_tool/tflite/Padding.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/Pool2DOptions.py b/tools/tflitefile_tool/tflite/Pool2DOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/PowOptions.py b/tools/tflitefile_tool/tflite/PowOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/QuantizationDetails.py b/tools/tflitefile_tool/tflite/QuantizationDetails.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/QuantizationParameters.py b/tools/tflitefile_tool/tflite/QuantizationParameters.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/QuantizeOptions.py b/tools/tflitefile_tool/tflite/QuantizeOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/RNNOptions.py b/tools/tflitefile_tool/tflite/RNNOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/RangeOptions.py b/tools/tflitefile_tool/tflite/RangeOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/RankOptions.py b/tools/tflitefile_tool/tflite/RankOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/ReducerOptions.py b/tools/tflitefile_tool/tflite/ReducerOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/ReshapeOptions.py b/tools/tflitefile_tool/tflite/ReshapeOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/ResizeBilinearOptions.py b/tools/tflitefile_tool/tflite/ResizeBilinearOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/ResizeNearestNeighborOptions.py b/tools/tflitefile_tool/tflite/ResizeNearestNeighborOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/ReverseSequenceOptions.py b/tools/tflitefile_tool/tflite/ReverseSequenceOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/ReverseV2Options.py b/tools/tflitefile_tool/tflite/ReverseV2Options.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/SVDFOptions.py b/tools/tflitefile_tool/tflite/SVDFOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/ScatterNdOptions.py b/tools/tflitefile_tool/tflite/ScatterNdOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/SelectOptions.py b/tools/tflitefile_tool/tflite/SelectOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/SequenceRNNOptions.py b/tools/tflitefile_tool/tflite/SequenceRNNOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/ShapeOptions.py b/tools/tflitefile_tool/tflite/ShapeOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/SkipGramOptions.py b/tools/tflitefile_tool/tflite/SkipGramOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/SliceOptions.py b/tools/tflitefile_tool/tflite/SliceOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/SoftmaxOptions.py b/tools/tflitefile_tool/tflite/SoftmaxOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/SpaceToBatchNDOptions.py b/tools/tflitefile_tool/tflite/SpaceToBatchNDOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/SpaceToDepthOptions.py b/tools/tflitefile_tool/tflite/SpaceToDepthOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/SparseToDenseOptions.py b/tools/tflitefile_tool/tflite/SparseToDenseOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/SplitOptions.py b/tools/tflitefile_tool/tflite/SplitOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/SplitVOptions.py b/tools/tflitefile_tool/tflite/SplitVOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/SquareOptions.py b/tools/tflitefile_tool/tflite/SquareOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/SquaredDifferenceOptions.py b/tools/tflitefile_tool/tflite/SquaredDifferenceOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/SqueezeOptions.py b/tools/tflitefile_tool/tflite/SqueezeOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/StridedSliceOptions.py b/tools/tflitefile_tool/tflite/StridedSliceOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/SubGraph.py b/tools/tflitefile_tool/tflite/SubGraph.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/SubOptions.py b/tools/tflitefile_tool/tflite/SubOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/Tensor.py b/tools/tflitefile_tool/tflite/Tensor.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/TensorType.py b/tools/tflitefile_tool/tflite/TensorType.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/TileOptions.py b/tools/tflitefile_tool/tflite/TileOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/TopKV2Options.py b/tools/tflitefile_tool/tflite/TopKV2Options.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/TransposeConvOptions.py b/tools/tflitefile_tool/tflite/TransposeConvOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/TransposeOptions.py b/tools/tflitefile_tool/tflite/TransposeOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/UnidirectionalSequenceLSTMOptions.py b/tools/tflitefile_tool/tflite/UnidirectionalSequenceLSTMOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/UniqueOptions.py b/tools/tflitefile_tool/tflite/UniqueOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/UnpackOptions.py b/tools/tflitefile_tool/tflite/UnpackOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/WhereOptions.py b/tools/tflitefile_tool/tflite/WhereOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/WhileOptions.py b/tools/tflitefile_tool/tflite/WhileOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/ZerosLikeOptions.py b/tools/tflitefile_tool/tflite/ZerosLikeOptions.py old mode 100644 new mode 100755 diff --git a/tools/tflitefile_tool/tflite/__init__.py b/tools/tflitefile_tool/tflite/__init__.py old mode 100644 new mode 100755 diff --git a/tools/tflkit/summarize_pb.py b/tools/tflkit/summarize_pb.py old mode 100644 new mode 100755