Skip to content
This repository was archived by the owner on Feb 16, 2019. It is now read-only.

Commit 397b303

Browse files
authored
Merge pull request #18 from lcskrishna/non-amd-openclport
Added support for OpenCL 1.2 build
2 parents c81a919 + 88a4e8c commit 397b303

File tree

5 files changed

+60
-6
lines changed

5 files changed

+60
-6
lines changed

openvx/ago/ago_drama_alloc.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ static int agoOptimizeDramaAllocGpuResources(AgoGraph * graph)
8484
// create command queue: for now use device#0 -- TBD: this needs to be changed in future
8585
cl_int err = -1;
8686
graph->opencl_device = context->opencl_device_list[0];
87+
#if defined(CL_VERSION_2_0)
8788
graph->opencl_cmdq = clCreateCommandQueueWithProperties(context->opencl_context, graph->opencl_device, NULL, &err);
89+
#else
90+
graph->opencl_cmdq = clCreateCommandQueue(context->opencl_context, graph->opencl_device, 0, &err);
91+
#endif
8892
if (err) {
8993
agoAddLogEntry(&graph->ref, VX_FAILURE, "ERROR: clCreateCommandQueueWithProperties(%p,%p,0,*) => %d\n", context->opencl_context, graph->opencl_device, err);
9094
return -1;

openvx/ago/ago_internal.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,13 @@ THE SOFTWARE.
144144
#define DATA_OPENCL_ARRAY_OFFSET 16 // first 16 bytes of array buffer will be used for numitems
145145
// opencl configuration flags
146146
#define CONFIG_OPENCL_USE_1_2 0x0001 // use OpenCL 1.2
147+
#if defined(CL_VERSION_2_0)
147148
#define CONFIG_OPENCL_SVM_MASK 0x00F0 // OpenCL SVM flags mask
148149
#define CONFIG_OPENCL_SVM_ENABLE 0x0010 // use OpenCL SVM
149150
#define CONFIG_OPENCL_SVM_AS_FGS 0x0020 // use OpenCL SVM as fine grain system
150151
#define CONFIG_OPENCL_SVM_AS_CLMEM 0x0040 // use OpenCL SVM as cl_mem
151152
#endif
153+
#endif
152154
// opencl image fixed byte offset
153155
#define OPENCL_IMAGE_FIXED_OFFSET 256
154156

@@ -393,9 +395,11 @@ struct AgoData {
393395
#if ENABLE_OPENCL
394396
cl_mem opencl_buffer;
395397
cl_mem opencl_buffer_allocated;
396-
#endif
398+
#if defined(CL_VERSION_2_0)
397399
vx_uint8 * opencl_svm_buffer;
398400
vx_uint8 * opencl_svm_buffer_allocated;
401+
#endif
402+
#endif
399403
vx_uint32 opencl_buffer_offset;
400404
vx_bool isVirtual;
401405
vx_bool isDelayed;
@@ -669,7 +673,9 @@ struct AgoContext {
669673
cl_command_queue opencl_cmdq;
670674
vx_uint32 opencl_config_flags;
671675
char opencl_extensions[1024];
676+
#if defined(CL_VERSION_2_0)
672677
cl_device_svm_capabilities opencl_svmcaps;
678+
#endif
673679
cl_uint opencl_num_devices;
674680
cl_device_id opencl_device_list[16];
675681
char opencl_build_options[256];

openvx/ago/ago_util.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2907,8 +2907,11 @@ AgoData::AgoData()
29072907
buffer{ nullptr }, buffer_allocated{ nullptr }, reserved{ nullptr }, reserved_allocated{ nullptr }, buffer_sync_flags{ 0 },
29082908
#if ENABLE_OPENCL
29092909
opencl_buffer{ nullptr }, opencl_buffer_allocated{ nullptr },
2910+
#if defined(CL_VERSION_2_0)
2911+
opencl_svm_buffer{ nullptr }, opencl_svm_buffer_allocated{ nullptr },
29102912
#endif
2911-
opencl_svm_buffer{ nullptr }, opencl_svm_buffer_allocated{ nullptr }, opencl_buffer_offset{ 0 },
2913+
#endif
2914+
opencl_buffer_offset{ 0 },
29122915
isVirtual{ vx_false_e }, isDelayed{ vx_false_e }, isNotFullyConfigured{ vx_false_e }, isInitialized{ vx_false_e }, siblingIndex{ 0 },
29132916
numChildren{ 0 }, children{ nullptr }, parent{ nullptr }, inputUsageCount{ 0 }, outputUsageCount{ 0 }, inoutUsageCount{ 0 },
29142917
nextMapId{ 0 }, hierarchical_level{ 0 }, hierarchical_life_start{ 0 }, hierarchical_life_end{ 0 }, ownerOfUserBufferOpenCL{ nullptr }
@@ -3069,7 +3072,10 @@ AgoContext::AgoContext()
30693072
num_active_modules{ 0 }, num_active_references{ 0 }, callback_log{ nullptr }, callback_reentrant{ vx_false_e },
30703073
thread_config{ CONFIG_THREAD_DEFAULT }, importing_module_index_plus1{ 0 }, graph_garbage_data{ nullptr }, graph_garbage_node{ nullptr }, graph_garbage_list{ nullptr }
30713074
#if ENABLE_OPENCL
3072-
, opencl_context_imported{ false }, opencl_context{ nullptr }, opencl_cmdq{ nullptr }, opencl_config_flags{ 0 }, opencl_svmcaps{ 0 }, opencl_num_devices{ 0 }, isAmdMediaOpsSupported{ true }
3075+
#if defined(CL_VERSION_2_0)
3076+
, opencl_svmcaps{ 0 }
3077+
#endif
3078+
, opencl_context_imported{ false }, opencl_context{ nullptr }, opencl_cmdq{ nullptr }, opencl_config_flags{ 0 }, opencl_num_devices{ 0 }, isAmdMediaOpsSupported{ true }
30733079
#endif
30743080
{
30753081
memset(&kernelList, 0, sizeof(kernelList));

openvx/ago/ago_util_opencl.cpp

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ int agoGpuOclReleaseData(AgoData * data)
115115
clReleaseMemObject(data->opencl_buffer_allocated);
116116
data->opencl_buffer_allocated = NULL;
117117
}
118+
#if defined(CL_VERSION_2_0)
118119
if (data->opencl_svm_buffer_allocated) {
119120
if (data->ref.context->opencl_config_flags & CONFIG_OPENCL_SVM_AS_FGS) {
120121
agoReleaseMemory(data->opencl_svm_buffer_allocated);
@@ -124,8 +125,9 @@ int agoGpuOclReleaseData(AgoData * data)
124125
}
125126
data->opencl_svm_buffer_allocated = NULL;
126127
}
127-
data->opencl_buffer = NULL;
128128
data->opencl_svm_buffer = NULL;
129+
#endif
130+
data->opencl_buffer = NULL;
129131
data->opencl_buffer_offset = 0;
130132
return 0;
131133
}
@@ -229,19 +231,25 @@ int agoGpuOclCreateContext(AgoContext * context, cl_context opencl_context)
229231
return -1;
230232
}
231233
context->isAmdMediaOpsSupported = strstr(extensions, "cl_amd_media_ops") ? true : false;
234+
#if defined(CL_VERSION_2_0)
232235
agoAddLogEntry(&context->ref, VX_SUCCESS, "OK: OpenVX using GPU device#%d (%s) [%s] [SvmCaps " VX_FMT_SIZE " %d]\n", device_id, deviceName, deviceVersion, context->opencl_svmcaps, context->opencl_config_flags);
236+
#else
237+
agoAddLogEntry(&context->ref, VX_SUCCESS, "OK: OpenVX using GPU device#%d (%s) [%s] [%d]\n", device_id, deviceName, deviceVersion, context->opencl_config_flags);
238+
#endif
233239
memset(context->opencl_extensions, 0, sizeof(context->opencl_extensions));
234240
status = clGetDeviceInfo(context->opencl_device_list[device_id], CL_DEVICE_EXTENSIONS, sizeof(context->opencl_extensions), context->opencl_extensions, NULL);
235241
if (status) {
236242
agoAddLogEntry(&context->ref, VX_FAILURE, "ERROR: clGetDeviceInfo(%p,CL_DEVICE_EXTENSIONS) => %d\n", context->opencl_device_list[device_id], status);
237243
return -1;
238244
}
245+
#if defined(CL_VERSION_2_0)
239246
context->opencl_svmcaps = 0;
240247
status = clGetDeviceInfo(context->opencl_device_list[device_id], CL_DEVICE_SVM_CAPABILITIES, sizeof(context->opencl_svmcaps), &context->opencl_svmcaps, NULL);
241248
if (status) {
242249
agoAddLogEntry(&context->ref, VX_FAILURE, "ERROR: clGetDeviceInfo(%p,CL_DEVICE_SVM_CAPABILITIES) => %d\n", context->opencl_device_list[device_id], status);
243250
return -1;
244251
}
252+
#endif
245253
// get default OpenCL build options
246254
strcpy(context->opencl_build_options, (context->opencl_config_flags & CONFIG_OPENCL_USE_1_2) ? "-cl-std=CL1.2" : "-cl-std=CL2.0");
247255
// override build options with environment variable
@@ -254,6 +262,7 @@ int agoGpuOclCreateContext(AgoContext * context, cl_context opencl_context)
254262
}
255263

