Skip to content

Add support for Aspects #307

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 12 commits into from
Mar 9, 2021
Merged
Show file tree
Hide file tree
Changes from 10 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
43 changes: 43 additions & 0 deletions dpctl-capi/helper/include/dpctl_utils_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,46 @@ DPCTL_DPCTLDeviceTypeToSyclDeviceType(DPCTLSyclDeviceType DTy);
*/
DPCTLSyclDeviceType
DPCTL_SyclDeviceTypeToDPCTLDeviceType(sycl::info::device_type D);

/*!
* @brief Converts a sycl::aspect input value to a string.
*
* @param aspectTy A sycl::aspect value.
* @return A string representation of a sycl::aspect.
* @throws runtime_error
*/
std::string DPCTL_AspectToStr(sycl::aspect aspectTy);

/*!
* @brief Converts a string to sycl::aspect value.
*
* @param aspectTyStr Input string for which we search a
* sycl::aspect value.
* @return The sycl::aspect value corresponding to the input
* string.
* @throws runtime_error
*/
sycl::aspect DPCTL_StrToAspectType(const std::string &aspectTyStr);

/*!
* @brief Converts a DPCTLSyclAspectType enum value to its corresponding
* sycl::aspect enum value.
*
* @param AspectTy A DPCTLSyclAspectType enum value
* @return A sycl::aspect enum value for the input
* DPCTLSyclAspectType enum value.
* @throws runtime_error
*/
sycl::aspect DPCTL_DPCTLAspectTypeToSyclAspect(DPCTLSyclAspectType AspectTy);

/*!
* @brief Converts a sycl::aspect enum value to corresponding
* DPCTLSyclAspectType enum value.
*
* @param Aspect sycl::aspect to be converted to
* DPCTLSyclAspectType enum.
* @return A DPCTLSyclAspectType enum value for the input
* sycl::aspect enum value.
* @throws runtime_error
*/
DPCTLSyclAspectType DPCTL_SyclAspectToDPCTLAspectType(sycl::aspect Aspect);
222 changes: 222 additions & 0 deletions dpctl-capi/helper/source/dpctl_utils_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,225 @@ DPCTLSyclDeviceType DPCTL_SyclDeviceTypeToDPCTLDeviceType(info::device_type D)
return DPCTLSyclDeviceType::DPCTL_UNKNOWN_DEVICE;
}
}

/*!
* Transforms cl::sycl::aspect to string.
*/
std::string DPCTL_AspectToStr(aspect aspectTy)
{
std::stringstream ss;
switch (aspectTy) {
case aspect::host:
ss << "host" << '\n';
break;
case aspect::cpu:
ss << "cpu" << '\n';
break;
case aspect::gpu:
ss << "gpu" << '\n';
break;
case aspect::accelerator:
ss << "accelerator" << '\n';
break;
case aspect::custom:
ss << "custom" << '\n';
break;
case aspect::fp16:
ss << "fp16" << '\n';
break;
case aspect::fp64:
ss << "fp64" << '\n';
break;
case aspect::int64_base_atomics:
ss << "int64_base_atomics" << '\n';
break;
case aspect::int64_extended_atomics:
ss << "int64_extended_atomics" << '\n';
break;
case aspect::image:
ss << "image" << '\n';
break;
case aspect::online_compiler:
ss << "online_compiler" << '\n';
break;
case aspect::online_linker:
ss << "online_linker" << '\n';
break;
case aspect::queue_profiling:
ss << "queue_profiling" << '\n';
break;
case aspect::usm_device_allocations:
ss << "usm_device_allocations" << '\n';
break;
case aspect::usm_host_allocations:
ss << "usm_host_allocations" << '\n';
break;
case aspect::usm_shared_allocations:
ss << "usm_shared_allocations" << '\n';
break;
case aspect::usm_restricted_shared_allocations:
ss << "usm_restricted_shared_allocations" << '\n';
break;
case aspect::usm_system_allocator:
ss << "usm_system_allocator" << '\n';
break;
default:
throw runtime_error("Unsupported aspect type", -1);
}
return ss.str();
}

