From 145ff1125eb3540a0354ddc9da06db86e828fcb0 Mon Sep 17 00:00:00 2001 From: Alexey Bader Date: Fri, 14 Jul 2023 01:56:19 -0700 Subject: [PATCH 1/7] [SYCL][NFC] Refactor includes in DPC++ headers The main goal of this refactoring is to reduce amount of includes to the context.hpp header. Two new includes are added: 1. sycl/include/sycl/detail/impl_utils.hpp is intended to replace sycl/include/sycl/detail/common.hpp when only interopability with "impl" class is needed. common.hpp include is overloaded with a bunch of other functionality. 2. sycl/include/sycl/async_handler.hpp separates async_handler definiton from exception.hpp. --- sycl/include/sycl/async_handler.hpp | 23 ++++++++ sycl/include/sycl/backend_types.hpp | 2 +- sycl/include/sycl/buffer.hpp | 1 + sycl/include/sycl/context.hpp | 10 +--- sycl/include/sycl/detail/common.hpp | 35 ------------ sycl/include/sycl/detail/impl_utils.hpp | 55 +++++++++++++++++++ .../include/sycl/detail/info_desc_helpers.hpp | 3 +- sycl/include/sycl/detail/owner_less_base.hpp | 2 +- sycl/include/sycl/detail/property_helper.hpp | 2 +- .../sycl/detail/property_list_base.hpp | 2 +- sycl/include/sycl/detail/stl_type_traits.hpp | 4 +- sycl/include/sycl/device_selector.hpp | 1 + sycl/include/sycl/exception_list.hpp | 3 +- .../experimental/device_architecture.hpp | 8 +++ .../sycl/ext/oneapi/experimental/graph.hpp | 1 + sycl/include/sycl/info/info_desc.hpp | 6 +- sycl/include/sycl/property_list.hpp | 1 - sycl/include/sycl/queue.hpp | 2 +- sycl/source/detail/config.hpp | 1 + sycl/source/detail/sampler_impl.hpp | 1 + sycl/source/detail/sycl_mem_obj_t.hpp | 2 +- 21 files changed, 108 insertions(+), 57 deletions(-) create mode 100644 sycl/include/sycl/async_handler.hpp create mode 100644 sycl/include/sycl/detail/impl_utils.hpp diff --git a/sycl/include/sycl/async_handler.hpp b/sycl/include/sycl/async_handler.hpp new file mode 100644 index 0000000000000..b9ae6bc8a0b79 --- /dev/null +++ b/sycl/include/sycl/async_handler.hpp @@ -0,0 +1,23 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#pragma once + +#include + +#include + +namespace sycl { +__SYCL_INLINE_VER_NAMESPACE(_V1) { + +// Forward declaration +class exception_list; + +using async_handler = std::function; +} +} // namespace sycl diff --git a/sycl/include/sycl/backend_types.hpp b/sycl/include/sycl/backend_types.hpp index b74c4828a536a..eedf87515a2dc 100644 --- a/sycl/include/sycl/backend_types.hpp +++ b/sycl/include/sycl/backend_types.hpp @@ -8,7 +8,7 @@ #pragma once -#include +#include #include namespace sycl { diff --git a/sycl/include/sycl/buffer.hpp b/sycl/include/sycl/buffer.hpp index 18153b33d9c70..ae230c328b637 100644 --- a/sycl/include/sycl/buffer.hpp +++ b/sycl/include/sycl/buffer.hpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include diff --git a/sycl/include/sycl/context.hpp b/sycl/include/sycl/context.hpp index 765896cffae5e..1c4cd91678567 100644 --- a/sycl/include/sycl/context.hpp +++ b/sycl/include/sycl/context.hpp @@ -8,16 +8,11 @@ #pragma once -#include -#include -#include +#include +#include #include #include #include -#include -#include -#include -#include #include // 4.6.2 Context class @@ -27,6 +22,7 @@ __SYCL_INLINE_VER_NAMESPACE(_V1) { // Forward declarations class device; class platform; + namespace detail { class context_impl; } diff --git a/sycl/include/sycl/detail/common.hpp b/sycl/include/sycl/detail/common.hpp index 2f8a65d0216b5..7983baca607ec 100644 --- a/sycl/include/sycl/detail/common.hpp +++ b/sycl/include/sycl/detail/common.hpp @@ -259,41 +259,6 @@ inline std::string codeToString(pi_int32 code) { namespace sycl { __SYCL_INLINE_VER_NAMESPACE(_V1) { namespace detail { - -// Helper function for extracting implementation from SYCL's interface objects. -// Note! This function relies on the fact that all SYCL interface classes -// contain "impl" field that points to implementation object. "impl" field -// should be accessible from this function. -// -// Note that due to a bug in MSVC compilers (including MSVC2019 v19.20), it -// may not recognize the usage of this function in friend member declarations -// if the template parameter name there is not equal to the name used here, -// i.e. 'Obj'. For example, using 'Obj' here and 'T' in such declaration -// would trigger that error in MSVC: -// template -// friend decltype(T::impl) detail::getSyclObjImpl(const T &SyclObject); -template decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject) { - assert(SyclObject.impl && "every constructor should create an impl"); - return SyclObject.impl; -} - -// Returns the raw pointer to the impl object of given face object. The caller -// must make sure the returned pointer is not captured in a field or otherwise -// stored - i.e. must live only as on-stack value. -template -typename std::add_pointer_t -getRawSyclObjImpl(const T &SyclObject) { - return SyclObject.impl.get(); -} - -// Helper function for creation SYCL interface objects from implementations. -// Note! This function relies on the fact that all SYCL interface classes -// contain "impl" field that points to implementation object. "impl" field -// should be accessible from this function. -template T createSyclObjFromImpl(decltype(T::impl) ImplObj) { - return T(ImplObj); -} - // Produces N-dimensional object of type T whose all components are initialized // to given integer value. template class T> struct InitializedVal { diff --git a/sycl/include/sycl/detail/impl_utils.hpp b/sycl/include/sycl/detail/impl_utils.hpp new file mode 100644 index 0000000000000..34e209b8c17c3 --- /dev/null +++ b/sycl/include/sycl/detail/impl_utils.hpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#pragma once + +#include + +#include + +namespace sycl { +__SYCL_INLINE_VER_NAMESPACE(_V1) { +namespace detail { + +// Helper function for extracting implementation from SYCL's interface objects. +// Note! This function relies on the fact that all SYCL interface classes +// contain "impl" field that points to implementation object. "impl" field +// should be accessible from this function. +// +// Note that due to a bug in MSVC compilers (including MSVC2019 v19.20), it +// may not recognize the usage of this function in friend member declarations +// if the template parameter name there is not equal to the name used here, +// i.e. 'Obj'. For example, using 'Obj' here and 'T' in such declaration +// would trigger that error in MSVC: +// template +// friend decltype(T::impl) detail::getSyclObjImpl(const T &SyclObject); +template decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject) { + assert(SyclObject.impl && "every constructor should create an impl"); + return SyclObject.impl; +} + +// Returns the raw pointer to the impl object of given face object. The caller +// must make sure the returned pointer is not captured in a field or otherwise +// stored - i.e. must live only as on-stack value. +template +typename std::add_pointer_t +getRawSyclObjImpl(const T &SyclObject) { + return SyclObject.impl.get(); +} + +// Helper function for creation SYCL interface objects from implementations. +// Note! This function relies on the fact that all SYCL interface classes +// contain "impl" field that points to implementation object. "impl" field +// should be accessible from this function. +template T createSyclObjFromImpl(decltype(T::impl) ImplObj) { + return T(ImplObj); +} + +} // namespace detail +} // __SYCL_INLINE_VER_NAMESPACE(_V1) +} // namespace sycl diff --git a/sycl/include/sycl/detail/info_desc_helpers.hpp b/sycl/include/sycl/detail/info_desc_helpers.hpp index 8eef426a9ae23..b6f652b33520c 100644 --- a/sycl/include/sycl/detail/info_desc_helpers.hpp +++ b/sycl/include/sycl/detail/info_desc_helpers.hpp @@ -9,7 +9,8 @@ #pragma once #include -#include +#include +#include #include namespace sycl { diff --git a/sycl/include/sycl/detail/owner_less_base.hpp b/sycl/include/sycl/detail/owner_less_base.hpp index d082afd954d1c..b810596c1f217 100644 --- a/sycl/include/sycl/detail/owner_less_base.hpp +++ b/sycl/include/sycl/detail/owner_less_base.hpp @@ -8,8 +8,8 @@ #pragma once -#include #include +#include #include namespace sycl { diff --git a/sycl/include/sycl/detail/property_helper.hpp b/sycl/include/sycl/detail/property_helper.hpp index 1ecd9b15e1773..5ada3ee10c4d9 100644 --- a/sycl/include/sycl/detail/property_helper.hpp +++ b/sycl/include/sycl/detail/property_helper.hpp @@ -8,7 +8,7 @@ #pragma once -#include +#include namespace sycl { __SYCL_INLINE_VER_NAMESPACE(_V1) { diff --git a/sycl/include/sycl/detail/property_list_base.hpp b/sycl/include/sycl/detail/property_list_base.hpp index e1e5e0d053d24..96ff4aab89a55 100644 --- a/sycl/include/sycl/detail/property_list_base.hpp +++ b/sycl/include/sycl/detail/property_list_base.hpp @@ -8,9 +8,9 @@ #pragma once -#include #include #include +#include #include #include diff --git a/sycl/include/sycl/detail/stl_type_traits.hpp b/sycl/include/sycl/detail/stl_type_traits.hpp index 30261af1eb9f0..747632f649c20 100644 --- a/sycl/include/sycl/detail/stl_type_traits.hpp +++ b/sycl/include/sycl/detail/stl_type_traits.hpp @@ -8,9 +8,9 @@ #pragma once +#include + #include -#include -#include #include namespace sycl { diff --git a/sycl/include/sycl/device_selector.hpp b/sycl/include/sycl/device_selector.hpp index d34ec60f5c0d6..4a23f701d53aa 100644 --- a/sycl/include/sycl/device_selector.hpp +++ b/sycl/include/sycl/device_selector.hpp @@ -21,6 +21,7 @@ __SYCL_INLINE_VER_NAMESPACE(_V1) { // Forward declarations class device; +class context; enum class aspect; namespace ext::oneapi { diff --git a/sycl/include/sycl/exception_list.hpp b/sycl/include/sycl/exception_list.hpp index 8852fd02b0b6f..1aa71c0130019 100644 --- a/sycl/include/sycl/exception_list.hpp +++ b/sycl/include/sycl/exception_list.hpp @@ -10,6 +10,7 @@ // 4.9.2 Exception Class Interface +#include #include #include #include @@ -52,8 +53,6 @@ class __SYCL_EXPORT exception_list { std::vector MList; }; -using async_handler = std::function; - namespace detail { // Default implementation of async_handler used by queue and context when no // user-defined async_handler is specified. diff --git a/sycl/include/sycl/ext/oneapi/experimental/device_architecture.hpp b/sycl/include/sycl/ext/oneapi/experimental/device_architecture.hpp index 9dd985e3b3af7..45aa5b8c59855 100644 --- a/sycl/include/sycl/ext/oneapi/experimental/device_architecture.hpp +++ b/sycl/include/sycl/ext/oneapi/experimental/device_architecture.hpp @@ -1,3 +1,11 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + #pragma once #include diff --git a/sycl/include/sycl/ext/oneapi/experimental/graph.hpp b/sycl/include/sycl/ext/oneapi/experimental/graph.hpp index 368b7733b496b..b0e9100ce2ae1 100644 --- a/sycl/include/sycl/ext/oneapi/experimental/graph.hpp +++ b/sycl/include/sycl/ext/oneapi/experimental/graph.hpp @@ -9,6 +9,7 @@ #pragma once #include +#include #include #include diff --git a/sycl/include/sycl/info/info_desc.hpp b/sycl/include/sycl/info/info_desc.hpp index 90040767f9589..be57a9430ca60 100644 --- a/sycl/include/sycl/info/info_desc.hpp +++ b/sycl/include/sycl/info/info_desc.hpp @@ -9,10 +9,9 @@ #pragma once #include -#include -#include +#include #include -#include +#include namespace sycl { __SYCL_INLINE_VER_NAMESPACE(_V1) { @@ -21,6 +20,7 @@ class device; class platform; class kernel_id; enum class memory_scope; +enum class memory_order; // TODO: stop using OpenCL directly, use PI. namespace info { diff --git a/sycl/include/sycl/property_list.hpp b/sycl/include/sycl/property_list.hpp index 367b91e7ff463..9566f9ea8e390 100644 --- a/sycl/include/sycl/property_list.hpp +++ b/sycl/include/sycl/property_list.hpp @@ -8,7 +8,6 @@ #pragma once -#include #include #include diff --git a/sycl/include/sycl/queue.hpp b/sycl/include/sycl/queue.hpp index 66635610b7bd4..e64e9182ec977 100644 --- a/sycl/include/sycl/queue.hpp +++ b/sycl/include/sycl/queue.hpp @@ -9,9 +9,9 @@ #pragma once #include -#include #include #include +#include #include #include diff --git a/sycl/source/detail/config.hpp b/sycl/source/detail/config.hpp index 7a21efb515b23..febb5770a5b78 100644 --- a/sycl/source/detail/config.hpp +++ b/sycl/source/detail/config.hpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include diff --git a/sycl/source/detail/sampler_impl.hpp b/sycl/source/detail/sampler_impl.hpp index 32652d6ea5c0f..07a79a21cd64b 100644 --- a/sycl/source/detail/sampler_impl.hpp +++ b/sycl/source/detail/sampler_impl.hpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include diff --git a/sycl/source/detail/sycl_mem_obj_t.hpp b/sycl/source/detail/sycl_mem_obj_t.hpp index 100fc3c39b766..582c8b652d95d 100644 --- a/sycl/source/detail/sycl_mem_obj_t.hpp +++ b/sycl/source/detail/sycl_mem_obj_t.hpp @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include From c14baa8970d08ddacbff08b4f91dfdffe70db349 Mon Sep 17 00:00:00 2001 From: Alexey Bader Date: Tue, 18 Jul 2023 14:51:39 -0700 Subject: [PATCH 2/7] Fix formatting. --- sycl/include/sycl/async_handler.hpp | 2 +- sycl/include/sycl/buffer.hpp | 2 +- sycl/include/sycl/ext/oneapi/experimental/graph.hpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sycl/include/sycl/async_handler.hpp b/sycl/include/sycl/async_handler.hpp index b9ae6bc8a0b79..278941b38f0b6 100644 --- a/sycl/include/sycl/async_handler.hpp +++ b/sycl/include/sycl/async_handler.hpp @@ -19,5 +19,5 @@ __SYCL_INLINE_VER_NAMESPACE(_V1) { class exception_list; using async_handler = std::function; -} +} // __SYCL_INLINE_VER_NAMESPACE(_V1) } // namespace sycl diff --git a/sycl/include/sycl/buffer.hpp b/sycl/include/sycl/buffer.hpp index ae230c328b637..bf56a88e760d8 100644 --- a/sycl/include/sycl/buffer.hpp +++ b/sycl/include/sycl/buffer.hpp @@ -16,8 +16,8 @@ #include #include #include -#include #include +#include #include #include diff --git a/sycl/include/sycl/ext/oneapi/experimental/graph.hpp b/sycl/include/sycl/ext/oneapi/experimental/graph.hpp index b0e9100ce2ae1..47031708b9b6d 100644 --- a/sycl/include/sycl/ext/oneapi/experimental/graph.hpp +++ b/sycl/include/sycl/ext/oneapi/experimental/graph.hpp @@ -9,8 +9,8 @@ #pragma once #include -#include #include +#include #include #include From 25a17206b7e7ab1a53728e197f323544ca6748d2 Mon Sep 17 00:00:00 2001 From: Alexey Bader Date: Tue, 18 Jul 2023 16:26:56 -0700 Subject: [PATCH 3/7] Include what you use. --- sycl/include/sycl/backend_types.hpp | 3 ++- sycl/source/detail/posix_pi.cpp | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/sycl/include/sycl/backend_types.hpp b/sycl/include/sycl/backend_types.hpp index eedf87515a2dc..ce308e3d52d82 100644 --- a/sycl/include/sycl/backend_types.hpp +++ b/sycl/include/sycl/backend_types.hpp @@ -9,7 +9,8 @@ #pragma once #include -#include + +#include namespace sycl { __SYCL_INLINE_VER_NAMESPACE(_V1) { diff --git a/sycl/source/detail/posix_pi.cpp b/sycl/source/detail/posix_pi.cpp index decce7bb67083..8b44ecc6b82ec 100644 --- a/sycl/source/detail/posix_pi.cpp +++ b/sycl/source/detail/posix_pi.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include From b3539c565e50943f291fd244b9739ef2e7babf17 Mon Sep 17 00:00:00 2001 From: Alexey Bader Date: Tue, 18 Jul 2023 16:54:58 -0700 Subject: [PATCH 4/7] Remove getRawSyclObjImpl template. --- sycl/include/sycl/context.hpp | 4 ---- sycl/include/sycl/detail/impl_utils.hpp | 9 -------- sycl/include/sycl/device.hpp | 4 ---- .../program_manager/program_manager.cpp | 22 ++++++++++--------- 4 files changed, 12 insertions(+), 27 deletions(-) diff --git a/sycl/include/sycl/context.hpp b/sycl/include/sycl/context.hpp index 1c4cd91678567..84be99825e5b6 100644 --- a/sycl/include/sycl/context.hpp +++ b/sycl/include/sycl/context.hpp @@ -230,10 +230,6 @@ class __SYCL_EXPORT context : public detail::OwnerLessBase { template friend decltype(Obj::impl) detail::getSyclObjImpl(const Obj &SyclObject); - template - friend typename std::add_pointer_t - detail::getRawSyclObjImpl(const T &SyclObject); - template friend T detail::createSyclObjFromImpl(decltype(T::impl) ImplObj); }; diff --git a/sycl/include/sycl/detail/impl_utils.hpp b/sycl/include/sycl/detail/impl_utils.hpp index 34e209b8c17c3..94159f7c8ab50 100644 --- a/sycl/include/sycl/detail/impl_utils.hpp +++ b/sycl/include/sycl/detail/impl_utils.hpp @@ -33,15 +33,6 @@ template decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject) { return SyclObject.impl; } -// Returns the raw pointer to the impl object of given face object. The caller -// must make sure the returned pointer is not captured in a field or otherwise -// stored - i.e. must live only as on-stack value. -template -typename std::add_pointer_t -getRawSyclObjImpl(const T &SyclObject) { - return SyclObject.impl.get(); -} - // Helper function for creation SYCL interface objects from implementations. // Note! This function relies on the fact that all SYCL interface classes // contain "impl" field that points to implementation object. "impl" field diff --git a/sycl/include/sycl/device.hpp b/sycl/include/sycl/device.hpp index 9f4202f674be4..946067ca318dd 100644 --- a/sycl/include/sycl/device.hpp +++ b/sycl/include/sycl/device.hpp @@ -277,10 +277,6 @@ class __SYCL_EXPORT device : public detail::OwnerLessBase { template friend decltype(Obj::impl) detail::getSyclObjImpl(const Obj &SyclObject); - template - friend typename std::add_pointer_t - detail::getRawSyclObjImpl(const T &SyclObject); - template friend T detail::createSyclObjFromImpl(decltype(T::impl) ImplObj); diff --git a/sycl/source/detail/program_manager/program_manager.cpp b/sycl/source/detail/program_manager/program_manager.cpp index d1d2b6eea1e3a..61e2a4832d74a 100644 --- a/sycl/source/detail/program_manager/program_manager.cpp +++ b/sycl/source/detail/program_manager/program_manager.cpp @@ -114,8 +114,9 @@ ProgramManager::getDeviceImage(const std::string &KernelName, bool JITCompilationIsRequired) { if (DbgProgMgr > 0) std::cerr << ">>> ProgramManager::getDeviceImage(\"" << KernelName << "\", " - << getRawSyclObjImpl(Context) << ", " << getRawSyclObjImpl(Device) - << ", " << JITCompilationIsRequired << ")\n"; + << getSyclObjImpl(Context).get() << ", " + << getSyclObjImpl(Device).get() << ", " + << JITCompilationIsRequired << ")\n"; KernelSetId KSId = getKernelSetId(KernelName); return getDeviceImage(KSId, Context, Device, JITCompilationIsRequired); @@ -282,8 +283,8 @@ ProgramManager::createPIProgram(const RTDeviceBinaryImage &Img, const context &Context, const device &Device) { if (DbgProgMgr > 0) std::cerr << ">>> ProgramManager::createPIProgram(" << &Img << ", " - << getRawSyclObjImpl(Context) << ", " << getRawSyclObjImpl(Device) - << ")\n"; + << getSyclObjImpl(Context).get() << ", " + << getSyclObjImpl(Device).get() << ")\n"; const pi_device_binary_struct &RawImg = Img.getRawData(); // perform minimal sanity checks on the device image and the descriptor @@ -718,7 +719,7 @@ sycl::detail::pi::PiProgram ProgramManager::getBuiltPIProgram( ProgramPtr BuiltProgram = build(std::move(ProgramManaged), ContextImpl, CompileOpts, LinkOpts, - getRawSyclObjImpl(Device)->getHandleRef(), DeviceLibReqMask); + getSyclObjImpl(Device).get()->getHandleRef(), DeviceLibReqMask); emitBuiltProgramInfo(BuiltProgram.get(), ContextImpl); @@ -1053,8 +1054,9 @@ ProgramManager::getDeviceImage(KernelSetId KSId, const context &Context, bool JITCompilationIsRequired) { if (DbgProgMgr > 0) { std::cerr << ">>> ProgramManager::getDeviceImage(\"" << KSId << "\", " - << getRawSyclObjImpl(Context) << ", " << getRawSyclObjImpl(Device) - << ", " << JITCompilationIsRequired << ")\n"; + << getSyclObjImpl(Context).get() << ", " + << getSyclObjImpl(Device).get() << ", " + << JITCompilationIsRequired << ")\n"; std::cerr << "available device images:\n"; debugPrintBinaryImages(); @@ -2332,7 +2334,7 @@ device_image_plain ProgramManager::build(const device_image_plain &DeviceImage, ProgramPtr BuiltProgram = build(std::move(ProgramManaged), ContextImpl, CompileOpts, LinkOpts, - getRawSyclObjImpl(Devs[0])->getHandleRef(), DeviceLibReqMask); + getSyclObjImpl(Devs[0]).get()->getHandleRef(), DeviceLibReqMask); emitBuiltProgramInfo(BuiltProgram.get(), ContextImpl); @@ -2353,7 +2355,7 @@ device_image_plain ProgramManager::build(const device_image_plain &DeviceImage, uint32_t ImgId = Img.getImageID(); const sycl::detail::pi::PiDevice PiDevice = - getRawSyclObjImpl(Devs[0])->getHandleRef(); + getSyclObjImpl(Devs[0]).get()->getHandleRef(); auto CacheKey = std::make_pair(std::make_pair(std::move(SpecConsts), ImgId), std::make_pair(PiDevice, CompileOpts + LinkOpts)); @@ -2386,7 +2388,7 @@ device_image_plain ProgramManager::build(const device_image_plain &DeviceImage, // call to getOrBuild, so starting with "1" for (size_t Idx = 1; Idx < Devs.size(); ++Idx) { const sycl::detail::pi::PiDevice PiDeviceAdd = - getRawSyclObjImpl(Devs[Idx])->getHandleRef(); + getSyclObjImpl(Devs[Idx]).get()->getHandleRef(); // Change device in the cache key to reduce copying of spec const data. CacheKey.second.first = PiDeviceAdd; From debc4aaf7e0d4d5e2f3eed47fc1a6c25da1d2594 Mon Sep 17 00:00:00 2001 From: Alexey Bader Date: Tue, 18 Jul 2023 16:59:06 -0700 Subject: [PATCH 5/7] Fix formatting. --- sycl/source/detail/posix_pi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sycl/source/detail/posix_pi.cpp b/sycl/source/detail/posix_pi.cpp index 8b44ecc6b82ec..35abc17bd2e32 100644 --- a/sycl/source/detail/posix_pi.cpp +++ b/sycl/source/detail/posix_pi.cpp @@ -7,8 +7,8 @@ //===----------------------------------------------------------------------===// #include -#include #include +#include #include #include From 89a14b1e8743c326535d138d775e32028991531a Mon Sep 17 00:00:00 2001 From: Alexey Bader Date: Wed, 19 Jul 2023 13:54:57 -0700 Subject: [PATCH 6/7] Add file name to license comment. --- sycl/include/sycl/async_handler.hpp | 2 +- sycl/include/sycl/detail/impl_utils.hpp | 2 +- .../sycl/ext/oneapi/experimental/device_architecture.hpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sycl/include/sycl/async_handler.hpp b/sycl/include/sycl/async_handler.hpp index 278941b38f0b6..01ba71dc51efd 100644 --- a/sycl/include/sycl/async_handler.hpp +++ b/sycl/include/sycl/async_handler.hpp @@ -1,4 +1,4 @@ -//===----------------------------------------------------------------------===// +//===- async_handler.hpp --------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/sycl/include/sycl/detail/impl_utils.hpp b/sycl/include/sycl/detail/impl_utils.hpp index 94159f7c8ab50..a5664430fb700 100644 --- a/sycl/include/sycl/detail/impl_utils.hpp +++ b/sycl/include/sycl/detail/impl_utils.hpp @@ -1,4 +1,4 @@ -//===----------------------------------------------------------------------===// +//===- impl_utils.hpp -----------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/sycl/include/sycl/ext/oneapi/experimental/device_architecture.hpp b/sycl/include/sycl/ext/oneapi/experimental/device_architecture.hpp index 45aa5b8c59855..40031dea73a31 100644 --- a/sycl/include/sycl/ext/oneapi/experimental/device_architecture.hpp +++ b/sycl/include/sycl/ext/oneapi/experimental/device_architecture.hpp @@ -1,4 +1,4 @@ -//===----------------------------------------------------------------------===// +//===- device_architecture.hpp --------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. From 4eda86bf6beab6da78dad4e71c00312b3a86a2d1 Mon Sep 17 00:00:00 2001 From: Alexey Bader Date: Wed, 19 Jul 2023 14:06:29 -0700 Subject: [PATCH 7/7] Revert "Remove getRawSyclObjImpl template." This reverts commit b3539c565e50943f291fd244b9739ef2e7babf17. --- sycl/include/sycl/context.hpp | 4 ++++ sycl/include/sycl/detail/impl_utils.hpp | 9 ++++++++ sycl/include/sycl/device.hpp | 4 ++++ .../program_manager/program_manager.cpp | 22 +++++++++---------- 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/sycl/include/sycl/context.hpp b/sycl/include/sycl/context.hpp index 84be99825e5b6..1c4cd91678567 100644 --- a/sycl/include/sycl/context.hpp +++ b/sycl/include/sycl/context.hpp @@ -230,6 +230,10 @@ class __SYCL_EXPORT context : public detail::OwnerLessBase { template friend decltype(Obj::impl) detail::getSyclObjImpl(const Obj &SyclObject); + template + friend typename std::add_pointer_t + detail::getRawSyclObjImpl(const T &SyclObject); + template friend T detail::createSyclObjFromImpl(decltype(T::impl) ImplObj); }; diff --git a/sycl/include/sycl/detail/impl_utils.hpp b/sycl/include/sycl/detail/impl_utils.hpp index a5664430fb700..622d2d540a6fd 100644 --- a/sycl/include/sycl/detail/impl_utils.hpp +++ b/sycl/include/sycl/detail/impl_utils.hpp @@ -33,6 +33,15 @@ template decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject) { return SyclObject.impl; } +// Returns the raw pointer to the impl object of given face object. The caller +// must make sure the returned pointer is not captured in a field or otherwise +// stored - i.e. must live only as on-stack value. +template +typename std::add_pointer_t +getRawSyclObjImpl(const T &SyclObject) { + return SyclObject.impl.get(); +} + // Helper function for creation SYCL interface objects from implementations. // Note! This function relies on the fact that all SYCL interface classes // contain "impl" field that points to implementation object. "impl" field diff --git a/sycl/include/sycl/device.hpp b/sycl/include/sycl/device.hpp index 946067ca318dd..9f4202f674be4 100644 --- a/sycl/include/sycl/device.hpp +++ b/sycl/include/sycl/device.hpp @@ -277,6 +277,10 @@ class __SYCL_EXPORT device : public detail::OwnerLessBase { template friend decltype(Obj::impl) detail::getSyclObjImpl(const Obj &SyclObject); + template + friend typename std::add_pointer_t + detail::getRawSyclObjImpl(const T &SyclObject); + template friend T detail::createSyclObjFromImpl(decltype(T::impl) ImplObj); diff --git a/sycl/source/detail/program_manager/program_manager.cpp b/sycl/source/detail/program_manager/program_manager.cpp index 61e2a4832d74a..d1d2b6eea1e3a 100644 --- a/sycl/source/detail/program_manager/program_manager.cpp +++ b/sycl/source/detail/program_manager/program_manager.cpp @@ -114,9 +114,8 @@ ProgramManager::getDeviceImage(const std::string &KernelName, bool JITCompilationIsRequired) { if (DbgProgMgr > 0) std::cerr << ">>> ProgramManager::getDeviceImage(\"" << KernelName << "\", " - << getSyclObjImpl(Context).get() << ", " - << getSyclObjImpl(Device).get() << ", " - << JITCompilationIsRequired << ")\n"; + << getRawSyclObjImpl(Context) << ", " << getRawSyclObjImpl(Device) + << ", " << JITCompilationIsRequired << ")\n"; KernelSetId KSId = getKernelSetId(KernelName); return getDeviceImage(KSId, Context, Device, JITCompilationIsRequired); @@ -283,8 +282,8 @@ ProgramManager::createPIProgram(const RTDeviceBinaryImage &Img, const context &Context, const device &Device) { if (DbgProgMgr > 0) std::cerr << ">>> ProgramManager::createPIProgram(" << &Img << ", " - << getSyclObjImpl(Context).get() << ", " - << getSyclObjImpl(Device).get() << ")\n"; + << getRawSyclObjImpl(Context) << ", " << getRawSyclObjImpl(Device) + << ")\n"; const pi_device_binary_struct &RawImg = Img.getRawData(); // perform minimal sanity checks on the device image and the descriptor @@ -719,7 +718,7 @@ sycl::detail::pi::PiProgram ProgramManager::getBuiltPIProgram( ProgramPtr BuiltProgram = build(std::move(ProgramManaged), ContextImpl, CompileOpts, LinkOpts, - getSyclObjImpl(Device).get()->getHandleRef(), DeviceLibReqMask); + getRawSyclObjImpl(Device)->getHandleRef(), DeviceLibReqMask); emitBuiltProgramInfo(BuiltProgram.get(), ContextImpl); @@ -1054,9 +1053,8 @@ ProgramManager::getDeviceImage(KernelSetId KSId, const context &Context, bool JITCompilationIsRequired) { if (DbgProgMgr > 0) { std::cerr << ">>> ProgramManager::getDeviceImage(\"" << KSId << "\", " - << getSyclObjImpl(Context).get() << ", " - << getSyclObjImpl(Device).get() << ", " - << JITCompilationIsRequired << ")\n"; + << getRawSyclObjImpl(Context) << ", " << getRawSyclObjImpl(Device) + << ", " << JITCompilationIsRequired << ")\n"; std::cerr << "available device images:\n"; debugPrintBinaryImages(); @@ -2334,7 +2332,7 @@ device_image_plain ProgramManager::build(const device_image_plain &DeviceImage, ProgramPtr BuiltProgram = build(std::move(ProgramManaged), ContextImpl, CompileOpts, LinkOpts, - getSyclObjImpl(Devs[0]).get()->getHandleRef(), DeviceLibReqMask); + getRawSyclObjImpl(Devs[0])->getHandleRef(), DeviceLibReqMask); emitBuiltProgramInfo(BuiltProgram.get(), ContextImpl); @@ -2355,7 +2353,7 @@ device_image_plain ProgramManager::build(const device_image_plain &DeviceImage, uint32_t ImgId = Img.getImageID(); const sycl::detail::pi::PiDevice PiDevice = - getSyclObjImpl(Devs[0]).get()->getHandleRef(); + getRawSyclObjImpl(Devs[0])->getHandleRef(); auto CacheKey = std::make_pair(std::make_pair(std::move(SpecConsts), ImgId), std::make_pair(PiDevice, CompileOpts + LinkOpts)); @@ -2388,7 +2386,7 @@ device_image_plain ProgramManager::build(const device_image_plain &DeviceImage, // call to getOrBuild, so starting with "1" for (size_t Idx = 1; Idx < Devs.size(); ++Idx) { const sycl::detail::pi::PiDevice PiDeviceAdd = - getSyclObjImpl(Devs[Idx]).get()->getHandleRef(); + getRawSyclObjImpl(Devs[Idx])->getHandleRef(); // Change device in the cache key to reduce copying of spec const data. CacheKey.second.first = PiDeviceAdd;