Skip to content

Commit 44fbbcd

Browse files
authored
Add new getter functions to device interface. (#300)
- add get_backend, get_platform, get_device_type to SyclDevice - parameterize the Gtests for dpctl_sycl_devie_interface
1 parent a4eb55f commit 44fbbcd

7 files changed

+378
-325
lines changed

dpctl-capi/include/dpctl_sycl_device_interface.h

+38-4
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,28 @@ bool DPCTLDevice_IsGPU(__dpctl_keep const DPCTLSyclDeviceRef DRef);
124124
DPCTL_API
125125
bool DPCTLDevice_IsHost(__dpctl_keep const DPCTLSyclDeviceRef DRef);
126126

127+
/*!
128+
* @brief Returns the backend for the device.
129+
*
130+
* @param DRef Opaque pointer to a sycl::device
131+
* @return A DPCTLSyclBackendType enum value representing the sycl::backend
132+
* for the device.
133+
*/
134+
DPCTL_API
135+
DPCTLSyclBackendType
136+
DPCTLDevice_GetBackend(__dpctl_keep const DPCTLSyclDeviceRef DRef);
137+
138+
/*!
139+
* @brief Returns the DPCTLSyclDeviceType enum value for the DPCTLSyclDeviceRef
140+
* argument.
141+
*
142+
* @param DRef Opaque pointer to a sycl::device
143+
* @return The DPCTLSyclDeviceType value corresponding to the device.
144+
*/
145+
DPCTL_API
146+
DPCTLSyclDeviceType
147+
DPCTLDevice_GetDeviceType(__dpctl_keep const DPCTLSyclDeviceRef DRef);
148+
127149
/*!
128150
* @brief Returns the OpenCL software driver version as a C string.
129151
*
@@ -185,6 +207,17 @@ DPCTL_API
185207
uint32_t
186208
DPCTLDevice_GetMaxNumSubGroups(__dpctl_keep const DPCTLSyclDeviceRef DRef);
187209

210+
/*!
211+
* @brief Returns the sycl::platform for the device as DPCTLSyclPlatformRef
212+
* opaque pointer.
213+
*
214+
* @param DRef Opaque pointer to a sycl::device
215+
* @return An opaque pointer to the sycl::platform for the device.
216+
*/
217+
DPCTL_API
218+
__dpctl_give DPCTLSyclPlatformRef
219+
DPCTLDevice_GetPlatform(__dpctl_keep const DPCTLSyclDeviceRef DRef);
220+
188221
/*!
189222
* @brief Wrapper over
190223
* device.get_info<info::device::aspect::int64_base_atomics>.
@@ -244,11 +277,12 @@ bool DPCTLDevice_IsHostUnifiedMemory(
244277
* @brief Checks if two DPCTLSyclDeviceRef objects point to the same
245278
* sycl::device.
246279
*
247-
* @param DevRef1 First opaque pointer to the sycl device.
248-
* @param DevRef2 Second opaque pointer to the sycl device.
280+
* @param DRef1 First opaque pointer to a sycl device.
281+
* @param DRef2 Second opaque pointer to a sycl device.
249282
* @return True if the underlying sycl::device are same, false otherwise.
250283
*/
251284
DPCTL_API
252-
bool DPCTLDevice_AreEq(__dpctl_keep const DPCTLSyclDeviceRef DevRef1,
253-
__dpctl_keep const DPCTLSyclDeviceRef DevRef2);
285+
bool DPCTLDevice_AreEq(__dpctl_keep const DPCTLSyclDeviceRef DRef1,
286+
__dpctl_keep const DPCTLSyclDeviceRef DRef2);
287+
254288
DPCTL_C_EXTERN_C_END

dpctl-capi/source/dpctl_sycl_device_interface.cpp

+45
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ namespace
3939
// Create wrappers for C Binding types (see CBindingWrapping.h).
4040
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(device, DPCTLSyclDeviceRef)
4141
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(device_selector, DPCTLSyclDeviceSelectorRef)
42+
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(platform, DPCTLSyclPlatformRef)
4243

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

143+
DPCTLSyclDeviceType
144+
DPCTLDevice_GetDeviceType(__dpctl_keep const DPCTLSyclDeviceRef DRef)
145+
{
146+
DPCTLSyclDeviceType DTy = DPCTLSyclDeviceType::DPCTL_UNKNOWN_DEVICE;
147+
auto D = unwrap(DRef);
148+
if (D) {
149+
try {
150+
auto SyclDTy = D->get_info<info::device::device_type>();
151+
DTy = DPCTL_SyclDeviceTypeToDPCTLDeviceType(SyclDTy);
152+
} catch (runtime_error const &re) {
153+
// \todo log error
154+
std::cerr << re.what() << '\n';
155+
}
156+
}
157+
return DTy;
158+
}
159+
142160
bool DPCTLDevice_IsAccelerator(__dpctl_keep const DPCTLSyclDeviceRef DRef)
143161
{
144162
auto D = unwrap(DRef);
@@ -175,6 +193,18 @@ bool DPCTLDevice_IsHost(__dpctl_keep const DPCTLSyclDeviceRef DRef)
175193
return false;
176194
}
177195

196+
DPCTLSyclBackendType
197+
DPCTLDevice_GetBackend(__dpctl_keep const DPCTLSyclDeviceRef DRef)
198+
{
199+
DPCTLSyclBackendType BTy = DPCTLSyclBackendType::DPCTL_UNKNOWN_BACKEND;
200+
auto D = unwrap(DRef);
201+
if (D) {
202+
BTy = DPCTL_SyclBackendToDPCTLBackendType(
203+
D->get_platform().get_backend());
204+
}
205+
return BTy;
206+
}
207+
178208
uint32_t
179209
DPCTLDevice_GetMaxComputeUnits(__dpctl_keep const DPCTLSyclDeviceRef DRef)
180210
{
@@ -263,6 +293,21 @@ DPCTLDevice_GetMaxNumSubGroups(__dpctl_keep const DPCTLSyclDeviceRef DRef)
263293
return max_nsubgroups;
264294
}
265295

296+
__dpctl_give DPCTLSyclPlatformRef
297+
DPCTLDevice_GetPlatform(__dpctl_keep const DPCTLSyclDeviceRef DRef)
298+
{
299+
DPCTLSyclPlatformRef PRef = nullptr;
300+
auto D = unwrap(DRef);
301+
if (D) {
302+
try {
303+
PRef = wrap(new platform(D->get_platform()));
304+
} catch (std::bad_alloc const &ba) {
305+
std::cerr << ba.what() << '\n';
306+
}
307+
}
308+
return PRef;
309+
}
310+
266311
bool DPCTLDevice_HasInt64BaseAtomics(__dpctl_keep const DPCTLSyclDeviceRef DRef)
267312
{
268313
bool hasBaseAtomics = false;

0 commit comments

Comments
 (0)