/*!
* Transforms string to cl::sycl::aspect.
*/
aspect DPCTL_StrToAspectType(const std::string &aspectTyStr)
{
aspect aspectTy;
if (aspectTyStr == "host") {
aspectTy = aspect::host;
}
else if (aspectTyStr == "cpu") {
aspectTy = aspect::cpu;
}
else if (aspectTyStr == "gpu") {
aspectTy = aspect::gpu;
}
else if (aspectTyStr == "accelerator") {
aspectTy = aspect::accelerator;
}
else if (aspectTyStr == "custom") {
aspectTy = aspect::custom;
}
else if (aspectTyStr == "fp16") {
aspectTy = aspect::fp16;
}
else if (aspectTyStr == "fp64") {
aspectTy = aspect::fp64;
}
else if (aspectTyStr == "int64_base_atomics") {
aspectTy = aspect::int64_base_atomics;
}
else if (aspectTyStr == "int64_extended_atomics") {
aspectTy = aspect::int64_extended_atomics;
}
else if (aspectTyStr == "image") {
aspectTy = aspect::image;
}
else if (aspectTyStr == "online_compiler") {
aspectTy = aspect::online_compiler;
}
else if (aspectTyStr == "online_linker") {
aspectTy = aspect::online_linker;
}
else if (aspectTyStr == "queue_profiling") {
aspectTy = aspect::queue_profiling;
}
else if (aspectTyStr == "usm_device_allocations") {
aspectTy = aspect::usm_device_allocations;
}
else if (aspectTyStr == "usm_host_allocations") {
aspectTy = aspect::usm_host_allocations;
}
else if (aspectTyStr == "usm_shared_allocations") {
aspectTy = aspect::usm_shared_allocations;
}
else if (aspectTyStr == "usm_restricted_shared_allocations") {
aspectTy = aspect::usm_restricted_shared_allocations;
}
else if (aspectTyStr == "usm_system_allocator") {
aspectTy = aspect::usm_system_allocator;
}
else {
// \todo handle the error
throw runtime_error("Unsupported aspect type", -1);
}
return aspectTy;
}

aspect DPCTL_DPCTLAspectTypeToSyclAspect(DPCTLSyclAspectType AspectTy)
{
switch (AspectTy) {
case DPCTLSyclAspectType::host:
return aspect::host;
case DPCTLSyclAspectType::cpu:
return aspect::cpu;
case DPCTLSyclAspectType::gpu:
return aspect::gpu;
case DPCTLSyclAspectType::accelerator:
return aspect::accelerator;
case DPCTLSyclAspectType::custom:
return aspect::custom;
case DPCTLSyclAspectType::fp16:
return aspect::fp16;
case DPCTLSyclAspectType::fp64:
return aspect::fp64;
case DPCTLSyclAspectType::int64_base_atomics:
return aspect::int64_base_atomics;
case DPCTLSyclAspectType::int64_extended_atomics:
return aspect::int64_extended_atomics;
case DPCTLSyclAspectType::image:
return aspect::image;
case DPCTLSyclAspectType::online_compiler:
return aspect::online_compiler;
case DPCTLSyclAspectType::online_linker:
return aspect::online_linker;
case DPCTLSyclAspectType::queue_profiling:
return aspect::queue_profiling;
case DPCTLSyclAspectType::usm_device_allocations:
return aspect::usm_device_allocations;
case DPCTLSyclAspectType::usm_host_allocations:
return aspect::usm_host_allocations;
case DPCTLSyclAspectType::usm_shared_allocations:
return aspect::usm_shared_allocations;
case DPCTLSyclAspectType::usm_restricted_shared_allocations:
return aspect::usm_restricted_shared_allocations;
case DPCTLSyclAspectType::usm_system_allocator:
return aspect::usm_system_allocator;
default:
throw runtime_error("Unsupported aspect type", -1);
}
}

