From 865ef9d9ca1b0c0f4b3df63918172f50832516b3 Mon Sep 17 00:00:00 2001 From: etotmeni Date: Wed, 17 Mar 2021 09:13:57 -0500 Subject: [PATCH 01/23] wip --- .../include/dpctl_sycl_device_interface.h | 19 +++++++++++++++++ .../source/dpctl_sycl_device_interface.cpp | 21 +++++++++++++++++++ .../tests/test_sycl_device_interface.cpp | 11 ++++++++++ 3 files changed, 51 insertions(+) diff --git a/dpctl-capi/include/dpctl_sycl_device_interface.h b/dpctl-capi/include/dpctl_sycl_device_interface.h index 62d292ce31..b3132dc2ae 100644 --- a/dpctl-capi/include/dpctl_sycl_device_interface.h +++ b/dpctl-capi/include/dpctl_sycl_device_interface.h @@ -31,6 +31,7 @@ #include "Support/ExternC.h" #include "Support/MemOwnershipAttrs.h" #include "dpctl_data_types.h" +#include "dpctl_sycl_device_manager.h" #include "dpctl_sycl_enum_types.h" #include "dpctl_sycl_types.h" @@ -265,4 +266,22 @@ DPCTL_API bool DPCTLDevice_HasAspect(__dpctl_keep const DPCTLSyclDeviceRef DRef, DPCTLSyclAspectType AT); +/*! + * @brief Returns a vector of sub devices + * partitioned from this SYCL device based on the count parameter. The returned + * vector contains as many sub devices as can be created such that each sub + * device contains count compute units. If the device’s total number of compute + * units is not evenly divided by count, then the remaining compute units are + * not included in any of the sub devices. + * + * @param DRef Opaque pointer to a sycl::device + * @param count Count compute units that need to contains in + * subdevices + * @return A #DPCTLDeviceVectorRef containing #DPCTLSyclDeviceRef objects + */ +DPCTL_API +__dpctl_give DPCTLDeviceVectorRef +DPCTLDevice_CreateSubDevicesEqually(__dpctl_keep const DPCTLSyclDeviceRef DRef, + size_t count); + 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 7f6405f667..6d81fe9433 100644 --- a/dpctl-capi/source/dpctl_sycl_device_interface.cpp +++ b/dpctl-capi/source/dpctl_sycl_device_interface.cpp @@ -387,3 +387,24 @@ bool DPCTLDevice_HasAspect(__dpctl_keep const DPCTLSyclDeviceRef DRef, } return hasAspect; } + +__dpctl_give DPCTLDeviceVectorRef +DPCTLDevice_CreateSubDevicesEqually(__dpctl_keep const DPCTLSyclDeviceRef DRef, + size_t count) +{ + vector_class *Devices = nullptr; + auto D = unwrap(DRef); + if (D) { + try { + auto max_compute_units = DPCTLDevice_GetMaxComputeUnits(DRef); + auto subdevices = int(max_compute_units / count); + for (int i = 0; i < subdevices; ++i) { + Devices->emplace_back(wrap(new cl::sycl::device(count))); + } + } catch (runtime_error const &re) { + // \todo log error + std::cerr << re.what() << '\n'; + } + } + return wrap(Devices); +} diff --git a/dpctl-capi/tests/test_sycl_device_interface.cpp b/dpctl-capi/tests/test_sycl_device_interface.cpp index 97483d1ce6..0a8bf6fa26 100644 --- a/dpctl-capi/tests/test_sycl_device_interface.cpp +++ b/dpctl-capi/tests/test_sycl_device_interface.cpp @@ -255,6 +255,17 @@ TEST_P(TestDPCTLSyclDeviceInterface, Chk_IsHost) EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef)); } +TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesEqually) +{ + DPCTLSyclDeviceRef DRef = nullptr; + EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef)); + if (!DRef) + GTEST_SKIP_("Device not found"); + int count = 10; + EXPECT_NO_FATAL_FAILURE(DPCTLDevice_CreateSubDevicesEqually(DRef, count)); + EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef)); +} + INSTANTIATE_TEST_SUITE_P(DPCTLDevice_Fns, TestDPCTLSyclDeviceInterface, ::testing::Values("opencl", From 1979b634ab30972c3424b0b47dec291477c542b4 Mon Sep 17 00:00:00 2001 From: etotmeni Date: Mon, 22 Mar 2021 08:58:21 -0500 Subject: [PATCH 02/23] Added C-api initial for all sub-device funcs --- .../helper/include/dpctl_utils_helper.h | 27 +++++++ .../helper/source/dpctl_utils_helper.cpp | 46 ++++++++++++ .../include/dpctl_sycl_device_interface.h | 32 +++++++++ dpctl-capi/include/dpctl_sycl_enum_types.h | 15 ++++ .../source/dpctl_sycl_device_interface.cpp | 72 +++++++++++++++++-- .../tests/test_sycl_device_interface.cpp | 65 ++++++++++++++++- 6 files changed, 251 insertions(+), 6 deletions(-) diff --git a/dpctl-capi/helper/include/dpctl_utils_helper.h b/dpctl-capi/helper/include/dpctl_utils_helper.h index d87570aec8..cfe2f4f5bc 100644 --- a/dpctl-capi/helper/include/dpctl_utils_helper.h +++ b/dpctl-capi/helper/include/dpctl_utils_helper.h @@ -138,3 +138,30 @@ sycl::aspect DPCTL_DPCTLAspectTypeToSyclAspect(DPCTLSyclAspectType AspectTy); * @throws runtime_error */ DPCTLSyclAspectType DPCTL_SyclAspectToDPCTLAspectType(sycl::aspect Aspect); + +/*! + * @brief Converts a DPCTLPartitionAffinityDomainType enum value to its + * corresponding sycl::info::partition_affinity_domain enum value. + * + * @param PartitionAffinityDomainTy A + * DPCTLPartitionAffinityDomainType enum value + * @return A sycl::info::partition_affinity_domain enum value for the input + * DPCTLPartitionAffinityDomainType enum value. + * @throws runtime_error + */ +sycl::info::partition_affinity_domain +DPCTL_DPCTLPartitionAffinityDomainTypeToSycl( + DPCTLPartitionAffinityDomainType PartitionAffinityDomainTy); + +/*! + * @brief Converts a sycl::info::partition_affinity_domain enum value to + * corresponding DPCTLPartitionAffinityDomainType enum value. + * + * @param PartitionAffinityDomain sycl::info::partition_affinity_domain to be + * converted to DPCTLPartitionAffinityDomainType enum. + * @return A DPCTLPartitionAffinityDomainType enum value for the input + * sycl::info::partition_affinity_domain enum value. + * @throws runtime_error + */ +DPCTLPartitionAffinityDomainType DPCTL_SyclPartitionAffinityDomainToDPCTLType( + sycl::info::partition_affinity_domain PartitionAffinityDomain); diff --git a/dpctl-capi/helper/source/dpctl_utils_helper.cpp b/dpctl-capi/helper/source/dpctl_utils_helper.cpp index d90ab3c4ce..bd498951a4 100644 --- a/dpctl-capi/helper/source/dpctl_utils_helper.cpp +++ b/dpctl-capi/helper/source/dpctl_utils_helper.cpp @@ -382,3 +382,49 @@ DPCTLSyclAspectType DPCTL_SyclAspectToDPCTLAspectType(aspect Aspect) throw runtime_error("Unsupported aspect type", -1); } } + +info::partition_affinity_domain DPCTL_DPCTLPartitionAffinityDomainTypeToSycl( + DPCTLPartitionAffinityDomainType PartitionAffinityDomainTy) +{ + switch (PartitionAffinityDomainTy) { + case DPCTLPartitionAffinityDomainType::not_applicable: + return info::partition_affinity_domain::not_applicable; + case DPCTLPartitionAffinityDomainType::numa: + return info::partition_affinity_domain::numa; + case DPCTLPartitionAffinityDomainType::L4_cache: + return info::partition_affinity_domain::L4_cache; + case DPCTLPartitionAffinityDomainType::L3_cache: + return info::partition_affinity_domain::L3_cache; + case DPCTLPartitionAffinityDomainType::L2_cache: + return info::partition_affinity_domain::L2_cache; + case DPCTLPartitionAffinityDomainType::L1_cache: + return info::partition_affinity_domain::L1_cache; + case DPCTLPartitionAffinityDomainType::next_partitionable: + return info::partition_affinity_domain::next_partitionable; + default: + throw runtime_error("Unsupported partition_affinity_domain type", -1); + } +} + +DPCTLPartitionAffinityDomainType DPCTL_SyclPartitionAffinityDomainToDPCTLType( + sycl::info::partition_affinity_domain PartitionAffinityDomain) +{ + switch (PartitionAffinityDomain) { + case info::partition_affinity_domain::not_applicable: + return DPCTLPartitionAffinityDomainType::not_applicable; + case info::partition_affinity_domain::numa: + return DPCTLPartitionAffinityDomainType::numa; + case info::partition_affinity_domain::L4_cache: + return DPCTLPartitionAffinityDomainType::L4_cache; + case info::partition_affinity_domain::L3_cache: + return DPCTLPartitionAffinityDomainType::L3_cache; + case info::partition_affinity_domain::L2_cache: + return DPCTLPartitionAffinityDomainType::L2_cache; + case info::partition_affinity_domain::L1_cache: + return DPCTLPartitionAffinityDomainType::L1_cache; + case info::partition_affinity_domain::next_partitionable: + return DPCTLPartitionAffinityDomainType::next_partitionable; + default: + throw runtime_error("Unsupported partition_affinity_domain type", -1); + } +} diff --git a/dpctl-capi/include/dpctl_sycl_device_interface.h b/dpctl-capi/include/dpctl_sycl_device_interface.h index b3132dc2ae..dce43b22b1 100644 --- a/dpctl-capi/include/dpctl_sycl_device_interface.h +++ b/dpctl-capi/include/dpctl_sycl_device_interface.h @@ -34,6 +34,7 @@ #include "dpctl_sycl_device_manager.h" #include "dpctl_sycl_enum_types.h" #include "dpctl_sycl_types.h" +#include DPCTL_C_EXTERN_C_BEGIN @@ -284,4 +285,35 @@ __dpctl_give DPCTLDeviceVectorRef DPCTLDevice_CreateSubDevicesEqually(__dpctl_keep const DPCTLSyclDeviceRef DRef, size_t count); +/*! + * @brief Returns a vector of sub devices + * partitioned from this SYCL device based on the counts parameter. For each + * non-zero value M in the counts vector, a sub device with M compute units + * is created. + * + * @param DRef Opaque pointer to a sycl::device + * @param vector &counts Vector with count compute units + * that need to contains in subdevices + * @return A #DPCTLDeviceVectorRef containing #DPCTLSyclDeviceRef objects + */ +DPCTL_API +__dpctl_give DPCTLDeviceVectorRef +DPCTLDevice_CreateSubDevicesByCounts(__dpctl_keep const DPCTLSyclDeviceRef DRef, + const std::vector &counts); + +/*! + * @brief Returns a vector of sub devices + * partitioned from this SYCL device by affinity domain based on the domain + * parameter. + * + * @param DRef Opaque pointer to a sycl::device + * @param DPCTLPartitionAffinityDomainType DPCTLPartitionAffinityDomainType + * of sycl::info::partition_affinity_domain + * @return A #DPCTLDeviceVectorRef containing #DPCTLSyclDeviceRef objects + */ +DPCTL_API +__dpctl_give DPCTLDeviceVectorRef DPCTLDevice_CreateSubDevicesByAffinity( + __dpctl_keep const DPCTLSyclDeviceRef DRef, + DPCTLPartitionAffinityDomainType PartitionAffinityDomainTy); + 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 b69b67ea07..d102ff14b0 100644 --- a/dpctl-capi/include/dpctl_sycl_enum_types.h +++ b/dpctl-capi/include/dpctl_sycl_enum_types.h @@ -122,6 +122,21 @@ enum DPCTLSyclAspectType usm_system_allocator }; +/*! + * @brief DPCTL analogue of sycl::info::partition_affinity_domain enum + * + */ +enum DPCTLPartitionAffinityDomainType +{ + not_applicable, + numa, + L4_cache, + L3_cache, + L2_cache, + L1_cache, + next_partitionable +}; + /*! * @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 6d81fe9433..2d68c00b6e 100644 --- a/dpctl-capi/source/dpctl_sycl_device_interface.cpp +++ b/dpctl-capi/source/dpctl_sycl_device_interface.cpp @@ -39,6 +39,8 @@ namespace DEFINE_SIMPLE_CONVERSION_FUNCTIONS(device, DPCTLSyclDeviceRef) DEFINE_SIMPLE_CONVERSION_FUNCTIONS(device_selector, DPCTLSyclDeviceSelectorRef) DEFINE_SIMPLE_CONVERSION_FUNCTIONS(platform, DPCTLSyclPlatformRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(vector_class, + DPCTLDeviceVectorRef) } /* end of anonymous namespace */ @@ -396,11 +398,73 @@ DPCTLDevice_CreateSubDevicesEqually(__dpctl_keep const DPCTLSyclDeviceRef DRef, auto D = unwrap(DRef); if (D) { try { - auto max_compute_units = DPCTLDevice_GetMaxComputeUnits(DRef); - auto subdevices = int(max_compute_units / count); - for (int i = 0; i < subdevices; ++i) { - Devices->emplace_back(wrap(new cl::sycl::device(count))); + auto subDevices = D->create_sub_devices< + info::partition_property::partition_equally>(count); + Devices = new vector_class(); + for (auto &sd : subDevices) { + Devices->emplace_back(wrap(new device(sd))); } + } catch (std::bad_alloc const &ba) { + std::cerr << ba.what() << '\n'; + return nullptr; + } catch (feature_not_supported const &fnse) { + std::cerr << fnse.what() << '\n'; + } catch (runtime_error const &re) { + // \todo log error + std::cerr << re.what() << '\n'; + } + } + return wrap(Devices); +} + +__dpctl_give DPCTLDeviceVectorRef +DPCTLDevice_CreateSubDevicesByCounts(__dpctl_keep const DPCTLSyclDeviceRef DRef, + const std::vector &counts) +{ + vector_class *Devices = nullptr; + auto D = unwrap(DRef); + if (D) { + try { + auto subDevices = D->create_sub_devices< + info::partition_property::partition_by_counts>(counts); + Devices = new vector_class(); + for (auto &sd : subDevices) { + Devices->emplace_back(wrap(new device(sd))); + } + } catch (std::bad_alloc const &ba) { + std::cerr << ba.what() << '\n'; + return nullptr; + } catch (feature_not_supported const &fnse) { + std::cerr << fnse.what() << '\n'; + } catch (runtime_error const &re) { + // \todo log error + std::cerr << re.what() << '\n'; + } + } + return wrap(Devices); +} + +__dpctl_give DPCTLDeviceVectorRef DPCTLDevice_CreateSubDevicesByAffinity( + __dpctl_keep const DPCTLSyclDeviceRef DRef, + DPCTLPartitionAffinityDomainType PartitionAffinityDomainTy) +{ + vector_class *Devices = nullptr; + auto D = unwrap(DRef); + if (D) { + try { + auto domain = DPCTL_DPCTLPartitionAffinityDomainTypeToSycl( + PartitionAffinityDomainTy); + auto subDevices = D->create_sub_devices< + info::partition_property::partition_by_affinity_domain>(domain); + Devices = new vector_class(); + for (auto &sd : subDevices) { + Devices->emplace_back(wrap(new device(sd))); + } + } catch (std::bad_alloc const &ba) { + std::cerr << ba.what() << '\n'; + return nullptr; + } catch (feature_not_supported const &fnse) { + std::cerr << fnse.what() << '\n'; } catch (runtime_error const &re) { // \todo log error std::cerr << re.what() << '\n'; diff --git a/dpctl-capi/tests/test_sycl_device_interface.cpp b/dpctl-capi/tests/test_sycl_device_interface.cpp index 0a8bf6fa26..f1900c86b4 100644 --- a/dpctl-capi/tests/test_sycl_device_interface.cpp +++ b/dpctl-capi/tests/test_sycl_device_interface.cpp @@ -26,6 +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_utils.h" #include @@ -258,11 +259,71 @@ TEST_P(TestDPCTLSyclDeviceInterface, Chk_IsHost) TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesEqually) { DPCTLSyclDeviceRef DRef = nullptr; + DPCTLDeviceVectorRef DVRef = nullptr; + uint32_t maxCUs = 0; + + EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef)); + if (!DRef) + GTEST_SKIP_("Device not found"); + + EXPECT_NO_FATAL_FAILURE(maxCUs = DPCTLDevice_GetMaxComputeUnits(DRef)); + if (maxCUs) { + int count = maxCUs / 2; + EXPECT_NO_FATAL_FAILURE( + DVRef = DPCTLDevice_CreateSubDevicesEqually(DRef, count)); + if (DVRef) { + EXPECT_TRUE(DPCTLDeviceVector_Size(DVRef) > 0); + EXPECT_NO_FATAL_FAILURE(DPCTLDeviceVector_Delete(DVRef)); + } + } + + EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef)); +} + +TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesByCounts) +{ + DPCTLSyclDeviceRef DRef = nullptr; + DPCTLDeviceVectorRef DVRef = nullptr; + uint32_t maxCUs = 0; + EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef)); if (!DRef) GTEST_SKIP_("Device not found"); - int count = 10; - EXPECT_NO_FATAL_FAILURE(DPCTLDevice_CreateSubDevicesEqually(DRef, count)); + + EXPECT_NO_FATAL_FAILURE(maxCUs = DPCTLDevice_GetMaxComputeUnits(DRef)); + if (maxCUs) { + size_t count = maxCUs / 2; + const std::vector counts{count, count}; + EXPECT_NO_FATAL_FAILURE( + DVRef = DPCTLDevice_CreateSubDevicesByCounts(DRef, counts)); + if (DVRef) { + EXPECT_TRUE(DPCTLDeviceVector_Size(DVRef) > 0); + EXPECT_NO_FATAL_FAILURE(DPCTLDeviceVector_Delete(DVRef)); + } + } + + EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef)); +} + +TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesByAffinity) +{ + DPCTLSyclDeviceRef DRef = nullptr; + DPCTLDeviceVectorRef DVRef = nullptr; + DPCTLPartitionAffinityDomainType domain = numa; + + EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef)); + if (!DRef) + GTEST_SKIP_("Device not found"); + + if (domain) { + EXPECT_NO_FATAL_FAILURE( + DVRef = DPCTLDevice_CreateSubDevicesByAffinity(DRef, domain)); + if (DVRef) { + EXPECT_TRUE(DPCTLDeviceVector_Size(DVRef) > 0); + EXPECT_NO_FATAL_FAILURE(DPCTLDeviceVector_Delete(DVRef)); + } + } + EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef)); } From df044856b4b43458bb731b1f192846d25d7458be Mon Sep 17 00:00:00 2001 From: etotmeni Date: Tue, 23 Mar 2021 11:12:33 -0500 Subject: [PATCH 03/23] Change vector type + Added tests --- .../include/dpctl_sycl_device_interface.h | 6 +- .../source/dpctl_sycl_device_interface.cpp | 7 +- .../tests/test_sycl_device_interface.cpp | 72 ---- .../tests/test_sycl_device_subdevices.cpp | 382 ++++++++++++++++++ 4 files changed, 391 insertions(+), 76 deletions(-) create mode 100644 dpctl-capi/tests/test_sycl_device_subdevices.cpp diff --git a/dpctl-capi/include/dpctl_sycl_device_interface.h b/dpctl-capi/include/dpctl_sycl_device_interface.h index dce43b22b1..eff3ff6dd5 100644 --- a/dpctl-capi/include/dpctl_sycl_device_interface.h +++ b/dpctl-capi/include/dpctl_sycl_device_interface.h @@ -292,14 +292,16 @@ DPCTLDevice_CreateSubDevicesEqually(__dpctl_keep const DPCTLSyclDeviceRef DRef, * is created. * * @param DRef Opaque pointer to a sycl::device - * @param vector &counts Vector with count compute units + * @param counts Array with count compute units * that need to contains in subdevices + * @param ncounts Number of counts * @return A #DPCTLDeviceVectorRef containing #DPCTLSyclDeviceRef objects */ DPCTL_API __dpctl_give DPCTLDeviceVectorRef DPCTLDevice_CreateSubDevicesByCounts(__dpctl_keep const DPCTLSyclDeviceRef DRef, - const std::vector &counts); + __dpctl_keep size_t *counts, + size_t ncounts); /*! * @brief Returns a vector of sub devices diff --git a/dpctl-capi/source/dpctl_sycl_device_interface.cpp b/dpctl-capi/source/dpctl_sycl_device_interface.cpp index 2d68c00b6e..8388841e84 100644 --- a/dpctl-capi/source/dpctl_sycl_device_interface.cpp +++ b/dpctl-capi/source/dpctl_sycl_device_interface.cpp @@ -419,14 +419,17 @@ DPCTLDevice_CreateSubDevicesEqually(__dpctl_keep const DPCTLSyclDeviceRef DRef, __dpctl_give DPCTLDeviceVectorRef DPCTLDevice_CreateSubDevicesByCounts(__dpctl_keep const DPCTLSyclDeviceRef DRef, - const std::vector &counts) + __dpctl_keep size_t *counts, + size_t ncounts) { vector_class *Devices = nullptr; + std::vector vcounts; + vcounts.assign(counts, counts + ncounts); auto D = unwrap(DRef); if (D) { try { auto subDevices = D->create_sub_devices< - info::partition_property::partition_by_counts>(counts); + info::partition_property::partition_by_counts>(vcounts); Devices = new vector_class(); for (auto &sd : subDevices) { Devices->emplace_back(wrap(new device(sd))); diff --git a/dpctl-capi/tests/test_sycl_device_interface.cpp b/dpctl-capi/tests/test_sycl_device_interface.cpp index 284774e101..a25f35d926 100644 --- a/dpctl-capi/tests/test_sycl_device_interface.cpp +++ b/dpctl-capi/tests/test_sycl_device_interface.cpp @@ -26,7 +26,6 @@ #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_utils.h" #include @@ -269,77 +268,6 @@ TEST_P(TestDPCTLSyclDeviceInterface, Chk_IsHost) EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef)); } -TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesEqually) -{ - DPCTLSyclDeviceRef DRef = nullptr; - DPCTLDeviceVectorRef DVRef = nullptr; - uint32_t maxCUs = 0; - - EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef)); - if (!DRef) - GTEST_SKIP_("Device not found"); - - EXPECT_NO_FATAL_FAILURE(maxCUs = DPCTLDevice_GetMaxComputeUnits(DRef)); - if (maxCUs) { - int count = maxCUs / 2; - EXPECT_NO_FATAL_FAILURE( - DVRef = DPCTLDevice_CreateSubDevicesEqually(DRef, count)); - if (DVRef) { - EXPECT_TRUE(DPCTLDeviceVector_Size(DVRef) > 0); - EXPECT_NO_FATAL_FAILURE(DPCTLDeviceVector_Delete(DVRef)); - } - } - - EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef)); -} - -TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesByCounts) -{ - DPCTLSyclDeviceRef DRef = nullptr; - DPCTLDeviceVectorRef DVRef = nullptr; - uint32_t maxCUs = 0; - - EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef)); - if (!DRef) - GTEST_SKIP_("Device not found"); - - EXPECT_NO_FATAL_FAILURE(maxCUs = DPCTLDevice_GetMaxComputeUnits(DRef)); - if (maxCUs) { - size_t count = maxCUs / 2; - const std::vector counts{count, count}; - EXPECT_NO_FATAL_FAILURE( - DVRef = DPCTLDevice_CreateSubDevicesByCounts(DRef, counts)); - if (DVRef) { - EXPECT_TRUE(DPCTLDeviceVector_Size(DVRef) > 0); - EXPECT_NO_FATAL_FAILURE(DPCTLDeviceVector_Delete(DVRef)); - } - } - - EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef)); -} - -TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesByAffinity) -{ - DPCTLSyclDeviceRef DRef = nullptr; - DPCTLDeviceVectorRef DVRef = nullptr; - DPCTLPartitionAffinityDomainType domain = numa; - - EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef)); - if (!DRef) - GTEST_SKIP_("Device not found"); - - if (domain) { - EXPECT_NO_FATAL_FAILURE( - DVRef = DPCTLDevice_CreateSubDevicesByAffinity(DRef, domain)); - if (DVRef) { - EXPECT_TRUE(DPCTLDeviceVector_Size(DVRef) > 0); - EXPECT_NO_FATAL_FAILURE(DPCTLDeviceVector_Delete(DVRef)); - } - } - - EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef)); -} - INSTANTIATE_TEST_SUITE_P(DPCTLDevice_Fns, TestDPCTLSyclDeviceInterface, ::testing::Values("opencl", diff --git a/dpctl-capi/tests/test_sycl_device_subdevices.cpp b/dpctl-capi/tests/test_sycl_device_subdevices.cpp new file mode 100644 index 0000000000..d052b73bf8 --- /dev/null +++ b/dpctl-capi/tests/test_sycl_device_subdevices.cpp @@ -0,0 +1,382 @@ +//===--- test_sycl_device_interface.cpp - Test cases for device interface ===// +// +// Data Parallel Control (dpCtl) +// +// Copyright 2020-2021 Intel Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// This file has unit test cases for functions defined in +/// dpctl_sycl_device_interface.h. +/// +//===----------------------------------------------------------------------===// + +#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 "dpctl_sycl_platform_interface.h" +#include "dpctl_utils.h" +#include +#include + +using namespace cl::sycl; + +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(device, DPCTLSyclDeviceRef); + +struct TestDPCTLSyclDeviceInterface + : public ::testing::TestWithParam +{ + DPCTLSyclDeviceSelectorRef DSRef = nullptr; + + TestDPCTLSyclDeviceInterface() + { + EXPECT_NO_FATAL_FAILURE(DSRef = DPCTLFilterSelector_Create(GetParam())); + } + + void SetUp() + { + if (!DSRef) { + auto message = "Skipping as no device of type " + + std::string(GetParam()) + "."; + GTEST_SKIP_(message.c_str()); + } + } + + ~TestDPCTLSyclDeviceInterface() + { + EXPECT_NO_FATAL_FAILURE(DPCTLDeviceSelector_Delete(DSRef)); + } +}; + +TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesEqually) +{ + DPCTLSyclDeviceRef DRef = nullptr; + DPCTLDeviceVectorRef DVRef = nullptr; + uint32_t maxCUs = 0; + + EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef)); + if (!DRef) + GTEST_SKIP_("Device not found"); + + EXPECT_NO_FATAL_FAILURE(maxCUs = DPCTLDevice_GetMaxComputeUnits(DRef)); + if (maxCUs) { + int count = maxCUs / 2; + EXPECT_NO_FATAL_FAILURE( + DVRef = DPCTLDevice_CreateSubDevicesEqually(DRef, count)); + if (DVRef) { + EXPECT_TRUE(DPCTLDeviceVector_Size(DVRef) > 0); + EXPECT_NO_FATAL_FAILURE(DPCTLDeviceVector_Delete(DVRef)); + } + } + + EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef)); +} + +TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesByCounts) +{ + DPCTLSyclDeviceRef DRef = nullptr; + DPCTLDeviceVectorRef DVRef = nullptr; + uint32_t maxCUs = 0; + + EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef)); + if (!DRef) + GTEST_SKIP_("Device not found"); + + EXPECT_NO_FATAL_FAILURE(maxCUs = DPCTLDevice_GetMaxComputeUnits(DRef)); + if (maxCUs) { + size_t count = maxCUs / 2; + size_t *counts = nullptr; + int n = 2; + counts = new size_t[n]; + for (auto i = 0; i < n; ++i) { + counts[i] = count; + } + EXPECT_NO_FATAL_FAILURE( + DVRef = DPCTLDevice_CreateSubDevicesByCounts(DRef, counts, n)); + if (DVRef) { + EXPECT_TRUE(DPCTLDeviceVector_Size(DVRef) > 0); + EXPECT_NO_FATAL_FAILURE(DPCTLDeviceVector_Delete(DVRef)); + } + } + + EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef)); +} + +TEST_P(TestDPCTLSyclDeviceInterface, + Chk_CreateSubDevicesByAffinityNotApplicable) +{ + DPCTLSyclDeviceRef DRef = nullptr; + DPCTLDeviceVectorRef DVRef = nullptr; + + info::partition_affinity_domain domain = + info::partition_affinity_domain::not_applicable; + DPCTLPartitionAffinityDomainType dpctl_domain = + DPCTL_SyclPartitionAffinityDomainToDPCTLType(domain); + + EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef)); + if (!DRef) + GTEST_SKIP_("Device not found"); + + if (dpctl_domain) { + EXPECT_NO_FATAL_FAILURE( + DVRef = DPCTLDevice_CreateSubDevicesByAffinity(DRef, dpctl_domain)); + + auto D = unwrap(DRef); + try { + auto subDevices = D->create_sub_devices< + info::partition_property::partition_by_affinity_domain>(domain); + auto expected_size = subDevices.size(); + + if (DVRef) { + EXPECT_TRUE(DPCTLDeviceVector_Size(DVRef) == expected_size); + EXPECT_NO_FATAL_FAILURE(DPCTLDeviceVector_Delete(DVRef)); + } + } catch (runtime_error const &re) { + } + } + + EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef)); +} + +TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesByAffinityNuma) +{ + DPCTLSyclDeviceRef DRef = nullptr; + DPCTLDeviceVectorRef DVRef = nullptr; + + info::partition_affinity_domain domain = + info::partition_affinity_domain::numa; + DPCTLPartitionAffinityDomainType dpctl_domain = + DPCTL_SyclPartitionAffinityDomainToDPCTLType(domain); + + EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef)); + if (!DRef) + GTEST_SKIP_("Device not found"); + + if (dpctl_domain) { + EXPECT_NO_FATAL_FAILURE( + DVRef = DPCTLDevice_CreateSubDevicesByAffinity(DRef, dpctl_domain)); + + auto D = unwrap(DRef); + size_t expected_size = 0; + try { + auto subDevices = D->create_sub_devices< + info::partition_property::partition_by_affinity_domain>(domain); + expected_size = subDevices.size(); + } catch (runtime_error const &re) { + } + + if (DVRef && expected_size) { + EXPECT_TRUE(DPCTLDeviceVector_Size(DVRef) == expected_size); + EXPECT_NO_FATAL_FAILURE(DPCTLDeviceVector_Delete(DVRef)); + } + } + + EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef)); +} + +TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesByAffinityL4Cache) +{ + DPCTLSyclDeviceRef DRef = nullptr; + DPCTLDeviceVectorRef DVRef = nullptr; + + info::partition_affinity_domain domain = + info::partition_affinity_domain::L4_cache; + DPCTLPartitionAffinityDomainType dpctl_domain = + DPCTL_SyclPartitionAffinityDomainToDPCTLType(domain); + + EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef)); + if (!DRef) + GTEST_SKIP_("Device not found"); + + if (dpctl_domain) { + EXPECT_NO_FATAL_FAILURE( + DVRef = DPCTLDevice_CreateSubDevicesByAffinity(DRef, dpctl_domain)); + + auto D = unwrap(DRef); + try { + auto subDevices = D->create_sub_devices< + info::partition_property::partition_by_affinity_domain>(domain); + auto expected_size = subDevices.size(); + + if (DVRef) { + EXPECT_TRUE(DPCTLDeviceVector_Size(DVRef) == expected_size); + EXPECT_NO_FATAL_FAILURE(DPCTLDeviceVector_Delete(DVRef)); + } + } catch (runtime_error const &re) { + } + } + + EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef)); +} + +TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesByAffinityL3Cache) +{ + DPCTLSyclDeviceRef DRef = nullptr; + DPCTLDeviceVectorRef DVRef = nullptr; + + info::partition_affinity_domain domain = + info::partition_affinity_domain::L3_cache; + DPCTLPartitionAffinityDomainType dpctl_domain = + DPCTL_SyclPartitionAffinityDomainToDPCTLType(domain); + + EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef)); + if (!DRef) + GTEST_SKIP_("Device not found"); + + if (dpctl_domain) { + EXPECT_NO_FATAL_FAILURE( + DVRef = DPCTLDevice_CreateSubDevicesByAffinity(DRef, dpctl_domain)); + + auto D = unwrap(DRef); + try { + auto subDevices = D->create_sub_devices< + info::partition_property::partition_by_affinity_domain>(domain); + auto expected_size = subDevices.size(); + + if (DVRef) { + EXPECT_TRUE(DPCTLDeviceVector_Size(DVRef) == expected_size); + EXPECT_NO_FATAL_FAILURE(DPCTLDeviceVector_Delete(DVRef)); + } + } catch (runtime_error const &re) { + } + } + + EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef)); +} + +TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesByAffinityL2Cache) +{ + DPCTLSyclDeviceRef DRef = nullptr; + DPCTLDeviceVectorRef DVRef = nullptr; + + info::partition_affinity_domain domain = + info::partition_affinity_domain::L2_cache; + DPCTLPartitionAffinityDomainType dpctl_domain = + DPCTL_SyclPartitionAffinityDomainToDPCTLType(domain); + + EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef)); + if (!DRef) + GTEST_SKIP_("Device not found"); + + if (dpctl_domain) { + EXPECT_NO_FATAL_FAILURE( + DVRef = DPCTLDevice_CreateSubDevicesByAffinity(DRef, dpctl_domain)); + + auto D = unwrap(DRef); + try { + auto subDevices = D->create_sub_devices< + info::partition_property::partition_by_affinity_domain>(domain); + auto expected_size = subDevices.size(); + + if (DVRef) { + EXPECT_TRUE(DPCTLDeviceVector_Size(DVRef) == expected_size); + EXPECT_NO_FATAL_FAILURE(DPCTLDeviceVector_Delete(DVRef)); + } + } catch (runtime_error const &re) { + } + } + + EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef)); +} + +TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesByAffinityL1Cache) +{ + DPCTLSyclDeviceRef DRef = nullptr; + DPCTLDeviceVectorRef DVRef = nullptr; + + info::partition_affinity_domain domain = + info::partition_affinity_domain::L1_cache; + DPCTLPartitionAffinityDomainType dpctl_domain = + DPCTL_SyclPartitionAffinityDomainToDPCTLType(domain); + + EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef)); + if (!DRef) + GTEST_SKIP_("Device not found"); + + if (dpctl_domain) { + EXPECT_NO_FATAL_FAILURE( + DVRef = DPCTLDevice_CreateSubDevicesByAffinity(DRef, dpctl_domain)); + + auto D = unwrap(DRef); + try { + auto subDevices = D->create_sub_devices< + info::partition_property::partition_by_affinity_domain>(domain); + auto expected_size = subDevices.size(); + + if (DVRef) { + EXPECT_TRUE(DPCTLDeviceVector_Size(DVRef) == expected_size); + EXPECT_NO_FATAL_FAILURE(DPCTLDeviceVector_Delete(DVRef)); + } + } catch (runtime_error const &re) { + } + } + + EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef)); +} + +TEST_P(TestDPCTLSyclDeviceInterface, + Chk_CreateSubDevicesByAffinityNextPartitionable) +{ + DPCTLSyclDeviceRef DRef = nullptr; + DPCTLDeviceVectorRef DVRef = nullptr; + + info::partition_affinity_domain domain = + info::partition_affinity_domain::next_partitionable; + DPCTLPartitionAffinityDomainType dpctl_domain = + DPCTL_SyclPartitionAffinityDomainToDPCTLType(domain); + + EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef)); + if (!DRef) + GTEST_SKIP_("Device not found"); + + if (dpctl_domain) { + EXPECT_NO_FATAL_FAILURE( + DVRef = DPCTLDevice_CreateSubDevicesByAffinity(DRef, dpctl_domain)); + + auto D = unwrap(DRef); + try { + auto subDevices = D->create_sub_devices< + info::partition_property::partition_by_affinity_domain>(domain); + auto expected_size = subDevices.size(); + + if (DVRef) { + EXPECT_TRUE(DPCTLDeviceVector_Size(DVRef) == expected_size); + EXPECT_NO_FATAL_FAILURE(DPCTLDeviceVector_Delete(DVRef)); + } + } catch (runtime_error const &re) { + } + } + + EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef)); +} + +INSTANTIATE_TEST_SUITE_P(DPCTLDevice_Fns, + TestDPCTLSyclDeviceInterface, + ::testing::Values("opencl", + "opencl:gpu", + "opencl:cpu", + "opencl:gpu:0", + "gpu", + "cpu", + "level_zero", + "level_zero:gpu", + "opencl:cpu:0", + "level_zero:gpu:0", + "gpu:0", + "gpu:1", + "1")); From 6f4151d07491c2f4cf792844d6b5ebfba20ef61d Mon Sep 17 00:00:00 2001 From: etotmeni Date: Wed, 24 Mar 2021 07:23:43 -0500 Subject: [PATCH 04/23] fix tests + utils --- .../helper/include/dpctl_utils_helper.h | 2 + .../tests/test_sycl_device_subdevices.cpp | 131 ++++++++++++------ 2 files changed, 91 insertions(+), 42 deletions(-) diff --git a/dpctl-capi/helper/include/dpctl_utils_helper.h b/dpctl-capi/helper/include/dpctl_utils_helper.h index 1afcc283a9..1c158c8d51 100644 --- a/dpctl-capi/helper/include/dpctl_utils_helper.h +++ b/dpctl-capi/helper/include/dpctl_utils_helper.h @@ -160,6 +160,7 @@ DPCTLSyclAspectType DPCTL_SyclAspectToDPCTLAspectType(sycl::aspect Aspect); * DPCTLPartitionAffinityDomainType enum value. * @throws runtime_error */ +DPCTL_API sycl::info::partition_affinity_domain DPCTL_DPCTLPartitionAffinityDomainTypeToSycl( DPCTLPartitionAffinityDomainType PartitionAffinityDomainTy); @@ -174,5 +175,6 @@ DPCTL_DPCTLPartitionAffinityDomainTypeToSycl( * sycl::info::partition_affinity_domain enum value. * @throws runtime_error */ +DPCTL_API DPCTLPartitionAffinityDomainType DPCTL_SyclPartitionAffinityDomainToDPCTLType( sycl::info::partition_affinity_domain PartitionAffinityDomain); diff --git a/dpctl-capi/tests/test_sycl_device_subdevices.cpp b/dpctl-capi/tests/test_sycl_device_subdevices.cpp index d052b73bf8..4b7c3ea4f1 100644 --- a/dpctl-capi/tests/test_sycl_device_subdevices.cpp +++ b/dpctl-capi/tests/test_sycl_device_subdevices.cpp @@ -160,8 +160,9 @@ TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesByAffinityNuma) info::partition_affinity_domain domain = info::partition_affinity_domain::numa; - DPCTLPartitionAffinityDomainType dpctl_domain = - DPCTL_SyclPartitionAffinityDomainToDPCTLType(domain); + DPCTLPartitionAffinityDomainType dpctl_domain; + EXPECT_NO_FATAL_FAILURE( + dpctl_domain = DPCTL_SyclPartitionAffinityDomainToDPCTLType(domain)); EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef)); if (!DRef) @@ -177,7 +178,13 @@ TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesByAffinityNuma) auto subDevices = D->create_sub_devices< info::partition_property::partition_by_affinity_domain>(domain); expected_size = subDevices.size(); + } catch (std::bad_alloc const &ba) { + std::cerr << ba.what() << '\n'; + } catch (feature_not_supported const &fnse) { + std::cerr << fnse.what() << '\n'; } catch (runtime_error const &re) { + // \todo log error + std::cerr << re.what() << '\n'; } if (DVRef && expected_size) { @@ -196,8 +203,9 @@ TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesByAffinityL4Cache) info::partition_affinity_domain domain = info::partition_affinity_domain::L4_cache; - DPCTLPartitionAffinityDomainType dpctl_domain = - DPCTL_SyclPartitionAffinityDomainToDPCTLType(domain); + DPCTLPartitionAffinityDomainType dpctl_domain; + EXPECT_NO_FATAL_FAILURE( + dpctl_domain = DPCTL_SyclPartitionAffinityDomainToDPCTLType(domain)); EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef)); if (!DRef) @@ -208,16 +216,23 @@ TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesByAffinityL4Cache) DVRef = DPCTLDevice_CreateSubDevicesByAffinity(DRef, dpctl_domain)); auto D = unwrap(DRef); + size_t expected_size = 0; try { auto subDevices = D->create_sub_devices< info::partition_property::partition_by_affinity_domain>(domain); - auto expected_size = subDevices.size(); - - if (DVRef) { - EXPECT_TRUE(DPCTLDeviceVector_Size(DVRef) == expected_size); - EXPECT_NO_FATAL_FAILURE(DPCTLDeviceVector_Delete(DVRef)); - } + expected_size = subDevices.size(); + } catch (std::bad_alloc const &ba) { + std::cerr << ba.what() << '\n'; + } catch (feature_not_supported const &fnse) { + std::cerr << fnse.what() << '\n'; } catch (runtime_error const &re) { + // \todo log error + std::cerr << re.what() << '\n'; + } + + if (DVRef && expected_size) { + EXPECT_TRUE(DPCTLDeviceVector_Size(DVRef) == expected_size); + EXPECT_NO_FATAL_FAILURE(DPCTLDeviceVector_Delete(DVRef)); } } @@ -231,8 +246,9 @@ TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesByAffinityL3Cache) info::partition_affinity_domain domain = info::partition_affinity_domain::L3_cache; - DPCTLPartitionAffinityDomainType dpctl_domain = - DPCTL_SyclPartitionAffinityDomainToDPCTLType(domain); + DPCTLPartitionAffinityDomainType dpctl_domain; + EXPECT_NO_FATAL_FAILURE( + dpctl_domain = DPCTL_SyclPartitionAffinityDomainToDPCTLType(domain)); EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef)); if (!DRef) @@ -243,16 +259,23 @@ TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesByAffinityL3Cache) DVRef = DPCTLDevice_CreateSubDevicesByAffinity(DRef, dpctl_domain)); auto D = unwrap(DRef); + size_t expected_size = 0; try { auto subDevices = D->create_sub_devices< info::partition_property::partition_by_affinity_domain>(domain); - auto expected_size = subDevices.size(); - - if (DVRef) { - EXPECT_TRUE(DPCTLDeviceVector_Size(DVRef) == expected_size); - EXPECT_NO_FATAL_FAILURE(DPCTLDeviceVector_Delete(DVRef)); - } + expected_size = subDevices.size(); + } catch (std::bad_alloc const &ba) { + std::cerr << ba.what() << '\n'; + } catch (feature_not_supported const &fnse) { + std::cerr << fnse.what() << '\n'; } catch (runtime_error const &re) { + // \todo log error + std::cerr << re.what() << '\n'; + } + + if (DVRef && expected_size) { + EXPECT_TRUE(DPCTLDeviceVector_Size(DVRef) == expected_size); + EXPECT_NO_FATAL_FAILURE(DPCTLDeviceVector_Delete(DVRef)); } } @@ -266,8 +289,9 @@ TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesByAffinityL2Cache) info::partition_affinity_domain domain = info::partition_affinity_domain::L2_cache; - DPCTLPartitionAffinityDomainType dpctl_domain = - DPCTL_SyclPartitionAffinityDomainToDPCTLType(domain); + DPCTLPartitionAffinityDomainType dpctl_domain; + EXPECT_NO_FATAL_FAILURE( + dpctl_domain = DPCTL_SyclPartitionAffinityDomainToDPCTLType(domain)); EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef)); if (!DRef) @@ -278,16 +302,23 @@ TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesByAffinityL2Cache) DVRef = DPCTLDevice_CreateSubDevicesByAffinity(DRef, dpctl_domain)); auto D = unwrap(DRef); + size_t expected_size = 0; try { auto subDevices = D->create_sub_devices< info::partition_property::partition_by_affinity_domain>(domain); - auto expected_size = subDevices.size(); - - if (DVRef) { - EXPECT_TRUE(DPCTLDeviceVector_Size(DVRef) == expected_size); - EXPECT_NO_FATAL_FAILURE(DPCTLDeviceVector_Delete(DVRef)); - } + expected_size = subDevices.size(); + } catch (std::bad_alloc const &ba) { + std::cerr << ba.what() << '\n'; + } catch (feature_not_supported const &fnse) { + std::cerr << fnse.what() << '\n'; } catch (runtime_error const &re) { + // \todo log error + std::cerr << re.what() << '\n'; + } + + if (DVRef && expected_size) { + EXPECT_TRUE(DPCTLDeviceVector_Size(DVRef) == expected_size); + EXPECT_NO_FATAL_FAILURE(DPCTLDeviceVector_Delete(DVRef)); } } @@ -301,8 +332,9 @@ TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesByAffinityL1Cache) info::partition_affinity_domain domain = info::partition_affinity_domain::L1_cache; - DPCTLPartitionAffinityDomainType dpctl_domain = - DPCTL_SyclPartitionAffinityDomainToDPCTLType(domain); + DPCTLPartitionAffinityDomainType dpctl_domain; + EXPECT_NO_FATAL_FAILURE( + dpctl_domain = DPCTL_SyclPartitionAffinityDomainToDPCTLType(domain)); EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef)); if (!DRef) @@ -313,16 +345,23 @@ TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesByAffinityL1Cache) DVRef = DPCTLDevice_CreateSubDevicesByAffinity(DRef, dpctl_domain)); auto D = unwrap(DRef); + size_t expected_size = 0; try { auto subDevices = D->create_sub_devices< info::partition_property::partition_by_affinity_domain>(domain); - auto expected_size = subDevices.size(); - - if (DVRef) { - EXPECT_TRUE(DPCTLDeviceVector_Size(DVRef) == expected_size); - EXPECT_NO_FATAL_FAILURE(DPCTLDeviceVector_Delete(DVRef)); - } + expected_size = subDevices.size(); + } catch (std::bad_alloc const &ba) { + std::cerr << ba.what() << '\n'; + } catch (feature_not_supported const &fnse) { + std::cerr << fnse.what() << '\n'; } catch (runtime_error const &re) { + // \todo log error + std::cerr << re.what() << '\n'; + } + + if (DVRef && expected_size) { + EXPECT_TRUE(DPCTLDeviceVector_Size(DVRef) == expected_size); + EXPECT_NO_FATAL_FAILURE(DPCTLDeviceVector_Delete(DVRef)); } } @@ -337,8 +376,9 @@ TEST_P(TestDPCTLSyclDeviceInterface, info::partition_affinity_domain domain = info::partition_affinity_domain::next_partitionable; - DPCTLPartitionAffinityDomainType dpctl_domain = - DPCTL_SyclPartitionAffinityDomainToDPCTLType(domain); + DPCTLPartitionAffinityDomainType dpctl_domain; + EXPECT_NO_FATAL_FAILURE( + dpctl_domain = DPCTL_SyclPartitionAffinityDomainToDPCTLType(domain)); EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef)); if (!DRef) @@ -349,16 +389,23 @@ TEST_P(TestDPCTLSyclDeviceInterface, DVRef = DPCTLDevice_CreateSubDevicesByAffinity(DRef, dpctl_domain)); auto D = unwrap(DRef); + size_t expected_size = 0; try { auto subDevices = D->create_sub_devices< info::partition_property::partition_by_affinity_domain>(domain); - auto expected_size = subDevices.size(); - - if (DVRef) { - EXPECT_TRUE(DPCTLDeviceVector_Size(DVRef) == expected_size); - EXPECT_NO_FATAL_FAILURE(DPCTLDeviceVector_Delete(DVRef)); - } + expected_size = subDevices.size(); + } catch (std::bad_alloc const &ba) { + std::cerr << ba.what() << '\n'; + } catch (feature_not_supported const &fnse) { + std::cerr << fnse.what() << '\n'; } catch (runtime_error const &re) { + // \todo log error + std::cerr << re.what() << '\n'; + } + + if (DVRef && expected_size) { + EXPECT_TRUE(DPCTLDeviceVector_Size(DVRef) == expected_size); + EXPECT_NO_FATAL_FAILURE(DPCTLDeviceVector_Delete(DVRef)); } } From c7588e9a84714ad8165337fa8ba41748f874dd13 Mon Sep 17 00:00:00 2001 From: etotmeni Date: Wed, 24 Mar 2021 09:17:57 -0500 Subject: [PATCH 05/23] Change vector to DeviceVectorRef --- dpctl-capi/include/dpctl_vector.h | 10 ++++- .../source/dpctl_sycl_device_interface.cpp | 16 +++++--- dpctl-capi/source/dpctl_vector_templ.cpp | 37 +++++++++++++++++++ 3 files changed, 57 insertions(+), 6 deletions(-) diff --git a/dpctl-capi/include/dpctl_vector.h b/dpctl-capi/include/dpctl_vector.h index 590ccdf387..ded0340264 100644 --- a/dpctl-capi/include/dpctl_vector.h +++ b/dpctl-capi/include/dpctl_vector.h @@ -50,8 +50,16 @@ DPCTL_C_EXTERN_C_BEGIN size_t DPCTL##EL##Vector_Size(__dpctl_keep DPCTL##EL##VectorRef Ref); \ \ DPCTL_API \ + void DPCTL##EL##Vector_Resize(__dpctl_keep DPCTL##EL##VectorRef Ref, \ + size_t resize); \ + \ + DPCTL_API \ __dpctl_give DPCTLSycl##EL##Ref DPCTL##EL##Vector_GetAt( \ - __dpctl_keep DPCTL##EL##VectorRef Ref, size_t index); + __dpctl_keep DPCTL##EL##VectorRef Ref, size_t index); \ + \ + DPCTL_API \ + void DPCTL##EL##Vector_SetAt(__dpctl_keep DPCTL##EL##VectorRef Ref, \ + size_t index, DPCTLSycl##EL##Ref element); #define DPCTL_DECLARE_VECTOR(EL) \ DPCTL_DECLARE_VECTOR_TYPE(EL) \ diff --git a/dpctl-capi/source/dpctl_sycl_device_interface.cpp b/dpctl-capi/source/dpctl_sycl_device_interface.cpp index 8388841e84..b8ed9cc54f 100644 --- a/dpctl-capi/source/dpctl_sycl_device_interface.cpp +++ b/dpctl-capi/source/dpctl_sycl_device_interface.cpp @@ -394,15 +394,21 @@ __dpctl_give DPCTLDeviceVectorRef DPCTLDevice_CreateSubDevicesEqually(__dpctl_keep const DPCTLSyclDeviceRef DRef, size_t count) { - vector_class *Devices = nullptr; + // vector_class *Devices = nullptr; + DPCTLDeviceVectorRef Devices = nullptr; auto D = unwrap(DRef); if (D) { try { auto subDevices = D->create_sub_devices< info::partition_property::partition_equally>(count); - Devices = new vector_class(); - for (auto &sd : subDevices) { - Devices->emplace_back(wrap(new device(sd))); + // Devices = new vector_class(); + Devices = DPCTLDeviceVector_Create(); + DPCTLDeviceVector_Resize(Devices, subDevices.size()); + for (int i = 0; i < subDevices.size(); i++) { + // auto &sd : subDevices + DPCTLDeviceVector_SetAt(Devices, i, subDevices[i]); + // Devices->emplace_back(wrap(new device(sd))); + // Devices } } catch (std::bad_alloc const &ba) { std::cerr << ba.what() << '\n'; @@ -414,7 +420,7 @@ DPCTLDevice_CreateSubDevicesEqually(__dpctl_keep const DPCTLSyclDeviceRef DRef, std::cerr << re.what() << '\n'; } } - return wrap(Devices); + return Devices; } __dpctl_give DPCTLDeviceVectorRef diff --git a/dpctl-capi/source/dpctl_vector_templ.cpp b/dpctl-capi/source/dpctl_vector_templ.cpp index da060d8a6e..85528b7d57 100644 --- a/dpctl-capi/source/dpctl_vector_templ.cpp +++ b/dpctl-capi/source/dpctl_vector_templ.cpp @@ -93,6 +93,17 @@ size_t FN(EL, Size)(__dpctl_keep VECTOR(EL) VRef) return 0; } +/*! + * @brief Returns the number of elements in the vector. + * + */ +void FN(EL, Resize)(__dpctl_keep VECTOR(EL) VRef, size_t resize) +{ + auto V = unwrap(VRef); + if (V) + V->resize(resize); +} + /*! * @brief Returns a copy of the opaque pointer at specified index, and throws * an out_of_range exception if the index is incorrect. @@ -117,3 +128,29 @@ SYCLREF(EL) FN(EL, GetAt)(__dpctl_keep VECTOR(EL) VRef, size_t index) } return copy; } + +/*! + * @brief Returns a copy of the opaque pointer at specified index, and throws + * an out_of_range exception if the index is incorrect. + * + */ +void FN(EL, + SetAt)(__dpctl_keep VECTOR(EL) VRef, size_t index, SYCLREF(EL) element) +{ + auto Vec = unwrap(VRef); + // SYCLREF(EL) copy = nullptr; + if (Vec) { + try { + Vec->at(index) = unwrap(element); + // auto ret = Vec->at(index); + // auto Ref = unwrap(ret); + // copy = wrap(new std::remove_pointer::type(*Ref)); + } catch (std::out_of_range const &oor) { + std::cerr << oor.what() << '\n'; + } catch (std::bad_alloc const &ba) { + // \todo log error + std::cerr << ba.what() << '\n'; + // return nullptr; + } + } +} From 30817fb6ddbf4822b4eaa8e220eaf91801b5f334 Mon Sep 17 00:00:00 2001 From: etotmeni Date: Wed, 24 Mar 2021 10:25:27 -0500 Subject: [PATCH 06/23] Fix SetAt --- dpctl-capi/source/dpctl_sycl_device_interface.cpp | 8 ++------ dpctl-capi/source/dpctl_vector_templ.cpp | 5 +---- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/dpctl-capi/source/dpctl_sycl_device_interface.cpp b/dpctl-capi/source/dpctl_sycl_device_interface.cpp index b8ed9cc54f..d41eb20f24 100644 --- a/dpctl-capi/source/dpctl_sycl_device_interface.cpp +++ b/dpctl-capi/source/dpctl_sycl_device_interface.cpp @@ -394,21 +394,17 @@ __dpctl_give DPCTLDeviceVectorRef DPCTLDevice_CreateSubDevicesEqually(__dpctl_keep const DPCTLSyclDeviceRef DRef, size_t count) { - // vector_class *Devices = nullptr; DPCTLDeviceVectorRef Devices = nullptr; auto D = unwrap(DRef); if (D) { try { auto subDevices = D->create_sub_devices< info::partition_property::partition_equally>(count); - // Devices = new vector_class(); Devices = DPCTLDeviceVector_Create(); DPCTLDeviceVector_Resize(Devices, subDevices.size()); for (int i = 0; i < subDevices.size(); i++) { - // auto &sd : subDevices - DPCTLDeviceVector_SetAt(Devices, i, subDevices[i]); - // Devices->emplace_back(wrap(new device(sd))); - // Devices + DPCTLDeviceVector_SetAt(Devices, i, + wrap(new device(subDevices[i]))); } } catch (std::bad_alloc const &ba) { std::cerr << ba.what() << '\n'; diff --git a/dpctl-capi/source/dpctl_vector_templ.cpp b/dpctl-capi/source/dpctl_vector_templ.cpp index 85528b7d57..e78e9ffa34 100644 --- a/dpctl-capi/source/dpctl_vector_templ.cpp +++ b/dpctl-capi/source/dpctl_vector_templ.cpp @@ -141,10 +141,7 @@ void FN(EL, // SYCLREF(EL) copy = nullptr; if (Vec) { try { - Vec->at(index) = unwrap(element); - // auto ret = Vec->at(index); - // auto Ref = unwrap(ret); - // copy = wrap(new std::remove_pointer::type(*Ref)); + Vec->at(index) = element; } catch (std::out_of_range const &oor) { std::cerr << oor.what() << '\n'; } catch (std::bad_alloc const &ba) { From 230a45bc802b606a81a14b62957b65650988aae5 Mon Sep 17 00:00:00 2001 From: etotmeni Date: Wed, 24 Mar 2021 10:36:15 -0500 Subject: [PATCH 07/23] Backup --- dpctl-capi/include/dpctl_vector.h | 10 +----- .../source/dpctl_sycl_device_interface.cpp | 12 +++---- dpctl-capi/source/dpctl_vector_templ.cpp | 34 ------------------- 3 files changed, 6 insertions(+), 50 deletions(-) diff --git a/dpctl-capi/include/dpctl_vector.h b/dpctl-capi/include/dpctl_vector.h index ded0340264..590ccdf387 100644 --- a/dpctl-capi/include/dpctl_vector.h +++ b/dpctl-capi/include/dpctl_vector.h @@ -50,16 +50,8 @@ DPCTL_C_EXTERN_C_BEGIN size_t DPCTL##EL##Vector_Size(__dpctl_keep DPCTL##EL##VectorRef Ref); \ \ DPCTL_API \ - void DPCTL##EL##Vector_Resize(__dpctl_keep DPCTL##EL##VectorRef Ref, \ - size_t resize); \ - \ - DPCTL_API \ __dpctl_give DPCTLSycl##EL##Ref DPCTL##EL##Vector_GetAt( \ - __dpctl_keep DPCTL##EL##VectorRef Ref, size_t index); \ - \ - DPCTL_API \ - void DPCTL##EL##Vector_SetAt(__dpctl_keep DPCTL##EL##VectorRef Ref, \ - size_t index, DPCTLSycl##EL##Ref element); + __dpctl_keep DPCTL##EL##VectorRef Ref, size_t index); #define DPCTL_DECLARE_VECTOR(EL) \ DPCTL_DECLARE_VECTOR_TYPE(EL) \ diff --git a/dpctl-capi/source/dpctl_sycl_device_interface.cpp b/dpctl-capi/source/dpctl_sycl_device_interface.cpp index d41eb20f24..8388841e84 100644 --- a/dpctl-capi/source/dpctl_sycl_device_interface.cpp +++ b/dpctl-capi/source/dpctl_sycl_device_interface.cpp @@ -394,17 +394,15 @@ __dpctl_give DPCTLDeviceVectorRef DPCTLDevice_CreateSubDevicesEqually(__dpctl_keep const DPCTLSyclDeviceRef DRef, size_t count) { - DPCTLDeviceVectorRef Devices = nullptr; + vector_class *Devices = nullptr; auto D = unwrap(DRef); if (D) { try { auto subDevices = D->create_sub_devices< info::partition_property::partition_equally>(count); - Devices = DPCTLDeviceVector_Create(); - DPCTLDeviceVector_Resize(Devices, subDevices.size()); - for (int i = 0; i < subDevices.size(); i++) { - DPCTLDeviceVector_SetAt(Devices, i, - wrap(new device(subDevices[i]))); + Devices = new vector_class(); + for (auto &sd : subDevices) { + Devices->emplace_back(wrap(new device(sd))); } } catch (std::bad_alloc const &ba) { std::cerr << ba.what() << '\n'; @@ -416,7 +414,7 @@ DPCTLDevice_CreateSubDevicesEqually(__dpctl_keep const DPCTLSyclDeviceRef DRef, std::cerr << re.what() << '\n'; } } - return Devices; + return wrap(Devices); } __dpctl_give DPCTLDeviceVectorRef diff --git a/dpctl-capi/source/dpctl_vector_templ.cpp b/dpctl-capi/source/dpctl_vector_templ.cpp index e78e9ffa34..da060d8a6e 100644 --- a/dpctl-capi/source/dpctl_vector_templ.cpp +++ b/dpctl-capi/source/dpctl_vector_templ.cpp @@ -93,17 +93,6 @@ size_t FN(EL, Size)(__dpctl_keep VECTOR(EL) VRef) return 0; } -/*! - * @brief Returns the number of elements in the vector. - * - */ -void FN(EL, Resize)(__dpctl_keep VECTOR(EL) VRef, size_t resize) -{ - auto V = unwrap(VRef); - if (V) - V->resize(resize); -} - /*! * @brief Returns a copy of the opaque pointer at specified index, and throws * an out_of_range exception if the index is incorrect. @@ -128,26 +117,3 @@ SYCLREF(EL) FN(EL, GetAt)(__dpctl_keep VECTOR(EL) VRef, size_t index) } return copy; } - -/*! - * @brief Returns a copy of the opaque pointer at specified index, and throws - * an out_of_range exception if the index is incorrect. - * - */ -void FN(EL, - SetAt)(__dpctl_keep VECTOR(EL) VRef, size_t index, SYCLREF(EL) element) -{ - auto Vec = unwrap(VRef); - // SYCLREF(EL) copy = nullptr; - if (Vec) { - try { - Vec->at(index) = element; - } catch (std::out_of_range const &oor) { - std::cerr << oor.what() << '\n'; - } catch (std::bad_alloc const &ba) { - // \todo log error - std::cerr << ba.what() << '\n'; - // return nullptr; - } - } -} From 51f72d63688e208b4d2f6704cdc8cf96f90f7e67 Mon Sep 17 00:00:00 2001 From: etotmeni Date: Thu, 25 Mar 2021 05:08:56 -0500 Subject: [PATCH 08/23] Add backend --- dpctl/_backend.pxd | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/dpctl/_backend.pxd b/dpctl/_backend.pxd index 7aab8ca8d5..d9ac09da2a 100644 --- a/dpctl/_backend.pxd +++ b/dpctl/_backend.pxd @@ -104,6 +104,18 @@ cdef extern from "dpctl_sycl_enum_types.h": ctypedef _aspect_type DPCTLSyclAspectType + cdef enum _partition_affinity_domain_type 'DPCTLPartitionAffinityDomainType': + _not_applicable 'not_applicable', + _numa 'numa', + _L4_cache 'L4_cache', + _L3_cache 'L3_cache', + _L2_cache 'L2_cache', + _L1_cache 'L1_cache', + _next_partitionable 'next_partitionable', + + ctypedef _partition_affinity_domain_type DPCTLPartitionAffinityDomainType + + cdef extern from "dpctl_sycl_types.h": cdef struct DPCTLOpaqueSyclContext cdef struct DPCTLOpaqueSyclDevice @@ -155,6 +167,13 @@ cdef extern from "dpctl_sycl_device_interface.h": cdef bool DPCTLDevice_IsHostUnifiedMemory(const DPCTLSyclDeviceRef DRef) cpdef bool DPCTLDevice_HasAspect( const DPCTLSyclDeviceRef DRef, DPCTLSyclAspectType AT) + cdef DPCTLDeviceVectorRef DPCTLDevice_CreateSubDevicesEqually( + const DPCTLSyclDeviceRef DRef, size_t count) + cdef DPCTLDeviceVectorRef DPCTLDevice_CreateSubDevicesByCounts( + const DPCTLSyclDeviceRef DRef, size_t *counts, size_t ncounts) + cdef DPCTLDeviceVectorRef DPCTLDevice_CreateSubDevicesByAffinity( + const DPCTLSyclDeviceRef DRef, + DPCTLPartitionAffinityDomainType PartitionAffinityDomainTy) cdef extern from "dpctl_sycl_device_manager.h": From 972f55325f682e0d26f9a74bab25b5cbc0f4b124 Mon Sep 17 00:00:00 2001 From: etotmeni Date: Thu, 25 Mar 2021 10:11:32 -0500 Subject: [PATCH 09/23] work on cython part --- dpctl/_backend.pxd | 6 +++--- dpctl/_sycl_device.pxd | 3 +++ dpctl/_sycl_device.pyx | 25 +++++++++++++++++++++++++ dpctl/tests/test_sycl_device.py | 9 +++++++++ 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/dpctl/_backend.pxd b/dpctl/_backend.pxd index d9ac09da2a..8c2bfea7f1 100644 --- a/dpctl/_backend.pxd +++ b/dpctl/_backend.pxd @@ -167,11 +167,11 @@ cdef extern from "dpctl_sycl_device_interface.h": cdef bool DPCTLDevice_IsHostUnifiedMemory(const DPCTLSyclDeviceRef DRef) cpdef bool DPCTLDevice_HasAspect( const DPCTLSyclDeviceRef DRef, DPCTLSyclAspectType AT) - cdef DPCTLDeviceVectorRef DPCTLDevice_CreateSubDevicesEqually( + cdef list DPCTLDevice_CreateSubDevicesEqually( const DPCTLSyclDeviceRef DRef, size_t count) - cdef DPCTLDeviceVectorRef DPCTLDevice_CreateSubDevicesByCounts( + cdef list DPCTLDevice_CreateSubDevicesByCounts( const DPCTLSyclDeviceRef DRef, size_t *counts, size_t ncounts) - cdef DPCTLDeviceVectorRef DPCTLDevice_CreateSubDevicesByAffinity( + cdef list DPCTLDevice_CreateSubDevicesByAffinity( const DPCTLSyclDeviceRef DRef, DPCTLPartitionAffinityDomainType PartitionAffinityDomainTy) diff --git a/dpctl/_sycl_device.pxd b/dpctl/_sycl_device.pxd index 5293b8fa75..a03e4baf48 100644 --- a/dpctl/_sycl_device.pxd +++ b/dpctl/_sycl_device.pxd @@ -34,6 +34,8 @@ cdef class _SyclDevice: cdef const char *_device_name cdef const char *_driver_version cdef size_t *_max_work_item_sizes + # cdef list _create_sub_devices_equally + # cpdef create_sub_devices_equally(self, size_t count) cdef class SyclDevice(_SyclDevice): @@ -44,3 +46,4 @@ cdef class SyclDevice(_SyclDevice): cdef int _init_from__SyclDevice(self, _SyclDevice other) cdef int _init_from_selector(self, DPCTLSyclDeviceSelectorRef DSRef) cdef DPCTLSyclDeviceRef get_device_ref(self) + cpdef create_sub_devices_equally(self, size_t count) diff --git a/dpctl/_sycl_device.pyx b/dpctl/_sycl_device.pyx index cdfcfca4dc..478199705e 100644 --- a/dpctl/_sycl_device.pyx +++ b/dpctl/_sycl_device.pyx @@ -53,6 +53,7 @@ from ._backend cimport ( DPCTLSyclDeviceSelectorRef, DPCTLDevice_HasAspect, DPCTLSyclDeviceType, + DPCTLDevice_CreateSubDevicesEqually, ) from . import backend_type, device_type from libc.stdint cimport uint32_t @@ -74,6 +75,16 @@ cdef class _SyclDevice: DPCTLCString_Delete(self._driver_version) DPCTLSize_t_Array_Delete(self._max_work_item_sizes) + # cpdef create_sub_devices_equally(self, size_t count): + # """ Returns a vector of sub devices partitioned from this SYCL device + # based on the count parameter. The returned + # vector contains as many sub devices as can be created such that each sub + # device contains count compute units. If the device’s total number of compute + # units is not evenly divided by count, then the remaining compute units are + # not included in any of the sub devices. + # """ + # return self._create_sub_devices_equally + cdef class SyclDevice(_SyclDevice): """ Python equivalent for cl::sycl::device class. @@ -121,6 +132,7 @@ cdef class SyclDevice(_SyclDevice): device._driver_version = DPCTLDevice_GetDriverInfo(DRef) device._vendor_name = DPCTLDevice_GetVendorName(DRef) device._max_work_item_sizes = DPCTLDevice_GetMaxWorkItemSizes(DRef) + # device._create_sub_devices_equally = DPCTLDevice_CreateSubDevicesEqually(DRef, count) @staticmethod cdef SyclDevice _create(DPCTLSyclDeviceRef dref): @@ -138,6 +150,9 @@ cdef class SyclDevice(_SyclDevice): self._max_work_item_sizes = ( DPCTLDevice_GetMaxWorkItemSizes(self._device_ref) ) + # self._create_sub_devices_equally = ( + # DPCTLDevice_CreateSubDevicesEqually(self._device_ref, count) + # ) self._vendor_name = DPCTLDevice_GetVendorName(self._device_ref) cdef int _init_from_selector(self, DPCTLSyclDeviceSelectorRef DSRef): @@ -149,6 +164,16 @@ cdef class SyclDevice(_SyclDevice): SyclDevice._init_helper(self, DRef) return 0 + cpdef create_sub_devices_equally(self, size_t count): + """ Returns a vector of sub devices partitioned from this SYCL device + based on the count parameter. The returned + vector contains as many sub devices as can be created such that each sub + device contains count compute units. If the device’s total number of compute + units is not evenly divided by count, then the remaining compute units are + not included in any of the sub devices. + """ + return DPCTLDevice_CreateSubDevicesEqually(self._device_ref, count) + def __cinit__(self, arg=None): cdef DPCTLSyclDeviceSelectorRef DSRef = NULL cdef const char *filter_c_str = NULL diff --git a/dpctl/tests/test_sycl_device.py b/dpctl/tests/test_sycl_device.py index 22fa118277..9b2d1e276a 100644 --- a/dpctl/tests/test_sycl_device.py +++ b/dpctl/tests/test_sycl_device.py @@ -240,6 +240,14 @@ def check_is_host(device): pytest.fail("is_hostcall failed") +def check_create_sub_devices_equally(device): + try: + n = device.max_compute_units / 2 + device.create_sub_devices_equally(n) + except Exception: + pytest.fail("create_sub_devices_equally failed") + + list_of_checks = [ check_get_max_compute_units, check_get_max_work_item_dims, @@ -268,6 +276,7 @@ def check_is_host(device): check_has_aspect_usm_shared_allocations, check_has_aspect_usm_restricted_shared_allocations, check_has_aspect_usm_system_allocator, + check_create_sub_devices_equally, ] From f7d2bfac83b6d4ad51314f5ddd04c2915efab0aa Mon Sep 17 00:00:00 2001 From: etotmeni Date: Fri, 26 Mar 2021 07:34:55 -0500 Subject: [PATCH 10/23] Added cpdef func --- dpctl/_sycl_device.pxd | 2 +- dpctl/_sycl_device.pyx | 25 +++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/dpctl/_sycl_device.pxd b/dpctl/_sycl_device.pxd index a03e4baf48..8b267cf2a0 100644 --- a/dpctl/_sycl_device.pxd +++ b/dpctl/_sycl_device.pxd @@ -46,4 +46,4 @@ cdef class SyclDevice(_SyclDevice): cdef int _init_from__SyclDevice(self, _SyclDevice other) cdef int _init_from_selector(self, DPCTLSyclDeviceSelectorRef DSRef) cdef DPCTLSyclDeviceRef get_device_ref(self) - cpdef create_sub_devices_equally(self, size_t count) + cpdef list create_sub_devices_equally(self, size_t count) diff --git a/dpctl/_sycl_device.pyx b/dpctl/_sycl_device.pyx index 478199705e..1705d61f8b 100644 --- a/dpctl/_sycl_device.pyx +++ b/dpctl/_sycl_device.pyx @@ -29,6 +29,10 @@ from ._backend cimport ( DPCTLDevice_Copy, DPCTLDevice_CreateFromSelector, DPCTLDevice_Delete, + DPCTLDeviceVectorRef, + DPCTLDeviceVector_Delete, + DPCTLDeviceVector_GetAt, + DPCTLDeviceVector_Size, DPCTLDevice_GetBackend, DPCTLDevice_GetDeviceType, DPCTLDevice_GetDriverInfo, @@ -86,6 +90,19 @@ cdef class _SyclDevice: # return self._create_sub_devices_equally +cdef list _get_devices(DPCTLDeviceVectorRef DVRef): + cdef list devices = [] + cdef size_t nelems = 0 + if DVRef: + nelems = DPCTLDeviceVector_Size(DVRef) + for i in range(0, nelems): + DRef = DPCTLDeviceVector_GetAt(DVRef, i) + D = SyclDevice._create(DRef) + devices.append(D) + + return devices + + cdef class SyclDevice(_SyclDevice): """ Python equivalent for cl::sycl::device class. @@ -164,7 +181,7 @@ cdef class SyclDevice(_SyclDevice): SyclDevice._init_helper(self, DRef) return 0 - cpdef create_sub_devices_equally(self, size_t count): + cpdef list create_sub_devices_equally(self, size_t count): """ Returns a vector of sub devices partitioned from this SYCL device based on the count parameter. The returned vector contains as many sub devices as can be created such that each sub @@ -172,7 +189,11 @@ cdef class SyclDevice(_SyclDevice): units is not evenly divided by count, then the remaining compute units are not included in any of the sub devices. """ - return DPCTLDevice_CreateSubDevicesEqually(self._device_ref, count) + cdef DPCTLDeviceVectorRef DVRef = NULL + DVRef = DPCTLDevice_CreateSubDevicesEqually(self._device_ref, count) + cdef list devices = _get_devices(DVRef) + DPCTLDeviceVector_Delete(DVRef) + return devices def __cinit__(self, arg=None): cdef DPCTLSyclDeviceSelectorRef DSRef = NULL From 072305a1e27d793f2fed8782fd6601349d0336d1 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Fri, 26 Mar 2021 09:28:44 -0500 Subject: [PATCH 11/23] using const qualifier in iterating over vector of sub-devices --- dpctl-capi/source/dpctl_sycl_device_interface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dpctl-capi/source/dpctl_sycl_device_interface.cpp b/dpctl-capi/source/dpctl_sycl_device_interface.cpp index 31e4bebaa3..549f0967e3 100644 --- a/dpctl-capi/source/dpctl_sycl_device_interface.cpp +++ b/dpctl-capi/source/dpctl_sycl_device_interface.cpp @@ -537,7 +537,7 @@ DPCTLDevice_CreateSubDevicesEqually(__dpctl_keep const DPCTLSyclDeviceRef DRef, auto subDevices = D->create_sub_devices< info::partition_property::partition_equally>(count); Devices = new vector_class(); - for (auto &sd : subDevices) { + for (const auto &sd : subDevices) { Devices->emplace_back(wrap(new device(sd))); } } catch (std::bad_alloc const &ba) { From 1838637d9a3405cc685ee8d6802c1fe284fc2c7a Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Fri, 26 Mar 2021 09:29:29 -0500 Subject: [PATCH 12/23] fix Cython error due to mismatch in declaration of DPCTLDevice_CreateSubDevicesEqually and others --- dpctl/_backend.pxd | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/dpctl/_backend.pxd b/dpctl/_backend.pxd index 9617ff3014..b83521a53d 100644 --- a/dpctl/_backend.pxd +++ b/dpctl/_backend.pxd @@ -138,6 +138,14 @@ cdef extern from "dpctl_sycl_types.h": ctypedef DPCTLOpaqueSyclUSM *DPCTLSyclUSMRef +cdef extern from "dpctl_sycl_device_manager.h": + cdef struct DPCTLDeviceVector + ctypedef DPCTLDeviceVector *DPCTLDeviceVectorRef + ctypedef struct DPCTL_DeviceAndContextPair: + DPCTLSyclDeviceRef DRef + DPCTLSyclContextRef CRef + + cdef extern from "dpctl_sycl_device_interface.h": cdef bool DPCTLDevice_AreEq(const DPCTLSyclDeviceRef DRef1, const DPCTLSyclDeviceRef DRef2) @@ -175,22 +183,16 @@ cdef extern from "dpctl_sycl_device_interface.h": cdef uint32_t DPCTLDevice_GetPreferredVectorWidthHalf(const DPCTLSyclDeviceRef DRef) cpdef bool DPCTLDevice_HasAspect( const DPCTLSyclDeviceRef DRef, DPCTLSyclAspectType AT) - cdef list DPCTLDevice_CreateSubDevicesEqually( + cdef DPCTLDeviceVectorRef DPCTLDevice_CreateSubDevicesEqually( const DPCTLSyclDeviceRef DRef, size_t count) - cdef list DPCTLDevice_CreateSubDevicesByCounts( + cdef DPCTLDeviceVectorRef DPCTLDevice_CreateSubDevicesByCounts( const DPCTLSyclDeviceRef DRef, size_t *counts, size_t ncounts) - cdef list DPCTLDevice_CreateSubDevicesByAffinity( + cdef DPCTLDeviceVectorRef DPCTLDevice_CreateSubDevicesByAffinity( const DPCTLSyclDeviceRef DRef, DPCTLPartitionAffinityDomainType PartitionAffinityDomainTy) cdef extern from "dpctl_sycl_device_manager.h": - cdef struct DPCTLDeviceVector - ctypedef DPCTLDeviceVector *DPCTLDeviceVectorRef - ctypedef struct DPCTL_DeviceAndContextPair: - DPCTLSyclDeviceRef DRef - DPCTLSyclContextRef CRef - cdef void DPCTLDeviceVector_Delete(DPCTLDeviceVectorRef DVRef) cdef void DPCTLDeviceVector_Clear(DPCTLDeviceVectorRef DVRef) cdef size_t DPCTLDeviceVector_Size(DPCTLDeviceVectorRef DVRef) From 4a5efc3514c36750e62f8d22c644a9daf7a62d75 Mon Sep 17 00:00:00 2001 From: etotmeni Date: Fri, 26 Mar 2021 11:01:37 -0500 Subject: [PATCH 13/23] Fix tests --- .../tests/test_sycl_device_subdevices.cpp | 75 ++----------------- 1 file changed, 8 insertions(+), 67 deletions(-) diff --git a/dpctl-capi/tests/test_sycl_device_subdevices.cpp b/dpctl-capi/tests/test_sycl_device_subdevices.cpp index 4b7c3ea4f1..bab0af5f3a 100644 --- a/dpctl-capi/tests/test_sycl_device_subdevices.cpp +++ b/dpctl-capi/tests/test_sycl_device_subdevices.cpp @@ -41,16 +41,20 @@ DEFINE_SIMPLE_CONVERSION_FUNCTIONS(device, DPCTLSyclDeviceRef); struct TestDPCTLSyclDeviceInterface : public ::testing::TestWithParam { - DPCTLSyclDeviceSelectorRef DSRef = nullptr; + DPCTLSyclDeviceRef DRef = nullptr; TestDPCTLSyclDeviceInterface() { - EXPECT_NO_FATAL_FAILURE(DSRef = DPCTLFilterSelector_Create(GetParam())); + auto DS = DPCTLFilterSelector_Create(GetParam()); + if (DS) { + EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DS)); + } + DPCTLDeviceSelector_Delete(DS); } void SetUp() { - if (!DSRef) { + if (!DRef) { auto message = "Skipping as no device of type " + std::string(GetParam()) + "."; GTEST_SKIP_(message.c_str()); @@ -59,20 +63,15 @@ struct TestDPCTLSyclDeviceInterface ~TestDPCTLSyclDeviceInterface() { - EXPECT_NO_FATAL_FAILURE(DPCTLDeviceSelector_Delete(DSRef)); + DPCTLDevice_Delete(DRef); } }; TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesEqually) { - DPCTLSyclDeviceRef DRef = nullptr; DPCTLDeviceVectorRef DVRef = nullptr; uint32_t maxCUs = 0; - EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef)); - if (!DRef) - GTEST_SKIP_("Device not found"); - EXPECT_NO_FATAL_FAILURE(maxCUs = DPCTLDevice_GetMaxComputeUnits(DRef)); if (maxCUs) { int count = maxCUs / 2; @@ -83,20 +82,13 @@ TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesEqually) EXPECT_NO_FATAL_FAILURE(DPCTLDeviceVector_Delete(DVRef)); } } - - EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef)); } TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesByCounts) { - DPCTLSyclDeviceRef DRef = nullptr; DPCTLDeviceVectorRef DVRef = nullptr; uint32_t maxCUs = 0; - EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef)); - if (!DRef) - GTEST_SKIP_("Device not found"); - EXPECT_NO_FATAL_FAILURE(maxCUs = DPCTLDevice_GetMaxComputeUnits(DRef)); if (maxCUs) { size_t count = maxCUs / 2; @@ -113,14 +105,11 @@ TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesByCounts) EXPECT_NO_FATAL_FAILURE(DPCTLDeviceVector_Delete(DVRef)); } } - - EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef)); } TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesByAffinityNotApplicable) { - DPCTLSyclDeviceRef DRef = nullptr; DPCTLDeviceVectorRef DVRef = nullptr; info::partition_affinity_domain domain = @@ -128,10 +117,6 @@ TEST_P(TestDPCTLSyclDeviceInterface, DPCTLPartitionAffinityDomainType dpctl_domain = DPCTL_SyclPartitionAffinityDomainToDPCTLType(domain); - EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef)); - if (!DRef) - GTEST_SKIP_("Device not found"); - if (dpctl_domain) { EXPECT_NO_FATAL_FAILURE( DVRef = DPCTLDevice_CreateSubDevicesByAffinity(DRef, dpctl_domain)); @@ -149,13 +134,10 @@ TEST_P(TestDPCTLSyclDeviceInterface, } catch (runtime_error const &re) { } } - - EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef)); } TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesByAffinityNuma) { - DPCTLSyclDeviceRef DRef = nullptr; DPCTLDeviceVectorRef DVRef = nullptr; info::partition_affinity_domain domain = @@ -164,10 +146,6 @@ TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesByAffinityNuma) EXPECT_NO_FATAL_FAILURE( dpctl_domain = DPCTL_SyclPartitionAffinityDomainToDPCTLType(domain)); - EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef)); - if (!DRef) - GTEST_SKIP_("Device not found"); - if (dpctl_domain) { EXPECT_NO_FATAL_FAILURE( DVRef = DPCTLDevice_CreateSubDevicesByAffinity(DRef, dpctl_domain)); @@ -192,13 +170,10 @@ TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesByAffinityNuma) EXPECT_NO_FATAL_FAILURE(DPCTLDeviceVector_Delete(DVRef)); } } - - EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef)); } TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesByAffinityL4Cache) { - DPCTLSyclDeviceRef DRef = nullptr; DPCTLDeviceVectorRef DVRef = nullptr; info::partition_affinity_domain domain = @@ -207,10 +182,6 @@ TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesByAffinityL4Cache) EXPECT_NO_FATAL_FAILURE( dpctl_domain = DPCTL_SyclPartitionAffinityDomainToDPCTLType(domain)); - EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef)); - if (!DRef) - GTEST_SKIP_("Device not found"); - if (dpctl_domain) { EXPECT_NO_FATAL_FAILURE( DVRef = DPCTLDevice_CreateSubDevicesByAffinity(DRef, dpctl_domain)); @@ -235,13 +206,10 @@ TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesByAffinityL4Cache) EXPECT_NO_FATAL_FAILURE(DPCTLDeviceVector_Delete(DVRef)); } } - - EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef)); } TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesByAffinityL3Cache) { - DPCTLSyclDeviceRef DRef = nullptr; DPCTLDeviceVectorRef DVRef = nullptr; info::partition_affinity_domain domain = @@ -250,10 +218,6 @@ TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesByAffinityL3Cache) EXPECT_NO_FATAL_FAILURE( dpctl_domain = DPCTL_SyclPartitionAffinityDomainToDPCTLType(domain)); - EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef)); - if (!DRef) - GTEST_SKIP_("Device not found"); - if (dpctl_domain) { EXPECT_NO_FATAL_FAILURE( DVRef = DPCTLDevice_CreateSubDevicesByAffinity(DRef, dpctl_domain)); @@ -278,13 +242,10 @@ TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesByAffinityL3Cache) EXPECT_NO_FATAL_FAILURE(DPCTLDeviceVector_Delete(DVRef)); } } - - EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef)); } TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesByAffinityL2Cache) { - DPCTLSyclDeviceRef DRef = nullptr; DPCTLDeviceVectorRef DVRef = nullptr; info::partition_affinity_domain domain = @@ -293,10 +254,6 @@ TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesByAffinityL2Cache) EXPECT_NO_FATAL_FAILURE( dpctl_domain = DPCTL_SyclPartitionAffinityDomainToDPCTLType(domain)); - EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef)); - if (!DRef) - GTEST_SKIP_("Device not found"); - if (dpctl_domain) { EXPECT_NO_FATAL_FAILURE( DVRef = DPCTLDevice_CreateSubDevicesByAffinity(DRef, dpctl_domain)); @@ -321,13 +278,10 @@ TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesByAffinityL2Cache) EXPECT_NO_FATAL_FAILURE(DPCTLDeviceVector_Delete(DVRef)); } } - - EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef)); } TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesByAffinityL1Cache) { - DPCTLSyclDeviceRef DRef = nullptr; DPCTLDeviceVectorRef DVRef = nullptr; info::partition_affinity_domain domain = @@ -336,10 +290,6 @@ TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesByAffinityL1Cache) EXPECT_NO_FATAL_FAILURE( dpctl_domain = DPCTL_SyclPartitionAffinityDomainToDPCTLType(domain)); - EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef)); - if (!DRef) - GTEST_SKIP_("Device not found"); - if (dpctl_domain) { EXPECT_NO_FATAL_FAILURE( DVRef = DPCTLDevice_CreateSubDevicesByAffinity(DRef, dpctl_domain)); @@ -364,14 +314,11 @@ TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesByAffinityL1Cache) EXPECT_NO_FATAL_FAILURE(DPCTLDeviceVector_Delete(DVRef)); } } - - EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef)); } TEST_P(TestDPCTLSyclDeviceInterface, Chk_CreateSubDevicesByAffinityNextPartitionable) { - DPCTLSyclDeviceRef DRef = nullptr; DPCTLDeviceVectorRef DVRef = nullptr; info::partition_affinity_domain domain = @@ -380,10 +327,6 @@ TEST_P(TestDPCTLSyclDeviceInterface, EXPECT_NO_FATAL_FAILURE( dpctl_domain = DPCTL_SyclPartitionAffinityDomainToDPCTLType(domain)); - EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef)); - if (!DRef) - GTEST_SKIP_("Device not found"); - if (dpctl_domain) { EXPECT_NO_FATAL_FAILURE( DVRef = DPCTLDevice_CreateSubDevicesByAffinity(DRef, dpctl_domain)); @@ -408,8 +351,6 @@ TEST_P(TestDPCTLSyclDeviceInterface, EXPECT_NO_FATAL_FAILURE(DPCTLDeviceVector_Delete(DVRef)); } } - - EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef)); } INSTANTIATE_TEST_SUITE_P(DPCTLDevice_Fns, From ccebb86bb9471754f4b64c626e47af86809dd5ea Mon Sep 17 00:00:00 2001 From: etotmeni Date: Fri, 26 Mar 2021 11:07:16 -0500 Subject: [PATCH 14/23] Delete commented code --- dpctl/_sycl_device.pxd | 2 -- dpctl/_sycl_device.pyx | 14 -------------- 2 files changed, 16 deletions(-) diff --git a/dpctl/_sycl_device.pxd b/dpctl/_sycl_device.pxd index 8b267cf2a0..140f399c81 100644 --- a/dpctl/_sycl_device.pxd +++ b/dpctl/_sycl_device.pxd @@ -34,8 +34,6 @@ cdef class _SyclDevice: cdef const char *_device_name cdef const char *_driver_version cdef size_t *_max_work_item_sizes - # cdef list _create_sub_devices_equally - # cpdef create_sub_devices_equally(self, size_t count) cdef class SyclDevice(_SyclDevice): diff --git a/dpctl/_sycl_device.pyx b/dpctl/_sycl_device.pyx index f95c49be52..acd167f25a 100644 --- a/dpctl/_sycl_device.pyx +++ b/dpctl/_sycl_device.pyx @@ -87,16 +87,6 @@ cdef class _SyclDevice: DPCTLCString_Delete(self._driver_version) DPCTLSize_t_Array_Delete(self._max_work_item_sizes) - # cpdef create_sub_devices_equally(self, size_t count): - # """ Returns a vector of sub devices partitioned from this SYCL device - # based on the count parameter. The returned - # vector contains as many sub devices as can be created such that each sub - # device contains count compute units. If the device’s total number of compute - # units is not evenly divided by count, then the remaining compute units are - # not included in any of the sub devices. - # """ - # return self._create_sub_devices_equally - cdef list _get_devices(DPCTLDeviceVectorRef DVRef): cdef list devices = [] @@ -157,7 +147,6 @@ cdef class SyclDevice(_SyclDevice): device._driver_version = DPCTLDevice_GetDriverInfo(DRef) device._vendor_name = DPCTLDevice_GetVendorName(DRef) device._max_work_item_sizes = DPCTLDevice_GetMaxWorkItemSizes(DRef) - # device._create_sub_devices_equally = DPCTLDevice_CreateSubDevicesEqually(DRef, count) @staticmethod cdef SyclDevice _create(DPCTLSyclDeviceRef dref): @@ -175,9 +164,6 @@ cdef class SyclDevice(_SyclDevice): self._max_work_item_sizes = ( DPCTLDevice_GetMaxWorkItemSizes(self._device_ref) ) - # self._create_sub_devices_equally = ( - # DPCTLDevice_CreateSubDevicesEqually(self._device_ref, count) - # ) self._vendor_name = DPCTLDevice_GetVendorName(self._device_ref) cdef int _init_from_selector(self, DPCTLSyclDeviceSelectorRef DSRef): From d7ae52d500b1f1647211bb8aa65b216ac270e970 Mon Sep 17 00:00:00 2001 From: etotmeni Date: Fri, 26 Mar 2021 12:34:30 -0500 Subject: [PATCH 15/23] Added create_sub_devices_by_counts and create_sub_devices_by_affinity cython --- .../source/dpctl_sycl_device_interface.cpp | 4 +- dpctl/_backend.pxd | 2 +- dpctl/_sycl_device.pxd | 4 ++ dpctl/_sycl_device.pyx | 26 +++++++ dpctl/tests/test_sycl_device.py | 69 +++++++++++++++++++ 5 files changed, 102 insertions(+), 3 deletions(-) diff --git a/dpctl-capi/source/dpctl_sycl_device_interface.cpp b/dpctl-capi/source/dpctl_sycl_device_interface.cpp index 549f0967e3..16eb438909 100644 --- a/dpctl-capi/source/dpctl_sycl_device_interface.cpp +++ b/dpctl-capi/source/dpctl_sycl_device_interface.cpp @@ -567,7 +567,7 @@ DPCTLDevice_CreateSubDevicesByCounts(__dpctl_keep const DPCTLSyclDeviceRef DRef, auto subDevices = D->create_sub_devices< info::partition_property::partition_by_counts>(vcounts); Devices = new vector_class(); - for (auto &sd : subDevices) { + for (const auto &sd : subDevices) { Devices->emplace_back(wrap(new device(sd))); } } catch (std::bad_alloc const &ba) { @@ -596,7 +596,7 @@ __dpctl_give DPCTLDeviceVectorRef DPCTLDevice_CreateSubDevicesByAffinity( auto subDevices = D->create_sub_devices< info::partition_property::partition_by_affinity_domain>(domain); Devices = new vector_class(); - for (auto &sd : subDevices) { + for (const auto &sd : subDevices) { Devices->emplace_back(wrap(new device(sd))); } } catch (std::bad_alloc const &ba) { diff --git a/dpctl/_backend.pxd b/dpctl/_backend.pxd index b83521a53d..d035f9b2f9 100644 --- a/dpctl/_backend.pxd +++ b/dpctl/_backend.pxd @@ -104,7 +104,7 @@ cdef extern from "dpctl_sycl_enum_types.h": ctypedef _aspect_type DPCTLSyclAspectType - cdef enum _partition_affinity_domain_type 'DPCTLPartitionAffinityDomainType': + cpdef enum _partition_affinity_domain_type 'DPCTLPartitionAffinityDomainType': _not_applicable 'not_applicable', _numa 'numa', _L4_cache 'L4_cache', diff --git a/dpctl/_sycl_device.pxd b/dpctl/_sycl_device.pxd index 140f399c81..010c85ecfd 100644 --- a/dpctl/_sycl_device.pxd +++ b/dpctl/_sycl_device.pxd @@ -23,6 +23,8 @@ from ._backend cimport ( DPCTLSyclDeviceRef, DPCTLSyclDeviceSelectorRef, + DPCTLPartitionAffinityDomainType, + _partition_affinity_domain_type ) @@ -45,3 +47,5 @@ cdef class SyclDevice(_SyclDevice): cdef int _init_from_selector(self, DPCTLSyclDeviceSelectorRef DSRef) cdef DPCTLSyclDeviceRef get_device_ref(self) cpdef list create_sub_devices_equally(self, size_t count) + cpdef list create_sub_devices_by_counts(self, list counts, size_t ncounts) + cpdef list create_sub_devices_by_affinity(self, _partition_affinity_domain_type domain) diff --git a/dpctl/_sycl_device.pyx b/dpctl/_sycl_device.pyx index acd167f25a..9a50eca7d8 100644 --- a/dpctl/_sycl_device.pyx +++ b/dpctl/_sycl_device.pyx @@ -24,6 +24,7 @@ from ._backend cimport ( _aspect_type, _backend_type, _device_type, + _partition_affinity_domain_type, DPCTLCString_Delete, DPCTLDefaultSelector_Create, DPCTLDevice_Copy, @@ -66,6 +67,8 @@ from ._backend cimport ( DPCTLDevice_GetPreferredVectorWidthDouble, DPCTLDevice_GetPreferredVectorWidthHalf, DPCTLDevice_CreateSubDevicesEqually, + DPCTLDevice_CreateSubDevicesByCounts, + DPCTLDevice_CreateSubDevicesByAffinity, ) from . import backend_type, device_type from libc.stdint cimport uint32_t @@ -189,6 +192,29 @@ cdef class SyclDevice(_SyclDevice): DPCTLDeviceVector_Delete(DVRef) return devices + cpdef list create_sub_devices_by_counts(self, list counts, size_t ncounts): + """ Returns a vector of sub devices + partitioned from this SYCL device based on the counts parameter. For each + non-zero value M in the counts vector, a sub device with M compute units + is created. + """ + cdef DPCTLDeviceVectorRef DVRef = NULL + DVRef = DPCTLDevice_CreateSubDevicesByCounts(self._device_ref, counts, ncounts) + cdef list devices = _get_devices(DVRef) + DPCTLDeviceVector_Delete(DVRef) + return devices + + cpdef list create_sub_devices_by_affinity(self, _partition_affinity_domain_type domain): + """ Returns a vector of sub devices + partitioned from this SYCL device by affinity domain based on the domain + parameter. + """ + cdef DPCTLDeviceVectorRef DVRef = NULL + DVRef = DPCTLDevice_CreateSubDevicesByAffinity(self._device_ref, domain) + cdef list devices = _get_devices(DVRef) + DPCTLDeviceVector_Delete(DVRef) + return devices + def __cinit__(self, arg=None): cdef DPCTLSyclDeviceSelectorRef DSRef = NULL cdef const char *filter_c_str = NULL diff --git a/dpctl/tests/test_sycl_device.py b/dpctl/tests/test_sycl_device.py index d89c93fe14..21283c0d74 100644 --- a/dpctl/tests/test_sycl_device.py +++ b/dpctl/tests/test_sycl_device.py @@ -304,6 +304,67 @@ def check_create_sub_devices_equally(device): pytest.fail("create_sub_devices_equally failed") +def check_create_sub_devices_by_counts(device): + try: + n = device.max_compute_units / 2 + device.create_sub_devices_by_counts(np.array([n, n]), 2) + except Exception: + pytest.fail("create_sub_devices_by_counts failed") + + +def check_create_sub_devices_by_affinity_not_applicable(device): + try: + device.create_sub_devices_by_affinity( + _partition_affinity_domain_type._not_applicable + ) + except Exception: + pytest.fail("create_sub_devices_by_affinity failed") + + +def check_create_sub_devices_by_affinity_numa(device): + try: + device.create_sub_devices_by_affinity(_partition_affinity_domain_type._numa) + except Exception: + pytest.fail("create_sub_devices_by_affinity failed") + + +def check_create_sub_devices_by_affinity_L4_cache(device): + try: + device.create_sub_devices_by_affinity(_partition_affinity_domain_type._L4_cache) + except Exception: + pytest.fail("create_sub_devices_by_affinity failed") + + +def check_create_sub_devices_by_affinity_L3_cache(device): + try: + device.create_sub_devices_by_affinity(_partition_affinity_domain_type._L3_cache) + except Exception: + pytest.fail("create_sub_devices_by_affinity failed") + + +def check_create_sub_devices_by_affinity_L2_cache(device): + try: + device.create_sub_devices_by_affinity(_partition_affinity_domain_type._L2_cache) + except Exception: + pytest.fail("create_sub_devices_by_affinity failed") + + +def check_create_sub_devices_by_affinity_L1_cache(device): + try: + device.create_sub_devices_by_affinity(_partition_affinity_domain_type._L1_cache) + except Exception: + pytest.fail("create_sub_devices_by_affinity failed") + + +def check_create_sub_devices_by_affinity_next_partitionable(device): + try: + device.create_sub_devices_by_affinity( + _partition_affinity_domain_type._next_partitionable + ) + except Exception: + pytest.fail("create_sub_devices_by_affinity failed") + + list_of_checks = [ check_get_max_compute_units, check_get_max_work_item_dims, @@ -341,6 +402,14 @@ def check_create_sub_devices_equally(device): check_has_aspect_usm_restricted_shared_allocations, check_has_aspect_usm_system_allocator, check_create_sub_devices_equally, + check_create_sub_devices_by_counts, + check_create_sub_devices_by_affinity_not_applicable, + check_create_sub_devices_by_affinity_numa, + check_create_sub_devices_by_affinity_L4_cache, + check_create_sub_devices_by_affinity_L3_cache, + check_create_sub_devices_by_affinity_L2_cache, + check_create_sub_devices_by_affinity_L1_cache, + check_create_sub_devices_by_affinity_next_partitionable, ] From 5130e693ec4f742a644d8fc69336a3aa7090ba47 Mon Sep 17 00:00:00 2001 From: etotmeni Date: Mon, 29 Mar 2021 07:21:18 -0500 Subject: [PATCH 16/23] Fix cython create_sub_devices_by_counts --- dpctl/_sycl_device.pxd | 2 +- dpctl/_sycl_device.pyx | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/dpctl/_sycl_device.pxd b/dpctl/_sycl_device.pxd index 010c85ecfd..a09e8baf02 100644 --- a/dpctl/_sycl_device.pxd +++ b/dpctl/_sycl_device.pxd @@ -47,5 +47,5 @@ cdef class SyclDevice(_SyclDevice): cdef int _init_from_selector(self, DPCTLSyclDeviceSelectorRef DSRef) cdef DPCTLSyclDeviceRef get_device_ref(self) cpdef list create_sub_devices_equally(self, size_t count) - cpdef list create_sub_devices_by_counts(self, list counts, size_t ncounts) + cpdef list create_sub_devices_by_counts(self, size_t[:] counts, size_t ncounts) cpdef list create_sub_devices_by_affinity(self, _partition_affinity_domain_type domain) diff --git a/dpctl/_sycl_device.pyx b/dpctl/_sycl_device.pyx index 9a50eca7d8..6e53ce4837 100644 --- a/dpctl/_sycl_device.pyx +++ b/dpctl/_sycl_device.pyx @@ -192,14 +192,15 @@ cdef class SyclDevice(_SyclDevice): DPCTLDeviceVector_Delete(DVRef) return devices - cpdef list create_sub_devices_by_counts(self, list counts, size_t ncounts): + cpdef list create_sub_devices_by_counts(self, size_t[:] counts, size_t ncounts): """ Returns a vector of sub devices partitioned from this SYCL device based on the counts parameter. For each non-zero value M in the counts vector, a sub device with M compute units is created. """ + cdef size_t *counts_buff = &counts[0] cdef DPCTLDeviceVectorRef DVRef = NULL - DVRef = DPCTLDevice_CreateSubDevicesByCounts(self._device_ref, counts, ncounts) + DVRef = DPCTLDevice_CreateSubDevicesByCounts(self._device_ref, counts_buff, ncounts) cdef list devices = _get_devices(DVRef) DPCTLDeviceVector_Delete(DVRef) return devices From 3b4bae206f1aa318348f4fa3292f469911dbb620 Mon Sep 17 00:00:00 2001 From: etotmeni Date: Mon, 29 Mar 2021 08:20:10 -0500 Subject: [PATCH 17/23] Fix create_sub_devices_by_affinity --- dpctl/_backend.pxd | 2 +- dpctl/_sycl_device.pxd | 2 +- dpctl/_sycl_device.pyx | 21 +++++++++++++++++++-- dpctl/tests/test_sycl_device.py | 19 ++++++++----------- 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/dpctl/_backend.pxd b/dpctl/_backend.pxd index 4303965b60..66bf205f4c 100644 --- a/dpctl/_backend.pxd +++ b/dpctl/_backend.pxd @@ -104,7 +104,7 @@ cdef extern from "dpctl_sycl_enum_types.h": ctypedef _aspect_type DPCTLSyclAspectType - cpdef enum _partition_affinity_domain_type 'DPCTLPartitionAffinityDomainType': + cdef enum _partition_affinity_domain_type 'DPCTLPartitionAffinityDomainType': _not_applicable 'not_applicable', _numa 'numa', _L4_cache 'L4_cache', diff --git a/dpctl/_sycl_device.pxd b/dpctl/_sycl_device.pxd index a09e8baf02..df338b1e70 100644 --- a/dpctl/_sycl_device.pxd +++ b/dpctl/_sycl_device.pxd @@ -48,4 +48,4 @@ cdef class SyclDevice(_SyclDevice): cdef DPCTLSyclDeviceRef get_device_ref(self) cpdef list create_sub_devices_equally(self, size_t count) cpdef list create_sub_devices_by_counts(self, size_t[:] counts, size_t ncounts) - cpdef list create_sub_devices_by_affinity(self, _partition_affinity_domain_type domain) + cpdef list create_sub_devices_by_affinity(self, str domain) diff --git a/dpctl/_sycl_device.pyx b/dpctl/_sycl_device.pyx index 6e53ce4837..560d007b22 100644 --- a/dpctl/_sycl_device.pyx +++ b/dpctl/_sycl_device.pyx @@ -205,13 +205,30 @@ cdef class SyclDevice(_SyclDevice): DPCTLDeviceVector_Delete(DVRef) return devices - cpdef list create_sub_devices_by_affinity(self, _partition_affinity_domain_type domain): + cpdef list create_sub_devices_by_affinity(self, str domain): """ Returns a vector of sub devices partitioned from this SYCL device by affinity domain based on the domain parameter. """ + cdef _partition_affinity_domain_type domain_type + if domain == "not_applicable": + domain_type = _partition_affinity_domain_type._not_applicable + elif domain == "numa": + domain_type = _partition_affinity_domain_type._numa + elif domain == "L4_cache": + domain_type = _partition_affinity_domain_type._L4_cache + elif domain == "L3_cache": + domain_type = _partition_affinity_domain_type._L3_cache + elif domain == "L2_cache": + domain_type = _partition_affinity_domain_type._L2_cache + elif domain == "L1_cache": + domain_type = _partition_affinity_domain_type._L1_cache + elif domain == "next_partitionable": + domain_type = _partition_affinity_domain_type._next_partitionable + else: + raise Exception('Unsupported type of domain') cdef DPCTLDeviceVectorRef DVRef = NULL - DVRef = DPCTLDevice_CreateSubDevicesByAffinity(self._device_ref, domain) + DVRef = DPCTLDevice_CreateSubDevicesByAffinity(self._device_ref, domain_type) cdef list devices = _get_devices(DVRef) DPCTLDeviceVector_Delete(DVRef) return devices diff --git a/dpctl/tests/test_sycl_device.py b/dpctl/tests/test_sycl_device.py index ff1020e794..29c5e12193 100644 --- a/dpctl/tests/test_sycl_device.py +++ b/dpctl/tests/test_sycl_device.py @@ -19,6 +19,7 @@ import dpctl import pytest +import numpy as np list_of_standard_selectors = [ dpctl.select_accelerator_device, @@ -314,53 +315,49 @@ def check_create_sub_devices_by_counts(device): def check_create_sub_devices_by_affinity_not_applicable(device): try: - device.create_sub_devices_by_affinity( - _partition_affinity_domain_type._not_applicable - ) + device.create_sub_devices_by_affinity("not_applicable") except Exception: pytest.fail("create_sub_devices_by_affinity failed") def check_create_sub_devices_by_affinity_numa(device): try: - device.create_sub_devices_by_affinity(_partition_affinity_domain_type._numa) + device.create_sub_devices_by_affinity("numa") except Exception: pytest.fail("create_sub_devices_by_affinity failed") def check_create_sub_devices_by_affinity_L4_cache(device): try: - device.create_sub_devices_by_affinity(_partition_affinity_domain_type._L4_cache) + device.create_sub_devices_by_affinity("L4_cache") except Exception: pytest.fail("create_sub_devices_by_affinity failed") def check_create_sub_devices_by_affinity_L3_cache(device): try: - device.create_sub_devices_by_affinity(_partition_affinity_domain_type._L3_cache) + device.create_sub_devices_by_affinity("L3_cache") except Exception: pytest.fail("create_sub_devices_by_affinity failed") def check_create_sub_devices_by_affinity_L2_cache(device): try: - device.create_sub_devices_by_affinity(_partition_affinity_domain_type._L2_cache) + device.create_sub_devices_by_affinity("L2_cache") except Exception: pytest.fail("create_sub_devices_by_affinity failed") def check_create_sub_devices_by_affinity_L1_cache(device): try: - device.create_sub_devices_by_affinity(_partition_affinity_domain_type._L1_cache) + device.create_sub_devices_by_affinity("L1_cache") except Exception: pytest.fail("create_sub_devices_by_affinity failed") def check_create_sub_devices_by_affinity_next_partitionable(device): try: - device.create_sub_devices_by_affinity( - _partition_affinity_domain_type._next_partitionable - ) + device.create_sub_devices_by_affinity("next_partitionable") except Exception: pytest.fail("create_sub_devices_by_affinity failed") From 77ba7d2e995665e8e78638bcab7c0e3dfd03ebf6 Mon Sep 17 00:00:00 2001 From: etotmeni Date: Mon, 29 Mar 2021 11:04:19 -0500 Subject: [PATCH 18/23] Add create_sub_devices for all funcs --- dpctl/_sycl_device.pxd | 3 +- dpctl/_sycl_device.pyx | 50 ++++++++++++++++++++------------- dpctl/tests/test_sycl_device.py | 38 ++++++++++++------------- 3 files changed, 51 insertions(+), 40 deletions(-) diff --git a/dpctl/_sycl_device.pxd b/dpctl/_sycl_device.pxd index df338b1e70..e0a924279f 100644 --- a/dpctl/_sycl_device.pxd +++ b/dpctl/_sycl_device.pxd @@ -23,7 +23,6 @@ from ._backend cimport ( DPCTLSyclDeviceRef, DPCTLSyclDeviceSelectorRef, - DPCTLPartitionAffinityDomainType, _partition_affinity_domain_type ) @@ -48,4 +47,4 @@ cdef class SyclDevice(_SyclDevice): cdef DPCTLSyclDeviceRef get_device_ref(self) cpdef list create_sub_devices_equally(self, size_t count) cpdef list create_sub_devices_by_counts(self, size_t[:] counts, size_t ncounts) - cpdef list create_sub_devices_by_affinity(self, str domain) + cpdef list create_sub_devices_by_affinity(self, _partition_affinity_domain_type domain) diff --git a/dpctl/_sycl_device.pyx b/dpctl/_sycl_device.pyx index 560d007b22..c10a792490 100644 --- a/dpctl/_sycl_device.pyx +++ b/dpctl/_sycl_device.pyx @@ -73,6 +73,7 @@ from ._backend cimport ( from . import backend_type, device_type from libc.stdint cimport uint32_t import warnings +import numpy as np __all__ = [ "SyclDevice", @@ -205,34 +206,45 @@ cdef class SyclDevice(_SyclDevice): DPCTLDeviceVector_Delete(DVRef) return devices - cpdef list create_sub_devices_by_affinity(self, str domain): + cpdef list create_sub_devices_by_affinity(self, _partition_affinity_domain_type domain): """ Returns a vector of sub devices partitioned from this SYCL device by affinity domain based on the domain parameter. """ - cdef _partition_affinity_domain_type domain_type - if domain == "not_applicable": - domain_type = _partition_affinity_domain_type._not_applicable - elif domain == "numa": - domain_type = _partition_affinity_domain_type._numa - elif domain == "L4_cache": - domain_type = _partition_affinity_domain_type._L4_cache - elif domain == "L3_cache": - domain_type = _partition_affinity_domain_type._L3_cache - elif domain == "L2_cache": - domain_type = _partition_affinity_domain_type._L2_cache - elif domain == "L1_cache": - domain_type = _partition_affinity_domain_type._L1_cache - elif domain == "next_partitionable": - domain_type = _partition_affinity_domain_type._next_partitionable - else: - raise Exception('Unsupported type of domain') cdef DPCTLDeviceVectorRef DVRef = NULL - DVRef = DPCTLDevice_CreateSubDevicesByAffinity(self._device_ref, domain_type) + DVRef = DPCTLDevice_CreateSubDevicesByAffinity(self._device_ref, domain) cdef list devices = _get_devices(DVRef) DPCTLDeviceVector_Delete(DVRef) return devices + def create_sub_devices(self, partition=None): + if isinstance(partition, int) and partition > 0: + self.create_sub_devices_equally(partition) + elif isinstance(partition, tuple) and all([i > 0 for i in partition]): + counts = np.array([i for i in partition], dtype=np.uintp) + ncounts = len(counts) + self.create_sub_devices_by_counts(counts, ncounts) + elif isinstance(partition, str): + if partition == "not_applicable": + domain_type = _partition_affinity_domain_type._not_applicable + elif partition == "numa": + domain_type = _partition_affinity_domain_type._numa + elif partition == "L4_cache": + domain_type = _partition_affinity_domain_type._L4_cache + elif partition == "L3_cache": + domain_type = _partition_affinity_domain_type._L3_cache + elif partition == "L2_cache": + domain_type = _partition_affinity_domain_type._L2_cache + elif partition == "L1_cache": + domain_type = _partition_affinity_domain_type._L1_cache + elif partition == "next_partitionable": + domain_type = _partition_affinity_domain_type._next_partitionable + else: + raise Exception('Unsupported type of domain') + self.create_sub_devices_by_affinity(domain_type) + else: + raise Exception('Unsupported type of sub-device argument') + def __cinit__(self, arg=None): cdef DPCTLSyclDeviceSelectorRef DSRef = NULL cdef const char *filter_c_str = NULL diff --git a/dpctl/tests/test_sycl_device.py b/dpctl/tests/test_sycl_device.py index 29c5e12193..d31a0d0336 100644 --- a/dpctl/tests/test_sycl_device.py +++ b/dpctl/tests/test_sycl_device.py @@ -299,67 +299,67 @@ def check_get_preferred_vector_width_half(device): def check_create_sub_devices_equally(device): try: - n = device.max_compute_units / 2 - device.create_sub_devices_equally(n) + n = int(device.max_compute_units / 2) + device.create_sub_devices(n) except Exception: - pytest.fail("create_sub_devices_equally failed") + pytest.fail("create_sub_devices failed") def check_create_sub_devices_by_counts(device): try: n = device.max_compute_units / 2 - device.create_sub_devices_by_counts(np.array([n, n]), 2) + device.create_sub_devices((n, n)) except Exception: - pytest.fail("create_sub_devices_by_counts failed") + pytest.fail("create_sub_devices failed") def check_create_sub_devices_by_affinity_not_applicable(device): try: - device.create_sub_devices_by_affinity("not_applicable") + device.create_sub_devices("not_applicable") except Exception: - pytest.fail("create_sub_devices_by_affinity failed") + pytest.fail("create_sub_devices failed") def check_create_sub_devices_by_affinity_numa(device): try: - device.create_sub_devices_by_affinity("numa") + device.create_sub_devices("numa") except Exception: - pytest.fail("create_sub_devices_by_affinity failed") + pytest.fail("create_sub_devices failed") def check_create_sub_devices_by_affinity_L4_cache(device): try: - device.create_sub_devices_by_affinity("L4_cache") + device.create_sub_devices("L4_cache") except Exception: - pytest.fail("create_sub_devices_by_affinity failed") + pytest.fail("create_sub_devices failed") def check_create_sub_devices_by_affinity_L3_cache(device): try: - device.create_sub_devices_by_affinity("L3_cache") + device.create_sub_devices("L3_cache") except Exception: - pytest.fail("create_sub_devices_by_affinity failed") + pytest.fail("create_sub_devices failed") def check_create_sub_devices_by_affinity_L2_cache(device): try: - device.create_sub_devices_by_affinity("L2_cache") + device.create_sub_devices("L2_cache") except Exception: - pytest.fail("create_sub_devices_by_affinity failed") + pytest.fail("create_sub_devices failed") def check_create_sub_devices_by_affinity_L1_cache(device): try: - device.create_sub_devices_by_affinity("L1_cache") + device.create_sub_devices("L1_cache") except Exception: - pytest.fail("create_sub_devices_by_affinity failed") + pytest.fail("create_sub_devices failed") def check_create_sub_devices_by_affinity_next_partitionable(device): try: - device.create_sub_devices_by_affinity("next_partitionable") + device.create_sub_devices("next_partitionable") except Exception: - pytest.fail("create_sub_devices_by_affinity failed") + pytest.fail("create_sub_devices failed") def check_print_device_info(device): From 2f3e4fadb5f12d232c0372c55d4e26cdc8433353 Mon Sep 17 00:00:00 2001 From: etotmeni Date: Mon, 29 Mar 2021 11:07:01 -0500 Subject: [PATCH 19/23] Del useless import --- dpctl/tests/test_sycl_device.py | 1 - 1 file changed, 1 deletion(-) diff --git a/dpctl/tests/test_sycl_device.py b/dpctl/tests/test_sycl_device.py index d31a0d0336..a70672e3ac 100644 --- a/dpctl/tests/test_sycl_device.py +++ b/dpctl/tests/test_sycl_device.py @@ -19,7 +19,6 @@ import dpctl import pytest -import numpy as np list_of_standard_selectors = [ dpctl.select_accelerator_device, From b1aa862d53055530511585134e46408b93165188 Mon Sep 17 00:00:00 2001 From: etotmeni Date: Mon, 29 Mar 2021 11:26:27 -0500 Subject: [PATCH 20/23] Fix formatting --- dpctl-capi/source/dpctl_sycl_device_interface.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/dpctl-capi/source/dpctl_sycl_device_interface.cpp b/dpctl-capi/source/dpctl_sycl_device_interface.cpp index 16eb438909..b80638798c 100644 --- a/dpctl-capi/source/dpctl_sycl_device_interface.cpp +++ b/dpctl-capi/source/dpctl_sycl_device_interface.cpp @@ -611,4 +611,3 @@ __dpctl_give DPCTLDeviceVectorRef DPCTLDevice_CreateSubDevicesByAffinity( } return wrap(Devices); } - From 81df60e5086bb30a73dfc38f305d0fd3f968e902 Mon Sep 17 00:00:00 2001 From: etotmeni Date: Wed, 31 Mar 2021 06:45:02 -0500 Subject: [PATCH 21/23] Small fixes --- dpctl/_sycl_device.pxd | 7 ++--- dpctl/_sycl_device.pyx | 45 ++++++++++++++++++++++++--------- dpctl/tests/test_sycl_device.py | 21 ++++++++++++++- 3 files changed, 57 insertions(+), 16 deletions(-) diff --git a/dpctl/_sycl_device.pxd b/dpctl/_sycl_device.pxd index e0a924279f..99878c77c5 100644 --- a/dpctl/_sycl_device.pxd +++ b/dpctl/_sycl_device.pxd @@ -45,6 +45,7 @@ cdef class SyclDevice(_SyclDevice): cdef int _init_from__SyclDevice(self, _SyclDevice other) cdef int _init_from_selector(self, DPCTLSyclDeviceSelectorRef DSRef) cdef DPCTLSyclDeviceRef get_device_ref(self) - cpdef list create_sub_devices_equally(self, size_t count) - cpdef list create_sub_devices_by_counts(self, size_t[:] counts, size_t ncounts) - cpdef list create_sub_devices_by_affinity(self, _partition_affinity_domain_type domain) + cdef _raise_sub_devices_creation_error(self, fname, errcode) + cdef list create_sub_devices_equally(self, size_t count) + cdef list create_sub_devices_by_counts(self, list counts) + cdef list create_sub_devices_by_affinity(self, _partition_affinity_domain_type domain) diff --git a/dpctl/_sycl_device.pyx b/dpctl/_sycl_device.pyx index c10a792490..6977a5cfc8 100644 --- a/dpctl/_sycl_device.pyx +++ b/dpctl/_sycl_device.pyx @@ -73,13 +73,22 @@ from ._backend cimport ( from . import backend_type, device_type from libc.stdint cimport uint32_t import warnings -import numpy as np +from libc.stdlib cimport malloc, free __all__ = [ "SyclDevice", ] +cdef class SubDeviceCreationError(Exception): + """ + A SubDeviceCreationError exception is raised when + sub-devices were not created. + + """ + pass + + cdef class _SyclDevice: """ A helper metaclass to abstract a cl::sycl::device instance. """ @@ -179,7 +188,13 @@ cdef class SyclDevice(_SyclDevice): SyclDevice._init_helper(self, DRef) return 0 - cpdef list create_sub_devices_equally(self, size_t count): + cdef _raise_sub_devices_creation_error(self, fname, errcode): + e = SubDeviceCreationError("Sub-devices were not created.") + e.fname = fname + e.code = errcode + raise e + + cdef list create_sub_devices_equally(self, size_t count): """ Returns a vector of sub devices partitioned from this SYCL device based on the count parameter. The returned vector contains as many sub devices as can be created such that each sub @@ -189,41 +204,47 @@ cdef class SyclDevice(_SyclDevice): """ cdef DPCTLDeviceVectorRef DVRef = NULL DVRef = DPCTLDevice_CreateSubDevicesEqually(self._device_ref, count) + if DVRef is NULL: + self._raise_sub_devices_creation_error("DPCTLSubDeviceCreationError", -1) cdef list devices = _get_devices(DVRef) DPCTLDeviceVector_Delete(DVRef) return devices - cpdef list create_sub_devices_by_counts(self, size_t[:] counts, size_t ncounts): + cdef list create_sub_devices_by_counts(self, list counts): """ Returns a vector of sub devices partitioned from this SYCL device based on the counts parameter. For each non-zero value M in the counts vector, a sub device with M compute units is created. """ - cdef size_t *counts_buff = &counts[0] + cdef size_t ncounts = len(counts) + cdef size_t *counts_buff = malloc(ncounts * sizeof(size_t)) cdef DPCTLDeviceVectorRef DVRef = NULL DVRef = DPCTLDevice_CreateSubDevicesByCounts(self._device_ref, counts_buff, ncounts) + if DVRef is NULL: + self._raise_sub_devices_creation_error("DPCTLSubDeviceCreationError", -1) cdef list devices = _get_devices(DVRef) + free(counts_buff) DPCTLDeviceVector_Delete(DVRef) return devices - cpdef list create_sub_devices_by_affinity(self, _partition_affinity_domain_type domain): + cdef list create_sub_devices_by_affinity(self, _partition_affinity_domain_type domain): """ Returns a vector of sub devices partitioned from this SYCL device by affinity domain based on the domain parameter. """ cdef DPCTLDeviceVectorRef DVRef = NULL DVRef = DPCTLDevice_CreateSubDevicesByAffinity(self._device_ref, domain) + if DVRef is NULL: + self._raise_sub_devices_creation_error("DPCTLSubDeviceCreationError", -1) cdef list devices = _get_devices(DVRef) DPCTLDeviceVector_Delete(DVRef) return devices - def create_sub_devices(self, partition=None): + def create_sub_devices(self, partition): if isinstance(partition, int) and partition > 0: - self.create_sub_devices_equally(partition) - elif isinstance(partition, tuple) and all([i > 0 for i in partition]): - counts = np.array([i for i in partition], dtype=np.uintp) - ncounts = len(counts) - self.create_sub_devices_by_counts(counts, ncounts) + return self.create_sub_devices_equally(partition) + elif isinstance(partition, list) and all([i > 0 for i in partition]): + return self.create_sub_devices_by_counts(partition) elif isinstance(partition, str): if partition == "not_applicable": domain_type = _partition_affinity_domain_type._not_applicable @@ -241,7 +262,7 @@ cdef class SyclDevice(_SyclDevice): domain_type = _partition_affinity_domain_type._next_partitionable else: raise Exception('Unsupported type of domain') - self.create_sub_devices_by_affinity(domain_type) + return self.create_sub_devices_by_affinity(domain_type) else: raise Exception('Unsupported type of sub-device argument') diff --git a/dpctl/tests/test_sycl_device.py b/dpctl/tests/test_sycl_device.py index a70672e3ac..a53ccb395f 100644 --- a/dpctl/tests/test_sycl_device.py +++ b/dpctl/tests/test_sycl_device.py @@ -19,6 +19,7 @@ import dpctl import pytest +from dpctl._sycl_device import SubDeviceCreationError list_of_standard_selectors = [ dpctl.select_accelerator_device, @@ -300,6 +301,8 @@ def check_create_sub_devices_equally(device): try: n = int(device.max_compute_units / 2) device.create_sub_devices(n) + except SubDeviceCreationError: + pytest.skip("create_sub_devices can't create sub-devices on this device") except Exception: pytest.fail("create_sub_devices failed") @@ -307,7 +310,9 @@ def check_create_sub_devices_equally(device): def check_create_sub_devices_by_counts(device): try: n = device.max_compute_units / 2 - device.create_sub_devices((n, n)) + device.create_sub_devices([n, n]) + except SubDeviceCreationError: + pytest.skip("create_sub_devices can't create sub-devices on this device") except Exception: pytest.fail("create_sub_devices failed") @@ -315,6 +320,8 @@ def check_create_sub_devices_by_counts(device): def check_create_sub_devices_by_affinity_not_applicable(device): try: device.create_sub_devices("not_applicable") + except SubDeviceCreationError: + pytest.skip("create_sub_devices can't create sub-devices on this device") except Exception: pytest.fail("create_sub_devices failed") @@ -322,6 +329,8 @@ def check_create_sub_devices_by_affinity_not_applicable(device): def check_create_sub_devices_by_affinity_numa(device): try: device.create_sub_devices("numa") + except SubDeviceCreationError: + pytest.skip("create_sub_devices can't create sub-devices on this device") except Exception: pytest.fail("create_sub_devices failed") @@ -329,6 +338,8 @@ def check_create_sub_devices_by_affinity_numa(device): def check_create_sub_devices_by_affinity_L4_cache(device): try: device.create_sub_devices("L4_cache") + except SubDeviceCreationError: + pytest.skip("create_sub_devices can't create sub-devices on this device") except Exception: pytest.fail("create_sub_devices failed") @@ -336,6 +347,8 @@ def check_create_sub_devices_by_affinity_L4_cache(device): def check_create_sub_devices_by_affinity_L3_cache(device): try: device.create_sub_devices("L3_cache") + except SubDeviceCreationError: + pytest.skip("create_sub_devices can't create sub-devices on this device") except Exception: pytest.fail("create_sub_devices failed") @@ -343,6 +356,8 @@ def check_create_sub_devices_by_affinity_L3_cache(device): def check_create_sub_devices_by_affinity_L2_cache(device): try: device.create_sub_devices("L2_cache") + except SubDeviceCreationError: + pytest.skip("create_sub_devices can't create sub-devices on this device") except Exception: pytest.fail("create_sub_devices failed") @@ -350,6 +365,8 @@ def check_create_sub_devices_by_affinity_L2_cache(device): def check_create_sub_devices_by_affinity_L1_cache(device): try: device.create_sub_devices("L1_cache") + except SubDeviceCreationError: + pytest.skip("create_sub_devices can't create sub-devices on this device") except Exception: pytest.fail("create_sub_devices failed") @@ -357,6 +374,8 @@ def check_create_sub_devices_by_affinity_L1_cache(device): def check_create_sub_devices_by_affinity_next_partitionable(device): try: device.create_sub_devices("next_partitionable") + except SubDeviceCreationError: + pytest.skip("create_sub_devices can't create sub-devices on this device") except Exception: pytest.fail("create_sub_devices failed") From f3defb9f572ecb9e71ad7a6a98885c415e7b7370 Mon Sep 17 00:00:00 2001 From: etotmeni Date: Wed, 31 Mar 2021 07:10:48 -0500 Subject: [PATCH 22/23] Fix create_sub_devices_by_counts array --- dpctl/_sycl_device.pyx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dpctl/_sycl_device.pyx b/dpctl/_sycl_device.pyx index 6977a5cfc8..5a421ace6f 100644 --- a/dpctl/_sycl_device.pyx +++ b/dpctl/_sycl_device.pyx @@ -219,6 +219,9 @@ cdef class SyclDevice(_SyclDevice): cdef size_t ncounts = len(counts) cdef size_t *counts_buff = malloc(ncounts * sizeof(size_t)) cdef DPCTLDeviceVectorRef DVRef = NULL + cdef int i + for i in range(ncounts): + counts_buff[i] = counts[i] DVRef = DPCTLDevice_CreateSubDevicesByCounts(self._device_ref, counts_buff, ncounts) if DVRef is NULL: self._raise_sub_devices_creation_error("DPCTLSubDeviceCreationError", -1) From af105179b18f2a7bcdf27f9f4cef8a29700315a2 Mon Sep 17 00:00:00 2001 From: etotmeni Date: Wed, 31 Mar 2021 07:20:43 -0500 Subject: [PATCH 23/23] Del useless import --- dpctl-capi/include/dpctl_sycl_device_interface.h | 1 - 1 file changed, 1 deletion(-) diff --git a/dpctl-capi/include/dpctl_sycl_device_interface.h b/dpctl-capi/include/dpctl_sycl_device_interface.h index 161d0edbff..a82f3b8130 100644 --- a/dpctl-capi/include/dpctl_sycl_device_interface.h +++ b/dpctl-capi/include/dpctl_sycl_device_interface.h @@ -34,7 +34,6 @@ #include "dpctl_sycl_device_manager.h" #include "dpctl_sycl_enum_types.h" #include "dpctl_sycl_types.h" -#include DPCTL_C_EXTERN_C_BEGIN