Skip to content

Commit c9fd48b

Browse files
Merge pull request #343 from IntelPython/review-sub-devices
Review sub devices
2 parents 77df794 + 8481251 commit c9fd48b

10 files changed

+842
-2
lines changed

dpctl-capi/helper/include/dpctl_utils_helper.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,32 @@ sycl::aspect DPCTL_DPCTLAspectTypeToSyclAspect(DPCTLSyclAspectType AspectTy);
149149
*/
150150
DPCTL_API
151151
DPCTLSyclAspectType DPCTL_SyclAspectToDPCTLAspectType(sycl::aspect Aspect);
152+
153+
/*!
154+
* @brief Converts a DPCTLPartitionAffinityDomainType enum value to its
155+
* corresponding sycl::info::partition_affinity_domain enum value.
156+
*
157+
* @param PartitionAffinityDomainTy A
158+
* DPCTLPartitionAffinityDomainType enum value
159+
* @return A sycl::info::partition_affinity_domain enum value for the input
160+
* DPCTLPartitionAffinityDomainType enum value.
161+
* @throws runtime_error
162+
*/
163+
DPCTL_API
164+
sycl::info::partition_affinity_domain
165+
DPCTL_DPCTLPartitionAffinityDomainTypeToSycl(
166+
DPCTLPartitionAffinityDomainType PartitionAffinityDomainTy);
167+
168+
/*!
169+
* @brief Converts a sycl::info::partition_affinity_domain enum value to
170+
* corresponding DPCTLPartitionAffinityDomainType enum value.
171+
*
172+
* @param PartitionAffinityDomain sycl::info::partition_affinity_domain to be
173+
* converted to DPCTLPartitionAffinityDomainType enum.
174+
* @return A DPCTLPartitionAffinityDomainType enum value for the input
175+
* sycl::info::partition_affinity_domain enum value.
176+
* @throws runtime_error
177+
*/
178+
DPCTL_API
179+
DPCTLPartitionAffinityDomainType DPCTL_SyclPartitionAffinityDomainToDPCTLType(
180+
sycl::info::partition_affinity_domain PartitionAffinityDomain);

dpctl-capi/helper/source/dpctl_utils_helper.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,3 +382,49 @@ DPCTLSyclAspectType DPCTL_SyclAspectToDPCTLAspectType(aspect Aspect)
382382
throw runtime_error("Unsupported aspect type", -1);
383383
}
384384
}
385+
386+
info::partition_affinity_domain DPCTL_DPCTLPartitionAffinityDomainTypeToSycl(
387+
DPCTLPartitionAffinityDomainType PartitionAffinityDomainTy)
388+
{
389+
switch (PartitionAffinityDomainTy) {
390+
case DPCTLPartitionAffinityDomainType::not_applicable:
391+
return info::partition_affinity_domain::not_applicable;
392+
case DPCTLPartitionAffinityDomainType::numa:
393+
return info::partition_affinity_domain::numa;
394+
case DPCTLPartitionAffinityDomainType::L4_cache:
395+
return info::partition_affinity_domain::L4_cache;
396+
case DPCTLPartitionAffinityDomainType::L3_cache:
397+
return info::partition_affinity_domain::L3_cache;
398+
case DPCTLPartitionAffinityDomainType::L2_cache:
399+
return info::partition_affinity_domain::L2_cache;
400+
case DPCTLPartitionAffinityDomainType::L1_cache:
401+
return info::partition_affinity_domain::L1_cache;
402+
case DPCTLPartitionAffinityDomainType::next_partitionable:
403+
return info::partition_affinity_domain::next_partitionable;
404+
default:
405+
throw runtime_error("Unsupported partition_affinity_domain type", -1);
406+
}
407+
}
408+
409+
DPCTLPartitionAffinityDomainType DPCTL_SyclPartitionAffinityDomainToDPCTLType(
410+
sycl::info::partition_affinity_domain PartitionAffinityDomain)
411+
{
412+
switch (PartitionAffinityDomain) {
413+
case info::partition_affinity_domain::not_applicable:
414+
return DPCTLPartitionAffinityDomainType::not_applicable;
415+
case info::partition_affinity_domain::numa:
416+
return DPCTLPartitionAffinityDomainType::numa;
417+
case info::partition_affinity_domain::L4_cache:
418+
return DPCTLPartitionAffinityDomainType::L4_cache;
419+
case info::partition_affinity_domain::L3_cache:
420+
return DPCTLPartitionAffinityDomainType::L3_cache;
421+
case info::partition_affinity_domain::L2_cache:
422+
return DPCTLPartitionAffinityDomainType::L2_cache;
423+
case info::partition_affinity_domain::L1_cache:
424+
return DPCTLPartitionAffinityDomainType::L1_cache;
425+
case info::partition_affinity_domain::next_partitionable:
426+
return DPCTLPartitionAffinityDomainType::next_partitionable;
427+
default:
428+
throw runtime_error("Unsupported partition_affinity_domain type", -1);
429+
}
430+
}

