From 91f552fb6e1bbed774485347a86f303495dafc77 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Wed, 2 Nov 2022 13:35:31 -0500 Subject: [PATCH 01/10] Added dpctl_sycl_type_casters.hpp defining convertion functions wrap/unwrap functions for conversions between opaque DPCTL types and underlying SYCL object pointers is provided in this new header. Use of the header is deployed to files in libsyclinterface/source/ and libsyclinterface/tests/ folders. Removed libsyclinterface/include/Support/CBindingWrapping.h --- .../include/Support/CBindingWrapping.h | 55 ---- .../include/dpctl_sycl_type_casters.hpp | 249 ++++++++++++++++++ .../source/dpctl_sycl_context_interface.cpp | 11 +- .../source/dpctl_sycl_device_interface.cpp | 8 +- .../source/dpctl_sycl_device_manager.cpp | 6 +- .../dpctl_sycl_device_selector_interface.cpp | 26 +- .../source/dpctl_sycl_event_interface.cpp | 8 +- .../dpctl_sycl_kernel_bundle_interface.cpp | 7 +- .../source/dpctl_sycl_kernel_interface.cpp | 9 +- .../source/dpctl_sycl_platform_interface.cpp | 11 +- .../source/dpctl_sycl_platform_manager.cpp | 3 +- .../source/dpctl_sycl_queue_interface.cpp | 8 +- .../source/dpctl_sycl_queue_manager.cpp | 6 +- .../source/dpctl_sycl_usm_interface.cpp | 12 +- .../source/dpctl_vector_templ.cpp | 18 +- .../tests/test_sycl_context_interface.cpp | 1 - .../tests/test_sycl_device_aspects.cpp | 3 +- .../test_sycl_device_selector_interface.cpp | 8 +- .../tests/test_sycl_device_subdevices.cpp | 4 +- .../tests/test_sycl_event_interface.cpp | 1 - .../tests/test_sycl_platform_interface.cpp | 1 - .../tests/test_sycl_queue_interface.cpp | 3 +- .../tests/test_sycl_queue_manager.cpp | 4 +- .../tests/test_sycl_queue_submit.cpp | 3 +- .../tests/test_sycl_usm_interface.cpp | 4 +- 25 files changed, 282 insertions(+), 187 deletions(-) delete mode 100644 libsyclinterface/include/Support/CBindingWrapping.h create mode 100644 libsyclinterface/include/dpctl_sycl_type_casters.hpp diff --git a/libsyclinterface/include/Support/CBindingWrapping.h b/libsyclinterface/include/Support/CBindingWrapping.h deleted file mode 100644 index 6ace044267..0000000000 --- a/libsyclinterface/include/Support/CBindingWrapping.h +++ /dev/null @@ -1,55 +0,0 @@ -//===- CBindingWrapping.h - Wrappers for casting C pointers -*-C++-*- ===// -// -// Data Parallel Control (dpctl) -// -// Copyright 2020-2022 Intel Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//===----------------------------------------------------------------------===// -/// -/// \file -/// This file declares the wrapping macros for the dpctl C interface. -/// -//===----------------------------------------------------------------------===// - -#pragma once - -/*! - @brief Creates two convenience functions to reinterpret_cast an opaque - pointer to a pointer to a Sycl type and vice-versa. -*/ -#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \ - __attribute__((unused)) inline ty *unwrap(ref P) \ - { \ - return reinterpret_cast(P); \ - } \ - \ - __attribute__((unused)) inline ref wrap(const ty *P) \ - { \ - return reinterpret_cast(const_cast(P)); \ - } - -/*! - @brief Add an overloaded unwrap to assert that a pointer can be legally - cast. @see DEFINE_SIMPLE_CONVERSION_FUNCTIONS() -*/ -#define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \ - DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \ - \ - template __attribute__((unused)) inline T *unwrap(ref P) \ - { \ - T *Q = (T *)unwrap(P); \ - assert(Q && "Invalid cast!"); \ - return Q; \ - } diff --git a/libsyclinterface/include/dpctl_sycl_type_casters.hpp b/libsyclinterface/include/dpctl_sycl_type_casters.hpp new file mode 100644 index 0000000000..c0a5cbf025 --- /dev/null +++ b/libsyclinterface/include/dpctl_sycl_type_casters.hpp @@ -0,0 +1,249 @@ +//===-- dpctl_sycl_type_casters.h - Defines casters between --------*-C++-*- =// +// the opaque and the underlying types. +// +// Data Parallel Control (dpctl) +// +// Copyright 2020-2022 Intel Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// This file defines casters between opaque types and underlying SYCL types. +/// +//===----------------------------------------------------------------------===// + +#pragma once + +#ifdef __cplusplus + +#include "dpctl_sycl_types.h" +#include +#include + +#if __SYCL_COMPILER_VERSION >= 20221020 + +class dpctl_device_selector +{ +public: + virtual ~dpctl_device_selector() = default; + + virtual int operator()(const sycl::device &device) const = 0; +}; + +class dpctl_accelerator_selector : public dpctl_device_selector +{ +public: + dpctl_accelerator_selector() = default; + int operator()(const sycl::device &d) const + { + return sycl::accelerator_selector_v(d); + } +}; + +class dpctl_default_selector : public dpctl_device_selector +{ +public: + dpctl_default_selector() = default; + int operator()(const sycl::device &d) const + { + return sycl::default_selector_v(d); + } +}; + +class dpctl_gpu_selector : public dpctl_device_selector +{ +public: + dpctl_gpu_selector() = default; + int operator()(const sycl::device &d) const + { + return sycl::gpu_selector_v(d); + } +}; + +class dpctl_cpu_selector : public dpctl_device_selector +{ +public: + dpctl_cpu_selector() = default; + int operator()(const sycl::device &d) const + { + return sycl::cpu_selector_v(d); + } +}; + +class dpctl_filter_selector : public dpctl_device_selector +{ +public: + dpctl_filter_selector(const std::string &fs) : _impl(fs) {} + + int operator()(const sycl::device &d) const + { + return _impl(d); + } + +private: + sycl::ext::oneapi::filter_selector _impl; +}; + +class dpctl_host_selector : public dpctl_device_selector +{ +public: + dpctl_host_selector() = default; + int operator()(const sycl::device &) const + { + return REJECTED_SCORE; + } + +private: + constexpr static int REJECTED_SCORE = -1; +}; + +#else + +class dpctl_device_selector : public sycl::device_selector +{ +public: + virtual ~dpctl_device_selector() = default; + + virtual int operator()(const sycl::device &device) const = 0; +}; + +class dpctl_accelerator_selector : public dpctl_device_selector +{ +public: + dpctl_accelerator_selector() : _impl(){}; + int operator()(const sycl::device &d) const + { + return _impl(d); + } + +private: + sycl::accelerator_selector _impl; +}; + +class dpctl_default_selector : public dpctl_device_selector +{ +public: + dpctl_default_selector() : _impl(){}; + int operator()(const sycl::device &d) const + { + return _impl(d); + } + +private: + sycl::default_selector _impl; +}; + +class dpctl_gpu_selector : public dpctl_device_selector +{ +public: + dpctl_gpu_selector() : _impl(){}; + int operator()(const sycl::device &d) const + { + return _impl(d); + } + +private: + sycl::gpu_selector _impl; +}; + +class dpctl_cpu_selector : public dpctl_device_selector +{ +public: + dpctl_cpu_selector() : _impl(){}; + int operator()(const sycl::device &d) const + { + return _impl(d); + } + +private: + sycl::cpu_selector _impl; +}; + +class dpctl_filter_selector : public dpctl_device_selector +{ +public: + dpctl_filter_selector(const std::string &fs) : _impl(fs) {} + + int operator()(const sycl::device &d) const + { + return _impl(d); + } + +private: + sycl::ext::oneapi::filter_selector _impl; +}; + +class dpctl_host_selector : public dpctl_device_selector +{ +public: + dpctl_host_selector() : _impl(){}; + int operator()(const sycl::device &d) const + { + return _impl(d); + } + +private: + sycl::host_selector _impl; +}; + +#endif + +/*! + @brief Creates two convenience functions to reinterpret_cast an opaque + pointer to a pointer to a Sycl type and vice-versa. +*/ +#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \ + __attribute__((unused)) inline ty *unwrap(ref P) \ + { \ + return reinterpret_cast(P); \ + } \ + \ + __attribute__((unused)) inline ref wrap(const ty *P) \ + { \ + return reinterpret_cast(const_cast(P)); \ + } \ + template ::value, bool> = true> \ + ref wrap(const ty *P) \ + { \ + return reinterpret_cast(const_cast(P)); \ + } + +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(dpctl_device_selector, + DPCTLSyclDeviceSelectorRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(sycl::device, DPCTLSyclDeviceRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(sycl::context, DPCTLSyclContextRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(sycl::queue, DPCTLSyclQueueRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(void, DPCTLSyclUSMRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(sycl::platform, DPCTLSyclPlatformRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(sycl::event, DPCTLSyclEventRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(sycl::kernel, DPCTLSyclKernelRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS( + sycl::kernel_bundle, + DPCTLSyclKernelBundleRef) + +#include "dpctl_sycl_device_manager.h" +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(std::vector, + DPCTLDeviceVectorRef) + +#include "dpctl_sycl_platform_manager.h" +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(std::vector, + DPCTLPlatformVectorRef) + +#include "dpctl_sycl_event_interface.h" +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(std::vector, + DPCTLEventVectorRef) + +#endif diff --git a/libsyclinterface/source/dpctl_sycl_context_interface.cpp b/libsyclinterface/source/dpctl_sycl_context_interface.cpp index 57bc256b84..136848a68a 100644 --- a/libsyclinterface/source/dpctl_sycl_context_interface.cpp +++ b/libsyclinterface/source/dpctl_sycl_context_interface.cpp @@ -25,22 +25,13 @@ //===----------------------------------------------------------------------===// #include "dpctl_sycl_context_interface.h" -#include "Support/CBindingWrapping.h" #include "dpctl_error_handlers.h" +#include "dpctl_sycl_type_casters.hpp" #include #include using namespace sycl; -namespace -{ -// Create wrappers for C Binding types (see CBindingWrapping.h). -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(context, DPCTLSyclContextRef) -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(device, DPCTLSyclDeviceRef) -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(std::vector, - DPCTLDeviceVectorRef) -} /* end of anonymous namespace */ - __dpctl_give DPCTLSyclContextRef DPCTLContext_Create(__dpctl_keep const DPCTLSyclDeviceRef DRef, error_handler_callback *handler, diff --git a/libsyclinterface/source/dpctl_sycl_device_interface.cpp b/libsyclinterface/source/dpctl_sycl_device_interface.cpp index 7761018686..d8f8cfaeae 100644 --- a/libsyclinterface/source/dpctl_sycl_device_interface.cpp +++ b/libsyclinterface/source/dpctl_sycl_device_interface.cpp @@ -25,10 +25,10 @@ //===----------------------------------------------------------------------===// #include "dpctl_sycl_device_interface.h" -#include "Support/CBindingWrapping.h" #include "dpctl_error_handlers.h" #include "dpctl_string_utils.hpp" #include "dpctl_sycl_device_manager.h" +#include "dpctl_sycl_type_casters.hpp" #include "dpctl_utils_helper.h" #include /* SYCL headers */ #include @@ -39,12 +39,6 @@ using namespace sycl; namespace { -// Create wrappers for C Binding types (see CBindingWrapping.h). -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(device, DPCTLSyclDeviceRef) -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(device_selector, DPCTLSyclDeviceSelectorRef) -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(platform, DPCTLSyclPlatformRef) -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(std::vector, - DPCTLDeviceVectorRef) template __dpctl_keep size_t * diff --git a/libsyclinterface/source/dpctl_sycl_device_manager.cpp b/libsyclinterface/source/dpctl_sycl_device_manager.cpp index 2bbacb60da..544a9019fd 100644 --- a/libsyclinterface/source/dpctl_sycl_device_manager.cpp +++ b/libsyclinterface/source/dpctl_sycl_device_manager.cpp @@ -24,10 +24,10 @@ //===----------------------------------------------------------------------===// #include "dpctl_sycl_device_manager.h" -#include "Support/CBindingWrapping.h" #include "dpctl_error_handlers.h" #include "dpctl_string_utils.hpp" #include "dpctl_sycl_enum_types.h" +#include "dpctl_sycl_type_casters.hpp" #include "dpctl_utils_helper.h" #include /* SYCL headers */ #include @@ -40,10 +40,6 @@ using namespace sycl; namespace { -// Create wrappers for C Binding types (see CBindingWrapping.h). -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(device, DPCTLSyclDeviceRef) -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(context, DPCTLSyclContextRef) - /* * Helper function to print the metadata for a sycl::device. */ diff --git a/libsyclinterface/source/dpctl_sycl_device_selector_interface.cpp b/libsyclinterface/source/dpctl_sycl_device_selector_interface.cpp index fe0ce3e123..0480038968 100644 --- a/libsyclinterface/source/dpctl_sycl_device_selector_interface.cpp +++ b/libsyclinterface/source/dpctl_sycl_device_selector_interface.cpp @@ -24,24 +24,16 @@ //===----------------------------------------------------------------------===// #include "dpctl_sycl_device_selector_interface.h" -#include "Support/CBindingWrapping.h" #include "dpctl_error_handlers.h" +#include "dpctl_sycl_type_casters.hpp" #include /* SYCL headers */ using namespace sycl; -namespace -{ -// Create wrappers for C Binding types (see CBindingWrapping.h). -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(device_selector, DPCTLSyclDeviceSelectorRef) -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(device, DPCTLSyclDeviceRef) - -} /* end of anonymous namespace */ - __dpctl_give DPCTLSyclDeviceSelectorRef DPCTLAcceleratorSelector_Create() { try { - auto Selector = new accelerator_selector(); + auto Selector = new dpctl_accelerator_selector(); return wrap(Selector); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); @@ -52,7 +44,7 @@ __dpctl_give DPCTLSyclDeviceSelectorRef DPCTLAcceleratorSelector_Create() __dpctl_give DPCTLSyclDeviceSelectorRef DPCTLDefaultSelector_Create() { try { - auto Selector = new default_selector(); + auto Selector = new dpctl_default_selector(); return wrap(Selector); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); @@ -63,7 +55,7 @@ __dpctl_give DPCTLSyclDeviceSelectorRef DPCTLDefaultSelector_Create() __dpctl_give DPCTLSyclDeviceSelectorRef DPCTLCPUSelector_Create() { try { - auto Selector = new cpu_selector(); + auto Selector = new dpctl_cpu_selector(); return wrap(Selector); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); @@ -74,11 +66,7 @@ __dpctl_give DPCTLSyclDeviceSelectorRef DPCTLCPUSelector_Create() __dpctl_give DPCTLSyclDeviceSelectorRef DPCTLFilterSelector_Create(__dpctl_keep const char *filter_str) { -#if __SYCL_COMPILER_VERSION < 20210925 - using filter_selector_t = sycl::ONEAPI::filter_selector; -#else - using filter_selector_t = sycl::ext::oneapi::filter_selector; -#endif + using filter_selector_t = dpctl_filter_selector; try { auto Selector = new filter_selector_t(filter_str); return wrap(Selector); @@ -91,7 +79,7 @@ DPCTLFilterSelector_Create(__dpctl_keep const char *filter_str) __dpctl_give DPCTLSyclDeviceSelectorRef DPCTLGPUSelector_Create() { try { - auto Selector = new gpu_selector(); + auto Selector = new dpctl_gpu_selector(); return wrap(Selector); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); @@ -102,7 +90,7 @@ __dpctl_give DPCTLSyclDeviceSelectorRef DPCTLGPUSelector_Create() __dpctl_give DPCTLSyclDeviceSelectorRef DPCTLHostSelector_Create() { try { - auto Selector = new host_selector(); + auto Selector = new dpctl_host_selector(); return wrap(Selector); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); diff --git a/libsyclinterface/source/dpctl_sycl_event_interface.cpp b/libsyclinterface/source/dpctl_sycl_event_interface.cpp index 7fb22bd7dc..037f61f211 100644 --- a/libsyclinterface/source/dpctl_sycl_event_interface.cpp +++ b/libsyclinterface/source/dpctl_sycl_event_interface.cpp @@ -25,20 +25,14 @@ //===----------------------------------------------------------------------===// #include "dpctl_sycl_event_interface.h" -#include "Support/CBindingWrapping.h" #include "dpctl_error_handlers.h" +#include "dpctl_sycl_type_casters.hpp" #include "dpctl_utils_helper.h" #include /* SYCL headers */ #include using namespace sycl; -namespace -{ -// Create wrappers for C Binding types (see CBindingWrapping.h) -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(event, DPCTLSyclEventRef) -} /* end of anonymous namespace */ - #undef EL #define EL Event #include "dpctl_vector_templ.cpp" diff --git a/libsyclinterface/source/dpctl_sycl_kernel_bundle_interface.cpp b/libsyclinterface/source/dpctl_sycl_kernel_bundle_interface.cpp index e540259bb9..a646e1a5b1 100644 --- a/libsyclinterface/source/dpctl_sycl_kernel_bundle_interface.cpp +++ b/libsyclinterface/source/dpctl_sycl_kernel_bundle_interface.cpp @@ -27,9 +27,9 @@ #include "dpctl_sycl_kernel_bundle_interface.h" #include "Config/dpctl_config.h" -#include "Support/CBindingWrapping.h" #include "dpctl_dynamic_lib_helper.h" #include "dpctl_error_handlers.h" +#include "dpctl_sycl_type_casters.hpp" #include /* OpenCL headers */ #include /* Sycl headers */ #if __has_include() @@ -56,11 +56,6 @@ using namespace sycl; namespace { -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(context, DPCTLSyclContextRef) -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(device, DPCTLSyclDeviceRef) -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(kernel_bundle, - DPCTLSyclKernelBundleRef) -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(kernel, DPCTLSyclKernelRef) #ifdef __linux__ static const char *clLoaderName = DPCTL_LIBCL_LOADER_FILENAME; diff --git a/libsyclinterface/source/dpctl_sycl_kernel_interface.cpp b/libsyclinterface/source/dpctl_sycl_kernel_interface.cpp index 9f5e278e3b..24da329d3f 100644 --- a/libsyclinterface/source/dpctl_sycl_kernel_interface.cpp +++ b/libsyclinterface/source/dpctl_sycl_kernel_interface.cpp @@ -25,21 +25,14 @@ //===----------------------------------------------------------------------===// #include "dpctl_sycl_kernel_interface.h" -#include "Support/CBindingWrapping.h" #include "dpctl_error_handlers.h" #include "dpctl_string_utils.hpp" +#include "dpctl_sycl_type_casters.hpp" #include /* Sycl headers */ #include using namespace sycl; -namespace -{ - -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(kernel, DPCTLSyclKernelRef) - -} /* end of anonymous namespace */ - size_t DPCTLKernel_GetNumArgs(__dpctl_keep const DPCTLSyclKernelRef KRef) { if (!KRef) { diff --git a/libsyclinterface/source/dpctl_sycl_platform_interface.cpp b/libsyclinterface/source/dpctl_sycl_platform_interface.cpp index 121fbeed1d..d998e8b1f6 100644 --- a/libsyclinterface/source/dpctl_sycl_platform_interface.cpp +++ b/libsyclinterface/source/dpctl_sycl_platform_interface.cpp @@ -25,9 +25,9 @@ //===----------------------------------------------------------------------===// #include "dpctl_sycl_platform_interface.h" -#include "Support/CBindingWrapping.h" #include "dpctl_error_handlers.h" #include "dpctl_string_utils.hpp" +#include "dpctl_sycl_type_casters.hpp" #include "dpctl_utils_helper.h" #include #include @@ -38,15 +38,6 @@ using namespace sycl; -namespace -{ -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(platform, DPCTLSyclPlatformRef); -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(context, DPCTLSyclContextRef); -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(device_selector, DPCTLSyclDeviceSelectorRef); -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(std::vector, - DPCTLPlatformVectorRef); -} // namespace - __dpctl_give DPCTLSyclPlatformRef DPCTLPlatform_Copy(__dpctl_keep const DPCTLSyclPlatformRef PRef) { diff --git a/libsyclinterface/source/dpctl_sycl_platform_manager.cpp b/libsyclinterface/source/dpctl_sycl_platform_manager.cpp index bda2e6bb89..7349f1a927 100644 --- a/libsyclinterface/source/dpctl_sycl_platform_manager.cpp +++ b/libsyclinterface/source/dpctl_sycl_platform_manager.cpp @@ -25,10 +25,10 @@ //===----------------------------------------------------------------------===// #include "dpctl_sycl_platform_manager.h" -#include "Support/CBindingWrapping.h" #include "dpctl_error_handlers.h" #include "dpctl_string_utils.hpp" #include "dpctl_sycl_platform_interface.h" +#include "dpctl_sycl_type_casters.hpp" #include "dpctl_utils_helper.h" #include #include @@ -40,7 +40,6 @@ using namespace sycl; namespace { -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(platform, DPCTLSyclPlatformRef); std::string platform_print_info_impl(const platform &p, size_t verbosity) { diff --git a/libsyclinterface/source/dpctl_sycl_queue_interface.cpp b/libsyclinterface/source/dpctl_sycl_queue_interface.cpp index 9f0b4fa038..98ef528c0a 100644 --- a/libsyclinterface/source/dpctl_sycl_queue_interface.cpp +++ b/libsyclinterface/source/dpctl_sycl_queue_interface.cpp @@ -25,11 +25,11 @@ //===----------------------------------------------------------------------===// #include "dpctl_sycl_queue_interface.h" -#include "Support/CBindingWrapping.h" #include "dpctl_error_handlers.h" #include "dpctl_sycl_context_interface.h" #include "dpctl_sycl_device_interface.h" #include "dpctl_sycl_device_manager.h" +#include "dpctl_sycl_type_casters.hpp" #include /* SYCL headers */ #include #include @@ -38,12 +38,6 @@ using namespace sycl; namespace { -// Create wrappers for C Binding types (see CBindingWrapping.h). -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(context, DPCTLSyclContextRef) -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(device, DPCTLSyclDeviceRef) -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(event, DPCTLSyclEventRef) -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(kernel, DPCTLSyclKernelRef) -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(queue, DPCTLSyclQueueRef) /*! * @brief Set the kernel arg object diff --git a/libsyclinterface/source/dpctl_sycl_queue_manager.cpp b/libsyclinterface/source/dpctl_sycl_queue_manager.cpp index f9f9ab4bba..dee84d3869 100644 --- a/libsyclinterface/source/dpctl_sycl_queue_manager.cpp +++ b/libsyclinterface/source/dpctl_sycl_queue_manager.cpp @@ -24,9 +24,9 @@ /// //===----------------------------------------------------------------------===// #include "dpctl_sycl_queue_manager.h" -#include "Support/CBindingWrapping.h" #include "dpctl_error_handlers.h" #include "dpctl_sycl_device_manager.h" +#include "dpctl_sycl_type_casters.hpp" #include /* SYCL headers */ #include @@ -37,10 +37,6 @@ using namespace sycl; // Anonymous namespace for private helpers namespace { -// Create wrappers for C Binding types (see CBindingWrapping.h). -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(queue, DPCTLSyclQueueRef) -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(device, DPCTLSyclDeviceRef) -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(context, DPCTLSyclContextRef) struct QueueManager { diff --git a/libsyclinterface/source/dpctl_sycl_usm_interface.cpp b/libsyclinterface/source/dpctl_sycl_usm_interface.cpp index a6c92cb1ab..5a36004395 100644 --- a/libsyclinterface/source/dpctl_sycl_usm_interface.cpp +++ b/libsyclinterface/source/dpctl_sycl_usm_interface.cpp @@ -25,23 +25,13 @@ //===----------------------------------------------------------------------===// #include "dpctl_sycl_usm_interface.h" -#include "Support/CBindingWrapping.h" #include "dpctl_error_handlers.h" #include "dpctl_sycl_device_interface.h" +#include "dpctl_sycl_type_casters.hpp" #include /* SYCL headers */ using namespace sycl; -namespace -{ -// Create wrappers for C Binding types (see CBindingWrapping.h). -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(queue, DPCTLSyclQueueRef) -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(device, DPCTLSyclDeviceRef) -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(context, DPCTLSyclContextRef) -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(void, DPCTLSyclUSMRef) - -} /* end of anonymous namespace */ - __dpctl_give DPCTLSyclUSMRef DPCTLmalloc_shared(size_t size, __dpctl_keep const DPCTLSyclQueueRef QRef) { diff --git a/libsyclinterface/source/dpctl_vector_templ.cpp b/libsyclinterface/source/dpctl_vector_templ.cpp index 5a3220f364..20e6f224ec 100644 --- a/libsyclinterface/source/dpctl_vector_templ.cpp +++ b/libsyclinterface/source/dpctl_vector_templ.cpp @@ -25,15 +25,11 @@ //===----------------------------------------------------------------------===// #include "Support/MemOwnershipAttrs.h" #include "dpctl_error_handlers.h" +#include "dpctl_sycl_type_casters.hpp" #include "dpctl_vector_macros.h" #include #include -namespace -{ -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(std::vector, VECTOR(EL)) -} - /*! * @brief Creates a new std::vector of the opaque SYCL pointer types. * @@ -41,10 +37,11 @@ DEFINE_SIMPLE_CONVERSION_FUNCTIONS(std::vector, VECTOR(EL)) */ __dpctl_give VECTOR(EL) FN(EL, Create)() { - std::vector *Vec = nullptr; + using vecTy = std::vector; + vecTy *Vec = nullptr; try { Vec = new std::vector(); - return wrap(Vec); + return wrap(Vec); } catch (std::exception const &e) { delete Vec; error_handler(e, __FILE__, __func__, __LINE__); @@ -61,15 +58,16 @@ __dpctl_give VECTOR(EL) FN(EL, Create)() __dpctl_give VECTOR(EL) FN(EL, CreateFromArray)(size_t n, __dpctl_keep SYCLREF(EL) * elems) { - std::vector *Vec = nullptr; + using vecTy = std::vector; + vecTy *Vec = nullptr; try { - Vec = new std::vector(); + Vec = new vecTy(); for (size_t i = 0; i < n; ++i) { auto Ref = unwrap(elems[i]); Vec->emplace_back( wrap(new std::remove_pointer::type(*Ref))); } - return wrap(Vec); + return wrap(Vec); } catch (std::exception const &e) { delete Vec; error_handler(e, __FILE__, __func__, __LINE__); diff --git a/libsyclinterface/tests/test_sycl_context_interface.cpp b/libsyclinterface/tests/test_sycl_context_interface.cpp index 29ae87ae04..edb7b9b6e2 100644 --- a/libsyclinterface/tests/test_sycl_context_interface.cpp +++ b/libsyclinterface/tests/test_sycl_context_interface.cpp @@ -25,7 +25,6 @@ /// //===----------------------------------------------------------------------===// -#include "Support/CBindingWrapping.h" #include "dpctl_sycl_context_interface.h" #include "dpctl_sycl_device_interface.h" #include "dpctl_sycl_device_selector_interface.h" diff --git a/libsyclinterface/tests/test_sycl_device_aspects.cpp b/libsyclinterface/tests/test_sycl_device_aspects.cpp index 5153278c7b..387e6aa6ec 100644 --- a/libsyclinterface/tests/test_sycl_device_aspects.cpp +++ b/libsyclinterface/tests/test_sycl_device_aspects.cpp @@ -24,10 +24,10 @@ /// //===----------------------------------------------------------------------===// -#include "Support/CBindingWrapping.h" #include "dpctl_sycl_device_interface.h" #include "dpctl_sycl_device_selector_interface.h" #include "dpctl_sycl_enum_types.h" +#include "dpctl_sycl_type_casters.hpp" #include "dpctl_utils_helper.h" #include #include @@ -35,7 +35,6 @@ namespace { -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(sycl::device, DPCTLSyclDeviceRef); template struct are_same : std::true_type { diff --git a/libsyclinterface/tests/test_sycl_device_selector_interface.cpp b/libsyclinterface/tests/test_sycl_device_selector_interface.cpp index e165066918..487014e3d1 100644 --- a/libsyclinterface/tests/test_sycl_device_selector_interface.cpp +++ b/libsyclinterface/tests/test_sycl_device_selector_interface.cpp @@ -24,21 +24,15 @@ /// //===----------------------------------------------------------------------===// -#include "Support/CBindingWrapping.h" #include "dpctl_sycl_device_interface.h" #include "dpctl_sycl_device_manager.h" #include "dpctl_sycl_device_selector_interface.h" +#include "dpctl_sycl_type_casters.hpp" #include #include using namespace sycl; -namespace -{ -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(device, DPCTLSyclDeviceRef) -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(device_selector, DPCTLSyclDeviceSelectorRef) -} // namespace - struct TestDeviceSelectorInterface : public ::testing::Test { }; diff --git a/libsyclinterface/tests/test_sycl_device_subdevices.cpp b/libsyclinterface/tests/test_sycl_device_subdevices.cpp index 86962847ae..752ad32837 100644 --- a/libsyclinterface/tests/test_sycl_device_subdevices.cpp +++ b/libsyclinterface/tests/test_sycl_device_subdevices.cpp @@ -25,11 +25,11 @@ /// //===----------------------------------------------------------------------===// -#include "Support/CBindingWrapping.h" #include "dpctl_sycl_device_interface.h" #include "dpctl_sycl_device_selector_interface.h" #include "dpctl_sycl_enum_types.h" #include "dpctl_sycl_platform_interface.h" +#include "dpctl_sycl_type_casters.hpp" #include "dpctl_utils.h" #include "dpctl_utils_helper.h" #include @@ -37,8 +37,6 @@ using namespace sycl; -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(device, DPCTLSyclDeviceRef); - const DPCTLPartitionAffinityDomainType a_dpctl_domain = DPCTLPartitionAffinityDomainType::not_applicable; diff --git a/libsyclinterface/tests/test_sycl_event_interface.cpp b/libsyclinterface/tests/test_sycl_event_interface.cpp index 396ea1a45a..940ad8f44c 100644 --- a/libsyclinterface/tests/test_sycl_event_interface.cpp +++ b/libsyclinterface/tests/test_sycl_event_interface.cpp @@ -24,7 +24,6 @@ /// //===----------------------------------------------------------------------===// -#include "Support/CBindingWrapping.h" #include "dpctl_sycl_event_interface.h" #include "dpctl_sycl_types.h" #include diff --git a/libsyclinterface/tests/test_sycl_platform_interface.cpp b/libsyclinterface/tests/test_sycl_platform_interface.cpp index 38cc3edf2d..9fac7ad7c3 100644 --- a/libsyclinterface/tests/test_sycl_platform_interface.cpp +++ b/libsyclinterface/tests/test_sycl_platform_interface.cpp @@ -24,7 +24,6 @@ /// //===----------------------------------------------------------------------===// -#include "Support/CBindingWrapping.h" #include "dpctl_sycl_context_interface.h" #include "dpctl_sycl_device_selector_interface.h" #include "dpctl_sycl_platform_interface.h" diff --git a/libsyclinterface/tests/test_sycl_queue_interface.cpp b/libsyclinterface/tests/test_sycl_queue_interface.cpp index ccccf25559..f3200f3da9 100644 --- a/libsyclinterface/tests/test_sycl_queue_interface.cpp +++ b/libsyclinterface/tests/test_sycl_queue_interface.cpp @@ -24,7 +24,6 @@ /// //===----------------------------------------------------------------------===// -#include "Support/CBindingWrapping.h" #include "dpctl_sycl_context_interface.h" #include "dpctl_sycl_device_interface.h" #include "dpctl_sycl_device_manager.h" @@ -32,6 +31,7 @@ #include "dpctl_sycl_event_interface.h" #include "dpctl_sycl_queue_interface.h" #include "dpctl_sycl_queue_manager.h" +#include "dpctl_sycl_type_casters.hpp" #include "dpctl_sycl_usm_interface.h" #include #include @@ -40,7 +40,6 @@ using namespace sycl; namespace { -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(queue, DPCTLSyclQueueRef); void error_handler_fn(int /*err*/) { diff --git a/libsyclinterface/tests/test_sycl_queue_manager.cpp b/libsyclinterface/tests/test_sycl_queue_manager.cpp index 455de3d5bd..4f9e84ea20 100644 --- a/libsyclinterface/tests/test_sycl_queue_manager.cpp +++ b/libsyclinterface/tests/test_sycl_queue_manager.cpp @@ -23,13 +23,13 @@ /// dpctl_sycl_queue_interface.h and dpctl_sycl_queue_manager.h. /// //===----------------------------------------------------------------------===// -#include "Support/CBindingWrapping.h" #include "dpctl_sycl_context_interface.h" #include "dpctl_sycl_device_interface.h" #include "dpctl_sycl_device_manager.h" #include "dpctl_sycl_device_selector_interface.h" #include "dpctl_sycl_queue_interface.h" #include "dpctl_sycl_queue_manager.h" +#include "dpctl_sycl_type_casters.hpp" #include #include #include @@ -40,8 +40,6 @@ using namespace sycl; namespace { -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(queue, DPCTLSyclQueueRef); - void foo(size_t &num) { auto DS1 = DPCTLFilterSelector_Create("opencl:gpu"); diff --git a/libsyclinterface/tests/test_sycl_queue_submit.cpp b/libsyclinterface/tests/test_sycl_queue_submit.cpp index 3716e425c3..38492e2709 100644 --- a/libsyclinterface/tests/test_sycl_queue_submit.cpp +++ b/libsyclinterface/tests/test_sycl_queue_submit.cpp @@ -23,7 +23,6 @@ /// inside dpctl_sycl_queue_interface.cpp. //===----------------------------------------------------------------------===// -#include "Support/CBindingWrapping.h" #include "dpctl_sycl_context_interface.h" #include "dpctl_sycl_device_interface.h" #include "dpctl_sycl_device_selector_interface.h" @@ -31,6 +30,7 @@ #include "dpctl_sycl_kernel_bundle_interface.h" #include "dpctl_sycl_kernel_interface.h" #include "dpctl_sycl_queue_interface.h" +#include "dpctl_sycl_type_casters.hpp" #include "dpctl_sycl_usm_interface.h" #include #include @@ -41,7 +41,6 @@ namespace { constexpr size_t SIZE = 1024; static_assert(SIZE % 8 == 0); -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(void, DPCTLSyclUSMRef); } /* end of anonymous namespace */ struct TestQueueSubmit : public ::testing::Test diff --git a/libsyclinterface/tests/test_sycl_usm_interface.cpp b/libsyclinterface/tests/test_sycl_usm_interface.cpp index 05f7350b93..15b11f79e7 100644 --- a/libsyclinterface/tests/test_sycl_usm_interface.cpp +++ b/libsyclinterface/tests/test_sycl_usm_interface.cpp @@ -24,13 +24,13 @@ /// //===----------------------------------------------------------------------===// -#include "Support/CBindingWrapping.h" #include "dpctl_sycl_context_interface.h" #include "dpctl_sycl_device_interface.h" #include "dpctl_sycl_device_selector_interface.h" #include "dpctl_sycl_event_interface.h" #include "dpctl_sycl_queue_interface.h" #include "dpctl_sycl_queue_manager.h" +#include "dpctl_sycl_type_casters.hpp" #include "dpctl_sycl_usm_interface.h" #include #include @@ -42,8 +42,6 @@ namespace { constexpr size_t SIZE = 1024; -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(void, DPCTLSyclUSMRef); - void common_test_body(size_t nbytes, const DPCTLSyclUSMRef Ptr, const DPCTLSyclQueueRef Q, From 23799c93e250833cd8db1165ede850933f984c3b Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Thu, 3 Nov 2022 11:20:55 -0500 Subject: [PATCH 02/10] Fixed dpctl_device_selector for open-source DPC++, make wrap/unwrap templated Moved dpctl_*_selector definitions into dpctl::syclinterface namespace. wrap/unwrap functions are made templated, with template parameter being C++ type to pointer of which the opaque pointer is cast. dpctl_device_selector for SYCL 2020 implements virtual call operator to enable type inference of this type as std::function. The derived classes override the call operator as appropriate. Calls to constructors of sycl::device and sycl::platform which take device selector callable are implemented differently depending on the compiler version. --- .../dpctl_sycl_device_selector_interface.h | 16 +-- .../include/dpctl_sycl_platform_interface.h | 5 +- .../include/dpctl_sycl_type_casters.hpp | 52 ++++--- .../source/dpctl_sycl_context_interface.cpp | 44 +++--- .../source/dpctl_sycl_device_interface.cpp | 133 ++++++++++-------- .../source/dpctl_sycl_device_manager.cpp | 34 +++-- .../dpctl_sycl_device_selector_interface.cpp | 23 +-- .../source/dpctl_sycl_event_interface.cpp | 41 +++--- .../dpctl_sycl_kernel_bundle_interface.cpp | 28 ++-- .../source/dpctl_sycl_kernel_interface.cpp | 23 +-- .../source/dpctl_sycl_platform_interface.cpp | 52 ++++--- .../source/dpctl_sycl_platform_manager.cpp | 9 +- .../source/dpctl_sycl_queue_interface.cpp | 104 +++++++------- .../source/dpctl_sycl_queue_manager.cpp | 21 +-- .../source/dpctl_sycl_usm_interface.cpp | 47 ++++--- .../source/dpctl_vector_templ.cpp | 34 +++-- .../tests/test_sycl_device_manager.cpp | 4 +- 17 files changed, 384 insertions(+), 286 deletions(-) diff --git a/libsyclinterface/include/dpctl_sycl_device_selector_interface.h b/libsyclinterface/include/dpctl_sycl_device_selector_interface.h index 77688c3ba8..04813b1cc6 100644 --- a/libsyclinterface/include/dpctl_sycl_device_selector_interface.h +++ b/libsyclinterface/include/dpctl_sycl_device_selector_interface.h @@ -65,12 +65,12 @@ DPCTL_API __dpctl_give DPCTLSyclDeviceSelectorRef DPCTLCPUSelector_Create(void); /*! - * @brief Returns an opaque wrapper for sycl::ONEAPI::filter_selector object - * based on the passed in filter string. + * @brief Returns an opaque wrapper for sycl::ext::oneapi::filter_selector + * object based on the passed in filter string. * * @param filter_str A C string providing a filter based on which to - * create a device_selector. - * @return An opaque pointer to a sycl::ONEAPI::filter_selector object. + * create a device selector. + * @return An opaque pointer to a sycl::ext::oneapi::filter_selector object. * @ingroup DeviceSelectors */ DPCTL_API @@ -78,18 +78,18 @@ __dpctl_give DPCTLSyclDeviceSelectorRef DPCTLFilterSelector_Create(__dpctl_keep const char *filter_str); /*! - * @brief Returns an opaque wrapper for sycl::gpu_selector object. + * @brief Returns an opaque wrapper for dpctl_gpu_selector object. * - * @return An opaque pointer to a sycl::gpu_selector object. + * @return An opaque pointer to a dpctl_gpu_selector object. * @ingroup DeviceSelectors */ DPCTL_API __dpctl_give DPCTLSyclDeviceSelectorRef DPCTLGPUSelector_Create(void); /*! - * @brief Returns an opaque wrapper for sycl::host_selector object. + * @brief Returns an opaque wrapper for dpctl_host_selector object. * - * @return An opaque pointer to a sycl::host_selector object. + * @return An opaque pointer to a dpctl_host_selector object. * @ingroup DeviceSelectors */ DPCTL_API diff --git a/libsyclinterface/include/dpctl_sycl_platform_interface.h b/libsyclinterface/include/dpctl_sycl_platform_interface.h index 01318df1e7..3e40453e4a 100644 --- a/libsyclinterface/include/dpctl_sycl_platform_interface.h +++ b/libsyclinterface/include/dpctl_sycl_platform_interface.h @@ -63,9 +63,10 @@ __dpctl_give DPCTLSyclPlatformRef DPCTLPlatform_Create(void); /*! * @brief Creates a new DPCTLSyclPlatformRef for a SYCL platform constructed - * using the device_selector wrapped by DPCTLSyclDeviceSelectorRef. + * using the dpctl_device_selector wrapped by DPCTLSyclDeviceSelectorRef. * - * @param DSRef An opaque pointer to a SYCL device_selector object. + * @param DSRef An opaque pointer to a SYCL dpctl_device_selector + * object. * @return A new DPCTLSyclPlatformRef pointer wrapping a SYCL platform object. * @ingroup PlatformInterface */ diff --git a/libsyclinterface/include/dpctl_sycl_type_casters.hpp b/libsyclinterface/include/dpctl_sycl_type_casters.hpp index c0a5cbf025..cacb904e0f 100644 --- a/libsyclinterface/include/dpctl_sycl_type_casters.hpp +++ b/libsyclinterface/include/dpctl_sycl_type_casters.hpp @@ -30,23 +30,32 @@ #include "dpctl_sycl_types.h" #include +#include #include +namespace dpctl::syclinterface +{ + #if __SYCL_COMPILER_VERSION >= 20221020 class dpctl_device_selector { public: virtual ~dpctl_device_selector() = default; - - virtual int operator()(const sycl::device &device) const = 0; + static constexpr int REJECT_DEVICE = -1; + virtual int operator()(const sycl::device &d) const + { + std::cout << "Outright rejecting " + << d.get_info() << std::endl; + return REJECT_DEVICE; + }; }; class dpctl_accelerator_selector : public dpctl_device_selector { public: dpctl_accelerator_selector() = default; - int operator()(const sycl::device &d) const + int operator()(const sycl::device &d) const override { return sycl::accelerator_selector_v(d); } @@ -56,9 +65,11 @@ class dpctl_default_selector : public dpctl_device_selector { public: dpctl_default_selector() = default; - int operator()(const sycl::device &d) const + int operator()(const sycl::device &d) const override { - return sycl::default_selector_v(d); + auto score = sycl::default_selector_v(d); + std::cout << "Got score = " << score << std::endl; + return score; } }; @@ -66,7 +77,7 @@ class dpctl_gpu_selector : public dpctl_device_selector { public: dpctl_gpu_selector() = default; - int operator()(const sycl::device &d) const + int operator()(const sycl::device &d) const override { return sycl::gpu_selector_v(d); } @@ -76,7 +87,7 @@ class dpctl_cpu_selector : public dpctl_device_selector { public: dpctl_cpu_selector() = default; - int operator()(const sycl::device &d) const + int operator()(const sycl::device &d) const override { return sycl::cpu_selector_v(d); } @@ -87,7 +98,7 @@ class dpctl_filter_selector : public dpctl_device_selector public: dpctl_filter_selector(const std::string &fs) : _impl(fs) {} - int operator()(const sycl::device &d) const + int operator()(const sycl::device &d) const override { return _impl(d); } @@ -100,13 +111,10 @@ class dpctl_host_selector : public dpctl_device_selector { public: dpctl_host_selector() = default; - int operator()(const sycl::device &) const + int operator()(const sycl::device &) const override { - return REJECTED_SCORE; + return REJECT_DEVICE; } - -private: - constexpr static int REJECTED_SCORE = -1; }; #else @@ -201,22 +209,20 @@ class dpctl_host_selector : public dpctl_device_selector #endif /*! - @brief Creates two convenience functions to reinterpret_cast an opaque - pointer to a pointer to a Sycl type and vice-versa. + @brief Creates two convenience templated functions to + reinterpret_cast an opaque pointer to a pointer to a Sycl type + and vice-versa. */ #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \ - __attribute__((unused)) inline ty *unwrap(ref P) \ + template ::value, bool> = true> \ + __attribute__((unused)) T *unwrap(ref P) \ { \ return reinterpret_cast(P); \ - } \ - \ - __attribute__((unused)) inline ref wrap(const ty *P) \ - { \ - return reinterpret_cast(const_cast(P)); \ } \ template ::value, bool> = true> \ - ref wrap(const ty *P) \ + __attribute__((unused)) ref wrap(const ty *P) \ { \ return reinterpret_cast(const_cast(P)); \ } @@ -247,3 +253,5 @@ DEFINE_SIMPLE_CONVERSION_FUNCTIONS(std::vector, DPCTLEventVectorRef) #endif + +} // namespace dpctl::syclinterface diff --git a/libsyclinterface/source/dpctl_sycl_context_interface.cpp b/libsyclinterface/source/dpctl_sycl_context_interface.cpp index 136848a68a..28f8c9d95a 100644 --- a/libsyclinterface/source/dpctl_sycl_context_interface.cpp +++ b/libsyclinterface/source/dpctl_sycl_context_interface.cpp @@ -32,13 +32,18 @@ using namespace sycl; +namespace +{ +using namespace dpctl::syclinterface; +} // end of anonymous namespace + __dpctl_give DPCTLSyclContextRef DPCTLContext_Create(__dpctl_keep const DPCTLSyclDeviceRef DRef, error_handler_callback *handler, int /**/) { DPCTLSyclContextRef CRef = nullptr; - auto Device = unwrap(DRef); + auto Device = unwrap(DRef); if (!Device) { error_handler("Cannot create device from DPCTLSyclDeviceRef" "as input is a nullptr.", @@ -46,7 +51,8 @@ DPCTLContext_Create(__dpctl_keep const DPCTLSyclDeviceRef DRef, return nullptr; } try { - CRef = wrap(new context(*Device, DPCTL_AsyncErrorHandler(handler))); + CRef = wrap( + new context(*Device, DPCTL_AsyncErrorHandler(handler))); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); } @@ -61,7 +67,7 @@ DPCTLContext_CreateFromDevices(__dpctl_keep const DPCTLDeviceVectorRef DVRef, { DPCTLSyclContextRef CRef = nullptr; std::vector Devices; - auto DeviceRefs = unwrap(DVRef); + auto DeviceRefs = unwrap>(DVRef); if (!DeviceRefs) { error_handler("Cannot create device reference from DPCTLDeviceVectorRef" "as input is a nullptr.", @@ -71,11 +77,12 @@ DPCTLContext_CreateFromDevices(__dpctl_keep const DPCTLDeviceVectorRef DVRef, Devices.reserve(DeviceRefs->size()); for (auto const &DRef : *DeviceRefs) { - Devices.emplace_back(*unwrap(DRef)); + Devices.emplace_back(*unwrap(DRef)); } try { - CRef = wrap(new context(Devices, DPCTL_AsyncErrorHandler(handler))); + CRef = wrap( + new context(Devices, DPCTL_AsyncErrorHandler(handler))); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); } @@ -91,13 +98,13 @@ bool DPCTLContext_AreEq(__dpctl_keep const DPCTLSyclContextRef CtxRef1, __LINE__); return false; } - return (*unwrap(CtxRef1) == *unwrap(CtxRef2)); + return (*unwrap(CtxRef1) == *unwrap(CtxRef2)); } __dpctl_give DPCTLSyclContextRef DPCTLContext_Copy(__dpctl_keep const DPCTLSyclContextRef CRef) { - auto Context = unwrap(CRef); + auto Context = unwrap(CRef); if (!Context) { error_handler("Cannot copy DPCTLSyclContextRef as input is a nullptr.", __FILE__, __func__, __LINE__); @@ -105,7 +112,7 @@ DPCTLContext_Copy(__dpctl_keep const DPCTLSyclContextRef CRef) } try { auto CopiedContext = new context(*Context); - return wrap(CopiedContext); + return wrap(CopiedContext); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); return nullptr; @@ -115,16 +122,17 @@ DPCTLContext_Copy(__dpctl_keep const DPCTLSyclContextRef CRef) __dpctl_give DPCTLDeviceVectorRef DPCTLContext_GetDevices(__dpctl_keep const DPCTLSyclContextRef CRef) { - auto Context = unwrap(CRef); + auto Context = unwrap(CRef); if (!Context) { error_handler("Cannot retrieve devices from DPCTLSyclContextRef as " "input is a nullptr.", __FILE__, __func__, __LINE__); return nullptr; } - std::vector *DevicesVectorPtr = nullptr; + using vecTy = std::vector; + vecTy *DevicesVectorPtr = nullptr; try { - DevicesVectorPtr = new std::vector(); + DevicesVectorPtr = new vecTy(); } catch (std::exception const &e) { delete DevicesVectorPtr; error_handler(e, __FILE__, __func__, __LINE__); @@ -134,9 +142,9 @@ DPCTLContext_GetDevices(__dpctl_keep const DPCTLSyclContextRef CRef) auto Devices = Context->get_devices(); DevicesVectorPtr->reserve(Devices.size()); for (const auto &Dev : Devices) { - DevicesVectorPtr->emplace_back(wrap(new device(Dev))); + DevicesVectorPtr->emplace_back(wrap(new device(Dev))); } - return wrap(DevicesVectorPtr); + return wrap(DevicesVectorPtr); } catch (std::exception const &e) { delete DevicesVectorPtr; error_handler(e, __FILE__, __func__, __LINE__); @@ -146,7 +154,7 @@ DPCTLContext_GetDevices(__dpctl_keep const DPCTLSyclContextRef CRef) size_t DPCTLContext_DeviceCount(__dpctl_keep const DPCTLSyclContextRef CRef) { - auto Context = unwrap(CRef); + auto Context = unwrap(CRef); if (!Context) { error_handler("Cannot retrieve devices from DPCTLSyclContextRef as " "input is a nullptr.", @@ -159,7 +167,7 @@ size_t DPCTLContext_DeviceCount(__dpctl_keep const DPCTLSyclContextRef CRef) bool DPCTLContext_IsHost(__dpctl_keep const DPCTLSyclContextRef CtxRef) { - auto Ctx = unwrap(CtxRef); + auto Ctx = unwrap(CtxRef); if (Ctx) { return Ctx->is_host(); } @@ -168,7 +176,7 @@ bool DPCTLContext_IsHost(__dpctl_keep const DPCTLSyclContextRef CtxRef) void DPCTLContext_Delete(__dpctl_take DPCTLSyclContextRef CtxRef) { - delete unwrap(CtxRef); + delete unwrap(CtxRef); } DPCTLSyclBackendType @@ -178,7 +186,7 @@ DPCTLContext_GetBackend(__dpctl_keep const DPCTLSyclContextRef CtxRef) return DPCTL_UNKNOWN_BACKEND; } - auto BE = unwrap(CtxRef)->get_platform().get_backend(); + auto BE = unwrap(CtxRef)->get_platform().get_backend(); switch (BE) { case backend::host: @@ -197,7 +205,7 @@ DPCTLContext_GetBackend(__dpctl_keep const DPCTLSyclContextRef CtxRef) size_t DPCTLContext_Hash(__dpctl_keep const DPCTLSyclContextRef CtxRef) { if (CtxRef) { - auto C = unwrap(CtxRef); + auto C = unwrap(CtxRef); std::hash hash_fn; return hash_fn(*C); } diff --git a/libsyclinterface/source/dpctl_sycl_device_interface.cpp b/libsyclinterface/source/dpctl_sycl_device_interface.cpp index d8f8cfaeae..03b20ba680 100644 --- a/libsyclinterface/source/dpctl_sycl_device_interface.cpp +++ b/libsyclinterface/source/dpctl_sycl_device_interface.cpp @@ -40,12 +40,24 @@ using namespace sycl; namespace { +using namespace dpctl::syclinterface; + +device *new_device_from_selector(const dpctl_device_selector *sel) +{ +#if __SYCL_COMPILER_VERSION >= 20221020L + return new device( + [=](const device &d) -> int { return sel->operator()(d); }); +#else + return new device(*sel); +#endif +} + template __dpctl_keep size_t * DPCTLDevice__GetMaxWorkItemSizes(__dpctl_keep const DPCTLSyclDeviceRef DRef) { size_t *sizes = nullptr; - auto D = unwrap(DRef); + auto D = unwrap(DRef); if (D) { try { #if __SYCL_COMPILER_VERSION >= 20220805 @@ -70,7 +82,7 @@ DPCTLDevice__GetMaxWorkItemSizes(__dpctl_keep const DPCTLSyclDeviceRef DRef) __dpctl_give DPCTLSyclDeviceRef DPCTLDevice_Copy(__dpctl_keep const DPCTLSyclDeviceRef DRef) { - auto Device = unwrap(DRef); + auto Device = unwrap(DRef); if (!Device) { error_handler("Cannot copy DPCTLSyclDeviceRef as input is a nullptr", __FILE__, __func__, __LINE__); @@ -78,7 +90,7 @@ DPCTLDevice_Copy(__dpctl_keep const DPCTLSyclDeviceRef DRef) } try { auto CopiedDevice = new device(*Device); - return wrap(CopiedDevice); + return wrap(CopiedDevice); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); return nullptr; @@ -89,7 +101,7 @@ __dpctl_give DPCTLSyclDeviceRef DPCTLDevice_Create() { try { auto Device = new device(); - return wrap(Device); + return wrap(Device); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); return nullptr; @@ -99,7 +111,7 @@ __dpctl_give DPCTLSyclDeviceRef DPCTLDevice_Create() __dpctl_give DPCTLSyclDeviceRef DPCTLDevice_CreateFromSelector( __dpctl_keep const DPCTLSyclDeviceSelectorRef DSRef) { - auto Selector = unwrap(DSRef); + auto Selector = unwrap(DSRef); if (!Selector) { error_handler("Cannot difine device selector for DPCTLSyclDeviceRef " "as input is a nullptr.", @@ -107,8 +119,8 @@ __dpctl_give DPCTLSyclDeviceRef DPCTLDevice_CreateFromSelector( return nullptr; } try { - auto Device = new device(*Selector); - return wrap(Device); + auto Device = new_device_from_selector(Selector); + return wrap(Device); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); return nullptr; @@ -117,14 +129,14 @@ __dpctl_give DPCTLSyclDeviceRef DPCTLDevice_CreateFromSelector( void DPCTLDevice_Delete(__dpctl_take DPCTLSyclDeviceRef DRef) { - delete unwrap(DRef); + delete unwrap(DRef); } DPCTLSyclDeviceType DPCTLDevice_GetDeviceType(__dpctl_keep const DPCTLSyclDeviceRef DRef) { DPCTLSyclDeviceType DTy = DPCTLSyclDeviceType::DPCTL_UNKNOWN_DEVICE; - auto D = unwrap(DRef); + auto D = unwrap(DRef); if (D) { try { auto SyclDTy = D->get_info(); @@ -138,7 +150,7 @@ DPCTLDevice_GetDeviceType(__dpctl_keep const DPCTLSyclDeviceRef DRef) bool DPCTLDevice_IsAccelerator(__dpctl_keep const DPCTLSyclDeviceRef DRef) { - auto D = unwrap(DRef); + auto D = unwrap(DRef); if (D) { return D->is_accelerator(); } @@ -147,7 +159,7 @@ bool DPCTLDevice_IsAccelerator(__dpctl_keep const DPCTLSyclDeviceRef DRef) bool DPCTLDevice_IsCPU(__dpctl_keep const DPCTLSyclDeviceRef DRef) { - auto D = unwrap(DRef); + auto D = unwrap(DRef); if (D) { return D->is_cpu(); } @@ -156,7 +168,7 @@ bool DPCTLDevice_IsCPU(__dpctl_keep const DPCTLSyclDeviceRef DRef) bool DPCTLDevice_IsGPU(__dpctl_keep const DPCTLSyclDeviceRef DRef) { - auto D = unwrap(DRef); + auto D = unwrap(DRef); if (D) { return D->is_gpu(); } @@ -165,7 +177,7 @@ bool DPCTLDevice_IsGPU(__dpctl_keep const DPCTLSyclDeviceRef DRef) bool DPCTLDevice_IsHost(__dpctl_keep const DPCTLSyclDeviceRef DRef) { - auto D = unwrap(DRef); + auto D = unwrap(DRef); if (D) { return D->is_host(); } @@ -176,7 +188,7 @@ DPCTLSyclBackendType DPCTLDevice_GetBackend(__dpctl_keep const DPCTLSyclDeviceRef DRef) { DPCTLSyclBackendType BTy = DPCTLSyclBackendType::DPCTL_UNKNOWN_BACKEND; - auto D = unwrap(DRef); + auto D = unwrap(DRef); if (D) { BTy = DPCTL_SyclBackendToDPCTLBackendType( D->get_platform().get_backend()); @@ -188,7 +200,7 @@ uint32_t DPCTLDevice_GetMaxComputeUnits(__dpctl_keep const DPCTLSyclDeviceRef DRef) { uint32_t nComputeUnits = 0; - auto D = unwrap(DRef); + auto D = unwrap(DRef); if (D) { try { nComputeUnits = D->get_info(); @@ -203,7 +215,7 @@ uint64_t DPCTLDevice_GetGlobalMemSize(__dpctl_keep const DPCTLSyclDeviceRef DRef) { uint64_t GlobalMemSize = 0; - auto D = unwrap(DRef); + auto D = unwrap(DRef); if (D) { try { GlobalMemSize = D->get_info(); @@ -217,7 +229,7 @@ DPCTLDevice_GetGlobalMemSize(__dpctl_keep const DPCTLSyclDeviceRef DRef) uint64_t DPCTLDevice_GetLocalMemSize(__dpctl_keep const DPCTLSyclDeviceRef DRef) { uint64_t LocalMemSize = 0; - auto D = unwrap(DRef); + auto D = unwrap(DRef); if (D) { try { LocalMemSize = D->get_info(); @@ -232,7 +244,7 @@ uint32_t DPCTLDevice_GetMaxWorkItemDims(__dpctl_keep const DPCTLSyclDeviceRef DRef) { uint32_t maxWorkItemDims = 0; - auto D = unwrap(DRef); + auto D = unwrap(DRef); if (D) { try { maxWorkItemDims = @@ -272,7 +284,7 @@ size_t DPCTLDevice_GetMaxWorkGroupSize(__dpctl_keep const DPCTLSyclDeviceRef DRef) { size_t max_wg_size = 0; - auto D = unwrap(DRef); + auto D = unwrap(DRef); if (D) { try { max_wg_size = D->get_info(); @@ -287,7 +299,7 @@ uint32_t DPCTLDevice_GetMaxNumSubGroups(__dpctl_keep const DPCTLSyclDeviceRef DRef) { size_t max_nsubgroups = 0; - auto D = unwrap(DRef); + auto D = unwrap(DRef); if (D) { try { max_nsubgroups = D->get_info(); @@ -302,10 +314,10 @@ __dpctl_give DPCTLSyclPlatformRef DPCTLDevice_GetPlatform(__dpctl_keep const DPCTLSyclDeviceRef DRef) { DPCTLSyclPlatformRef PRef = nullptr; - auto D = unwrap(DRef); + auto D = unwrap(DRef); if (D) { try { - PRef = wrap(new platform(D->get_platform())); + PRef = wrap(new platform(D->get_platform())); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); } @@ -317,7 +329,7 @@ __dpctl_give const char * DPCTLDevice_GetName(__dpctl_keep const DPCTLSyclDeviceRef DRef) { const char *cstr_name = nullptr; - auto D = unwrap(DRef); + auto D = unwrap(DRef); if (D) { try { auto name = D->get_info(); @@ -333,7 +345,7 @@ __dpctl_give const char * DPCTLDevice_GetVendor(__dpctl_keep const DPCTLSyclDeviceRef DRef) { const char *cstr_vendor = nullptr; - auto D = unwrap(DRef); + auto D = unwrap(DRef); if (D) { try { auto vendor = D->get_info(); @@ -349,7 +361,7 @@ __dpctl_give const char * DPCTLDevice_GetDriverVersion(__dpctl_keep const DPCTLSyclDeviceRef DRef) { const char *cstr_driver = nullptr; - auto D = unwrap(DRef); + auto D = unwrap(DRef); if (D) { try { auto driver = D->get_info(); @@ -364,8 +376,8 @@ DPCTLDevice_GetDriverVersion(__dpctl_keep const DPCTLSyclDeviceRef DRef) bool DPCTLDevice_AreEq(__dpctl_keep const DPCTLSyclDeviceRef DRef1, __dpctl_keep const DPCTLSyclDeviceRef DRef2) { - auto D1 = unwrap(DRef1); - auto D2 = unwrap(DRef2); + auto D1 = unwrap(DRef1); + auto D2 = unwrap(DRef2); if (D1 && D2) return *D1 == *D2; else @@ -376,7 +388,7 @@ bool DPCTLDevice_HasAspect(__dpctl_keep const DPCTLSyclDeviceRef DRef, DPCTLSyclAspectType AT) { bool hasAspect = false; - auto D = unwrap(DRef); + auto D = unwrap(DRef); if (D) { try { hasAspect = D->has(DPCTL_DPCTLAspectTypeToSyclAspect(AT)); @@ -391,7 +403,7 @@ bool DPCTLDevice_HasAspect(__dpctl_keep const DPCTLSyclDeviceRef DRef, TYPE DPCTLDevice_##FUNC(__dpctl_keep const DPCTLSyclDeviceRef DRef) \ { \ TYPE result = 0; \ - auto D = unwrap(DRef); \ + auto D = unwrap(DRef); \ if (D) { \ try { \ result = D->get_info(); \ @@ -414,7 +426,7 @@ bool DPCTLDevice_GetSubGroupIndependentForwardProgress( __dpctl_keep const DPCTLSyclDeviceRef DRef) { bool SubGroupProgress = false; - auto D = unwrap(DRef); + auto D = unwrap(DRef); if (D) { try { SubGroupProgress = D->get_info< @@ -430,7 +442,7 @@ uint32_t DPCTLDevice_GetPreferredVectorWidthChar( __dpctl_keep const DPCTLSyclDeviceRef DRef) { size_t vector_width_char = 0; - auto D = unwrap(DRef); + auto D = unwrap(DRef); if (D) { try { vector_width_char = @@ -446,7 +458,7 @@ uint32_t DPCTLDevice_GetPreferredVectorWidthShort( __dpctl_keep const DPCTLSyclDeviceRef DRef) { size_t vector_width_short = 0; - auto D = unwrap(DRef); + auto D = unwrap(DRef); if (D) { try { vector_width_short = @@ -462,7 +474,7 @@ uint32_t DPCTLDevice_GetPreferredVectorWidthInt( __dpctl_keep const DPCTLSyclDeviceRef DRef) { size_t vector_width_int = 0; - auto D = unwrap(DRef); + auto D = unwrap(DRef); if (D) { try { vector_width_int = @@ -478,7 +490,7 @@ uint32_t DPCTLDevice_GetPreferredVectorWidthLong( __dpctl_keep const DPCTLSyclDeviceRef DRef) { size_t vector_width_long = 0; - auto D = unwrap(DRef); + auto D = unwrap(DRef); if (D) { try { vector_width_long = @@ -494,7 +506,7 @@ uint32_t DPCTLDevice_GetPreferredVectorWidthFloat( __dpctl_keep const DPCTLSyclDeviceRef DRef) { size_t vector_width_float = 0; - auto D = unwrap(DRef); + auto D = unwrap(DRef); if (D) { try { vector_width_float = @@ -510,7 +522,7 @@ uint32_t DPCTLDevice_GetPreferredVectorWidthDouble( __dpctl_keep const DPCTLSyclDeviceRef DRef) { size_t vector_width_double = 0; - auto D = unwrap(DRef); + auto D = unwrap(DRef); if (D) { try { vector_width_double = @@ -526,7 +538,7 @@ uint32_t DPCTLDevice_GetPreferredVectorWidthHalf( __dpctl_keep const DPCTLSyclDeviceRef DRef) { size_t vector_width_half = 0; - auto D = unwrap(DRef); + auto D = unwrap(DRef); if (D) { try { vector_width_half = @@ -541,11 +553,11 @@ uint32_t DPCTLDevice_GetPreferredVectorWidthHalf( __dpctl_give DPCTLSyclDeviceRef DPCTLDevice_GetParentDevice(__dpctl_keep const DPCTLSyclDeviceRef DRef) { - auto D = unwrap(DRef); + auto D = unwrap(DRef); if (D) { try { auto parent_D = D->get_info(); - return wrap(new device(parent_D)); + return wrap(new device(parent_D)); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); return nullptr; @@ -559,20 +571,21 @@ __dpctl_give DPCTLDeviceVectorRef DPCTLDevice_CreateSubDevicesEqually(__dpctl_keep const DPCTLSyclDeviceRef DRef, size_t count) { - std::vector *Devices = nullptr; + using vecTy = std::vector; + vecTy *Devices = nullptr; if (DRef) { if (count == 0) { error_handler("Cannot create sub-devices with zero compute units", __FILE__, __func__, __LINE__); return nullptr; } - auto D = unwrap(DRef); + auto D = unwrap(DRef); try { auto subDevices = D->create_sub_devices< info::partition_property::partition_equally>(count); - Devices = new std::vector(); + Devices = new vecTy(); for (const auto &sd : subDevices) { - Devices->emplace_back(wrap(new device(sd))); + Devices->emplace_back(wrap(new device(sd))); } } catch (std::exception const &e) { delete Devices; @@ -580,7 +593,7 @@ DPCTLDevice_CreateSubDevicesEqually(__dpctl_keep const DPCTLSyclDeviceRef DRef, return nullptr; } } - return wrap(Devices); + return wrap(Devices); } __dpctl_give DPCTLDeviceVectorRef @@ -588,7 +601,8 @@ DPCTLDevice_CreateSubDevicesByCounts(__dpctl_keep const DPCTLSyclDeviceRef DRef, __dpctl_keep size_t *counts, size_t ncounts) { - std::vector *Devices = nullptr; + using vecTy = std::vector; + vecTy *Devices = nullptr; std::vector vcounts(ncounts); vcounts.assign(counts, counts + ncounts); size_t min_elem = *std::min_element(vcounts.begin(), vcounts.end()); @@ -598,7 +612,7 @@ DPCTLDevice_CreateSubDevicesByCounts(__dpctl_keep const DPCTLSyclDeviceRef DRef, return nullptr; } if (DRef) { - auto D = unwrap(DRef); + auto D = unwrap(DRef); std::vector::type> subDevices; try { subDevices = D->create_sub_devices< @@ -608,9 +622,9 @@ DPCTLDevice_CreateSubDevicesByCounts(__dpctl_keep const DPCTLSyclDeviceRef DRef, return nullptr; } try { - Devices = new std::vector(); + Devices = new vecTy(); for (const auto &sd : subDevices) { - Devices->emplace_back(wrap(new device(sd))); + Devices->emplace_back(wrap(new device(sd))); } } catch (std::exception const &e) { delete Devices; @@ -618,24 +632,25 @@ DPCTLDevice_CreateSubDevicesByCounts(__dpctl_keep const DPCTLSyclDeviceRef DRef, return nullptr; } } - return wrap(Devices); + return wrap(Devices); } __dpctl_give DPCTLDeviceVectorRef DPCTLDevice_CreateSubDevicesByAffinity( __dpctl_keep const DPCTLSyclDeviceRef DRef, DPCTLPartitionAffinityDomainType PartitionAffinityDomainTy) { - std::vector *Devices = nullptr; - auto D = unwrap(DRef); + using vecTy = std::vector; + vecTy *Devices = nullptr; + auto D = unwrap(DRef); if (D) { try { auto domain = DPCTL_DPCTLPartitionAffinityDomainTypeToSycl( PartitionAffinityDomainTy); auto subDevices = D->create_sub_devices< info::partition_property::partition_by_affinity_domain>(domain); - Devices = new std::vector(); + Devices = new vecTy(); for (const auto &sd : subDevices) { - Devices->emplace_back(wrap(new device(sd))); + Devices->emplace_back(wrap(new device(sd))); } } catch (std::exception const &e) { delete Devices; @@ -643,13 +658,13 @@ __dpctl_give DPCTLDeviceVectorRef DPCTLDevice_CreateSubDevicesByAffinity( return nullptr; } } - return wrap(Devices); + return wrap(Devices); } size_t DPCTLDevice_Hash(__dpctl_keep const DPCTLSyclDeviceRef DRef) { if (DRef) { - auto D = unwrap(DRef); + auto D = unwrap(DRef); std::hash hash_fn; return hash_fn(*D); } @@ -663,7 +678,7 @@ size_t DPCTLDevice_GetProfilingTimerResolution( __dpctl_keep const DPCTLSyclDeviceRef DRef) { if (DRef) { - auto D = unwrap(DRef); + auto D = unwrap(DRef); return D->get_info(); } else { @@ -676,7 +691,7 @@ uint32_t DPCTLDevice_GetGlobalMemCacheLineSize( __dpctl_keep const DPCTLSyclDeviceRef DRef) { if (DRef) { - auto D = unwrap(DRef); + auto D = unwrap(DRef); return D->get_info(); } else { @@ -689,7 +704,7 @@ uint64_t DPCTLDevice_GetGlobalMemCacheSize(__dpctl_keep const DPCTLSyclDeviceRef DRef) { if (DRef) { - auto D = unwrap(DRef); + auto D = unwrap(DRef); return D->get_info(); } else { @@ -702,7 +717,7 @@ DPCTLGlobalMemCacheType DPCTLDevice_GetGlobalMemCacheType(__dpctl_keep const DPCTLSyclDeviceRef DRef) { if (DRef) { - auto D = unwrap(DRef); + auto D = unwrap(DRef); auto mem_type = D->get_info(); switch (mem_type) { case info::global_mem_cache_type::none: diff --git a/libsyclinterface/source/dpctl_sycl_device_manager.cpp b/libsyclinterface/source/dpctl_sycl_device_manager.cpp index 544a9019fd..3ce34df2c5 100644 --- a/libsyclinterface/source/dpctl_sycl_device_manager.cpp +++ b/libsyclinterface/source/dpctl_sycl_device_manager.cpp @@ -40,6 +40,8 @@ using namespace sycl; namespace { +using namespace dpctl::syclinterface; + /* * Helper function to print the metadata for a sycl::device. */ @@ -111,7 +113,7 @@ struct DeviceCacheBuilder { static DeviceCache *cache = new DeviceCache([] { DeviceCache cache_l; - default_selector mRanker; + dpctl_default_selector mRanker; auto Platforms = platform::get_platforms(); for (const auto &P : Platforms) { auto Devices = P.get_devices(); @@ -144,16 +146,19 @@ struct DeviceCacheBuilder } // namespace #undef EL +#undef EL_SYCL_TYPE #define EL Device +#define EL_SYCL_TYPE sycl::device #include "dpctl_vector_templ.cpp" #undef EL +#undef EL_SYCL_TYPE DPCTLSyclContextRef DPCTLDeviceMgr_GetCachedContext(__dpctl_keep const DPCTLSyclDeviceRef DRef) { DPCTLSyclContextRef CRef = nullptr; - auto Device = unwrap(DRef); + auto Device = unwrap(DRef); if (!Device) { error_handler("Cannot create device from DPCTLSyclDeviceRef" "as input is a nullptr.", @@ -166,7 +171,7 @@ DPCTLDeviceMgr_GetCachedContext(__dpctl_keep const DPCTLSyclDeviceRef DRef) context *ContextPtr = nullptr; try { ContextPtr = new context(entry->second); - CRef = wrap(ContextPtr); + CRef = wrap(ContextPtr); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); delete ContextPtr; @@ -183,7 +188,8 @@ DPCTLDeviceMgr_GetCachedContext(__dpctl_keep const DPCTLSyclDeviceRef DRef) __dpctl_give DPCTLDeviceVectorRef DPCTLDeviceMgr_GetDevices(int device_identifier) { - std::vector *Devices = nullptr; + using vecTy = std::vector; + vecTy *Devices = nullptr; device_identifier = to_canonical_device_id(device_identifier); @@ -196,10 +202,10 @@ DPCTLDeviceMgr_GetDevices(int device_identifier) } if (!device_identifier) - return wrap(Devices); + return wrap(Devices); const auto &root_devices = device::get_devices(); - default_selector mRanker; + dpctl_default_selector mRanker; for (const auto &root_device : root_devices) { if (mRanker(root_device) < 0) @@ -209,18 +215,18 @@ DPCTLDeviceMgr_GetDevices(int device_identifier) auto Dty(DPCTL_SyclDeviceTypeToDPCTLDeviceType( root_device.get_info())); if ((device_identifier & Bty) && (device_identifier & Dty)) { - Devices->emplace_back(wrap(new device(root_device))); + Devices->emplace_back(wrap(new device(root_device))); } } // the wrap function is defined inside dpctl_vector_templ.cpp - return wrap(Devices); + return wrap(Devices); } __dpctl_give const char * DPCTLDeviceMgr_GetDeviceInfoStr(__dpctl_keep const DPCTLSyclDeviceRef DRef) { const char *cstr_info = nullptr; - auto D = unwrap(DRef); + auto D = unwrap(DRef); if (D) { try { auto infostr = get_device_info_str(*D); @@ -245,9 +251,9 @@ int DPCTLDeviceMgr_GetPositionInDevices(__dpctl_keep DPCTLSyclDeviceRef DRef, return not_found; const auto &root_devices = device::get_devices(); - default_selector mRanker; + dpctl_default_selector mRanker; int index = not_found; - auto reference_device = *(unwrap(DRef)); + const auto &reference_device = *(unwrap(DRef)); for (const auto &root_device : root_devices) { if (mRanker(root_device) < 0) @@ -278,7 +284,7 @@ size_t DPCTLDeviceMgr_GetNumDevices(int device_identifier) if (!device_identifier) return 0; - default_selector mRanker; + dpctl_default_selector mRanker; for (const auto &entry : cache) { if (mRanker(entry.first) < 0) continue; @@ -300,7 +306,7 @@ size_t DPCTLDeviceMgr_GetNumDevices(int device_identifier) */ void DPCTLDeviceMgr_PrintDeviceInfo(__dpctl_keep const DPCTLSyclDeviceRef DRef) { - auto Device = unwrap(DRef); + auto Device = unwrap(DRef); if (Device) std::cout << get_device_info_str(*Device); else @@ -310,7 +316,7 @@ void DPCTLDeviceMgr_PrintDeviceInfo(__dpctl_keep const DPCTLSyclDeviceRef DRef) int64_t DPCTLDeviceMgr_GetRelativeId(__dpctl_keep const DPCTLSyclDeviceRef DRef) { - auto Device = unwrap(DRef); + auto Device = unwrap(DRef); if (Device) return DPCTL_GetRelativeDeviceId(*Device); diff --git a/libsyclinterface/source/dpctl_sycl_device_selector_interface.cpp b/libsyclinterface/source/dpctl_sycl_device_selector_interface.cpp index 0480038968..e09d3b1b21 100644 --- a/libsyclinterface/source/dpctl_sycl_device_selector_interface.cpp +++ b/libsyclinterface/source/dpctl_sycl_device_selector_interface.cpp @@ -30,11 +30,16 @@ using namespace sycl; +namespace +{ +using namespace dpctl::syclinterface; +} // end of anonymous namespace + __dpctl_give DPCTLSyclDeviceSelectorRef DPCTLAcceleratorSelector_Create() { try { auto Selector = new dpctl_accelerator_selector(); - return wrap(Selector); + return wrap(Selector); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); return nullptr; @@ -45,7 +50,7 @@ __dpctl_give DPCTLSyclDeviceSelectorRef DPCTLDefaultSelector_Create() { try { auto Selector = new dpctl_default_selector(); - return wrap(Selector); + return wrap(Selector); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); return nullptr; @@ -56,7 +61,7 @@ __dpctl_give DPCTLSyclDeviceSelectorRef DPCTLCPUSelector_Create() { try { auto Selector = new dpctl_cpu_selector(); - return wrap(Selector); + return wrap(Selector); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); return nullptr; @@ -69,7 +74,7 @@ DPCTLFilterSelector_Create(__dpctl_keep const char *filter_str) using filter_selector_t = dpctl_filter_selector; try { auto Selector = new filter_selector_t(filter_str); - return wrap(Selector); + return wrap(Selector); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); return nullptr; @@ -80,7 +85,7 @@ __dpctl_give DPCTLSyclDeviceSelectorRef DPCTLGPUSelector_Create() { try { auto Selector = new dpctl_gpu_selector(); - return wrap(Selector); + return wrap(Selector); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); return nullptr; @@ -91,7 +96,7 @@ __dpctl_give DPCTLSyclDeviceSelectorRef DPCTLHostSelector_Create() { try { auto Selector = new dpctl_host_selector(); - return wrap(Selector); + return wrap(Selector); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); return nullptr; @@ -103,8 +108,8 @@ int DPCTLDeviceSelector_Score(__dpctl_keep DPCTLSyclDeviceSelectorRef DSRef, { constexpr int REJECT_DEVICE_SCORE = -1; if (DSRef && DRef) { - auto dev = *(unwrap(DRef)); - return (*unwrap(DSRef))(dev); + auto dev = *(unwrap(DRef)); + return (*unwrap(DSRef))(dev); } else return REJECT_DEVICE_SCORE; @@ -112,6 +117,6 @@ int DPCTLDeviceSelector_Score(__dpctl_keep DPCTLSyclDeviceSelectorRef DSRef, void DPCTLDeviceSelector_Delete(__dpctl_take DPCTLSyclDeviceSelectorRef DSRef) { - auto Selector = unwrap(DSRef); + auto Selector = unwrap(DSRef); delete Selector; } diff --git a/libsyclinterface/source/dpctl_sycl_event_interface.cpp b/libsyclinterface/source/dpctl_sycl_event_interface.cpp index 037f61f211..804c76ccb9 100644 --- a/libsyclinterface/source/dpctl_sycl_event_interface.cpp +++ b/libsyclinterface/source/dpctl_sycl_event_interface.cpp @@ -33,17 +33,25 @@ using namespace sycl; +namespace +{ +using namespace dpctl::syclinterface; +} // end of anonymous namespace + #undef EL +#undef EL_SYCL_TYPE #define EL Event +#define EL_SYCL_TYPE sycl::event #include "dpctl_vector_templ.cpp" #undef EL +#undef EL_SYCL_TYPE __dpctl_give DPCTLSyclEventRef DPCTLEvent_Create() { DPCTLSyclEventRef ERef = nullptr; try { auto E = new event(); - ERef = wrap(E); + ERef = wrap(E); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); } @@ -53,7 +61,7 @@ __dpctl_give DPCTLSyclEventRef DPCTLEvent_Create() void DPCTLEvent_Wait(__dpctl_keep DPCTLSyclEventRef ERef) { if (ERef) { - auto SyclEvent = unwrap(ERef); + auto SyclEvent = unwrap(ERef); try { if (SyclEvent) SyclEvent->wait(); @@ -71,7 +79,7 @@ void DPCTLEvent_Wait(__dpctl_keep DPCTLSyclEventRef ERef) void DPCTLEvent_WaitAndThrow(__dpctl_keep DPCTLSyclEventRef ERef) { if (ERef) { - auto SyclEvent = unwrap(ERef); + auto SyclEvent = unwrap(ERef); try { if (SyclEvent) SyclEvent->wait_and_throw(); @@ -88,13 +96,13 @@ void DPCTLEvent_WaitAndThrow(__dpctl_keep DPCTLSyclEventRef ERef) void DPCTLEvent_Delete(__dpctl_take DPCTLSyclEventRef ERef) { - delete unwrap(ERef); + delete unwrap(ERef); } __dpctl_give DPCTLSyclEventRef DPCTLEvent_Copy(__dpctl_keep DPCTLSyclEventRef ERef) { - auto SyclEvent = unwrap(ERef); + auto SyclEvent = unwrap(ERef); if (!SyclEvent) { error_handler("Cannot copy DPCTLSyclEventRef as input is a nullptr.", __FILE__, __func__, __LINE__); @@ -102,7 +110,7 @@ DPCTLEvent_Copy(__dpctl_keep DPCTLSyclEventRef ERef) } try { auto CopiedSyclEvent = new event(*SyclEvent); - return wrap(CopiedSyclEvent); + return wrap(CopiedSyclEvent); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); return nullptr; @@ -112,7 +120,7 @@ DPCTLEvent_Copy(__dpctl_keep DPCTLSyclEventRef ERef) DPCTLSyclBackendType DPCTLEvent_GetBackend(__dpctl_keep DPCTLSyclEventRef ERef) { DPCTLSyclBackendType BTy = DPCTLSyclBackendType::DPCTL_UNKNOWN_BACKEND; - auto E = unwrap(ERef); + auto E = unwrap(ERef); if (E) { BTy = DPCTL_SyclBackendToDPCTLBackendType(E->get_backend()); } @@ -128,7 +136,7 @@ DPCTLEvent_GetCommandExecutionStatus(__dpctl_keep DPCTLSyclEventRef ERef) { DPCTLSyclEventStatusType ESTy = DPCTLSyclEventStatusType::DPCTL_UNKNOWN_STATUS; - auto E = unwrap(ERef); + auto E = unwrap(ERef); if (E) { try { auto SyclESTy = @@ -144,7 +152,7 @@ DPCTLEvent_GetCommandExecutionStatus(__dpctl_keep DPCTLSyclEventRef ERef) uint64_t DPCTLEvent_GetProfilingInfoSubmit(__dpctl_keep DPCTLSyclEventRef ERef) { uint64_t profilingInfoSubmit = 0; - auto E = unwrap(ERef); + auto E = unwrap(ERef); if (E) { try { E->wait(); @@ -160,7 +168,7 @@ uint64_t DPCTLEvent_GetProfilingInfoSubmit(__dpctl_keep DPCTLSyclEventRef ERef) uint64_t DPCTLEvent_GetProfilingInfoStart(__dpctl_keep DPCTLSyclEventRef ERef) { uint64_t profilingInfoStart = 0; - auto E = unwrap(ERef); + auto E = unwrap(ERef); if (E) { try { E->wait(); @@ -176,7 +184,7 @@ uint64_t DPCTLEvent_GetProfilingInfoStart(__dpctl_keep DPCTLSyclEventRef ERef) uint64_t DPCTLEvent_GetProfilingInfoEnd(__dpctl_keep DPCTLSyclEventRef ERef) { uint64_t profilingInfoEnd = 0; - auto E = unwrap(ERef); + auto E = unwrap(ERef); if (E) { try { E->wait(); @@ -192,15 +200,16 @@ uint64_t DPCTLEvent_GetProfilingInfoEnd(__dpctl_keep DPCTLSyclEventRef ERef) __dpctl_give DPCTLEventVectorRef DPCTLEvent_GetWaitList(__dpctl_keep DPCTLSyclEventRef ERef) { - auto E = unwrap(ERef); + auto E = unwrap(ERef); if (!E) { error_handler("Cannot get wait list as input is a nullptr.", __FILE__, __func__, __LINE__); return nullptr; } - std::vector *EventsVectorPtr = nullptr; + using vecTy = std::vector; + vecTy *EventsVectorPtr = nullptr; try { - EventsVectorPtr = new std::vector(); + EventsVectorPtr = new vecTy(); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); return nullptr; @@ -209,9 +218,9 @@ DPCTLEvent_GetWaitList(__dpctl_keep DPCTLSyclEventRef ERef) auto Events = E->get_wait_list(); EventsVectorPtr->reserve(Events.size()); for (const auto &Ev : Events) { - EventsVectorPtr->emplace_back(wrap(new event(Ev))); + EventsVectorPtr->emplace_back(wrap(new event(Ev))); } - return wrap(EventsVectorPtr); + return wrap(EventsVectorPtr); } catch (std::exception const &e) { delete EventsVectorPtr; error_handler(e, __FILE__, __func__, __LINE__); diff --git a/libsyclinterface/source/dpctl_sycl_kernel_bundle_interface.cpp b/libsyclinterface/source/dpctl_sycl_kernel_bundle_interface.cpp index a646e1a5b1..a6e0492421 100644 --- a/libsyclinterface/source/dpctl_sycl_kernel_bundle_interface.cpp +++ b/libsyclinterface/source/dpctl_sycl_kernel_bundle_interface.cpp @@ -57,6 +57,8 @@ using namespace sycl; namespace { +using namespace dpctl::syclinterface; + #ifdef __linux__ static const char *clLoaderName = DPCTL_LIBCL_LOADER_FILENAME; static const int clLibLoadFlags = RTLD_NOLOAD | RTLD_NOW | RTLD_LOCAL; @@ -197,9 +199,10 @@ _CreateKernelBundle_common_ocl_impl(cl_program clProgram, return nullptr; } - kernel_bundle kb = + using ekbTy = kernel_bundle; + ekbTy kb = make_kernel_bundle(clProgram, ctx); - return wrap(new kernel_bundle(kb)); + return wrap(new ekbTy(kb)); } DPCTLSyclKernelBundleRef @@ -314,7 +317,7 @@ _GetKernel_ocl_impl(const kernel_bundle &kb, kernel interop_kernel = make_kernel(ocl_kernel_from_kb, ctx); - return wrap(new kernel(interop_kernel)); + return wrap(new kernel(interop_kernel)); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); return nullptr; @@ -471,7 +474,8 @@ _CreateKernelBundleWithIL_ze_impl(const context &SyclCtx, auto kb = make_kernel_bundle( {ZeModule, ext::oneapi::level_zero::ownership::keep}, SyclCtx); - return wrap(new kernel_bundle(kb)); + return wrap>( + new kernel_bundle(kb)); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); auto zeModuleDestroyFn = get_zeModuleDestroy(); @@ -525,7 +529,7 @@ _GetKernel_ze_impl(const kernel_bundle &kb, } if (found) { - return wrap(new kernel(*syclInteropKern_ptr)); + return wrap(new kernel(*syclInteropKern_ptr)); } else { error_handler("Kernel named " + std::string(kernel_name) + @@ -603,8 +607,8 @@ DPCTLKernelBundle_CreateFromSpirv(__dpctl_keep const DPCTLSyclContextRef CtxRef, return KBRef; } - context *SyclCtx = unwrap(CtxRef); - device *SyclDev = unwrap(DevRef); + context *SyclCtx = unwrap(CtxRef); + device *SyclDev = unwrap(DevRef); // get the backend type auto BE = SyclCtx->get_platform().get_backend(); switch (BE) { @@ -649,8 +653,8 @@ __dpctl_give DPCTLSyclKernelBundleRef DPCTLKernelBundle_CreateFromOCLSource( return nullptr; } - SyclCtx = unwrap(Ctx); - SyclDev = unwrap(Dev); + SyclCtx = unwrap(Ctx); + SyclDev = unwrap(Dev); // get the backend type auto BE = SyclCtx->get_platform().get_backend(); @@ -688,7 +692,7 @@ DPCTLKernelBundle_GetKernel(__dpctl_keep DPCTLSyclKernelBundleRef KBRef, __LINE__); return nullptr; } - auto SyclKB = unwrap(KBRef); + auto SyclKB = unwrap>(KBRef); sycl::backend be = SyclKB->get_backend(); switch (be) { case sycl::backend::opencl: @@ -716,7 +720,7 @@ bool DPCTLKernelBundle_HasKernel(__dpctl_keep DPCTLSyclKernelBundleRef KBRef, return false; } - auto SyclKB = unwrap(KBRef); + auto SyclKB = unwrap>(KBRef); sycl::backend be = SyclKB->get_backend(); switch (be) { case sycl::backend::opencl: @@ -733,5 +737,5 @@ bool DPCTLKernelBundle_HasKernel(__dpctl_keep DPCTLSyclKernelBundleRef KBRef, void DPCTLKernelBundle_Delete(__dpctl_take DPCTLSyclKernelBundleRef KBRef) { - delete unwrap(KBRef); + delete unwrap>(KBRef); } diff --git a/libsyclinterface/source/dpctl_sycl_kernel_interface.cpp b/libsyclinterface/source/dpctl_sycl_kernel_interface.cpp index 24da329d3f..cdf009e5b4 100644 --- a/libsyclinterface/source/dpctl_sycl_kernel_interface.cpp +++ b/libsyclinterface/source/dpctl_sycl_kernel_interface.cpp @@ -33,6 +33,11 @@ using namespace sycl; +namespace +{ +using namespace dpctl::syclinterface; +} // end of anonymous namespace + size_t DPCTLKernel_GetNumArgs(__dpctl_keep const DPCTLSyclKernelRef KRef) { if (!KRef) { @@ -42,14 +47,14 @@ size_t DPCTLKernel_GetNumArgs(__dpctl_keep const DPCTLSyclKernelRef KRef) return -1; } - auto sycl_kernel = unwrap(KRef); + auto sycl_kernel = unwrap(KRef); auto num_args = sycl_kernel->get_info(); return static_cast(num_args); } void DPCTLKernel_Delete(__dpctl_take DPCTLSyclKernelRef KRef) { - delete unwrap(KRef); + delete unwrap(KRef); } size_t DPCTLKernel_GetWorkGroupSize(__dpctl_keep const DPCTLSyclKernelRef KRef) @@ -60,7 +65,7 @@ size_t DPCTLKernel_GetWorkGroupSize(__dpctl_keep const DPCTLSyclKernelRef KRef) return 0; } - auto sycl_kern = unwrap(KRef); + auto sycl_kern = unwrap(KRef); auto devs = sycl_kern->get_kernel_bundle().get_devices(); if (devs.empty()) { error_handler("Input DPCTKSyclKernelRef has no associated device.", @@ -81,7 +86,7 @@ size_t DPCTLKernel_GetPreferredWorkGroupSizeMultiple( return 0; } - auto sycl_kern = unwrap(KRef); + auto sycl_kern = unwrap(KRef); auto devs = sycl_kern->get_kernel_bundle().get_devices(); if (devs.empty()) { error_handler("Input DPCTKSyclKernelRef has no associated device.", @@ -102,7 +107,7 @@ size_t DPCTLKernel_GetPrivateMemSize(__dpctl_keep const DPCTLSyclKernelRef KRef) return 0; } - auto sycl_kern = unwrap(KRef); + auto sycl_kern = unwrap(KRef); auto devs = sycl_kern->get_kernel_bundle().get_devices(); if (devs.empty()) { error_handler("Input DPCTKSyclKernelRef has no associated device.", @@ -124,7 +129,7 @@ DPCTLKernel_GetMaxNumSubGroups(__dpctl_keep const DPCTLSyclKernelRef KRef) return 0; } - auto sycl_kern = unwrap(KRef); + auto sycl_kern = unwrap(KRef); auto devs = sycl_kern->get_kernel_bundle().get_devices(); if (devs.empty()) { error_handler("Input DPCTKSyclKernelRef has no associated device.", @@ -149,7 +154,7 @@ DPCTLKernel_GetMaxSubGroupSize(__dpctl_keep const DPCTLSyclKernelRef KRef) return 0; } - auto sycl_kern = unwrap(KRef); + auto sycl_kern = unwrap(KRef); auto devs = sycl_kern->get_kernel_bundle().get_devices(); if (devs.empty()) { error_handler("Input DPCTKSyclKernelRef has no associated device.", @@ -171,7 +176,7 @@ DPCTLKernel_GetCompileNumSubGroups(__dpctl_keep const DPCTLSyclKernelRef KRef) return 0; } - auto sycl_kern = unwrap(KRef); + auto sycl_kern = unwrap(KRef); auto devs = sycl_kern->get_kernel_bundle().get_devices(); if (devs.empty()) { error_handler("Input DPCTKSyclKernelRef has no associated device.", @@ -194,7 +199,7 @@ DPCTLKernel_GetCompileSubGroupSize(__dpctl_keep const DPCTLSyclKernelRef KRef) return 0; } - auto sycl_kern = unwrap(KRef); + auto sycl_kern = unwrap(KRef); auto devs = sycl_kern->get_kernel_bundle().get_devices(); if (devs.empty()) { error_handler("Input DPCTKSyclKernelRef has no associated device.", diff --git a/libsyclinterface/source/dpctl_sycl_platform_interface.cpp b/libsyclinterface/source/dpctl_sycl_platform_interface.cpp index d998e8b1f6..4d8a893ef0 100644 --- a/libsyclinterface/source/dpctl_sycl_platform_interface.cpp +++ b/libsyclinterface/source/dpctl_sycl_platform_interface.cpp @@ -38,10 +38,27 @@ using namespace sycl; +namespace +{ + +using namespace dpctl::syclinterface; + +platform *new_platform_from_selector(const dpctl_device_selector *sel) +{ +#if __SYCL_COMPILER_VERSION >= 20221020L + return new platform( + [=](const device &d) -> int { return sel->operator()(d); }); +#else + return new platform(*sel); +#endif +} + +} // end of anonymous namespace + __dpctl_give DPCTLSyclPlatformRef DPCTLPlatform_Copy(__dpctl_keep const DPCTLSyclPlatformRef PRef) { - auto Platform = unwrap(PRef); + auto Platform = unwrap(PRef); if (!Platform) { error_handler("Cannot copy DPCTLSyclPlatformRef as input is a nullptr.", __FILE__, __func__, __LINE__); @@ -49,7 +66,7 @@ DPCTLPlatform_Copy(__dpctl_keep const DPCTLSyclPlatformRef PRef) } try { auto CopiedPlatform = new platform(*Platform); - return wrap(CopiedPlatform); + return wrap(CopiedPlatform); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); return nullptr; @@ -61,7 +78,7 @@ __dpctl_give DPCTLSyclPlatformRef DPCTLPlatform_Create() DPCTLSyclPlatformRef PRef = nullptr; try { auto P = new platform(); - PRef = wrap(P); + PRef = wrap(P); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); } @@ -72,11 +89,11 @@ __dpctl_give DPCTLSyclPlatformRef DPCTLPlatform_CreateFromSelector( __dpctl_keep const DPCTLSyclDeviceSelectorRef DSRef) { if (DSRef) { - auto DS = unwrap(DSRef); + auto DS = unwrap(DSRef); platform *P = nullptr; try { - P = new platform(*DS); - return wrap(P); + P = new_platform_from_selector(DS); + return wrap(P); } catch (std::exception const &e) { delete P; error_handler(e, __FILE__, __func__, __LINE__); @@ -93,7 +110,7 @@ __dpctl_give DPCTLSyclPlatformRef DPCTLPlatform_CreateFromSelector( void DPCTLPlatform_Delete(__dpctl_take DPCTLSyclPlatformRef PRef) { - auto P = unwrap(PRef); + auto P = unwrap(PRef); delete P; } @@ -101,7 +118,7 @@ DPCTLSyclBackendType DPCTLPlatform_GetBackend(__dpctl_keep const DPCTLSyclPlatformRef PRef) { DPCTLSyclBackendType BTy = DPCTLSyclBackendType::DPCTL_UNKNOWN_BACKEND; - auto P = unwrap(PRef); + auto P = unwrap(PRef); if (P) { BTy = DPCTL_SyclBackendToDPCTLBackendType(P->get_backend()); } @@ -115,7 +132,7 @@ DPCTLPlatform_GetBackend(__dpctl_keep const DPCTLSyclPlatformRef PRef) __dpctl_give const char * DPCTLPlatform_GetName(__dpctl_keep const DPCTLSyclPlatformRef PRef) { - auto P = unwrap(PRef); + auto P = unwrap(PRef); if (P) { try { auto name = P->get_info(); @@ -135,7 +152,7 @@ DPCTLPlatform_GetName(__dpctl_keep const DPCTLSyclPlatformRef PRef) __dpctl_give const char * DPCTLPlatform_GetVendor(__dpctl_keep const DPCTLSyclPlatformRef PRef) { - auto P = unwrap(PRef); + auto P = unwrap(PRef); if (P) { try { auto vendor = P->get_info(); @@ -155,7 +172,7 @@ DPCTLPlatform_GetVendor(__dpctl_keep const DPCTLSyclPlatformRef PRef) __dpctl_give const char * DPCTLPlatform_GetVersion(__dpctl_keep const DPCTLSyclPlatformRef PRef) { - auto P = unwrap(PRef); + auto P = unwrap(PRef); if (P) { try { auto driver = P->get_info(); @@ -174,12 +191,13 @@ DPCTLPlatform_GetVersion(__dpctl_keep const DPCTLSyclPlatformRef PRef) __dpctl_give DPCTLPlatformVectorRef DPCTLPlatform_GetPlatforms() { - std::vector *Platforms = nullptr; + using vecTy = std::vector; + vecTy *Platforms = nullptr; auto platforms = platform::get_platforms(); try { - Platforms = new std::vector(); + Platforms = new vecTy(); Platforms->reserve(platforms.size()); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); @@ -188,20 +206,20 @@ __dpctl_give DPCTLPlatformVectorRef DPCTLPlatform_GetPlatforms() // populate the vector for (const auto &P : platforms) { - Platforms->emplace_back(wrap(new platform(P))); + Platforms->emplace_back(wrap(new platform(P))); } // the wrap function is defined inside dpctl_vector_templ.cpp - return wrap(Platforms); + return wrap(Platforms); } __dpctl_give DPCTLSyclContextRef DPCTLPlatform_GetDefaultContext(__dpctl_keep const DPCTLSyclPlatformRef PRef) { - auto P = unwrap(PRef); + auto P = unwrap(PRef); if (P) { auto default_ctx = P->ext_oneapi_get_default_context(); - return wrap(new context(default_ctx)); + return wrap(new context(default_ctx)); } else { error_handler( diff --git a/libsyclinterface/source/dpctl_sycl_platform_manager.cpp b/libsyclinterface/source/dpctl_sycl_platform_manager.cpp index 7349f1a927..1ea724c091 100644 --- a/libsyclinterface/source/dpctl_sycl_platform_manager.cpp +++ b/libsyclinterface/source/dpctl_sycl_platform_manager.cpp @@ -41,6 +41,8 @@ using namespace sycl; namespace { +using namespace dpctl::syclinterface; + std::string platform_print_info_impl(const platform &p, size_t verbosity) { std::stringstream ss; @@ -97,14 +99,17 @@ std::string platform_print_info_impl(const platform &p, size_t verbosity) } // namespace #undef EL +#undef EL_SYCL_TYPE #define EL Platform +#define EL_SYCL_TYPE sycl::platform #include "dpctl_vector_templ.cpp" #undef EL +#undef EL_SYCL_TYPE void DPCTLPlatformMgr_PrintInfo(__dpctl_keep const DPCTLSyclPlatformRef PRef, size_t verbosity) { - auto p = unwrap(PRef); + auto p = unwrap(PRef); if (p) { std::cout << platform_print_info_impl(*p, verbosity); } @@ -119,7 +124,7 @@ DPCTLPlatformMgr_GetInfo(__dpctl_keep const DPCTLSyclPlatformRef PRef, size_t verbosity) { const char *cstr_info = nullptr; - auto p = unwrap(PRef); + auto p = unwrap(PRef); if (p) { auto infostr = platform_print_info_impl(*p, verbosity); cstr_info = dpctl::helper::cstring_from_string(infostr); diff --git a/libsyclinterface/source/dpctl_sycl_queue_interface.cpp b/libsyclinterface/source/dpctl_sycl_queue_interface.cpp index 98ef528c0a..6972b812c3 100644 --- a/libsyclinterface/source/dpctl_sycl_queue_interface.cpp +++ b/libsyclinterface/source/dpctl_sycl_queue_interface.cpp @@ -39,6 +39,8 @@ using namespace sycl; namespace { +using namespace dpctl::syclinterface; + /*! * @brief Set the kernel arg object * @@ -163,8 +165,8 @@ DPCTLQueue_Create(__dpctl_keep const DPCTLSyclContextRef CRef, int properties) { DPCTLSyclQueueRef q = nullptr; - auto dev = unwrap(DRef); - auto ctx = unwrap(CRef); + auto dev = unwrap(DRef); + auto ctx = unwrap(CRef); if (!(dev && ctx)) { error_handler("Cannot create queue from DPCTLSyclContextRef and " @@ -178,7 +180,7 @@ DPCTLQueue_Create(__dpctl_keep const DPCTLSyclContextRef CRef, try { auto Queue = new queue(*ctx, *dev, DPCTL_AsyncErrorHandler(handler), *propList); - q = wrap(Queue); + q = wrap(Queue); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); } @@ -186,7 +188,7 @@ DPCTLQueue_Create(__dpctl_keep const DPCTLSyclContextRef CRef, else if (properties) { try { auto Queue = new queue(*ctx, *dev, *propList); - q = wrap(Queue); + q = wrap(Queue); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); } @@ -195,7 +197,7 @@ DPCTLQueue_Create(__dpctl_keep const DPCTLSyclContextRef CRef, try { auto Queue = new queue(*ctx, *dev, DPCTL_AsyncErrorHandler(handler)); - q = wrap(Queue); + q = wrap(Queue); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); } @@ -203,7 +205,7 @@ DPCTLQueue_Create(__dpctl_keep const DPCTLSyclContextRef CRef, else { try { auto Queue = new queue(*ctx, *dev); - q = wrap(Queue); + q = wrap(Queue); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); } @@ -219,7 +221,7 @@ DPCTLQueue_CreateForDevice(__dpctl_keep const DPCTLSyclDeviceRef DRef, { DPCTLSyclContextRef CRef = nullptr; DPCTLSyclQueueRef QRef = nullptr; - auto Device = unwrap(DRef); + auto Device = unwrap(DRef); if (!Device) { error_handler("Cannot create queue from NULL device reference.", @@ -236,7 +238,7 @@ DPCTLQueue_CreateForDevice(__dpctl_keep const DPCTLSyclDeviceRef DRef, context *ContextPtr = nullptr; try { ContextPtr = new context(*Device); - CRef = wrap(ContextPtr); + CRef = wrap(ContextPtr); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); delete ContextPtr; @@ -255,7 +257,7 @@ DPCTLQueue_CreateForDevice(__dpctl_keep const DPCTLSyclDeviceRef DRef, */ void DPCTLQueue_Delete(__dpctl_take DPCTLSyclQueueRef QRef) { - delete unwrap(QRef); + delete unwrap(QRef); } /*! @@ -264,11 +266,11 @@ void DPCTLQueue_Delete(__dpctl_take DPCTLSyclQueueRef QRef) __dpctl_give DPCTLSyclQueueRef DPCTLQueue_Copy(__dpctl_keep const DPCTLSyclQueueRef QRef) { - auto Queue = unwrap(QRef); + auto Queue = unwrap(QRef); if (Queue) { try { auto CopiedQueue = new queue(*Queue); - return wrap(CopiedQueue); + return wrap(CopiedQueue); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); return nullptr; @@ -289,16 +291,16 @@ bool DPCTLQueue_AreEq(__dpctl_keep const DPCTLSyclQueueRef QRef1, __LINE__); return false; } - return (*unwrap(QRef1) == *unwrap(QRef2)); + return (*unwrap(QRef1) == *unwrap(QRef2)); } DPCTLSyclBackendType DPCTLQueue_GetBackend(__dpctl_keep DPCTLSyclQueueRef QRef) { - auto Q = unwrap(QRef); + auto Q = unwrap(QRef); if (Q) { try { auto C = Q->get_context(); - return DPCTLContext_GetBackend(wrap(&C)); + return DPCTLContext_GetBackend(wrap(&C)); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); return DPCTL_UNKNOWN_BACKEND; @@ -312,11 +314,11 @@ __dpctl_give DPCTLSyclDeviceRef DPCTLQueue_GetDevice(__dpctl_keep const DPCTLSyclQueueRef QRef) { DPCTLSyclDeviceRef DRef = nullptr; - auto Q = unwrap(QRef); + auto Q = unwrap(QRef); if (Q) { try { auto Device = new device(Q->get_device()); - DRef = wrap(Device); + DRef = wrap(Device); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); } @@ -331,10 +333,10 @@ DPCTLQueue_GetDevice(__dpctl_keep const DPCTLSyclQueueRef QRef) __dpctl_give DPCTLSyclContextRef DPCTLQueue_GetContext(__dpctl_keep const DPCTLSyclQueueRef QRef) { - auto Q = unwrap(QRef); + auto Q = unwrap(QRef); DPCTLSyclContextRef CRef = nullptr; if (Q) - CRef = wrap(new context(Q->get_context())); + CRef = wrap(new context(Q->get_context())); else { error_handler("Could not get the context for this queue.", __FILE__, __func__, __LINE__); @@ -353,8 +355,8 @@ DPCTLQueue_SubmitRange(__dpctl_keep const DPCTLSyclKernelRef KRef, __dpctl_keep const DPCTLSyclEventRef *DepEvents, size_t NDepEvents) { - auto Kernel = unwrap(KRef); - auto Queue = unwrap(QRef); + auto Kernel = unwrap(KRef); + auto Queue = unwrap(QRef); event e; try { @@ -362,7 +364,7 @@ DPCTLQueue_SubmitRange(__dpctl_keep const DPCTLSyclKernelRef KRef, // Depend on any event that was specified by the caller. if (NDepEvents) for (auto i = 0ul; i < NDepEvents; ++i) - cgh.depends_on(*unwrap(DepEvents[i])); + cgh.depends_on(*unwrap(DepEvents[i])); for (auto i = 0ul; i < NArgs; ++i) { // \todo add support for Sycl buffers @@ -390,7 +392,7 @@ DPCTLQueue_SubmitRange(__dpctl_keep const DPCTLSyclKernelRef KRef, return nullptr; } - return wrap(new event(e)); + return wrap(new event(e)); } __dpctl_give DPCTLSyclEventRef @@ -405,8 +407,8 @@ DPCTLQueue_SubmitNDRange(__dpctl_keep const DPCTLSyclKernelRef KRef, __dpctl_keep const DPCTLSyclEventRef *DepEvents, size_t NDepEvents) { - auto Kernel = unwrap(KRef); - auto Queue = unwrap(QRef); + auto Kernel = unwrap(KRef); + auto Queue = unwrap(QRef); event e; try { @@ -414,7 +416,7 @@ DPCTLQueue_SubmitNDRange(__dpctl_keep const DPCTLSyclKernelRef KRef, // Depend on any event that was specified by the caller. if (NDepEvents) for (auto i = 0ul; i < NDepEvents; ++i) - cgh.depends_on(*unwrap(DepEvents[i])); + cgh.depends_on(*unwrap(DepEvents[i])); for (auto i = 0ul; i < NArgs; ++i) { // \todo add support for Sycl buffers @@ -446,7 +448,7 @@ DPCTLQueue_SubmitNDRange(__dpctl_keep const DPCTLSyclKernelRef KRef, return nullptr; } - return wrap(new event(e)); + return wrap(new event(e)); } void DPCTLQueue_Wait(__dpctl_keep DPCTLSyclQueueRef QRef) @@ -454,7 +456,7 @@ void DPCTLQueue_Wait(__dpctl_keep DPCTLSyclQueueRef QRef) // \todo what happens if the QRef is null or a pointer to a valid sycl // queue if (QRef) { - auto SyclQueue = unwrap(QRef); + auto SyclQueue = unwrap(QRef); if (SyclQueue) SyclQueue->wait(); } @@ -469,7 +471,7 @@ DPCTLQueue_Memcpy(__dpctl_keep const DPCTLSyclQueueRef QRef, const void *Src, size_t Count) { - auto Q = unwrap(QRef); + auto Q = unwrap(QRef); if (Q) { sycl::event ev; try { @@ -478,7 +480,7 @@ DPCTLQueue_Memcpy(__dpctl_keep const DPCTLSyclQueueRef QRef, error_handler(e, __FILE__, __func__, __LINE__); return nullptr; } - return wrap(new event(ev)); + return wrap(new event(ev)); } else { error_handler("QRef passed to memcpy was NULL.", __FILE__, __func__, @@ -492,7 +494,7 @@ DPCTLQueue_Prefetch(__dpctl_keep DPCTLSyclQueueRef QRef, const void *Ptr, size_t Count) { - auto Q = unwrap(QRef); + auto Q = unwrap(QRef); if (Q) { if (Ptr) { sycl::event ev; @@ -502,7 +504,7 @@ DPCTLQueue_Prefetch(__dpctl_keep DPCTLSyclQueueRef QRef, error_handler(e, __FILE__, __func__, __LINE__); return nullptr; } - return wrap(new event(ev)); + return wrap(new event(ev)); } else { error_handler("Attempt to prefetch USM-allocation at nullptr.", @@ -523,7 +525,7 @@ DPCTLQueue_MemAdvise(__dpctl_keep DPCTLSyclQueueRef QRef, size_t Count, int Advice) { - auto Q = unwrap(QRef); + auto Q = unwrap(QRef); if (Q) { sycl::event ev; try { @@ -532,7 +534,7 @@ DPCTLQueue_MemAdvise(__dpctl_keep DPCTLSyclQueueRef QRef, error_handler(e, __FILE__, __func__, __LINE__); return nullptr; } - return wrap(new event(ev)); + return wrap(new event(ev)); } else { error_handler("QRef passed to prefetch was NULL.", __FILE__, __func__, @@ -543,7 +545,7 @@ DPCTLQueue_MemAdvise(__dpctl_keep DPCTLSyclQueueRef QRef, bool DPCTLQueue_IsInOrder(__dpctl_keep const DPCTLSyclQueueRef QRef) { - auto Q = unwrap(QRef); + auto Q = unwrap(QRef); if (Q) { return Q->is_in_order(); } @@ -553,7 +555,7 @@ bool DPCTLQueue_IsInOrder(__dpctl_keep const DPCTLSyclQueueRef QRef) bool DPCTLQueue_HasEnableProfiling(__dpctl_keep const DPCTLSyclQueueRef QRef) { - auto Q = unwrap(QRef); + auto Q = unwrap(QRef); if (Q) { return Q->has_property(); } @@ -563,7 +565,7 @@ bool DPCTLQueue_HasEnableProfiling(__dpctl_keep const DPCTLSyclQueueRef QRef) size_t DPCTLQueue_Hash(__dpctl_keep const DPCTLSyclQueueRef QRef) { - auto Q = unwrap(QRef); + auto Q = unwrap(QRef); if (Q) { std::hash hash_fn; return hash_fn(*Q); @@ -579,7 +581,7 @@ __dpctl_give DPCTLSyclEventRef DPCTLQueue_SubmitBarrierForEvents( __dpctl_keep const DPCTLSyclEventRef *DepEvents, size_t NDepEvents) { - auto Q = unwrap(QRef); + auto Q = unwrap(QRef); event e; if (Q) { try { @@ -587,7 +589,7 @@ __dpctl_give DPCTLSyclEventRef DPCTLQueue_SubmitBarrierForEvents( // Depend on any event that was specified by the caller. if (NDepEvents) for (auto i = 0ul; i < NDepEvents; ++i) - cgh.depends_on(*unwrap(DepEvents[i])); + cgh.depends_on(*unwrap(DepEvents[i])); cgh.ext_oneapi_barrier(); }); @@ -596,7 +598,7 @@ __dpctl_give DPCTLSyclEventRef DPCTLQueue_SubmitBarrierForEvents( return nullptr; } - return wrap(new event(e)); + return wrap(new event(e)); } else { error_handler("Argument QRef is NULL", __FILE__, __func__, __LINE__); @@ -616,7 +618,7 @@ DPCTLQueue_Memset(__dpctl_keep const DPCTLSyclQueueRef QRef, uint8_t Value, size_t Count) { - auto Q = unwrap(QRef); + auto Q = unwrap(QRef); if (Q && USMRef) { sycl::event ev; try { @@ -625,7 +627,7 @@ DPCTLQueue_Memset(__dpctl_keep const DPCTLSyclQueueRef QRef, error_handler(e, __FILE__, __func__, __LINE__); return nullptr; } - return wrap(new event(ev)); + return wrap(new event(ev)); } else { error_handler("QRef or USMRef passed to fill8 were NULL.", __FILE__, @@ -640,7 +642,7 @@ DPCTLQueue_Fill8(__dpctl_keep const DPCTLSyclQueueRef QRef, uint8_t Value, size_t Count) { - auto Q = unwrap(QRef); + auto Q = unwrap(QRef); if (Q && USMRef) { sycl::event ev; try { @@ -649,7 +651,7 @@ DPCTLQueue_Fill8(__dpctl_keep const DPCTLSyclQueueRef QRef, error_handler(e, __FILE__, __func__, __LINE__); return nullptr; } - return wrap(new event(ev)); + return wrap(new event(ev)); } else { error_handler("QRef or USMRef passed to fill8 were NULL.", __FILE__, @@ -664,7 +666,7 @@ DPCTLQueue_Fill16(__dpctl_keep const DPCTLSyclQueueRef QRef, uint16_t Value, size_t Count) { - auto Q = unwrap(QRef); + auto Q = unwrap(QRef); if (Q && USMRef) { sycl::event ev; try { @@ -673,7 +675,7 @@ DPCTLQueue_Fill16(__dpctl_keep const DPCTLSyclQueueRef QRef, error_handler(e, __FILE__, __func__, __LINE__); return nullptr; } - return wrap(new event(ev)); + return wrap(new event(ev)); } else { error_handler("QRef or USMRef passed to fill16 were NULL.", __FILE__, @@ -688,7 +690,7 @@ DPCTLQueue_Fill32(__dpctl_keep const DPCTLSyclQueueRef QRef, uint32_t Value, size_t Count) { - auto Q = unwrap(QRef); + auto Q = unwrap(QRef); if (Q && USMRef) { sycl::event ev; try { @@ -697,7 +699,7 @@ DPCTLQueue_Fill32(__dpctl_keep const DPCTLSyclQueueRef QRef, error_handler(e, __FILE__, __func__, __LINE__); return nullptr; } - return wrap(new event(ev)); + return wrap(new event(ev)); } else { error_handler("QRef or USMRef passed to fill32 were NULL.", __FILE__, @@ -712,7 +714,7 @@ DPCTLQueue_Fill64(__dpctl_keep const DPCTLSyclQueueRef QRef, uint64_t Value, size_t Count) { - auto Q = unwrap(QRef); + auto Q = unwrap(QRef); if (Q && USMRef) { sycl::event ev; try { @@ -721,7 +723,7 @@ DPCTLQueue_Fill64(__dpctl_keep const DPCTLSyclQueueRef QRef, error_handler(e, __FILE__, __func__, __LINE__); return nullptr; } - return wrap(new event(ev)); + return wrap(new event(ev)); } else { error_handler("QRef or USMRef passed to fill64 were NULL.", __FILE__, @@ -745,7 +747,7 @@ DPCTLQueue_Fill128(__dpctl_keep const DPCTLSyclQueueRef QRef, uint64_t *Value, size_t Count) { - auto Q = unwrap(QRef); + auto Q = unwrap(QRef); if (Q && USMRef) { sycl::event ev; try { @@ -757,7 +759,7 @@ DPCTLQueue_Fill128(__dpctl_keep const DPCTLSyclQueueRef QRef, error_handler(e, __FILE__, __func__, __LINE__); return nullptr; } - return wrap(new event(ev)); + return wrap(new event(ev)); } else { error_handler("QRef or USMRef passed to fill128 were NULL.", __FILE__, diff --git a/libsyclinterface/source/dpctl_sycl_queue_manager.cpp b/libsyclinterface/source/dpctl_sycl_queue_manager.cpp index dee84d3869..c2b9c94140 100644 --- a/libsyclinterface/source/dpctl_sycl_queue_manager.cpp +++ b/libsyclinterface/source/dpctl_sycl_queue_manager.cpp @@ -38,6 +38,8 @@ using namespace sycl; namespace { +using namespace dpctl::syclinterface; + struct QueueManager { using QueueStack = std::vector; @@ -45,12 +47,13 @@ struct QueueManager { thread_local static QueueStack *activeQueues = new QueueStack([] { QueueStack qs; - auto DS = default_selector(); + auto DS = dpctl_default_selector(); try { - auto DRef = wrap(new device(DS.select_device())); + auto DRef = wrap(new device(DS)); auto CRef = DPCTLDeviceMgr_GetCachedContext(DRef); if (CRef) { - qs.emplace_back(*unwrap(CRef), *unwrap(DRef)); + qs.emplace_back(*unwrap(CRef), + *unwrap(DRef)); } else { error_handler("Fatal Error: No cached context for default " @@ -58,8 +61,8 @@ struct QueueManager __FILE__, __func__, __LINE__); std::terminate(); } - delete unwrap(DRef); - delete unwrap(CRef); + delete unwrap(DRef); + delete unwrap(CRef); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); } @@ -105,7 +108,7 @@ DPCTLSyclQueueRef DPCTLQueueMgr_GetCurrentQueue() return nullptr; } auto last = qs.size() - 1; - return wrap(new queue(qs[last])); + return wrap(new queue(qs[last])); } // Relies on sycl::queue class' operator= to check for equivalent of queues. @@ -122,7 +125,7 @@ bool DPCTLQueueMgr_IsCurrentQueue(__dpctl_keep const DPCTLSyclQueueRef QRef) } auto last = qs.size() - 1; auto currQ = qs[last]; - return (*unwrap(QRef) == currQ); + return (*unwrap(QRef) == currQ); } // The function sets the global queue, i.e., the sycl::queue object at @@ -131,7 +134,7 @@ void DPCTLQueueMgr_SetGlobalQueue(__dpctl_keep const DPCTLSyclQueueRef qRef) { auto &qs = QueueManager::getQueueStack(); if (qRef) { - qs[0] = *unwrap(qRef); + qs[0] = *unwrap(qRef); } else { error_handler("Error: Failed to set the global queue.", __FILE__, @@ -145,7 +148,7 @@ void DPCTLQueueMgr_PushQueue(__dpctl_keep const DPCTLSyclQueueRef qRef) { auto &qs = QueueManager::getQueueStack(); if (qRef) { - qs.emplace_back(*unwrap(qRef)); + qs.emplace_back(*unwrap(qRef)); } else { error_handler("Error: Failed to set the current queue.", __FILE__, diff --git a/libsyclinterface/source/dpctl_sycl_usm_interface.cpp b/libsyclinterface/source/dpctl_sycl_usm_interface.cpp index 5a36004395..443d28bac3 100644 --- a/libsyclinterface/source/dpctl_sycl_usm_interface.cpp +++ b/libsyclinterface/source/dpctl_sycl_usm_interface.cpp @@ -32,6 +32,11 @@ using namespace sycl; +namespace +{ +using namespace dpctl::syclinterface; +} // end of anonymous namespace + __dpctl_give DPCTLSyclUSMRef DPCTLmalloc_shared(size_t size, __dpctl_keep const DPCTLSyclQueueRef QRef) { @@ -40,9 +45,9 @@ DPCTLmalloc_shared(size_t size, __dpctl_keep const DPCTLSyclQueueRef QRef) return nullptr; } try { - auto Q = unwrap(QRef); + auto Q = unwrap(QRef); auto Ptr = malloc_shared(size, *Q); - return wrap(Ptr); + return wrap(Ptr); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); return nullptr; @@ -59,9 +64,9 @@ DPCTLaligned_alloc_shared(size_t alignment, return nullptr; } try { - auto Q = unwrap(QRef); + auto Q = unwrap(QRef); auto Ptr = aligned_alloc_shared(alignment, size, *Q); - return wrap(Ptr); + return wrap(Ptr); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); return nullptr; @@ -77,9 +82,9 @@ DPCTLmalloc_host(size_t size, __dpctl_keep const DPCTLSyclQueueRef QRef) } // SYCL 2020 spec: for devices without aspect::usm_host_allocations: // undefined behavior - auto Q = unwrap(QRef); + auto Q = unwrap(QRef); auto Ptr = malloc_host(size, *Q); - return wrap(Ptr); + return wrap(Ptr); } __dpctl_give DPCTLSyclUSMRef @@ -93,9 +98,9 @@ DPCTLaligned_alloc_host(size_t alignment, } // SYCL 2020 spec: for devices without aspect::usm_host_allocations: // undefined behavior - auto Q = unwrap(QRef); + auto Q = unwrap(QRef); auto Ptr = aligned_alloc_host(alignment, size, *Q); - return wrap(Ptr); + return wrap(Ptr); } __dpctl_give DPCTLSyclUSMRef @@ -106,9 +111,9 @@ DPCTLmalloc_device(size_t size, __dpctl_keep const DPCTLSyclQueueRef QRef) return nullptr; } try { - auto Q = unwrap(QRef); + auto Q = unwrap(QRef); auto Ptr = malloc_device(size, *Q); - return wrap(Ptr); + return wrap(Ptr); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); return nullptr; @@ -125,9 +130,9 @@ DPCTLaligned_alloc_device(size_t alignment, return nullptr; } try { - auto Q = unwrap(QRef); + auto Q = unwrap(QRef); auto Ptr = aligned_alloc_device(alignment, size, *Q); - return wrap(Ptr); + return wrap(Ptr); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); return nullptr; @@ -146,8 +151,8 @@ void DPCTLfree_with_queue(__dpctl_take DPCTLSyclUSMRef MRef, __func__, __LINE__); return; } - auto Ptr = unwrap(MRef); - auto Q = unwrap(QRef); + auto Ptr = unwrap(MRef); + auto Q = unwrap(QRef); free(Ptr, *Q); } @@ -163,8 +168,8 @@ void DPCTLfree_with_context(__dpctl_take DPCTLSyclUSMRef MRef, __func__, __LINE__); return; } - auto Ptr = unwrap(MRef); - auto C = unwrap(CRef); + auto Ptr = unwrap(MRef); + auto C = unwrap(CRef); free(Ptr, *C); } @@ -179,8 +184,8 @@ const char *DPCTLUSM_GetPointerType(__dpctl_keep const DPCTLSyclUSMRef MRef, error_handler("Input MRef is nullptr.", __FILE__, __func__, __LINE__); return "unknown"; } - auto Ptr = unwrap(MRef); - auto C = unwrap(CRef); + auto Ptr = unwrap(MRef); + auto C = unwrap(CRef); auto kind = get_pointer_type(Ptr, *C); switch (kind) { @@ -208,10 +213,10 @@ DPCTLUSM_GetPointerDevice(__dpctl_keep const DPCTLSyclUSMRef MRef, return nullptr; } - auto Ptr = unwrap(MRef); - auto C = unwrap(CRef); + auto Ptr = unwrap(MRef); + auto C = unwrap(CRef); auto Dev = get_pointer_device(Ptr, *C); - return wrap(new device(Dev)); + return wrap(new device(Dev)); } diff --git a/libsyclinterface/source/dpctl_vector_templ.cpp b/libsyclinterface/source/dpctl_vector_templ.cpp index 20e6f224ec..b4be365107 100644 --- a/libsyclinterface/source/dpctl_vector_templ.cpp +++ b/libsyclinterface/source/dpctl_vector_templ.cpp @@ -41,7 +41,7 @@ __dpctl_give VECTOR(EL) FN(EL, Create)() vecTy *Vec = nullptr; try { Vec = new std::vector(); - return wrap(Vec); + return ::dpctl::syclinterface::wrap(Vec); } catch (std::exception const &e) { delete Vec; error_handler(e, __FILE__, __func__, __LINE__); @@ -63,11 +63,11 @@ __dpctl_give VECTOR(EL) try { Vec = new vecTy(); for (size_t i = 0; i < n; ++i) { - auto Ref = unwrap(elems[i]); - Vec->emplace_back( - wrap(new std::remove_pointer::type(*Ref))); + auto Ref = ::dpctl::syclinterface::unwrap(elems[i]); + Vec->emplace_back(::dpctl::syclinterface::wrap( + new EL_SYCL_TYPE(*Ref))); } - return wrap(Vec); + return ::dpctl::syclinterface::wrap(Vec); } catch (std::exception const &e) { delete Vec; error_handler(e, __FILE__, __func__, __LINE__); @@ -82,10 +82,11 @@ __dpctl_give VECTOR(EL) */ void FN(EL, Delete)(__dpctl_take VECTOR(EL) VRef) { - auto Vec = unwrap(VRef); + using vecTy = std::vector; + auto Vec = ::dpctl::syclinterface::unwrap(VRef); if (Vec) { for (auto i = 0ul; i < Vec->size(); ++i) { - auto D = unwrap((*Vec)[i]); + auto D = ::dpctl::syclinterface::unwrap((*Vec)[i]); delete D; } } @@ -98,10 +99,11 @@ void FN(EL, Delete)(__dpctl_take VECTOR(EL) VRef) */ void FN(EL, Clear)(__dpctl_keep VECTOR(EL) VRef) { - auto Vec = unwrap(VRef); + using vecTy = std::vector; + auto Vec = ::dpctl::syclinterface::unwrap(VRef); if (Vec) { for (auto i = 0ul; i < Vec->size(); ++i) { - auto D = unwrap((*Vec)[i]); + auto D = ::dpctl::syclinterface::unwrap((*Vec)[i]); delete D; } Vec->clear(); @@ -114,7 +116,8 @@ void FN(EL, Clear)(__dpctl_keep VECTOR(EL) VRef) */ size_t FN(EL, Size)(__dpctl_keep VECTOR(EL) VRef) { - auto V = unwrap(VRef); + using vecTy = std::vector; + auto V = ::dpctl::syclinterface::unwrap(VRef); if (V) return V->size(); else @@ -128,7 +131,8 @@ size_t FN(EL, Size)(__dpctl_keep VECTOR(EL) VRef) */ SYCLREF(EL) FN(EL, GetAt)(__dpctl_keep VECTOR(EL) VRef, size_t index) { - auto Vec = unwrap(VRef); + using vecTy = std::vector; + auto Vec = ::dpctl::syclinterface::unwrap(VRef); SYCLREF(EL) copy = nullptr; if (Vec) { SYCLREF(EL) ret; @@ -138,11 +142,11 @@ SYCLREF(EL) FN(EL, GetAt)(__dpctl_keep VECTOR(EL) VRef, size_t index) error_handler(e, __FILE__, __func__, __LINE__); return nullptr; } - auto Ref = unwrap(ret); - std::remove_pointer::type *elPtr = nullptr; + auto Ref = ::dpctl::syclinterface::unwrap(ret); + EL_SYCL_TYPE *elPtr = nullptr; try { - elPtr = new std::remove_pointer::type(*Ref); - copy = wrap(elPtr); + elPtr = new EL_SYCL_TYPE(*Ref); + copy = ::dpctl::syclinterface::wrap(elPtr); } catch (std::exception const &e) { delete elPtr; error_handler(e, __FILE__, __func__, __LINE__); diff --git a/libsyclinterface/tests/test_sycl_device_manager.cpp b/libsyclinterface/tests/test_sycl_device_manager.cpp index ed90c71e59..55b51bea0a 100644 --- a/libsyclinterface/tests/test_sycl_device_manager.cpp +++ b/libsyclinterface/tests/test_sycl_device_manager.cpp @@ -154,7 +154,7 @@ TEST_P(TestGetNumDevicesForDTy, ChkGetNumDevices) { auto devices = sycl::device::get_devices(sycl_dty); size_t nDevices = 0; - sycl::default_selector mRanker; + dpctl_default_selector mRanker; for (const sycl::device &d : devices) { if (mRanker(d) < 0) continue; @@ -188,7 +188,7 @@ TEST_P(TestGetNumDevicesForBTy, ChkGetNumDevices) { auto platforms = sycl::platform::get_platforms(); size_t nDevices = 0; - sycl::default_selector mRanker; + dpctl_default_selector mRanker; for (const auto &P : platforms) { if ((P.get_backend() == sycl_bty) || (sycl_bty == sycl::backend::all)) { auto devices = P.get_devices(); From 459754b4116bd2392dc354003d9012156eecd8be Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Thu, 3 Nov 2022 13:07:22 -0500 Subject: [PATCH 03/10] Move implementation of dpctl_*_selector class methods out to dedicated file --- .../include/dpctl_sycl_type_casters.hpp | 100 +++++----------- .../source/dpctl_device_selector.cpp | 110 ++++++++++++++++++ 2 files changed, 138 insertions(+), 72 deletions(-) create mode 100644 libsyclinterface/source/dpctl_device_selector.cpp diff --git a/libsyclinterface/include/dpctl_sycl_type_casters.hpp b/libsyclinterface/include/dpctl_sycl_type_casters.hpp index cacb904e0f..9320224b7d 100644 --- a/libsyclinterface/include/dpctl_sycl_type_casters.hpp +++ b/libsyclinterface/include/dpctl_sycl_type_casters.hpp @@ -28,9 +28,9 @@ #ifdef __cplusplus +#include "Support/DllExport.h" #include "dpctl_sycl_types.h" #include -#include #include namespace dpctl::syclinterface @@ -38,88 +38,62 @@ namespace dpctl::syclinterface #if __SYCL_COMPILER_VERSION >= 20221020 -class dpctl_device_selector +class DPCTL_API dpctl_device_selector { public: virtual ~dpctl_device_selector() = default; static constexpr int REJECT_DEVICE = -1; - virtual int operator()(const sycl::device &d) const - { - std::cout << "Outright rejecting " - << d.get_info() << std::endl; - return REJECT_DEVICE; - }; + virtual int operator()(const sycl::device &) const; }; -class dpctl_accelerator_selector : public dpctl_device_selector +class DPCTL_API dpctl_accelerator_selector : public dpctl_device_selector { public: dpctl_accelerator_selector() = default; - int operator()(const sycl::device &d) const override - { - return sycl::accelerator_selector_v(d); - } + int operator()(const sycl::device &d) const override; }; -class dpctl_default_selector : public dpctl_device_selector +class DPCTL_API dpctl_default_selector : public dpctl_device_selector { public: dpctl_default_selector() = default; - int operator()(const sycl::device &d) const override - { - auto score = sycl::default_selector_v(d); - std::cout << "Got score = " << score << std::endl; - return score; - } + int operator()(const sycl::device &d) const override; }; -class dpctl_gpu_selector : public dpctl_device_selector +class DPCTL_API dpctl_gpu_selector : public dpctl_device_selector { public: dpctl_gpu_selector() = default; - int operator()(const sycl::device &d) const override - { - return sycl::gpu_selector_v(d); - } + int operator()(const sycl::device &d) const override; }; -class dpctl_cpu_selector : public dpctl_device_selector +class DPCTL_API dpctl_cpu_selector : public dpctl_device_selector { public: dpctl_cpu_selector() = default; - int operator()(const sycl::device &d) const override - { - return sycl::cpu_selector_v(d); - } + int operator()(const sycl::device &d) const override; }; -class dpctl_filter_selector : public dpctl_device_selector +class DPCTL_API dpctl_filter_selector : public dpctl_device_selector { public: dpctl_filter_selector(const std::string &fs) : _impl(fs) {} - - int operator()(const sycl::device &d) const override - { - return _impl(d); - } + int operator()(const sycl::device &d) const override; private: sycl::ext::oneapi::filter_selector _impl; }; -class dpctl_host_selector : public dpctl_device_selector +class DPCTL_API dpctl_host_selector : public dpctl_device_selector { public: dpctl_host_selector() = default; - int operator()(const sycl::device &) const override - { - return REJECT_DEVICE; - } + int operator()(const sycl::device &) const override; }; #else -class dpctl_device_selector : public sycl::device_selector +class DPCTL_API dpctl_device_selector : public sycl::device_selector { public: virtual ~dpctl_device_selector() = default; @@ -127,80 +101,62 @@ class dpctl_device_selector : public sycl::device_selector virtual int operator()(const sycl::device &device) const = 0; }; -class dpctl_accelerator_selector : public dpctl_device_selector +class DPCTL_API dpctl_accelerator_selector : public dpctl_device_selector { public: dpctl_accelerator_selector() : _impl(){}; - int operator()(const sycl::device &d) const - { - return _impl(d); - } + int operator()(const sycl::device &d) const override; private: sycl::accelerator_selector _impl; }; -class dpctl_default_selector : public dpctl_device_selector +class DPCTL_API dpctl_default_selector : public dpctl_device_selector { public: dpctl_default_selector() : _impl(){}; - int operator()(const sycl::device &d) const - { - return _impl(d); - } + int operator()(const sycl::device &d) const override; private: sycl::default_selector _impl; }; -class dpctl_gpu_selector : public dpctl_device_selector +class DPCTL_API dpctl_gpu_selector : public dpctl_device_selector { public: dpctl_gpu_selector() : _impl(){}; - int operator()(const sycl::device &d) const - { - return _impl(d); - } + int operator()(const sycl::device &d) const override; private: sycl::gpu_selector _impl; }; -class dpctl_cpu_selector : public dpctl_device_selector +class DPCTL_API dpctl_cpu_selector : public dpctl_device_selector { public: dpctl_cpu_selector() : _impl(){}; - int operator()(const sycl::device &d) const - { - return _impl(d); - } + int operator()(const sycl::device &d) const override; private: sycl::cpu_selector _impl; }; -class dpctl_filter_selector : public dpctl_device_selector +class DPCTL_API dpctl_filter_selector : public dpctl_device_selector { public: dpctl_filter_selector(const std::string &fs) : _impl(fs) {} - int operator()(const sycl::device &d) const - { - return _impl(d); - } + int operator()(const sycl::device &d) const override; private: sycl::ext::oneapi::filter_selector _impl; }; -class dpctl_host_selector : public dpctl_device_selector +class DPCTL_API dpctl_host_selector : public dpctl_device_selector { public: dpctl_host_selector() : _impl(){}; - int operator()(const sycl::device &d) const - { - return _impl(d); - } + int operator()(const sycl::device &d) const override; private: sycl::host_selector _impl; diff --git a/libsyclinterface/source/dpctl_device_selector.cpp b/libsyclinterface/source/dpctl_device_selector.cpp new file mode 100644 index 0000000000..27b65d98f2 --- /dev/null +++ b/libsyclinterface/source/dpctl_device_selector.cpp @@ -0,0 +1,110 @@ +//===- dpctl_device_selector.cpp - Implementation of classes -*-C++-*- ===// +// dpctl_device_selector, dpctl_default_selector, etc. +// +// Data Parallel Control (dpctl) +// +// Copyright 2020-2022 Intel Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// This file implements device-selection classes declared in +/// dpctl_sycl_type_type_casters.hpp +/// +//===----------------------------------------------------------------------===// + +#include "dpctl_sycl_type_casters.hpp" +#include + +namespace dpctl +{ + +namespace syclinterface +{ + +#if __SYCL_COMPILER_VERSION >= 20221020 + +int dpctl_device_selector::operator()(const sycl::device &) const +{ + return REJECT_DEVICE; +} + +int dpctl_accelerator_selector::operator()(const sycl::device &d) const +{ + return sycl::accelerator_selector_v(d); +} + +int dpctl_default_selector::operator()(const sycl::device &d) const +{ + auto score = sycl::default_selector_v(d); + return score; +} + +int dpctl_gpu_selector::operator()(const sycl::device &d) const +{ + return sycl::gpu_selector_v(d); +} + +int dpctl_cpu_selector::operator()(const sycl::device &d) const +{ + return sycl::cpu_selector_v(d); +} + +int dpctl_filter_selector::operator()(const sycl::device &d) const +{ + return _impl(d); +} + +int dpctl_host_selector::operator()(const sycl::device &) const +{ + return REJECT_DEVICE; +} + +#else + +int dpctl_accelerator_selector::operator()(const sycl::device &d) const +{ + return _impl(d); +} + +int dpctl_default_selector::operator()(const sycl::device &d) const +{ + return _impl(d); +} + +int dpctl_gpu_selector::operator()(const sycl::device &d) const +{ + return _impl(d); +} + +int dpctl_cpu_selector::operator()(const sycl::device &d) const +{ + return _impl(d); +} + +int dpctl_filter_selector::operator()(const sycl::device &d) const +{ + return _impl(d); +} + +int dpctl_host_selector::operator()(const sycl::device &d) const +{ + return _impl(d); +} + +#endif + +} // namespace syclinterface +} // namespace dpctl From 9c1db5f3048963549cf20628ec7c1109717d0b98 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Thu, 3 Nov 2022 13:39:57 -0500 Subject: [PATCH 04/10] Adjust tests to account for namespace of wrap/unwrap --- .../tests/test_sycl_context_interface.cpp | 3 --- .../tests/test_sycl_device_aspects.cpp | 4 +++- .../tests/test_sycl_device_subdevices.cpp | 15 ++++++++------- .../tests/test_sycl_queue_interface.cpp | 3 ++- .../tests/test_sycl_queue_submit.cpp | 17 +++++++++++------ 5 files changed, 24 insertions(+), 18 deletions(-) diff --git a/libsyclinterface/tests/test_sycl_context_interface.cpp b/libsyclinterface/tests/test_sycl_context_interface.cpp index edb7b9b6e2..f20591e134 100644 --- a/libsyclinterface/tests/test_sycl_context_interface.cpp +++ b/libsyclinterface/tests/test_sycl_context_interface.cpp @@ -103,9 +103,6 @@ TEST_P(TestDPCTLContextInterface, ChkCreateWithDevicesGetDevices) DPCTLDeviceVectorRef DVRef = nullptr; DPCTLDeviceVectorRef Res_DVRef = nullptr; - /* TODO: Once we have wrappers for sub-device creation let us use those - * functions. - */ EXPECT_NO_FATAL_FAILURE(nCUs = DPCTLDevice_GetMaxComputeUnits(DRef)); if (nCUs > 1) { EXPECT_NO_FATAL_FAILURE( diff --git a/libsyclinterface/tests/test_sycl_device_aspects.cpp b/libsyclinterface/tests/test_sycl_device_aspects.cpp index 387e6aa6ec..fb7126d953 100644 --- a/libsyclinterface/tests/test_sycl_device_aspects.cpp +++ b/libsyclinterface/tests/test_sycl_device_aspects.cpp @@ -134,6 +134,8 @@ auto build_params() return build_gtest_values(pairs); } +using namespace dpctl::syclinterface; + } // namespace struct TestDPCTLSyclDeviceInterfaceAspects @@ -161,7 +163,7 @@ struct TestDPCTLSyclDeviceInterfaceAspects EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef)); if (!DRef) GTEST_SKIP_("Device not found"); - auto D = unwrap(DRef); + auto D = unwrap(DRef); auto syclAspect = GetParam().second.second; try { hasAspect = D->has(syclAspect); diff --git a/libsyclinterface/tests/test_sycl_device_subdevices.cpp b/libsyclinterface/tests/test_sycl_device_subdevices.cpp index 752ad32837..cb73359059 100644 --- a/libsyclinterface/tests/test_sycl_device_subdevices.cpp +++ b/libsyclinterface/tests/test_sycl_device_subdevices.cpp @@ -36,6 +36,7 @@ #include using namespace sycl; +using namespace dpctl::syclinterface; const DPCTLPartitionAffinityDomainType a_dpctl_domain = DPCTLPartitionAffinityDomainType::not_applicable; @@ -137,7 +138,7 @@ TEST_P(TestDPCTLSyclDeviceInterface, ChkCreateSubDevicesByAffinityNotApplicable) EXPECT_NO_FATAL_FAILURE( DVRef = DPCTLDevice_CreateSubDevicesByAffinity(DRef, dpctl_domain)); - auto D = unwrap(DRef); + auto D = unwrap(DRef); try { auto subDevices = D->create_sub_devices< info::partition_property::partition_by_affinity_domain>(domain); @@ -166,7 +167,7 @@ TEST_P(TestDPCTLSyclDeviceInterface, ChkCreateSubDevicesByAffinityNuma) EXPECT_NO_FATAL_FAILURE( DVRef = DPCTLDevice_CreateSubDevicesByAffinity(DRef, dpctl_domain)); - auto D = unwrap(DRef); + auto D = unwrap(DRef); size_t expected_size = 0; try { auto subDevices = D->create_sub_devices< @@ -197,7 +198,7 @@ TEST_P(TestDPCTLSyclDeviceInterface, ChkCreateSubDevicesByAffinityL4Cache) EXPECT_NO_FATAL_FAILURE( DVRef = DPCTLDevice_CreateSubDevicesByAffinity(DRef, dpctl_domain)); - auto D = unwrap(DRef); + auto D = unwrap(DRef); size_t expected_size = 0; try { auto subDevices = D->create_sub_devices< @@ -228,7 +229,7 @@ TEST_P(TestDPCTLSyclDeviceInterface, ChkCreateSubDevicesByAffinityL3Cache) EXPECT_NO_FATAL_FAILURE( DVRef = DPCTLDevice_CreateSubDevicesByAffinity(DRef, dpctl_domain)); - auto D = unwrap(DRef); + auto D = unwrap(DRef); size_t expected_size = 0; try { auto subDevices = D->create_sub_devices< @@ -259,7 +260,7 @@ TEST_P(TestDPCTLSyclDeviceInterface, ChkCreateSubDevicesByAffinityL2Cache) EXPECT_NO_FATAL_FAILURE( DVRef = DPCTLDevice_CreateSubDevicesByAffinity(DRef, dpctl_domain)); - auto D = unwrap(DRef); + auto D = unwrap(DRef); size_t expected_size = 0; try { auto subDevices = D->create_sub_devices< @@ -290,7 +291,7 @@ TEST_P(TestDPCTLSyclDeviceInterface, ChkCreateSubDevicesByAffinityL1Cache) EXPECT_NO_FATAL_FAILURE( DVRef = DPCTLDevice_CreateSubDevicesByAffinity(DRef, dpctl_domain)); - auto D = unwrap(DRef); + auto D = unwrap(DRef); size_t expected_size = 0; try { auto subDevices = D->create_sub_devices< @@ -322,7 +323,7 @@ TEST_P(TestDPCTLSyclDeviceInterface, EXPECT_NO_FATAL_FAILURE( DVRef = DPCTLDevice_CreateSubDevicesByAffinity(DRef, dpctl_domain)); - auto D = unwrap(DRef); + auto D = unwrap(DRef); size_t expected_size = 0; try { auto subDevices = D->create_sub_devices< diff --git a/libsyclinterface/tests/test_sycl_queue_interface.cpp b/libsyclinterface/tests/test_sycl_queue_interface.cpp index f3200f3da9..6c8a34c76f 100644 --- a/libsyclinterface/tests/test_sycl_queue_interface.cpp +++ b/libsyclinterface/tests/test_sycl_queue_interface.cpp @@ -37,6 +37,7 @@ #include using namespace sycl; +using namespace dpctl::syclinterface; namespace { @@ -347,7 +348,7 @@ TEST(TestDPCTLSyclQueueInterface, CheckMemOpsZeroQRef) TEST_P(TestDPCTLQueueMemberFunctions, CheckGetBackend) { - auto q = unwrap(QRef); + auto q = unwrap(QRef); auto Backend = q->get_device().get_platform().get_backend(); auto Bty = DPCTLQueue_GetBackend(QRef); switch (Bty) { diff --git a/libsyclinterface/tests/test_sycl_queue_submit.cpp b/libsyclinterface/tests/test_sycl_queue_submit.cpp index 38492e2709..680314b719 100644 --- a/libsyclinterface/tests/test_sycl_queue_submit.cpp +++ b/libsyclinterface/tests/test_sycl_queue_submit.cpp @@ -41,6 +41,9 @@ namespace { constexpr size_t SIZE = 1024; static_assert(SIZE % 8 == 0); + +using namespace dpctl::syclinterface; + } /* end of anonymous namespace */ struct TestQueueSubmit : public ::testing::Test @@ -92,8 +95,8 @@ TEST_F(TestQueueSubmit, CheckSubmitRange_saxpy) auto c = DPCTLmalloc_shared(SIZE * sizeof(float), QRef); ASSERT_TRUE(c != nullptr); - auto a_ptr = reinterpret_cast(unwrap(a)); - auto b_ptr = reinterpret_cast(unwrap(b)); + auto a_ptr = reinterpret_cast(unwrap(a)); + auto b_ptr = reinterpret_cast(unwrap(b)); // Initialize a,b for (auto i = 0ul; i < SIZE; ++i) { a_ptr[i] = i + 1.0; @@ -103,7 +106,8 @@ TEST_F(TestQueueSubmit, CheckSubmitRange_saxpy) // Create kernel args for axpy float d = 10.0; size_t Range[] = {SIZE}; - void *args2[4] = {unwrap(a), unwrap(b), unwrap(c), (void *)&d}; + void *args2[4] = {unwrap(a), unwrap(b), unwrap(c), + (void *)&d}; DPCTLKernelArgType addKernelArgTypes[] = {DPCTL_VOID_PTR, DPCTL_VOID_PTR, DPCTL_VOID_PTR, DPCTL_FLOAT}; auto ERef = DPCTLQueue_SubmitRange( @@ -152,8 +156,8 @@ TEST_F(TestQueueSubmit, CheckSubmitNDRange_saxpy) auto c = DPCTLmalloc_shared(SIZE * sizeof(float), QRef); ASSERT_TRUE(c != nullptr); - auto a_ptr = reinterpret_cast(unwrap(a)); - auto b_ptr = reinterpret_cast(unwrap(b)); + auto a_ptr = reinterpret_cast(unwrap(a)); + auto b_ptr = reinterpret_cast(unwrap(b)); // Initialize a,b for (auto i = 0ul; i < SIZE; ++i) { a_ptr[i] = i + 1.0; @@ -164,7 +168,8 @@ TEST_F(TestQueueSubmit, CheckSubmitNDRange_saxpy) float d = 10.0; size_t gRange[] = {1, 1, SIZE}; size_t lRange[] = {1, 1, 8}; - void *args2[4] = {unwrap(a), unwrap(b), unwrap(c), (void *)&d}; + void *args2[4] = {unwrap(a), unwrap(b), unwrap(c), + (void *)&d}; DPCTLKernelArgType addKernelArgTypes[] = {DPCTL_VOID_PTR, DPCTL_VOID_PTR, DPCTL_VOID_PTR, DPCTL_FLOAT}; DPCTLSyclEventRef events[1]; From 1d1dcc6f084ddbc4ecc7c50f46c953e87159d4d9 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Thu, 3 Nov 2022 13:39:22 -0500 Subject: [PATCH 05/10] Fence uses of is_host, backend::host with __SYCL_COMPILER_VERSION conditional --- libsyclinterface/source/dpctl_sycl_context_interface.cpp | 6 ++++++ libsyclinterface/source/dpctl_sycl_device_interface.cpp | 4 ++++ libsyclinterface/source/dpctl_sycl_platform_manager.cpp | 4 ++++ 3 files changed, 14 insertions(+) diff --git a/libsyclinterface/source/dpctl_sycl_context_interface.cpp b/libsyclinterface/source/dpctl_sycl_context_interface.cpp index 28f8c9d95a..ce0d7e608b 100644 --- a/libsyclinterface/source/dpctl_sycl_context_interface.cpp +++ b/libsyclinterface/source/dpctl_sycl_context_interface.cpp @@ -169,7 +169,11 @@ bool DPCTLContext_IsHost(__dpctl_keep const DPCTLSyclContextRef CtxRef) { auto Ctx = unwrap(CtxRef); if (Ctx) { +#if __SYCL_COMPILER_VERSION >= 20221020L + return false; +#else return Ctx->is_host(); +#endif } return false; } @@ -189,8 +193,10 @@ DPCTLContext_GetBackend(__dpctl_keep const DPCTLSyclContextRef CtxRef) auto BE = unwrap(CtxRef)->get_platform().get_backend(); switch (BE) { +#if __SYCL_COMPILER_VERSION < 20221020L case backend::host: return DPCTL_HOST; +#endif case backend::opencl: return DPCTL_OPENCL; case backend::ext_oneapi_level_zero: diff --git a/libsyclinterface/source/dpctl_sycl_device_interface.cpp b/libsyclinterface/source/dpctl_sycl_device_interface.cpp index 03b20ba680..6f5f919eab 100644 --- a/libsyclinterface/source/dpctl_sycl_device_interface.cpp +++ b/libsyclinterface/source/dpctl_sycl_device_interface.cpp @@ -179,7 +179,11 @@ bool DPCTLDevice_IsHost(__dpctl_keep const DPCTLSyclDeviceRef DRef) { auto D = unwrap(DRef); if (D) { +#if __SYCL_COMPILER_VERSION >= 20221020L + return false; +#else return D->is_host(); +#endif } return false; } diff --git a/libsyclinterface/source/dpctl_sycl_platform_manager.cpp b/libsyclinterface/source/dpctl_sycl_platform_manager.cpp index 1ea724c091..8abeef2f6b 100644 --- a/libsyclinterface/source/dpctl_sycl_platform_manager.cpp +++ b/libsyclinterface/source/dpctl_sycl_platform_manager.cpp @@ -70,7 +70,11 @@ std::string platform_print_info_impl(const platform &p, size_t verbosity) << p.get_info() << _endl << std::setw(4) << " " << std::left << std::setw(12) << "Vendor" << vendor << _endl << std::setw(4) << " " << std::left << std::setw(12) << "Backend"; +#if __SYCL_COMPILER_VERSION >= 20221020L + ss << p.get_backend(); +#else p.is_host() ? (ss << "unknown") : (ss << p.get_backend()); +#endif ss << _endl; // Get number of devices on the platform From dbc4b6a9b9de665371b9116bd787cf3ce3297d82 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Thu, 3 Nov 2022 14:43:19 -0500 Subject: [PATCH 06/10] Added config params for ifdef consts, moved device sel. class decl. to new file Added config parameters for __SYCL_COMPILER_VERSION cutoffs used throughout. Moved declarations of dpctl_device_selector and other derived classes to a dedicated .hpp file. --- .../helper/source/dpctl_utils_helper.cpp | 9 + .../include/Config/dpctl_config.h.in | 7 + .../include/dpctl_device_selection.hpp | 167 ++++++++++++++++++ .../include/dpctl_sycl_type_casters.hpp | 130 +------------- ...elector.cpp => dpctl_device_selection.cpp} | 8 +- .../source/dpctl_sycl_context_interface.cpp | 5 +- .../source/dpctl_sycl_device_interface.cpp | 8 +- .../dpctl_sycl_device_selector_interface.cpp | 1 + .../source/dpctl_sycl_platform_interface.cpp | 4 +- .../source/dpctl_sycl_platform_manager.cpp | 3 +- 10 files changed, 202 insertions(+), 140 deletions(-) create mode 100644 libsyclinterface/include/dpctl_device_selection.hpp rename libsyclinterface/source/{dpctl_device_selector.cpp => dpctl_device_selection.cpp} (93%) diff --git a/libsyclinterface/helper/source/dpctl_utils_helper.cpp b/libsyclinterface/helper/source/dpctl_utils_helper.cpp index a8e3267962..d23c9e5752 100644 --- a/libsyclinterface/helper/source/dpctl_utils_helper.cpp +++ b/libsyclinterface/helper/source/dpctl_utils_helper.cpp @@ -24,6 +24,7 @@ //===----------------------------------------------------------------------===// #include "dpctl_utils_helper.h" +#include "Config/dpctl_config.h" #include #include @@ -48,9 +49,11 @@ std::string DPCTL_DeviceTypeToStr(info::device_type devTy) case info::device_type::custom: ss << "custom"; break; +#if __SYCL_COMPILER_VERSION < __SYCL_COMPILER_2023_SWITCHOVER case info::device_type::host: ss << "host"; break; +#endif default: ss << "unknown"; } @@ -90,8 +93,10 @@ backend DPCTL_DPCTLBackendTypeToSyclBackend(DPCTLSyclBackendType BeTy) switch (BeTy) { case DPCTLSyclBackendType::DPCTL_CUDA: return backend::ext_oneapi_cuda; +#if __SYCL_COMPILER_VERSION < __SYCL_COMPILER_2023_SWITCHOVER case DPCTLSyclBackendType::DPCTL_HOST: return backend::host; +#endif case DPCTLSyclBackendType::DPCTL_LEVEL_ZERO: return backend::ext_oneapi_level_zero; case DPCTLSyclBackendType::DPCTL_OPENCL: @@ -108,8 +113,10 @@ DPCTLSyclBackendType DPCTL_SyclBackendToDPCTLBackendType(backend B) switch (B) { case backend::ext_oneapi_cuda: return DPCTLSyclBackendType::DPCTL_CUDA; +#if __SYCL_COMPILER_VERSION < __SYCL_COMPILER_2023_SWITCHOVER case backend::host: return DPCTLSyclBackendType::DPCTL_HOST; +#endif case backend::ext_oneapi_level_zero: return DPCTLSyclBackendType::DPCTL_LEVEL_ZERO; case backend::opencl: @@ -487,9 +494,11 @@ std::string DPCTL_GetDeviceFilterString(const device &Device) case backend::opencl: ss << "opencl"; break; +#if __SYCL_COMPILER_VERSION < __SYCL_COMPILER_2023_SWITCHOVER case backend::host: ss << "host"; break; +#endif default: ss << "unknown"; }; diff --git a/libsyclinterface/include/Config/dpctl_config.h.in b/libsyclinterface/include/Config/dpctl_config.h.in index 7dcfab21c9..b84f829dbb 100644 --- a/libsyclinterface/include/Config/dpctl_config.h.in +++ b/libsyclinterface/include/Config/dpctl_config.h.in @@ -29,6 +29,13 @@ #cmakedefine DPCTL_ENABLE_L0_PROGRAM_CREATION \ @DPCTL_ENABLE_L0_PROGRAM_CREATION@ +/* Version of SYCL DPC++ 2023 compiler at which transition to SYCL 2020 occurs */ +#define __SYCL_COMPILER_2023_SWITCHOVER 20221020L + +/* Version of SYCL DPC++ compiler at which info::max_work_item_size was + made templated */ +#define __SYCL_COMPILER_MAX_WORK_ITEM_SIZE_THRESHOLD 20220805L + /* The DPCPP version used to build dpctl */ #define DPCTL_DPCPP_VERSION "@IntelSycl_VERSION@" diff --git a/libsyclinterface/include/dpctl_device_selection.hpp b/libsyclinterface/include/dpctl_device_selection.hpp new file mode 100644 index 0000000000..2f1b34bb7f --- /dev/null +++ b/libsyclinterface/include/dpctl_device_selection.hpp @@ -0,0 +1,167 @@ +//===-- dpctl_device_selectors.h - Device selector class declar. --*-C++-*- =// +// +// +// Data Parallel Control (dpctl) +// +// Copyright 2020-2022 Intel Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// This file declares classes for device selection. +/// +//===----------------------------------------------------------------------===// + +#pragma once + +#include "Config/dpctl_config.h" +#include "Support/DllExport.h" +#include + +namespace dpctl +{ +namespace syclinterface +{ + +#if __SYCL_COMPILER_VERSION >= __SYCL_COMPILER_2023_SWITCHOVER + +class DPCTL_API dpctl_device_selector +{ +public: + virtual ~dpctl_device_selector() = default; + static constexpr int REJECT_DEVICE = -1; + virtual int operator()(const sycl::device &) const; +}; + +class DPCTL_API dpctl_accelerator_selector : public dpctl_device_selector +{ +public: + dpctl_accelerator_selector() = default; + int operator()(const sycl::device &d) const override; +}; + +class DPCTL_API dpctl_default_selector : public dpctl_device_selector +{ +public: + dpctl_default_selector() = default; + int operator()(const sycl::device &d) const override; +}; + +class DPCTL_API dpctl_gpu_selector : public dpctl_device_selector +{ +public: + dpctl_gpu_selector() = default; + int operator()(const sycl::device &d) const override; +}; + +class DPCTL_API dpctl_cpu_selector : public dpctl_device_selector +{ +public: + dpctl_cpu_selector() = default; + int operator()(const sycl::device &d) const override; +}; + +class DPCTL_API dpctl_filter_selector : public dpctl_device_selector +{ +public: + dpctl_filter_selector(const std::string &fs) : _impl(fs) {} + int operator()(const sycl::device &d) const override; + +private: + sycl::ext::oneapi::filter_selector _impl; +}; + +class DPCTL_API dpctl_host_selector : public dpctl_device_selector +{ +public: + dpctl_host_selector() = default; + int operator()(const sycl::device &) const override; +}; + +#else + +class DPCTL_API dpctl_device_selector : public sycl::device_selector +{ +public: + virtual ~dpctl_device_selector() = default; + + virtual int operator()(const sycl::device &device) const = 0; +}; + +class DPCTL_API dpctl_accelerator_selector : public dpctl_device_selector +{ +public: + dpctl_accelerator_selector() : _impl(){}; + int operator()(const sycl::device &d) const override; + +private: + sycl::accelerator_selector _impl; +}; + +class DPCTL_API dpctl_default_selector : public dpctl_device_selector +{ +public: + dpctl_default_selector() : _impl(){}; + int operator()(const sycl::device &d) const override; + +private: + sycl::default_selector _impl; +}; + +class DPCTL_API dpctl_gpu_selector : public dpctl_device_selector +{ +public: + dpctl_gpu_selector() : _impl(){}; + int operator()(const sycl::device &d) const override; + +private: + sycl::gpu_selector _impl; +}; + +class DPCTL_API dpctl_cpu_selector : public dpctl_device_selector +{ +public: + dpctl_cpu_selector() : _impl(){}; + int operator()(const sycl::device &d) const override; + +private: + sycl::cpu_selector _impl; +}; + +class DPCTL_API dpctl_filter_selector : public dpctl_device_selector +{ +public: + dpctl_filter_selector(const std::string &fs) : _impl(fs) {} + + int operator()(const sycl::device &d) const override; + +private: + sycl::ext::oneapi::filter_selector _impl; +}; + +class DPCTL_API dpctl_host_selector : public dpctl_device_selector +{ +public: + dpctl_host_selector() : _impl(){}; + int operator()(const sycl::device &d) const override; + +private: + sycl::host_selector _impl; +}; + +#endif + +} // namespace syclinterface +} // namespace dpctl diff --git a/libsyclinterface/include/dpctl_sycl_type_casters.hpp b/libsyclinterface/include/dpctl_sycl_type_casters.hpp index 9320224b7d..470165afdd 100644 --- a/libsyclinterface/include/dpctl_sycl_type_casters.hpp +++ b/libsyclinterface/include/dpctl_sycl_type_casters.hpp @@ -28,7 +28,7 @@ #ifdef __cplusplus -#include "Support/DllExport.h" +#include "dpctl_device_selection.hpp" #include "dpctl_sycl_types.h" #include #include @@ -36,134 +36,6 @@ namespace dpctl::syclinterface { -#if __SYCL_COMPILER_VERSION >= 20221020 - -class DPCTL_API dpctl_device_selector -{ -public: - virtual ~dpctl_device_selector() = default; - static constexpr int REJECT_DEVICE = -1; - virtual int operator()(const sycl::device &) const; -}; - -class DPCTL_API dpctl_accelerator_selector : public dpctl_device_selector -{ -public: - dpctl_accelerator_selector() = default; - int operator()(const sycl::device &d) const override; -}; - -class DPCTL_API dpctl_default_selector : public dpctl_device_selector -{ -public: - dpctl_default_selector() = default; - int operator()(const sycl::device &d) const override; -}; - -class DPCTL_API dpctl_gpu_selector : public dpctl_device_selector -{ -public: - dpctl_gpu_selector() = default; - int operator()(const sycl::device &d) const override; -}; - -class DPCTL_API dpctl_cpu_selector : public dpctl_device_selector -{ -public: - dpctl_cpu_selector() = default; - int operator()(const sycl::device &d) const override; -}; - -class DPCTL_API dpctl_filter_selector : public dpctl_device_selector -{ -public: - dpctl_filter_selector(const std::string &fs) : _impl(fs) {} - int operator()(const sycl::device &d) const override; - -private: - sycl::ext::oneapi::filter_selector _impl; -}; - -class DPCTL_API dpctl_host_selector : public dpctl_device_selector -{ -public: - dpctl_host_selector() = default; - int operator()(const sycl::device &) const override; -}; - -#else - -class DPCTL_API dpctl_device_selector : public sycl::device_selector -{ -public: - virtual ~dpctl_device_selector() = default; - - virtual int operator()(const sycl::device &device) const = 0; -}; - -class DPCTL_API dpctl_accelerator_selector : public dpctl_device_selector -{ -public: - dpctl_accelerator_selector() : _impl(){}; - int operator()(const sycl::device &d) const override; - -private: - sycl::accelerator_selector _impl; -}; - -class DPCTL_API dpctl_default_selector : public dpctl_device_selector -{ -public: - dpctl_default_selector() : _impl(){}; - int operator()(const sycl::device &d) const override; - -private: - sycl::default_selector _impl; -}; - -class DPCTL_API dpctl_gpu_selector : public dpctl_device_selector -{ -public: - dpctl_gpu_selector() : _impl(){}; - int operator()(const sycl::device &d) const override; - -private: - sycl::gpu_selector _impl; -}; - -class DPCTL_API dpctl_cpu_selector : public dpctl_device_selector -{ -public: - dpctl_cpu_selector() : _impl(){}; - int operator()(const sycl::device &d) const override; - -private: - sycl::cpu_selector _impl; -}; - -class DPCTL_API dpctl_filter_selector : public dpctl_device_selector -{ -public: - dpctl_filter_selector(const std::string &fs) : _impl(fs) {} - - int operator()(const sycl::device &d) const override; - -private: - sycl::ext::oneapi::filter_selector _impl; -}; - -class DPCTL_API dpctl_host_selector : public dpctl_device_selector -{ -public: - dpctl_host_selector() : _impl(){}; - int operator()(const sycl::device &d) const override; - -private: - sycl::host_selector _impl; -}; - -#endif - /*! @brief Creates two convenience templated functions to reinterpret_cast an opaque pointer to a pointer to a Sycl type diff --git a/libsyclinterface/source/dpctl_device_selector.cpp b/libsyclinterface/source/dpctl_device_selection.cpp similarity index 93% rename from libsyclinterface/source/dpctl_device_selector.cpp rename to libsyclinterface/source/dpctl_device_selection.cpp index 27b65d98f2..3eaa5f3463 100644 --- a/libsyclinterface/source/dpctl_device_selector.cpp +++ b/libsyclinterface/source/dpctl_device_selection.cpp @@ -21,20 +21,20 @@ /// /// \file /// This file implements device-selection classes declared in -/// dpctl_sycl_type_type_casters.hpp +/// dpctl_device_selection.hpp /// //===----------------------------------------------------------------------===// -#include "dpctl_sycl_type_casters.hpp" +#include "dpctl_device_selection.hpp" +#include "Config/dpctl_config.h" #include namespace dpctl { - namespace syclinterface { -#if __SYCL_COMPILER_VERSION >= 20221020 +#if __SYCL_COMPILER_VERSION >= __SYCL_COMPILER_2023_SWITCHOVER int dpctl_device_selector::operator()(const sycl::device &) const { diff --git a/libsyclinterface/source/dpctl_sycl_context_interface.cpp b/libsyclinterface/source/dpctl_sycl_context_interface.cpp index ce0d7e608b..b83d17e101 100644 --- a/libsyclinterface/source/dpctl_sycl_context_interface.cpp +++ b/libsyclinterface/source/dpctl_sycl_context_interface.cpp @@ -25,6 +25,7 @@ //===----------------------------------------------------------------------===// #include "dpctl_sycl_context_interface.h" +#include "Config/dpctl_config.h" #include "dpctl_error_handlers.h" #include "dpctl_sycl_type_casters.hpp" #include @@ -169,7 +170,7 @@ bool DPCTLContext_IsHost(__dpctl_keep const DPCTLSyclContextRef CtxRef) { auto Ctx = unwrap(CtxRef); if (Ctx) { -#if __SYCL_COMPILER_VERSION >= 20221020L +#if __SYCL_COMPILER_VERSION >= __SYCL_COMPILER_2023_SWITCHOVER return false; #else return Ctx->is_host(); @@ -193,7 +194,7 @@ DPCTLContext_GetBackend(__dpctl_keep const DPCTLSyclContextRef CtxRef) auto BE = unwrap(CtxRef)->get_platform().get_backend(); switch (BE) { -#if __SYCL_COMPILER_VERSION < 20221020L +#if __SYCL_COMPILER_VERSION < __SYCL_COMPILER_2023_SWITCHOVER case backend::host: return DPCTL_HOST; #endif diff --git a/libsyclinterface/source/dpctl_sycl_device_interface.cpp b/libsyclinterface/source/dpctl_sycl_device_interface.cpp index 6f5f919eab..985e8b5719 100644 --- a/libsyclinterface/source/dpctl_sycl_device_interface.cpp +++ b/libsyclinterface/source/dpctl_sycl_device_interface.cpp @@ -25,6 +25,8 @@ //===----------------------------------------------------------------------===// #include "dpctl_sycl_device_interface.h" +#include "Config/dpctl_config.h" +#include "dpctl_device_selection.hpp" #include "dpctl_error_handlers.h" #include "dpctl_string_utils.hpp" #include "dpctl_sycl_device_manager.h" @@ -44,7 +46,7 @@ using namespace dpctl::syclinterface; device *new_device_from_selector(const dpctl_device_selector *sel) { -#if __SYCL_COMPILER_VERSION >= 20221020L +#if __SYCL_COMPILER_VERSION >= __SYCL_COMPILER_2023_SWITCHOVER return new device( [=](const device &d) -> int { return sel->operator()(d); }); #else @@ -60,7 +62,7 @@ DPCTLDevice__GetMaxWorkItemSizes(__dpctl_keep const DPCTLSyclDeviceRef DRef) auto D = unwrap(DRef); if (D) { try { -#if __SYCL_COMPILER_VERSION >= 20220805 +#if __SYCL_COMPILER_VERSION >= __SYCL_COMPILER_MAX_WORK_ITEM_SIZE_THRESHOLD auto id_sizes = D->get_info>(); #else @@ -179,7 +181,7 @@ bool DPCTLDevice_IsHost(__dpctl_keep const DPCTLSyclDeviceRef DRef) { auto D = unwrap(DRef); if (D) { -#if __SYCL_COMPILER_VERSION >= 20221020L +#if __SYCL_COMPILER_VERSION >= __SYCL_COMPILER_2023_SWITCHOVER return false; #else return D->is_host(); diff --git a/libsyclinterface/source/dpctl_sycl_device_selector_interface.cpp b/libsyclinterface/source/dpctl_sycl_device_selector_interface.cpp index e09d3b1b21..5440b803f8 100644 --- a/libsyclinterface/source/dpctl_sycl_device_selector_interface.cpp +++ b/libsyclinterface/source/dpctl_sycl_device_selector_interface.cpp @@ -24,6 +24,7 @@ //===----------------------------------------------------------------------===// #include "dpctl_sycl_device_selector_interface.h" +#include "dpctl_device_selection.hpp" #include "dpctl_error_handlers.h" #include "dpctl_sycl_type_casters.hpp" #include /* SYCL headers */ diff --git a/libsyclinterface/source/dpctl_sycl_platform_interface.cpp b/libsyclinterface/source/dpctl_sycl_platform_interface.cpp index 4d8a893ef0..a33a1e3328 100644 --- a/libsyclinterface/source/dpctl_sycl_platform_interface.cpp +++ b/libsyclinterface/source/dpctl_sycl_platform_interface.cpp @@ -25,6 +25,8 @@ //===----------------------------------------------------------------------===// #include "dpctl_sycl_platform_interface.h" +#include "Config/dpctl_config.h" +#include "dpctl_device_selection.hpp" #include "dpctl_error_handlers.h" #include "dpctl_string_utils.hpp" #include "dpctl_sycl_type_casters.hpp" @@ -45,7 +47,7 @@ using namespace dpctl::syclinterface; platform *new_platform_from_selector(const dpctl_device_selector *sel) { -#if __SYCL_COMPILER_VERSION >= 20221020L +#if __SYCL_COMPILER_VERSION >= __SYCL_COMPILER_2023_SWITCHOVER return new platform( [=](const device &d) -> int { return sel->operator()(d); }); #else diff --git a/libsyclinterface/source/dpctl_sycl_platform_manager.cpp b/libsyclinterface/source/dpctl_sycl_platform_manager.cpp index 8abeef2f6b..ffbfb9a939 100644 --- a/libsyclinterface/source/dpctl_sycl_platform_manager.cpp +++ b/libsyclinterface/source/dpctl_sycl_platform_manager.cpp @@ -25,6 +25,7 @@ //===----------------------------------------------------------------------===// #include "dpctl_sycl_platform_manager.h" +#include "Config/dpctl_config.h" #include "dpctl_error_handlers.h" #include "dpctl_string_utils.hpp" #include "dpctl_sycl_platform_interface.h" @@ -70,7 +71,7 @@ std::string platform_print_info_impl(const platform &p, size_t verbosity) << p.get_info() << _endl << std::setw(4) << " " << std::left << std::setw(12) << "Vendor" << vendor << _endl << std::setw(4) << " " << std::left << std::setw(12) << "Backend"; -#if __SYCL_COMPILER_VERSION >= 20221020L +#if __SYCL_COMPILER_VERSION >= __SYCL_COMPILER_2023_SWITCHOVER ss << p.get_backend(); #else p.is_host() ? (ss << "unknown") : (ss << p.get_backend()); From 6052ba06a1bf90e9b360a77011edaac37deef0eb Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Thu, 3 Nov 2022 14:53:36 -0500 Subject: [PATCH 07/10] Use full qualifier sycl::device to fix compilation error Added ifdefs around changes needed to work with both newer OS compiler and current oneAPI DPC++ --- libsyclinterface/tests/test_helper.cpp | 13 +++++++++++++ libsyclinterface/tests/test_sycl_device_aspects.cpp | 2 +- libsyclinterface/tests/test_sycl_device_manager.cpp | 3 +++ .../tests/test_sycl_event_interface.cpp | 6 ++++++ .../tests/test_sycl_queue_interface.cpp | 3 +++ 5 files changed, 26 insertions(+), 1 deletion(-) diff --git a/libsyclinterface/tests/test_helper.cpp b/libsyclinterface/tests/test_helper.cpp index 06d3a43b55..0fe530fbce 100644 --- a/libsyclinterface/tests/test_helper.cpp +++ b/libsyclinterface/tests/test_helper.cpp @@ -45,9 +45,12 @@ TEST_F(TestHelperFns, ChkDeviceTypeToStr) res = DPCTL_DeviceTypeToStr(sycl::info::device_type::gpu)); ASSERT_TRUE(res == "gpu"); +#if __SYCL_COMPILER_VERSION < __SYCL_COMPILER_2023_SWITCHOVER EXPECT_NO_FATAL_FAILURE( res = DPCTL_DeviceTypeToStr(sycl::info::device_type::host)); + // since host device is being deprecated in SYCL 2020, accept unknown ASSERT_TRUE(res == "host"); +#endif EXPECT_NO_FATAL_FAILURE( res = DPCTL_DeviceTypeToStr(sycl::info::device_type::custom)); @@ -72,8 +75,10 @@ TEST_F(TestHelperFns, ChkStrToDeviceType) EXPECT_NO_FATAL_FAILURE(dev_type = DPCTL_StrToDeviceType("gpu")); ASSERT_TRUE(dev_type == sycl::info::device_type::gpu); +#if __SYCL_COMPILER_VERSION < __SYCL_COMPILER_2023_SWITCHOVER EXPECT_NO_FATAL_FAILURE(dev_type = DPCTL_StrToDeviceType("host")); ASSERT_TRUE(dev_type == sycl::info::device_type::host); +#endif EXPECT_NO_FATAL_FAILURE(dev_type = DPCTL_StrToDeviceType("accelerator")); ASSERT_TRUE(dev_type == sycl::info::device_type::accelerator); @@ -92,9 +97,11 @@ TEST_F(TestHelperFns, ChkDPCTLBackendTypeToSyclBackend) DPCTLSyclBackendType::DPCTL_CUDA)); ASSERT_TRUE(res == sycl::backend::ext_oneapi_cuda); +#if __SYCL_COMPILER_VERSION < __SYCL_COMPILER_2023_SWITCHOVER EXPECT_NO_FATAL_FAILURE(res = DPCTL_DPCTLBackendTypeToSyclBackend( DPCTLSyclBackendType::DPCTL_HOST)); ASSERT_TRUE(res == sycl::backend::host); +#endif EXPECT_NO_FATAL_FAILURE(res = DPCTL_DPCTLBackendTypeToSyclBackend( DPCTLSyclBackendType::DPCTL_OPENCL)); @@ -121,9 +128,11 @@ TEST_F(TestHelperFns, ChkSyclBackendToDPCTLBackendType) DTy = DPCTL_SyclBackendToDPCTLBackendType(sycl::backend::opencl)); ASSERT_TRUE(DTy == DPCTLSyclBackendType::DPCTL_OPENCL); +#if __SYCL_COMPILER_VERSION < __SYCL_COMPILER_2023_SWITCHOVER EXPECT_NO_FATAL_FAILURE( DTy = DPCTL_SyclBackendToDPCTLBackendType(sycl::backend::host)); ASSERT_TRUE(DTy == DPCTLSyclBackendType::DPCTL_HOST); +#endif EXPECT_NO_FATAL_FAILURE(DTy = DPCTL_SyclBackendToDPCTLBackendType( sycl::backend::ext_oneapi_cuda)); @@ -154,9 +163,11 @@ TEST_F(TestHelperFns, ChkDPCTLDeviceTypeToSyclDeviceType) DPCTLSyclDeviceType::DPCTL_CUSTOM)); ASSERT_TRUE(dev_type == sycl::info::device_type::custom); +#if __SYCL_COMPILER_VERSION < __SYCL_COMPILER_2023_SWITCHOVER EXPECT_NO_FATAL_FAILURE(dev_type = DPCTL_DPCTLDeviceTypeToSyclDeviceType( DPCTLSyclDeviceType::DPCTL_HOST_DEVICE)); ASSERT_TRUE(dev_type == sycl::info::device_type::host); +#endif EXPECT_NO_FATAL_FAILURE(dev_type = DPCTL_DPCTLDeviceTypeToSyclDeviceType( DPCTLSyclDeviceType::DPCTL_AUTOMATIC)); @@ -179,9 +190,11 @@ TEST_F(TestHelperFns, SyclDeviceTypeToDPCTLDeviceType) sycl::info::device_type::gpu)); ASSERT_TRUE(DTy == DPCTLSyclDeviceType::DPCTL_GPU); +#if __SYCL_COMPILER_VERSION < __SYCL_COMPILER_2023_SWITCHOVER EXPECT_NO_FATAL_FAILURE(DTy = DPCTL_SyclDeviceTypeToDPCTLDeviceType( sycl::info::device_type::host)); ASSERT_TRUE(DTy == DPCTLSyclDeviceType::DPCTL_HOST_DEVICE); +#endif EXPECT_NO_FATAL_FAILURE(DTy = DPCTL_SyclDeviceTypeToDPCTLDeviceType( sycl::info::device_type::accelerator)); diff --git a/libsyclinterface/tests/test_sycl_device_aspects.cpp b/libsyclinterface/tests/test_sycl_device_aspects.cpp index fb7126d953..0ea8d1fc06 100644 --- a/libsyclinterface/tests/test_sycl_device_aspects.cpp +++ b/libsyclinterface/tests/test_sycl_device_aspects.cpp @@ -163,7 +163,7 @@ struct TestDPCTLSyclDeviceInterfaceAspects EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef)); if (!DRef) GTEST_SKIP_("Device not found"); - auto D = unwrap(DRef); + auto D = unwrap(DRef); auto syclAspect = GetParam().second.second; try { hasAspect = D->has(syclAspect); diff --git a/libsyclinterface/tests/test_sycl_device_manager.cpp b/libsyclinterface/tests/test_sycl_device_manager.cpp index 55b51bea0a..ad4d3f39ab 100644 --- a/libsyclinterface/tests/test_sycl_device_manager.cpp +++ b/libsyclinterface/tests/test_sycl_device_manager.cpp @@ -24,6 +24,7 @@ /// //===----------------------------------------------------------------------===// +#include "dpctl_device_selection.hpp" #include "dpctl_sycl_device_interface.h" #include "dpctl_sycl_device_manager.h" #include "dpctl_sycl_device_selector_interface.h" @@ -32,6 +33,8 @@ #include #include +using dpctl::syclinterface::dpctl_default_selector; + struct TestDPCTLDeviceManager : public ::testing::TestWithParam { DPCTLSyclDeviceSelectorRef DSRef = nullptr; diff --git a/libsyclinterface/tests/test_sycl_event_interface.cpp b/libsyclinterface/tests/test_sycl_event_interface.cpp index 940ad8f44c..17ebff151e 100644 --- a/libsyclinterface/tests/test_sycl_event_interface.cpp +++ b/libsyclinterface/tests/test_sycl_event_interface.cpp @@ -24,6 +24,7 @@ /// //===----------------------------------------------------------------------===// +#include "Config/dpctl_config.h" #include "dpctl_sycl_event_interface.h" #include "dpctl_sycl_types.h" #include @@ -156,7 +157,12 @@ TEST_F(TestDPCTLSyclEventInterface, ChkGetCommandExecutionStatus) TEST_F(TestDPCTLSyclEventInterface, CheckGetProfiling) { property_list propList{property::queue::enable_profiling()}; + +#if __SYCL_COMPILER_VERSION >= __SYCL_COMPILER_2023_SWITCHOVER + queue Q(cpu_selector_v, propList); +#else queue Q(cpu_selector(), propList); +#endif auto eA = Q.submit( [&](handler &h) { h.parallel_for(1000, [=](id<1>) { /*...*/ }); }); DPCTLSyclEventRef ERef = reinterpret_cast(&eA); diff --git a/libsyclinterface/tests/test_sycl_queue_interface.cpp b/libsyclinterface/tests/test_sycl_queue_interface.cpp index 6c8a34c76f..38266eb2f9 100644 --- a/libsyclinterface/tests/test_sycl_queue_interface.cpp +++ b/libsyclinterface/tests/test_sycl_queue_interface.cpp @@ -24,6 +24,7 @@ /// //===----------------------------------------------------------------------===// +#include "Config/dpctl_config.h" #include "dpctl_sycl_context_interface.h" #include "dpctl_sycl_device_interface.h" #include "dpctl_sycl_device_manager.h" @@ -355,9 +356,11 @@ TEST_P(TestDPCTLQueueMemberFunctions, CheckGetBackend) case DPCTL_CUDA: EXPECT_TRUE(Backend == backend::ext_oneapi_cuda); break; +#if __SYCL_COMPILER_VERSION < __SYCL_COMPILER_2023_SWITCHOVER case DPCTL_HOST: EXPECT_TRUE(Backend == backend::host); break; +#endif case DPCTL_LEVEL_ZERO: EXPECT_TRUE(Backend == backend::ext_oneapi_level_zero); break; From ec3ee3a7f46199299a3c7ed489a5062c0ce11cca Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Fri, 4 Nov 2022 09:02:44 -0500 Subject: [PATCH 08/10] Do not use aspect::host in 2023 compiler, since it is also deprecated --- .../helper/source/dpctl_utils_helper.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libsyclinterface/helper/source/dpctl_utils_helper.cpp b/libsyclinterface/helper/source/dpctl_utils_helper.cpp index d23c9e5752..a3e79b38e0 100644 --- a/libsyclinterface/helper/source/dpctl_utils_helper.cpp +++ b/libsyclinterface/helper/source/dpctl_utils_helper.cpp @@ -177,9 +177,11 @@ std::string DPCTL_AspectToStr(aspect aspectTy) { std::stringstream ss; switch (aspectTy) { +#if __SYCL_COMPILER_VERSION < __SYCL_COMPILER_2023_SWITCHOVER case aspect::host: ss << "host"; break; +#endif case aspect::cpu: ss << "cpu"; break; @@ -249,9 +251,13 @@ std::string DPCTL_AspectToStr(aspect aspectTy) aspect DPCTL_StrToAspectType(const std::string &aspectTyStr) { aspect aspectTy; - if (aspectTyStr == "host") { + if (false) { + } +#if __SYCL_COMPILER_VERSION < __SYCL_COMPILER_2023_SWITCHOVER + else if (aspectTyStr == "host") { aspectTy = aspect::host; } +#endif else if (aspectTyStr == "cpu") { aspectTy = aspect::cpu; } @@ -319,8 +325,10 @@ aspect DPCTL_StrToAspectType(const std::string &aspectTyStr) aspect DPCTL_DPCTLAspectTypeToSyclAspect(DPCTLSyclAspectType AspectTy) { switch (AspectTy) { +#if __SYCL_COMPILER_VERSION < __SYCL_COMPILER_2023_SWITCHOVER case DPCTLSyclAspectType::host: return aspect::host; +#endif case DPCTLSyclAspectType::cpu: return aspect::cpu; case DPCTLSyclAspectType::gpu: @@ -367,8 +375,10 @@ aspect DPCTL_DPCTLAspectTypeToSyclAspect(DPCTLSyclAspectType AspectTy) DPCTLSyclAspectType DPCTL_SyclAspectToDPCTLAspectType(aspect Aspect) { switch (Aspect) { +#if __SYCL_COMPILER_VERSION < __SYCL_COMPILER_2023_SWITCHOVER case aspect::host: return DPCTLSyclAspectType::host; +#endif case aspect::cpu: return DPCTLSyclAspectType::cpu; case aspect::gpu: From f83353b7a5ceef40c8c2d03eaaf386b1eaba5e05 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Fri, 4 Nov 2022 09:03:17 -0500 Subject: [PATCH 09/10] Exclude testing of aspect::host with 2023 compiler --- libsyclinterface/tests/test_sycl_device_aspects.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libsyclinterface/tests/test_sycl_device_aspects.cpp b/libsyclinterface/tests/test_sycl_device_aspects.cpp index 0ea8d1fc06..a1cae92876 100644 --- a/libsyclinterface/tests/test_sycl_device_aspects.cpp +++ b/libsyclinterface/tests/test_sycl_device_aspects.cpp @@ -24,6 +24,7 @@ /// //===----------------------------------------------------------------------===// +#include "Config/dpctl_config.h" #include "dpctl_sycl_device_interface.h" #include "dpctl_sycl_device_selector_interface.h" #include "dpctl_sycl_enum_types.h" @@ -100,7 +101,9 @@ auto build_params() constexpr auto param_2 = get_param_list>( +#if __SYCL_COMPILER_VERSION < __SYCL_COMPILER_2023_SWITCHOVER std::make_pair("host", sycl::aspect::host), +#endif std::make_pair("cpu", sycl::aspect::cpu), std::make_pair("gpu", sycl::aspect::gpu), std::make_pair("accelerator", sycl::aspect::accelerator), From e28769a745d2a3dae70e8790a82e4323e24f2faf Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Sat, 5 Nov 2022 08:38:02 -0500 Subject: [PATCH 10/10] Addressing PR feedback --- libsyclinterface/helper/source/dpctl_utils_helper.cpp | 6 ++---- libsyclinterface/include/dpctl_device_selection.hpp | 2 +- libsyclinterface/source/dpctl_device_selection.cpp | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/libsyclinterface/helper/source/dpctl_utils_helper.cpp b/libsyclinterface/helper/source/dpctl_utils_helper.cpp index a3e79b38e0..e13189784d 100644 --- a/libsyclinterface/helper/source/dpctl_utils_helper.cpp +++ b/libsyclinterface/helper/source/dpctl_utils_helper.cpp @@ -251,16 +251,14 @@ std::string DPCTL_AspectToStr(aspect aspectTy) aspect DPCTL_StrToAspectType(const std::string &aspectTyStr) { aspect aspectTy; - if (false) { + if (aspectTyStr == "cpu") { + aspectTy = aspect::cpu; } #if __SYCL_COMPILER_VERSION < __SYCL_COMPILER_2023_SWITCHOVER else if (aspectTyStr == "host") { aspectTy = aspect::host; } #endif - else if (aspectTyStr == "cpu") { - aspectTy = aspect::cpu; - } else if (aspectTyStr == "gpu") { aspectTy = aspect::gpu; } diff --git a/libsyclinterface/include/dpctl_device_selection.hpp b/libsyclinterface/include/dpctl_device_selection.hpp index 2f1b34bb7f..a904228d34 100644 --- a/libsyclinterface/include/dpctl_device_selection.hpp +++ b/libsyclinterface/include/dpctl_device_selection.hpp @@ -1,4 +1,4 @@ -//===-- dpctl_device_selectors.h - Device selector class declar. --*-C++-*- =// +//===-- dpctl_device_selection.h - Device selector class declar. --*-C++-*- =// // // // Data Parallel Control (dpctl) diff --git a/libsyclinterface/source/dpctl_device_selection.cpp b/libsyclinterface/source/dpctl_device_selection.cpp index 3eaa5f3463..12c28cbc23 100644 --- a/libsyclinterface/source/dpctl_device_selection.cpp +++ b/libsyclinterface/source/dpctl_device_selection.cpp @@ -1,4 +1,4 @@ -//===- dpctl_device_selector.cpp - Implementation of classes -*-C++-*- ===// +//===- dpctl_device_selection.cpp - Implementation of classes -*-C++-*- ===// // dpctl_device_selector, dpctl_default_selector, etc. // // Data Parallel Control (dpctl)