@@ -1008,7 +1008,7 @@ int OpenclDevice::CompileKernelFile( GPUEnv *gpuInfo, const char *buildOption )
1008
1008
// PERF_COUNT_START("CompileKernelFile")
1009
1009
cl_int clStatus = 0 ;
1010
1010
size_t length;
1011
- char *buildLog = nullptr , *binary ;
1011
+ char *buildLog = nullptr ;
1012
1012
const char *source;
1013
1013
size_t source_size[1 ];
1014
1014
int b_error, binary_status, binaryExisted, idx;
@@ -1051,15 +1051,10 @@ int OpenclDevice::CompileKernelFile( GPUEnv *gpuInfo, const char *buildOption )
1051
1051
return 0 ;
1052
1052
}
1053
1053
1054
- binary = (char *) malloc ( length + 2 );
1055
- if ( !binary )
1056
- {
1057
- return 0 ;
1058
- }
1059
-
1060
- memset ( binary, 0 , length + 2 );
1061
- b_error |= fread ( binary, 1 , length, fd ) != length;
1054
+ std::vector<uint8_t > binary (length + 2 );
1062
1055
1056
+ memset (&binary[0 ], 0 , length + 2 );
1057
+ b_error |= fread (&binary[0 ], 1 , length, fd) != length;
1063
1058
1064
1059
fclose ( fd );
1065
1060
// PERF_COUNT_SUB("read file")
@@ -1071,12 +1066,12 @@ int OpenclDevice::CompileKernelFile( GPUEnv *gpuInfo, const char *buildOption )
1071
1066
CHECK_OPENCL ( clStatus, " clGetContextInfo" );
1072
1067
// PERF_COUNT_SUB("get devices")
1073
1068
// fprintf(stderr, "[OD] Create kernel from binary\n");
1069
+ const uint8_t *c_binary = &binary[0 ];
1074
1070
gpuInfo->mpArryPrograms [idx] = clCreateProgramWithBinary ( gpuInfo->mpContext ,numDevices,
1075
- mpArryDevsID, &length, ( const unsigned char **) &binary ,
1071
+ mpArryDevsID, &length, &c_binary ,
1076
1072
&binary_status, &clStatus );
1077
1073
CHECK_OPENCL ( clStatus, " clCreateProgramWithBinary" );
1078
1074
// PERF_COUNT_SUB("clCreateProgramWithBinary")
1079
- free ( binary );
1080
1075
free ( mpArryDevsID );
1081
1076
mpArryDevsID = nullptr ;
1082
1077
// PERF_COUNT_SUB("binaryExisted")
0 commit comments