Skip to content

Review sub devices #343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions dpctl-capi/helper/include/dpctl_utils_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,32 @@ sycl::aspect DPCTL_DPCTLAspectTypeToSyclAspect(DPCTLSyclAspectType AspectTy);
*/
DPCTL_API
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
*/
DPCTL_API
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
*/
DPCTL_API
DPCTLPartitionAffinityDomainType DPCTL_SyclPartitionAffinityDomainToDPCTLType(
sycl::info::partition_affinity_domain PartitionAffinityDomain);
46 changes: 46 additions & 0 deletions dpctl-capi/helper/source/dpctl_utils_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
52 changes: 52 additions & 0 deletions dpctl-capi/include/dpctl_sycl_device_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -265,6 +266,57 @@ 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);

/*!
* @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 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,
__dpctl_keep size_t *counts,
size_t ncounts);

/*!
* @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

/*!
Expand Down
15 changes: 15 additions & 0 deletions dpctl-capi/include/dpctl_sycl_enum_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
88 changes: 88 additions & 0 deletions dpctl-capi/source/dpctl_sycl_device_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<DPCTLSyclDeviceRef>,
DPCTLDeviceVectorRef)

} /* end of anonymous namespace */

Expand Down Expand Up @@ -525,3 +527,89 @@ uint32_t DPCTLDevice_GetPreferredVectorWidthHalf(
}
return vector_width_half;
}

__dpctl_give DPCTLDeviceVectorRef
DPCTLDevice_CreateSubDevicesEqually(__dpctl_keep const DPCTLSyclDeviceRef DRef,
size_t count)
{
vector_class<DPCTLSyclDeviceRef> *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<DPCTLSyclDeviceRef>();
for (const 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,
__dpctl_keep size_t *counts,
size_t ncounts)
{
vector_class<DPCTLSyclDeviceRef> *Devices = nullptr;
std::vector<size_t> 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>(vcounts);
Devices = new vector_class<DPCTLSyclDeviceRef>();
for (const 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<DPCTLSyclDeviceRef> *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<DPCTLSyclDeviceRef>();
for (const 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);
}
Loading