From 4e73cc83d6d646f2c8ee52ba3ee90dc5669b1bef Mon Sep 17 00:00:00 2001 From: Chih-Hsuan Yen Date: Thu, 16 Dec 2021 09:08:57 +0800 Subject: [PATCH] Fix building DNNL EP with clang (#10014) Before this change, building DNNL EP from onnxruntime 1.10.0 with clang fails with: In file included from /build/python-onnxruntime/src/onnxruntime/onnxruntime/core/providers/dnnl/subgraph/dnnl_squeeze.cc:4: In file included from /build/python-onnxruntime/src/onnxruntime/onnxruntime/core/providers/dnnl/subgraph/dnnl_squeeze.h:5: In file included from /build/python-onnxruntime/src/onnxruntime/onnxruntime/core/providers/dnnl/subgraph/dnnl_subgraph.h:10: In file included from /build/python-onnxruntime/src/onnxruntime/onnxruntime/core/providers/shared_library/provider_api.h:19: In file included from /build/python-onnxruntime/src/onnxruntime/include/onnxruntime/core/common/common.h:36: /build/python-onnxruntime/src/onnxruntime/include/onnxruntime/core/common/make_string.h:33:6: error: call to function 'operator<<' that is neither visible in the template definition nor found by argument-dependent lookup ss << t; ^ /build/python-onnxruntime/src/onnxruntime/include/onnxruntime/core/common/make_string.h:39:3: note: in instantiation of function template specialization 'onnxruntime::detail::MakeStringImpl>' requested here MakeStringImpl(ss, args...); ^ /build/python-onnxruntime/src/onnxruntime/include/onnxruntime/core/common/make_string.h:39:3: note: in instantiation of function template specialization 'onnxruntime::detail::MakeStringImpl>' requested here /build/python-onnxruntime/src/onnxruntime/include/onnxruntime/core/common/make_string.h:39:3: note: in instantiation of function template specialization 'onnxruntime::detail::MakeStringImpl>' requested here /build/python-onnxruntime/src/onnxruntime/include/onnxruntime/core/common/make_string.h:39:3: note: in instantiation of function template specialization 'onnxruntime::detail::MakeStringImpl>' requested here /build/python-onnxruntime/src/onnxruntime/include/onnxruntime/core/common/make_string.h:39:3: note: in instantiation of function template specialization 'onnxruntime::detail::MakeStringImpl>' requested here /build/python-onnxruntime/src/onnxruntime/include/onnxruntime/core/common/make_string.h:46:3: note: in instantiation of function template specialization 'onnxruntime::detail::MakeStringImpl>' requested here MakeStringImpl(ss, args...); ^ /build/python-onnxruntime/src/onnxruntime/include/onnxruntime/core/common/make_string.h:93:18: note: in instantiation of function template specialization 'onnxruntime::detail::MakeStringImpl>' requested here return detail::MakeStringImpl(detail::if_char_array_make_ptr_t(args)...); ^ /build/python-onnxruntime/src/onnxruntime/onnxruntime/core/providers/dnnl/subgraph/dnnl_squeeze.cc:46:7: note: in instantiation of function template specialization 'onnxruntime::MakeString>' requested here ORT_ENFORCE(data_dims[i] == 1, "Dimension of input ", i, " must be 1 instead of ", data_dims[i], ^ /build/python-onnxruntime/src/onnxruntime/include/onnxruntime/core/common/common.h:184:64: note: expanded from macro 'ORT_ENFORCE' ::onnxruntime::MakeString(__VA_ARGS__)); \ ^ /build/python-onnxruntime/src/onnxruntime/include/onnxruntime/core/framework/tensor_shape.h:147:15: note: 'operator<<' should be declared prior to the call site std::ostream& operator<<(std::ostream& out, const TensorShape& shape); ^ 1 error generated. make[2]: *** [CMakeFiles/onnxruntime_providers_dnnl.dir/build.make:384: CMakeFiles/onnxruntime_providers_dnnl.dir/build/python-onnxruntime/src/onnxruntime/onnxruntime/core/providers/dnnl/subgraph/dnnl_squeeze.cc.o] Error 1 Two-phase lookups fail as: 1. visible in the template definition - fails as `std::ostream& operator<<(std::ostream& out, const TensorShape& shape)` (from include/onnxruntime/core/framework/tensor_shape.h) is defined after `template std::string MakeString(const Args&... args)` (from include/onnxruntime/core/common/make_string.h) as per `clang++ -E` 2. argument-dependent lookup - fails as the argument data_dims has type `std::vector` (via typedef in dnnl.hpp), while `std::ostream& operator<<(std::ostream& out, const TensorShape& shape)` is in namespace onnxruntime instead of std There are several possible fixes: * Make operator<< appear before MakeString by adjust the order of header files - I consider it fragile * Also define operator<< in namespace std - may results in namespace pollution * Use an argument of a class in onnxruntime namespace - this commit --- onnxruntime/core/providers/dnnl/subgraph/dnnl_squeeze.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onnxruntime/core/providers/dnnl/subgraph/dnnl_squeeze.cc b/onnxruntime/core/providers/dnnl/subgraph/dnnl_squeeze.cc index db66cb3a39..f9c2fe9b6b 100644 --- a/onnxruntime/core/providers/dnnl/subgraph/dnnl_squeeze.cc +++ b/onnxruntime/core/providers/dnnl/subgraph/dnnl_squeeze.cc @@ -44,7 +44,7 @@ void DnnlSqueeze::CreatePrimitive(DnnlSubgraphPrimitive& sp, DnnlNode& node) { if ((j < axes_data.size() && axes_data[j] == static_cast(i)) || (axes_data.size() == 0 && data_dims[i] == 1)) { ORT_ENFORCE(data_dims[i] == 1, "Dimension of input ", i, " must be 1 instead of ", data_dims[i], - ". shape=", data_dims); + ". shape=", TensorShape(data_dims)); ++j; continue; }