256264
// decide SVM features
265+
#if defined(CL_VERSION_2_0)
257266
if (context->opencl_svmcaps & (CL_DEVICE_SVM_FINE_GRAIN_BUFFER | CL_DEVICE_SVM_FINE_GRAIN_SYSTEM)) {
258267
context->opencl_config_flags &= ~CONFIG_OPENCL_SVM_MASK;
259268
if (context->attr_affinity.device_info & AGO_TARGET_AFFINITY_GPU_INFO_SVM_MASK) {
@@ -280,8 +289,13 @@ int agoGpuOclCreateContext(AgoContext * context, cl_context opencl_context)
280289
}
281290
}
282291
}
292+
#endif
283293
// create command queue for buffer sync
294+
#if defined(CL_VERSION_2_0)
284295
context->opencl_cmdq = clCreateCommandQueueWithProperties(context->opencl_context, context->opencl_device_list[device_id], NULL, &status);
296+
#else
297+
context->opencl_cmdq = clCreateCommandQueue(context->opencl_context, context->opencl_device_list[device_id], 0, &status);
298+
#endif
285299
if (status) {
286300
agoAddLogEntry(&context->ref, VX_FAILURE, "ERROR: clCreateCommandQueueWithProperties(%p,%p,0,*) => %d\n", context->opencl_context, context->opencl_device_list[device_id], status);
287301
return -1;
@@ -302,6 +316,7 @@ int agoGpuOclAllocBuffer(AgoData * data)
302316
AgoData * dataMaster = data->u.img.roiMasterImage ? data->u.img.roiMasterImage : data; // to handle image ROI
303317
if (!dataMaster->opencl_buffer && !dataMaster->u.img.enableUserBufferOpenCL && !(dataMaster->import_type == VX_MEMORY_TYPE_OPENCL)) {
304318
cl_int err = CL_SUCCESS;
319+
#if defined(CL_VERSION_2_0)
305320
if (!dataMaster->buffer && !dataMaster->u.img.isUniform) {
306321
if (context->opencl_config_flags & CONFIG_OPENCL_SVM_ENABLE) {
307322
if (context->opencl_config_flags & CONFIG_OPENCL_SVM_AS_FGS) {
@@ -330,7 +345,9 @@ int agoGpuOclAllocBuffer(AgoData * data)
330345
dataMaster->opencl_buffer = dataMaster->opencl_buffer_allocated = clCreateBuffer(context->opencl_context, CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR, dataMaster->size + dataMaster->opencl_buffer_offset, dataMaster->opencl_svm_buffer_allocated, &err);
331346
}
332347
}
333-
else {
348+
else
349+
#endif
350+
{
334351
// allocate normal opencl_buffer
335352
dataMaster->opencl_buffer = dataMaster->opencl_buffer_allocated = clCreateBuffer(context->opencl_context, CL_MEM_READ_WRITE, dataMaster->size + dataMaster->opencl_buffer_offset, NULL, &err);
336353
}
@@ -357,13 +374,16 @@ int agoGpuOclAllocBuffer(AgoData * data)
357374
if (data != dataMaster) {
358375
// special handling for image ROI
359376
data->opencl_buffer = dataMaster->opencl_buffer;
377+
#if defined(CL_VERSION_2_0)
360378
data->opencl_svm_buffer = dataMaster->opencl_svm_buffer;
379+
#endif
361380
}
362381
}
363382
else if (data->ref.type == VX_TYPE_ARRAY || data->ref.type == AGO_TYPE_CANNY_STACK) {
364383
if (!data->opencl_buffer) {
365384
data->opencl_buffer_offset = DATA_OPENCL_ARRAY_OFFSET; // first few bytes reserved for numitems/stacktop
366385
cl_int err = CL_SUCCESS;
386+
#if defined(CL_VERSION_2_0)
367387
if (!data->buffer) {
368388
if (context->opencl_config_flags & CONFIG_OPENCL_SVM_ENABLE) {
369389
if (context->opencl_config_flags & CONFIG_OPENCL_SVM_AS_FGS) {
@@ -395,7 +415,9 @@ int agoGpuOclAllocBuffer(AgoData * data)
395415
data->opencl_buffer = data->opencl_buffer_allocated = clCreateBuffer(context->opencl_context, CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR, data->size + data->opencl_buffer_offset, data->opencl_svm_buffer_allocated, &err);
396416
}
397417
}
398-
else {
418+
else
419+
#endif
420+
{
399421
// normal opencl_buffer allocation
400422
data->opencl_buffer = data->opencl_buffer_allocated = clCreateBuffer(context->opencl_context, CL_MEM_READ_WRITE, data->size + data->opencl_buffer_offset, NULL, &err);
401423
if (data->opencl_buffer) {
@@ -476,7 +498,9 @@ int agoGpuOclAllocBuffer(AgoData * data)
476498
if (data != dataMaster) {
477499
// special handling for tensor ROI
478500
data->opencl_buffer = dataMaster->opencl_buffer;
501+
#if defined(CL_VERSION_2_0)
479502
data->opencl_svm_buffer = dataMaster->opencl_svm_buffer;
503+
#endif
480504
data->opencl_buffer_offset = (vx_uint32)data->u.tensor.offset;
481505
}
482506
}
@@ -579,13 +603,15 @@ int agoGpuOclDataSetBufferAsKernelArg(AgoData * data, cl_kernel opencl_kernel, v
579603
return -1;
580604
}
581605
}
606+
#if defined(CL_VERSION_2_0)
582607
else if (data->opencl_svm_buffer) {
583608
cl_int err = clSetKernelArgSVMPointer(opencl_kernel, (cl_uint)kernelArgIndex, data->opencl_svm_buffer);
584609
if (err) {
585610
agoAddLogEntry(&data->ref, VX_FAILURE, "ERROR: clSetKernelArgSVMPointer(supernode,%d,*,buffer) failed(%d) for group#%d\n", (cl_uint)kernelArgIndex, err, group);
586611
return -1;
587612
}
588613
}
614+
#endif
589615
else if (data->import_type != VX_MEMORY_TYPE_OPENCL && !(data->ref.type == VX_TYPE_IMAGE && data->u.img.enableUserBufferOpenCL)) {
590616
agoAddLogEntry(&data->ref, VX_FAILURE, "ERROR: agoGpuOclDataSetBufferAsKernelArg(supernode,%d) OpenCL buffer not allocated for group#%d\n", (cl_uint)kernelArgIndex, group);
591617
return -1;
@@ -1123,7 +1149,11 @@ static int agoGpuOclDataOutputAtomicSync(AgoGraph * graph, AgoData * data)
11231149
// update number of items
11241150
cl_int err = CL_SUCCESS;
11251151
int64_t stime = agoGetClockCounter();
1152+
#if defined(CL_VERSION_2_0)
11261153
vx_uint32 * pNumItems = (vx_uint32 *)data->opencl_svm_buffer;
1154+
#else
1155+
vx_uint32 * pNumItems = nullptr;
1156+
#endif
11271157
if (data->opencl_buffer) {
11281158
pNumItems = (vx_uint32 *)clEnqueueMapBuffer(opencl_cmdq, data->opencl_buffer, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE, 0, sizeof(vx_uint32), 0, NULL, NULL, &err);
11291159
if (err) {
@@ -1152,7 +1182,11 @@ static int agoGpuOclDataOutputAtomicSync(AgoGraph * graph, AgoData * data)
11521182
// update number of items and reset it for next use
11531183
int64_t stime = agoGetClockCounter();
11541184
cl_int err = CL_SUCCESS;
1185+
#if defined(CL_VERSION_2_0)
11551186
vx_uint8 * stack = data->opencl_svm_buffer;
1187+
#else
1188+
vx_uint8 * stack = nullptr;
1189+
#endif
11561190
if (data->opencl_buffer) {
11571191
stack = (vx_uint8 *)clEnqueueMapBuffer(opencl_cmdq, data->opencl_buffer, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE, 0, sizeof(vx_uint32), 0, NULL, NULL, &err);
11581192
if (err) {

openvx/api/vx_api.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,11 @@ VX_API_ENTRY vx_status VX_API_CALL vxQueryImage(vx_image image_, vx_enum attribu
10201020
*(cl_mem *)ptr = image->opencl_buffer;
10211021
}
10221022
else {
1023+
#if defined(CL_VERSION_2_0)
10231024
*(vx_uint8 **)ptr = image->opencl_svm_buffer;
1025+
#else
1026+
*(vx_uint8 **)ptr = NULL;
1027+
#endif
10241028
}
10251029
status = VX_SUCCESS;
10261030
}

0 commit comments

Comments
 (0)