From 62c85df69934e87bb63128b70f4e655b0f346c53 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=9C=A4=ED=98=84=EC=8B=9D/On-Device=20Lab=28SR=29/Princip?= =?utf8?q?al=20Engineer/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Wed, 12 Jun 2019 17:51:58 +0900 Subject: [PATCH] [moco/tf] class storing user-provided compiler arguments (#3734) * [moco/tf] class storing user-provided compiler arguments When a user run the compiler with arguments, these arguments are parsed and stored into this class. Signed-off-by: Hyun Sik Yoon * Using default constructor --- contrib/moco/lib/frontend/tf/src/CompilerArgs.h | 85 ++++++++++++++++++++++ .../moco/lib/frontend/tf/src/CompilerArgs.test.cpp | 29 ++++++++ 2 files changed, 114 insertions(+) create mode 100644 contrib/moco/lib/frontend/tf/src/CompilerArgs.h create mode 100644 contrib/moco/lib/frontend/tf/src/CompilerArgs.test.cpp diff --git a/contrib/moco/lib/frontend/tf/src/CompilerArgs.h b/contrib/moco/lib/frontend/tf/src/CompilerArgs.h new file mode 100644 index 0000000..7529935 --- /dev/null +++ b/contrib/moco/lib/frontend/tf/src/CompilerArgs.h @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2019 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 __COMPILER_ARGS_H +#define __COMPILER_ARGS_H + +#include + +#include +#include + +namespace moco +{ +namespace tf +{ + +/** + * @brief Class that stores parsed arguments passed from command line interface. + * Command line parser should fill member vars of the instance of this class. + */ +class CompilerArgs final +{ +public: + /** + * @brief Adds graph input name and its shape provided from user + */ + void addInput(const std::string &input_name, const nncc::core::ADT::tensor::Shape &shape) + { + if (_inputs.find(input_name) != _inputs.end()) + throw std::runtime_error{"Duplicated input name: " + input_name}; + + _inputs[input_name] = shape; + } + + const nncc::core::ADT::tensor::Shape *getInputShape(const std::string &input_name) + { + auto res = _inputs.find(input_name); + if (res == _inputs.end()) + return nullptr; + else + return &res->second; + } + +public: + /** + * @brief function to get a singleton instance + */ + static CompilerArgs *get() + { + static CompilerArgs me; + return &me; + } + + /** + * @brief Clears all data. Only for testing purpose. + */ + void clear() { _inputs.clear(); } + +private: + CompilerArgs() = default; + +private: + // For command line argument input shapes and input names + std::map _inputs; + + // add more compiler arguments +}; + +} // namespace tf +} // namespace moco + +#endif // __COMPILER_ARGS_H diff --git a/contrib/moco/lib/frontend/tf/src/CompilerArgs.test.cpp b/contrib/moco/lib/frontend/tf/src/CompilerArgs.test.cpp new file mode 100644 index 0000000..1cf2150 --- /dev/null +++ b/contrib/moco/lib/frontend/tf/src/CompilerArgs.test.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2019 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 "CompilerArgs.h" + +#include + +#include + +TEST(CompilerArgs, inputShape_empty) +{ + auto args = moco::tf::CompilerArgs::get(); + + std::string any_name = "any"; + ASSERT_TRUE(args->getInputShape(any_name) == nullptr); +} -- 2.7.4