Unverified Commit 54e5a816 authored by Robert Kimball's avatar Robert Kimball Committed by GitHub

Fix SUSE build and run errors (#1284)

* build on suse w/gcc 4.8.5

* fix SUSE build error

* add comments

* remove template function

* update per review comment

* fix nan check emitted code
parent c6a0fae3
......@@ -49,6 +49,7 @@
#include "header_resource.hpp"
#include "ngraph/codegen/compiler.hpp"
#include "ngraph/file_util.hpp"
#include "ngraph/log.hpp"
#include "ngraph/util.hpp"
#if defined(__clang__)
......@@ -424,19 +425,25 @@ void codegen::CompilerCore::configure_search_path()
add_header_search_path(CLANG_BUILTIN_HEADERS_PATH);
string header_version = find_header_version("/usr/include/c++");
string os_specific_path =
find_os_specific_path(file_util::path_join("/usr/include/c++", header_version));
// /usr/include/c++/7
add_header_search_path("/usr/include/c++/" + header_version);
add_header_search_path(file_util::path_join("/usr/include/c++/", header_version));
// /usr/include/x86_64-linux-gnu/c++/7
add_header_search_path("/usr/include/x86_64-linux-gnu/c++/" + header_version);
add_header_search_path(
file_util::path_join("/usr/include/x86_64-linux-gnu/c++/", header_version));
add_header_search_path("/usr/lib/gcc/x86_64-linux-gnu/" + header_version + "/include");
add_header_search_path(
file_util::path_join("/usr/lib/gcc/x86_64-linux-gnu/", header_version, "/include"));
add_header_search_path("/usr/local/include");
add_header_search_path("/usr/lib/gcc/x86_64-linux-gnu/" + header_version + "/include-fixed");
add_header_search_path(
file_util::path_join("/usr/include/c++/", header_version, os_specific_path));
add_header_search_path(
file_util::path_join("/usr/lib/gcc/x86_64-linux-gnu/", header_version, "/include-fixed"));
add_header_search_path("/usr/include/x86_64-linux-gnu");
add_header_search_path("/usr/include");
add_header_search_path("/usr/include/c++/" + header_version + "/x86_64-redhat-linux");
add_header_search_path(EIGEN_HEADERS_PATH);
add_header_search_path(MKLDNN_HEADERS_PATH);
......@@ -512,3 +519,25 @@ string codegen::CompilerCore::find_header_version(const string& path)
}
return rc;
}
string codegen::CompilerCore::find_os_specific_path(const string& path)
{
string rc;
auto f = [&](const std::string& file, bool is_dir) {
if (is_dir)
{
const string prefix = "x86_64-";
const string suffix = "-linux";
string path = file_util::get_file_name(file);
if (path.size() > (prefix.size() + suffix.size()) &&
path.compare(0, prefix.size(), prefix) == 0 &&
path.compare(path.size() - suffix.size(), suffix.size(), suffix) == 0)
{
rc = path.substr(prefix.size(), path.size() - prefix.size() - suffix.size());
rc = prefix + rc + suffix;
}
}
};
file_util::iterate_files(path, f);
return rc;
}
......@@ -96,6 +96,7 @@ private:
bool is_version_number(const std::string& path);
std::string find_header_version(const std::string& path);
std::string find_os_specific_path(const std::string& path);
void configure_search_path();
void load_headers_from_resource();
};
......@@ -73,6 +73,16 @@ string file_util::get_directory(const string& s)
return rc;
}
string file_util::path_join(const string& s1, const string& s2, const string& s3)
{
return path_join(path_join(s1, s2), s3);
}
string file_util::path_join(const string& s1, const string& s2, const string& s3, const string& s4)
{
return path_join(path_join(path_join(s1, s2), s3), s4);
}
string file_util::path_join(const string& s1, const string& s2)
{
string rc;
......
......@@ -40,6 +40,11 @@ namespace ngraph
// @param s1 Left side of path
// @param s2 Right side of path
std::string path_join(const std::string& s1, const std::string& s2);
std::string path_join(const std::string& s1, const std::string& s2, const std::string& s3);
std::string path_join(const std::string& s1,
const std::string& s2,
const std::string& s3,
const std::string& s4);
// @brief Returns the size in bytes of filename
// @param filename The name of the file
......
......@@ -171,8 +171,8 @@ static void
auto ctype = node->get_element_type().c_type_string();
writer << "{ // A " << funcname << " for" << node->get_name() << "\n";
writer.indent++;
writer << " ngraph::check_fp_values<" << ctype << "," << funcname << "> (\"" << node->get_name()
<< "\", (" << ctype << "*)" << out[0].get_name() << ", " << out[0].get_size() << ");\n";
writer << " ngraph::check_fp_values_" << funcname << "(\"" << node->get_name() << "\", ("
<< ctype << "*)" << out[0].get_name() << ", " << out[0].get_size() << ");\n";
writer.indent--;
writer << "}\n";
}
......@@ -819,12 +819,12 @@ using namespace ngraph::runtime;
{
if (std::getenv("NGRAPH_CPU_NAN_CHECK"))
{
generate_isnan_isinf_check(writer, node, out, "std::isnan");
generate_isnan_isinf_check(writer, node, out, "isnan");
}
if (std::getenv("NGRAPH_CPU_INF_CHECK"))
{
generate_isnan_isinf_check(writer, node, out, "std::isinf");
generate_isnan_isinf_check(writer, node, out, "isinf");
}
}
}
......
......@@ -387,3 +387,47 @@ std::ostream& operator<<(std::ostream& os, const ngraph::NodeVector& nv)
os << vector_to_string(names);
return os;
}
void ngraph::check_fp_values_isinf(const char* name, const float* array, size_t n)
{
for (size_t i = 0; i < n; i++)
{
if (isinf(array[i]))
{
throw std::runtime_error("Discovered Inf in '" + string(name) + "'");
}
}
}
void ngraph::check_fp_values_isinf(const char* name, const double* array, size_t n)
{
for (size_t i = 0; i < n; i++)
{
if (isinf(array[i]))
{
throw std::runtime_error("Discovered Inf in '" + string(name) + "'");
}
}
}
void ngraph::check_fp_values_isnan(const char* name, const float* array, size_t n)
{
for (size_t i = 0; i < n; i++)
{
if (isinf(array[i]))
{
throw std::runtime_error("Discovered NaN in '" + string(name) + "'");
}
}
}
void ngraph::check_fp_values_isnan(const char* name, const double* array, size_t n)
{
for (size_t i = 0; i < n; i++)
{
if (isinf(array[i]))
{
throw std::runtime_error("Discovered NaN in '" + string(name) + "'");
}
}
}
......@@ -212,29 +212,10 @@ namespace ngraph
return y > x ? 0 : x - y;
}
template <typename T, bool (*func)(T)>
void check_fp_values(const char* name, const T* array, size_t n)
{
bool (*fPtr)(T) = &std::isinf;
const char* cerr_type = fPtr == func ? "Inf" : "NaN";
for (size_t i = 0; i < n; i++)
{
if (func(array[i]))
{
throw std::runtime_error(std::string("Discovered ") + cerr_type + " in '" + name +
"'");
}
}
}
template void
check_fp_values<float, std::isinf>(const char* name, const float* array, size_t n);
template void
check_fp_values<float, std::isnan>(const char* name, const float* array, size_t n);
template void
check_fp_values<double, std::isinf>(const char* name, const double* array, size_t n);
template void
check_fp_values<double, std::isnan>(const char* name, const double* array, size_t n);
void check_fp_values_isinf(const char* name, const float* array, size_t n);
void check_fp_values_isinf(const char* name, const double* array, size_t n);
void check_fp_values_isnan(const char* name, const float* array, size_t n);
void check_fp_values_isnan(const char* name, const double* array, size_t n);
void* aligned_alloc(size_t alignment, size_t size);
void aligned_free(void*);
......
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