Skip to content

Commit 1f6e0a8

Browse files
Cleaned up _GetErrorCode_*_impl
1 parent b4d2d8b commit 1f6e0a8

File tree

1 file changed

+32
-80
lines changed

1 file changed

+32
-80
lines changed

libsyclinterface/source/dpctl_sycl_kernel_bundle_interface.cpp

Lines changed: 32 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ static const int clLibLoadFlags = 0;
6464
#error "OpenCL program compilation is unavailable for this platform"
6565
#endif
6666

67+
#define CodeStringSuffix(code) \
68+
std::string(" (code=") + std::to_string(static_cast<int>(code)) + ")"
69+
70+
#define EnumCaseString(code) \
71+
case code: \
72+
return std::string(#code) + CodeStringSuffix(code)
73+
6774
constexpr backend cl_be = backend::opencl;
6875

6976
struct cl_loader
@@ -155,41 +162,18 @@ clCreateKernelFT get_clCreateKernel()
155162

156163
std::string _GetErrorCode_ocl_impl(cl_int code)
157164
{
158-
if (code == CL_BUILD_PROGRAM_FAILURE) {
159-
return "CL_BUILD_PROGRAM_FAILURE (code=" +
160-
std::to_string(static_cast<int>(code)) + ")";
161-
}
162-
else if (code == CL_INVALID_CONTEXT) {
163-
return "CL_INVALID_CONTEXT (code=" +
164-
std::to_string(static_cast<int>(code)) + ")";
165-
}
166-
else if (code == CL_INVALID_DEVICE) {
167-
return "CL_INVALID_DEVICE (code=" +
168-
std::to_string(static_cast<int>(code)) + ")";
169-
}
170-
else if (code == CL_INVALID_VALUE) {
171-
return "CL_INVALID_VALUE (code=" +
172-
std::to_string(static_cast<int>(code)) + ")";
173-
}
174-
else if (code == CL_OUT_OF_RESOURCES) {
175-
return "CL_OUT_OF_RESOURCES (code=" +
176-
std::to_string(static_cast<int>(code)) + ")";
177-
}
178-
else if (code == CL_OUT_OF_HOST_MEMORY) {
179-
return "CL_OUT_OF_HOST_MEMORY (code=" +
180-
std::to_string(static_cast<int>(code)) + ")";
181-
}
182-
else if (code == CL_INVALID_OPERATION) {
183-
return "CL_INVALID_OPERATION (code=" +
184-
std::to_string(static_cast<int>(code)) + ")";
185-
}
186-
else if (code == CL_INVALID_BINARY) {
187-
return "CL_INVALID_BINARY (code=" +
188-
std::to_string(static_cast<int>(code)) + ")";
165+
switch (code) {
166+
EnumCaseString(CL_BUILD_PROGRAM_FAILURE);
167+
EnumCaseString(CL_INVALID_CONTEXT);
168+
EnumCaseString(CL_INVALID_DEVICE);
169+
EnumCaseString(CL_INVALID_VALUE);
170+
EnumCaseString(CL_OUT_OF_RESOURCES);
171+
EnumCaseString(CL_OUT_OF_HOST_MEMORY);
172+
EnumCaseString(CL_INVALID_OPERATION);
173+
EnumCaseString(CL_INVALID_BINARY);
174+
default:
175+
return "<< ERROR CODE UNRECOGNIZED >>" + CodeStringSuffix(code);
189176
}
190-
191-
return "<< ERROR CODE UNRECOGNIZED >> (code=" +
192-
std::to_string(static_cast<int>(code)) + ")";
193177
}
194178

195179
DPCTLSyclKernelBundleRef
@@ -426,53 +410,21 @@ zeKernelCreateFT get_zeKernelCreate()
426410

427411
std::string _GetErrorCode_ze_impl(ze_result_t code)
428412
{
429-
if (code == ZE_RESULT_ERROR_UNINITIALIZED) {
430-
return "ZE_RESULT_ERROR_UNINITIALIZED (code=" +
431-
std::to_string(static_cast<int>(code)) + ")";
432-
}
433-
else if (code == ZE_RESULT_ERROR_DEVICE_LOST) {
434-
return "ZE_RESULT_ERROR_DEVICE_LOST (code=" +
435-
std::to_string(static_cast<int>(code)) + ")";
436-
}
437-
else if (code == ZE_RESULT_ERROR_INVALID_NULL_HANDLE) {
438-
return "ZE_RESULT_ERROR_INVALID_NULL_HANDLE (code=" +
439-
std::to_string(static_cast<int>(code)) + ")";
440-
}
441-
else if (code == ZE_RESULT_ERROR_INVALID_NULL_POINTER) {
442-
return "ZE_RESULT_ERROR_INVALID_NULL_POINTER (code=" +
443-
std::to_string(static_cast<int>(code)) + ")";
444-
}
445-
else if (code == ZE_RESULT_ERROR_INVALID_ENUMERATION) {
446-
return "ZE_RESULT_ERROR_INVALID_ENUMERATION (code=" +
447-
std::to_string(static_cast<int>(code)) + ")";
448-
}
449-
else if (code == ZE_RESULT_ERROR_INVALID_NATIVE_BINARY) {
450-
return "ZE_RESULT_ERROR_INVALID_NATIVE_BINARY (code=" +
451-
std::to_string(static_cast<int>(code)) + ")";
452-
}
453-
else if (code == ZE_RESULT_ERROR_INVALID_SIZE) {
454-
return "ZE_RESULT_ERROR_INVALID_SIZE (code=" +
455-
std::to_string(static_cast<int>(code)) + ")";
456-
}
457-
else if (code == ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY) {
458-
return "ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY (code=" +
459-
std::to_string(static_cast<int>(code)) + ")";
460-
}
461-
else if (code == ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY) {
462-
return "ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY (code=" +
463-
std::to_string(static_cast<int>(code)) + ")";
464-
}
465-
else if (code == ZE_RESULT_ERROR_MODULE_BUILD_FAILURE) {
466-
return "ZE_RESULT_ERROR_MODULE_BUILD_FAILURE (code=" +
467-
std::to_string(static_cast<int>(code)) + ")";
468-
}
469-
else if (code == ZE_RESULT_ERROR_INVALID_MODULE_UNLINKED) {
470-
return "ZE_RESULT_ERROR_INVALID_MODULE_UNLINKED (code=" +
471-
std::to_string(static_cast<int>(code)) + ")";
413+
switch (code) {
414+
EnumCaseString(ZE_RESULT_ERROR_UNINITIALIZED);
415+
EnumCaseString(ZE_RESULT_ERROR_DEVICE_LOST);
416+
EnumCaseString(ZE_RESULT_ERROR_INVALID_NULL_HANDLE);
417+
EnumCaseString(ZE_RESULT_ERROR_INVALID_NULL_POINTER);
418+
EnumCaseString(ZE_RESULT_ERROR_INVALID_ENUMERATION);
419+
EnumCaseString(ZE_RESULT_ERROR_INVALID_NATIVE_BINARY);
420+
EnumCaseString(ZE_RESULT_ERROR_INVALID_SIZE);
421+
EnumCaseString(ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY);
422+
EnumCaseString(ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY);
423+
EnumCaseString(ZE_RESULT_ERROR_MODULE_BUILD_FAILURE);
424+
EnumCaseString(ZE_RESULT_ERROR_INVALID_MODULE_UNLINKED);
425+
default:
426+
return "<< UNRECOGNIZED ZE_RESULT_T CODE >> " + CodeStringSuffix(code);
472427
}
473-
474-
return "<< UNRECOGNIZE ZE_RESULT_T CODE >> (code=" +
475-
std::to_string(static_cast<int>(code)) + ")";
476428
}
477429

478430
__dpctl_give DPCTLSyclKernelBundleRef

0 commit comments

Comments
 (0)