Skip to content

Commit 8d47967

Browse files
authored
Adds new helper functions to convert between DPCTL and SYCL enum values. (#296)
Merging this to keep the wheels of development rolling. Windows CI fails due so issue not related to these changes.
1 parent 8a7e228 commit 8d47967

File tree

2 files changed

+146
-4
lines changed

2 files changed

+146
-4
lines changed

dpctl-capi/helper/include/dpctl_utils_helper.h

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,74 @@
2424

2525
#pragma once
2626

27+
#include "../include/dpctl_sycl_enum_types.h"
2728
#include <CL/sycl.hpp>
28-
using namespace cl::sycl;
2929

30-
std::string DPCTL_DeviceTypeToStr(info::device_type devTy);
31-
info::device_type DPCTL_StrToDeviceType(std::string devTyStr);
30+
/*!
31+
* @brief Converts a sycl::info::device_type input value to a string.
32+
*
33+
* @param devTy A sycl::info::device_type enum value.
34+
* @return A string representation of a sycl::info::device_type enum.
35+
*/
36+
std::string DPCTL_DeviceTypeToStr(sycl::info::device_type devTy);
37+
38+
/*!
39+
* @brief Converts a string to sycl::info::device_type enum value.
40+
*
41+
* Tries to interpret the input string a return a corresponding device_type. If
42+
* no conversion is possible, then a runtime_error is thrown.
43+
*
44+
* @param devTyStr Input string for which we search a
45+
* sycl::info::device_type enum value.
46+
* @return The sycl::info::device_type enum value corresponding to the input
47+
* string.
48+
* @throws runtime_error
49+
*/
50+
sycl::info::device_type DPCTL_StrToDeviceType(const std::string &devTyStr);
51+
52+
/*!
53+
* @brief Converts a DPCTLSyclBackendType enum value to its corresponding
54+
* sycl::backend enum value. If conversion fails, a runtime_error is thrown.
55+
*
56+
* @param BeTy My Param doc
57+
* @return A sycl::backend enum value for the input
58+
* DPCTLSyclDeviceType enum value.
59+
* @throws runtime_error
60+
*/
61+
sycl::backend DPCTL_DPCTLBackendTypeToSyclBackend(DPCTLSyclBackendType BeTy);
62+
63+
/*!
64+
* @brief Converts a sycl::backend enum value to corresponding
65+
* DPCTLSyclBackendType enum value.
66+
*
67+
* @param B sycl::backend to be converted to
68+
* DPCTLSyclBackendType enum.
69+
* @return A DPCTLSyclBackendType enum value for the input
70+
* sycl::backend enum value.
71+
*/
72+
DPCTLSyclBackendType DPCTL_SyclBackendToDPCTLBackendType(sycl::backend B);
73+
74+
/*!
75+
* @brief Converts a DPCTLSyclDeviceType enum value to its corresponding
76+
* sycl::info::device_type enum value. If conversion fails, a runtime_error is
77+
* thrown.
78+
*
79+
* @param DTy A DPCTLSyclDeviceType enum value
80+
* @return A sycl::info::device_type enum value for the input
81+
* DPCTLSyclDeviceType enum value.
82+
* @throws runtime_error
83+
*/
84+
sycl::info::device_type
85+
DPCTL_DPCTLDeviceTypeToSyclDeviceType(DPCTLSyclDeviceType DTy);
86+
87+
/*!
88+
* @brief Converts a sycl::info::device_type enum value to corresponding
89+
* DPCTLSyclDeviceType enum value.
90+
*
91+
* @param D sycl::info::device_type to be converted to
92+
* DPCTLSyclDeviceType enum.
93+
* @return A DPCTLSyclDeviceType enum value for the input
94+
* sycl::info::device_type enum value.
95+
*/
96+
DPCTLSyclDeviceType
97+
DPCTL_SyclDeviceTypeToDPCTLDeviceType(sycl::info::device_type D);

dpctl-capi/helper/source/dpctl_utils_helper.cpp

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ std::string DPCTL_DeviceTypeToStr(info::device_type devTy)
6060
/*!
6161
* Transforms string to enum info::device_type.
6262
*/
63-
info::device_type DPCTL_StrToDeviceType(std::string devTyStr)
63+
info::device_type DPCTL_StrToDeviceType(const std::string &devTyStr)
6464
{
6565
info::device_type devTy;
6666
if (devTyStr == "cpu") {
@@ -84,3 +84,79 @@ info::device_type DPCTL_StrToDeviceType(std::string devTyStr)
8484
}
8585
return devTy;
8686
}
87+
88+
backend DPCTL_DPCTLBackendTypeToSyclBackend(DPCTLSyclBackendType BeTy)
89+
{
90+
switch (BeTy) {
91+
case DPCTLSyclBackendType::DPCTL_CUDA:
92+
return backend::cuda;
93+
case DPCTLSyclBackendType::DPCTL_HOST:
94+
return backend::host;
95+
case DPCTLSyclBackendType::DPCTL_LEVEL_ZERO:
96+
return backend::level_zero;
97+
case DPCTLSyclBackendType::DPCTL_OPENCL:
98+
return backend::opencl;
99+
default:
100+
throw runtime_error("Unsupported backend type", -1);
101+
}
102+
}
103+
104+
DPCTLSyclBackendType DPCTL_SyclBackendToDPCTLBackendType(backend B)
105+
{
106+
switch (B) {
107+
case backend::cuda:
108+
return DPCTLSyclBackendType::DPCTL_CUDA;
109+
case backend::host:
110+
return DPCTLSyclBackendType::DPCTL_HOST;
111+
case backend::level_zero:
112+
return DPCTLSyclBackendType::DPCTL_LEVEL_ZERO;
113+
case backend::opencl:
114+
return DPCTLSyclBackendType::DPCTL_OPENCL;
115+
default:
116+
return DPCTLSyclBackendType::DPCTL_UNKNOWN_BACKEND;
117+
}
118+
}
119+
120+
info::device_type DPCTL_DPCTLDeviceTypeToSyclDeviceType(DPCTLSyclDeviceType DTy)
121+
{
122+
switch (DTy) {
123+
case DPCTLSyclDeviceType::DPCTL_ACCELERATOR:
124+
return info::device_type::accelerator;
125+
case DPCTLSyclDeviceType::DPCTL_ALL:
126+
return info::device_type::all;
127+
case DPCTLSyclDeviceType::DPCTL_AUTOMATIC:
128+
return info::device_type::automatic;
129+
case DPCTLSyclDeviceType::DPCTL_CPU:
130+
return info::device_type::cpu;
131+
case DPCTLSyclDeviceType::DPCTL_CUSTOM:
132+
return info::device_type::custom;
133+
case DPCTLSyclDeviceType::DPCTL_GPU:
134+
return info::device_type::gpu;
135+
case DPCTLSyclDeviceType::DPCTL_HOST_DEVICE:
136+
return info::device_type::host;
137+
default:
138+
throw runtime_error("Unsupported device type", -1);
139+
}
140+
}
141+
142+
DPCTLSyclDeviceType DPCTL_SyclDeviceTypeToDPCTLDeviceType(info::device_type D)
143+
{
144+
switch (D) {
145+
case info::device_type::accelerator:
146+
return DPCTLSyclDeviceType::DPCTL_ACCELERATOR;
147+
case info::device_type::all:
148+
return DPCTLSyclDeviceType::DPCTL_ALL;
149+
case info::device_type::automatic:
150+
return DPCTLSyclDeviceType::DPCTL_AUTOMATIC;
151+
case info::device_type::cpu:
152+
return DPCTLSyclDeviceType::DPCTL_CPU;
153+
case info::device_type::custom:
154+
return DPCTLSyclDeviceType::DPCTL_CUSTOM;
155+
case info::device_type::gpu:
156+
return DPCTLSyclDeviceType::DPCTL_GPU;
157+
case info::device_type::host:
158+
return DPCTLSyclDeviceType::DPCTL_HOST_DEVICE;
159+
default:
160+
return DPCTLSyclDeviceType::DPCTL_UNKNOWN_DEVICE;
161+
}
162+
}

0 commit comments

Comments
 (0)