Unverified Commit d3a8e62a authored by Robert Kimball's avatar Robert Kimball Committed by GitHub

[MLIR] Add some sane utilities for environment variable handling (#4103)

* Add env_util files and update getenv_bool

* More getenv cleanup

* More env cleanup

* Add env var file

* fix doc file

* cleanup

* Update doc string

* Fix compile errors

* Fix compile error

* Fix compile error

* Fix one more

* Fix compile error

* Revert MLIR changes due to failing test

* Revert MLIR changes due to failing test

* Fix compile error

* Fix env var usage
Co-authored-by: 's avatarSang Ik Lee <sang.ik.lee@intel.com>
Co-authored-by: 's avatarScott Cyphers <diyessi@users.noreply.github.com>
parent ec935c0b
# Environment Variables
| Name | Default | Description |
| ------------------------------------|:---:| --- |
| NGRAPH_CODEGEN | |
| NGRAPH_COMPILER_DEBUGINFO_ENABLE | |
| NGRAPH_COMPILER_DIAG_ENABLE | |
| NGRAPH_COMPILER_REPORT_ENABLE | |
| NGRAPH_CPU_BIN_TRACER_LOG | |
| NGRAPH_CPU_CHECK_PARMS_AND_CONSTS | |
| NGRAPH_CPU_CONCURRENCY | |
| NGRAPH_CPU_DEBUG_TRACER | |
| NGRAPH_CPU_EIGEN_THREAD_COUNT | |
| NGRAPH_CPU_INF_CHECK | |
| NGRAPH_CPU_NAN_CHECK | |
| NGRAPH_CPU_TRACER_LOG | |
| NGRAPH_CPU_TRACING | |
| NGRAPH_CPU_USE_REF_KERNELS | |
| NGRAPH_CPU_USE_TBB | |
| NGRAPH_DECONV_FUSE | |
| NGRAPH_DEX_DEBUG | |
| NGRAPH_DISABLE_LOGGING | |
| NGRAPH_DISABLED_FUSIONS | |
| NGRAPH_ENABLE_REPLACE_CHECK | |
| NGRAPH_ENABLE_SERIALIZE_TRACING | |
| NGRAPH_ENABLE_TRACING | |
| NGRAPH_ENABLE_VISUALIZE_TRACING | |
| NGRAPH_FAIL_MATCH_AT | |
| NGRAPH_GRAPH_REWRITE_RERUN_DYNAMIC_CHECK | |
| NGRAPH_GTEST_INFO | |
| NGRAPH_INTER_OP_PARALLELISM | |
| NGRAPH_INTRA_OP_PARALLELISM | |
| NGRAPH_MLIR | |
| NGRAPH_MLIR_MAX_CYCLE_DEPTH | |
| NGRAPH_MLIR_OPT_LEVEL | |
| NGRAPH_MLIR_OPTIONS | |
| NGRAPH_PASS_ATTRIBUTES | |
| NGRAPH_PASS_CPU_LAYOUT_ELTWISE | |
| NGRAPH_PASS_ENABLES | |
| NGRAPH_PROFILE_PASS_ENABLE | |
| NGRAPH_PROVENANCE_ENABLE | |
| NGRAPH_SERIALIZER_OUTPUT_SHAPES | |
| NGRAPH_VISUALIZE_EDGE_JUMP_DISTANCE | |
| NGRAPH_VISUALIZE_EDGE_LABELS | |
| NGRAPH_VISUALIZE_TRACING_FORMAT | |
| NGRAPH_VISUALIZE_TREE_OUTPUT_SHAPES | |
| NGRAPH_VISUALIZE_TREE_OUTPUT_TYPES | |
| OMP_NUM_THREADS | |
......@@ -81,6 +81,8 @@ set (SRC
distributed.cpp
distributed.hpp
enum_names.hpp
env_util.cpp
env_util.hpp
except.hpp
factory.cpp
factory.hpp
......
......@@ -49,6 +49,7 @@
#include "header_resource.hpp"
#include "ngraph/codegen/compiler.hpp"
#include "ngraph/env_util.hpp"
#include "ngraph/file_util.hpp"
#include "ngraph/log.hpp"
#include "ngraph/util.hpp"
......@@ -156,9 +157,9 @@ static std::string GetExecutablePath(const char* Argv0)
}
codegen::CompilerCore::CompilerCore()
: m_debuginfo_enabled((std::getenv("NGRAPH_COMPILER_DEBUGINFO_ENABLE") != nullptr))
, m_enable_diag_output((std::getenv("NGRAPH_COMPILER_DIAG_ENABLE") != nullptr))
, m_enable_pass_report((std::getenv("NGRAPH_COMPILER_REPORT_ENABLE") != nullptr))
: m_debuginfo_enabled(getenv_bool("NGRAPH_COMPILER_DEBUGINFO_ENABLE"))
, m_enable_diag_output(getenv_bool("NGRAPH_COMPILER_DIAG_ENABLE"))
, m_enable_pass_report(getenv_bool("NGRAPH_COMPILER_REPORT_ENABLE"))
, m_source_name("code.cpp")
{
initialize();
......
......@@ -16,6 +16,7 @@
#include "ngraph/descriptor/input.hpp"
#include "ngraph/descriptor/output.hpp"
#include "ngraph/env_util.hpp"
#include "ngraph/node.hpp"
#include "ngraph/type/element_type.hpp"
......@@ -57,9 +58,7 @@ void descriptor::Input::replace_output(Output& new_output)
m_output = &new_output;
m_src_node = std::shared_ptr<Node>(new_output.get_node());
static const auto nerc = std::getenv("NGRAPH_ENABLE_REPLACE_CHECK");
if (nerc)
if (getenv_bool("NGRAPH_ENABLE_REPLACE_CHECK"))
{
// the result of copy_with_new_args will be thrown away or
// an exception will be thrown by `m_node`'s class c-tor
......
//*****************************************************************************
// Copyright 2017-2019 Intel Corporation
//
// 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 <sstream>
#include "ngraph/env_util.hpp"
#include "ngraph/util.hpp"
using namespace std;
std::string ngraph::getenv_string(const char* env_var)
{
const char* env_p = ::getenv(env_var);
string env_string = env_p ? env_p : "";
return env_string;
}
int32_t ngraph::getenv_int(const char* env_var, int32_t default_value)
{
const char* env_p = ::getenv(env_var);
int32_t env = default_value;
// If env_var is not "" or undefined
if (env_p && *env_p)
{
errno = 0;
char* err;
env = strtol(env_p, &err, 0);
// if conversion leads to an overflow
if (errno)
{
std::stringstream ss;
ss << "Environment variable \"" << env_var << "\"=\"" << env_p
<< "\" converted to different value \"" << env << "\" due to overflow." << std::endl;
throw runtime_error(ss.str());
}
// if syntax error is there - conversion will still happen
// but warn user of syntax error
if (*err)
{
std::stringstream ss;
ss << "Environment variable \"" << env_var << "\"=\"" << env_p
<< "\" converted to different value \"" << env << "\" due to syntax error \"" << err
<< '\"' << std::endl;
throw runtime_error(ss.str());
}
}
else
{
NGRAPH_DEBUG << "Environment variable (" << env_var << ") empty or undefined, "
<< " defaulted to -1 here.";
}
return env;
}
bool ngraph::getenv_bool(const char* env_var, bool default_value)
{
string value = to_lower(getenv_string(env_var));
set<string> off = {"0", "false", "off"};
set<string> on = {"1", "true", "on"};
bool rc;
if (value == "")
{
rc = default_value;
}
else if (off.find(value) != off.end())
{
rc = false;
}
else if (on.find(value) != on.end())
{
rc = true;
}
else
{
stringstream ss;
ss << "environment variable '" << env_var << "' value '" << value
<< "' invalid. Must be boolean.";
throw runtime_error(ss.str());
}
return rc;
}
//*****************************************************************************
// Copyright 2017-2019 Intel Corporation
//
// 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.
//*****************************************************************************
#pragma once
#include <string>
namespace ngraph
{
/// \brief Get the names environment variable as a string.
/// \param env_var The string name of the environment variable to get.
/// \return Returns string by value or an empty string if the environment
/// variable is not set.
std::string getenv_string(const char* env_var);
/// \brief Get the names environment variable as an integer. If the value is not a
/// valid integer then an exception is thrown.
/// \param env_var The string name of the environment variable to get.
/// \param default_value The value to return if the environment variable is not set.
/// \return Returns value or default_value if the environment variable is not set.
int32_t getenv_int(const char* env_var, int32_t default_value = -1);
/// \brief Get the names environment variable as a boolean. If the value is not a
/// valid boolean then an exception is thrown. Valid booleans are one of
/// 1, 0, on, off, true, false
/// All values are case insensitive.
/// If the environment variable is not set the default_value is returned.
/// \param env_var The string name of the environment variable to get.
/// \param default_value The value to return if the environment variable is not set.
/// \return Returns the boolean value of the environment variable.
bool getenv_bool(const char* env_var, bool default_value = false);
}
......@@ -20,18 +20,14 @@
#include "distributed.hpp"
#include "event_tracing.hpp"
#include "ngraph/env_util.hpp"
#include "nlohmann/json.hpp"
using namespace std;
static bool read_tracing_env_var()
{
return (std::getenv("NGRAPH_ENABLE_TRACING") != nullptr);
}
NGRAPH_API mutex ngraph::Event::s_file_mutex;
NGRAPH_API ofstream ngraph::Event::s_event_log;
NGRAPH_API bool ngraph::Event::s_tracing_enabled = read_tracing_env_var();
NGRAPH_API bool ngraph::Event::s_tracing_enabled = ngraph::getenv_bool("NGRAPH_ENABLE_TRACING");
NGRAPH_API bool ngraph::Event::s_event_writer_registered = false;
NGRAPH_API std::function<void(const ngraph::Event& event)> ngraph::Event::s_event_writer;
......
......@@ -33,6 +33,7 @@
#include <sys/types.h>
#include <vector>
#include "ngraph/env_util.hpp"
#include "ngraph/file_util.hpp"
#include "ngraph/log.hpp"
......@@ -185,16 +186,16 @@ string file_util::get_temp_directory_path()
{
const vector<string> potential_tmps = {"NGRAPH_TMP", "TMPDIR", "TMP", "TEMP", "TEMPDIR"};
const char* path = nullptr;
string path;
for (const string& var : potential_tmps)
{
path = getenv(var.c_str());
if (path != nullptr)
path = getenv_string(var.c_str());
if (!path.empty())
{
break;
}
}
if (path == nullptr)
if (path.empty())
{
path = "/tmp";
}
......
......@@ -22,6 +22,7 @@
#include <mutex>
#include <thread>
#include "ngraph/env_util.hpp"
#include "ngraph/log.hpp"
using namespace std;
......@@ -122,7 +123,7 @@ void ngraph::LogPrintf(const char* fmt, ...)
// This function will be executed only once during startup (loading of the DSO)
static bool CheckLoggingLevel()
{
if (std::getenv("NGRAPH_DISABLE_LOGGING") != nullptr)
if (getenv_bool("NGRAPH_DISABLE_LOGGING"))
{
return true;
}
......
......@@ -21,6 +21,7 @@
#include <vector>
#include "graph_rewrite.hpp"
#include "ngraph/env_util.hpp"
#include "ngraph/log.hpp"
using namespace std;
......@@ -68,8 +69,7 @@ bool pass::GraphRewrite::run_on_function(shared_ptr<Function> f)
vector<MatchClosure> original_matchers{m_matchers};
// This check is very expensive and is only needed for experimental features, so we will hide
// it behind an environment variable for now. TODO: Find a less expensive way to handle this.
static bool s_rerun_dynamic_check =
(std::getenv("NGRAPH_GRAPH_REWRITE_RERUN_DYNAMIC_CHECK") != nullptr);
static bool s_rerun_dynamic_check = getenv_bool("NGRAPH_GRAPH_REWRITE_RERUN_DYNAMIC_CHECK");
bool is_dyn_func = s_rerun_dynamic_check && f->is_dynamic();
do
{
......@@ -124,11 +124,10 @@ bool pass::GraphRewrite::run_on_function(shared_ptr<Function> f)
static vector<regex> initialize_fusion_regexes()
{
const char* cnsf = getenv("NGRAPH_DISABLED_FUSIONS");
static const string nsf = getenv_string("NGRAPH_DISABLED_FUSIONS");
vector<regex> regexes;
if (cnsf)
if (!nsf.empty())
{
const string nsf = cnsf;
const auto sregexes = split(nsf, ';');
transform(sregexes.begin(),
......@@ -210,8 +209,7 @@ bool pass::RecurrentGraphRewrite::run_on_function(shared_ptr<Function> f)
// This check is very expensive and is only needed for experimental features, so we will hide
// it behind an environment variable for now. TODO: Find a less expensive way to handle this.
static bool s_rerun_dynamic_check =
(std::getenv("NGRAPH_GRAPH_REWRITE_RERUN_DYNAMIC_CHECK") != nullptr);
static bool s_rerun_dynamic_check = getenv_bool("NGRAPH_GRAPH_REWRITE_RERUN_DYNAMIC_CHECK");
auto run_matchers = [&]() -> bool {
bool is_dyn_func = s_rerun_dynamic_check && f->is_dynamic();
......
......@@ -23,6 +23,7 @@
#include <iostream>
#include <memory>
#include "ngraph/env_util.hpp"
#include "ngraph/function.hpp"
#include "ngraph/graph_util.hpp"
#include "ngraph/node.hpp"
......@@ -36,17 +37,10 @@ using namespace std;
using namespace ngraph;
pass::Manager::Manager()
: m_visualize(getenv_bool("NGRAPH_ENABLE_VISUALIZE_TRACING"))
, m_serialize(getenv_bool("NGRAPH_ENABLE_SERIALIZE_TRACING"))
{
static const auto nevt = std::getenv("NGRAPH_ENABLE_VISUALIZE_TRACING");
if (nevt)
{
m_visualize = true;
}
static const auto nest = std::getenv("NGRAPH_ENABLE_SERIALIZE_TRACING");
if (nest)
{
m_serialize = true;
}
}
pass::Manager::~Manager()
......@@ -55,7 +49,7 @@ pass::Manager::~Manager()
void pass::Manager::run_passes(shared_ptr<Function> func, bool /* transitive */)
{
static bool profile_enabled = getenv("NGRAPH_PROFILE_PASS_ENABLE") != nullptr;
static bool profile_enabled = getenv_bool("NGRAPH_PROFILE_PASS_ENABLE");
get_state().set_function(func);
vector<std::pair<shared_ptr<Function>, bool>> fs{std::make_pair(func, func->is_dynamic())};
......@@ -145,8 +139,8 @@ void pass::Manager::run_passes(shared_ptr<Function> func, bool /* transitive */)
if (m_visualize)
{
auto format = std::getenv("NGRAPH_VISUALIZE_TRACING_FORMAT");
auto file_ext = format ? std::string(format) : std::string("svg");
static const string format = getenv_string("NGRAPH_VISUALIZE_TRACING_FORMAT");
auto file_ext = format.empty() ? "svg" : format;
pass::VisualizeTree vt(base_filename + std::string(".") + file_ext);
vt.set_ops_to_details(get_state().get_visualize_tree_ops_map());
vt.run_on_module(f_array);
......
......@@ -15,6 +15,7 @@
//*****************************************************************************
#include "ngraph/pass/pass_config.hpp"
#include "ngraph/env_util.hpp"
#include "ngraph/except.hpp"
#include "ngraph/log.hpp"
#include "ngraph/util.hpp"
......@@ -32,11 +33,11 @@ pass::PassConfig::PassConfig()
// E.g., NGRAPH_PASS_ENABLES="CoreFusion:0;LikeReplacement:1;CPUCollapseDims" would
// set disables on CoreFusion and enables on LikeReplacement and CPUCollapseDims
//
const char* env_str = getenv("NGRAPH_PASS_ENABLES");
if (env_str)
string pass_enables = getenv_string("NGRAPH_PASS_ENABLES");
if (!pass_enables.empty())
{
stringstream ss;
ss << env_str;
ss << pass_enables;
while (ss.good())
{
string substr;
......@@ -60,11 +61,11 @@ pass::PassConfig::PassConfig()
// would set false on "OptimizeForMemory", true on "MemoryAssignment::ReuseMemory" and true on
// "UseDefaultLayouts"
//
env_str = getenv("NGRAPH_PASS_ATTRIBUTES");
if (env_str)
static const string pass_attributes = getenv_string("NGRAPH_PASS_ATTRIBUTES");
if (!pass_attributes.empty())
{
stringstream ss;
ss << env_str;
ss << pass_attributes;
while (ss.good())
{
string substr;
......
......@@ -16,6 +16,7 @@
#include <fstream>
#include "ngraph/env_util.hpp"
#include "ngraph/file_util.hpp"
#include "ngraph/function.hpp"
#include "ngraph/graph_util.hpp"
......@@ -158,7 +159,7 @@ static std::string label_edge(const std::shared_ptr<Node>& /* src */,
int64_t jump_distance)
{
std::stringstream ss;
if (getenv("NGRAPH_VISUALIZE_EDGE_LABELS") != nullptr)
if (getenv_bool("NGRAPH_VISUALIZE_EDGE_LABELS"))
{
size_t output = 0;
if (auto goe = as_type_ptr<op::GetOutputElement>(dst))
......@@ -170,7 +171,7 @@ static std::string label_edge(const std::shared_ptr<Node>& /* src */,
ss << label_edge.str();
}
else if (getenv("NGRAPH_VISUALIZE_EDGE_JUMP_DISTANCE") != nullptr)
else if (getenv_bool("NGRAPH_VISUALIZE_EDGE_JUMP_DISTANCE"))
{
if (jump_distance > 1)
{
......@@ -367,8 +368,8 @@ string pass::VisualizeTree::get_attributes(shared_ptr<Node> node)
stringstream label;
label << "label=\"" << get_node_name(node);
static const char* nvtos = getenv("NGRAPH_VISUALIZE_TREE_OUTPUT_SHAPES");
if (nvtos != nullptr)
static const bool nvtos = getenv_bool("NGRAPH_VISUALIZE_TREE_OUTPUT_SHAPES");
if (nvtos)
{
// The shapes of the Outputs of a multi-output op
// will be printed for its corresponding `GetOutputElement`s
......@@ -377,8 +378,8 @@ string pass::VisualizeTree::get_attributes(shared_ptr<Node> node)
: pretty_partial_shape(node->get_output_partial_shape(0)));
}
static const char* nvtot = getenv("NGRAPH_VISUALIZE_TREE_OUTPUT_TYPES");
if (nvtot != nullptr)
static const bool nvtot = getenv_bool("NGRAPH_VISUALIZE_TREE_OUTPUT_TYPES");
if (nvtot)
{
// The types of the Outputs of a multi-output op
// will be printed for its corresponding `GetOutputElement`s
......
......@@ -18,6 +18,7 @@
#include <regex>
#include "matcher.hpp"
#include "ngraph/env_util.hpp"
#include "ngraph/graph_util.hpp"
#include "ngraph/log.hpp"
#include "ngraph/op/get_output_element.hpp"
......@@ -109,8 +110,8 @@ namespace ngraph
// This env var allows one to specify node name patterns to abort pattern matching
// at particular nodes. The upshot is that one can quickly zero in on an offending
// fusion by disabling individual fusions or optimizations that use Matcher.
static const char* node_skip_cregex = std::getenv("NGRAPH_FAIL_MATCH_AT");
if (node_skip_cregex)
static const std::string node_skip_cregex = getenv_string("NGRAPH_FAIL_MATCH_AT");
if (!node_skip_cregex.empty())
{
static const std::regex node_skip_regex(node_skip_cregex);
if (std::regex_match(graph_node->get_name(), node_skip_regex))
......
......@@ -18,9 +18,11 @@
#include <cstdlib>
#include "ngraph/env_util.hpp"
namespace ngraph
{
static bool s_provenance_enabled = std::getenv("NGRAPH_PROVENANCE_ENABLE") != nullptr;
static bool s_provenance_enabled = getenv_bool("NGRAPH_PROVENANCE_ENABLE");
void set_provenance_enabled(bool enabled);
bool get_provenance_enabled();
}
......@@ -20,6 +20,7 @@
#include <string>
#include "chrome_trace.hpp"
#include "ngraph/env_util.hpp"
#include "ngraph/log.hpp"
using namespace std;
......@@ -27,7 +28,7 @@ using namespace ngraph;
static bool read_tracing_env_var()
{
static const bool is_enabled = (getenv("NGRAPH_ENABLE_TRACING") != nullptr);
static const bool is_enabled = getenv_bool("NGRAPH_ENABLE_TRACING");
return is_enabled;
}
......
......@@ -20,6 +20,7 @@
#include <stack>
#include "ngraph/cpio.hpp"
#include "ngraph/env_util.hpp"
#include "ngraph/file_util.hpp"
#include "ngraph/graph_util.hpp"
#include "ngraph/ops.hpp"
......@@ -33,8 +34,7 @@ using namespace std;
using json = nlohmann::json;
using const_data_callback_t = shared_ptr<Node>(const string&, const element::Type&, const Shape&);
static bool s_serialize_output_shapes_enabled =
(std::getenv("NGRAPH_SERIALIZER_OUTPUT_SHAPES") != nullptr);
static bool s_serialize_output_shapes_enabled = getenv_bool("NGRAPH_SERIALIZER_OUTPUT_SHAPES");
void ngraph::set_serialize_output_shapes(bool enable)
{
......
......@@ -22,6 +22,7 @@
#include "gtest/gtest.h"
#include "ngraph/env_util.hpp"
#include "ngraph/ngraph.hpp"
#include "util/all_close_f.hpp"
#include "util/float_util.hpp"
......@@ -104,7 +105,7 @@ protected:
TEST_P(all_close_f_param_test, test_boundaries)
{
if (std::getenv("NGRAPH_GTEST_INFO") != nullptr)
if (getenv_bool("NGRAPH_GTEST_INFO"))
{
// Print short string documenting which test is being run
std::cout << "[ INFO ] Test params: (" << expected << ", " << tolerance_bits << ")\n";
......@@ -261,7 +262,7 @@ protected:
TEST_P(all_close_f_double_param_test, test_boundaries)
{
if (std::getenv("NGRAPH_GTEST_INFO") != nullptr)
if (getenv_bool("NGRAPH_GTEST_INFO"))
{
// Print short string documenting which test is being run
std::cout << "[ INFO ] Test params: (" << expected << ", " << tolerance_bits << ")\n";
......
......@@ -22,6 +22,7 @@
#include "ngraph/codegen/compiler.hpp"
#include "ngraph/codegen/execution_engine.hpp"
#include "ngraph/env_util.hpp"
#include "ngraph/file_util.hpp"
#include "ngraph/log.hpp"
#include "ngraph/op/concat.hpp"
......@@ -63,7 +64,7 @@ TEST(benchmark, concat_32x1x200_axis1_6)
}
}
bool using_ref_kernels = (std::getenv("NGRAPH_CPU_USE_REF_KERNELS") != nullptr);
bool using_ref_kernels = getenv_bool("NGRAPH_CPU_USE_REF_KERNELS");
vector<std::string> backend_names{"INTERPRETER", "CPU"};
vector<int> n_runs{200, 200, using_ref_kernels ? 200 : 200000}; // one for each backend
......
......@@ -22,6 +22,7 @@
#include "gtest/gtest.h"
#include "ngraph/autodiff/adjoints.hpp"
#include "ngraph/env_util.hpp"
#include "ngraph/file_util.hpp"
#include "ngraph/graph_util.hpp"
#include "ngraph/log.hpp"
......@@ -40,14 +41,8 @@ using namespace std;
bool static is_codegen_mode()
{
static bool codegen_set = false;
static bool codegen_mode = false;
if (!codegen_set)
{
const char* ngraph_codegen = std::getenv("NGRAPH_CODEGEN");
codegen_mode = (ngraph_codegen != nullptr) && std::string(ngraph_codegen) != "0";
codegen_set = true;
}
static bool codegen_mode = getenv_bool("NGRAPH_CODEGEN");
;
return codegen_mode;
}
......
......@@ -23,6 +23,7 @@
#include "gtest/gtest.h"
#include "misc.hpp"
#include "ngraph/autodiff/adjoints.hpp"
#include "ngraph/env_util.hpp"
#include "ngraph/file_util.hpp"
#include "ngraph/graph_util.hpp"
#include "ngraph/log.hpp"
......@@ -1210,7 +1211,7 @@ shared_ptr<Function> gen_deconv(const bool add_goe)
TEST(cpu_fusion, fuse_deconv)
{
bool use_deconv_fuse = (getenv("NGRAPH_DECONV_FUSE") != nullptr);
bool use_deconv_fuse = (getenv_bool("NGRAPH_DECONV_FUSE"));
if (!use_deconv_fuse)
{
set_environment("NGRAPH_DECONV_FUSE", "1", 1);
......
......@@ -24,6 +24,7 @@
#include "gtest/gtest.h"
#include "misc.hpp"
#include "ngraph/autodiff/adjoints.hpp"
#include "ngraph/env_util.hpp"
#include "ngraph/file_util.hpp"
#include "ngraph/graph_util.hpp"
#include "ngraph/log.hpp"
......@@ -139,7 +140,7 @@ TEST(cpu_test, abc_tbb)
{
// Force TBB flow graph generation in the CPU backend
// This has no effect on other backends
bool use_tbb = (getenv("NGRAPH_CPU_USE_TBB") != nullptr);
bool use_tbb = getenv_bool("NGRAPH_CPU_USE_TBB");
if (!use_tbb)
{
set_environment("NGRAPH_CPU_USE_TBB", "1", 1);
......@@ -968,14 +969,7 @@ constexpr int tolerance = FLOAT_MANTISSA_BITS - three_quarters_of_available_bits
bool static is_codegen_mode()
{
static bool codegen_set = false;
static bool codegen_mode = false;
if (!codegen_set)
{
const char* ngraph_codegen = std::getenv("NGRAPH_CODEGEN");
codegen_mode = (ngraph_codegen != nullptr) && std::string(ngraph_codegen) != "0";
codegen_set = true;
}
static bool codegen_mode = getenv_bool("NGRAPH_CODEGEN");
return codegen_mode;
}
......
......@@ -17,6 +17,7 @@
#include <climits>
#include <cmath>
#include "ngraph/env_util.hpp"
#include "ngraph/util.hpp"
#include "util/all_close_f.hpp"
......@@ -404,7 +405,7 @@ uint32_t test::matching_mantissa_bits(uint64_t distance)
}
bool all_below_min_signal = below_min_count == distances.size();
if (rc && (std::getenv("NGRAPH_GTEST_INFO") != nullptr))
if (rc && (getenv_bool("NGRAPH_GTEST_INFO")))
{
// Short unobtrusive message when passing
std::cout << "[ INFO ] Verifying match of <= " << (FLOAT_MANTISSA_BITS - tolerance_bits)
......@@ -536,7 +537,7 @@ uint32_t test::matching_mantissa_bits(uint64_t distance)
}
bool all_below_min_signal = below_min_count == distances.size();
if (rc && (std::getenv("NGRAPH_GTEST_INFO") != nullptr))
if (rc && (getenv_bool("NGRAPH_GTEST_INFO")))
{
// Short unobtrusive message when passing
std::cout << "[ INFO ] Verifying match of >= "
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment