#include <tflite/Assert.h>
#include <tflite/NNAPISession.h>
-#include <misc/environment.h>
#include <misc/benchmark.h>
#include <cpp14/memory.h>
# Library `nnfw_lib_misc`
-set(NNFW_UTILITY_SRCS src/environment.cpp)
-list(APPEND NNFW_UTILITY_SRCS src/tensor/Shape.cpp)
+set(NNFW_UTILITY_SRCS src/tensor/Shape.cpp)
list(APPEND NNFW_UTILITY_SRCS src/tensor/NonIncreasingStride.cpp)
list(APPEND NNFW_UTILITY_SRCS src/tensor/IndexFormatter.cpp)
list(APPEND NNFW_UTILITY_SRCS src/tensor/Comparator.cpp)
return std::stoi(_value);
}
+ /**
+ * @brief Get environment variable of float type
+ * @param[in] def Default value of environment variable
+ * @return Defaut value passed as a parameter when there is no environment variable,
+ * otherwise the value of environment variable passed into constructor
+ */
+ float asFloat(float def) const
+ {
+ if (_value.empty())
+ return def;
+ return std::stof(_value);
+ }
+
private:
std::string _value;
};
+++ /dev/null
-/*
- * 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.
- */
-
-/**
- * @file environment.h
- * @ingroup COM_AI_RUNTIME
- * @brief This file contains utility functions and classes to access environment variables
- */
-
-#ifndef __UTIL_ENVIRONMENT_H__
-#define __UTIL_ENVIRONMENT_H__
-
-namespace nnfw
-{
-namespace misc
-{
-
-/**
- * @brief Get the environment variable of int type
- * @param[in] name Name of the environment variable
- * @param[in] defaultValue Default value when the value of environment variable does not exist
- * @return The int value of the environment variable
- */
-int get_env_int(const char *name, int defaultValue = 0);
-
-/**
- * @brief Get the environment variable of bool type
- * @param[in] name Name of the environment variable
- * @param[in] defaultValue Default value when the value of environment variable does not exist
- * @return @c 0 if the value of the environment variable is @c "0", @c 1 in case of other number
- */
-bool get_env_bool(const char *name, bool defaultValue = false);
-}
-}
-
-#include <string>
-
-namespace nnfw
-{
-namespace misc
-{
-namespace env
-{
-/**
- * @brief Parent struct of @ref IntAccessor and @ref FloatAccessor
- * @tparam T Type of the value of environment variable
- */
-template <typename T> struct Accessor
-{
- /**
- * @brief Destroy the Accessor object
- */
- virtual ~Accessor() = default;
- /**
- * @brief Read the value of environment variable
- * @param[out] out The value of environment variable
- * @return @c true if accessing environment variable is successful,
- * @c false if there is exist no such environment variable
- */
- virtual bool access(T &out) const = 0;
-};
-
-/**
- * @brief Class to read int environment variable
- */
-class IntAccessor : public Accessor<int>
-{
-public:
- /**
- * @brief Construct a new IntAccessor object
- * @param[in] tag Name of environment variable
- */
- IntAccessor(const std::string &tag);
-
-public:
- /**
- * @brief Read the value of environment variable
- * @param[out] out The value of environment variable
- * @return @c true if accessing environment variable is successful,
- * @c false if there is exist no such environment variable
- */
- bool access(int &out) const override;
-
-private:
- std::string _tag;
-};
-
-/**
- * @brief Class to read float environment variable
- */
-class FloatAccessor : public Accessor<float>
-{
-public:
- /**
- * @brief Construct a new FloatAccessor object
- * @param[in] tag Name of environment variable
- */
- FloatAccessor(const std::string &tag);
-
-public:
- /**
- * @brief Read the value of environment variable
- * @param[out] out The value of environment variable
- * @return @c true if accessing environment variable is successful,
- * @c false if there is exist no such environment variable
- */
- bool access(float &out) const override;
-
-private:
- std::string _tag;
-};
-
-} // namespace env
-} // namespace misc
-} // namespace nnfw
-
-#endif // __UTIL_ENVIRONMENT_H__
+++ /dev/null
-/*
- * 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 <string.h>
-#include <cstdlib>
-#include <string>
-
-#include "misc/environment.h"
-
-namespace nnfw
-{
-namespace misc
-{
-
-int get_env_int(const char *name, int defaultValue)
-{
- const char *value = std::getenv(name);
- if (value != nullptr)
- return std::stoi(value);
- return defaultValue;
-}
-
-bool get_env_bool(const char *name, bool defaultValue)
-{
- const char *value = std::getenv(name);
- if (value != nullptr)
- {
- return std::stoi(value) != 0;
- }
-
- return defaultValue;
-}
-
-} // namespace misc
-} // namespace nnfw
-
-namespace nnfw
-{
-namespace misc
-{
-namespace env
-{
-
-IntAccessor::IntAccessor(const std::string &tag) : _tag{tag}
-{
- // DO NOTHING
-}
-
-bool IntAccessor::access(int &out) const
-{
- auto value = std::getenv(_tag.c_str());
-
- if (value == nullptr)
- {
- return false;
- }
-
- out = std::stoi(value);
- return true;
-}
-
-FloatAccessor::FloatAccessor(const std::string &tag) : _tag{tag}
-{
- // DO NOTHING
-}
-
-bool FloatAccessor::access(float &out) const
-{
- auto value = std::getenv(_tag.c_str());
-
- if (value == nullptr)
- {
- return false;
- }
-
- out = std::stof(value);
- return true;
-}
-
-} // namespace env
-} // namespace misc
-} // namespace nnfw
#include "misc/tensor/Zipper.h"
#include "misc/tensor/Comparator.h"
-#include "misc/environment.h"
+#include "misc/EnvVar.h"
#include <iostream>
#include <cassert>
{
RandomTestParam param;
- param.verbose = 0;
- param.tolerance = 1;
-
- nnfw::misc::env::IntAccessor("VERBOSE").access(param.verbose);
- nnfw::misc::env::IntAccessor("TOLERANCE").access(param.tolerance);
+ param.verbose = nnfw::misc::EnvVar("VERBOSE").asInt(0);
+ param.tolerance = nnfw::misc::EnvVar("TOLERANCE").asInt(1);
+ ;
return RandomTestRunner{seed, param};
}
#include <iostream>
#include <thread>
-#include "misc/environment.h"
+#include "misc/EnvVar.h"
#include "misc/benchmark.h"
using namespace tflite;
const auto filename = argv[1];
- const bool use_nnapi = nnfw::misc::get_env_bool("USE_NNAPI");
- const auto thread_count = nnfw::misc::get_env_int("THREAD", -1);
- const auto pause = nnfw::misc::get_env_int("PAUSE", 0);
+ const bool use_nnapi = nnfw::misc::EnvVar("USE_NNAPI").asBool(false);
+ const auto thread_count = nnfw::misc::EnvVar("THREAD").asInt(-1);
+ const auto pause = nnfw::misc::EnvVar("PAUSE").asInt(0);
std::cout << "Num threads: " << thread_count << std::endl;
if (use_nnapi)
//
// Measure
//
- const auto cnt = nnfw::misc::get_env_int("COUNT", 1);
+ const auto cnt = nnfw::misc::EnvVar("COUNT").asInt(1);
using namespace boost::accumulators;
#include "tensor_dumper.h"
#include "tensor_loader.h"
#include "misc/benchmark.h"
-#include "misc/environment.h"
+#include "misc/EnvVar.h"
#include "misc/fp32.h"
#include "tflite/Diff.h"
#include "tflite/Assert.h"
TFLITE_ENSURE(builder(&interpreter))
- interpreter->SetNumThreads(nnfw::misc::get_env_int("THREAD", -1));
+ interpreter->SetNumThreads(nnfw::misc::EnvVar("THREAD").asInt(-1));
};
}
catch (const std::exception &e)
// TODO Code duplication (copied from RandomTestRunner)
- int tolerance = 1;
- nnfw::misc::env::IntAccessor("TOLERANCE").access(tolerance);
+ int tolerance = nnfw::misc::EnvVar("TOLERANCE").asInt(1);
auto equals = [tolerance](float lhs, float rhs) {
// NOTE Hybrid approach