diff --git a/libsyclinterface/helper/source/dpctl_utils_helper.cpp b/libsyclinterface/helper/source/dpctl_utils_helper.cpp index a8e3267962..e13189784d 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: @@ -170,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; @@ -242,12 +251,14 @@ std::string DPCTL_AspectToStr(aspect aspectTy) aspect DPCTL_StrToAspectType(const std::string &aspectTyStr) { aspect aspectTy; - if (aspectTyStr == "host") { - aspectTy = aspect::host; - } - else if (aspectTyStr == "cpu") { + 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 == "gpu") { aspectTy = aspect::gpu; } @@ -312,8 +323,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: @@ -360,8 +373,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: @@ -487,9 +502,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/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_device_selection.hpp b/libsyclinterface/include/dpctl_device_selection.hpp new file mode 100644 index 0000000000..a904228d34 --- /dev/null +++ b/libsyclinterface/include/dpctl_device_selection.hpp @@ -0,0 +1,167 @@ +//===-- dpctl_device_selection.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_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 new file mode 100644 index 0000000000..470165afdd --- /dev/null +++ b/libsyclinterface/include/dpctl_sycl_type_casters.hpp @@ -0,0 +1,85 @@ +//===-- 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_device_selection.hpp" +#include "dpctl_sycl_types.h" +#include +#include + +namespace dpctl::syclinterface +{ + +/*! + @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) \ + template ::value, bool> = true> \ + __attribute__((unused)) T *unwrap(ref P) \ + { \ + return reinterpret_cast(P); \ + } \ + template ::value, bool> = true> \ + __attribute__((unused)) 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 + +} // namespace dpctl::syclinterface diff --git a/libsyclinterface/source/dpctl_device_selection.cpp b/libsyclinterface/source/dpctl_device_selection.cpp new file mode 100644 index 0000000000..12c28cbc23 --- /dev/null +++ b/libsyclinterface/source/dpctl_device_selection.cpp @@ -0,0 +1,110 @@ +//===- dpctl_device_selection.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_device_selection.hpp +/// +//===----------------------------------------------------------------------===// + +#include "dpctl_device_selection.hpp" +#include "Config/dpctl_config.h" +#include + +namespace dpctl +{ +namespace syclinterface +{ + +#if __SYCL_COMPILER_VERSION >= __SYCL_COMPILER_2023_SWITCHOVER + +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 diff --git a/libsyclinterface/source/dpctl_sycl_context_interface.cpp b/libsyclinterface/source/dpctl_sycl_context_interface.cpp index 57bc256b84..b83d17e101 100644 --- a/libsyclinterface/source/dpctl_sycl_context_interface.cpp +++ b/libsyclinterface/source/dpctl_sycl_context_interface.cpp @@ -25,8 +25,9 @@ //===----------------------------------------------------------------------===// #include "dpctl_sycl_context_interface.h" -#include "Support/CBindingWrapping.h" +#include "Config/dpctl_config.h" #include "dpctl_error_handlers.h" +#include "dpctl_sycl_type_casters.hpp" #include #include @@ -34,12 +35,8 @@ 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 */ +using namespace dpctl::syclinterface; +} // end of anonymous namespace __dpctl_give DPCTLSyclContextRef DPCTLContext_Create(__dpctl_keep const DPCTLSyclDeviceRef DRef, @@ -47,7 +44,7 @@ DPCTLContext_Create(__dpctl_keep const DPCTLSyclDeviceRef DRef, 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.", @@ -55,7 +52,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__); } @@ -70,7 +68,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.", @@ -80,11 +78,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__); } @@ -100,13 +99,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__); @@ -114,7 +113,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; @@ -124,16 +123,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__); @@ -143,9 +143,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__); @@ -155,7 +155,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.", @@ -168,16 +168,20 @@ 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) { +#if __SYCL_COMPILER_VERSION >= __SYCL_COMPILER_2023_SWITCHOVER + return false; +#else return Ctx->is_host(); +#endif } return false; } void DPCTLContext_Delete(__dpctl_take DPCTLSyclContextRef CtxRef) { - delete unwrap(CtxRef); + delete unwrap(CtxRef); } DPCTLSyclBackendType @@ -187,11 +191,13 @@ 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) { +#if __SYCL_COMPILER_VERSION < __SYCL_COMPILER_2023_SWITCHOVER case backend::host: return DPCTL_HOST; +#endif case backend::opencl: return DPCTL_OPENCL; case backend::ext_oneapi_level_zero: @@ -206,7 +212,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 7761018686..985e8b5719 100644 --- a/libsyclinterface/source/dpctl_sycl_device_interface.cpp +++ b/libsyclinterface/source/dpctl_sycl_device_interface.cpp @@ -25,10 +25,12 @@ //===----------------------------------------------------------------------===// #include "dpctl_sycl_device_interface.h" -#include "Support/CBindingWrapping.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" +#include "dpctl_sycl_type_casters.hpp" #include "dpctl_utils_helper.h" #include /* SYCL headers */ #include @@ -39,22 +41,28 @@ 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) + +using namespace dpctl::syclinterface; + +device *new_device_from_selector(const dpctl_device_selector *sel) +{ +#if __SYCL_COMPILER_VERSION >= __SYCL_COMPILER_2023_SWITCHOVER + 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 +#if __SYCL_COMPILER_VERSION >= __SYCL_COMPILER_MAX_WORK_ITEM_SIZE_THRESHOLD auto id_sizes = D->get_info>(); #else @@ -76,7 +84,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__); @@ -84,7 +92,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; @@ -95,7 +103,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; @@ -105,7 +113,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.", @@ -113,8 +121,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; @@ -123,14 +131,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(); @@ -144,7 +152,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(); } @@ -153,7 +161,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(); } @@ -162,7 +170,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(); } @@ -171,9 +179,13 @@ 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) { +#if __SYCL_COMPILER_VERSION >= __SYCL_COMPILER_2023_SWITCHOVER + return false; +#else return D->is_host(); +#endif } return false; } @@ -182,7 +194,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()); @@ -194,7 +206,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(); @@ -209,7 +221,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(); @@ -223,7 +235,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(); @@ -238,7 +250,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 = @@ -278,7 +290,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(); @@ -293,7 +305,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(); @@ -308,10 +320,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__); } @@ -323,7 +335,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(); @@ -339,7 +351,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(); @@ -355,7 +367,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(); @@ -370,8 +382,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 @@ -382,7 +394,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)); @@ -397,7 +409,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(); \ @@ -420,7 +432,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< @@ -436,7 +448,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 = @@ -452,7 +464,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 = @@ -468,7 +480,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 = @@ -484,7 +496,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 = @@ -500,7 +512,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 = @@ -516,7 +528,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 = @@ -532,7 +544,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 = @@ -547,11 +559,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; @@ -565,20 +577,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; @@ -586,7 +599,7 @@ DPCTLDevice_CreateSubDevicesEqually(__dpctl_keep const DPCTLSyclDeviceRef DRef, return nullptr; } } - return wrap(Devices); + return wrap(Devices); } __dpctl_give DPCTLDeviceVectorRef @@ -594,7 +607,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()); @@ -604,7 +618,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< @@ -614,9 +628,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; @@ -624,24 +638,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; @@ -649,13 +664,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); } @@ -669,7 +684,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 { @@ -682,7 +697,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 { @@ -695,7 +710,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 { @@ -708,7 +723,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 2bbacb60da..3ce34df2c5 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,9 +40,7 @@ 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) +using namespace dpctl::syclinterface; /* * Helper function to print the metadata for a sycl::device. @@ -115,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(); @@ -148,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.", @@ -170,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; @@ -187,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); @@ -200,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) @@ -213,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); @@ -249,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) @@ -282,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; @@ -304,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 @@ -314,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 fe0ce3e123..5440b803f8 100644 --- a/libsyclinterface/source/dpctl_sycl_device_selector_interface.cpp +++ b/libsyclinterface/source/dpctl_sycl_device_selector_interface.cpp @@ -24,25 +24,23 @@ //===----------------------------------------------------------------------===// #include "dpctl_sycl_device_selector_interface.h" -#include "Support/CBindingWrapping.h" +#include "dpctl_device_selection.hpp" #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 */ +using namespace dpctl::syclinterface; +} // end of anonymous namespace __dpctl_give DPCTLSyclDeviceSelectorRef DPCTLAcceleratorSelector_Create() { try { - auto Selector = new accelerator_selector(); - return wrap(Selector); + auto Selector = new dpctl_accelerator_selector(); + return wrap(Selector); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); return nullptr; @@ -52,8 +50,8 @@ __dpctl_give DPCTLSyclDeviceSelectorRef DPCTLAcceleratorSelector_Create() __dpctl_give DPCTLSyclDeviceSelectorRef DPCTLDefaultSelector_Create() { try { - auto Selector = new default_selector(); - return wrap(Selector); + auto Selector = new dpctl_default_selector(); + return wrap(Selector); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); return nullptr; @@ -63,8 +61,8 @@ __dpctl_give DPCTLSyclDeviceSelectorRef DPCTLDefaultSelector_Create() __dpctl_give DPCTLSyclDeviceSelectorRef DPCTLCPUSelector_Create() { try { - auto Selector = new cpu_selector(); - return wrap(Selector); + auto Selector = new dpctl_cpu_selector(); + return wrap(Selector); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); return nullptr; @@ -74,14 +72,10 @@ __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); + return wrap(Selector); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); return nullptr; @@ -91,8 +85,8 @@ DPCTLFilterSelector_Create(__dpctl_keep const char *filter_str) __dpctl_give DPCTLSyclDeviceSelectorRef DPCTLGPUSelector_Create() { try { - auto Selector = new gpu_selector(); - return wrap(Selector); + auto Selector = new dpctl_gpu_selector(); + return wrap(Selector); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); return nullptr; @@ -102,8 +96,8 @@ __dpctl_give DPCTLSyclDeviceSelectorRef DPCTLGPUSelector_Create() __dpctl_give DPCTLSyclDeviceSelectorRef DPCTLHostSelector_Create() { try { - auto Selector = new host_selector(); - return wrap(Selector); + auto Selector = new dpctl_host_selector(); + return wrap(Selector); } catch (std::exception const &e) { error_handler(e, __FILE__, __func__, __LINE__); return nullptr; @@ -115,8 +109,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; @@ -124,6 +118,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 7fb22bd7dc..804c76ccb9 100644 --- a/libsyclinterface/source/dpctl_sycl_event_interface.cpp +++ b/libsyclinterface/source/dpctl_sycl_event_interface.cpp @@ -25,8 +25,8 @@ //===----------------------------------------------------------------------===// #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 @@ -35,21 +35,23 @@ using namespace sycl; namespace { -// Create wrappers for C Binding types (see CBindingWrapping.h) -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(event, DPCTLSyclEventRef) -} /* end of anonymous 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__); } @@ -59,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(); @@ -77,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(); @@ -94,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__); @@ -108,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; @@ -118,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()); } @@ -134,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 = @@ -150,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(); @@ -166,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(); @@ -182,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(); @@ -198,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; @@ -215,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 e540259bb9..a6e0492421 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,8 @@ 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) + +using namespace dpctl::syclinterface; #ifdef __linux__ static const char *clLoaderName = DPCTL_LIBCL_LOADER_FILENAME; @@ -202,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 @@ -319,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; @@ -476,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(); @@ -530,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) + @@ -608,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) { @@ -654,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(); @@ -693,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: @@ -721,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: @@ -738,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 9f5e278e3b..cdf009e5b4 100644 --- a/libsyclinterface/source/dpctl_sycl_kernel_interface.cpp +++ b/libsyclinterface/source/dpctl_sycl_kernel_interface.cpp @@ -25,9 +25,9 @@ //===----------------------------------------------------------------------===// #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 @@ -35,10 +35,8 @@ using namespace sycl; namespace { - -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(kernel, DPCTLSyclKernelRef) - -} /* end of anonymous namespace */ +using namespace dpctl::syclinterface; +} // end of anonymous namespace size_t DPCTLKernel_GetNumArgs(__dpctl_keep const DPCTLSyclKernelRef KRef) { @@ -49,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) @@ -67,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.", @@ -88,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.", @@ -109,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.", @@ -131,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.", @@ -156,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.", @@ -178,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.", @@ -201,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 121fbeed1d..a33a1e3328 100644 --- a/libsyclinterface/source/dpctl_sycl_platform_interface.cpp +++ b/libsyclinterface/source/dpctl_sycl_platform_interface.cpp @@ -25,9 +25,11 @@ //===----------------------------------------------------------------------===// #include "dpctl_sycl_platform_interface.h" -#include "Support/CBindingWrapping.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" #include "dpctl_utils_helper.h" #include #include @@ -40,17 +42,25 @@ 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 + +using namespace dpctl::syclinterface; + +platform *new_platform_from_selector(const dpctl_device_selector *sel) +{ +#if __SYCL_COMPILER_VERSION >= __SYCL_COMPILER_2023_SWITCHOVER + 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__); @@ -58,7 +68,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; @@ -70,7 +80,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__); } @@ -81,11 +91,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__); @@ -102,7 +112,7 @@ __dpctl_give DPCTLSyclPlatformRef DPCTLPlatform_CreateFromSelector( void DPCTLPlatform_Delete(__dpctl_take DPCTLSyclPlatformRef PRef) { - auto P = unwrap(PRef); + auto P = unwrap(PRef); delete P; } @@ -110,7 +120,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()); } @@ -124,7 +134,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(); @@ -144,7 +154,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(); @@ -164,7 +174,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(); @@ -183,12 +193,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__); @@ -197,20 +208,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 bda2e6bb89..ffbfb9a939 100644 --- a/libsyclinterface/source/dpctl_sycl_platform_manager.cpp +++ b/libsyclinterface/source/dpctl_sycl_platform_manager.cpp @@ -25,10 +25,11 @@ //===----------------------------------------------------------------------===// #include "dpctl_sycl_platform_manager.h" -#include "Support/CBindingWrapping.h" +#include "Config/dpctl_config.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 +41,8 @@ using namespace sycl; namespace { -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(platform, DPCTLSyclPlatformRef); + +using namespace dpctl::syclinterface; std::string platform_print_info_impl(const platform &p, size_t verbosity) { @@ -69,7 +71,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 >= __SYCL_COMPILER_2023_SWITCHOVER + ss << p.get_backend(); +#else p.is_host() ? (ss << "unknown") : (ss << p.get_backend()); +#endif ss << _endl; // Get number of devices on the platform @@ -98,14 +104,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); } @@ -120,7 +129,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 9f0b4fa038..6972b812c3 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,8 @@ 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) + +using namespace dpctl::syclinterface; /*! * @brief Set the kernel arg object @@ -169,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 " @@ -184,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__); } @@ -192,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__); } @@ -201,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__); } @@ -209,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__); } @@ -225,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.", @@ -242,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; @@ -261,7 +257,7 @@ DPCTLQueue_CreateForDevice(__dpctl_keep const DPCTLSyclDeviceRef DRef, */ void DPCTLQueue_Delete(__dpctl_take DPCTLSyclQueueRef QRef) { - delete unwrap(QRef); + delete unwrap(QRef); } /*! @@ -270,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; @@ -295,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; @@ -318,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__); } @@ -337,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__); @@ -359,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 { @@ -368,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 @@ -396,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 @@ -411,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 { @@ -420,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 @@ -452,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) @@ -460,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(); } @@ -475,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 { @@ -484,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__, @@ -498,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; @@ -508,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.", @@ -529,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 { @@ -538,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__, @@ -549,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(); } @@ -559,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(); } @@ -569,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); @@ -585,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 { @@ -593,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(); }); @@ -602,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__); @@ -622,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 { @@ -631,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__, @@ -646,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 { @@ -655,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__, @@ -670,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 { @@ -679,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__, @@ -694,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 { @@ -703,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__, @@ -718,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 { @@ -727,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__, @@ -751,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 { @@ -763,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 f9f9ab4bba..c2b9c94140 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,8 @@ 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) + +using namespace dpctl::syclinterface; struct QueueManager { @@ -49,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 " @@ -62,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__); } @@ -109,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. @@ -126,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 @@ -135,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__, @@ -149,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 a6c92cb1ab..443d28bac3 100644 --- a/libsyclinterface/source/dpctl_sycl_usm_interface.cpp +++ b/libsyclinterface/source/dpctl_sycl_usm_interface.cpp @@ -25,22 +25,17 @@ //===----------------------------------------------------------------------===// #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 */ +using namespace dpctl::syclinterface; +} // end of anonymous namespace __dpctl_give DPCTLSyclUSMRef DPCTLmalloc_shared(size_t size, __dpctl_keep const DPCTLSyclQueueRef QRef) @@ -50,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; @@ -69,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; @@ -87,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 @@ -103,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 @@ -116,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; @@ -135,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; @@ -156,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); } @@ -173,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); } @@ -189,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) { @@ -218,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 5a3220f364..b4be365107 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 ::dpctl::syclinterface::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))); + 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__); @@ -84,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; } } @@ -100,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(); @@ -116,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 @@ -130,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; @@ -140,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_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_context_interface.cpp b/libsyclinterface/tests/test_sycl_context_interface.cpp index 29ae87ae04..f20591e134 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" @@ -104,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 5153278c7b..a1cae92876 100644 --- a/libsyclinterface/tests/test_sycl_device_aspects.cpp +++ b/libsyclinterface/tests/test_sycl_device_aspects.cpp @@ -24,10 +24,11 @@ /// //===----------------------------------------------------------------------===// -#include "Support/CBindingWrapping.h" +#include "Config/dpctl_config.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 +36,6 @@ namespace { -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(sycl::device, DPCTLSyclDeviceRef); template struct are_same : std::true_type { @@ -101,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), @@ -135,6 +137,8 @@ auto build_params() return build_gtest_values(pairs); } +using namespace dpctl::syclinterface; + } // namespace struct TestDPCTLSyclDeviceInterfaceAspects @@ -162,7 +166,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 ed90c71e59..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; @@ -154,7 +157,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 +191,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(); 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..cb73359059 100644 --- a/libsyclinterface/tests/test_sycl_device_subdevices.cpp +++ b/libsyclinterface/tests/test_sycl_device_subdevices.cpp @@ -25,19 +25,18 @@ /// //===----------------------------------------------------------------------===// -#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 #include using namespace sycl; - -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(device, DPCTLSyclDeviceRef); +using namespace dpctl::syclinterface; const DPCTLPartitionAffinityDomainType a_dpctl_domain = DPCTLPartitionAffinityDomainType::not_applicable; @@ -139,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); @@ -168,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< @@ -199,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< @@ -230,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< @@ -261,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< @@ -292,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< @@ -324,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_event_interface.cpp b/libsyclinterface/tests/test_sycl_event_interface.cpp index 396ea1a45a..17ebff151e 100644 --- a/libsyclinterface/tests/test_sycl_event_interface.cpp +++ b/libsyclinterface/tests/test_sycl_event_interface.cpp @@ -24,7 +24,7 @@ /// //===----------------------------------------------------------------------===// -#include "Support/CBindingWrapping.h" +#include "Config/dpctl_config.h" #include "dpctl_sycl_event_interface.h" #include "dpctl_sycl_types.h" #include @@ -157,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_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..38266eb2f9 100644 --- a/libsyclinterface/tests/test_sycl_queue_interface.cpp +++ b/libsyclinterface/tests/test_sycl_queue_interface.cpp @@ -24,7 +24,7 @@ /// //===----------------------------------------------------------------------===// -#include "Support/CBindingWrapping.h" +#include "Config/dpctl_config.h" #include "dpctl_sycl_context_interface.h" #include "dpctl_sycl_device_interface.h" #include "dpctl_sycl_device_manager.h" @@ -32,15 +32,16 @@ #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 using namespace sycl; +using namespace dpctl::syclinterface; namespace { -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(queue, DPCTLSyclQueueRef); void error_handler_fn(int /*err*/) { @@ -348,16 +349,18 @@ 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) { 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; 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..680314b719 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,9 @@ namespace { constexpr size_t SIZE = 1024; static_assert(SIZE % 8 == 0); -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(void, DPCTLSyclUSMRef); + +using namespace dpctl::syclinterface; + } /* end of anonymous namespace */ struct TestQueueSubmit : public ::testing::Test @@ -93,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; @@ -104,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( @@ -153,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; @@ -165,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]; 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,