From edcc2ae65ebf7e26be431a0b34a7237a5b368c11 Mon Sep 17 00:00:00 2001 From: etotmeni Date: Tue, 2 Mar 2021 05:02:52 -0600 Subject: [PATCH 01/11] Add support of aspects --- .../include/dpctl_sycl_device_interface.h | 12 ++ dpctl-capi/include/dpctl_sycl_enum_types.h | 28 ++++ .../source/dpctl_sycl_device_interface.cpp | 12 ++ .../tests/test_sycl_device_interface.cpp | 128 +++++++++++++++++ dpctl/_backend.pxd | 25 ++++ dpctl/_sycl_device.pyx | 97 +++++++++++++ dpctl/tests/test_sycl_device.py | 133 ++++++++++++++++++ 7 files changed, 435 insertions(+) diff --git a/dpctl-capi/include/dpctl_sycl_device_interface.h b/dpctl-capi/include/dpctl_sycl_device_interface.h index 79d380d9eb..c7af18b759 100644 --- a/dpctl-capi/include/dpctl_sycl_device_interface.h +++ b/dpctl-capi/include/dpctl_sycl_device_interface.h @@ -251,4 +251,16 @@ bool DPCTLDevice_IsHostUnifiedMemory( DPCTL_API bool DPCTLDevice_AreEq(__dpctl_keep const DPCTLSyclDeviceRef DevRef1, __dpctl_keep const DPCTLSyclDeviceRef DevRef2); + +/*! + * @brief Checks if device has aspect. + * + * @param DRef Opaque pointer to a sycl::device + * @param AT DPCTLSyclAspectType of device::aspect. + * @return True if sycl::device has device::aspect, else false. + */ +DPCTL_API +bool DPCTLDevice_HasAspect(__dpctl_keep const DPCTLSyclDeviceRef DRef, + __dpctl_keep const DPCTLSyclAspectType AT); + DPCTL_C_EXTERN_C_END diff --git a/dpctl-capi/include/dpctl_sycl_enum_types.h b/dpctl-capi/include/dpctl_sycl_enum_types.h index 8b6b413394..61d4def4fd 100644 --- a/dpctl-capi/include/dpctl_sycl_enum_types.h +++ b/dpctl-capi/include/dpctl_sycl_enum_types.h @@ -92,4 +92,32 @@ typedef enum DPCTL_VOID_PTR } DPCTLKernelArgType; +/*! + * @brief DPCTL device has an associated set of aspects which identify + * characteristics of the device. + * + */ +enum DPCTLSyclAspectType +{ + cpu, + gpu, + accelerator, + custom, + emulated, + host_debuggable, + fp16, + fp64, + atomic64, + image, + online_compiler, + online_linker, + queue_profiling, + usm_device_allocations, + usm_host_allocations, + usm_atomic_host_allocations, + usm_shared_allocations, + usm_atomic_shared_allocations, + usm_system_allocations +}; + DPCTL_C_EXTERN_C_END diff --git a/dpctl-capi/source/dpctl_sycl_device_interface.cpp b/dpctl-capi/source/dpctl_sycl_device_interface.cpp index d534dd8d7a..1db9fc3299 100644 --- a/dpctl-capi/source/dpctl_sycl_device_interface.cpp +++ b/dpctl-capi/source/dpctl_sycl_device_interface.cpp @@ -395,3 +395,15 @@ bool DPCTLDevice_AreEq(__dpctl_keep const DPCTLSyclDeviceRef DevRef1, return false; return (*unwrap(DevRef1) == *unwrap(DevRef2)); } + +bool DPCTLDevice_HasAspect(__dpctl_keep const DPCTLSyclDeviceRef DRef, + __dpctl_keep const DPCTLSyclAspectType AT) +{ + auto D = unwrap(DRef); + if (!D) { + std::cerr << "Aspect does not exist\n"; + return false; + } + + return D->has(cl::sycl::aspect(AT)); +} diff --git a/dpctl-capi/tests/test_sycl_device_interface.cpp b/dpctl-capi/tests/test_sycl_device_interface.cpp index 65032446ba..1ab6c60ece 100644 --- a/dpctl-capi/tests/test_sycl_device_interface.cpp +++ b/dpctl-capi/tests/test_sycl_device_interface.cpp @@ -25,6 +25,7 @@ //===----------------------------------------------------------------------===// #include "dpctl_sycl_device_interface.h" +#include "dpctl_sycl_enum_types.h" #include "dpctl_sycl_queue_interface.h" #include "dpctl_sycl_queue_manager.h" #include "dpctl_utils.h" @@ -68,6 +69,42 @@ struct TestDPCTLSyclDeviceInterface : public ::testing::Test } }; +struct TestDPCTLSyclDeviceInterfaceAspects + : public ::testing::TestWithParam +{ + DPCTLSyclDeviceRef OpenCL_cpu = nullptr; + DPCTLSyclDeviceRef OpenCL_gpu = nullptr; + DPCTLSyclDeviceRef OpenCL_Level0_gpu = nullptr; + + TestDPCTLSyclDeviceInterfaceAspects() + { + if (DPCTLQueueMgr_GetNumQueues(DPCTL_OPENCL, DPCTL_CPU)) { + auto Q = DPCTLQueueMgr_GetQueue(DPCTL_OPENCL, DPCTL_CPU, 0); + OpenCL_cpu = DPCTLQueue_GetDevice(Q); + DPCTLQueue_Delete(Q); + } + + if (DPCTLQueueMgr_GetNumQueues(DPCTL_OPENCL, DPCTL_GPU)) { + auto Q = DPCTLQueueMgr_GetQueue(DPCTL_OPENCL, DPCTL_GPU, 0); + OpenCL_gpu = DPCTLQueue_GetDevice(Q); + DPCTLQueue_Delete(Q); + } + + if (DPCTLQueueMgr_GetNumQueues(DPCTL_LEVEL_ZERO, DPCTL_GPU)) { + auto Q = DPCTLQueueMgr_GetQueue(DPCTL_LEVEL_ZERO, DPCTL_GPU, 0); + OpenCL_Level0_gpu = DPCTLQueue_GetDevice(Q); + DPCTLQueue_Delete(Q); + } + } + + ~TestDPCTLSyclDeviceInterfaceAspects() + { + DPCTLDevice_Delete(OpenCL_cpu); + DPCTLDevice_Delete(OpenCL_gpu); + DPCTLDevice_Delete(OpenCL_Level0_gpu); + } +}; + TEST_F(TestDPCTLSyclDeviceInterface, CheckOCLCPU_GetDriverInfo) { if (!OpenCL_cpu) @@ -391,3 +428,94 @@ TEST_F(TestDPCTLSyclDeviceInterface, CheckLevel0GPU_IsGPU) EXPECT_TRUE(DPCTLDevice_IsGPU(OpenCL_Level0_gpu)); } + +TEST_P(TestDPCTLSyclDeviceInterfaceAspects, CheckOCLCPU_HasAspect) +{ + if (!OpenCL_cpu) + GTEST_SKIP_("Skipping as no OpenCL CPU device found."); + + DPCTLSyclAspectType GetAspect = GetParam(); + + if (GetAspect == emulated || + // GetAspect == image || + GetAspect == usm_device_allocations || + GetAspect == usm_host_allocations || + GetAspect == usm_atomic_host_allocations || + GetAspect == usm_shared_allocations || + GetAspect == usm_atomic_shared_allocations || + GetAspect == usm_system_allocations) + GTEST_SKIP_("This device aspect has not been implemented yet."); + + auto Aspect = DPCTLDevice_HasAspect(OpenCL_cpu, GetAspect); + auto D = reinterpret_cast(OpenCL_cpu); + auto HasAspect = D->has(cl::sycl::aspect(GetAspect)); + EXPECT_TRUE(Aspect == HasAspect); +} + +TEST_P(TestDPCTLSyclDeviceInterfaceAspects, CheckOCLGPU_HasAspect) +{ + if (!OpenCL_gpu) + GTEST_SKIP_("Skipping as no OpenCL CPU device found."); + + DPCTLSyclAspectType GetAspect = GetParam(); + + if (GetAspect == emulated || + // GetAspect == image || + GetAspect == usm_device_allocations || + GetAspect == usm_host_allocations || + GetAspect == usm_atomic_host_allocations || + GetAspect == usm_shared_allocations || + GetAspect == usm_atomic_shared_allocations || + GetAspect == usm_system_allocations) + GTEST_SKIP_("This device aspect has not been implemented yet."); + + auto Aspect = DPCTLDevice_HasAspect(OpenCL_gpu, GetAspect); + auto D = reinterpret_cast(OpenCL_gpu); + auto HasAspect = D->has(cl::sycl::aspect(GetAspect)); + EXPECT_TRUE(Aspect == HasAspect); +} + +TEST_P(TestDPCTLSyclDeviceInterfaceAspects, CheckLevel0GPU_HasAspect) +{ + if (!OpenCL_Level0_gpu) + GTEST_SKIP_("Skipping as no OpenCL CPU device found."); + + DPCTLSyclAspectType GetAspect = GetParam(); + + if (GetAspect == emulated || + // GetAspect == image || + GetAspect == usm_device_allocations || + GetAspect == usm_host_allocations || + GetAspect == usm_atomic_host_allocations || + GetAspect == usm_shared_allocations || + GetAspect == usm_atomic_shared_allocations || + GetAspect == usm_system_allocations) + GTEST_SKIP_("This device aspect has not been implemented yet."); + + auto Aspect = DPCTLDevice_HasAspect(OpenCL_Level0_gpu, GetAspect); + auto D = reinterpret_cast(OpenCL_Level0_gpu); + auto HasAspect = D->has(cl::sycl::aspect(GetAspect)); + EXPECT_TRUE(Aspect == HasAspect); +} + +INSTANTIATE_TEST_SUITE_P(DPCTLSyclDeviceInterfaceAspects, + TestDPCTLSyclDeviceInterfaceAspects, + ::testing::Values(cpu, + gpu, + accelerator, + custom, + emulated, + host_debuggable, + fp16, + fp64, + atomic64, + // image, + online_compiler, + online_linker, + queue_profiling, + usm_device_allocations, + usm_host_allocations, + usm_atomic_host_allocations, + usm_shared_allocations, + usm_atomic_shared_allocations, + usm_system_allocations)); diff --git a/dpctl/_backend.pxd b/dpctl/_backend.pxd index 23836cb545..67c4043c86 100644 --- a/dpctl/_backend.pxd +++ b/dpctl/_backend.pxd @@ -68,6 +68,29 @@ cdef extern from "dpctl_sycl_enum_types.h": ctypedef _arg_data_type DPCTLKernelArgType + cdef enum _aspect_type 'DPCTLSyclAspectType': + _cpu 'cpu', + _gpu 'gpu', + _accelerator 'accelerator', + _custom 'custom', + _emulated 'emulated', + _host_debuggable 'host_debuggable', + _fp16 'fp16', + _fp64 'fp64', + _atomic64 'atomic64', + _image 'image', + _online_compiler 'online_compiler', + _online_linker 'online_linker', + _queue_profiling 'queue_profiling', + _usm_device_allocations 'usm_device_allocations', + _usm_host_allocations 'usm_host_allocations', + _usm_atomic_host_allocations 'usm_atomic_host_allocations', + _usm_shared_allocations 'usm_shared_allocations', + _usm_atomic_shared_allocations 'usm_atomic_shared_allocations', + _usm_system_allocations 'usm_system_allocations' + + ctypedef _aspect_type DPCTLSyclAspectType + cdef extern from "dpctl_sycl_types.h": cdef struct DPCTLOpaqueSyclContext @@ -113,6 +136,8 @@ cdef extern from "dpctl_sycl_device_interface.h": cpdef bool DPCTLDevice_HasInt64BaseAtomics(const DPCTLSyclDeviceRef DRef) cpdef bool DPCTLDevice_HasInt64ExtendedAtomics( const DPCTLSyclDeviceRef DRef) + cpdef bool DPCTLDevice_HasAspect( + const DPCTLSyclDeviceRef DRef, const DPCTLSyclAspectType AT) cdef extern from "dpctl_sycl_device_selector_interface.h": diff --git a/dpctl/_sycl_device.pyx b/dpctl/_sycl_device.pyx index 1aed50e76a..a867bfc074 100644 --- a/dpctl/_sycl_device.pyx +++ b/dpctl/_sycl_device.pyx @@ -21,6 +21,7 @@ """ from ._backend cimport ( + _aspect_type, DPCTLAcceleratorSelector_Create, DPCTLCPUSelector_Create, DPCTLDefaultSelector_Create, @@ -50,6 +51,7 @@ from ._backend cimport ( DPCTLSize_t_Array_Delete, DPCTLSyclDeviceRef, DPCTLSyclDeviceSelectorRef, + DPCTLDevice_HasAspect ) from . import device_type @@ -344,6 +346,101 @@ cdef class SyclDevice(_SyclDevice): "a SYCL filter selector string." ) + @property + def aspect_cpu(self): + cdef _aspect_type AT = _aspect_type._cpu + return DPCTLDevice_HasAspect(self._device_ref, AT) + + @property + def aspect_gpu(self): + cdef _aspect_type AT = _aspect_type._gpu + return DPCTLDevice_HasAspect(self._device_ref, AT) + + @property + def aspect_accelerator(self): + cdef _aspect_type AT = _aspect_type._accelerator + return DPCTLDevice_HasAspect(self._device_ref, AT) + + @property + def aspect_custom(self): + cdef _aspect_type AT = _aspect_type._custom + return DPCTLDevice_HasAspect(self._device_ref, AT) + + @property + def aspect_emulated(self): + cdef _aspect_type AT = _aspect_type._emulated + return DPCTLDevice_HasAspect(self._device_ref, AT) + + @property + def aspect_host_debuggable(self): + cdef _aspect_type AT = _aspect_type._host_debuggable + return DPCTLDevice_HasAspect(self._device_ref, AT) + + @property + def aspect_fp16(self): + cdef _aspect_type AT = _aspect_type._fp16 + return DPCTLDevice_HasAspect(self._device_ref, AT) + + @property + def aspect_fp64(self): + cdef _aspect_type AT = _aspect_type._fp64 + return DPCTLDevice_HasAspect(self._device_ref, AT) + + @property + def aspect_atomic64(self): + cdef _aspect_type AT = _aspect_type._atomic64 + return DPCTLDevice_HasAspect(self._device_ref, AT) + + @property + def aspect_image(self): + cdef _aspect_type AT = _aspect_type._image + return DPCTLDevice_HasAspect(self._device_ref, AT) + + @property + def aspect_online_compiler(self): + cdef _aspect_type AT = _aspect_type._online_compiler + return DPCTLDevice_HasAspect(self._device_ref, AT) + + @property + def aspect_online_linker(self): + cdef _aspect_type AT = _aspect_type._online_linker + return DPCTLDevice_HasAspect(self._device_ref, AT) + + @property + def aspect_queue_profiling(self): + cdef _aspect_type AT = _aspect_type._queue_profiling + return DPCTLDevice_HasAspect(self._device_ref, AT) + + @property + def aspect_usm_device_allocations(self): + cdef _aspect_type AT = _aspect_type._usm_device_allocations + return DPCTLDevice_HasAspect(self._device_ref, AT) + + @property + def aspect_usm_host_allocations(self): + cdef _aspect_type AT = _aspect_type._usm_host_allocations + return DPCTLDevice_HasAspect(self._device_ref, AT) + + @property + def aspect_usm_atomic_host_allocations(self): + cdef _aspect_type AT = _aspect_type._usm_atomic_host_allocations + return DPCTLDevice_HasAspect(self._device_ref, AT) + + @property + def aspect_usm_shared_allocations(self): + cdef _aspect_type AT = _aspect_type._usm_shared_allocations + return DPCTLDevice_HasAspect(self._device_ref, AT) + + @property + def aspect_usm_atomic_shared_allocations(self): + cdef _aspect_type AT = _aspect_type._usm_atomic_shared_allocations + return DPCTLDevice_HasAspect(self._device_ref, AT) + + @property + def aspect_usm_system_allocations(self): + cdef _aspect_type AT = _aspect_type._usm_system_allocations + return DPCTLDevice_HasAspect(self._device_ref, AT) + @property def __name__(self): return "SyclDevice" diff --git a/dpctl/tests/test_sycl_device.py b/dpctl/tests/test_sycl_device.py index 23f79d222b..ad15356a99 100644 --- a/dpctl/tests/test_sycl_device.py +++ b/dpctl/tests/test_sycl_device.py @@ -100,6 +100,139 @@ def check_has_int64_extended_atomics(device): pytest.fail("has_int64_extended_atomics call failed") +def check_has_aspect_cpu(device): + try: + device.aspect_cpu() + except Exception: + pytest.fail("aspect_cpu call failed") + + +def check_has_aspect_gpu(device): + try: + device.aspect_gpu() + except Exception: + pytest.fail("aspect_gpu call failed") + + +def check_has_aspect_accelerator(device): + try: + device.aspect_accelerator() + except Exception: + pytest.fail("aspect_accelerator call failed") + + +def check_has_aspect_custom(device): + try: + device.aspect_custom() + except Exception: + pytest.fail("aspect_custom call failed") + + +def check_has_aspect_emulated(device): + try: + device.aspect_emulated() + except Exception: + pytest.fail("aspect_emulated call failed") + + +def check_has_aspect_host_debuggable(device): + try: + device.aspect_host_debuggable() + except Exception: + pytest.fail("aspect_host_debuggable call failed") + + +def check_has_aspect_fp16(device): + try: + device.aspect_fp16() + except Exception: + pytest.fail("aspect_fp16 call failed") + + +def check_has_aspect_fp64(device): + try: + device.aspect_fp64() + except Exception: + pytest.fail("aspect_fp64 call failed") + + +def check_has_aspect_atomic64(device): + try: + device.aspect_atomic64() + except Exception: + pytest.fail("aspect_atomic64 call failed") + + +def check_has_aspect_image(device): + try: + device.aspect_image() + except Exception: + pytest.fail("aspect_image call failed") + + +def check_has_aspect_online_compiler(device): + try: + device.aspect_online_compiler() + except Exception: + pytest.fail("aspect_online_compiler call failed") + + +def check_has_aspect_online_linker(device): + try: + device.aspect_online_linker() + except Exception: + pytest.fail("aspect_online_linker call failed") + + +def check_has_aspect_queue_profiling(device): + try: + device.aspect_queue_profiling() + except Exception: + pytest.fail("aspect_queue_profiling call failed") + + +def check_has_aspect_usm_device_allocations(device): + try: + device.aspect_usm_device_allocations() + except Exception: + pytest.fail("aspect_usm_device_allocations call failed") + + +def check_has_aspect_usm_host_allocations(device): + try: + device.aspect_usm_host_allocations() + except Exception: + pytest.fail("aspect_usm_host_allocations call failed") + + +def check_has_aspect_usm_atomic_host_allocations(device): + try: + device.aspect_usm_atomic_host_allocations() + except Exception: + pytest.fail("aspect_usm_atomic_host_allocations call failed") + + +def check_has_aspect_usm_shared_allocations(device): + try: + device.aspect_usm_shared_allocations() + except Exception: + pytest.fail("aspect_usm_shared_allocations call failed") + + +def check_has_aspect_usm_atomic_shared_allocations(device): + try: + device.aspect_usm_atomic_shared_allocations() + except Exception: + pytest.fail("aspect_usm_atomic_shared_allocations call failed") + + +def check_has_aspect_usm_system_allocations(device): + try: + device.aspect_usm_system_allocations() + except Exception: + pytest.fail("aspect_usm_system_allocations call failed") + + def check_is_accelerator(device): try: device.is_accelerator() From 964921e0d89f056caacfc9e5f11860249b859635 Mon Sep 17 00:00:00 2001 From: etotmeni Date: Tue, 2 Mar 2021 07:58:41 -0600 Subject: [PATCH 02/11] Small fix --- dpctl/_sycl_device.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dpctl/_sycl_device.pyx b/dpctl/_sycl_device.pyx index 275aef5877..84323f2bfb 100644 --- a/dpctl/_sycl_device.pyx +++ b/dpctl/_sycl_device.pyx @@ -56,7 +56,7 @@ from ._backend cimport ( DPCTLSyclBackendType, DPCTLSyclDeviceRef, DPCTLSyclDeviceSelectorRef, - DPCTLDevice_HasAspect + DPCTLDevice_HasAspect, DPCTLSyclDeviceType, ) from . import backend_type, device_type From 52aacbb61516693933aa76fa764ce937738b3177 Mon Sep 17 00:00:00 2001 From: etotmeni Date: Wed, 3 Mar 2021 04:19:13 -0600 Subject: [PATCH 03/11] Fix c api aspects --- .../source/dpctl_sycl_device_interface.cpp | 14 +- dpctl-capi/tests/test_sycl_device_aspects.cpp | 150 ++++++++++++++++++ .../tests/test_sycl_device_interface.cpp | 130 --------------- 3 files changed, 159 insertions(+), 135 deletions(-) create mode 100644 dpctl-capi/tests/test_sycl_device_aspects.cpp diff --git a/dpctl-capi/source/dpctl_sycl_device_interface.cpp b/dpctl-capi/source/dpctl_sycl_device_interface.cpp index 0a23d98cd9..35e0e934cc 100644 --- a/dpctl-capi/source/dpctl_sycl_device_interface.cpp +++ b/dpctl-capi/source/dpctl_sycl_device_interface.cpp @@ -444,11 +444,15 @@ bool DPCTLDevice_AreEq(__dpctl_keep const DPCTLSyclDeviceRef DevRef1, bool DPCTLDevice_HasAspect(__dpctl_keep const DPCTLSyclDeviceRef DRef, __dpctl_keep const DPCTLSyclAspectType AT) { + bool hasAspect = false; auto D = unwrap(DRef); - if (!D) { - std::cerr << "Aspect does not exist\n"; - return false; + if (D) { + try { + hasAspect = D->has(cl::sycl::aspect(AT)); + } catch (runtime_error const &re) { + // \todo log error + std::cerr << re.what() << '\n'; + } } - - return D->has(cl::sycl::aspect(AT)); + return hasAspect; } diff --git a/dpctl-capi/tests/test_sycl_device_aspects.cpp b/dpctl-capi/tests/test_sycl_device_aspects.cpp new file mode 100644 index 0000000000..ebe78a83ff --- /dev/null +++ b/dpctl-capi/tests/test_sycl_device_aspects.cpp @@ -0,0 +1,150 @@ +#include "Support/CBindingWrapping.h" +#include "dpctl_sycl_device_interface.h" +#include "dpctl_sycl_device_selector_interface.h" +#include "dpctl_sycl_enum_types.h" +#include +#include +#include + +namespace +{ +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(sycl::device, DPCTLSyclDeviceRef); + +template struct are_same : std::true_type +{ +}; + +template struct are_same : std::true_type +{ +}; + +template +struct are_same + : std::integral_constant::value && + are_same::value)> +{ +}; + +template ::value>::type * = nullptr> +constexpr auto get_param_list(Ts... args) +{ + std::array params{{args...}}; + return params; +} + +template +constexpr auto build_param_pairs(const std::array &arr1, + const std::array &arr2) +{ + std::array, S1 * S2> paramPairs; + auto n = 0ul; + + for (auto &p1 : arr1) { + for (auto &p2 : arr2) { + paramPairs[n] = {p1, p2}; + ++n; + } + } + + return paramPairs; +} + +template +auto build_gtest_values_impl(const PArr &arr, std::index_sequence) +{ + return ::testing::Values(arr[I]...); +} + +template > +auto build_gtest_values(const std::array, N> ¶ms) +{ + return build_gtest_values_impl(params, Indices()); +} + +auto build_params() +{ + constexpr auto param_1 = get_param_list( + "opencl:gpu", "opencl:cpu", "level_zero:gpu", "host"); + constexpr auto param_2 = get_param_list( + cpu, gpu, accelerator, custom, emulated, host_debuggable, fp16, fp64, + atomic64, online_compiler, online_linker, queue_profiling, + usm_device_allocations, usm_host_allocations, + usm_atomic_host_allocations, usm_shared_allocations, + usm_atomic_shared_allocations, usm_system_allocations); + + auto pairs = + build_param_pairs(param_1, param_2); + + return build_gtest_values(pairs); +} + +} // namespace + +struct TestDPCTLSyclDeviceInterfaceAspects + : public ::testing::TestWithParam< + std::pair> +{ + DPCTLSyclDeviceSelectorRef DSRef = nullptr; + + TestDPCTLSyclDeviceInterfaceAspects() + { + auto params = GetParam(); + auto filterstr = params.first; + EXPECT_NO_FATAL_FAILURE(DSRef = DPCTLFilterSelector_Create(filterstr)); + } + + void SetUp() + { + if (!DSRef) { + auto message = "Skipping as no device of type " + + std::string(GetParam().first) + "."; + GTEST_SKIP_(message.c_str()); + } + auto aspectTy = GetParam().second; + if (aspectTy == emulated || aspectTy == usm_device_allocations || + aspectTy == usm_host_allocations || + aspectTy == usm_atomic_host_allocations || + aspectTy == usm_shared_allocations || + aspectTy == usm_atomic_shared_allocations || + aspectTy == usm_system_allocations) + { + GTEST_SKIP_("This device aspect has not been implemented yet."); + } + } + + ~TestDPCTLSyclDeviceInterfaceAspects() + { + EXPECT_NO_FATAL_FAILURE(DPCTLDeviceSelector_Delete(DSRef)); + } +}; + +TEST_P(TestDPCTLSyclDeviceInterfaceAspects, Chk_HasAspect) +{ + + bool expected = false, actual = false; + auto aspectTy = GetParam().second; + DPCTLSyclDeviceRef DRef = nullptr; + EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef)); + if (!DRef) + GTEST_SKIP_("Device not found"); + EXPECT_NO_FATAL_FAILURE(expected = DPCTLDevice_HasAspect(DRef, aspectTy)); + auto D = unwrap(DRef); + try { + actual = D->has(cl::sycl::aspect(aspectTy)); + } catch (...) { + GTEST_SKIP_("Aspect not supported"); + } + EXPECT_TRUE(expected == actual); + EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef)); +} + +INSTANTIATE_TEST_SUITE_P(DPCTLSyclDeviceInterfaceAspects, + TestDPCTLSyclDeviceInterfaceAspects, + build_params()); diff --git a/dpctl-capi/tests/test_sycl_device_interface.cpp b/dpctl-capi/tests/test_sycl_device_interface.cpp index 42ece381d5..9478bcaa02 100644 --- a/dpctl-capi/tests/test_sycl_device_interface.cpp +++ b/dpctl-capi/tests/test_sycl_device_interface.cpp @@ -26,10 +26,7 @@ #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_queue_interface.h" -#include "dpctl_sycl_queue_manager.h" #include "dpctl_utils.h" #include #include @@ -61,42 +58,6 @@ struct TestDPCTLSyclDeviceInterface } }; -struct TestDPCTLSyclDeviceInterfaceAspects - : public ::testing::TestWithParam -{ - DPCTLSyclDeviceRef OpenCL_cpu = nullptr; - DPCTLSyclDeviceRef OpenCL_gpu = nullptr; - DPCTLSyclDeviceRef OpenCL_Level0_gpu = nullptr; - - TestDPCTLSyclDeviceInterfaceAspects() - { - if (DPCTLQueueMgr_GetNumQueues(DPCTL_OPENCL, DPCTL_CPU)) { - auto Q = DPCTLQueueMgr_GetQueue(DPCTL_OPENCL, DPCTL_CPU, 0); - OpenCL_cpu = DPCTLQueue_GetDevice(Q); - DPCTLQueue_Delete(Q); - } - - if (DPCTLQueueMgr_GetNumQueues(DPCTL_OPENCL, DPCTL_GPU)) { - auto Q = DPCTLQueueMgr_GetQueue(DPCTL_OPENCL, DPCTL_GPU, 0); - OpenCL_gpu = DPCTLQueue_GetDevice(Q); - DPCTLQueue_Delete(Q); - } - - if (DPCTLQueueMgr_GetNumQueues(DPCTL_LEVEL_ZERO, DPCTL_GPU)) { - auto Q = DPCTLQueueMgr_GetQueue(DPCTL_LEVEL_ZERO, DPCTL_GPU, 0); - OpenCL_Level0_gpu = DPCTLQueue_GetDevice(Q); - DPCTLQueue_Delete(Q); - } - } - - ~TestDPCTLSyclDeviceInterfaceAspects() - { - DPCTLDevice_Delete(OpenCL_cpu); - DPCTLDevice_Delete(OpenCL_gpu); - DPCTLDevice_Delete(OpenCL_Level0_gpu); - } -}; - TEST_P(TestDPCTLSyclDeviceInterface, Chk_GetBackend) { DPCTLSyclDeviceRef DRef = nullptr; @@ -340,94 +301,3 @@ INSTANTIATE_TEST_SUITE_P(DPCTLDevice_Fns, "gpu:0", "gpu:1", "1")); - -TEST_P(TestDPCTLSyclDeviceInterfaceAspects, CheckOCLCPU_HasAspect) -{ - if (!OpenCL_cpu) - GTEST_SKIP_("Skipping as no OpenCL CPU device found."); - - DPCTLSyclAspectType GetAspect = GetParam(); - - if (GetAspect == emulated || - // GetAspect == image || - GetAspect == usm_device_allocations || - GetAspect == usm_host_allocations || - GetAspect == usm_atomic_host_allocations || - GetAspect == usm_shared_allocations || - GetAspect == usm_atomic_shared_allocations || - GetAspect == usm_system_allocations) - GTEST_SKIP_("This device aspect has not been implemented yet."); - - auto Aspect = DPCTLDevice_HasAspect(OpenCL_cpu, GetAspect); - auto D = reinterpret_cast(OpenCL_cpu); - auto HasAspect = D->has(cl::sycl::aspect(GetAspect)); - EXPECT_TRUE(Aspect == HasAspect); -} - -TEST_P(TestDPCTLSyclDeviceInterfaceAspects, CheckOCLGPU_HasAspect) -{ - if (!OpenCL_gpu) - GTEST_SKIP_("Skipping as no OpenCL CPU device found."); - - DPCTLSyclAspectType GetAspect = GetParam(); - - if (GetAspect == emulated || - // GetAspect == image || - GetAspect == usm_device_allocations || - GetAspect == usm_host_allocations || - GetAspect == usm_atomic_host_allocations || - GetAspect == usm_shared_allocations || - GetAspect == usm_atomic_shared_allocations || - GetAspect == usm_system_allocations) - GTEST_SKIP_("This device aspect has not been implemented yet."); - - auto Aspect = DPCTLDevice_HasAspect(OpenCL_gpu, GetAspect); - auto D = reinterpret_cast(OpenCL_gpu); - auto HasAspect = D->has(cl::sycl::aspect(GetAspect)); - EXPECT_TRUE(Aspect == HasAspect); -} - -TEST_P(TestDPCTLSyclDeviceInterfaceAspects, CheckLevel0GPU_HasAspect) -{ - if (!OpenCL_Level0_gpu) - GTEST_SKIP_("Skipping as no OpenCL CPU device found."); - - DPCTLSyclAspectType GetAspect = GetParam(); - - if (GetAspect == emulated || - // GetAspect == image || - GetAspect == usm_device_allocations || - GetAspect == usm_host_allocations || - GetAspect == usm_atomic_host_allocations || - GetAspect == usm_shared_allocations || - GetAspect == usm_atomic_shared_allocations || - GetAspect == usm_system_allocations) - GTEST_SKIP_("This device aspect has not been implemented yet."); - - auto Aspect = DPCTLDevice_HasAspect(OpenCL_Level0_gpu, GetAspect); - auto D = reinterpret_cast(OpenCL_Level0_gpu); - auto HasAspect = D->has(cl::sycl::aspect(GetAspect)); - EXPECT_TRUE(Aspect == HasAspect); -} - -INSTANTIATE_TEST_SUITE_P(DPCTLSyclDeviceInterfaceAspects, - TestDPCTLSyclDeviceInterfaceAspects, - ::testing::Values(cpu, - gpu, - accelerator, - custom, - emulated, - host_debuggable, - fp16, - fp64, - atomic64, - // image, - online_compiler, - online_linker, - queue_profiling, - usm_device_allocations, - usm_host_allocations, - usm_atomic_host_allocations, - usm_shared_allocations, - usm_atomic_shared_allocations, - usm_system_allocations)); From df7fdab15ead42a55366867bb7c9a06ddd61e725 Mon Sep 17 00:00:00 2001 From: etotmeni Date: Wed, 3 Mar 2021 04:31:23 -0600 Subject: [PATCH 04/11] Del old atomics funcs --- .../include/dpctl_sycl_device_interface.h | 23 -------------- .../source/dpctl_sycl_device_interface.cpp | 31 ------------------- .../tests/test_sycl_device_interface.cpp | 31 ------------------- dpctl/_backend.pxd | 2 -- dpctl/_sycl_device.pxd | 2 -- dpctl/_sycl_device.pyx | 18 ----------- dpctl/tests/test_sycl_device.py | 14 --------- 7 files changed, 121 deletions(-) diff --git a/dpctl-capi/include/dpctl_sycl_device_interface.h b/dpctl-capi/include/dpctl_sycl_device_interface.h index a073eb8270..2882e69b24 100644 --- a/dpctl-capi/include/dpctl_sycl_device_interface.h +++ b/dpctl-capi/include/dpctl_sycl_device_interface.h @@ -218,29 +218,6 @@ DPCTL_API __dpctl_give DPCTLSyclPlatformRef DPCTLDevice_GetPlatform(__dpctl_keep const DPCTLSyclDeviceRef DRef); -/*! - * @brief Wrapper over - * device.get_info. - * - * @param DRef Opaque pointer to a sycl::device - * @return Returns true if device has int64_base_atomics else returns false. - */ -DPCTL_API -bool DPCTLDevice_HasInt64BaseAtomics( - __dpctl_keep const DPCTLSyclDeviceRef DRef); - -/*! - * @brief Wrapper over - * device.get_info. - * - * @param DRef Opaque pointer to a sycl::device - * @return Returns true if device has int64_extended_atomics else returns - * false. - */ -DPCTL_API -bool DPCTLDevice_HasInt64ExtendedAtomics( - __dpctl_keep const DPCTLSyclDeviceRef DRef); - /*! * @brief Returns a C string for the device name. * diff --git a/dpctl-capi/source/dpctl_sycl_device_interface.cpp b/dpctl-capi/source/dpctl_sycl_device_interface.cpp index 35e0e934cc..a03bc7683a 100644 --- a/dpctl-capi/source/dpctl_sycl_device_interface.cpp +++ b/dpctl-capi/source/dpctl_sycl_device_interface.cpp @@ -308,37 +308,6 @@ DPCTLDevice_GetPlatform(__dpctl_keep const DPCTLSyclDeviceRef DRef) return PRef; } -bool DPCTLDevice_HasInt64BaseAtomics(__dpctl_keep const DPCTLSyclDeviceRef DRef) -{ - bool hasBaseAtomics = false; - auto D = unwrap(DRef); - if (D) { - try { - hasBaseAtomics = D->has(aspect::int64_base_atomics); - } catch (runtime_error const &re) { - // \todo log error - std::cerr << re.what() << '\n'; - } - } - return hasBaseAtomics; -} - -bool DPCTLDevice_HasInt64ExtendedAtomics( - __dpctl_keep const DPCTLSyclDeviceRef DRef) -{ - bool hasExtendedAtomics = false; - auto D = unwrap(DRef); - if (D) { - try { - hasExtendedAtomics = D->has(aspect::int64_extended_atomics); - } catch (runtime_error const &re) { - // \todo log error - std::cerr << re.what() << '\n'; - } - } - return hasExtendedAtomics; -} - __dpctl_give const char * DPCTLDevice_GetName(__dpctl_keep const DPCTLSyclDeviceRef DRef) { diff --git a/dpctl-capi/tests/test_sycl_device_interface.cpp b/dpctl-capi/tests/test_sycl_device_interface.cpp index 9478bcaa02..97483d1ce6 100644 --- a/dpctl-capi/tests/test_sycl_device_interface.cpp +++ b/dpctl-capi/tests/test_sycl_device_interface.cpp @@ -215,37 +215,6 @@ TEST_P(TestDPCTLSyclDeviceInterface, Chk_GetPlatform) EXPECT_NO_FATAL_FAILURE(DPCTLPlatform_Delete(PRef)); } -// TODO: Update when DPC++ properly supports aspects -TEST_P(TestDPCTLSyclDeviceInterface, Chk_HasInt64BaseAtomics) -{ - DPCTLSyclDeviceRef DRef = nullptr; - bool atomics = 0; - EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef)); - if (!DRef) - GTEST_SKIP_("Device not found"); - EXPECT_NO_FATAL_FAILURE(atomics = DPCTLDevice_HasInt64BaseAtomics(DRef)); - auto D = reinterpret_cast(DRef); - auto has_atomics = D->has(aspect::int64_base_atomics); - EXPECT_TRUE(has_atomics == atomics); - EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef)); -} - -// TODO: Update when DPC++ properly supports aspects -TEST_P(TestDPCTLSyclDeviceInterface, Chk_HasInt64ExtendedAtomics) -{ - DPCTLSyclDeviceRef DRef = nullptr; - bool atomics = 0; - EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef)); - if (!DRef) - GTEST_SKIP_("Device not found"); - EXPECT_NO_FATAL_FAILURE(atomics = - DPCTLDevice_HasInt64ExtendedAtomics(DRef)); - auto D = reinterpret_cast(DRef); - auto has_atomics = D->has(aspect::int64_extended_atomics); - EXPECT_TRUE(has_atomics == atomics); - EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef)); -} - TEST_P(TestDPCTLSyclDeviceInterface, Chk_IsAccelerator) { DPCTLSyclDeviceRef DRef = nullptr; diff --git a/dpctl/_backend.pxd b/dpctl/_backend.pxd index 41015f4ac0..3c3d00098e 100644 --- a/dpctl/_backend.pxd +++ b/dpctl/_backend.pxd @@ -142,8 +142,6 @@ cdef extern from "dpctl_sycl_device_interface.h": cdef DPCTLSyclPlatformRef DPCTLDevice_GetPlatform( const DPCTLSyclDeviceRef DRef) cdef const char *DPCTLDevice_GetVendorName(const DPCTLSyclDeviceRef DRef) - cdef bool DPCTLDevice_HasInt64BaseAtomics(const DPCTLSyclDeviceRef DRef) - cdef bool DPCTLDevice_HasInt64ExtendedAtomics(const DPCTLSyclDeviceRef DRef) cdef bool DPCTLDevice_IsAccelerator(const DPCTLSyclDeviceRef DRef) cdef bool DPCTLDevice_IsCPU(const DPCTLSyclDeviceRef DRef) cdef bool DPCTLDevice_IsGPU(const DPCTLSyclDeviceRef DRef) diff --git a/dpctl/_sycl_device.pxd b/dpctl/_sycl_device.pxd index 2e0c76a296..f71cdbb717 100644 --- a/dpctl/_sycl_device.pxd +++ b/dpctl/_sycl_device.pxd @@ -57,8 +57,6 @@ cdef class _SyclDevice: cpdef get_max_work_item_sizes(self) cpdef get_max_work_group_size(self) cpdef get_max_num_sub_groups(self) - cpdef has_int64_base_atomics(self) - cpdef has_int64_extended_atomics(self) cpdef is_accelerator(self) cpdef is_cpu(self) cpdef is_gpu(self) diff --git a/dpctl/_sycl_device.pyx b/dpctl/_sycl_device.pyx index 84323f2bfb..159fab194b 100644 --- a/dpctl/_sycl_device.pyx +++ b/dpctl/_sycl_device.pyx @@ -42,8 +42,6 @@ from ._backend cimport ( DPCTLDevice_GetMaxWorkItemSizes, DPCTLDevice_GetVendorName, DPCTLDevice_GetName, - DPCTLDevice_HasInt64BaseAtomics, - DPCTLDevice_HasInt64ExtendedAtomics, DPCTLDevice_IsAccelerator, DPCTLDevice_IsCPU, DPCTLDevice_IsGPU, @@ -160,16 +158,6 @@ cdef class _SyclDevice: """ return self._driver_version.decode() - cpdef has_int64_base_atomics(self): - """ Returns true if device has int64_base_atomics else returns false. - """ - return self._int64_base_atomics - - cpdef has_int64_extended_atomics(self): - """ Returns true if device has int64_extended_atomics else returns false. - """ - return self._int64_extended_atomics - cpdef get_max_compute_units(self): """ Returns the number of parallel compute units available to the device. The minimum value is 1. @@ -313,10 +301,6 @@ cdef class SyclDevice(_SyclDevice): device._device_ref = DRef device._device_name = DPCTLDevice_GetName(DRef) device._driver_version = DPCTLDevice_GetDriverInfo(DRef) - device._int64_base_atomics = DPCTLDevice_HasInt64BaseAtomics(DRef) - device._int64_extended_atomics = ( - DPCTLDevice_HasInt64ExtendedAtomics(DRef) - ) device._max_compute_units = DPCTLDevice_GetMaxComputeUnits(DRef) device._max_num_sub_groups = DPCTLDevice_GetMaxNumSubGroups(DRef) device._max_work_group_size = DPCTLDevice_GetMaxWorkGroupSize(DRef) @@ -339,8 +323,6 @@ cdef class SyclDevice(_SyclDevice): self._device_ref = DPCTLDevice_Copy(other._device_ref) self._device_name = DPCTLDevice_GetName(self._device_ref) self._driver_version = DPCTLDevice_GetDriverInfo(self._device_ref) - self._int64_base_atomics = other._int64_base_atomics - self._int64_extended_atomics = other._int64_extended_atomics self._max_compute_units = other._max_compute_units self._max_num_sub_groups = other._max_num_sub_groups self._max_work_group_size = other._max_work_group_size diff --git a/dpctl/tests/test_sycl_device.py b/dpctl/tests/test_sycl_device.py index 2d4e762849..27d867b238 100644 --- a/dpctl/tests/test_sycl_device.py +++ b/dpctl/tests/test_sycl_device.py @@ -86,20 +86,6 @@ def check_get_max_num_sub_groups(device): assert max_num_sub_groups > 0 -def check_has_int64_base_atomics(device): - try: - device.has_int64_base_atomics() - except Exception: - pytest.fail("has_int64_base_atomics call failed") - - -def check_has_int64_extended_atomics(device): - try: - device.has_int64_extended_atomics() - except Exception: - pytest.fail("has_int64_extended_atomics call failed") - - def check_has_aspect_cpu(device): try: device.aspect_cpu() From 65812569b26e1faff8586c8010c67a2f8d3a0608 Mon Sep 17 00:00:00 2001 From: etotmeni Date: Wed, 3 Mar 2021 05:28:13 -0600 Subject: [PATCH 05/11] Fix aspect pytest --- dpctl/tests/test_sycl_device.py | 59 +++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 21 deletions(-) diff --git a/dpctl/tests/test_sycl_device.py b/dpctl/tests/test_sycl_device.py index 27d867b238..ff5479b839 100644 --- a/dpctl/tests/test_sycl_device.py +++ b/dpctl/tests/test_sycl_device.py @@ -88,133 +88,133 @@ def check_get_max_num_sub_groups(device): def check_has_aspect_cpu(device): try: - device.aspect_cpu() + device.aspect_cpu except Exception: pytest.fail("aspect_cpu call failed") def check_has_aspect_gpu(device): try: - device.aspect_gpu() + device.aspect_gpu except Exception: pytest.fail("aspect_gpu call failed") def check_has_aspect_accelerator(device): try: - device.aspect_accelerator() + device.aspect_accelerator except Exception: pytest.fail("aspect_accelerator call failed") def check_has_aspect_custom(device): try: - device.aspect_custom() + device.aspect_custom except Exception: pytest.fail("aspect_custom call failed") def check_has_aspect_emulated(device): try: - device.aspect_emulated() + device.aspect_emulated except Exception: pytest.fail("aspect_emulated call failed") def check_has_aspect_host_debuggable(device): try: - device.aspect_host_debuggable() + device.aspect_host_debuggable except Exception: pytest.fail("aspect_host_debuggable call failed") def check_has_aspect_fp16(device): try: - device.aspect_fp16() + device.aspect_fp16 except Exception: pytest.fail("aspect_fp16 call failed") def check_has_aspect_fp64(device): try: - device.aspect_fp64() + device.aspect_fp64 except Exception: pytest.fail("aspect_fp64 call failed") def check_has_aspect_atomic64(device): try: - device.aspect_atomic64() + device.aspect_atomic64 except Exception: pytest.fail("aspect_atomic64 call failed") def check_has_aspect_image(device): try: - device.aspect_image() + device.aspect_image except Exception: pytest.fail("aspect_image call failed") def check_has_aspect_online_compiler(device): try: - device.aspect_online_compiler() + device.aspect_online_compiler except Exception: pytest.fail("aspect_online_compiler call failed") def check_has_aspect_online_linker(device): try: - device.aspect_online_linker() + device.aspect_online_linker except Exception: pytest.fail("aspect_online_linker call failed") def check_has_aspect_queue_profiling(device): try: - device.aspect_queue_profiling() + device.aspect_queue_profiling except Exception: pytest.fail("aspect_queue_profiling call failed") def check_has_aspect_usm_device_allocations(device): try: - device.aspect_usm_device_allocations() + device.aspect_usm_device_allocations except Exception: pytest.fail("aspect_usm_device_allocations call failed") def check_has_aspect_usm_host_allocations(device): try: - device.aspect_usm_host_allocations() + device.aspect_usm_host_allocations except Exception: pytest.fail("aspect_usm_host_allocations call failed") def check_has_aspect_usm_atomic_host_allocations(device): try: - device.aspect_usm_atomic_host_allocations() + device.aspect_usm_atomic_host_allocations except Exception: pytest.fail("aspect_usm_atomic_host_allocations call failed") def check_has_aspect_usm_shared_allocations(device): try: - device.aspect_usm_shared_allocations() + device.aspect_usm_shared_allocations except Exception: pytest.fail("aspect_usm_shared_allocations call failed") def check_has_aspect_usm_atomic_shared_allocations(device): try: - device.aspect_usm_atomic_shared_allocations() + device.aspect_usm_atomic_shared_allocations except Exception: pytest.fail("aspect_usm_atomic_shared_allocations call failed") def check_has_aspect_usm_system_allocations(device): try: - device.aspect_usm_system_allocations() + device.aspect_usm_system_allocations except Exception: pytest.fail("aspect_usm_system_allocations call failed") @@ -253,12 +253,29 @@ def check_is_host(device): check_get_max_work_item_sizes, check_get_max_work_group_size, check_get_max_num_sub_groups, - check_has_int64_base_atomics, - check_has_int64_extended_atomics, check_is_accelerator, check_is_cpu, check_is_gpu, check_is_host, + check_has_aspect_cpu, + check_has_aspect_gpu, + check_has_aspect_accelerator, + check_has_aspect_custom, + check_has_aspect_emulated, + check_has_aspect_host_debuggable, + check_has_aspect_fp16, + check_has_aspect_fp64, + check_has_aspect_atomic64, + check_has_aspect_image, + check_has_aspect_online_compiler, + check_has_aspect_online_linker, + check_has_aspect_queue_profiling, + check_has_aspect_usm_device_allocations, + check_has_aspect_usm_host_allocations, + check_has_aspect_usm_atomic_host_allocations, + check_has_aspect_usm_shared_allocations, + check_has_aspect_usm_atomic_shared_allocations, + check_has_aspect_usm_system_allocations, ] From c3d1b02980bb46b87154e731897fd439a287ac0a Mon Sep 17 00:00:00 2001 From: etotmeni Date: Wed, 3 Mar 2021 08:32:47 -0600 Subject: [PATCH 06/11] Small fix --- dpctl/_sycl_device.pxd | 2 -- 1 file changed, 2 deletions(-) diff --git a/dpctl/_sycl_device.pxd b/dpctl/_sycl_device.pxd index f71cdbb717..b7a7d09ab1 100644 --- a/dpctl/_sycl_device.pxd +++ b/dpctl/_sycl_device.pxd @@ -44,8 +44,6 @@ cdef class _SyclDevice: cdef size_t *_max_work_item_sizes cdef size_t _max_work_group_size cdef uint32_t _max_num_sub_groups - cdef bool _int64_base_atomics - cdef bool _int64_extended_atomics cdef DPCTLSyclDeviceRef get_device_ref(self) cpdef get_backend(self) cpdef get_device_name(self) From e47306737c96c8f979bb5d53f0745cbb12695322 Mon Sep 17 00:00:00 2001 From: etotmeni Date: Thu, 4 Mar 2021 12:05:06 -0600 Subject: [PATCH 07/11] Add utils funcs and fix aspects via dpc++ --- .../helper/include/dpctl_utils_helper.h | 46 ++++ .../helper/source/dpctl_utils_helper.cpp | 222 ++++++++++++++++++ dpctl-capi/include/dpctl_sycl_enum_types.h | 11 +- .../source/dpctl_sycl_device_interface.cpp | 2 +- dpctl-capi/tests/test_sycl_device_aspects.cpp | 39 ++- dpctl/_backend.pxd | 37 ++- dpctl/_sycl_device.pyx | 37 ++- dpctl/tests/test_sycl_device.py | 64 +++-- 8 files changed, 353 insertions(+), 105 deletions(-) diff --git a/dpctl-capi/helper/include/dpctl_utils_helper.h b/dpctl-capi/helper/include/dpctl_utils_helper.h index 7215220565..8e3a4f5d91 100644 --- a/dpctl-capi/helper/include/dpctl_utils_helper.h +++ b/dpctl-capi/helper/include/dpctl_utils_helper.h @@ -95,3 +95,49 @@ DPCTL_DPCTLDeviceTypeToSyclDeviceType(DPCTLSyclDeviceType DTy); */ DPCTLSyclDeviceType DPCTL_SyclDeviceTypeToDPCTLDeviceType(sycl::info::device_type D); + +/*! + * @brief Converts a sycl::aspect input value to a string. + * + * @param aspectTy A sycl::aspect value. + * @return A string representation of a sycl::aspect. + */ +std::string DPCTL_AspectToStr(sycl::aspect aspectTy); + +/*! + * @brief Converts a string to sycl::aspect value. + * + * Tries to interpret the input string a return a corresponding device_type. + If + * no conversion is possible, then a runtime_error is thrown. + * + * @param aspectTyStr Input string for which we search a + * sycl::aspect value. + * @return The sycl::aspect value corresponding to the input + * string. + * @throws runtime_error + */ +sycl::aspect DPCTL_StrToAspectType(const std::string &aspectTyStr); + +/*! + * @brief Converts a DPCTLSyclAspectType enum value to its corresponding + * sycl::aspect enum value. + * + * @param AspectTy A DPCTLSyclAspectType enum value + * @return A sycl::aspect enum value for the input + * DPCTLSyclAspectType enum value. + * @throws runtime_error + */ +sycl::aspect +DPCTL_DPCTLAspectTypeToSyclAspectType(DPCTLSyclAspectType AspectTy); + +/*! + * @brief Converts a sycl::aspect enum value to corresponding + * DPCTLSyclAspectType enum value. + * + * @param Aspect sycl::aspect to be converted to + * DPCTLSyclAspectType enum. + * @return A DPCTLSyclAspectType enum value for the input + * sycl::aspect enum value. + */ +DPCTLSyclAspectType DPCTL_SyclAspectTypeToDPCTLAspectType(sycl::aspect Aspect); diff --git a/dpctl-capi/helper/source/dpctl_utils_helper.cpp b/dpctl-capi/helper/source/dpctl_utils_helper.cpp index eb2fd8e862..5e444da524 100644 --- a/dpctl-capi/helper/source/dpctl_utils_helper.cpp +++ b/dpctl-capi/helper/source/dpctl_utils_helper.cpp @@ -160,3 +160,225 @@ DPCTLSyclDeviceType DPCTL_SyclDeviceTypeToDPCTLDeviceType(info::device_type D) return DPCTLSyclDeviceType::DPCTL_UNKNOWN_DEVICE; } } + +/*! + * Transforms cl::sycl::aspect to string. + */ +std::string DPCTL_AspectToStr(aspect aspectTy) +{ + std::stringstream ss; + switch (aspectTy) { + case aspect::host: + ss << "host" << '\n'; + break; + case aspect::cpu: + ss << "cpu" << '\n'; + break; + case aspect::gpu: + ss << "gpu" << '\n'; + break; + case aspect::accelerator: + ss << "accelerator" << '\n'; + break; + case aspect::custom: + ss << "custom" << '\n'; + break; + case aspect::fp16: + ss << "fp16" << '\n'; + break; + case aspect::fp64: + ss << "fp64" << '\n'; + break; + case aspect::int64_base_atomics: + ss << "int64_base_atomics" << '\n'; + break; + case aspect::int64_extended_atomics: + ss << "int64_extended_atomics" << '\n'; + break; + case aspect::image: + ss << "image" << '\n'; + break; + case aspect::online_compiler: + ss << "online_compiler" << '\n'; + break; + case aspect::online_linker: + ss << "online_linker" << '\n'; + break; + case aspect::queue_profiling: + ss << "queue_profiling" << '\n'; + break; + case aspect::usm_device_allocations: + ss << "usm_device_allocations" << '\n'; + break; + case aspect::usm_host_allocations: + ss << "usm_host_allocations" << '\n'; + break; + case aspect::usm_shared_allocations: + ss << "usm_shared_allocations" << '\n'; + break; + case aspect::usm_restricted_shared_allocations: + ss << "usm_restricted_shared_allocations" << '\n'; + break; + case aspect::usm_system_allocator: + ss << "usm_system_allocator" << '\n'; + break; + default: + ss << "unknown" << '\n'; + } + return ss.str(); +} + +/*! + * Transforms string to cl::sycl::aspect. + */ +aspect DPCTL_StrToAspectType(const std::string &aspectTyStr) +{ + aspect aspectTy; + if (aspectTyStr == "host") { + aspectTy = aspect::host; + } + else if (aspectTyStr == "cpu") { + aspectTy = aspect::cpu; + } + else if (aspectTyStr == "gpu") { + aspectTy = aspect::gpu; + } + else if (aspectTyStr == "accelerator") { + aspectTy = aspect::accelerator; + } + else if (aspectTyStr == "custom") { + aspectTy = aspect::custom; + } + else if (aspectTyStr == "fp16") { + aspectTy = aspect::fp16; + } + else if (aspectTyStr == "fp64") { + aspectTy = aspect::fp64; + } + else if (aspectTyStr == "int64_base_atomics") { + aspectTy = aspect::int64_base_atomics; + } + else if (aspectTyStr == "int64_extended_atomics") { + aspectTy = aspect::int64_extended_atomics; + } + else if (aspectTyStr == "image") { + aspectTy = aspect::image; + } + else if (aspectTyStr == "online_compiler") { + aspectTy = aspect::online_compiler; + } + else if (aspectTyStr == "online_linker") { + aspectTy = aspect::online_linker; + } + else if (aspectTyStr == "queue_profiling") { + aspectTy = aspect::queue_profiling; + } + else if (aspectTyStr == "usm_device_allocations") { + aspectTy = aspect::usm_device_allocations; + } + else if (aspectTyStr == "usm_host_allocations") { + aspectTy = aspect::usm_host_allocations; + } + else if (aspectTyStr == "usm_shared_allocations") { + aspectTy = aspect::usm_shared_allocations; + } + else if (aspectTyStr == "usm_restricted_shared_allocations") { + aspectTy = aspect::usm_restricted_shared_allocations; + } + else if (aspectTyStr == "usm_system_allocator") { + aspectTy = aspect::usm_system_allocator; + } + else { + // \todo handle the error + throw std::runtime_error("Unknown aspect."); + } + return aspectTy; +} + +aspect DPCTL_DPCTLAspectTypeToSyclAspectType(DPCTLSyclAspectType AspectTy) +{ + switch (AspectTy) { + case DPCTLSyclAspectType::host: + return aspect::host; + case DPCTLSyclAspectType::cpu: + return aspect::cpu; + case DPCTLSyclAspectType::gpu: + return aspect::gpu; + case DPCTLSyclAspectType::accelerator: + return aspect::accelerator; + case DPCTLSyclAspectType::custom: + return aspect::custom; + case DPCTLSyclAspectType::fp16: + return aspect::fp16; + case DPCTLSyclAspectType::fp64: + return aspect::fp64; + case DPCTLSyclAspectType::int64_base_atomics: + return aspect::int64_base_atomics; + case DPCTLSyclAspectType::int64_extended_atomics: + return aspect::int64_extended_atomics; + case DPCTLSyclAspectType::image: + return aspect::image; + case DPCTLSyclAspectType::online_compiler: + return aspect::online_compiler; + case DPCTLSyclAspectType::online_linker: + return aspect::online_linker; + case DPCTLSyclAspectType::queue_profiling: + return aspect::queue_profiling; + case DPCTLSyclAspectType::usm_device_allocations: + return aspect::usm_device_allocations; + case DPCTLSyclAspectType::usm_host_allocations: + return aspect::usm_host_allocations; + case DPCTLSyclAspectType::usm_shared_allocations: + return aspect::usm_shared_allocations; + case DPCTLSyclAspectType::usm_restricted_shared_allocations: + return aspect::usm_restricted_shared_allocations; + case DPCTLSyclAspectType::usm_system_allocator: + return aspect::usm_system_allocator; + default: + throw runtime_error("Unsupported aspect type", -1); + } +} + +DPCTLSyclAspectType DPCTL_SyclAspectTypeToDPCTLAspectType(aspect Aspect) +{ + switch (Aspect) { + case aspect::host: + return DPCTLSyclAspectType::host; + case aspect::cpu: + return DPCTLSyclAspectType::cpu; + case aspect::gpu: + return DPCTLSyclAspectType::gpu; + case aspect::accelerator: + return DPCTLSyclAspectType::accelerator; + case aspect::custom: + return DPCTLSyclAspectType::custom; + case aspect::fp16: + return DPCTLSyclAspectType::fp16; + case aspect::fp64: + return DPCTLSyclAspectType::fp64; + case aspect::int64_base_atomics: + return DPCTLSyclAspectType::int64_base_atomics; + case aspect::int64_extended_atomics: + return DPCTLSyclAspectType::int64_extended_atomics; + case aspect::image: + return DPCTLSyclAspectType::image; + case aspect::online_compiler: + return DPCTLSyclAspectType::online_compiler; + case aspect::online_linker: + return DPCTLSyclAspectType::online_linker; + case aspect::queue_profiling: + return DPCTLSyclAspectType::queue_profiling; + case aspect::usm_device_allocations: + return DPCTLSyclAspectType::usm_device_allocations; + case aspect::usm_host_allocations: + return DPCTLSyclAspectType::usm_host_allocations; + case aspect::usm_shared_allocations: + return DPCTLSyclAspectType::usm_shared_allocations; + case aspect::usm_restricted_shared_allocations: + return DPCTLSyclAspectType::usm_restricted_shared_allocations; + case aspect::usm_system_allocator: + return DPCTLSyclAspectType::usm_system_allocator; + default: + throw runtime_error("Unsupported aspect type", -1); + } +} \ No newline at end of file diff --git a/dpctl-capi/include/dpctl_sycl_enum_types.h b/dpctl-capi/include/dpctl_sycl_enum_types.h index 3e1f3c6e46..b69b67ea07 100644 --- a/dpctl-capi/include/dpctl_sycl_enum_types.h +++ b/dpctl-capi/include/dpctl_sycl_enum_types.h @@ -102,25 +102,24 @@ typedef enum */ enum DPCTLSyclAspectType { + host, cpu, gpu, accelerator, custom, - emulated, - host_debuggable, fp16, fp64, - atomic64, + int64_base_atomics, + int64_extended_atomics, image, online_compiler, online_linker, queue_profiling, usm_device_allocations, usm_host_allocations, - usm_atomic_host_allocations, usm_shared_allocations, - usm_atomic_shared_allocations, - usm_system_allocations + usm_restricted_shared_allocations, + usm_system_allocator }; /*! diff --git a/dpctl-capi/source/dpctl_sycl_device_interface.cpp b/dpctl-capi/source/dpctl_sycl_device_interface.cpp index a03bc7683a..44ee2da1c0 100644 --- a/dpctl-capi/source/dpctl_sycl_device_interface.cpp +++ b/dpctl-capi/source/dpctl_sycl_device_interface.cpp @@ -417,7 +417,7 @@ bool DPCTLDevice_HasAspect(__dpctl_keep const DPCTLSyclDeviceRef DRef, auto D = unwrap(DRef); if (D) { try { - hasAspect = D->has(cl::sycl::aspect(AT)); + hasAspect = D->has(DPCTL_DPCTLAspectTypeToSyclAspectType(AT)); } catch (runtime_error const &re) { // \todo log error std::cerr << re.what() << '\n'; diff --git a/dpctl-capi/tests/test_sycl_device_aspects.cpp b/dpctl-capi/tests/test_sycl_device_aspects.cpp index ebe78a83ff..014f1fdf5a 100644 --- a/dpctl-capi/tests/test_sycl_device_aspects.cpp +++ b/dpctl-capi/tests/test_sycl_device_aspects.cpp @@ -1,3 +1,4 @@ +#include "../helper/include/dpctl_utils_helper.h" #include "Support/CBindingWrapping.h" #include "dpctl_sycl_device_interface.h" #include "dpctl_sycl_device_selector_interface.h" @@ -72,11 +73,10 @@ auto build_params() constexpr auto param_1 = get_param_list( "opencl:gpu", "opencl:cpu", "level_zero:gpu", "host"); constexpr auto param_2 = get_param_list( - cpu, gpu, accelerator, custom, emulated, host_debuggable, fp16, fp64, - atomic64, online_compiler, online_linker, queue_profiling, - usm_device_allocations, usm_host_allocations, - usm_atomic_host_allocations, usm_shared_allocations, - usm_atomic_shared_allocations, usm_system_allocations); + host, cpu, gpu, accelerator, custom, fp16, fp64, int64_base_atomics, + int64_extended_atomics, online_compiler, online_linker, queue_profiling, + usm_device_allocations, usm_host_allocations, usm_shared_allocations, + usm_restricted_shared_allocations, usm_system_allocator); auto pairs = build_param_pairs> { DPCTLSyclDeviceSelectorRef DSRef = nullptr; + bool actual = false; TestDPCTLSyclDeviceInterfaceAspects() { @@ -107,16 +108,17 @@ struct TestDPCTLSyclDeviceInterfaceAspects std::string(GetParam().first) + "."; GTEST_SKIP_(message.c_str()); } - auto aspectTy = GetParam().second; - if (aspectTy == emulated || aspectTy == usm_device_allocations || - aspectTy == usm_host_allocations || - aspectTy == usm_atomic_host_allocations || - aspectTy == usm_shared_allocations || - aspectTy == usm_atomic_shared_allocations || - aspectTy == usm_system_allocations) - { - GTEST_SKIP_("This device aspect has not been implemented yet."); + DPCTLSyclDeviceRef DRef = nullptr; + EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef)); + if (!DRef) + GTEST_SKIP_("Device not found"); + auto D = unwrap(DRef); + try { + actual = D->has( + DPCTL_DPCTLAspectTypeToSyclAspectType(GetParam().second)); + } catch (...) { } + EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef)); } ~TestDPCTLSyclDeviceInterfaceAspects() @@ -127,20 +129,13 @@ struct TestDPCTLSyclDeviceInterfaceAspects TEST_P(TestDPCTLSyclDeviceInterfaceAspects, Chk_HasAspect) { - - bool expected = false, actual = false; + bool expected = false; auto aspectTy = GetParam().second; DPCTLSyclDeviceRef DRef = nullptr; EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef)); if (!DRef) GTEST_SKIP_("Device not found"); EXPECT_NO_FATAL_FAILURE(expected = DPCTLDevice_HasAspect(DRef, aspectTy)); - auto D = unwrap(DRef); - try { - actual = D->has(cl::sycl::aspect(aspectTy)); - } catch (...) { - GTEST_SKIP_("Aspect not supported"); - } EXPECT_TRUE(expected == actual); EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef)); } diff --git a/dpctl/_backend.pxd b/dpctl/_backend.pxd index 3c3d00098e..7dfea07dae 100644 --- a/dpctl/_backend.pxd +++ b/dpctl/_backend.pxd @@ -74,25 +74,24 @@ cdef extern from "dpctl_sycl_enum_types.h": ctypedef _arg_data_type DPCTLKernelArgType cdef enum _aspect_type 'DPCTLSyclAspectType': - _cpu 'cpu', - _gpu 'gpu', - _accelerator 'accelerator', - _custom 'custom', - _emulated 'emulated', - _host_debuggable 'host_debuggable', - _fp16 'fp16', - _fp64 'fp64', - _atomic64 'atomic64', - _image 'image', - _online_compiler 'online_compiler', - _online_linker 'online_linker', - _queue_profiling 'queue_profiling', - _usm_device_allocations 'usm_device_allocations', - _usm_host_allocations 'usm_host_allocations', - _usm_atomic_host_allocations 'usm_atomic_host_allocations', - _usm_shared_allocations 'usm_shared_allocations', - _usm_atomic_shared_allocations 'usm_atomic_shared_allocations', - _usm_system_allocations 'usm_system_allocations' + _host 'host', + _cpu 'cpu', + _gpu 'gpu', + _accelerator 'accelerator', + _custom 'custom', + _fp16 'fp16', + _fp64 'fp64', + _int64_base_atomics 'int64_base_atomics', + _int64_extended_atomics 'int64_extended_atomics', + _image 'image', + _online_compiler 'online_compiler', + _online_linker 'online_linker', + _queue_profiling 'queue_profiling', + _usm_device_allocations 'usm_device_allocations', + _usm_host_allocations 'usm_host_allocations', + _usm_shared_allocations 'usm_shared_allocations', + _usm_restricted_shared_allocations 'usm_restricted_shared_allocations', + _usm_system_allocator 'usm_system_allocator' ctypedef _aspect_type DPCTLSyclAspectType diff --git a/dpctl/_sycl_device.pyx b/dpctl/_sycl_device.pyx index 159fab194b..10b0f662c6 100644 --- a/dpctl/_sycl_device.pyx +++ b/dpctl/_sycl_device.pyx @@ -379,6 +379,11 @@ cdef class SyclDevice(_SyclDevice): "a SYCL filter selector string." ) + @property + def aspect_host(self): + cdef _aspect_type AT = _aspect_type._host + return DPCTLDevice_HasAspect(self._device_ref, AT) + @property def aspect_cpu(self): cdef _aspect_type AT = _aspect_type._cpu @@ -399,16 +404,6 @@ cdef class SyclDevice(_SyclDevice): cdef _aspect_type AT = _aspect_type._custom return DPCTLDevice_HasAspect(self._device_ref, AT) - @property - def aspect_emulated(self): - cdef _aspect_type AT = _aspect_type._emulated - return DPCTLDevice_HasAspect(self._device_ref, AT) - - @property - def aspect_host_debuggable(self): - cdef _aspect_type AT = _aspect_type._host_debuggable - return DPCTLDevice_HasAspect(self._device_ref, AT) - @property def aspect_fp16(self): cdef _aspect_type AT = _aspect_type._fp16 @@ -420,8 +415,13 @@ cdef class SyclDevice(_SyclDevice): return DPCTLDevice_HasAspect(self._device_ref, AT) @property - def aspect_atomic64(self): - cdef _aspect_type AT = _aspect_type._atomic64 + def aspect_int64_base_atomics(self): + cdef _aspect_type AT = _aspect_type._int64_base_atomics + return DPCTLDevice_HasAspect(self._device_ref, AT) + + @property + def aspect_int64_extended_atomics(self): + cdef _aspect_type AT = _aspect_type._int64_extended_atomics return DPCTLDevice_HasAspect(self._device_ref, AT) @property @@ -454,24 +454,19 @@ cdef class SyclDevice(_SyclDevice): cdef _aspect_type AT = _aspect_type._usm_host_allocations return DPCTLDevice_HasAspect(self._device_ref, AT) - @property - def aspect_usm_atomic_host_allocations(self): - cdef _aspect_type AT = _aspect_type._usm_atomic_host_allocations - return DPCTLDevice_HasAspect(self._device_ref, AT) - @property def aspect_usm_shared_allocations(self): cdef _aspect_type AT = _aspect_type._usm_shared_allocations return DPCTLDevice_HasAspect(self._device_ref, AT) @property - def aspect_usm_atomic_shared_allocations(self): - cdef _aspect_type AT = _aspect_type._usm_atomic_shared_allocations + def aspect_usm_restricted_shared_allocations(self): + cdef _aspect_type AT = _aspect_type._usm_restricted_shared_allocations return DPCTLDevice_HasAspect(self._device_ref, AT) @property - def aspect_usm_system_allocations(self): - cdef _aspect_type AT = _aspect_type._usm_system_allocations + def aspect_usm_system_allocator(self): + cdef _aspect_type AT = _aspect_type._usm_system_allocator return DPCTLDevice_HasAspect(self._device_ref, AT) @property diff --git a/dpctl/tests/test_sycl_device.py b/dpctl/tests/test_sycl_device.py index ff5479b839..be80923b93 100644 --- a/dpctl/tests/test_sycl_device.py +++ b/dpctl/tests/test_sycl_device.py @@ -86,6 +86,13 @@ def check_get_max_num_sub_groups(device): assert max_num_sub_groups > 0 +def check_has_aspect_host(device): + try: + device.aspect_host + except Exception: + pytest.fail("aspect_host call failed") + + def check_has_aspect_cpu(device): try: device.aspect_cpu @@ -114,20 +121,6 @@ def check_has_aspect_custom(device): pytest.fail("aspect_custom call failed") -def check_has_aspect_emulated(device): - try: - device.aspect_emulated - except Exception: - pytest.fail("aspect_emulated call failed") - - -def check_has_aspect_host_debuggable(device): - try: - device.aspect_host_debuggable - except Exception: - pytest.fail("aspect_host_debuggable call failed") - - def check_has_aspect_fp16(device): try: device.aspect_fp16 @@ -142,11 +135,18 @@ def check_has_aspect_fp64(device): pytest.fail("aspect_fp64 call failed") -def check_has_aspect_atomic64(device): +def check_has_aspect_int64_base_atomics(device): + try: + device.aspect_int64_base_atomics + except Exception: + pytest.fail("aspect_int64_base_atomics call failed") + + +def check_has_aspect_int64_extended_atomics(device): try: - device.aspect_atomic64 + device.aspect_int64_extended_atomics except Exception: - pytest.fail("aspect_atomic64 call failed") + pytest.fail("aspect_int64_extended_atomics call failed") def check_has_aspect_image(device): @@ -191,13 +191,6 @@ def check_has_aspect_usm_host_allocations(device): pytest.fail("aspect_usm_host_allocations call failed") -def check_has_aspect_usm_atomic_host_allocations(device): - try: - device.aspect_usm_atomic_host_allocations - except Exception: - pytest.fail("aspect_usm_atomic_host_allocations call failed") - - def check_has_aspect_usm_shared_allocations(device): try: device.aspect_usm_shared_allocations @@ -205,18 +198,18 @@ def check_has_aspect_usm_shared_allocations(device): pytest.fail("aspect_usm_shared_allocations call failed") -def check_has_aspect_usm_atomic_shared_allocations(device): +def check_has_aspect_usm_restricted_shared_allocations(device): try: - device.aspect_usm_atomic_shared_allocations + device.aspect_usm_restricted_shared_allocations except Exception: - pytest.fail("aspect_usm_atomic_shared_allocations call failed") + pytest.fail("aspect_usm_restricted_shared_allocations call failed") -def check_has_aspect_usm_system_allocations(device): +def check_has_aspect_usm_system_allocator(device): try: - device.aspect_usm_system_allocations + device.aspect_usm_system_allocator except Exception: - pytest.fail("aspect_usm_system_allocations call failed") + pytest.fail("aspect_usm_system_allocator call failed") def check_is_accelerator(device): @@ -257,25 +250,24 @@ def check_is_host(device): check_is_cpu, check_is_gpu, check_is_host, + check_has_aspect_host, check_has_aspect_cpu, check_has_aspect_gpu, check_has_aspect_accelerator, check_has_aspect_custom, - check_has_aspect_emulated, - check_has_aspect_host_debuggable, check_has_aspect_fp16, check_has_aspect_fp64, - check_has_aspect_atomic64, + check_has_aspect_int64_base_atomics, + check_has_aspect_int64_extended_atomics, check_has_aspect_image, check_has_aspect_online_compiler, check_has_aspect_online_linker, check_has_aspect_queue_profiling, check_has_aspect_usm_device_allocations, check_has_aspect_usm_host_allocations, - check_has_aspect_usm_atomic_host_allocations, check_has_aspect_usm_shared_allocations, - check_has_aspect_usm_atomic_shared_allocations, - check_has_aspect_usm_system_allocations, + check_has_aspect_usm_restricted_shared_allocations, + check_has_aspect_usm_system_allocator, ] From 5dfc4daaa6d27abaa4497c390a16db77b80a4dc5 Mon Sep 17 00:00:00 2001 From: etotmeni Date: Fri, 5 Mar 2021 05:41:51 -0600 Subject: [PATCH 08/11] WIP fix --- .../helper/include/dpctl_utils_helper.h | 11 ++-- .../helper/source/dpctl_utils_helper.cpp | 8 +-- .../include/dpctl_sycl_device_interface.h | 2 +- .../source/dpctl_sycl_device_interface.cpp | 4 +- dpctl-capi/tests/test_sycl_device_aspects.cpp | 56 +++++++++++-------- dpctl/_backend.pxd | 2 +- 6 files changed, 46 insertions(+), 37 deletions(-) diff --git a/dpctl-capi/helper/include/dpctl_utils_helper.h b/dpctl-capi/helper/include/dpctl_utils_helper.h index 8e3a4f5d91..d87570aec8 100644 --- a/dpctl-capi/helper/include/dpctl_utils_helper.h +++ b/dpctl-capi/helper/include/dpctl_utils_helper.h @@ -101,16 +101,13 @@ DPCTL_SyclDeviceTypeToDPCTLDeviceType(sycl::info::device_type D); * * @param aspectTy A sycl::aspect value. * @return A string representation of a sycl::aspect. + * @throws runtime_error */ std::string DPCTL_AspectToStr(sycl::aspect aspectTy); /*! * @brief Converts a string to sycl::aspect value. * - * Tries to interpret the input string a return a corresponding device_type. - If - * no conversion is possible, then a runtime_error is thrown. - * * @param aspectTyStr Input string for which we search a * sycl::aspect value. * @return The sycl::aspect value corresponding to the input @@ -128,8 +125,7 @@ sycl::aspect DPCTL_StrToAspectType(const std::string &aspectTyStr); * DPCTLSyclAspectType enum value. * @throws runtime_error */ -sycl::aspect -DPCTL_DPCTLAspectTypeToSyclAspectType(DPCTLSyclAspectType AspectTy); +sycl::aspect DPCTL_DPCTLAspectTypeToSyclAspect(DPCTLSyclAspectType AspectTy); /*! * @brief Converts a sycl::aspect enum value to corresponding @@ -139,5 +135,6 @@ DPCTL_DPCTLAspectTypeToSyclAspectType(DPCTLSyclAspectType AspectTy); * DPCTLSyclAspectType enum. * @return A DPCTLSyclAspectType enum value for the input * sycl::aspect enum value. + * @throws runtime_error */ -DPCTLSyclAspectType DPCTL_SyclAspectTypeToDPCTLAspectType(sycl::aspect Aspect); +DPCTLSyclAspectType DPCTL_SyclAspectToDPCTLAspectType(sycl::aspect Aspect); diff --git a/dpctl-capi/helper/source/dpctl_utils_helper.cpp b/dpctl-capi/helper/source/dpctl_utils_helper.cpp index 5e444da524..70f9112b57 100644 --- a/dpctl-capi/helper/source/dpctl_utils_helper.cpp +++ b/dpctl-capi/helper/source/dpctl_utils_helper.cpp @@ -223,7 +223,7 @@ std::string DPCTL_AspectToStr(aspect aspectTy) ss << "usm_system_allocator" << '\n'; break; default: - ss << "unknown" << '\n'; + throw runtime_error("Unsupported aspect type", -1); } return ss.str(); } @@ -290,12 +290,12 @@ aspect DPCTL_StrToAspectType(const std::string &aspectTyStr) } else { // \todo handle the error - throw std::runtime_error("Unknown aspect."); + throw runtime_error("Unsupported aspect type", -1); } return aspectTy; } -aspect DPCTL_DPCTLAspectTypeToSyclAspectType(DPCTLSyclAspectType AspectTy) +aspect DPCTL_DPCTLAspectTypeToSyclAspect(DPCTLSyclAspectType AspectTy) { switch (AspectTy) { case DPCTLSyclAspectType::host: @@ -339,7 +339,7 @@ aspect DPCTL_DPCTLAspectTypeToSyclAspectType(DPCTLSyclAspectType AspectTy) } } -DPCTLSyclAspectType DPCTL_SyclAspectTypeToDPCTLAspectType(aspect Aspect) +DPCTLSyclAspectType DPCTL_SyclAspectToDPCTLAspectType(aspect Aspect) { switch (Aspect) { case aspect::host: diff --git a/dpctl-capi/include/dpctl_sycl_device_interface.h b/dpctl-capi/include/dpctl_sycl_device_interface.h index 2882e69b24..7dce2edcb0 100644 --- a/dpctl-capi/include/dpctl_sycl_device_interface.h +++ b/dpctl-capi/include/dpctl_sycl_device_interface.h @@ -271,6 +271,6 @@ bool DPCTLDevice_AreEq(__dpctl_keep const DPCTLSyclDeviceRef DevRef1, */ DPCTL_API bool DPCTLDevice_HasAspect(__dpctl_keep const DPCTLSyclDeviceRef DRef, - __dpctl_keep const DPCTLSyclAspectType AT); + DPCTLSyclAspectType AT); DPCTL_C_EXTERN_C_END diff --git a/dpctl-capi/source/dpctl_sycl_device_interface.cpp b/dpctl-capi/source/dpctl_sycl_device_interface.cpp index 44ee2da1c0..c27b1ab254 100644 --- a/dpctl-capi/source/dpctl_sycl_device_interface.cpp +++ b/dpctl-capi/source/dpctl_sycl_device_interface.cpp @@ -411,13 +411,13 @@ bool DPCTLDevice_AreEq(__dpctl_keep const DPCTLSyclDeviceRef DevRef1, } bool DPCTLDevice_HasAspect(__dpctl_keep const DPCTLSyclDeviceRef DRef, - __dpctl_keep const DPCTLSyclAspectType AT) + DPCTLSyclAspectType AT) { bool hasAspect = false; auto D = unwrap(DRef); if (D) { try { - hasAspect = D->has(DPCTL_DPCTLAspectTypeToSyclAspectType(AT)); + hasAspect = D->has(DPCTL_DPCTLAspectTypeToSyclAspect(AT)); } catch (runtime_error const &re) { // \todo log error std::cerr << re.what() << '\n'; diff --git a/dpctl-capi/tests/test_sycl_device_aspects.cpp b/dpctl-capi/tests/test_sycl_device_aspects.cpp index 014f1fdf5a..836023d9e3 100644 --- a/dpctl-capi/tests/test_sycl_device_aspects.cpp +++ b/dpctl-capi/tests/test_sycl_device_aspects.cpp @@ -72,11 +72,28 @@ auto build_params() { constexpr auto param_1 = get_param_list( "opencl:gpu", "opencl:cpu", "level_zero:gpu", "host"); - constexpr auto param_2 = get_param_list( - host, cpu, gpu, accelerator, custom, fp16, fp64, int64_base_atomics, - int64_extended_atomics, online_compiler, online_linker, queue_profiling, - usm_device_allocations, usm_host_allocations, usm_shared_allocations, - usm_restricted_shared_allocations, usm_system_allocator); + + constexpr auto param_2 = + get_param_list>( + {"host", cl::sycl::aspect::host}, {"cpu", cl::sycl::aspect::cpu}, + {"gpu", cl::sycl::aspect::gpu}, + {"accelerator", cl::sycl::aspect::accelerator}, + {"custom", cl::sycl::aspect::custom}, + {"fp16", cl::sycl::aspect::fp16}, {"fp64", cl::sycl::aspect::fp64}, + {"int64_base_atomics", cl::sycl::aspect::int64_base_atomics}, + {"int64_extended_atomics", + cl::sycl::aspect::int64_extended_atomics}, + {"online_compiler", cl::sycl::aspect::online_compiler}, + {"online_linker", cl::sycl::aspect::online_linker}, + {"queue_profiling", cl::sycl::aspect::queue_profiling}, + {"usm_device_allocations", + cl::sycl::aspect::usm_device_allocations}, + {"usm_host_allocations", cl::sycl::aspect::usm_host_allocations}, + {"usm_shared_allocations", + cl::sycl::aspect::usm_shared_allocations}, + {"usm_restricted_shared_allocations", + cl::sycl::aspect::usm_restricted_shared_allocations}, + {"usm_system_allocator", cl::sycl::aspect::usm_system_allocator}); auto pairs = build_param_pairs> { DPCTLSyclDeviceSelectorRef DSRef = nullptr; - bool actual = false; + DPCTLSyclDeviceRef DRef = nullptr; + bool hasAspect = false; TestDPCTLSyclDeviceInterfaceAspects() { - auto params = GetParam(); - auto filterstr = params.first; + auto filterstr = GetParam().first; EXPECT_NO_FATAL_FAILURE(DSRef = DPCTLFilterSelector_Create(filterstr)); } @@ -108,36 +125,31 @@ struct TestDPCTLSyclDeviceInterfaceAspects std::string(GetParam().first) + "."; GTEST_SKIP_(message.c_str()); } - DPCTLSyclDeviceRef DRef = nullptr; + EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef)); if (!DRef) GTEST_SKIP_("Device not found"); auto D = unwrap(DRef); + auto syclAspect = GetParam().second.second; try { - actual = D->has( - DPCTL_DPCTLAspectTypeToSyclAspectType(GetParam().second)); - } catch (...) { + hasAspect = D->has(syclAspect); + } catch (std::runtime_error const &re) { } - EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef)); } ~TestDPCTLSyclDeviceInterfaceAspects() { EXPECT_NO_FATAL_FAILURE(DPCTLDeviceSelector_Delete(DSRef)); + EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef)); } }; TEST_P(TestDPCTLSyclDeviceInterfaceAspects, Chk_HasAspect) { - bool expected = false; - auto aspectTy = GetParam().second; - DPCTLSyclDeviceRef DRef = nullptr; - EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef)); - if (!DRef) - GTEST_SKIP_("Device not found"); - EXPECT_NO_FATAL_FAILURE(expected = DPCTLDevice_HasAspect(DRef, aspectTy)); - EXPECT_TRUE(expected == actual); - EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef)); + bool actual = false; + auto dpctlAspect = DPCTL_StrToAspect(GetParam().second.first); + EXPECT_NO_FATAL_FAILURE(actual = DPCTLDevice_HasAspect(DRef, dpctlAspect)); + EXPECT_TRUE(hasAspect == actual); } INSTANTIATE_TEST_SUITE_P(DPCTLSyclDeviceInterfaceAspects, diff --git a/dpctl/_backend.pxd b/dpctl/_backend.pxd index 7dfea07dae..530fc22d8d 100644 --- a/dpctl/_backend.pxd +++ b/dpctl/_backend.pxd @@ -147,7 +147,7 @@ cdef extern from "dpctl_sycl_device_interface.h": cdef bool DPCTLDevice_IsHost(const DPCTLSyclDeviceRef DRef) cdef bool DPCTLDevice_IsHostUnifiedMemory(const DPCTLSyclDeviceRef DRef) cpdef bool DPCTLDevice_HasAspect( - const DPCTLSyclDeviceRef DRef, const DPCTLSyclAspectType AT) + const DPCTLSyclDeviceRef DRef, DPCTLSyclAspectType AT) cdef extern from "dpctl_sycl_device_selector_interface.h": From 06948297d400df1dfaae00af985d05ece4b8a0a2 Mon Sep 17 00:00:00 2001 From: etotmeni Date: Fri, 5 Mar 2021 08:50:48 -0600 Subject: [PATCH 09/11] Fix pairs --- dpctl-capi/tests/test_sycl_device_aspects.cpp | 50 ++++++++++--------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/dpctl-capi/tests/test_sycl_device_aspects.cpp b/dpctl-capi/tests/test_sycl_device_aspects.cpp index 836023d9e3..e6877ca12d 100644 --- a/dpctl-capi/tests/test_sycl_device_aspects.cpp +++ b/dpctl-capi/tests/test_sycl_device_aspects.cpp @@ -75,29 +75,30 @@ auto build_params() constexpr auto param_2 = get_param_list>( - {"host", cl::sycl::aspect::host}, {"cpu", cl::sycl::aspect::cpu}, - {"gpu", cl::sycl::aspect::gpu}, - {"accelerator", cl::sycl::aspect::accelerator}, - {"custom", cl::sycl::aspect::custom}, - {"fp16", cl::sycl::aspect::fp16}, {"fp64", cl::sycl::aspect::fp64}, - {"int64_base_atomics", cl::sycl::aspect::int64_base_atomics}, - {"int64_extended_atomics", - cl::sycl::aspect::int64_extended_atomics}, - {"online_compiler", cl::sycl::aspect::online_compiler}, - {"online_linker", cl::sycl::aspect::online_linker}, - {"queue_profiling", cl::sycl::aspect::queue_profiling}, - {"usm_device_allocations", - cl::sycl::aspect::usm_device_allocations}, - {"usm_host_allocations", cl::sycl::aspect::usm_host_allocations}, - {"usm_shared_allocations", - cl::sycl::aspect::usm_shared_allocations}, - {"usm_restricted_shared_allocations", - cl::sycl::aspect::usm_restricted_shared_allocations}, - {"usm_system_allocator", cl::sycl::aspect::usm_system_allocator}); + // clang-format off + std::make_pair("host", cl::sycl::aspect::host), + std::make_pair("cpu", cl::sycl::aspect::cpu), + std::make_pair("gpu", cl::sycl::aspect::gpu), + std::make_pair("accelerator", cl::sycl::aspect::accelerator), + std::make_pair("custom", cl::sycl::aspect::custom), + std::make_pair("fp16", cl::sycl::aspect::fp16), + std::make_pair("fp64", cl::sycl::aspect::fp64), + std::make_pair("int64_base_atomics", cl::sycl::aspect::int64_base_atomics), + std::make_pair("int64_extended_atomics", cl::sycl::aspect::int64_extended_atomics), + std::make_pair("online_compiler", cl::sycl::aspect::online_compiler), + std::make_pair("online_linker", cl::sycl::aspect::online_linker), + std::make_pair("queue_profiling", cl::sycl::aspect::queue_profiling), + std::make_pair("usm_device_allocations", cl::sycl::aspect::usm_device_allocations), + std::make_pair("usm_host_allocations", cl::sycl::aspect::usm_host_allocations), + std::make_pair("usm_shared_allocations", cl::sycl::aspect::usm_shared_allocations), + std::make_pair("usm_restricted_shared_allocations", cl::sycl::aspect::usm_restricted_shared_allocations), + std::make_pair("usm_system_allocator", cl::sycl::aspect::usm_system_allocator)); + // clang-format on auto pairs = - build_param_pairs(param_1, param_2); + build_param_pairs, + param_1.size(), param_2.size()>(param_1, param_2); return build_gtest_values(pairs); } @@ -106,7 +107,7 @@ auto build_params() struct TestDPCTLSyclDeviceInterfaceAspects : public ::testing::TestWithParam< - std::pair> + std::pair>> { DPCTLSyclDeviceSelectorRef DSRef = nullptr; DPCTLSyclDeviceRef DRef = nullptr; @@ -147,8 +148,9 @@ struct TestDPCTLSyclDeviceInterfaceAspects TEST_P(TestDPCTLSyclDeviceInterfaceAspects, Chk_HasAspect) { bool actual = false; - auto dpctlAspect = DPCTL_StrToAspect(GetParam().second.first); - EXPECT_NO_FATAL_FAILURE(actual = DPCTLDevice_HasAspect(DRef, dpctlAspect)); + auto dpctlAspect = DPCTL_StrToAspectType(GetParam().second.first); + auto AspectTy = DPCTL_SyclAspectToDPCTLAspectType(dpctlAspect); + EXPECT_NO_FATAL_FAILURE(actual = DPCTLDevice_HasAspect(DRef, AspectTy)); EXPECT_TRUE(hasAspect == actual); } From 669ed5734c37f609aeda50d089ad72dcd3375cac Mon Sep 17 00:00:00 2001 From: etotmeni Date: Fri, 5 Mar 2021 11:02:18 -0600 Subject: [PATCH 10/11] Fix error catch + small fixes --- dpctl-capi/helper/source/dpctl_utils_helper.cpp | 2 +- dpctl-capi/tests/test_sycl_device_aspects.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dpctl-capi/helper/source/dpctl_utils_helper.cpp b/dpctl-capi/helper/source/dpctl_utils_helper.cpp index 70f9112b57..d90ab3c4ce 100644 --- a/dpctl-capi/helper/source/dpctl_utils_helper.cpp +++ b/dpctl-capi/helper/source/dpctl_utils_helper.cpp @@ -381,4 +381,4 @@ DPCTLSyclAspectType DPCTL_SyclAspectToDPCTLAspectType(aspect Aspect) default: throw runtime_error("Unsupported aspect type", -1); } -} \ No newline at end of file +} diff --git a/dpctl-capi/tests/test_sycl_device_aspects.cpp b/dpctl-capi/tests/test_sycl_device_aspects.cpp index e6877ca12d..32f5dc342b 100644 --- a/dpctl-capi/tests/test_sycl_device_aspects.cpp +++ b/dpctl-capi/tests/test_sycl_device_aspects.cpp @@ -134,7 +134,7 @@ struct TestDPCTLSyclDeviceInterfaceAspects auto syclAspect = GetParam().second.second; try { hasAspect = D->has(syclAspect); - } catch (std::runtime_error const &re) { + } catch (cl::sycl::runtime_error const &re) { } } From bfe344296e6b3a530040b16bb52b3e341b321241 Mon Sep 17 00:00:00 2001 From: etotmeni Date: Tue, 9 Mar 2021 05:41:20 -0600 Subject: [PATCH 11/11] Small fix --- dpctl-capi/tests/test_sycl_device_aspects.cpp | 35 +++++---- dpctl/_sycl_device.pyx | 36 +++++----- dpctl/tests/test_sycl_device.py | 72 +++++++++---------- 3 files changed, 75 insertions(+), 68 deletions(-) diff --git a/dpctl-capi/tests/test_sycl_device_aspects.cpp b/dpctl-capi/tests/test_sycl_device_aspects.cpp index 32f5dc342b..8cf2a725db 100644 --- a/dpctl-capi/tests/test_sycl_device_aspects.cpp +++ b/dpctl-capi/tests/test_sycl_device_aspects.cpp @@ -75,25 +75,32 @@ auto build_params() constexpr auto param_2 = get_param_list>( - // clang-format off - std::make_pair("host", cl::sycl::aspect::host), - std::make_pair("cpu", cl::sycl::aspect::cpu), + std::make_pair("host", cl::sycl::aspect::host), + std::make_pair("cpu", cl::sycl::aspect::cpu), std::make_pair("gpu", cl::sycl::aspect::gpu), std::make_pair("accelerator", cl::sycl::aspect::accelerator), std::make_pair("custom", cl::sycl::aspect::custom), - std::make_pair("fp16", cl::sycl::aspect::fp16), + std::make_pair("fp16", cl::sycl::aspect::fp16), std::make_pair("fp64", cl::sycl::aspect::fp64), - std::make_pair("int64_base_atomics", cl::sycl::aspect::int64_base_atomics), - std::make_pair("int64_extended_atomics", cl::sycl::aspect::int64_extended_atomics), - std::make_pair("online_compiler", cl::sycl::aspect::online_compiler), + std::make_pair("int64_base_atomics", + cl::sycl::aspect::int64_base_atomics), + std::make_pair("int64_extended_atomics", + cl::sycl::aspect::int64_extended_atomics), + std::make_pair("online_compiler", + cl::sycl::aspect::online_compiler), std::make_pair("online_linker", cl::sycl::aspect::online_linker), - std::make_pair("queue_profiling", cl::sycl::aspect::queue_profiling), - std::make_pair("usm_device_allocations", cl::sycl::aspect::usm_device_allocations), - std::make_pair("usm_host_allocations", cl::sycl::aspect::usm_host_allocations), - std::make_pair("usm_shared_allocations", cl::sycl::aspect::usm_shared_allocations), - std::make_pair("usm_restricted_shared_allocations", cl::sycl::aspect::usm_restricted_shared_allocations), - std::make_pair("usm_system_allocator", cl::sycl::aspect::usm_system_allocator)); - // clang-format on + std::make_pair("queue_profiling", + cl::sycl::aspect::queue_profiling), + std::make_pair("usm_device_allocations", + cl::sycl::aspect::usm_device_allocations), + std::make_pair("usm_host_allocations", + cl::sycl::aspect::usm_host_allocations), + std::make_pair("usm_shared_allocations", + cl::sycl::aspect::usm_shared_allocations), + std::make_pair("usm_restricted_shared_allocations", + cl::sycl::aspect::usm_restricted_shared_allocations), + std::make_pair("usm_system_allocator", + cl::sycl::aspect::usm_system_allocator)); auto pairs = build_param_pairs