Skip to content

Commit 26bf594

Browse files
1e-toDiptorup DebetotmeniPokhodenkoSA
authored
Extra device info (#147)
* Add wrapper functions over device properties used inside Numba. * Add unit test cases for dppl_sycl_device_interface.cpp * change and fixes for existing funcs * Add device::aspects for int64_base_atomics and int64_extended_atomics * Fixes according comments * Fix tests * Codestyle * Codestyle * Some fixes + add tests for level0 gpu * Change names in tests level0gpu * Update changelog * Fix import _backend in _sycl_core.pxd Co-authored-by: Diptorup Deb <diptorup.deb@intel.com> Co-authored-by: etotmeni <elena.totmenina@intel.com> Co-authored-by: Sergey Pokhodenko <sergey.pokhodenko@intel.com>
1 parent 7d548cd commit 26bf594

13 files changed

+827
-28
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
All notable changes to this project will be documented in this file.
33

44
## [Unreleased]
5+
### Added
6+
- 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.
7+
58
### Removed
69
- The Legacy OpenCL interface.
710

backends/include/dppl_sycl_device_interface.h

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,76 @@ DPPL_API
102102
__dppl_give const char*
103103
DPPLDevice_GetDriverInfo (__dppl_keep const DPPLSyclDeviceRef DRef);
104104

105+
/*!
106+
* @brief Wrapper over device.get_info<info::device::max_compute_units>().
107+
*
108+
* @param DRef Opaque pointer to a sycl::device
109+
* @return Returns the valid result if device exists else returns 0.
110+
*/
111+
DPPL_API
112+
uint32_t
113+
DPPLDevice_GetMaxComputeUnits (__dppl_keep const DPPLSyclDeviceRef DRef);
114+
115+
/*!
116+
* @brief Wrapper for get_info<info::device::max_work_item_dimensions>().
117+
*
118+
* @param DRef Opaque pointer to a sycl::device
119+
* @return Returns the valid result if device exists else returns 0.
120+
*/
121+
DPPL_API
122+
uint32_t
123+
DPPLDevice_GetMaxWorkItemDims (__dppl_keep const DPPLSyclDeviceRef DRef);
124+
125+
/*!
126+
* @brief Wrapper for get_info<info::device::max_work_item_sizes>().
127+
*
128+
* @param DRef Opaque pointer to a sycl::device
129+
* @return Returns the valid result if device exists else returns NULL.
130+
*/
131+
DPPL_API
132+
__dppl_keep size_t*
133+
DPPLDevice_GetMaxWorkItemSizes (__dppl_keep const DPPLSyclDeviceRef DRef);
134+
135+
/*!
136+
* @brief Wrapper for get_info<info::device::max_work_group_size>().
137+
*
138+
* @param DRef Opaque pointer to a sycl::device
139+
* @return Returns the valid result if device exists else returns 0.
140+
*/
141+
DPPL_API
142+
size_t
143+
DPPLDevice_GetMaxWorkGroupSize (__dppl_keep const DPPLSyclDeviceRef DRef);
144+
145+
/*!
146+
* @brief Wrapper over device.get_info<info::device::max_num_sub_groups>.
147+
*
148+
* @param DRef Opaque pointer to a sycl::device
149+
* @return Returns the valid result if device exists else returns 0.
150+
*/
151+
DPPL_API
152+
uint32_t
153+
DPPLDevice_GetMaxNumSubGroups (__dppl_keep const DPPLSyclDeviceRef DRef);
154+
155+
/*!
156+
* @brief Wrapper over device.get_info<info::device::aspect::int64_base_atomics>.
157+
*
158+
* @param DRef Opaque pointer to a sycl::device
159+
* @return Returns true if device has int64_base_atomics else returns false.
160+
*/
161+
DPPL_API
162+
bool
163+
DPPLDevice_HasInt64BaseAtomics (__dppl_keep const DPPLSyclDeviceRef DRef);
164+
165+
/*!
166+
* @brief Wrapper over device.get_info<info::device::aspect::int64_extended_atomics>.
167+
*
168+
* @param DRef Opaque pointer to a sycl::device
169+
* @return Returns true if device has int64_extended_atomics else returns false.
170+
*/
171+
DPPL_API
172+
bool
173+
DPPLDevice_HasInt64ExtendedAtomics (__dppl_keep const DPPLSyclDeviceRef DRef);
174+
105175
/*!
106176
* @brief Returns a C string for the device name.
107177
*

backends/include/dppl_utils.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,27 @@
2424

2525
#pragma once
2626

27+
#include "dppl_data_types.h"
2728
#include "Support/DllExport.h"
2829
#include "Support/ExternC.h"
2930
#include "Support/MemOwnershipAttrs.h"
3031

3132
DPPL_C_EXTERN_C_BEGIN
3233

3334
/*!
34-
* @brief Deletes the C String argument
35+
* @brief Deletes the C String argument.
3536
*
3637
* @param str C string to be deleted
3738
*/
3839
DPPL_API
3940
void DPPLCString_Delete (__dppl_take const char* str);
4041

42+
/*!
43+
* @brief Deletes an array of size_t elements.
44+
*
45+
* @param arr Array to be deleted.
46+
*/
47+
DPPL_API
48+
void DPPLSize_t_Array_Delete (__dppl_take size_t* arr);
49+
4150
DPPL_C_EXTERN_C_END

backends/source/dppl_sycl_device_interface.cpp

Lines changed: 125 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -103,53 +103,161 @@ void DPPLDevice_Delete (__dppl_take DPPLSyclDeviceRef DRef)
103103

104104
bool DPPLDevice_IsAccelerator (__dppl_keep const DPPLSyclDeviceRef DRef)
105105
{
106-
return unwrap(DRef)->is_accelerator();
106+
auto D = unwrap(DRef);
107+
if (D) {
108+
return D->is_accelerator();
109+
}
110+
return false;
107111
}
108112

109113
bool DPPLDevice_IsCPU (__dppl_keep const DPPLSyclDeviceRef DRef)
110114
{
111-
return unwrap(DRef)->is_cpu();
115+
auto D = unwrap(DRef);
116+
if (D) {
117+
return D->is_cpu();
118+
}
119+
return false;
112120
}
113121

114122
bool DPPLDevice_IsGPU (__dppl_keep const DPPLSyclDeviceRef DRef)
115123
{
116-
return unwrap(DRef)->is_gpu();
124+
auto D = unwrap(DRef);
125+
if (D) {
126+
return D->is_gpu();
127+
}
128+
return false;
117129
}
118130

119131

120132
bool DPPLDevice_IsHost (__dppl_keep const DPPLSyclDeviceRef DRef)
121133
{
122-
return unwrap(DRef)->is_host();
134+
auto D = unwrap(DRef);
135+
if (D) {
136+
return D->is_host();
137+
}
138+
return false;
139+
}
140+
141+
142+
uint32_t
143+
DPPLDevice_GetMaxComputeUnits (__dppl_keep const DPPLSyclDeviceRef DRef)
144+
{
145+
auto D = unwrap(DRef);
146+
if (D) {
147+
return D->get_info<info::device::max_compute_units>();
148+
}
149+
return 0;
150+
}
151+
152+
uint32_t
153+
DPPLDevice_GetMaxWorkItemDims (__dppl_keep const DPPLSyclDeviceRef DRef)
154+
{
155+
auto D = unwrap(DRef);
156+
if (D) {
157+
return D->get_info<info::device::max_work_item_dimensions>();
158+
}
159+
return 0;
160+
}
161+
162+
__dppl_keep size_t*
163+
DPPLDevice_GetMaxWorkItemSizes (__dppl_keep const DPPLSyclDeviceRef DRef)
164+
{
165+
size_t *sizes = nullptr;
166+
auto D = unwrap(DRef);
167+
if (D) {
168+
auto id_sizes = D->get_info<info::device::max_work_item_sizes>();
169+
sizes = new size_t[3];
170+
for(auto i = 0ul; i < 3; ++i) {
171+
sizes[i] = id_sizes[i];
172+
}
173+
}
174+
return sizes;
175+
}
176+
177+
size_t
178+
DPPLDevice_GetMaxWorkGroupSize (__dppl_keep const DPPLSyclDeviceRef DRef)
179+
{
180+
auto D = unwrap(DRef);
181+
if (D) {
182+
return D->get_info<info::device::max_work_group_size>();
183+
}
184+
return 0;
185+
}
186+
187+
uint32_t
188+
DPPLDevice_GetMaxNumSubGroups (__dppl_keep const DPPLSyclDeviceRef DRef)
189+
{
190+
auto D = unwrap(DRef);
191+
if (D) {
192+
return D->get_info<info::device::max_num_sub_groups>();
193+
}
194+
return 0;
195+
}
196+
197+
bool
198+
DPPLDevice_HasInt64BaseAtomics (__dppl_keep const DPPLSyclDeviceRef DRef)
199+
{
200+
auto D = unwrap(DRef);
201+
if (D) {
202+
return D->has(aspect::int64_base_atomics);
203+
}
204+
return false;
205+
}
206+
207+
bool
208+
DPPLDevice_HasInt64ExtendedAtomics (__dppl_keep const DPPLSyclDeviceRef DRef)
209+
{
210+
auto D = unwrap(DRef);
211+
if (D) {
212+
return D->has(aspect::int64_extended_atomics);
213+
}
214+
return false;
123215
}
124216

125217
__dppl_give const char*
126218
DPPLDevice_GetName (__dppl_keep const DPPLSyclDeviceRef DRef)
127219
{
128-
auto name = unwrap(DRef)->get_info<info::device::name>();
129-
auto cstr_name = new char [name.length()+1];
130-
std::strcpy (cstr_name, name.c_str());
131-
return cstr_name;
220+
auto D = unwrap(DRef);
221+
if (D) {
222+
auto name = D->get_info<info::device::name>();
223+
auto cstr_name = new char [name.length()+1];
224+
std::strcpy (cstr_name, name.c_str());
225+
return cstr_name;
226+
}
227+
return nullptr;
132228
}
133229

134230
__dppl_give const char*
135231
DPPLDevice_GetVendorName (__dppl_keep const DPPLSyclDeviceRef DRef)
136232
{
137-
auto vendor = unwrap(DRef)->get_info<info::device::name>();
138-
auto cstr_vendor = new char [vendor.length()+1];
139-
std::strcpy (cstr_vendor, vendor.c_str());
140-
return cstr_vendor;
233+
auto D = unwrap(DRef);
234+
if (D) {
235+
auto vendor = D->get_info<info::device::vendor>();
236+
auto cstr_vendor = new char [vendor.length()+1];
237+
std::strcpy (cstr_vendor, vendor.c_str());
238+
return cstr_vendor;
239+
}
240+
return nullptr;
141241
}
142242

143243
__dppl_give const char*
144244
DPPLDevice_GetDriverInfo (__dppl_keep const DPPLSyclDeviceRef DRef)
145245
{
146-
auto driver = unwrap(DRef)->get_info<info::device::driver_version>();
147-
auto cstr_driver = new char [driver.length()+1];
148-
std::strcpy (cstr_driver, driver.c_str());
149-
return cstr_driver;
246+
auto D = unwrap(DRef);
247+
if (D) {
248+
auto driver = D->get_info<info::device::driver_version>();
249+
auto cstr_driver = new char [driver.length()+1];
250+
std::strcpy (cstr_driver, driver.c_str());
251+
return cstr_driver;
252+
}
253+
return nullptr;
150254
}
151255

152256
bool DPPLDevice_IsHostUnifiedMemory (__dppl_keep const DPPLSyclDeviceRef DRef)
153257
{
154-
return unwrap(DRef)->get_info<info::device::host_unified_memory>();
258+
auto D = unwrap(DRef);
259+
if (D) {
260+
return D->get_info<info::device::host_unified_memory>();
261+
}
262+
return false;
155263
}

backends/source/dppl_utils.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,8 @@ void DPPLCString_Delete (__dppl_take const char* str)
2929
{
3030
delete[] str;
3131
}
32+
33+
void DPPLSize_t_Array_Delete (__dppl_take size_t* arr)
34+
{
35+
delete[] arr;
36+
}

backends/tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ else()
2323
link_directories(${GTEST_LIB_DIR})
2424

2525
set(DPCTL_C_API_TEST_CASES
26+
test_sycl_device_interface
2627
test_sycl_kernel_interface
2728
test_sycl_platform_interface
2829
test_sycl_program_interface

0 commit comments

Comments
 (0)