|
| 1 | +// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out |
| 2 | +// RUN: %CPU_RUN_PLACEHOLDER %t.out |
| 3 | +// RUN: %GPU_RUN_PLACEHOLDER %t.out |
| 4 | +// RUN: %ACC_RUN_PLACEHOLDER %t.out |
| 5 | + |
| 6 | +/* Check that: |
| 7 | +1) [info::device::partition_properties]: returns the partition properties |
| 8 | +supported by this SYCL device; a vector of info::partition_property. If this |
| 9 | +SYCL device cannot be partitioned into at least two sub devices then the |
| 10 | +returned vector **must be empty**. |
| 11 | +
|
| 12 | +2) [create_sub_devices()]: If the SYCL device |
| 13 | +does not support info::partition_property::partition_by_affinity_domain or the |
| 14 | +SYCL device does not support the info::partition_affinity_domain provided, an |
| 15 | +exception with the **feature_not_supported error code must be thrown**. |
| 16 | +*/ |
| 17 | + |
| 18 | +#include <CL/sycl.hpp> |
| 19 | + |
| 20 | +/** returns true if the device supports a particular affinity domain |
| 21 | + */ |
| 22 | +static bool |
| 23 | +supports_affinity_domain(const cl::sycl::device &dev, |
| 24 | + cl::sycl::info::partition_property partitionProp, |
| 25 | + cl::sycl::info::partition_affinity_domain domain) { |
| 26 | + if (partitionProp != |
| 27 | + cl::sycl::info::partition_property::partition_by_affinity_domain) { |
| 28 | + return true; |
| 29 | + } |
| 30 | + auto supported = |
| 31 | + dev.get_info<cl::sycl::info::device::partition_affinity_domains>(); |
| 32 | + for (cl::sycl::info::partition_affinity_domain dom : supported) { |
| 33 | + if (dom == domain) { |
| 34 | + return true; |
| 35 | + } |
| 36 | + } |
| 37 | + return false; |
| 38 | +} |
| 39 | + |
| 40 | +/** returns true if the device supports a particular partition property |
| 41 | + */ |
| 42 | +static bool |
| 43 | +supports_partition_property(const cl::sycl::device &dev, |
| 44 | + cl::sycl::info::partition_property partitionProp) { |
| 45 | + auto supported = dev.get_info<cl::sycl::info::device::partition_properties>(); |
| 46 | + for (cl::sycl::info::partition_property prop : supported) { |
| 47 | + if (prop == partitionProp) { |
| 48 | + return true; |
| 49 | + } |
| 50 | + } |
| 51 | + return false; |
| 52 | +} |
| 53 | + |
| 54 | +int main() { |
| 55 | + |
| 56 | + auto dev = cl::sycl::device(cl::sycl::default_selector()); |
| 57 | + |
| 58 | + cl::sycl::info::partition_property partitionProperty = |
| 59 | + cl::sycl::info::partition_property::partition_by_affinity_domain; |
| 60 | + cl::sycl::info::partition_affinity_domain affinityDomain = |
| 61 | + cl::sycl::info::partition_affinity_domain::next_partitionable; |
| 62 | + |
| 63 | + if (supports_partition_property(dev, partitionProperty)) { |
| 64 | + if (supports_affinity_domain(dev, partitionProperty, affinityDomain)) { |
| 65 | + auto subDevices = dev.create_sub_devices< |
| 66 | + cl::sycl::info::partition_property::partition_by_affinity_domain>( |
| 67 | + affinityDomain); |
| 68 | + |
| 69 | + if (subDevices.size() < 2) { |
| 70 | + std::cerr << "device::create_sub_device(info::partition_affinity_" |
| 71 | + "domain) should have returned at least 2 devices" |
| 72 | + << std::endl; |
| 73 | + return -1; |
| 74 | + } |
| 75 | + } |
| 76 | + } else { |
| 77 | + try { |
| 78 | + auto subDevices = dev.create_sub_devices< |
| 79 | + cl::sycl::info::partition_property::partition_by_affinity_domain>( |
| 80 | + affinityDomain); |
| 81 | + std::cerr << "device::create_sub_device(info::partition_affinity_domain) " |
| 82 | + "should have thrown an exception" |
| 83 | + << std::endl; |
| 84 | + return -1; |
| 85 | + } catch (const cl::sycl::feature_not_supported &e) { |
| 86 | + } catch (...) { |
| 87 | + std::cerr << "device::create_sub_device(info::partition_affinity_domain) " |
| 88 | + "should have thrown cl::sycl::feature_not_supported" |
| 89 | + << std::endl; |
| 90 | + return -1; |
| 91 | + } |
| 92 | + } |
| 93 | + return 0; |
| 94 | +} |
0 commit comments