-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathopencl_common.c
192 lines (181 loc) · 10.5 KB
/
opencl_common.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
// vim:ft=opencl:
/**
* @version 0.1.3 (2011)
* @author Johannes Gilger <[email protected]>
*
* Copyright 2011 Johannes Gilger
*
* This file is part of engine-cuda
*
* engine-cuda is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License or
* any later version.
*
* engine-cuda is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with engine-cuda. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <CL/opencl.h>
#include "opencl_common.h"
#include "common.h"
void transferHostToDevice_PINNED (const unsigned char **input, uint32_t **deviceMem, uint8_t **hostMem, size_t *size) {
}
void transferHostToDevice_ZEROCOPY (const unsigned char **input, uint32_t **deviceMem, uint8_t **hostMem, size_t *size) {
}
void transferHostToDevice_PAGEABLE (const unsigned char **input, uint32_t **deviceMem, uint8_t **hostMem, size_t *size) {
}
void transferDeviceToHost_PINNED (unsigned char **output, uint32_t **deviceMem, uint8_t **hostMemS, uint8_t **hostMemOUT, size_t *size) {
}
void transferDeviceToHost_ZEROCOPY (unsigned char **output, uint32_t **deviceMem, uint8_t **hostMemS, uint8_t **hostMemOUT, size_t *size) {
}
void transferDeviceToHost_PAGEABLE (unsigned char **output, uint32_t **deviceMem, uint8_t **hostMemS, uint8_t **hostMemOUT, size_t *size) {
}
void opencl_device_init(int buffer_size, cl_context *context, cl_command_queue *queue, cl_mem *device_buffer, cl_mem *device_output, uint8_t **host_data, uint64_t **device_data) {
}
void opencl_device_finish(cl_context *context, cl_command_queue *queue, cl_mem *device_buffer, cl_mem *device_output) {
}
char *print_cl_errstring(cl_int err) {
switch (err) {
case CL_SUCCESS: return strdup("Success!");
case CL_DEVICE_NOT_FOUND: return strdup("Device not found.");
case CL_DEVICE_NOT_AVAILABLE: return strdup("Device not available");
case CL_COMPILER_NOT_AVAILABLE: return strdup("Compiler not available");
case CL_MEM_OBJECT_ALLOCATION_FAILURE: return strdup("Memory object allocation failure");
case CL_OUT_OF_RESOURCES: return strdup("Out of resources");
case CL_OUT_OF_HOST_MEMORY: return strdup("Out of host memory");
case CL_PROFILING_INFO_NOT_AVAILABLE: return strdup("Profiling information not available");
case CL_MEM_COPY_OVERLAP: return strdup("Memory copy overlap");
case CL_IMAGE_FORMAT_MISMATCH: return strdup("Image format mismatch");
case CL_IMAGE_FORMAT_NOT_SUPPORTED: return strdup("Image format not supported");
case CL_BUILD_PROGRAM_FAILURE: return strdup("Program build failure");
case CL_MAP_FAILURE: return strdup("Map failure");
case CL_INVALID_VALUE: return strdup("Invalid value");
case CL_INVALID_DEVICE_TYPE: return strdup("Invalid device type");
case CL_INVALID_PLATFORM: return strdup("Invalid platform");
case CL_INVALID_DEVICE: return strdup("Invalid device");
case CL_INVALID_CONTEXT: return strdup("Invalid context");
case CL_INVALID_QUEUE_PROPERTIES: return strdup("Invalid queue properties");
case CL_INVALID_COMMAND_QUEUE: return strdup("Invalid command queue");
case CL_INVALID_HOST_PTR: return strdup("Invalid host pointer");
case CL_INVALID_MEM_OBJECT: return strdup("Invalid memory object");
case CL_INVALID_IMAGE_FORMAT_DESCRIPTOR: return strdup("Invalid image format descriptor");
case CL_INVALID_IMAGE_SIZE: return strdup("Invalid image size");
case CL_INVALID_SAMPLER: return strdup("Invalid sampler");
case CL_INVALID_BINARY: return strdup("Invalid binary");
case CL_INVALID_BUILD_OPTIONS: return strdup("Invalid build options");
case CL_INVALID_PROGRAM: return strdup("Invalid program");
case CL_INVALID_PROGRAM_EXECUTABLE: return strdup("Invalid program executable");
case CL_INVALID_KERNEL_NAME: return strdup("Invalid kernel name");
case CL_INVALID_KERNEL_DEFINITION: return strdup("Invalid kernel definition");
case CL_INVALID_KERNEL: return strdup("Invalid kernel");
case CL_INVALID_ARG_INDEX: return strdup("Invalid argument index");
case CL_INVALID_ARG_VALUE: return strdup("Invalid argument value");
case CL_INVALID_ARG_SIZE: return strdup("Invalid argument size");
case CL_INVALID_KERNEL_ARGS: return strdup("Invalid kernel arguments");
case CL_INVALID_WORK_DIMENSION: return strdup("Invalid work dimension");
case CL_INVALID_WORK_GROUP_SIZE: return strdup("Invalid work group size");
case CL_INVALID_WORK_ITEM_SIZE: return strdup("Invalid work item size");
case CL_INVALID_GLOBAL_OFFSET: return strdup("Invalid global offset");
case CL_INVALID_EVENT_WAIT_LIST: return strdup("Invalid event wait list");
case CL_INVALID_EVENT: return strdup("Invalid event");
case CL_INVALID_OPERATION: return strdup("Invalid operation");
case CL_INVALID_GL_OBJECT: return strdup("Invalid OpenGL object");
case CL_INVALID_BUFFER_SIZE: return strdup("Invalid buffer size");
case CL_INVALID_MIP_LEVEL: return strdup("Invalid mip-map level");
default: return strdup("Unknown");
}
}
void check_opencl_error(cl_int error) {
if (error != CL_SUCCESS) {
fprintf(stdout, "OpenCL error: %s (%d)\n", print_cl_errstring(error), error);
exit(error);
}
}
int timeval_subtract (struct timeval *result, struct timeval *x, struct timeval *y) {
if (x->tv_usec < y->tv_usec) {
int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
y->tv_usec -= 1000000 * nsec;
y->tv_sec += nsec;
}
if (x->tv_usec - y->tv_usec > 1000000) {
int nsec = (x->tv_usec - y->tv_usec) / 1000000;
y->tv_usec += 1000000 * nsec;
y->tv_sec -= nsec;
}
result->tv_sec = x->tv_sec - y->tv_sec;
result->tv_usec = x->tv_usec - y->tv_usec;
return x->tv_sec < y->tv_sec;
}
const char *cl_error_to_str(cl_int e)
{
switch (e) {
case CL_SUCCESS: return "success";
case CL_DEVICE_NOT_FOUND: return "device not found";
case CL_DEVICE_NOT_AVAILABLE: return "device not available";
#if !(defined(CL_PLATFORM_NVIDIA) && CL_PLATFORM_NVIDIA == 0x3001)
case CL_COMPILER_NOT_AVAILABLE: return "device compiler not available";
#endif
case CL_MEM_OBJECT_ALLOCATION_FAILURE: return "mem object allocation failure";
case CL_OUT_OF_RESOURCES: return "out of resources";
case CL_OUT_OF_HOST_MEMORY: return "out of host memory";
case CL_PROFILING_INFO_NOT_AVAILABLE: return "profiling info not available";
case CL_MEM_COPY_OVERLAP: return "mem copy overlap";
case CL_IMAGE_FORMAT_MISMATCH: return "image format mismatch";
case CL_IMAGE_FORMAT_NOT_SUPPORTED: return "image format not supported";
case CL_BUILD_PROGRAM_FAILURE: return "build program failure";
case CL_MAP_FAILURE: return "map failure";
case CL_INVALID_VALUE: return "invalid value";
case CL_INVALID_DEVICE_TYPE: return "invalid device type";
case CL_INVALID_PLATFORM: return "invalid platform";
case CL_INVALID_DEVICE: return "invalid device";
case CL_INVALID_CONTEXT: return "invalid context";
case CL_INVALID_QUEUE_PROPERTIES: return "invalid queue properties";
case CL_INVALID_COMMAND_QUEUE: return "invalid command queue";
case CL_INVALID_HOST_PTR: return "invalid host ptr";
case CL_INVALID_MEM_OBJECT: return "invalid mem object";
case CL_INVALID_IMAGE_FORMAT_DESCRIPTOR: return "invalid image format descriptor";
case CL_INVALID_IMAGE_SIZE: return "invalid image size";
case CL_INVALID_SAMPLER: return "invalid sampler";
case CL_INVALID_BINARY: return "invalid binary";
case CL_INVALID_BUILD_OPTIONS: return "invalid build options";
case CL_INVALID_PROGRAM: return "invalid program";
case CL_INVALID_PROGRAM_EXECUTABLE: return "invalid program executable";
case CL_INVALID_KERNEL_NAME: return "invalid kernel name";
case CL_INVALID_KERNEL_DEFINITION: return "invalid kernel definition";
case CL_INVALID_KERNEL: return "invalid kernel";
case CL_INVALID_ARG_INDEX: return "invalid arg index";
case CL_INVALID_ARG_VALUE: return "invalid arg value";
case CL_INVALID_ARG_SIZE: return "invalid arg size";
case CL_INVALID_KERNEL_ARGS: return "invalid kernel args";
case CL_INVALID_WORK_DIMENSION: return "invalid work dimension";
case CL_INVALID_WORK_GROUP_SIZE: return "invalid work group size";
case CL_INVALID_WORK_ITEM_SIZE: return "invalid work item size";
case CL_INVALID_GLOBAL_OFFSET: return "invalid global offset";
case CL_INVALID_EVENT_WAIT_LIST: return "invalid event wait list";
case CL_INVALID_EVENT: return "invalid event";
case CL_INVALID_OPERATION: return "invalid operation";
case CL_INVALID_GL_OBJECT: return "invalid gl object";
case CL_INVALID_BUFFER_SIZE: return "invalid buffer size";
case CL_INVALID_MIP_LEVEL: return "invalid mip level";
#if defined(cl_khr_gl_sharing) && (cl_khr_gl_sharing >= 1)
case CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR: return "invalid gl sharegroup reference number";
#endif
#ifdef CL_VERSION_1_1
case CL_MISALIGNED_SUB_BUFFER_OFFSET: return "misaligned sub-buffer offset";
case CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST: return "exec status error for events in wait list";
case CL_INVALID_GLOBAL_WORK_SIZE: return "invalid global work size";
#endif
default: return "invalid/unknown error code";
}
}