diff --git a/dpctl-capi/helper/include/dpctl_utils_helper.h b/dpctl-capi/helper/include/dpctl_utils_helper.h index 7215220565..d87570aec8 100644 --- a/dpctl-capi/helper/include/dpctl_utils_helper.h +++ b/dpctl-capi/helper/include/dpctl_utils_helper.h @@ -95,3 +95,46 @@ 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. + * @throws runtime_error + */ +std::string DPCTL_AspectToStr(sycl::aspect aspectTy); + +/*! + * @brief Converts a string to sycl::aspect value. + * + * @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_DPCTLAspectTypeToSyclAspect(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. + * @throws runtime_error + */ +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 eb2fd8e862..d90ab3c4ce 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: + throw runtime_error("Unsupported aspect type", -1); + } + 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 runtime_error("Unsupported aspect type", -1); + } + return aspectTy; +} + +aspect DPCTL_DPCTLAspectTypeToSyclAspect(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_SyclAspectToDPCTLAspectType(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); + } +} diff --git a/dpctl-capi/include/dpctl_sycl_device_interface.h b/dpctl-capi/include/dpctl_sycl_device_interface.h index f5a55507aa..7dce2edcb0 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. * @@ -282,7 +259,18 @@ bool DPCTLDevice_IsHostUnifiedMemory( * @return True if the underlying sycl::device are same, false otherwise. */ DPCTL_API -bool DPCTLDevice_AreEq(__dpctl_keep const DPCTLSyclDeviceRef DRef1, - __dpctl_keep const DPCTLSyclDeviceRef DRef2); +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, + 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 4c1790aaff..b69b67ea07 100644 --- a/dpctl-capi/include/dpctl_sycl_enum_types.h +++ b/dpctl-capi/include/dpctl_sycl_enum_types.h @@ -95,6 +95,33 @@ typedef enum DPCTL_VOID_PTR } DPCTLKernelArgType; +/*! + * @brief DPCTL device has an associated set of aspects which identify + * characteristics of the device. + * + */ +enum DPCTLSyclAspectType +{ + host, + cpu, + gpu, + accelerator, + custom, + fp16, + fp64, + int64_base_atomics, + int64_extended_atomics, + image, + online_compiler, + online_linker, + queue_profiling, + usm_device_allocations, + usm_host_allocations, + usm_shared_allocations, + usm_restricted_shared_allocations, + usm_system_allocator +}; + /*! * @brief Enums to depict the properties that can be passed to a sycl::queue * constructor. diff --git a/dpctl-capi/source/dpctl_sycl_device_interface.cpp b/dpctl-capi/source/dpctl_sycl_device_interface.cpp index 28b033114c..c27b1ab254 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) { @@ -440,3 +409,19 @@ bool DPCTLDevice_AreEq(__dpctl_keep const DPCTLSyclDeviceRef DevRef1, return false; return (*unwrap(DevRef1) == *unwrap(DevRef2)); } + +bool DPCTLDevice_HasAspect(__dpctl_keep const DPCTLSyclDeviceRef DRef, + DPCTLSyclAspectType AT) +{ + bool hasAspect = false; + auto D = unwrap(DRef); + if (D) { + try { + hasAspect = D->has(DPCTL_DPCTLAspectTypeToSyclAspect(AT)); + } catch (runtime_error const &re) { + // \todo log error + std::cerr << re.what() << '\n'; + } + } + 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..8cf2a725db --- /dev/null +++ b/dpctl-capi/tests/test_sycl_device_aspects.cpp @@ -0,0 +1,166 @@ +#include "../helper/include/dpctl_utils_helper.h" +#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>( + 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)); + + auto pairs = + build_param_pairs, + param_1.size(), param_2.size()>(param_1, param_2); + + return build_gtest_values(pairs); +} + +} // namespace + +struct TestDPCTLSyclDeviceInterfaceAspects + : public ::testing::TestWithParam< + std::pair>> +{ + DPCTLSyclDeviceSelectorRef DSRef = nullptr; + DPCTLSyclDeviceRef DRef = nullptr; + bool hasAspect = false; + + TestDPCTLSyclDeviceInterfaceAspects() + { + auto filterstr = GetParam().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()); + } + + 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 { + hasAspect = D->has(syclAspect); + } catch (cl::sycl::runtime_error const &re) { + } + } + + ~TestDPCTLSyclDeviceInterfaceAspects() + { + EXPECT_NO_FATAL_FAILURE(DPCTLDeviceSelector_Delete(DSRef)); + EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef)); + } +}; + +TEST_P(TestDPCTLSyclDeviceInterfaceAspects, Chk_HasAspect) +{ + bool actual = false; + 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); +} + +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 b913317d84..97483d1ce6 100644 --- a/dpctl-capi/tests/test_sycl_device_interface.cpp +++ b/dpctl-capi/tests/test_sycl_device_interface.cpp @@ -27,8 +27,6 @@ #include "dpctl_sycl_device_interface.h" #include "dpctl_sycl_device_selector_interface.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 @@ -217,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 4e28a9968b..530fc22d8d 100644 --- a/dpctl/_backend.pxd +++ b/dpctl/_backend.pxd @@ -73,6 +73,28 @@ cdef extern from "dpctl_sycl_enum_types.h": ctypedef _arg_data_type DPCTLKernelArgType + cdef enum _aspect_type 'DPCTLSyclAspectType': + _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 + cdef extern from "dpctl_sycl_types.h": cdef struct DPCTLOpaqueSyclContext @@ -119,13 +141,13 @@ 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) cdef bool DPCTLDevice_IsHost(const DPCTLSyclDeviceRef DRef) cdef bool DPCTLDevice_IsHostUnifiedMemory(const DPCTLSyclDeviceRef DRef) + cpdef bool DPCTLDevice_HasAspect( + const DPCTLSyclDeviceRef DRef, DPCTLSyclAspectType AT) cdef extern from "dpctl_sycl_device_selector_interface.h": diff --git a/dpctl/_sycl_device.pxd b/dpctl/_sycl_device.pxd index 2e0c76a296..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) @@ -57,8 +55,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 e8ea50bfc5..dec36d2767 100644 --- a/dpctl/_sycl_device.pyx +++ b/dpctl/_sycl_device.pyx @@ -21,6 +21,7 @@ """ from ._backend cimport ( + _aspect_type, _backend_type, _device_type, DPCTLAcceleratorSelector_Create, @@ -41,8 +42,6 @@ from ._backend cimport ( DPCTLDevice_GetMaxWorkItemSizes, DPCTLDevice_GetVendorName, DPCTLDevice_GetName, - DPCTLDevice_HasInt64BaseAtomics, - DPCTLDevice_HasInt64ExtendedAtomics, DPCTLDevice_IsAccelerator, DPCTLDevice_IsCPU, DPCTLDevice_IsGPU, @@ -55,6 +54,7 @@ from ._backend cimport ( DPCTLSyclBackendType, DPCTLSyclDeviceRef, DPCTLSyclDeviceSelectorRef, + DPCTLDevice_HasAspect, DPCTLSyclDeviceType, ) from . import backend_type, device_type @@ -158,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. @@ -311,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) @@ -337,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 @@ -395,6 +379,96 @@ cdef class SyclDevice(_SyclDevice): "a SYCL filter selector string." ) + @property + def has_aspect_host(self): + cdef _aspect_type AT = _aspect_type._host + return DPCTLDevice_HasAspect(self._device_ref, AT) + + @property + def has_aspect_cpu(self): + cdef _aspect_type AT = _aspect_type._cpu + return DPCTLDevice_HasAspect(self._device_ref, AT) + + @property + def has_aspect_gpu(self): + cdef _aspect_type AT = _aspect_type._gpu + return DPCTLDevice_HasAspect(self._device_ref, AT) + + @property + def has_aspect_accelerator(self): + cdef _aspect_type AT = _aspect_type._accelerator + return DPCTLDevice_HasAspect(self._device_ref, AT) + + @property + def has_aspect_custom(self): + cdef _aspect_type AT = _aspect_type._custom + return DPCTLDevice_HasAspect(self._device_ref, AT) + + @property + def has_aspect_fp16(self): + cdef _aspect_type AT = _aspect_type._fp16 + return DPCTLDevice_HasAspect(self._device_ref, AT) + + @property + def has_aspect_fp64(self): + cdef _aspect_type AT = _aspect_type._fp64 + return DPCTLDevice_HasAspect(self._device_ref, AT) + + @property + def has_aspect_int64_base_atomics(self): + cdef _aspect_type AT = _aspect_type._int64_base_atomics + return DPCTLDevice_HasAspect(self._device_ref, AT) + + @property + def has_aspect_int64_extended_atomics(self): + cdef _aspect_type AT = _aspect_type._int64_extended_atomics + return DPCTLDevice_HasAspect(self._device_ref, AT) + + @property + def has_aspect_image(self): + cdef _aspect_type AT = _aspect_type._image + return DPCTLDevice_HasAspect(self._device_ref, AT) + + @property + def has_aspect_online_compiler(self): + cdef _aspect_type AT = _aspect_type._online_compiler + return DPCTLDevice_HasAspect(self._device_ref, AT) + + @property + def has_aspect_online_linker(self): + cdef _aspect_type AT = _aspect_type._online_linker + return DPCTLDevice_HasAspect(self._device_ref, AT) + + @property + def has_aspect_queue_profiling(self): + cdef _aspect_type AT = _aspect_type._queue_profiling + return DPCTLDevice_HasAspect(self._device_ref, AT) + + @property + def has_aspect_usm_device_allocations(self): + cdef _aspect_type AT = _aspect_type._usm_device_allocations + return DPCTLDevice_HasAspect(self._device_ref, AT) + + @property + def has_aspect_usm_host_allocations(self): + cdef _aspect_type AT = _aspect_type._usm_host_allocations + return DPCTLDevice_HasAspect(self._device_ref, AT) + + @property + def has_aspect_usm_shared_allocations(self): + cdef _aspect_type AT = _aspect_type._usm_shared_allocations + return DPCTLDevice_HasAspect(self._device_ref, AT) + + @property + def has_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 has_aspect_usm_system_allocator(self): + cdef _aspect_type AT = _aspect_type._usm_system_allocator + 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 7df90c6df3..130e5cd82e 100644 --- a/dpctl/tests/test_sycl_device.py +++ b/dpctl/tests/test_sycl_device.py @@ -86,18 +86,130 @@ def check_get_max_num_sub_groups(device): assert max_num_sub_groups > 0 -def check_has_int64_base_atomics(device): +def check_has_aspect_host(device): try: - device.has_int64_base_atomics() + device.has_aspect_host except Exception: - pytest.fail("has_int64_base_atomics call failed") + pytest.fail("has_aspect_host call failed") -def check_has_int64_extended_atomics(device): +def check_has_aspect_cpu(device): try: - device.has_int64_extended_atomics() + device.has_aspect_cpu except Exception: - pytest.fail("has_int64_extended_atomics call failed") + pytest.fail("has_aspect_cpu call failed") + + +def check_has_aspect_gpu(device): + try: + device.has_aspect_gpu + except Exception: + pytest.fail("has_aspect_gpu call failed") + + +def check_has_aspect_accelerator(device): + try: + device.has_aspect_accelerator + except Exception: + pytest.fail("has_aspect_accelerator call failed") + + +def check_has_aspect_custom(device): + try: + device.has_aspect_custom + except Exception: + pytest.fail("has_aspect_custom call failed") + + +def check_has_aspect_fp16(device): + try: + device.has_aspect_fp16 + except Exception: + pytest.fail("has_aspect_fp16 call failed") + + +def check_has_aspect_fp64(device): + try: + device.has_aspect_fp64 + except Exception: + pytest.fail("has_aspect_fp64 call failed") + + +def check_has_aspect_int64_base_atomics(device): + try: + device.has_aspect_int64_base_atomics + except Exception: + pytest.fail("has_aspect_int64_base_atomics call failed") + + +def check_has_aspect_int64_extended_atomics(device): + try: + device.has_aspect_int64_extended_atomics + except Exception: + pytest.fail("has_aspect_int64_extended_atomics call failed") + + +def check_has_aspect_image(device): + try: + device.has_aspect_image + except Exception: + pytest.fail("has_aspect_image call failed") + + +def check_has_aspect_online_compiler(device): + try: + device.has_aspect_online_compiler + except Exception: + pytest.fail("has_aspect_online_compiler call failed") + + +def check_has_aspect_online_linker(device): + try: + device.has_aspect_online_linker + except Exception: + pytest.fail("has_aspect_online_linker call failed") + + +def check_has_aspect_queue_profiling(device): + try: + device.has_aspect_queue_profiling + except Exception: + pytest.fail("has_aspect_queue_profiling call failed") + + +def check_has_aspect_usm_device_allocations(device): + try: + device.has_aspect_usm_device_allocations + except Exception: + pytest.fail("has_aspect_usm_device_allocations call failed") + + +def check_has_aspect_usm_host_allocations(device): + try: + device.has_aspect_usm_host_allocations + except Exception: + pytest.fail("has_aspect_usm_host_allocations call failed") + + +def check_has_aspect_usm_shared_allocations(device): + try: + device.has_aspect_usm_shared_allocations + except Exception: + pytest.fail("has_aspect_usm_shared_allocations call failed") + + +def check_has_aspect_usm_restricted_shared_allocations(device): + try: + device.has_aspect_usm_restricted_shared_allocations + except Exception: + pytest.fail("has_aspect_usm_restricted_shared_allocations call failed") + + +def check_has_aspect_usm_system_allocator(device): + try: + device.has_aspect_usm_system_allocator + except Exception: + pytest.fail("has_aspect_usm_system_allocator call failed") def check_is_accelerator(device): @@ -134,12 +246,28 @@ 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_host, + check_has_aspect_cpu, + check_has_aspect_gpu, + check_has_aspect_accelerator, + check_has_aspect_custom, + check_has_aspect_fp16, + check_has_aspect_fp64, + 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_shared_allocations, + check_has_aspect_usm_restricted_shared_allocations, + check_has_aspect_usm_system_allocator, ]