dpctl-capi/include/dpctl_sycl_device_interface.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "Support/ExternC.h"
3232
#include "Support/MemOwnershipAttrs.h"
3333
#include "dpctl_data_types.h"
34+
#include "dpctl_sycl_device_manager.h"
3435
#include "dpctl_sycl_enum_types.h"
3536
#include "dpctl_sycl_types.h"
3637

@@ -265,6 +266,57 @@ DPCTL_API
265266
bool DPCTLDevice_HasAspect(__dpctl_keep const DPCTLSyclDeviceRef DRef,
266267
DPCTLSyclAspectType AT);
267268

269+
/*!
270+
* @brief Returns a vector of sub devices
271+
* partitioned from this SYCL device based on the count parameter. The returned
272+
* vector contains as many sub devices as can be created such that each sub
273+
* device contains count compute units. If the device’s total number of compute
274+
* units is not evenly divided by count, then the remaining compute units are
275+
* not included in any of the sub devices.
276+
*
277+
* @param DRef Opaque pointer to a sycl::device
278+
* @param count Count compute units that need to contains in
279+
* subdevices
280+
* @return A #DPCTLDeviceVectorRef containing #DPCTLSyclDeviceRef objects
281+
*/
282+
DPCTL_API
283+
__dpctl_give DPCTLDeviceVectorRef
284+
DPCTLDevice_CreateSubDevicesEqually(__dpctl_keep const DPCTLSyclDeviceRef DRef,
285+
size_t count);
286+
287+
/*!
288+
* @brief Returns a vector of sub devices
289+
* partitioned from this SYCL device based on the counts parameter. For each
290+
* non-zero value M in the counts vector, a sub device with M compute units
291+
* is created.
292+
*
293+
* @param DRef Opaque pointer to a sycl::device
294+
* @param counts Array with count compute units
295+
* that need to contains in subdevices
296+
* @param ncounts Number of counts
297+
* @return A #DPCTLDeviceVectorRef containing #DPCTLSyclDeviceRef objects
298+
*/
299+
DPCTL_API
300+
__dpctl_give DPCTLDeviceVectorRef
301+
DPCTLDevice_CreateSubDevicesByCounts(__dpctl_keep const DPCTLSyclDeviceRef DRef,
302+
__dpctl_keep size_t *counts,
303+
size_t ncounts);
304+
305+
/*!
306+
* @brief Returns a vector of sub devices
307+
* partitioned from this SYCL device by affinity domain based on the domain
308+
* parameter.
309+
*
310+
* @param DRef Opaque pointer to a sycl::device
311+
* @param DPCTLPartitionAffinityDomainType DPCTLPartitionAffinityDomainType
312+
* of sycl::info::partition_affinity_domain
313+
* @return A #DPCTLDeviceVectorRef containing #DPCTLSyclDeviceRef objects
314+
*/
315+
DPCTL_API
316+
__dpctl_give DPCTLDeviceVectorRef DPCTLDevice_CreateSubDevicesByAffinity(
317+
__dpctl_keep const DPCTLSyclDeviceRef DRef,
318+
DPCTLPartitionAffinityDomainType PartitionAffinityDomainTy);
319+
268320
DPCTL_C_EXTERN_C_END
269321

270322
/*!

dpctl-capi/include/dpctl_sycl_enum_types.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,21 @@ enum DPCTLSyclAspectType
122122
usm_system_allocator
123123
};
124124

125+
/*!
126+
* @brief DPCTL analogue of sycl::info::partition_affinity_domain enum
127+
*
128+
*/
129+
enum DPCTLPartitionAffinityDomainType
130+
{
131+
not_applicable,
132+
numa,
133+
L4_cache,
134+
L3_cache,
135+
L2_cache,
136+
L1_cache,
137+
next_partitionable
138+
};
139+
125140
/*!
126141
* @brief Enums to depict the properties that can be passed to a sycl::queue
127142
* constructor.

dpctl-capi/source/dpctl_sycl_device_interface.cpp

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ namespace
3939
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(device, DPCTLSyclDeviceRef)
4040
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(device_selector, DPCTLSyclDeviceSelectorRef)
4141
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(platform, DPCTLSyclPlatformRef)
42+
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(vector_class<DPCTLSyclDeviceRef>,
43+
DPCTLDeviceVectorRef)
4244

4345
} /* end of anonymous namespace */
4446

