Skip to content

Commit

Permalink
DPC++ link error workaround. (openvinotoolkit#4192)
Browse files Browse the repository at this point in the history
* DPC++ link error workaround.

OpenVINO C++ program failed to link when DPC++ compiler is used.
'make_shared_blob' causes 'unresolved external symbol' error on linking.
Commented out some __clang__ specific directives to workaround the issue in "ie_blob.h".

* DPC++ compatibility issue fix #2

1. Removed type-by-type template class definition for __clang__.
2. Modified TBlob() destructor. The 'unresolved reference' error occur again if I left 'virtual ~TBlob();' only. It seems it needs to be 'virtual ~TBlob() {};'.

* DPC++ compatibility fix #3 - Add DPC++ conditional code

Uses '__SYCL_COMPILER_VERSION' predefined macro to check if the compiler is a DPC++ or not.
Added conditional directive to switch code based of the detected compiler.
NOTE: User program must include <CL/sycl.hpp>, or the '__SYCL_COMPILER_VERSION' macro won't be defined and this fix won't take effect.

* DPC++ compatibility issue fix #4

Changed from #ifdef to #if + logical formulas.

* DPC++ compatibility issue fix #5

Added compiler check logic in src/ie_rtti.cpp

* DPC++ Compatibility issue #6 - ie_parameter.cpp

Added compiler check macro for DPC++ to ie_parameter.cpp as well.

Co-authored-by: Yasunori Shimura <[email protected]>
  • Loading branch information
yas-sim and yassim-intel authored Feb 13, 2021
1 parent eeb7835 commit 15d6a0f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
9 changes: 5 additions & 4 deletions inference-engine/include/ie_blob.h
Original file line number Diff line number Diff line change
Expand Up @@ -577,13 +577,14 @@ class TBlob : public MemoryBlob {
/**
*@brief Virtual destructor.
*/
#ifdef __clang__

#if defined(__clang__) && !defined(__SYCL_COMPILER_VERSION)
virtual ~TBlob();
#else
virtual ~TBlob() {
free();
}
#endif // __clang__
#endif // __clang__ && !__SYCL_COMPILER_VERSION

/**
* @brief Gets the size of the given type.
Expand Down Expand Up @@ -806,7 +807,7 @@ class TBlob : public MemoryBlob {
}
};

#ifdef __clang__
#if defined(__clang__) && !defined(__SYCL_COMPILER_VERSION)
extern template class INFERENCE_ENGINE_API_CLASS(InferenceEngine::TBlob<float>);
extern template class INFERENCE_ENGINE_API_CLASS(InferenceEngine::TBlob<double>);
extern template class INFERENCE_ENGINE_API_CLASS(InferenceEngine::TBlob<int8_t>);
Expand All @@ -819,7 +820,7 @@ extern template class INFERENCE_ENGINE_API_CLASS(InferenceEngine::TBlob<long>);
extern template class INFERENCE_ENGINE_API_CLASS(InferenceEngine::TBlob<long long>);
extern template class INFERENCE_ENGINE_API_CLASS(InferenceEngine::TBlob<unsigned long>);
extern template class INFERENCE_ENGINE_API_CLASS(InferenceEngine::TBlob<unsigned long long>);
#endif // __clang__
#endif // __clang__ && !__SYCL_COMPILER_VERSION

/**
* @brief Creates a blob with the given tensor descriptor.
Expand Down
8 changes: 4 additions & 4 deletions inference-engine/include/ie_parameter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,11 @@ class INFERENCE_ENGINE_API_CLASS(Parameter) {
struct HasOperatorEqual : CheckOperatorEqual<T, EqualTo>::type {};

struct Any {
#ifdef __clang__
#if defined(__clang__) && !defined(__SYCL_COMPILER_VERSION)
virtual ~Any();
#else
virtual ~Any() = default;
#endif
#endif // __clang__ && !__SYCL_COMPILER_VERSION
virtual bool is(const std::type_info&) const = 0;
virtual Any* copy() const = 0;
virtual bool operator==(const Any& rhs) const = 0;
Expand Down Expand Up @@ -326,7 +326,7 @@ class INFERENCE_ENGINE_API_CLASS(Parameter) {
Any* ptr = nullptr;
};

#ifdef __clang__
#if defined(__clang__) && !defined(__SYCL_COMPILER_VERSION)
extern template struct INFERENCE_ENGINE_API_CLASS(InferenceEngine::Parameter::RealData<InferenceEngine::Blob::Ptr>);
extern template struct INFERENCE_ENGINE_API_CLASS(InferenceEngine::Parameter::RealData<int>);
extern template struct INFERENCE_ENGINE_API_CLASS(InferenceEngine::Parameter::RealData<bool>);
Expand All @@ -341,6 +341,6 @@ extern template struct INFERENCE_ENGINE_API_CLASS(
InferenceEngine::Parameter::RealData<std::tuple<unsigned int, unsigned int>>);
extern template struct INFERENCE_ENGINE_API_CLASS(
InferenceEngine::Parameter::RealData<std::tuple<unsigned int, unsigned int, unsigned int>>);
#endif // __clang__
#endif // __clang__ && !__SYCL_COMPILER_VERSION

} // namespace InferenceEngine
8 changes: 4 additions & 4 deletions inference-engine/src/inference_engine/ie_rtti.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Parameter::~Parameter() {
clear();
}

#ifdef __clang__
#if defined(__clang__) && !defined(__SYCL_COMPILER_VERSION)
Parameter::Any::~Any() {}

template struct InferenceEngine::Parameter::RealData<int>;
Expand All @@ -97,12 +97,12 @@ template struct InferenceEngine::Parameter::RealData<std::vector<unsigned long>>
template struct InferenceEngine::Parameter::RealData<std::tuple<unsigned int, unsigned int>>;
template struct InferenceEngine::Parameter::RealData<std::tuple<unsigned int, unsigned int, unsigned int>>;
template struct InferenceEngine::Parameter::RealData<InferenceEngine::Blob::Ptr>;
#endif // __clang__
#endif // __clang__ && !__SYCL_COMPILER_VERSION
//
// ie_blob.h
//

#ifdef __clang__
#if defined(__clang__) && !defined(__SYCL_COMPILER_VERSION)
template <typename T, typename U>
TBlob<T, U>::~TBlob() {
free();
Expand All @@ -120,4 +120,4 @@ template class InferenceEngine::TBlob<long>;
template class InferenceEngine::TBlob<long long>;
template class InferenceEngine::TBlob<unsigned long>;
template class InferenceEngine::TBlob<unsigned long long>;
#endif // __clang__
#endif // __clang__ && !__SYCL_COMPILER_VERSION

0 comments on commit 15d6a0f

Please sign in to comment.