|
| 1 | +// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out |
| 2 | +// RUN: %HOST_RUN_PLACEHOLDER %t.out |
| 3 | +// RUN: %CPU_RUN_PLACEHOLDER %t.out |
| 4 | +// RUN: %GPU_RUN_PLACEHOLDER %t.out |
| 5 | +// RUN: %ACC_RUN_PLACEHOLDER %t.out |
| 6 | + |
| 7 | +//==------------ subdevice.cpp - SYCL subdevice basic test -----------------==// |
| 8 | +// |
| 9 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 10 | +// See https://llvm.org/LICENSE.txt for license information. |
| 11 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 12 | +// |
| 13 | +//===----------------------------------------------------------------------===// |
| 14 | + |
| 15 | +#include <CL/sycl.hpp> |
| 16 | +#include <algorithm> |
| 17 | +#include <cassert> |
| 18 | +#include <iostream> |
| 19 | +#include <utility> |
| 20 | + |
| 21 | +using namespace cl::sycl; |
| 22 | + |
| 23 | +int main() { |
| 24 | + try { |
| 25 | + auto devices = device::get_devices(); |
| 26 | + for (const auto &dev : devices) { |
| 27 | + // TODO: implement subdevices creation for host device |
| 28 | + if (dev.is_host()) |
| 29 | + continue; |
| 30 | + |
| 31 | + assert(dev.get_info<info::device::partition_type_property>() == |
| 32 | + info::partition_property::no_partition); |
| 33 | + |
| 34 | + size_t MaxSubDevices = |
| 35 | + dev.get_info<info::device::partition_max_sub_devices>(); |
| 36 | + |
| 37 | + if (MaxSubDevices == 0) |
| 38 | + continue; |
| 39 | + |
| 40 | + try { |
| 41 | + auto SubDevicesEq = |
| 42 | + dev.create_sub_devices<info::partition_property::partition_equally>( |
| 43 | + 1); |
| 44 | + assert(SubDevicesEq.size() == MaxSubDevices && |
| 45 | + "Requested 1 compute unit in each subdevice, expected maximum " |
| 46 | + "number of subdevices in output"); |
| 47 | + std::cout << "Created " << SubDevicesEq.size() |
| 48 | + << " subdevices using equal partition scheme" << std::endl; |
| 49 | + |
| 50 | + assert( |
| 51 | + SubDevicesEq[0].get_info<info::device::partition_type_property>() == |
| 52 | + info::partition_property::partition_equally); |
| 53 | + |
| 54 | + assert(SubDevicesEq[0].get_info<info::device::parent_device>().get() == |
| 55 | + dev.get()); |
| 56 | + } catch (feature_not_supported) { |
| 57 | + // okay skip it |
| 58 | + } |
| 59 | + |
| 60 | + try { |
| 61 | + vector_class<size_t> Counts(MaxSubDevices, 1); |
| 62 | + auto SubDevicesByCount = dev.create_sub_devices< |
| 63 | + info::partition_property::partition_by_counts>(Counts); |
| 64 | + assert(SubDevicesByCount.size() == MaxSubDevices && |
| 65 | + "Maximum number of subdevices was requested with 1 compute unit " |
| 66 | + "on each"); |
| 67 | + std::cout << "Created " << SubDevicesByCount.size() |
| 68 | + << " subdevices using partition by counts scheme." |
| 69 | + << std::endl; |
| 70 | + assert(SubDevicesByCount[0] |
| 71 | + .get_info<info::device::partition_type_property>() == |
| 72 | + info::partition_property::partition_by_counts); |
| 73 | + } catch (feature_not_supported) { |
| 74 | + // okay skip it |
| 75 | + } |
| 76 | + |
| 77 | + try { |
| 78 | + auto SubDevicesDomainNuma = dev.create_sub_devices< |
| 79 | + info::partition_property::partition_by_affinity_domain>( |
| 80 | + info::partition_affinity_domain::numa); |
| 81 | + std::cout |
| 82 | + << "Created " << SubDevicesDomainNuma.size() |
| 83 | + << " subdevices using partition by numa affinity domain scheme." |
| 84 | + << std::endl; |
| 85 | + |
| 86 | + auto SubSubDevicesDomainNuma = |
| 87 | + SubDevicesDomainNuma[0] |
| 88 | + .create_sub_devices< |
| 89 | + info::partition_property::partition_by_affinity_domain>( |
| 90 | + info::partition_affinity_domain::numa); |
| 91 | + |
| 92 | + std::cout << "Created " << SubSubDevicesDomainNuma.size() |
| 93 | + << " sub-subdevices from subdevice 0 using partition by numa " |
| 94 | + "affinity domain scheme." |
| 95 | + << std::endl; |
| 96 | + } catch (feature_not_supported) { |
| 97 | + // okay skip it |
| 98 | + } |
| 99 | + |
| 100 | + try { |
| 101 | + auto SubDevicesDomainL4 = dev.create_sub_devices< |
| 102 | + info::partition_property::partition_by_affinity_domain>( |
| 103 | + info::partition_affinity_domain::L4_cache); |
| 104 | + std::cout << "Created " << SubDevicesDomainL4.size() |
| 105 | + << " subdevices using partition by L4 cache domain scheme." |
| 106 | + << std::endl; |
| 107 | + } catch (feature_not_supported) { |
| 108 | + // okay skip it |
| 109 | + } |
| 110 | + |
| 111 | + try { |
| 112 | + auto SubDevicesDomainL3 = dev.create_sub_devices< |
| 113 | + info::partition_property::partition_by_affinity_domain>( |
| 114 | + info::partition_affinity_domain::L3_cache); |
| 115 | + std::cout << "Created " << SubDevicesDomainL3.size() |
| 116 | + << " subdevices using partition by L3 cache domain scheme." |
| 117 | + << std::endl; |
| 118 | + } catch (feature_not_supported) { |
| 119 | + // okay skip it |
| 120 | + } |
| 121 | + |
| 122 | + try { |
| 123 | + auto SubDevicesDomainL2 = dev.create_sub_devices< |
| 124 | + info::partition_property::partition_by_affinity_domain>( |
| 125 | + info::partition_affinity_domain::L2_cache); |
| 126 | + std::cout << "Created " << SubDevicesDomainL2.size() |
| 127 | + << " subdevices using partition by L2 cache domain scheme." |
| 128 | + << std::endl; |
| 129 | + } catch (feature_not_supported) { |
| 130 | + // okay skip it |
| 131 | + } |
| 132 | + |
| 133 | + try { |
| 134 | + auto SubDevicesDomainL1 = dev.create_sub_devices< |
| 135 | + info::partition_property::partition_by_affinity_domain>( |
| 136 | + info::partition_affinity_domain::L1_cache); |
| 137 | + std::cout << "Created " << SubDevicesDomainL1.size() |
| 138 | + << " subdevices using partition by L1 cache domain scheme." |
| 139 | + << std::endl; |
| 140 | + } catch (feature_not_supported) { |
| 141 | + // okay skip it |
| 142 | + } |
| 143 | + |
| 144 | + try { |
| 145 | + auto SubDevicesDomainNextPart = dev.create_sub_devices< |
| 146 | + info::partition_property::partition_by_affinity_domain>( |
| 147 | + info::partition_affinity_domain::next_partitionable); |
| 148 | + std::cout << "Created " << SubDevicesDomainNextPart.size() |
| 149 | + << " subdevices using partition by next partitionable " |
| 150 | + "domain scheme." |
| 151 | + << std::endl; |
| 152 | + |
| 153 | + auto SubSubDevicesDomainNextPart = |
| 154 | + SubDevicesDomainNextPart[0] |
| 155 | + .create_sub_devices< |
| 156 | + info::partition_property::partition_by_affinity_domain>( |
| 157 | + info::partition_affinity_domain::next_partitionable); |
| 158 | + std::cout << "Created " << SubSubDevicesDomainNextPart.size() |
| 159 | + << " sub-subdevices from subdevice 0 using partition by next " |
| 160 | + "partitionable domain scheme." |
| 161 | + << std::endl; |
| 162 | + } catch (feature_not_supported) { |
| 163 | + // okay skip it |
| 164 | + } |
| 165 | + } |
| 166 | + } catch (exception e) { |
| 167 | + std::cout << "SYCL exception caught: " << e.what() << std::endl; |
| 168 | + return 1; |
| 169 | + } |
| 170 | + return 0; |
| 171 | +} |
0 commit comments