DPCTLSyclAspectType DPCTL_SyclAspectToDPCTLAspectType(aspect Aspect)
{
switch (Aspect) {
case aspect::host:
return DPCTLSyclAspectType::host;
case aspect::cpu:
return DPCTLSyclAspectType::cpu;
case aspect::gpu:
return DPCTLSyclAspectType::gpu;
case aspect::accelerator:
return DPCTLSyclAspectType::accelerator;
case aspect::custom:
return DPCTLSyclAspectType::custom;
case aspect::fp16:
return DPCTLSyclAspectType::fp16;
case aspect::fp64:
return DPCTLSyclAspectType::fp64;
case aspect::int64_base_atomics:
return DPCTLSyclAspectType::int64_base_atomics;
case aspect::int64_extended_atomics:
return DPCTLSyclAspectType::int64_extended_atomics;
case aspect::image:
return DPCTLSyclAspectType::image;
case aspect::online_compiler:
return DPCTLSyclAspectType::online_compiler;
case aspect::online_linker:
return DPCTLSyclAspectType::online_linker;
case aspect::queue_profiling:
return DPCTLSyclAspectType::queue_profiling;
case aspect::usm_device_allocations:
return DPCTLSyclAspectType::usm_device_allocations;
case aspect::usm_host_allocations:
return DPCTLSyclAspectType::usm_host_allocations;
case aspect::usm_shared_allocations:
return DPCTLSyclAspectType::usm_shared_allocations;
case aspect::usm_restricted_shared_allocations:
return DPCTLSyclAspectType::usm_restricted_shared_allocations;
case aspect::usm_system_allocator:
return DPCTLSyclAspectType::usm_system_allocator;
default:
throw runtime_error("Unsupported aspect type", -1);
}
}
38 changes: 13 additions & 25 deletions dpctl-capi/include/dpctl_sycl_device_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,29 +218,6 @@ DPCTL_API
__dpctl_give DPCTLSyclPlatformRef
DPCTLDevice_GetPlatform(__dpctl_keep const DPCTLSyclDeviceRef DRef);

/*!
* @brief Wrapper over
* device.get_info<info::device::aspect::int64_base_atomics>.
*
* @param DRef Opaque pointer to a sycl::device
* @return Returns true if device has int64_base_atomics else returns false.
*/
DPCTL_API
bool DPCTLDevice_HasInt64BaseAtomics(
__dpctl_keep const DPCTLSyclDeviceRef DRef);

/*!
* @brief Wrapper over
* device.get_info<info::device::aspect::int64_extended_atomics>.
*
* @param DRef Opaque pointer to a sycl::device
* @return Returns true if device has int64_extended_atomics else returns
* false.
*/
DPCTL_API
bool DPCTLDevice_HasInt64ExtendedAtomics(
__dpctl_keep const DPCTLSyclDeviceRef DRef);

/*!
* @brief Returns a C string for the device name.
*
Expand Down Expand Up @@ -282,7 +259,18 @@ bool DPCTLDevice_IsHostUnifiedMemory(
* @return True if the underlying sycl::device are same, false otherwise.
*/
DPCTL_API
bool DPCTLDevice_AreEq(__dpctl_keep const DPCTLSyclDeviceRef DRef1,
__dpctl_keep const DPCTLSyclDeviceRef DRef2);
bool DPCTLDevice_AreEq(__dpctl_keep const DPCTLSyclDeviceRef DevRef1,
__dpctl_keep const DPCTLSyclDeviceRef DevRef2);

/*!
* @brief Checks if device has aspect.
*
* @param DRef Opaque pointer to a sycl::device
* @param AT DPCTLSyclAspectType of device::aspect.
* @return True if sycl::device has device::aspect, else false.
*/
DPCTL_API
bool DPCTLDevice_HasAspect(__dpctl_keep const DPCTLSyclDeviceRef DRef,
DPCTLSyclAspectType AT);

DPCTL_C_EXTERN_C_END
27 changes: 27 additions & 0 deletions dpctl-capi/include/dpctl_sycl_enum_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,33 @@ typedef enum
DPCTL_VOID_PTR
} DPCTLKernelArgType;

/*!
* @brief DPCTL device has an associated set of aspects which identify
* characteristics of the device.
*
*/
enum DPCTLSyclAspectType
{
host,
cpu,
gpu,
accelerator,
custom,
fp16,
fp64,
int64_base_atomics,
int64_extended_atomics,
image,
online_compiler,
online_linker,
queue_profiling,
usm_device_allocations,
usm_host_allocations,
usm_shared_allocations,
usm_restricted_shared_allocations,
usm_system_allocator
};

/*!
* @brief Enums to depict the properties that can be passed to a sycl::queue
* constructor.
Expand Down
Loading