From 45e9dd84d96325a0d45c085891cb43c01c80894f Mon Sep 17 00:00:00 2001 From: mdimakov Date: Fri, 5 Mar 2021 11:54:58 +0300 Subject: [PATCH 01/10] [SYCL] Add caching into device Signed-off-by: mdimakov --- sycl/include/CL/sycl/device.hpp | 9 ++++++++- sycl/source/device.cpp | 15 ++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/sycl/include/CL/sycl/device.hpp b/sycl/include/CL/sycl/device.hpp index 2ca17e7f84ccc..e34fb85f2eec9 100644 --- a/sycl/include/CL/sycl/device.hpp +++ b/sycl/include/CL/sycl/device.hpp @@ -177,7 +177,10 @@ class __SYCL_EXPORT device { /// \return a native handle, the type of which defined by the backend. template auto get_native() const -> typename interop::type { - return (typename interop::type)getNative(); + auto cl_device = (typename interop::type)getNative(); + std::lock_guard lock(device_mutex); + device_impls[cl_device] = impl; + return n_handle; } /// Indicates if the SYCL device has the given feature. @@ -192,6 +195,10 @@ class __SYCL_EXPORT device { shared_ptr_class impl; device(shared_ptr_class impl) : impl(impl) {} + static std::unordered_map> device_impls; + std::mutex device_mutex; + pi_native_handle getNative() const; template diff --git a/sycl/source/device.cpp b/sycl/source/device.cpp index 57ca9f6190615..732b6a1d5bf2e 100644 --- a/sycl/source/device.cpp +++ b/sycl/source/device.cpp @@ -29,12 +29,21 @@ void force_type(info::device_type &t, const info::device_type &ft) { device::device() : impl(detail::device_impl::getHostDeviceImpl()) {} -device::device(cl_device_id deviceId) - : impl(std::make_shared( +device::device(cl_device_id deviceId) { + /*: impl(std::make_shared( detail::pi::cast(deviceId), - RT::getPlugin())) { + RT::getPlugin())) {*/ + // The implementation constructor takes ownership of the native handle so we // must retain it in order to adhere to SYCL 1.2.1 spec (Rev6, section 4.3.1.) + if (device_impls.count(deviceId)) + impl = device_impls[deviceId].lock(); + else { + impl = std::make_shared( + detail::pi::cast(deviceId), + RT::getPlugin())); + device_impls[deviceId] = impl; + } clRetainDevice(deviceId); } From a20af7ebe3792e6f58d3b9c6b117190375a77a88 Mon Sep 17 00:00:00 2001 From: mdimakov Date: Fri, 5 Mar 2021 11:55:42 +0300 Subject: [PATCH 02/10] [SYCL] Add checking for weak_ptr into device Signed-off-by: mdimakov --- sycl/source/device.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sycl/source/device.cpp b/sycl/source/device.cpp index 732b6a1d5bf2e..c44da72193d8a 100644 --- a/sycl/source/device.cpp +++ b/sycl/source/device.cpp @@ -36,7 +36,8 @@ device::device(cl_device_id deviceId) { // The implementation constructor takes ownership of the native handle so we // must retain it in order to adhere to SYCL 1.2.1 spec (Rev6, section 4.3.1.) - if (device_impls.count(deviceId)) + if (device_impls.count(deviceId) && + !device_impls.expired()) impl = device_impls[deviceId].lock(); else { impl = std::make_shared( From b5e45fc07fa2ee1f1d10fd54e695a8926442d5ec Mon Sep 17 00:00:00 2001 From: mdimakov Date: Tue, 9 Mar 2021 12:17:49 +0300 Subject: [PATCH 03/10] [SYCL] Add caching for device and platform Signed-off-by: mdimakov --- sycl/include/CL/sycl/device.hpp | 6 +++--- sycl/include/CL/sycl/platform.hpp | 10 +++++++++- sycl/source/device.cpp | 31 +++++++++++++++++++------------ sycl/source/platform.cpp | 24 ++++++++++++++++++++---- 4 files changed, 51 insertions(+), 20 deletions(-) diff --git a/sycl/include/CL/sycl/device.hpp b/sycl/include/CL/sycl/device.hpp index e34fb85f2eec9..e06f0b9e7c534 100644 --- a/sycl/include/CL/sycl/device.hpp +++ b/sycl/include/CL/sycl/device.hpp @@ -16,7 +16,7 @@ #include #include -#include +#include #include __SYCL_INLINE_NAMESPACE(cl) { @@ -180,7 +180,7 @@ class __SYCL_EXPORT device { auto cl_device = (typename interop::type)getNative(); std::lock_guard lock(device_mutex); device_impls[cl_device] = impl; - return n_handle; + return cl_device; } /// Indicates if the SYCL device has the given feature. @@ -197,7 +197,7 @@ class __SYCL_EXPORT device { static std::unordered_map> device_impls; - std::mutex device_mutex; + static std::mutex device_mutex; pi_native_handle getNative() const; diff --git a/sycl/include/CL/sycl/platform.hpp b/sycl/include/CL/sycl/platform.hpp index 6d2c36ef2cf27..8138a288d1d5c 100644 --- a/sycl/include/CL/sycl/platform.hpp +++ b/sycl/include/CL/sycl/platform.hpp @@ -12,6 +12,7 @@ #include // 4.6.2 Platform class +#include #include __SYCL_INLINE_NAMESPACE(cl) { namespace sycl { @@ -112,8 +113,11 @@ class __SYCL_EXPORT platform { /// \return a native handle, the type of which defined by the backend. template auto get_native() const -> typename interop::type { - return reinterpret_cast::type>( + auto cl_platform = reinterpret_cast::type>( getNative()); + std::lock_guard lock(platform_mutex); + platform_impls[cl_platform] = impl; + return cl_platform; } /// Indicates if all of the SYCL devices on this platform have the @@ -132,6 +136,10 @@ class __SYCL_EXPORT platform { shared_ptr_class impl; platform(shared_ptr_class impl) : impl(impl) {} + static std::unordered_map> platform_impls; + static std::mutex platform_mutex; + template friend T detail::createSyclObjFromImpl(decltype(T::impl) ImplObj); template diff --git a/sycl/source/device.cpp b/sycl/source/device.cpp index c44da72193d8a..2f8ac0c670853 100644 --- a/sycl/source/device.cpp +++ b/sycl/source/device.cpp @@ -29,21 +29,28 @@ void force_type(info::device_type &t, const info::device_type &ft) { device::device() : impl(detail::device_impl::getHostDeviceImpl()) {} -device::device(cl_device_id deviceId) { - /*: impl(std::make_shared( - detail::pi::cast(deviceId), - RT::getPlugin())) {*/ +std::unordered_map> device::device_impls; +std::mutex device::device_mutex; +device::device(cl_device_id deviceId) { // The implementation constructor takes ownership of the native handle so we // must retain it in order to adhere to SYCL 1.2.1 spec (Rev6, section 4.3.1.) - if (device_impls.count(deviceId) && - !device_impls.expired()) - impl = device_impls[deviceId].lock(); - else { - impl = std::make_shared( - detail::pi::cast(deviceId), - RT::getPlugin())); - device_impls[deviceId] = impl; + { + std::lock_guard lock(device_mutex); + auto it = device_impls.find(deviceId); + if (it != device_impls.end() && + !it->second.expired()) + impl = it->second.lock(); + else { + impl = std::make_shared( + detail::pi::cast(deviceId), + RT::getPlugin()); + if (it == device_impls.end()) + device_impls[deviceId] = impl; + else + it->second = impl; + } } clRetainDevice(deviceId); } diff --git a/sycl/source/platform.cpp b/sycl/source/platform.cpp index 3ab9f5b020d6d..d908038dfe2b6 100644 --- a/sycl/source/platform.cpp +++ b/sycl/source/platform.cpp @@ -18,10 +18,26 @@ namespace sycl { platform::platform() : impl(detail::platform_impl::getHostPlatformImpl()) {} -platform::platform(cl_platform_id PlatformId) - : impl(std::make_shared( - detail::pi::cast(PlatformId), - RT::getPlugin())) {} +std::unordered_map> platform::platform_impls; +std::mutex platform::platform_mutex; + +platform::platform(cl_platform_id PlatformId) { + std::lock_guard lock(platform_mutex); + auto it = platform_impls.find(PlatformId); + if (it != platform_impls.end() && + !it->second.expired()) + impl = it->second.lock(); + else { + impl = std::make_shared( + detail::pi::cast(PlatformId), + RT::getPlugin()); + if (it == platform_impls.end()) + platform_impls[PlatformId] = impl; + else + it->second = impl; + } +} platform::platform(const device_selector &dev_selector) { *this = dev_selector.select_device().get_platform(); From 1088259c40afc5e5f8818b52c4409493cce6585a Mon Sep 17 00:00:00 2001 From: mdimakov Date: Tue, 9 Mar 2021 12:34:38 +0300 Subject: [PATCH 04/10] [SYCL] Clang-format fix Signed-off-by: mdimakov --- sycl/include/CL/sycl/device.hpp | 4 ++-- sycl/include/CL/sycl/platform.hpp | 8 +++++--- sycl/source/device.cpp | 13 ++++++------- sycl/source/platform.cpp | 11 +++++------ 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/sycl/include/CL/sycl/device.hpp b/sycl/include/CL/sycl/device.hpp index e06f0b9e7c534..baed6360161ae 100644 --- a/sycl/include/CL/sycl/device.hpp +++ b/sycl/include/CL/sycl/device.hpp @@ -195,8 +195,8 @@ class __SYCL_EXPORT device { shared_ptr_class impl; device(shared_ptr_class impl) : impl(impl) {} - static std::unordered_map> device_impls; + static std::unordered_map> + device_impls; static std::mutex device_mutex; pi_native_handle getNative() const; diff --git a/sycl/include/CL/sycl/platform.hpp b/sycl/include/CL/sycl/platform.hpp index 8138a288d1d5c..0422e1605db50 100644 --- a/sycl/include/CL/sycl/platform.hpp +++ b/sycl/include/CL/sycl/platform.hpp @@ -113,8 +113,9 @@ class __SYCL_EXPORT platform { /// \return a native handle, the type of which defined by the backend. template auto get_native() const -> typename interop::type { - auto cl_platform = reinterpret_cast::type>( - getNative()); + auto cl_platform = + reinterpret_cast::type>( + getNative()); std::lock_guard lock(platform_mutex); platform_impls[cl_platform] = impl; return cl_platform; @@ -137,7 +138,8 @@ class __SYCL_EXPORT platform { platform(shared_ptr_class impl) : impl(impl) {} static std::unordered_map> platform_impls; + std::weak_ptr> + platform_impls; static std::mutex platform_mutex; template diff --git a/sycl/source/device.cpp b/sycl/source/device.cpp index 2f8ac0c670853..5ecb91c5b16ba 100644 --- a/sycl/source/device.cpp +++ b/sycl/source/device.cpp @@ -29,9 +29,9 @@ void force_type(info::device_type &t, const info::device_type &ft) { device::device() : impl(detail::device_impl::getHostDeviceImpl()) {} -std::unordered_map> device::device_impls; -std::mutex device::device_mutex; +std::unordered_map> + device::device_impls; +std::mutex device::device_mutex; device::device(cl_device_id deviceId) { // The implementation constructor takes ownership of the native handle so we @@ -39,13 +39,12 @@ device::device(cl_device_id deviceId) { { std::lock_guard lock(device_mutex); auto it = device_impls.find(deviceId); - if (it != device_impls.end() && - !it->second.expired()) + if (it != device_impls.end() && !it->second.expired()) impl = it->second.lock(); else { impl = std::make_shared( - detail::pi::cast(deviceId), - RT::getPlugin()); + detail::pi::cast(deviceId), + RT::getPlugin()); if (it == device_impls.end()) device_impls[deviceId] = impl; else diff --git a/sycl/source/platform.cpp b/sycl/source/platform.cpp index d908038dfe2b6..78993a2f121e4 100644 --- a/sycl/source/platform.cpp +++ b/sycl/source/platform.cpp @@ -18,20 +18,19 @@ namespace sycl { platform::platform() : impl(detail::platform_impl::getHostPlatformImpl()) {} -std::unordered_map> platform::platform_impls; +std::unordered_map> + platform::platform_impls; std::mutex platform::platform_mutex; platform::platform(cl_platform_id PlatformId) { std::lock_guard lock(platform_mutex); auto it = platform_impls.find(PlatformId); - if (it != platform_impls.end() && - !it->second.expired()) + if (it != platform_impls.end() && !it->second.expired()) impl = it->second.lock(); else { impl = std::make_shared( - detail::pi::cast(PlatformId), - RT::getPlugin()); + detail::pi::cast(PlatformId), + RT::getPlugin()); if (it == platform_impls.end()) platform_impls[PlatformId] = impl; else From 6fdff7e4e442d22041dd0de7ef531a120bdbad38 Mon Sep 17 00:00:00 2001 From: mdimakov Date: Tue, 9 Mar 2021 12:37:40 +0300 Subject: [PATCH 05/10] [SYCL] Clang-format fix Signed-off-by: mdimakov --- sycl/source/device.cpp | 2 +- sycl/source/platform.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sycl/source/device.cpp b/sycl/source/device.cpp index 5ecb91c5b16ba..382087bec0001 100644 --- a/sycl/source/device.cpp +++ b/sycl/source/device.cpp @@ -39,7 +39,7 @@ device::device(cl_device_id deviceId) { { std::lock_guard lock(device_mutex); auto it = device_impls.find(deviceId); - if (it != device_impls.end() && !it->second.expired()) + if (it != device_impls.end() && !it->second.expired()) impl = it->second.lock(); else { impl = std::make_shared( diff --git a/sycl/source/platform.cpp b/sycl/source/platform.cpp index 78993a2f121e4..0c814406136fe 100644 --- a/sycl/source/platform.cpp +++ b/sycl/source/platform.cpp @@ -25,7 +25,7 @@ std::mutex platform::platform_mutex; platform::platform(cl_platform_id PlatformId) { std::lock_guard lock(platform_mutex); auto it = platform_impls.find(PlatformId); - if (it != platform_impls.end() && !it->second.expired()) + if (it != platform_impls.end() && !it->second.expired()) impl = it->second.lock(); else { impl = std::make_shared( From a88ccbd64e03a2fad7f2196eca96c89dc6888e0f Mon Sep 17 00:00:00 2001 From: mdimakov Date: Wed, 10 Mar 2021 22:16:29 +0300 Subject: [PATCH 06/10] Resolve merge conflict --- clang/lib/Sema/SemaDeclAttr.cpp | 46 +++++++++++++++++++++++++++ sycl/test/abi/sycl_symbols_linux.dump | 24 ++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 14ffacf36ba0d..700f5133225c3 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -3453,6 +3453,52 @@ static void handleMaxGlobalWorkDimAttr(Sema &S, Decl *D, const ParsedAttr &A) { S.addIntelSingleArgAttr(D, A, E); } +// Handles [[intel::loop_fuse]] and [[intel::loop_fuse_independent]]. +void Sema::AddSYCLIntelLoopFuseAttr(Decl *D, const AttributeCommonInfo &CI, + Expr *E) { + if (!E->isValueDependent()) { + // Validate that we have an integer constant expression and then store the + // converted constant expression into the semantic attribute so that we + // don't have to evaluate it again later. + llvm::APSInt ArgVal; + ExprResult Res = VerifyIntegerConstantExpression(E, &ArgVal); + if (Res.isInvalid()) + return; + E = Res.get(); + // This attribute requires a non-negative value. + if (ArgVal < 0) { + Diag(E->getExprLoc(), diag::err_attribute_requires_positive_integer) + << CI << /*non-negative*/ 1; + return; + } + // Check to see if there's a duplicate attribute with different values + // already applied to the declaration. + if (const auto *DeclAttr = D->getAttr()) { + // If the other attribute argument is instantiation dependent, we won't + // have converted it to a constant expression yet and thus we test + // whether this is a null pointer. + const auto *DeclExpr = dyn_cast(DeclAttr->getValue()); + if (DeclExpr && ArgVal != DeclExpr->getResultAsAPSInt()) { + Diag(CI.getLoc(), diag::warn_duplicate_attribute) << CI; + Diag(DeclAttr->getLoc(), diag::note_previous_attribute); + return; + } + // [[intel::loop_fuse]] and [[intel::loop_fuse_independent]] are + // incompatible. + // FIXME: If additional spellings are provided for this attribute, + // this code will do the wrong thing. + if (DeclAttr->getAttributeSpellingListIndex() != + CI.getAttributeSpellingListIndex()) { + Diag(CI.getLoc(), diag::err_attributes_are_not_compatible) + << CI << DeclAttr; + Diag(DeclAttr->getLocation(), diag::note_conflicting_attribute); + return; + } + } + } + + D->addAttr(::new (Context) SYCLIntelLoopFuseAttr(Context, CI, E)); +} SYCLIntelLoopFuseAttr * Sema::mergeSYCLIntelLoopFuseAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E) { diff --git a/sycl/test/abi/sycl_symbols_linux.dump b/sycl/test/abi/sycl_symbols_linux.dump index f652421aaaab1..ef2b49a01ba41 100644 --- a/sycl/test/abi/sycl_symbols_linux.dump +++ b/sycl/test/abi/sycl_symbols_linux.dump @@ -3779,10 +3779,14 @@ _ZN2cl4sycl6detail18stringifyErrorCodeEi _ZN2cl4sycl6detail19convertChannelOrderE23_pi_image_channel_order _ZN2cl4sycl6detail19convertChannelOrderENS0_19image_channel_orderE _ZN2cl4sycl6detail19getImageElementSizeEhNS0_18image_channel_typeE +_ZN2cl4sycl6detail19kernel_bundle_plain37set_specialization_constant_raw_valueEjPKvm _ZN2cl4sycl6detail20associateWithHandlerERNS0_7handlerEPNS1_16AccessorBaseHostENS0_6access6targetE _ZN2cl4sycl6detail20getDeviceFromHandlerERNS0_7handlerE _ZN2cl4sycl6detail22addHostAccessorAndWaitEPNS1_16AccessorImplHostE _ZN2cl4sycl6detail22getImageNumberChannelsENS0_19image_channel_orderE +_ZN2cl4sycl6detail22get_kernel_bundle_implERKNS0_7contextERKSt6vectorINS0_6deviceESaIS6_EENS0_12bundle_stateE +_ZN2cl4sycl6detail22get_kernel_bundle_implERKNS0_7contextERKSt6vectorINS0_6deviceESaIS6_EENS0_12bundle_stateERKSt8functionIFbRKSt10shared_ptrINS1_17device_image_implEEEE +_ZN2cl4sycl6detail22get_kernel_bundle_implERKNS0_7contextERKSt6vectorINS0_6deviceESaIS6_EERKS5_INS0_9kernel_idESaISB_EENS0_12bundle_stateE _ZN2cl4sycl6detail27getPixelCoordLinearFiltModeENS0_3vecIfLi4EEENS0_15addressing_modeENS0_5rangeILi3EEERS3_ _ZN2cl4sycl6detail28getDeviceFunctionPointerImplERNS0_6deviceERNS0_7programEPKc _ZN2cl4sycl6detail28getPixelCoordNearestFiltModeENS0_3vecIfLi4EEENS0_15addressing_modeENS0_5rangeILi3EEE @@ -3876,6 +3880,8 @@ _ZN2cl4sycl8platformC1Ev _ZN2cl4sycl8platformC2EP15_cl_platform_id _ZN2cl4sycl8platformC2ERKNS0_15device_selectorE _ZN2cl4sycl8platformC2Ev +_ZN2cl4sycl9kernel_idC1EPKc +_ZN2cl4sycl9kernel_idC2EPKc _ZNK2cl4sycl12cpu_selectorclERKNS0_6deviceE _ZNK2cl4sycl12gpu_selectorclERKNS0_6deviceE _ZNK2cl4sycl13host_selectorclERKNS0_6deviceE @@ -3946,6 +3952,23 @@ _ZNK2cl4sycl6detail12sampler_impl18get_filtering_modeEv _ZNK2cl4sycl6detail12sampler_impl19get_addressing_modeEv _ZNK2cl4sycl6detail12sampler_impl33get_coordinate_normalization_modeEv _ZNK2cl4sycl6detail14host_half_impl4halfcvfEv +_ZNK2cl4sycl6detail18device_image_plain10has_kernelERKNS0_9kernel_idE +_ZNK2cl4sycl6detail18device_image_plain10has_kernelERKNS0_9kernel_idERKNS0_6deviceE +_ZNK2cl4sycl6detail19kernel_bundle_plain10get_kernelERKNS0_9kernel_idE +_ZNK2cl4sycl6detail19kernel_bundle_plain10has_kernelERKNS0_9kernel_idE +_ZNK2cl4sycl6detail19kernel_bundle_plain10has_kernelERKNS0_9kernel_idERKNS0_6deviceE +_ZNK2cl4sycl6detail19kernel_bundle_plain11get_backendEv +_ZNK2cl4sycl6detail19kernel_bundle_plain11get_contextEv +_ZNK2cl4sycl6detail19kernel_bundle_plain11get_devicesEv +_ZNK2cl4sycl6detail19kernel_bundle_plain14get_kernel_idsEv +_ZNK2cl4sycl6detail19kernel_bundle_plain27has_specialization_constantEj +_ZNK2cl4sycl6detail19kernel_bundle_plain30native_specialization_constantEv +_ZNK2cl4sycl6detail19kernel_bundle_plain33contains_specialization_constantsEv +_ZNK2cl4sycl6detail19kernel_bundle_plain37get_specialization_constant_raw_valueEjPvm +_ZNK2cl4sycl6detail19kernel_bundle_plain3endEv +_ZNK2cl4sycl6detail19kernel_bundle_plain5beginEv +_ZNK2cl4sycl6detail19kernel_bundle_plain5emptyEv +_ZNK2cl4sycl6device11get_backendEv _ZNK2cl4sycl6device12get_platformEv _ZNK2cl4sycl6device13has_extensionERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE _ZNK2cl4sycl6device14is_acceleratorEv @@ -4187,5 +4210,6 @@ _ZNK2cl4sycl9exception11get_cl_codeEv _ZNK2cl4sycl9exception11get_contextEv _ZNK2cl4sycl9exception11has_contextEv _ZNK2cl4sycl9exception4whatEv +_ZNK2cl4sycl9kernel_id8get_nameEv __sycl_register_lib __sycl_unregister_lib From b72b4cf7b0f836a01694a46bc9245d25098b843f Mon Sep 17 00:00:00 2001 From: mdimakov Date: Thu, 11 Mar 2021 21:47:45 +0300 Subject: [PATCH 07/10] [SYCL] Use existing caching implementation Signed-off-by: mdimakov --- sycl/include/CL/sycl/device.hpp | 10 +--------- sycl/include/CL/sycl/platform.hpp | 14 ++------------ sycl/source/device.cpp | 30 +++++++++--------------------- sycl/source/platform.cpp | 18 ++---------------- 4 files changed, 14 insertions(+), 58 deletions(-) diff --git a/sycl/include/CL/sycl/device.hpp b/sycl/include/CL/sycl/device.hpp index baed6360161ae..f88ce11e1e451 100644 --- a/sycl/include/CL/sycl/device.hpp +++ b/sycl/include/CL/sycl/device.hpp @@ -16,7 +16,6 @@ #include #include -#include #include __SYCL_INLINE_NAMESPACE(cl) { @@ -177,10 +176,7 @@ class __SYCL_EXPORT device { /// \return a native handle, the type of which defined by the backend. template auto get_native() const -> typename interop::type { - auto cl_device = (typename interop::type)getNative(); - std::lock_guard lock(device_mutex); - device_impls[cl_device] = impl; - return cl_device; + return (typename interop::type)getNative(); } /// Indicates if the SYCL device has the given feature. @@ -195,10 +191,6 @@ class __SYCL_EXPORT device { shared_ptr_class impl; device(shared_ptr_class impl) : impl(impl) {} - static std::unordered_map> - device_impls; - static std::mutex device_mutex; - pi_native_handle getNative() const; template diff --git a/sycl/include/CL/sycl/platform.hpp b/sycl/include/CL/sycl/platform.hpp index 0422e1605db50..6d2c36ef2cf27 100644 --- a/sycl/include/CL/sycl/platform.hpp +++ b/sycl/include/CL/sycl/platform.hpp @@ -12,7 +12,6 @@ #include // 4.6.2 Platform class -#include #include __SYCL_INLINE_NAMESPACE(cl) { namespace sycl { @@ -113,12 +112,8 @@ class __SYCL_EXPORT platform { /// \return a native handle, the type of which defined by the backend. template auto get_native() const -> typename interop::type { - auto cl_platform = - reinterpret_cast::type>( - getNative()); - std::lock_guard lock(platform_mutex); - platform_impls[cl_platform] = impl; - return cl_platform; + return reinterpret_cast::type>( + getNative()); } /// Indicates if all of the SYCL devices on this platform have the @@ -137,11 +132,6 @@ class __SYCL_EXPORT platform { shared_ptr_class impl; platform(shared_ptr_class impl) : impl(impl) {} - static std::unordered_map> - platform_impls; - static std::mutex platform_mutex; - template friend T detail::createSyclObjFromImpl(decltype(T::impl) ImplObj); template diff --git a/sycl/source/device.cpp b/sycl/source/device.cpp index 382087bec0001..a00fd16e45cbf 100644 --- a/sycl/source/device.cpp +++ b/sycl/source/device.cpp @@ -29,29 +29,17 @@ void force_type(info::device_type &t, const info::device_type &ft) { device::device() : impl(detail::device_impl::getHostDeviceImpl()) {} -std::unordered_map> - device::device_impls; -std::mutex device::device_mutex; - -device::device(cl_device_id deviceId) { +device::device(cl_device_id DeviceId) { // The implementation constructor takes ownership of the native handle so we // must retain it in order to adhere to SYCL 1.2.1 spec (Rev6, section 4.3.1.) - { - std::lock_guard lock(device_mutex); - auto it = device_impls.find(deviceId); - if (it != device_impls.end() && !it->second.expired()) - impl = it->second.lock(); - else { - impl = std::make_shared( - detail::pi::cast(deviceId), - RT::getPlugin()); - if (it == device_impls.end()) - device_impls[deviceId] = impl; - else - it->second = impl; - } - } - clRetainDevice(deviceId); + detail::RT::PiDevice Device; + auto Plugin = detail::RT::getPlugin(); + Plugin.call( + detail::pi::cast(DeviceId), nullptr, &Device); + auto Platform = detail::platform_impl::getPlatformFromPiDevice( + Device, Plugin); + impl = Platform->getOrMakeDeviceImpl(Device, Platform); + clRetainDevice(DeviceId); } device::device(const device_selector &deviceSelector) { diff --git a/sycl/source/platform.cpp b/sycl/source/platform.cpp index 0c814406136fe..10afefb81c642 100644 --- a/sycl/source/platform.cpp +++ b/sycl/source/platform.cpp @@ -18,24 +18,10 @@ namespace sycl { platform::platform() : impl(detail::platform_impl::getHostPlatformImpl()) {} -std::unordered_map> - platform::platform_impls; -std::mutex platform::platform_mutex; - platform::platform(cl_platform_id PlatformId) { - std::lock_guard lock(platform_mutex); - auto it = platform_impls.find(PlatformId); - if (it != platform_impls.end() && !it->second.expired()) - impl = it->second.lock(); - else { - impl = std::make_shared( + impl = detail::platform_impl::getOrMakePlatformImpl( detail::pi::cast(PlatformId), - RT::getPlugin()); - if (it == platform_impls.end()) - platform_impls[PlatformId] = impl; - else - it->second = impl; - } + detail::RT::getPlugin()); } platform::platform(const device_selector &dev_selector) { From e0103952f1b4e4c35c252f368dd8612b40061737 Mon Sep 17 00:00:00 2001 From: mdimakov Date: Thu, 11 Mar 2021 21:50:47 +0300 Subject: [PATCH 08/10] Remove problems --- clang/lib/Sema/SemaDeclAttr.cpp | 7 +------ sycl/test/abi/sycl_symbols_linux.dump | 1 - 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 91140e8b74028..1ab711a56efb0 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -3462,6 +3462,7 @@ void Sema::AddSYCLIntelLoopFuseAttr(Decl *D, const AttributeCommonInfo &CI, if (Res.isInvalid()) return; E = Res.get(); + // This attribute requires a non-negative value. if (ArgVal < 0) { Diag(E->getExprLoc(), diag::err_attribute_requires_positive_integer) @@ -3496,12 +3497,6 @@ void Sema::AddSYCLIntelLoopFuseAttr(Decl *D, const AttributeCommonInfo &CI, D->addAttr(::new (Context) SYCLIntelLoopFuseAttr(Context, CI, E)); } -<<<<<<< HEAD -SYCLIntelLoopFuseAttr * -Sema::mergeSYCLIntelLoopFuseAttr(Decl *D, const AttributeCommonInfo &CI, - Expr *E) { -======= ->>>>>>> sycl SYCLIntelLoopFuseAttr * Sema::MergeSYCLIntelLoopFuseAttr(Decl *D, const SYCLIntelLoopFuseAttr &A) { diff --git a/sycl/test/abi/sycl_symbols_linux.dump b/sycl/test/abi/sycl_symbols_linux.dump index ef2b49a01ba41..eb9608569576c 100644 --- a/sycl/test/abi/sycl_symbols_linux.dump +++ b/sycl/test/abi/sycl_symbols_linux.dump @@ -3968,7 +3968,6 @@ _ZNK2cl4sycl6detail19kernel_bundle_plain37get_specialization_constant_raw_valueE _ZNK2cl4sycl6detail19kernel_bundle_plain3endEv _ZNK2cl4sycl6detail19kernel_bundle_plain5beginEv _ZNK2cl4sycl6detail19kernel_bundle_plain5emptyEv -_ZNK2cl4sycl6device11get_backendEv _ZNK2cl4sycl6device12get_platformEv _ZNK2cl4sycl6device13has_extensionERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE _ZNK2cl4sycl6device14is_acceleratorEv From 89179d08aa6218b9915cff91bb6ab2e4e5fcd02b Mon Sep 17 00:00:00 2001 From: mdimakov Date: Thu, 11 Mar 2021 21:54:36 +0300 Subject: [PATCH 09/10] Clang-format fix Signed-off-by: mdimakov --- sycl/source/device.cpp | 4 ++-- sycl/source/platform.cpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/sycl/source/device.cpp b/sycl/source/device.cpp index a00fd16e45cbf..4bdb2d9a1a154 100644 --- a/sycl/source/device.cpp +++ b/sycl/source/device.cpp @@ -36,8 +36,8 @@ device::device(cl_device_id DeviceId) { auto Plugin = detail::RT::getPlugin(); Plugin.call( detail::pi::cast(DeviceId), nullptr, &Device); - auto Platform = detail::platform_impl::getPlatformFromPiDevice( - Device, Plugin); + auto Platform = + detail::platform_impl::getPlatformFromPiDevice(Device, Plugin); impl = Platform->getOrMakeDeviceImpl(Device, Platform); clRetainDevice(DeviceId); } diff --git a/sycl/source/platform.cpp b/sycl/source/platform.cpp index 10afefb81c642..bcda122e345a0 100644 --- a/sycl/source/platform.cpp +++ b/sycl/source/platform.cpp @@ -19,9 +19,9 @@ namespace sycl { platform::platform() : impl(detail::platform_impl::getHostPlatformImpl()) {} platform::platform(cl_platform_id PlatformId) { - impl = detail::platform_impl::getOrMakePlatformImpl( - detail::pi::cast(PlatformId), - detail::RT::getPlugin()); + impl = detail::platform_impl::getOrMakePlatformImpl( + detail::pi::cast(PlatformId), + detail::RT::getPlugin()); } platform::platform(const device_selector &dev_selector) { From 3221fc2ffd9848fa6011a3f8a3c2f8011c1237de Mon Sep 17 00:00:00 2001 From: mdimakov Date: Fri, 12 Mar 2021 11:33:54 +0300 Subject: [PATCH 10/10] Adress review comment Signed-off-by: mdimakov --- sycl/include/CL/sycl/device.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/sycl/include/CL/sycl/device.hpp b/sycl/include/CL/sycl/device.hpp index f88ce11e1e451..2ca17e7f84ccc 100644 --- a/sycl/include/CL/sycl/device.hpp +++ b/sycl/include/CL/sycl/device.hpp @@ -16,6 +16,7 @@ #include #include +#include #include __SYCL_INLINE_NAMESPACE(cl) {