Skip to content

Feature/extra device info #115

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
Closed
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
50 changes: 50 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,56 @@ 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_GetMaxComputeUnites (__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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @return Returns the valid result if device exists else returns Null.
* @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 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
124 changes: 107 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,143 @@ 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 unwrap(DRef)->is_accelerator();
}
return false;
}

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

}

bool DPPLDevice_IsGPU (__dppl_keep const DPPLSyclDeviceRef DRef)
{
return unwrap(DRef)->is_gpu();
auto D = unwrap(DRef);
if(D) {
return unwrap(DRef)->is_gpu();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use D.

}
return false;
}


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


uint32_t
DPPLDevice_GetMaxComputeUnites (__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;
}

__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 = unwrap(DRef)->get_info<info::device::name>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use D.

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 = unwrap(DRef)->get_info<info::device::name>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use D.

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(D) {
if (D) {

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;
}
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;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
}

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(PYDPPL_BACKEND_TEST_CASES
test_sycl_device_interface
test_sycl_kernel_interface
test_sycl_platform_interface
test_sycl_program_interface
Expand Down
Loading