source = source_str;\r
source_size[0] = strlen( source );\r
\r
-#ifdef __APPLE__\r
- binaryExisted = 0;\r
-#else\r
- binaryExisted = hb_binary_generated(gpu_info->context, filename, &fd);\r
-#endif\r
- if (binaryExisted == 1)\r
+ if ((binaryExisted = hb_binary_generated(gpu_info->context, filename, &fd)) == 1)\r
{\r
- status = clGetContextInfo( gpu_info->context,\r
- CL_CONTEXT_NUM_DEVICES,\r
- sizeof(numDevices),\r
- &numDevices,\r
- NULL );\r
- if( status != CL_SUCCESS )\r
+ status = clGetContextInfo(gpu_info->context,\r
+ CL_CONTEXT_NUM_DEVICES,\r
+ sizeof(numDevices),\r
+ &numDevices,\r
+ NULL);\r
+ if (status != CL_SUCCESS)\r
{\r
- hb_log( "OpenCL: Unable to get the number of devices in context." );\r
+ hb_log("OpenCL: Unable to get the number of devices in context.");\r
return 0;\r
}\r
\r
- devices = (cl_device_id*)malloc( sizeof(cl_device_id) * numDevices );\r
- if( devices == NULL )\r
+ devices = (cl_device_id*)malloc(sizeof(cl_device_id) * numDevices);\r
+ if (devices == NULL)\r
return 0;\r
\r
- b_error = 0;\r
- length = 0;\r
- b_error |= fseek( fd, 0, SEEK_END ) < 0;\r
- b_error |= ( length = ftell( fd ) ) <= 0;\r
- b_error |= fseek( fd, 0, SEEK_SET ) < 0;\r
- if( b_error )\r
+ length = 0;\r
+ b_error = 0;\r
+ b_error |= fseek(fd, 0, SEEK_END) < 0;\r
+ b_error |= (length = ftell(fd)) <= 0;\r
+ b_error |= fseek(fd, 0, SEEK_SET) < 0;\r
+ if (b_error)\r
return 0;\r
\r
- binary = (char*)malloc( length+2 );\r
- if( !binary )\r
+ binary = (char*)calloc(length + 2, sizeof(char));\r
+ if (binary == NULL)\r
return 0;\r
\r
- memset( binary, 0, length+2 );\r
- b_error |= fread( binary, 1, length, fd ) != length;\r
- if( binary[length-1] != '\n' )\r
- binary[length++] = '\n';\r
+ b_error |= fread(binary, 1, length, fd) != length;\r
+#if 0 // this doesn't work under OS X and/or with some non-AMD GPUs\r
+ if (binary[length-1] != '\n')\r
+ binary[length++] = '\n;\r
+#endif\r
+\r
+ if (b_error)\r
+ return 0;\r
\r
- fclose( fd );\r
- fd = NULL;\r
/* grab the handles to all of the devices in the context. */\r
- status = clGetContextInfo( gpu_info->context,\r
- CL_CONTEXT_DEVICES,\r
- sizeof(cl_device_id) * numDevices,\r
- devices,\r
- NULL );\r
-\r
- gpu_info->programs[idx] = clCreateProgramWithBinary( gpu_info->context,\r
- numDevices,\r
- devices,\r
- &length,\r
- (const unsigned char**)&binary,\r
- &binary_status,\r
- &status );\r
-\r
- free( devices );\r
+ status = clGetContextInfo(gpu_info->context,\r
+ CL_CONTEXT_DEVICES,\r
+ sizeof(cl_device_id) * numDevices,\r
+ devices,\r
+ NULL);\r
+\r
+ gpu_info->programs[idx] = clCreateProgramWithBinary(gpu_info->context,\r
+ numDevices,\r
+ devices,\r
+ &length,\r
+ (const unsigned char**)&binary,\r
+ &binary_status,\r
+ &status);\r
+\r
+ fclose(fd);\r
+ free(devices);\r
+ fd = NULL;\r
devices = NULL;\r
}\r
else\r
\r
strcpy( gpu_env.kernelSrcFile[idx], filename );\r
\r
-#ifndef __APPLE__\r
- if (!binaryExisted)\r
+ if (binaryExisted != 1)\r
{\r
hb_generat_bin_from_kernel_source(gpu_env.programs[idx], filename);\r
}\r
-#endif\r
\r
gpu_info->file_count += 1;\r
\r