Skip to content

Subdevices work #326

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

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
865ef9d
wip
Mar 17, 2021
1979b63
Added C-api initial for all sub-device funcs
Mar 22, 2021
a1fa5f3
Merge branch 'master' of https://github.com/IntelPython/dpctl into su…
Mar 22, 2021
df04485
Change vector type + Added tests
Mar 23, 2021
3ff6620
Merge branch 'master' of https://github.com/IntelPython/dpctl into su…
Mar 24, 2021
6f4151d
fix tests + utils
Mar 24, 2021
c7588e9
Change vector to DeviceVectorRef
Mar 24, 2021
30817fb
Fix SetAt
Mar 24, 2021
230a45b
Backup
Mar 24, 2021
51f72d6
Add backend
Mar 25, 2021
972f553
work on cython part
Mar 25, 2021
f7d2bfa
Added cpdef func
Mar 26, 2021
8933f35
Merge remote-tracking branch 'origin/master' into sub_devices
oleksandr-pavlyk Mar 26, 2021
072305a
using const qualifier in iterating over vector of sub-devices
oleksandr-pavlyk Mar 26, 2021
1838637
fix Cython error due to mismatch in declaration of DPCTLDevice_Create…
oleksandr-pavlyk Mar 26, 2021
4a5efc3
Fix tests
Mar 26, 2021
ccebb86
Delete commented code
Mar 26, 2021
d7ae52d
Added create_sub_devices_by_counts and create_sub_devices_by_affinity…
Mar 26, 2021
64799c1
Merge master
Mar 29, 2021
5130e69
Fix cython create_sub_devices_by_counts
Mar 29, 2021
3b4bae2
Fix create_sub_devices_by_affinity
Mar 29, 2021
77ba7d2
Add create_sub_devices for all funcs
Mar 29, 2021
2f3e4fa
Del useless import
Mar 29, 2021
b1aa862
Fix formatting
Mar 29, 2021
f58b2c6
Merge master
Mar 31, 2021
81df60e
Small fixes
Mar 31, 2021
f3defb9
Fix create_sub_devices_by_counts array
Mar 31, 2021
af10517
Del useless import
Mar 31, 2021
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