Skip to content

Add new getter functions to device interface. #300

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
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
42 changes: 38 additions & 4 deletions dpctl-capi/include/dpctl_sycl_device_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,28 @@ bool DPCTLDevice_IsGPU(__dpctl_keep const DPCTLSyclDeviceRef DRef);
DPCTL_API
bool DPCTLDevice_IsHost(__dpctl_keep const DPCTLSyclDeviceRef DRef);

/*!
* @brief Returns the backend for the device.
*
* @param DRef Opaque pointer to a sycl::device
* @return A DPCTLSyclBackendType enum value representing the sycl::backend
* for the device.
*/
DPCTL_API
DPCTLSyclBackendType
DPCTLDevice_GetBackend(__dpctl_keep const DPCTLSyclDeviceRef DRef);

/*!
* @brief Returns the DPCTLSyclDeviceType enum value for the DPCTLSyclDeviceRef
* argument.
*
* @param DRef Opaque pointer to a sycl::device
* @return The DPCTLSyclDeviceType value corresponding to the device.
*/
DPCTL_API
DPCTLSyclDeviceType
DPCTLDevice_GetDeviceType(__dpctl_keep const DPCTLSyclDeviceRef DRef);

/*!
* @brief Returns the OpenCL software driver version as a C string.
*
Expand Down Expand Up @@ -185,6 +207,17 @@ DPCTL_API
uint32_t
DPCTLDevice_GetMaxNumSubGroups(__dpctl_keep const DPCTLSyclDeviceRef DRef);

/*!
* @brief Returns the sycl::platform for the device as DPCTLSyclPlatformRef
* opaque pointer.
*
* @param DRef Opaque pointer to a sycl::device
* @return An opaque pointer to the sycl::platform for the device.
*/
DPCTL_API
__dpctl_give DPCTLSyclPlatformRef
DPCTLDevice_GetPlatform(__dpctl_keep const DPCTLSyclDeviceRef DRef);

/*!
* @brief Wrapper over
* device.get_info<info::device::aspect::int64_base_atomics>.
Expand Down Expand Up @@ -244,11 +277,12 @@ bool DPCTLDevice_IsHostUnifiedMemory(
* @brief Checks if two DPCTLSyclDeviceRef objects point to the same
* sycl::device.
*
* @param DevRef1 First opaque pointer to the sycl device.
* @param DevRef2 Second opaque pointer to the sycl device.
* @param DRef1 First opaque pointer to a sycl device.
* @param DRef2 Second opaque pointer to a sycl device.
* @return True if the underlying sycl::device are same, false otherwise.
*/
DPCTL_API
bool DPCTLDevice_AreEq(__dpctl_keep const DPCTLSyclDeviceRef DevRef1,
__dpctl_keep const DPCTLSyclDeviceRef DevRef2);
bool DPCTLDevice_AreEq(__dpctl_keep const DPCTLSyclDeviceRef DRef1,
__dpctl_keep const DPCTLSyclDeviceRef DRef2);

DPCTL_C_EXTERN_C_END
45 changes: 45 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,7 @@ namespace
// Create wrappers for C Binding types (see CBindingWrapping.h).
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(device, DPCTLSyclDeviceRef)
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(device_selector, DPCTLSyclDeviceSelectorRef)
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(platform, DPCTLSyclPlatformRef)

/*!
* @brief Helper function to print the metadata for a sycl::device.
Expand Down Expand Up @@ -139,6 +140,23 @@ void DPCTLDevice_Delete(__dpctl_take DPCTLSyclDeviceRef DRef)
delete unwrap(DRef);
}

DPCTLSyclDeviceType
DPCTLDevice_GetDeviceType(__dpctl_keep const DPCTLSyclDeviceRef DRef)
{
DPCTLSyclDeviceType DTy = DPCTLSyclDeviceType::DPCTL_UNKNOWN_DEVICE;
auto D = unwrap(DRef);
if (D) {
try {
auto SyclDTy = D->get_info<info::device::device_type>();
DTy = DPCTL_SyclDeviceTypeToDPCTLDeviceType(SyclDTy);
} catch (runtime_error const &re) {
// \todo log error
std::cerr << re.what() << '\n';
}
}
return DTy;
}

bool DPCTLDevice_IsAccelerator(__dpctl_keep const DPCTLSyclDeviceRef DRef)
{
auto D = unwrap(DRef);
Expand Down Expand Up @@ -175,6 +193,18 @@ bool DPCTLDevice_IsHost(__dpctl_keep const DPCTLSyclDeviceRef DRef)
return false;
}

DPCTLSyclBackendType
DPCTLDevice_GetBackend(__dpctl_keep const DPCTLSyclDeviceRef DRef)
{
DPCTLSyclBackendType BTy = DPCTLSyclBackendType::DPCTL_UNKNOWN_BACKEND;
auto D = unwrap(DRef);
if (D) {
BTy = DPCTL_SyclBackendToDPCTLBackendType(
D->get_platform().get_backend());
}
return BTy;
}

uint32_t
DPCTLDevice_GetMaxComputeUnits(__dpctl_keep const DPCTLSyclDeviceRef DRef)
{
Expand Down Expand Up @@ -263,6 +293,21 @@ DPCTLDevice_GetMaxNumSubGroups(__dpctl_keep const DPCTLSyclDeviceRef DRef)
return max_nsubgroups;
}

__dpctl_give DPCTLSyclPlatformRef
DPCTLDevice_GetPlatform(__dpctl_keep const DPCTLSyclDeviceRef DRef)
{
DPCTLSyclPlatformRef PRef = nullptr;
auto D = unwrap(DRef);
if (D) {
try {
PRef = wrap(new platform(D->get_platform()));
} catch (std::bad_alloc const &ba) {
std::cerr << ba.what() << '\n';
}
}
return PRef;
}

bool DPCTLDevice_HasInt64BaseAtomics(__dpctl_keep const DPCTLSyclDeviceRef DRef)
{
bool hasBaseAtomics = false;
Expand Down
Loading