forked from Samsung/ONE
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- This patch is based on d9bb6af23b6f69d03acb Signed-off-by: nnfw-bot <[email protected]>
- Loading branch information
Showing
2,032 changed files
with
34,430 additions
and
11,457 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# circle2circle | ||
|
||
_circle2circle_ provides Circle optimizations and quantizations as executable tool |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <loco.h> | ||
#include <luci/CircleExporter.h> | ||
#include <mio/circle/schema_generated.h> | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
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__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <mio/circle/schema_generated.h> | ||
|
||
#include <memory> | ||
|
||
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<Model> load_model(const std::string &path); | ||
|
||
} // namespace luci | ||
|
||
#endif // __CIRCLE2CIRCLE_MODEL_H__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <luci/Importer.h> | ||
#include <luci/CircleOptimizer.h> | ||
#include <luci/Service/Validate.h> | ||
#include <luci/CircleExporter.h> | ||
|
||
#include <stdex/Memory.h> | ||
#include <oops/InternalExn.h> | ||
|
||
#include <functional> | ||
#include <iostream> | ||
#include <map> | ||
#include <string> | ||
|
||
using OptionHook = std::function<int(const char **)>; | ||
|
||
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<std::string, OptionHook> 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<luci::Model> 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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <gtest/gtest.h> | ||
|
||
TEST(Circle2CircleTest, NoArg_NEG) | ||
{ | ||
Argv<1> argv; | ||
argv.add("circle2circle"); | ||
|
||
::testing::internal::CaptureStdout(); | ||
int result = entry(1, argv.argv()); | ||
ASSERT_EQ(result, 255); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <oops/InternalExn.h> | ||
|
||
#include <fstream> | ||
#include <iostream> | ||
|
||
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(); | ||
} |
Oops, something went wrong.