@@ -525,3 +527,89 @@ uint32_t DPCTLDevice_GetPreferredVectorWidthHalf(
525527
}
526528
return vector_width_half;
527529
}
530+
531+
__dpctl_give DPCTLDeviceVectorRef
532+
DPCTLDevice_CreateSubDevicesEqually(__dpctl_keep const DPCTLSyclDeviceRef DRef,
533+
size_t count)
534+
{
535+
vector_class<DPCTLSyclDeviceRef> *Devices = nullptr;
536+
auto D = unwrap(DRef);
537+
if (D) {
538+
try {
539+
auto subDevices = D->create_sub_devices<
540+
info::partition_property::partition_equally>(count);
541+
Devices = new vector_class<DPCTLSyclDeviceRef>();
542+
for (const auto &sd : subDevices) {
543+
Devices->emplace_back(wrap(new device(sd)));
544+
}
545+
} catch (std::bad_alloc const &ba) {
546+
std::cerr << ba.what() << '\n';
547+
return nullptr;
548+
} catch (feature_not_supported const &fnse) {
549+
std::cerr << fnse.what() << '\n';
550+
} catch (runtime_error const &re) {
551+
// \todo log error
552+
std::cerr << re.what() << '\n';
553+
}
554+
}
555+
return wrap(Devices);
556+
}
557+
558+
__dpctl_give DPCTLDeviceVectorRef
559+
DPCTLDevice_CreateSubDevicesByCounts(__dpctl_keep const DPCTLSyclDeviceRef DRef,
560+
__dpctl_keep size_t *counts,
561+
size_t ncounts)
562+
{
563+
vector_class<DPCTLSyclDeviceRef> *Devices = nullptr;
564+
std::vector<size_t> vcounts;
565+
vcounts.assign(counts, counts + ncounts);
566+
auto D = unwrap(DRef);
567+
if (D) {
568+
try {
569+
auto subDevices = D->create_sub_devices<
570+
info::partition_property::partition_by_counts>(vcounts);
571+
Devices = new vector_class<DPCTLSyclDeviceRef>();
572+
for (const auto &sd : subDevices) {
573+
Devices->emplace_back(wrap(new device(sd)));
574+
}
575+
} catch (std::bad_alloc const &ba) {
576+
std::cerr << ba.what() << '\n';
577+
return nullptr;
578+
} catch (feature_not_supported const &fnse) {
579+
std::cerr << fnse.what() << '\n';
580+
} catch (runtime_error const &re) {
581+
// \todo log error
582+
std::cerr << re.what() << '\n';
583+
}
584+
}
585+
return wrap(Devices);
586+
}
587+
588+
__dpctl_give DPCTLDeviceVectorRef DPCTLDevice_CreateSubDevicesByAffinity(
589+
__dpctl_keep const DPCTLSyclDeviceRef DRef,
590+
DPCTLPartitionAffinityDomainType PartitionAffinityDomainTy)
591+
{
592+
vector_class<DPCTLSyclDeviceRef> *Devices = nullptr;
593+
auto D = unwrap(DRef);
594+
if (D) {
595+
try {
596+
auto domain = DPCTL_DPCTLPartitionAffinityDomainTypeToSycl(
597+
PartitionAffinityDomainTy);
598+
auto subDevices = D->create_sub_devices<
599+
info::partition_property::partition_by_affinity_domain>(domain);
600+
Devices = new vector_class<DPCTLSyclDeviceRef>();
601+
for (const auto &sd : subDevices) {
602+
Devices->emplace_back(wrap(new device(sd)));
603+
}
604+
} catch (std::bad_alloc const &ba) {
605+
std::cerr << ba.what() << '\n';
606+
return nullptr;
607+
} catch (feature_not_supported const &fnse) {
608+
std::cerr << fnse.what() << '\n';
609+
} catch (runtime_error const &re) {
610+
// \todo log error
611+
std::cerr << re.what() << '\n';
612+
}
613+
}
614+
return wrap(Devices);
615+
}

0 commit comments

Comments
 (0)