clSPARSE  v0.10.0.0
a software library containing Sparse functions written in OpenCL
clSPARSE-error.h
Go to the documentation of this file.
1 /* ************************************************************************
2  * Copyright 2015 Advanced Micro Devices, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  * ************************************************************************ */
16 
22 #pragma once
23 #ifndef _CLSPARSE_ERROR_H_
24 #define _CLSPARSE_ERROR_H_
25 
26 #if defined(__APPLE__) || defined(__MACOSX)
27 # include <OpenCL/cl.h>
28 #else
29 # include <CL/cl.h>
30 #endif
31 
32 #if !defined( NDEBUG )
33 #include <stdio.h> // for printf
34 #endif
35 
36 // On windows 'C' compiler, compiler only understands __inline
37 #if defined( _WIN32 ) && !defined( __cplusplus )
38 #define inline __inline
39 #endif
40 
47 static inline const char*
48 stringifyStatus( const cl_int status )
49 {
50  switch( status )
51  {
52  case CL_INVALID_GLOBAL_WORK_SIZE:
53  return "CL_INVALID_GLOBAL_WORK_SIZE";
54  case CL_INVALID_MIP_LEVEL:
55  return "CL_INVALID_MIP_LEVEL";
56  case CL_INVALID_BUFFER_SIZE:
57  return "CL_INVALID_BUFFER_SIZE";
58  case CL_INVALID_GL_OBJECT:
59  return "CL_INVALID_GL_OBJECT";
60  case CL_INVALID_OPERATION:
61  return "CL_INVALID_OPERATION";
62  case CL_INVALID_EVENT:
63  return "CL_INVALID_EVENT";
64  case CL_INVALID_EVENT_WAIT_LIST:
65  return "CL_INVALID_EVENT_WAIT_LIST";
66  case CL_INVALID_GLOBAL_OFFSET:
67  return "CL_INVALID_GLOBAL_OFFSET";
68  case CL_INVALID_WORK_ITEM_SIZE:
69  return "CL_INVALID_WORK_ITEM_SIZE";
70  case CL_INVALID_WORK_GROUP_SIZE:
71  return "CL_INVALID_WORK_GROUP_SIZE";
72  case CL_INVALID_WORK_DIMENSION:
73  return "CL_INVALID_WORK_DIMENSION";
74  case CL_INVALID_KERNEL_ARGS:
75  return "CL_INVALID_KERNEL_ARGS";
76  case CL_INVALID_ARG_SIZE:
77  return "CL_INVALID_ARG_SIZE";
78  case CL_INVALID_ARG_VALUE:
79  return "CL_INVALID_ARG_VALUE";
80  case CL_INVALID_ARG_INDEX:
81  return "CL_INVALID_ARG_INDEX";
82  case CL_INVALID_KERNEL:
83  return "CL_INVALID_KERNEL";
84  case CL_INVALID_KERNEL_DEFINITION:
85  return "CL_INVALID_KERNEL_DEFINITION";
86  case CL_INVALID_KERNEL_NAME:
87  return "CL_INVALID_KERNEL_NAME";
88  case CL_INVALID_PROGRAM_EXECUTABLE:
89  return "CL_INVALID_PROGRAM_EXECUTABLE";
90  case CL_INVALID_PROGRAM:
91  return "CL_INVALID_PROGRAM";
92  case CL_INVALID_BUILD_OPTIONS:
93  return "CL_INVALID_BUILD_OPTIONS";
94  case CL_INVALID_BINARY:
95  return "CL_INVALID_BINARY";
96  case CL_INVALID_SAMPLER:
97  return "CL_INVALID_SAMPLER";
98  case CL_INVALID_IMAGE_SIZE:
99  return "CL_INVALID_IMAGE_SIZE";
100  case CL_INVALID_IMAGE_FORMAT_DESCRIPTOR:
101  return "CL_INVALID_IMAGE_FORMAT_DESCRIPTOR";
102  case CL_INVALID_MEM_OBJECT:
103  return "CL_INVALID_MEM_OBJECT";
104  case CL_INVALID_HOST_PTR:
105  return "CL_INVALID_HOST_PTR";
106  case CL_INVALID_COMMAND_QUEUE:
107  return "CL_INVALID_COMMAND_QUEUE";
108  case CL_INVALID_QUEUE_PROPERTIES:
109  return "CL_INVALID_QUEUE_PROPERTIES";
110  case CL_INVALID_CONTEXT:
111  return "CL_INVALID_CONTEXT";
112  case CL_INVALID_DEVICE:
113  return "CL_INVALID_DEVICE";
114  case CL_INVALID_PLATFORM:
115  return "CL_INVALID_PLATFORM";
116  case CL_INVALID_DEVICE_TYPE:
117  return "CL_INVALID_DEVICE_TYPE";
118  case CL_INVALID_VALUE:
119  return "CL_INVALID_VALUE";
120  case CL_MAP_FAILURE:
121  return "CL_MAP_FAILURE";
122  case CL_BUILD_PROGRAM_FAILURE:
123  return "CL_BUILD_PROGRAM_FAILURE";
124  case CL_IMAGE_FORMAT_NOT_SUPPORTED:
125  return "CL_IMAGE_FORMAT_NOT_SUPPORTED";
126  case CL_IMAGE_FORMAT_MISMATCH:
127  return "CL_IMAGE_FORMAT_MISMATCH";
128  case CL_MEM_COPY_OVERLAP:
129  return "CL_MEM_COPY_OVERLAP";
130  case CL_PROFILING_INFO_NOT_AVAILABLE:
131  return "CL_PROFILING_INFO_NOT_AVAILABLE";
132  case CL_OUT_OF_HOST_MEMORY:
133  return "CL_OUT_OF_HOST_MEMORY";
134  case CL_OUT_OF_RESOURCES:
135  return "CL_OUT_OF_RESOURCES";
136  case CL_MEM_OBJECT_ALLOCATION_FAILURE:
137  return "CL_MEM_OBJECT_ALLOCATION_FAILURE";
138  case CL_COMPILER_NOT_AVAILABLE:
139  return "CL_COMPILER_NOT_AVAILABLE";
140  case CL_DEVICE_NOT_AVAILABLE:
141  return "CL_DEVICE_NOT_AVAILABLE";
142  case CL_DEVICE_NOT_FOUND:
143  return "CL_DEVICE_NOT_FOUND";
144  case CL_SUCCESS:
145  return "CL_SUCCESS";
146  default:
147  return "Unrecognized status code";
148  break;
149  }
150 }
151 
157 static inline cl_int
158 clSPARSE_V( cl_int res, const char* msg, const char* file, size_t lineno )
159 {
160  switch( res )
161  {
162  case CL_SUCCESS:
163  break;
164  default:
165  {
166 #if !defined( NDEBUG )
167 #if defined( _WIN32 )
168  printf( "[%s:%Iu]\nCLSPARSE_V( %s ) - %s", file, lineno, stringifyStatus( res ), msg );
169 #else
170  printf( "[%s:%zu]\nCLSPARSE_V( %s ) - %s", file, lineno, stringifyStatus( res ), msg );
171 #endif
172 #endif
173  }
174  }
175 
176  return res;
177 }
178 
182 #define CLSPARSE_V( _status, _message ) clSPARSE_V( _status, _message, __FILE__, __LINE__ )
183 
184 #endif