Skip to content

Commit 5db1d6f

Browse files
1e-toetotmeni
and
etotmeni
authored
Add support for Aspects (#307)
* Add support of Current DPCPP aspects to dpctl. * All aspects are now available in the C API using the `DPCTLDevice_HasAspect` function. * Previous C API functions to get atomics aspects are now removed. * Add utilities functions to convert SYCL aspects to dpctl aspect types and vice-versa * Add a utility function to convert aspects to string. Co-authored-by: etotmeni <[email protected]>
1 parent 7219c50 commit 5db1d6f

11 files changed

+739
-121
lines changed

dpctl-capi/helper/include/dpctl_utils_helper.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,46 @@ DPCTL_DPCTLDeviceTypeToSyclDeviceType(DPCTLSyclDeviceType DTy);
9595
*/
9696
DPCTLSyclDeviceType
9797
DPCTL_SyclDeviceTypeToDPCTLDeviceType(sycl::info::device_type D);
98+
99+
/*!
100+
* @brief Converts a sycl::aspect input value to a string.
101+
*
102+
* @param aspectTy A sycl::aspect value.
103+
* @return A string representation of a sycl::aspect.
104+
* @throws runtime_error
105+
*/
106+
std::string DPCTL_AspectToStr(sycl::aspect aspectTy);
107+
108+
/*!
109+
* @brief Converts a string to sycl::aspect value.
110+
*
111+
* @param aspectTyStr Input string for which we search a
112+
* sycl::aspect value.
113+
* @return The sycl::aspect value corresponding to the input
114+
* string.
115+
* @throws runtime_error
116+
*/
117+
sycl::aspect DPCTL_StrToAspectType(const std::string &aspectTyStr);
118+
119+
/*!
120+
* @brief Converts a DPCTLSyclAspectType enum value to its corresponding
121+
* sycl::aspect enum value.
122+
*
123+
* @param AspectTy A DPCTLSyclAspectType enum value
124+
* @return A sycl::aspect enum value for the input
125+
* DPCTLSyclAspectType enum value.
126+
* @throws runtime_error
127+
*/
128+
sycl::aspect DPCTL_DPCTLAspectTypeToSyclAspect(DPCTLSyclAspectType AspectTy);
129+
130+
/*!
131+
* @brief Converts a sycl::aspect enum value to corresponding
132+
* DPCTLSyclAspectType enum value.
133+
*
134+
* @param Aspect sycl::aspect to be converted to
135+
* DPCTLSyclAspectType enum.
136+
* @return A DPCTLSyclAspectType enum value for the input
137+
* sycl::aspect enum value.
138+
* @throws runtime_error
139+
*/
140+
DPCTLSyclAspectType DPCTL_SyclAspectToDPCTLAspectType(sycl::aspect Aspect);

dpctl-capi/helper/source/dpctl_utils_helper.cpp

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,225 @@ DPCTLSyclDeviceType DPCTL_SyclDeviceTypeToDPCTLDeviceType(info::device_type D)
160160
return DPCTLSyclDeviceType::DPCTL_UNKNOWN_DEVICE;
161161
}
162162
}
163+
164+
/*!
165+
* Transforms cl::sycl::aspect to string.
166+
*/
167+
std::string DPCTL_AspectToStr(aspect aspectTy)
168+
{
169+
std::stringstream ss;
170+
switch (aspectTy) {
171+
case aspect::host:
172+
ss << "host" << '\n';
173+
break;
174+
case aspect::cpu:
175+
ss << "cpu" << '\n';
176+
break;
177+
case aspect::gpu:
178+
ss << "gpu" << '\n';
179+
break;
180+
case aspect::accelerator:
181+
ss << "accelerator" << '\n';
182+
break;
183+
case aspect::custom:
184+
ss << "custom" << '\n';
185+
break;
186+
case aspect::fp16:
187+
ss << "fp16" << '\n';
188+
break;
189+
case aspect::fp64:
190+
ss << "fp64" << '\n';
191+
break;
192+
case aspect::int64_base_atomics:
193+
ss << "int64_base_atomics" << '\n';
194+
break;
195+
case aspect::int64_extended_atomics:
196+
ss << "int64_extended_atomics" << '\n';
197+
break;
198+
case aspect::image:
199+
ss << "image" << '\n';
200+
break;
201+
case aspect::online_compiler:
202+
ss << "online_compiler" << '\n';
203+
break;
204+
case aspect::online_linker:
205+
ss << "online_linker" << '\n';
206+
break;
207+
case aspect::queue_profiling:
208+
ss << "queue_profiling" << '\n';
209+
break;
210+
case aspect::usm_device_allocations:
211+
ss << "usm_device_allocations" << '\n';
212+
break;
213+
case aspect::usm_host_allocations:
214+
ss << "usm_host_allocations" << '\n';
215+
break;
216+
case aspect::usm_shared_allocations:
217+
ss << "usm_shared_allocations" << '\n';
218+
break;
219+
case aspect::usm_restricted_shared_allocations:
220+
ss << "usm_restricted_shared_allocations" << '\n';
221+
break;
222+
case aspect::usm_system_allocator:
223+
ss << "usm_system_allocator" << '\n';
224+
break;
225+
default:
226+
throw runtime_error("Unsupported aspect type", -1);
227+
}
228+
return ss.str();
229+
}
230+
231+
/*!
232+
* Transforms string to cl::sycl::aspect.
233+
*/
234+
aspect DPCTL_StrToAspectType(const std::string &aspectTyStr)
235+
{
236+
aspect aspectTy;
237+
if (aspectTyStr == "host") {
238+
aspectTy = aspect::host;
239+
}
240+
else if (aspectTyStr == "cpu") {
241+
aspectTy = aspect::cpu;
242+
}
243+
else if (aspectTyStr == "gpu") {
244+
aspectTy = aspect::gpu;
245+
}
246+
else if (aspectTyStr == "accelerator") {
247+
aspectTy = aspect::accelerator;
248+
}
249+
else if (aspectTyStr == "custom") {
250+
aspectTy = aspect::custom;
251+
}
252+
else if (aspectTyStr == "fp16") {
253+
aspectTy = aspect::fp16;
254+
}
255+
else if (aspectTyStr == "fp64") {
256+
aspectTy = aspect::fp64;
257+
}
258+
else if (aspectTyStr == "int64_base_atomics") {
259+
aspectTy = aspect::int64_base_atomics;
260+
}
261+
else if (aspectTyStr == "int64_extended_atomics") {
262+
aspectTy = aspect::int64_extended_atomics;
263+
}
264+
else if (aspectTyStr == "image") {
265+
aspectTy = aspect::image;
266+
}
267+
else if (aspectTyStr == "online_compiler") {
268+
aspectTy = aspect::online_compiler;
269+
}
270+
else if (aspectTyStr == "online_linker") {
271+
aspectTy = aspect::online_linker;
272+
}
273+
else if (aspectTyStr == "queue_profiling") {
274+
aspectTy = aspect::queue_profiling;
275+
}
276+
else if (aspectTyStr == "usm_device_allocations") {
277+
aspectTy = aspect::usm_device_allocations;
278+
}
279+
else if (aspectTyStr == "usm_host_allocations") {
280+
aspectTy = aspect::usm_host_allocations;
281+
}
282+
else if (aspectTyStr == "usm_shared_allocations") {
283+
aspectTy = aspect::usm_shared_allocations;
284+
}
285+
else if (aspectTyStr == "usm_restricted_shared_allocations") {
286+
aspectTy = aspect::usm_restricted_shared_allocations;
287+
}
288+
else if (aspectTyStr == "usm_system_allocator") {
289+
aspectTy = aspect::usm_system_allocator;
290+
}
291+
else {
292+
// \todo handle the error
293+
throw runtime_error("Unsupported aspect type", -1);
294+
}
295+
return aspectTy;
296+
}
297+
298+
aspect DPCTL_DPCTLAspectTypeToSyclAspect(DPCTLSyclAspectType AspectTy)
299+
{
300+
switch (AspectTy) {
301+
case DPCTLSyclAspectType::host:
302+
return aspect::host;
303+
case DPCTLSyclAspectType::cpu:
304+
return aspect::cpu;
305+
case DPCTLSyclAspectType::gpu:
306+
return aspect::gpu;
307+
case DPCTLSyclAspectType::accelerator:
308+
return aspect::accelerator;
309+
case DPCTLSyclAspectType::custom:
310+
return aspect::custom;
311+
case DPCTLSyclAspectType::fp16:
312+
return aspect::fp16;
313+
case DPCTLSyclAspectType::fp64:
314+
return aspect::fp64;
315+
case DPCTLSyclAspectType::int64_base_atomics:
316+
return aspect::int64_base_atomics;
317+
case DPCTLSyclAspectType::int64_extended_atomics:
318+
return aspect::int64_extended_atomics;
319+
case DPCTLSyclAspectType::image:
320+
return aspect::image;
321+
case DPCTLSyclAspectType::online_compiler:
322+
return aspect::online_compiler;
323+
case DPCTLSyclAspectType::online_linker:
324+
return aspect::online_linker;
325+
case DPCTLSyclAspectType::queue_profiling:
326+
return aspect::queue_profiling;
327+
case DPCTLSyclAspectType::usm_device_allocations:
328+
return aspect::usm_device_allocations;
329+
case DPCTLSyclAspectType::usm_host_allocations:
330+
return aspect::usm_host_allocations;
331+
case DPCTLSyclAspectType::usm_shared_allocations:
332+
return aspect::usm_shared_allocations;
333+
case DPCTLSyclAspectType::usm_restricted_shared_allocations:
334+
return aspect::usm_restricted_shared_allocations;
335+
case DPCTLSyclAspectType::usm_system_allocator:
336+
return aspect::usm_system_allocator;
337+
default:
338+
throw runtime_error("Unsupported aspect type", -1);
339+
}
340+
}
341+
342+
DPCTLSyclAspectType DPCTL_SyclAspectToDPCTLAspectType(aspect Aspect)
343+
{
344+
switch (Aspect) {
345+
case aspect::host:
346+
return DPCTLSyclAspectType::host;
347+
case aspect::cpu:
348+
return DPCTLSyclAspectType::cpu;
349+
case aspect::gpu:
350+
return DPCTLSyclAspectType::gpu;
351+
case aspect::accelerator:
352+
return DPCTLSyclAspectType::accelerator;
353+
case aspect::custom:
354+
return DPCTLSyclAspectType::custom;
355+
case aspect::fp16:
356+
return DPCTLSyclAspectType::fp16;
357+
case aspect::fp64:
358+
return DPCTLSyclAspectType::fp64;
359+
case aspect::int64_base_atomics:
360+
return DPCTLSyclAspectType::int64_base_atomics;
361+
case aspect::int64_extended_atomics:
362+
return DPCTLSyclAspectType::int64_extended_atomics;
363+
case aspect::image:
364+
return DPCTLSyclAspectType::image;
365+
case aspect::online_compiler:
366+
return DPCTLSyclAspectType::online_compiler;
367+
case aspect::online_linker:
368+
return DPCTLSyclAspectType::online_linker;
369+
case aspect::queue_profiling:
370+
return DPCTLSyclAspectType::queue_profiling;
371+
case aspect::usm_device_allocations:
372+
return DPCTLSyclAspectType::usm_device_allocations;
373+
case aspect::usm_host_allocations:
374+
return DPCTLSyclAspectType::usm_host_allocations;
375+
case aspect::usm_shared_allocations:
376+
return DPCTLSyclAspectType::usm_shared_allocations;
377+
case aspect::usm_restricted_shared_allocations:
378+
return DPCTLSyclAspectType::usm_restricted_shared_allocations;
379+
case aspect::usm_system_allocator:
380+
return DPCTLSyclAspectType::usm_system_allocator;
381+
default:
382+
throw runtime_error("Unsupported aspect type", -1);
383+
}
384+
}

