タイトルごとに、読み取り可能なOpenCLエラーコードを表示する便利な方法はありますか?
'-1000'のようなコードを名前に変換できると、エラーコードを参照する時間を大幅に節約できます。
これは私が現在していることです。 OpenCL1.2のエラーリストは完全だと思います。
cl_int result = clSomeFunction();
if(result != CL_SUCCESS)
std::cerr << getErrorString(result) << std::endl;
そして、getErrorStringは次のように定義されています。
const char *getErrorString(cl_int error)
{
switch(error){
// run-time and JIT compiler errors
case 0: return "CL_SUCCESS";
case -1: return "CL_DEVICE_NOT_FOUND";
case -2: return "CL_DEVICE_NOT_AVAILABLE";
case -3: return "CL_COMPILER_NOT_AVAILABLE";
case -4: return "CL_MEM_OBJECT_ALLOCATION_FAILURE";
case -5: return "CL_OUT_OF_RESOURCES";
case -6: return "CL_OUT_OF_Host_MEMORY";
case -7: return "CL_PROFILING_INFO_NOT_AVAILABLE";
case -8: return "CL_MEM_COPY_OVERLAP";
case -9: return "CL_IMAGE_FORMAT_MISMATCH";
case -10: return "CL_IMAGE_FORMAT_NOT_SUPPORTED";
case -11: return "CL_BUILD_PROGRAM_FAILURE";
case -12: return "CL_MAP_FAILURE";
case -13: return "CL_MISALIGNED_SUB_BUFFER_OFFSET";
case -14: return "CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST";
case -15: return "CL_COMPILE_PROGRAM_FAILURE";
case -16: return "CL_LINKER_NOT_AVAILABLE";
case -17: return "CL_LINK_PROGRAM_FAILURE";
case -18: return "CL_DEVICE_PARTITION_FAILED";
case -19: return "CL_KERNEL_ARG_INFO_NOT_AVAILABLE";
// compile-time errors
case -30: return "CL_INVALID_VALUE";
case -31: return "CL_INVALID_DEVICE_TYPE";
case -32: return "CL_INVALID_PLATFORM";
case -33: return "CL_INVALID_DEVICE";
case -34: return "CL_INVALID_CONTEXT";
case -35: return "CL_INVALID_QUEUE_PROPERTIES";
case -36: return "CL_INVALID_COMMAND_QUEUE";
case -37: return "CL_INVALID_Host_PTR";
case -38: return "CL_INVALID_MEM_OBJECT";
case -39: return "CL_INVALID_IMAGE_FORMAT_DESCRIPTOR";
case -40: return "CL_INVALID_IMAGE_SIZE";
case -41: return "CL_INVALID_SAMPLER";
case -42: return "CL_INVALID_BINARY";
case -43: return "CL_INVALID_BUILD_OPTIONS";
case -44: return "CL_INVALID_PROGRAM";
case -45: return "CL_INVALID_PROGRAM_EXECUTABLE";
case -46: return "CL_INVALID_KERNEL_NAME";
case -47: return "CL_INVALID_KERNEL_DEFINITION";
case -48: return "CL_INVALID_KERNEL";
case -49: return "CL_INVALID_ARG_INDEX";
case -50: return "CL_INVALID_ARG_VALUE";
case -51: return "CL_INVALID_ARG_SIZE";
case -52: return "CL_INVALID_KERNEL_ARGS";
case -53: return "CL_INVALID_WORK_DIMENSION";
case -54: return "CL_INVALID_WORK_GROUP_SIZE";
case -55: return "CL_INVALID_WORK_ITEM_SIZE";
case -56: return "CL_INVALID_GLOBAL_OFFSET";
case -57: return "CL_INVALID_EVENT_WAIT_LIST";
case -58: return "CL_INVALID_EVENT";
case -59: return "CL_INVALID_OPERATION";
case -60: return "CL_INVALID_GL_OBJECT";
case -61: return "CL_INVALID_BUFFER_SIZE";
case -62: return "CL_INVALID_MIP_LEVEL";
case -63: return "CL_INVALID_GLOBAL_WORK_SIZE";
case -64: return "CL_INVALID_PROPERTY";
case -65: return "CL_INVALID_IMAGE_DESCRIPTOR";
case -66: return "CL_INVALID_COMPILER_OPTIONS";
case -67: return "CL_INVALID_LINKER_OPTIONS";
case -68: return "CL_INVALID_DEVICE_PARTITION_COUNT";
// extension errors
case -1000: return "CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR";
case -1001: return "CL_PLATFORM_NOT_FOUND_KHR";
case -1002: return "CL_INVALID_D3D10_DEVICE_KHR";
case -1003: return "CL_INVALID_D3D10_RESOURCE_KHR";
case -1004: return "CL_D3D10_RESOURCE_ALREADY_ACQUIRED_KHR";
case -1005: return "CL_D3D10_RESOURCE_NOT_ACQUIRED_KHR";
default: return "Unknown OpenCL error";
}
}
文字列とは異なるバージョンのOpenCLエラーコードが必要な場合は、 ここ は小さなスクリプトです。
_$ ./clext.py /directory/to/opencl/headers
_
たとえば、OpenCL 2.2のヘルプ関数を文字列に変換するエラーコードを作成するには、次のコマンドを実行します。
_$ ./clext.py ~/Developments/OpenCL-Headers/opencl22/CL
_
現在のディレクトリにファイル_clext.h
_を作成します。
次に、このファイルをプロジェクトに含め、const char* clGetErrorString(int errorCode)
を使用して、エラーコードからエラー文字列を取得できます。
OpenCL 2.2用に生成されたファイル_clext.h
_の内容は次のとおりです。
_// auto generated from ./clext.py
#ifndef __CL_EXT__
#define __CL_EXT__
#include <stdio.h>
/*
* Given a cl code and return a string represenation
*/
const char* clGetErrorString(int errorCode) {
switch (errorCode) {
case 0: return "CL_SUCCESS";
case -1: return "CL_DEVICE_NOT_FOUND";
case -2: return "CL_DEVICE_NOT_AVAILABLE";
case -3: return "CL_COMPILER_NOT_AVAILABLE";
case -4: return "CL_MEM_OBJECT_ALLOCATION_FAILURE";
case -5: return "CL_OUT_OF_RESOURCES";
case -6: return "CL_OUT_OF_Host_MEMORY";
case -7: return "CL_PROFILING_INFO_NOT_AVAILABLE";
case -8: return "CL_MEM_COPY_OVERLAP";
case -9: return "CL_IMAGE_FORMAT_MISMATCH";
case -10: return "CL_IMAGE_FORMAT_NOT_SUPPORTED";
case -12: return "CL_MAP_FAILURE";
case -13: return "CL_MISALIGNED_SUB_BUFFER_OFFSET";
case -14: return "CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST";
case -15: return "CL_COMPILE_PROGRAM_FAILURE";
case -16: return "CL_LINKER_NOT_AVAILABLE";
case -17: return "CL_LINK_PROGRAM_FAILURE";
case -18: return "CL_DEVICE_PARTITION_FAILED";
case -19: return "CL_KERNEL_ARG_INFO_NOT_AVAILABLE";
case -30: return "CL_INVALID_VALUE";
case -31: return "CL_INVALID_DEVICE_TYPE";
case -32: return "CL_INVALID_PLATFORM";
case -33: return "CL_INVALID_DEVICE";
case -34: return "CL_INVALID_CONTEXT";
case -35: return "CL_INVALID_QUEUE_PROPERTIES";
case -36: return "CL_INVALID_COMMAND_QUEUE";
case -37: return "CL_INVALID_Host_PTR";
case -38: return "CL_INVALID_MEM_OBJECT";
case -39: return "CL_INVALID_IMAGE_FORMAT_DESCRIPTOR";
case -40: return "CL_INVALID_IMAGE_SIZE";
case -41: return "CL_INVALID_SAMPLER";
case -42: return "CL_INVALID_BINARY";
case -43: return "CL_INVALID_BUILD_OPTIONS";
case -44: return "CL_INVALID_PROGRAM";
case -45: return "CL_INVALID_PROGRAM_EXECUTABLE";
case -46: return "CL_INVALID_KERNEL_NAME";
case -47: return "CL_INVALID_KERNEL_DEFINITION";
case -48: return "CL_INVALID_KERNEL";
case -49: return "CL_INVALID_ARG_INDEX";
case -50: return "CL_INVALID_ARG_VALUE";
case -51: return "CL_INVALID_ARG_SIZE";
case -52: return "CL_INVALID_KERNEL_ARGS";
case -53: return "CL_INVALID_WORK_DIMENSION";
case -54: return "CL_INVALID_WORK_GROUP_SIZE";
case -55: return "CL_INVALID_WORK_ITEM_SIZE";
case -56: return "CL_INVALID_GLOBAL_OFFSET";
case -57: return "CL_INVALID_EVENT_WAIT_LIST";
case -58: return "CL_INVALID_EVENT";
case -59: return "CL_INVALID_OPERATION";
case -60: return "CL_INVALID_GL_OBJECT";
case -61: return "CL_INVALID_BUFFER_SIZE";
case -62: return "CL_INVALID_MIP_LEVEL";
case -63: return "CL_INVALID_GLOBAL_WORK_SIZE";
case -64: return "CL_INVALID_PROPERTY";
case -65: return "CL_INVALID_IMAGE_DESCRIPTOR";
case -66: return "CL_INVALID_COMPILER_OPTIONS";
case -67: return "CL_INVALID_LINKER_OPTIONS";
case -68: return "CL_INVALID_DEVICE_PARTITION_COUNT";
case -69: return "CL_INVALID_PIPE_SIZE";
case -70: return "CL_INVALID_DEVICE_QUEUE";
case -71: return "CL_INVALID_SPEC_ID";
case -72: return "CL_MAX_SIZE_RESTRICTION_EXCEEDED";
case -1002: return "CL_INVALID_D3D10_DEVICE_KHR";
case -1003: return "CL_INVALID_D3D10_RESOURCE_KHR";
case -1004: return "CL_D3D10_RESOURCE_ALREADY_ACQUIRED_KHR";
case -1005: return "CL_D3D10_RESOURCE_NOT_ACQUIRED_KHR";
case -1006: return "CL_INVALID_D3D11_DEVICE_KHR";
case -1007: return "CL_INVALID_D3D11_RESOURCE_KHR";
case -1008: return "CL_D3D11_RESOURCE_ALREADY_ACQUIRED_KHR";
case -1009: return "CL_D3D11_RESOURCE_NOT_ACQUIRED_KHR";
case -1010: return "CL_INVALID_DX9_MEDIA_ADAPTER_KHR";
case -1011: return "CL_INVALID_DX9_MEDIA_SURFACE_KHR";
case -1012: return "CL_DX9_MEDIA_SURFACE_ALREADY_ACQUIRED_KHR";
case -1013: return "CL_DX9_MEDIA_SURFACE_NOT_ACQUIRED_KHR";
case -1093: return "CL_INVALID_EGL_OBJECT_KHR";
case -1092: return "CL_EGL_RESOURCE_NOT_ACQUIRED_KHR";
case -1001: return "CL_PLATFORM_NOT_FOUND_KHR";
case -1057: return "CL_DEVICE_PARTITION_FAILED_EXT";
case -1058: return "CL_INVALID_PARTITION_COUNT_EXT";
case -1059: return "CL_INVALID_PARTITION_NAME_EXT";
case -1094: return "CL_INVALID_ACCELERATOR_INTEL";
case -1095: return "CL_INVALID_ACCELERATOR_TYPE_INTEL";
case -1096: return "CL_INVALID_ACCELERATOR_DESCRIPTOR_INTEL";
case -1097: return "CL_ACCELERATOR_TYPE_NOT_SUPPORTED_INTEL";
case -1000: return "CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR";
case -1098: return "CL_INVALID_VA_API_MEDIA_ADAPTER_INTEL";
case -1099: return "CL_INVALID_VA_API_MEDIA_SURFACE_INTEL";
case -1100: return "CL_VA_API_MEDIA_SURFACE_ALREADY_ACQUIRED_INTEL";
case -1101: return "CL_VA_API_MEDIA_SURFACE_NOT_ACQUIRED_INTEL";
default: return "CL_UNKNOWN_ERROR";
}
}
/*
* check cl error, if not CL_SUCCESS, print to stderr
*/
int clCheckError(int errorCode) {
if (errorCode != 0) {
fprintf(stderr, "%s\n", clGetErrorString(errorCode));
}
return errorCode;
}
#endif /* __CL_EXT__*/
_
他の回答のハードコードされたエラーコードが気に入らない場合は、Cで行うことを次に示します。
#define CaseReturnString(x)case x:return #x; char * opencl_errstr(cl_int err) { スイッチ(err) { CaseReturnString(CL_SUCCESS) CaseReturnString(CL_DEVICE_NOT_FOUND) CaseReturnString(CL_DEVICE_NOT_AVAILABLE) CaseReturnString(CL_COMPILER_NOT_AIL) CaseReturnString(CL_COMPILER_NOT_A ) CaseReturnString(CL_OUT_OF_RESOURCES) CaseReturnString(CL_OUT_OF_Host_MEMORY) CaseReturnString(CL_PROFILING_INFO_NOT_AVAILABLE) CaseReturnString(CL_PROFILING_INFO_NOT_AVAILABLE) CaseReturnString(CL_IMAGE_FORMAT_NOT_SUPPORTED) CaseReturnString(CL_BUILD_PROGRAM_FAILURE) CaseReturnString(CL_MAP_FAILURE) CaseReturnString(CL_MISALIGNED_SUB_BUFFER_OFFSET) CaseReturnString(CL_COMPILE_PROGRAM_FAILURE) CaseReturnString(CL_LINKER_NOT_AVAILE) CaseReturnString(CL_LINKER_NOT_AVAIL CL_DEVICE_PARTITION_FAILED) CaseReturnString(CL_KERNEL_ARG_INFO_NOT_AVAILABLE) CaseReturnString(CL_INVALID_VALUE) CaseReturnString(CL_INVALID_DEVICE_TYPE) CaseReturnString(CL_INVALID_DEVICE_TYPE) CaseReturnString 。] CaseReturnString(CL_INVALID_CONTEXT) CaseReturnString(CL_INVALID_QUEUE_PROPERTIES) CaseReturnString(CL_INVALID_COMMAND_QUEUE) CaseReturnString(CL_INVALID_Host_P TR) CaseReturnString(CL_INVALID_MEM_OBJECT) CaseReturnString(CL_INVALID_IMAGE_FORMAT_DESCRIPTOR) CaseReturnString(CL_INVALID_IMAGE_SIZE) CaseReturnString(CL_INVALID ___)CaseReturnString(CL_INVALID_SAMP_ 。] CaseReturnString(CL_INVALID_BUILD_OPTIONS) CaseReturnString(CL_INVALID_PROGRAM) CaseReturnString(CL_INVALID_PROGRAM_EXECUTABLE) CaseReturnString(CL_INVALID_KERNEL_NAME) CaseReturnString(CL_INVALID_KERNEL_NAME)[ ) CaseReturnString(CL_INVALID_ARG_INDEX) CaseReturnString(CL_INVALID_ARG_VALUE) CaseReturnString(CL_INVALID_ARG_SIZE) CaseReturnStri ng(CL_INVALID_KERNEL_ARGS) CaseReturnString(CL_INVALID_WORK_DIMENSION) CaseReturnString(CL_INVALID_WORK_GROUP_SIZE) CaseReturnString(CL_INVALID_WORK_ITEM_SIZE)[._。] CaseReturnString(CL_INVALID_WORK_ITEM_SIZE)[._ .____。] CaseReturnString(CL_INVALID_EVENT) CaseReturnString(CL_INVALID_OPERATION) CaseReturnString(CL_INVALID_GL_OBJECT) CaseReturnString(CL_INVALID_BUFFER_SIZE)[.___。] CaseReturnString(CL_INVALID_BUFFER_SIZE)[.___。 (CL_INVALID_GLOBAL_WORK_SIZE) CaseReturnString(CL_INVALID_PROPERTY) CaseReturnString(CL_INVALID_IMAGE_DESCRIPTOR) CaseReturnString(CL_INVALID_COMPILER_OPTIONS)[.____。 CaseReturnString(CL_INVALID_LINKER_OPTIONS) CaseReturnString(CL_INVALID_DEVICE_PARTITION_COUNT) デフォルト:「不明なOpenCLエラーコード」を返します; } }