Commit a99859d9 authored by Sang Ik Lee's avatar Sang Ik Lee Committed by Scott Cyphers

Improve pragma usage. (#3355)

parent 2765573c
......@@ -105,12 +105,16 @@ void ngraph::LogPrintf(const char* fmt, ...)
va_start(args1, fmt);
va_list args2;
va_copy(args2, args1);
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
#endif
std::vector<char> buf(1 + std::vsnprintf(nullptr, 0, fmt, args1));
va_end(args1);
std::vsnprintf(buf.data(), buf.size(), fmt, args2);
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
va_end(args2);
get_distributed_interface()->log_print(get_timestamp(), buf);
}
......
......@@ -52,7 +52,7 @@ op::Constant::~Constant()
string op::Constant::convert_value_to_string(size_t index) const
{
string rc;
#if !(defined(__GNUC__) && (__GNUC__ == 4 && __GNUC_MINOR__ == 8))
#if defined(__GNUC__) && !(__GNUC__ == 4 && __GNUC_MINOR__ == 8)
#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Wswitch"
#pragma GCC diagnostic error "-Wswitch-enum"
......@@ -79,7 +79,7 @@ string op::Constant::convert_value_to_string(size_t index) const
case element::Type_t::undefined: throw runtime_error("unsupported type");
case element::Type_t::dynamic: throw runtime_error("unsupported type");
}
#if !(defined(__GNUC__) && (__GNUC__ == 4 && __GNUC_MINOR__ == 8))
#if defined(__GNUC__) && !(__GNUC__ == 4 && __GNUC_MINOR__ == 8)
#pragma GCC diagnostic pop
#endif
return rc;
......@@ -89,7 +89,7 @@ vector<string> op::Constant::get_value_strings() const
{
vector<string> rc;
#if !(defined(__GNUC__) && (__GNUC__ == 4 && __GNUC_MINOR__ == 8))
#if defined(__GNUC__) && !(__GNUC__ == 4 && __GNUC_MINOR__ == 8)
#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Wswitch"
#pragma GCC diagnostic error "-Wswitch-enum"
......@@ -177,7 +177,7 @@ vector<string> op::Constant::get_value_strings() const
case element::Type_t::undefined: throw runtime_error("unsupported type");
case element::Type_t::dynamic: throw runtime_error("unsupported type");
}
#if !(defined(__GNUC__) && (__GNUC__ == 4 && __GNUC_MINOR__ == 8))
#if defined(__GNUC__) && !(__GNUC__ == 4 && __GNUC_MINOR__ == 8)
#pragma GCC diagnostic pop
#endif
......@@ -285,9 +285,11 @@ static bool test_bitwise_identical(const op::Constant* constant)
bool op::Constant::are_all_data_elements_bitwise_identical() const
{
bool rc = false;
#if defined(__GNUC__) && !(__GNUC__ == 4 && __GNUC_MINOR__ == 8)
#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Wswitch"
#pragma GCC diagnostic error "-Wswitch-enum"
#endif
switch (get_element_type().get_type_enum())
{
case element::Type_t::boolean:
......@@ -322,7 +324,9 @@ bool op::Constant::are_all_data_elements_bitwise_identical() const
case element::Type_t::undefined:
case element::Type_t::dynamic: break;
}
#if defined(__GNUC__) && !(__GNUC__ == 4 && __GNUC_MINOR__ == 8)
#pragma GCC diagnostic pop
#endif
return rc;
}
......
......@@ -293,7 +293,7 @@ namespace ngraph
{
throw std::runtime_error("Constant initializer does not match shape");
}
#if !(defined(__GNUC__) && (__GNUC__ == 4 && __GNUC_MINOR__ == 8))
#if defined(__GNUC__) && !(__GNUC__ == 4 && __GNUC_MINOR__ == 8)
#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Wswitch"
#pragma GCC diagnostic error "-Wswitch-enum"
......@@ -342,7 +342,7 @@ namespace ngraph
case element::Type_t::undefined: throw std::runtime_error("unsupported type");
case element::Type_t::dynamic: throw std::runtime_error("unsupported type");
}
#if !(defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ == 8)
#if defined(__GNUC__) && !(__GNUC__ == 4 && __GNUC_MINOR__ == 8)
#pragma GCC diagnostic pop
#endif
}
......
......@@ -795,7 +795,7 @@ template <typename TI>
shared_ptr<op::Constant> fold_constant_convert_helper0(shared_ptr<op::Constant> constant,
const element::Type& output_element_type)
{
#if !(defined(__GNUC__) && (__GNUC__ == 4 && __GNUC_MINOR__ == 8))
#if defined(__GNUC__) && !(__GNUC__ == 4 && __GNUC_MINOR__ == 8)
#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Wswitch"
#pragma GCC diagnostic error "-Wswitch-enum"
......@@ -835,7 +835,7 @@ shared_ptr<op::Constant> fold_constant_convert_helper0(shared_ptr<op::Constant>
case element::Type_t::u64:
return fold_constant_convert_helper1<TI, uint64_t>(constant, output_element_type);
}
#if !(defined(__GNUC__) && (__GNUC__ == 4 && __GNUC_MINOR__ == 8))
#if defined(__GNUC__) && !(__GNUC__ == 4 && __GNUC_MINOR__ == 8)
#pragma GCC diagnostic pop
#endif
}
......@@ -850,7 +850,7 @@ static shared_ptr<op::Constant> fold_constant_convert(shared_ptr<op::Constant> c
return constant;
}
#if !(defined(__GNUC__) && (__GNUC__ == 4 && __GNUC_MINOR__ == 8))
#if defined(__GNUC__) && !(__GNUC__ == 4 && __GNUC_MINOR__ == 8)
#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Wswitch"
#pragma GCC diagnostic error "-Wswitch-enum"
......@@ -890,7 +890,7 @@ static shared_ptr<op::Constant> fold_constant_convert(shared_ptr<op::Constant> c
case element::Type_t::u64:
return fold_constant_convert_helper0<uint64_t>(constant, output_element_type);
}
#if !(defined(__GNUC__) && (__GNUC__ == 4 && __GNUC_MINOR__ == 8))
#if defined(__GNUC__) && !(__GNUC__ == 4 && __GNUC_MINOR__ == 8)
#pragma GCC diagnostic pop
#endif
}
......
......@@ -49,14 +49,18 @@ namespace ngraph
auto out0_buffer_index = external_function->get_buffer_index(out[0].get_name());
// Kill clang diagnostics bug
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmissing-braces"
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-braces"
#endif
array<size_t, 2> weight_sizes{
args[0].get_size() * args[0].get_element_type().size(),
args[1].get_size() * args[1].get_element_type().size()};
#pragma GCC diagnostic pop
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
shared_ptr<uint8_t> stacked_weights(new uint8_t[weight_sizes[0] + weight_sizes[1]],
std::default_delete<uint8_t[]>());
......@@ -396,14 +400,18 @@ namespace ngraph
auto out2_buffer_index = external_function->get_buffer_index(out[2].get_name());
// Kill clang diagnostics bug
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmissing-braces"
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-braces"
#endif
array<size_t, 2> weight_sizes{
args[0].get_size() * args[0].get_element_type().size(),
args[1].get_size() * args[1].get_element_type().size()};
#pragma GCC diagnostic pop
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
shared_ptr<uint8_t> stacked_weights(new uint8_t[weight_sizes[0] + weight_sizes[1]],
std::default_delete<uint8_t[]>());
shared_ptr<uint8_t> stacked_dweights(new uint8_t[weight_sizes[0] + weight_sizes[1]],
......
......@@ -1154,14 +1154,18 @@ void ngraph::runtime::cpu::pass::CPUFusion::construct_leaky_relu()
auto alpha_vec = alpha_const_op->get_vector<float>();
for (auto val : alpha_vec)
{
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
#endif
if (val != alpha_vec[0])
{
NGRAPH_DEBUG << "alpha is not a singular constant";
return false;
}
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
}
if (alpha_vec[0] < 0)
......
......@@ -141,8 +141,10 @@ bool runtime::gcpu::GCPUExecutable::call(const vector<shared_ptr<runtime::Tensor
// get op type
element::Type type;
#if defined(__GNUC__) && !(__GNUC__ == 4 && __GNUC_MINOR__ == 8)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wswitch-enum"
#endif
switch (type_id)
{
case OP_TYPEID::Convert:
......@@ -164,7 +166,9 @@ bool runtime::gcpu::GCPUExecutable::call(const vector<shared_ptr<runtime::Tensor
case OP_TYPEID::TopK: type = op->get_output_element_type(1); break;
default: type = op->get_output_element_type(0); break;
}
#if defined(__GNUC__) && !(__GNUC__ == 4 && __GNUC_MINOR__ == 8)
#pragma GCC diagnostic pop
#endif
if (m_performance_counters_enabled)
{
......
......@@ -194,7 +194,7 @@ private:
// We want to check that every OP_TYPEID enumeration is included in the list.
// These GCC flags enable compile-time checking so that if an enumeration
// is not in the list an error is generated.
#if !(defined(__GNUC__) && (__GNUC__ == 4 && __GNUC_MINOR__ == 8))
#if defined(__GNUC__) && !(__GNUC__ == 4 && __GNUC_MINOR__ == 8)
#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Wswitch"
#pragma GCC diagnostic error "-Wswitch-enum"
......@@ -1378,7 +1378,7 @@ private:
break;
}
default: throw unsupported_op("Unsupported op '" + node.description() + "'");
#if !(defined(__GNUC__) && (__GNUC__ == 4 && __GNUC_MINOR__ == 8))
#if defined(__GNUC__) && !(__GNUC__ == 4 && __GNUC_MINOR__ == 8)
#pragma GCC diagnostic pop
#endif
}
......
......@@ -460,7 +460,7 @@ shared_ptr<runtime::Executable>
// We want to check that every OP_TYPEID enumeration is included in the list.
// These GCC flags enable compile-time checking so that if an enumeration
// is not in the list an error is generated.
#if !(defined(__GNUC__) && (__GNUC__ == 4 && __GNUC_MINOR__ == 8))
#if defined(__GNUC__) && !(__GNUC__ == 4 && __GNUC_MINOR__ == 8)
#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Wswitch"
#pragma GCC diagnostic error "-Wswitch-enum"
......@@ -2098,7 +2098,7 @@ shared_ptr<runtime::Executable>
throw unsupported_op("Unsupported op '" + op->description() +
"' in IntelGPU back end.");
}
#if !(defined(__GNUC__) && (__GNUC__ == 4 && __GNUC_MINOR__ == 8))
#if defined(__GNUC__) && !(__GNUC__ == 4 && __GNUC_MINOR__ == 8)
#pragma GCC diagnostic pop
#endif
}
......
......@@ -160,8 +160,10 @@ bool runtime::interpreter::INTExecutable::call(const vector<shared_ptr<runtime::
// get op type
element::Type type;
#if defined(__GNUC__) && !(__GNUC__ == 4 && __GNUC_MINOR__ == 8)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wswitch-enum"
#endif
switch (type_id)
{
case OP_TYPEID::Convert:
......@@ -183,7 +185,9 @@ bool runtime::interpreter::INTExecutable::call(const vector<shared_ptr<runtime::
case OP_TYPEID::TopK: type = op->get_output_element_type(1); break;
default: type = op->get_output_element_type(0); break;
}
#if defined(__GNUC__) && !(__GNUC__ == 4 && __GNUC_MINOR__ == 8)
#pragma GCC diagnostic pop
#endif
if (m_performance_counters_enabled)
{
......
......@@ -211,7 +211,7 @@ private:
// We want to check that every OP_TYPEID enumeration is included in the list.
// These GCC flags enable compile-time checking so that if an enumeration
// is not in the list an error is generated.
#if !(defined(__GNUC__) && (__GNUC__ == 4 && __GNUC_MINOR__ == 8))
#if defined(__GNUC__) && !(__GNUC__ == 4 && __GNUC_MINOR__ == 8)
#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Wswitch"
#pragma GCC diagnostic error "-Wswitch-enum"
......@@ -1461,7 +1461,7 @@ private:
case OP_TYPEID::DynPad:
case OP_TYPEID::Tile:
default: throw unsupported_op("Unsupported op '" + node.description() + "'");
#if !(defined(__GNUC__) && (__GNUC__ == 4 && __GNUC_MINOR__ == 8))
#if defined(__GNUC__) && !(__GNUC__ == 4 && __GNUC_MINOR__ == 8)
#pragma GCC diagnostic pop
#endif
}
......
......@@ -16,8 +16,10 @@
#pragma once
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
#endif
#include <cstddef>
......@@ -42,4 +44,6 @@ namespace ngraph
}
}
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
......@@ -16,8 +16,10 @@
#pragma once
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
#endif
#include <cstddef>
......@@ -42,4 +44,6 @@ namespace ngraph
}
}
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
......@@ -35,13 +35,17 @@ namespace ngraph
{
// this is intentional to be able to compare floats directly
// without using relative or absolute tolerance
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
#endif
if (std::get<0>(a) == std::get<0>(b))
{
return std::get<1>(a) < std::get<1>(b);
}
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
return a > b;
}
......
......@@ -526,7 +526,7 @@ static shared_ptr<ngraph::Function>
{
args.push_back(node_map.at(name));
}
#if !(defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ == 8)
#if defined(__GNUC__) && !(__GNUC__ == 4 && __GNUC_MINOR__ == 8)
#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Wswitch"
#pragma GCC diagnostic error "-Wswitch-enum"
......@@ -1599,7 +1599,7 @@ static shared_ptr<ngraph::Function>
throw runtime_error(ss.str());
}
}
#if !(defined(__GNUC__) && (__GNUC__ == 4 && __GNUC_MINOR__ == 8))
#if defined(__GNUC__) && !(__GNUC__ == 4 && __GNUC_MINOR__ == 8)
#pragma GCC diagnostic pop
#endif
......
......@@ -75,10 +75,14 @@ size_t bfloat16::size() const
bool bfloat16::operator==(const bfloat16& other) const
{
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
#endif
return (static_cast<float>(*this) == static_cast<float>(other));
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
}
bool bfloat16::operator<(const bfloat16& other) const
......
......@@ -97,10 +97,14 @@ size_t float16::size() const
bool float16::operator==(const float16& other) const
{
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
#endif
return (static_cast<float>(*this) == static_cast<float>(other));
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
}
bool float16::operator<(const float16& other) const
......
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