dpctl-capi/include/dpctl_sycl_device_interface.h

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -210,29 +210,6 @@ DPCTL_API
210210
__dpctl_give DPCTLSyclPlatformRef
211211
DPCTLDevice_GetPlatform(__dpctl_keep const DPCTLSyclDeviceRef DRef);
212212

213-
/*!
214-
* @brief Wrapper over
215-
* device.get_info<info::device::aspect::int64_base_atomics>.
216-
*
217-
* @param DRef Opaque pointer to a sycl::device
218-
* @return Returns true if device has int64_base_atomics else returns false.
219-
*/
220-
DPCTL_API
221-
bool DPCTLDevice_HasInt64BaseAtomics(
222-
__dpctl_keep const DPCTLSyclDeviceRef DRef);
223-
224-
/*!
225-
* @brief Wrapper over
226-
* device.get_info<info::device::aspect::int64_extended_atomics>.
227-
*
228-
* @param DRef Opaque pointer to a sycl::device
229-
* @return Returns true if device has int64_extended_atomics else returns
230-
* false.
231-
*/
232-
DPCTL_API
233-
bool DPCTLDevice_HasInt64ExtendedAtomics(
234-
__dpctl_keep const DPCTLSyclDeviceRef DRef);
235-
236213
/*!
237214
* @brief Returns a C string for the device name.
238215
*
@@ -274,7 +251,18 @@ bool DPCTLDevice_IsHostUnifiedMemory(
274251
* @return True if the underlying sycl::device are same, false otherwise.
275252
*/
276253
DPCTL_API
277-
bool DPCTLDevice_AreEq(__dpctl_keep const DPCTLSyclDeviceRef DRef1,
278-
__dpctl_keep const DPCTLSyclDeviceRef DRef2);
254+
bool DPCTLDevice_AreEq(__dpctl_keep const DPCTLSyclDeviceRef DevRef1,
255+
__dpctl_keep const DPCTLSyclDeviceRef DevRef2);
256+
257+
/*!
258+
* @brief Checks if device has aspect.
259+
*
260+
* @param DRef Opaque pointer to a sycl::device
261+
* @param AT DPCTLSyclAspectType of device::aspect.
262+
* @return True if sycl::device has device::aspect, else false.
263+
*/
264+
DPCTL_API
265+
bool DPCTLDevice_HasAspect(__dpctl_keep const DPCTLSyclDeviceRef DRef,
266+
DPCTLSyclAspectType AT);
279267

280268
DPCTL_C_EXTERN_C_END

dpctl-capi/include/dpctl_sycl_enum_types.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,33 @@ typedef enum
9595
DPCTL_VOID_PTR
9696
} DPCTLKernelArgType;
9797

98+
/*!
99+
* @brief DPCTL device has an associated set of aspects which identify
100+
* characteristics of the device.
101+
*
102+
*/
103+
enum DPCTLSyclAspectType
104+
{
105+
host,
106+
cpu,
107+
gpu,
108+
accelerator,
109+
custom,
110+
fp16,
111+
fp64,
112+
int64_base_atomics,
113+
int64_extended_atomics,
114+
image,
115+
online_compiler,
116+
online_linker,
117+
queue_profiling,
118+
usm_device_allocations,
119+
usm_host_allocations,
120+
usm_shared_allocations,
121+
usm_restricted_shared_allocations,
122+
usm_system_allocator
123+
};
124+
98125
/*!
99126
* @brief Enums to depict the properties that can be passed to a sycl::queue
100127
* constructor.

0 commit comments

Comments
 (0)