Skip to content

Extra device info #147

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 15 commits into from
Oct 23, 2020
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
All notable changes to this project will be documented in this file.

## [Unreleased]
### Added
- Device descriptors "max_compute_units", "max_work_item_dimensions", "max_work_item_sizes", "max_work_group_size", "max_num_sub_groups" and "aspects" for int64 atomics inside dpctl C API and inside the dpctl.SyclDevice class.

### Removed
- The Legacy OpenCL interface.

Expand Down
70 changes: 70 additions & 0 deletions backends/include/dppl_sycl_device_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,76 @@ DPPL_API
__dppl_give const char*
DPPLDevice_GetDriverInfo (__dppl_keep const DPPLSyclDeviceRef DRef);

/*!
* @brief Wrapper over device.get_info<info::device::max_compute_units>().
*
* @param DRef Opaque pointer to a sycl::device
* @return Returns the valid result if device exists else returns 0.
*/
DPPL_API
uint32_t
DPPLDevice_GetMaxComputeUnits (__dppl_keep const DPPLSyclDeviceRef DRef);

/*!
* @brief Wrapper for get_info<info::device::max_work_item_dimensions>().
*
* @param DRef Opaque pointer to a sycl::device
* @return Returns the valid result if device exists else returns 0.
*/
DPPL_API
uint32_t
DPPLDevice_GetMaxWorkItemDims (__dppl_keep const DPPLSyclDeviceRef DRef);

/*!
* @brief Wrapper for get_info<info::device::max_work_item_sizes>().
*
* @param DRef Opaque pointer to a sycl::device
* @return Returns the valid result if device exists else returns NULL.
*/
DPPL_API
__dppl_keep size_t*
DPPLDevice_GetMaxWorkItemSizes (__dppl_keep const DPPLSyclDeviceRef DRef);

/*!
* @brief Wrapper for get_info<info::device::max_work_group_size>().
*
* @param DRef Opaque pointer to a sycl::device
* @return Returns the valid result if device exists else returns 0.
*/
DPPL_API
size_t
DPPLDevice_GetMaxWorkGroupSize (__dppl_keep const DPPLSyclDeviceRef DRef);

