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 #ifdef __ALTIVEC__
27 #undef bool
28 #undef vector
29 #endif
30 
31 #if defined(__APPLE__) || defined(__MACOSX)
32 # include <OpenCL/cl.h>
33 #else
34 # include <CL/cl.h>
35 #endif
36 
37 #if !defined( NDEBUG )
38 #include <stdio.h> // for printf
39 #endif
40 
41 // On windows 'C' compiler, compiler only understands __inline
42 #if defined( _WIN32 ) && !defined( __cplusplus )
43 #define inline __inline
44 #endif
45 
52 static inline const char*
53 stringifyStatus( const cl_int status )
54 {
55  switch( status )
56  {
57  case CL_INVALID_GLOBAL_WORK_SIZE:
58  return "CL_INVALID_GLOBAL_WORK_SIZE";
59  case CL_INVALID_MIP_LEVEL:
60  return "CL_INVALID_MIP_LEVEL";
61  case CL_INVALID_BUFFER_SIZE:
62  return "CL_INVALID_BUFFER_SIZE";
63  case CL_INVALID_GL_OBJECT:
64  return "CL_INVALID_GL_OBJECT";
65  case CL_INVALID_OPERATION:
66  return "CL_INVALID_OPERATION";
67  case CL_INVALID_EVENT:
68  return "CL_INVALID_EVENT";
69  case CL_INVALID_EVENT_WAIT_LIST:
70  return "CL_INVALID_EVENT_WAIT_LIST";
71  case CL_INVALID_GLOBAL_OFFSET:
72  return "CL_INVALID_GLOBAL_OFFSET";
73  case CL_INVALID_WORK_ITEM_SIZE:
74  return "CL_INVALID_WORK_ITEM_SIZE";
75  case CL_INVALID_WORK_GROUP_SIZE:
76  return "CL_INVALID_WORK_GROUP_SIZE";
77  case CL_INVALID_WORK_DIMENSION:
78  return "CL_INVALID_WORK_DIMENSION";
79  case CL_INVALID_KERNEL_ARGS:
80  return "CL_INVALID_KERNEL_ARGS";
81  case CL_INVALID_ARG_SIZE:
82  return "CL_INVALID_ARG_SIZE";
83  case CL_INVALID_ARG_VALUE:
84  return "CL_INVALID_ARG_VALUE";
85  case CL_INVALID_ARG_INDEX:
86  return "CL_INVALID_ARG_INDEX";
87  case CL_INVALID_KERNEL:
88  return "CL_INVALID_KERNEL";
89  case CL_INVALID_KERNEL_DEFINITION:
90  return "CL_INVALID_KERNEL_DEFINITION";
91  case CL_INVALID_KERNEL_NAME:
92  return "CL_INVALID_KERNEL_NAME";
93  case CL_INVALID_PROGRAM_EXECUTABLE:
94  return "CL_INVALID_PROGRAM_EXECUTABLE";
95  case CL_INVALID_PROGRAM:
96  return "CL_INVALID_PROGRAM";
97  case CL_INVALID_BUILD_OPTIONS:
98  return "CL_INVALID_BUILD_OPTIONS";
99  case CL_INVALID_BINARY:
100  return "CL_INVALID_BINARY";
101  case CL_INVALID_SAMPLER:
102  return "CL_INVALID_SAMPLER";
103  case CL_INVALID_IMAGE_SIZE:
104  return "CL_INVALID_IMAGE_SIZE";
105  case CL_INVALID_IMAGE_FORMAT_DESCRIPTOR:
106  return "CL_INVALID_IMAGE_FORMAT_DESCRIPTOR";
107  case CL_INVALID_MEM_OBJECT:
108  return "CL_INVALID_MEM_OBJECT";
109  case CL_INVALID_HOST_PTR:
110  return "CL_INVALID_HOST_PTR";
111  case CL_INVALID_COMMAND_QUEUE:
112  return "CL_INVALID_COMMAND_QUEUE";
113  case CL_INVALID_QUEUE_PROPERTIES:
114  return "CL_INVALID_QUEUE_PROPERTIES";
115  case CL_INVALID_CONTEXT:
116  return "CL_INVALID_CONTEXT";
117  case CL_INVALID_DEVICE:
118  return "CL_INVALID_DEVICE";
119  case CL_INVALID_PLATFORM:
120  return "CL_INVALID_PLATFORM";
121  case CL_INVALID_DEVICE_TYPE:
122  return "CL_INVALID_DEVICE_TYPE";
123  case CL_INVALID_VALUE:
124  return "CL_INVALID_VALUE";
125  case CL_MAP_FAILURE:
126  return "CL_MAP_FAILURE";
127  case CL_BUILD_PROGRAM_FAILURE:
128  return "CL_BUILD_PROGRAM_FAILURE";
129  case CL_IMAGE_FORMAT_NOT_SUPPORTED:
130  return "CL_IMAGE_FORMAT_NOT_SUPPORTED";
131  case CL_IMAGE_FORMAT_MISMATCH:
132  return "CL_IMAGE_FORMAT_MISMATCH";
133  case CL_MEM_COPY_OVERLAP:
134  return "CL_MEM_COPY_OVERLAP";
135  case CL_PROFILING_INFO_NOT_AVAILABLE:
136  return "CL_PROFILING_INFO_NOT_AVAILABLE";
137  case CL_OUT_OF_HOST_MEMORY:
138  return "CL_OUT_OF_HOST_MEMORY";
139  case CL_OUT_OF_RESOURCES:
140  return "CL_OUT_OF_RESOURCES";
141  case CL_MEM_OBJECT_ALLOCATION_FAILURE:
142  return "CL_MEM_OBJECT_ALLOCATION_FAILURE";
143  case CL_COMPILER_NOT_AVAILABLE:
144  return "CL_COMPILER_NOT_AVAILABLE";
145  case CL_DEVICE_NOT_AVAILABLE:
146  return "CL_DEVICE_NOT_AVAILABLE";
147  case CL_DEVICE_NOT_FOUND:
148  return "CL_DEVICE_NOT_FOUND";
149  case CL_SUCCESS:
150  return "CL_SUCCESS";
151  default:
152  return "Unrecognized status code";
153  break;
154  }
155 }
156 
162 static inline cl_int
163 clSPARSE_V( cl_int res, const char* msg, const char* file, size_t lineno )
164 {
165  switch( res )
166  {
167  case CL_SUCCESS:
168  break;
169  default:
170  {
171 #if !defined( NDEBUG )
172 #if defined( _WIN32 )
173  printf( "[%s:%Iu]\nCLSPARSE_V( %s ) - %s", file, lineno, stringifyStatus( res ), msg );
174 #else
175  printf( "[%s:%zu]\nCLSPARSE_V( %s ) - %s", file, lineno, stringifyStatus( res ), msg );
176 #endif
177 #endif
178  }
179  }
180 
181  return res;
182 }
183 
187 #define CLSPARSE_V( _status, _message ) clSPARSE_V( _status, _message, __FILE__, __LINE__ )
188 
189 #endif