@@ -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) {
0 commit comments