/*!
* @brief Wrapper over device.get_info<info::device::max_num_sub_groups>.
*
* @param DRef Opaque pointer to a sycl::device
* @return Returns the valid result if device exists else returns 0.
*/
DPPL_API
uint32_t
DPPLDevice_GetMaxNumSubGroups (__dppl_keep const DPPLSyclDeviceRef 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.
*/
DPPL_API
bool
DPPLDevice_HasInt64BaseAtomics (__dppl_keep const DPPLSyclDeviceRef 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.
*/
DPPL_API
bool
DPPLDevice_HasInt64ExtendedAtomics (__dppl_keep const DPPLSyclDeviceRef DRef);

/*!
* @brief Returns a C string for the device name.
*
Expand Down
11 changes: 10 additions & 1 deletion backends/include/dppl_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,27 @@

#pragma once

#include "dppl_data_types.h"
#include "Support/DllExport.h"
#include "Support/ExternC.h"
#include "Support/MemOwnershipAttrs.h"

DPPL_C_EXTERN_C_BEGIN

/*!
* @brief Deletes the C String argument
* @brief Deletes the C String argument.
*
* @param str C string to be deleted
*/
DPPL_API
void DPPLCString_Delete (__dppl_take const char* str);

/*!
* @brief Deletes an array of size_t elements.
*
* @param arr Array to be deleted.
*/
DPPL_API
void DPPLSize_t_Array_Delete (__dppl_take size_t* arr);

DPPL_C_EXTERN_C_END
142 changes: 125 additions & 17 deletions backends/source/dppl_sycl_device_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,53 +103,161 @@ void DPPLDevice_Delete (__dppl_take DPPLSyclDeviceRef DRef)

bool DPPLDevice_IsAccelerator (__dppl_keep const DPPLSyclDeviceRef DRef)
{
return unwrap(DRef)->is_accelerator();
auto D = unwrap(DRef);
if (D) {
return D->is_accelerator();
}
return false;
}

bool DPPLDevice_IsCPU (__dppl_keep const DPPLSyclDeviceRef DRef)
{
return unwrap(DRef)->is_cpu();
auto D = unwrap(DRef);
if (D) {
return D->is_cpu();
}
return false;
}

bool DPPLDevice_IsGPU (__dppl_keep const DPPLSyclDeviceRef DRef)
{
return unwrap(DRef)->is_gpu();
auto D = unwrap(DRef);
if (D) {
return D->is_gpu();
}
return false;
}


bool DPPLDevice_IsHost (__dppl_keep const DPPLSyclDeviceRef DRef)
{
return unwrap(DRef)->is_host();
auto D = unwrap(DRef);
if (D) {
return D->is_host();
}
return false;
}


uint32_t
DPPLDevice_GetMaxComputeUnits (__dppl_keep const DPPLSyclDeviceRef DRef)
{
auto D = unwrap(DRef);
if (D) {
return D->get_info<info::device::max_compute_units>();
}
return 0;
}

uint32_t
DPPLDevice_GetMaxWorkItemDims (__dppl_keep const DPPLSyclDeviceRef DRef)
{
auto D = unwrap(DRef);
if (D) {
return D->get_info<info::device::max_work_item_dimensions>();
}
return 0;
}

__dppl_keep size_t*
DPPLDevice_GetMaxWorkItemSizes (__dppl_keep const DPPLSyclDeviceRef DRef)
{
size_t *sizes = nullptr;
auto D = unwrap(DRef);
if (D) {
auto id_sizes = D->get_info<info::device::max_work_item_sizes>();
sizes = new size_t[3];
for(auto i = 0ul; i < 3; ++i) {
sizes[i] = id_sizes[i];
}
}
return sizes;
}

size_t
DPPLDevice_GetMaxWorkGroupSize (__dppl_keep const DPPLSyclDeviceRef DRef)
{
auto D = unwrap(DRef);
if (D) {
return D->get_info<info::device::max_work_group_size>();
}
return 0;
}

uint32_t
DPPLDevice_GetMaxNumSubGroups (__dppl_keep const DPPLSyclDeviceRef DRef)
{
auto D = unwrap(DRef);
if (D) {
return D->get_info<info::device::max_num_sub_groups>();
}
return 0;
}

bool
DPPLDevice_HasInt64BaseAtomics (__dppl_keep const DPPLSyclDeviceRef DRef)
{
auto D = unwrap(DRef);
if (D) {
return D->has(aspect::int64_base_atomics);
}
return false;
}

bool
DPPLDevice_HasInt64ExtendedAtomics (__dppl_keep const DPPLSyclDeviceRef DRef)
{
auto D = unwrap(DRef);
if (D) {
return D->has(aspect::int64_extended_atomics);
}
return false;
}

__dppl_give const char*
DPPLDevice_GetName (__dppl_keep const DPPLSyclDeviceRef DRef)
{
auto name = unwrap(DRef)->get_info<info::device::name>();
auto cstr_name = new char [name.length()+1];
std::strcpy (cstr_name, name.c_str());
return cstr_name;
auto D = unwrap(DRef);
if (D) {
auto name = D->get_info<info::device::name>();
auto cstr_name = new char [name.length()+1];
std::strcpy (cstr_name, name.c_str());
return cstr_name;
}
return nullptr;
}

__dppl_give const char*
DPPLDevice_GetVendorName (__dppl_keep const DPPLSyclDeviceRef DRef)
{
auto vendor = unwrap(DRef)->get_info<info::device::name>();
auto cstr_vendor = new char [vendor.length()+1];
std::strcpy (cstr_vendor, vendor.c_str());
return cstr_vendor;
auto D = unwrap(DRef);
if (D) {
auto vendor = D->get_info<info::device::vendor>();
auto cstr_vendor = new char [vendor.length()+1];
std::strcpy (cstr_vendor, vendor.c_str());
return cstr_vendor;
}
return nullptr;
}

__dppl_give const char*
DPPLDevice_GetDriverInfo (__dppl_keep const DPPLSyclDeviceRef DRef)
{
auto driver = unwrap(DRef)->get_info<info::device::driver_version>();
auto cstr_driver = new char [driver.length()+1];
std::strcpy (cstr_driver, driver.c_str());
return cstr_driver;
auto D = unwrap(DRef);
if (D) {
auto driver = D->get_info<info::device::driver_version>();
auto cstr_driver = new char [driver.length()+1];
std::strcpy (cstr_driver, driver.c_str());
return cstr_driver;
}
return nullptr;
}

bool DPPLDevice_IsHostUnifiedMemory (__dppl_keep const DPPLSyclDeviceRef DRef)
{
return unwrap(DRef)->get_info<info::device::host_unified_memory>();
auto D = unwrap(DRef);
if (D) {
return D->get_info<info::device::host_unified_memory>();
}
return false;
}
5 changes: 5 additions & 0 deletions backends/source/dppl_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,8 @@ void DPPLCString_Delete (__dppl_take const char* str)
{
delete[] str;
}

void DPPLSize_t_Array_Delete (__dppl_take size_t* arr)
{
delete[] arr;
}
1 change: 1 addition & 0 deletions backends/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ else()
link_directories(${GTEST_LIB_DIR})

set(DPCTL_C_API_TEST_CASES
test_sycl_device_interface
test_sycl_kernel_interface
test_sycl_platform_interface
test_sycl_program_interface
Expand Down
Loading