@@ -667,7 +667,6 @@ static cl_mem allocateZeroCopyBuffer(const KernelEnv& rEnv,
667
667
static Pix* mapOutputCLBuffer (const KernelEnv& rEnv, cl_mem clbuffer, Pix* pixd,
668
668
Pix* pixs, int elements, cl_mem_flags flags,
669
669
bool memcopy = false , bool sync = true ) {
670
- PROCNAME (" mapOutputCLBuffer" );
671
670
if (!pixd) {
672
671
if (memcopy) {
673
672
if ((pixd = pixCreateTemplate (pixs)) == nullptr )
@@ -891,35 +890,33 @@ int OpenclDevice::WriteBinaryToFile(const char* fileName, const char* birary,
891
890
892
891
return 1 ;
893
892
}
893
+
894
894
int OpenclDevice::GeneratBinFromKernelSource (cl_program program,
895
895
const char * clFileName) {
896
896
unsigned int i = 0 ;
897
897
cl_int clStatus;
898
- size_t * binarySizes;
899
898
cl_uint numDevices;
900
- cl_device_id * mpArryDevsID;
901
899
char * str = nullptr ;
902
900
903
901
clStatus = clGetProgramInfo (program, CL_PROGRAM_NUM_DEVICES,
904
902
sizeof (numDevices), &numDevices, nullptr );
905
903
CHECK_OPENCL (clStatus, " clGetProgramInfo" );
906
904
907
- mpArryDevsID = (cl_device_id *)malloc (sizeof (cl_device_id ) * numDevices);
908
- if (mpArryDevsID == nullptr ) {
909
- return 0 ;
910
- }
905
+ std::vector<cl_device_id > mpArryDevsID (numDevices);
906
+
911
907
/* grab the handles to all of the devices in the program. */
912
908
clStatus = clGetProgramInfo (program, CL_PROGRAM_DEVICES,
913
- sizeof (cl_device_id ) * numDevices, mpArryDevsID,
909
+ sizeof (cl_device_id ) * numDevices,
910
+ &mpArryDevsID[0 ],
914
911
nullptr );
915
912
CHECK_OPENCL (clStatus, " clGetProgramInfo" );
916
913
917
914
/* figure out the sizes of each of the binaries. */
918
- binarySizes = ( size_t *) malloc ( sizeof ( size_t ) * numDevices);
915
+ std::vector< size_t > binarySizes ( numDevices);
919
916
920
917
clStatus =
921
918
clGetProgramInfo (program, CL_PROGRAM_BINARY_SIZES,
922
- sizeof (size_t ) * numDevices, binarySizes, nullptr );
919
+ sizeof (size_t ) * numDevices, & binarySizes[ 0 ] , nullptr );
923
920
CHECK_OPENCL (clStatus, " clGetProgramInfo" );
924
921
925
922
/* copy over all of the generated binaries. */
@@ -969,23 +966,15 @@ int OpenclDevice::GeneratBinFromKernelSource(cl_program program,
969
966
free (binaries[i]);
970
967
}
971
968
972
- free (binarySizes);
973
- binarySizes = nullptr ;
974
-
975
- free (mpArryDevsID);
976
- mpArryDevsID = nullptr ;
977
-
978
969
return 1 ;
979
970
}
980
971
981
972
int OpenclDevice::CompileKernelFile (GPUEnv* gpuInfo, const char * buildOption) {
982
973
// PERF_COUNT_START("CompileKernelFile")
983
974
cl_int clStatus = 0 ;
984
- size_t length;
985
- char * buildLog = nullptr ;
986
975
const char * source;
987
976
size_t source_size[1 ];
988
- int b_error, binary_status, binaryExisted, idx;
977
+ int binary_status, binaryExisted, idx;
989
978
cl_uint numDevices;
990
979
FILE *fd, *fd1;
991
980
const char * filename = " kernel.cl" ;
@@ -1010,10 +999,10 @@ int OpenclDevice::CompileKernelFile(GPUEnv* gpuInfo, const char* buildOption) {
1010
999
1011
1000
std::vector<cl_device_id > mpArryDevsID (numDevices);
1012
1001
// PERF_COUNT_SUB("get numDevices")
1013
- b_error = 0 ;
1014
- length = 0 ;
1015
- b_error |= fseek (fd, 0 , SEEK_END) < 0 ;
1016
- b_error |= ( length = ftell (fd)) <= 0 ;
1002
+ bool b_error = fseek (fd, 0 , SEEK_END) < 0 ;
1003
+ long pos = ftell (fd) ;
1004
+ b_error |= (pos <= 0 ) ;
1005
+ size_t length = pos ;
1017
1006
b_error |= fseek (fd, 0 , SEEK_SET) < 0 ;
1018
1007
if (b_error) {
1019
1008
return 0 ;
@@ -1072,6 +1061,7 @@ int OpenclDevice::CompileKernelFile(GPUEnv* gpuInfo, const char* buildOption) {
1072
1061
PERF_COUNT_END
1073
1062
if (clStatus != CL_SUCCESS) {
1074
1063
printf (" BuildProgram error!\n " );
1064
+ size_t length;
1075
1065
if (!gpuInfo->mnIsUserCreated ) {
1076
1066
clStatus = clGetProgramBuildInfo (
1077
1067
gpuInfo->mpArryPrograms [idx], gpuInfo->mpArryDevsID [0 ],
@@ -1085,18 +1075,15 @@ int OpenclDevice::CompileKernelFile(GPUEnv* gpuInfo, const char* buildOption) {
1085
1075
printf (" opencl create build log fail\n " );
1086
1076
return 0 ;
1087
1077
}
1088
- buildLog = (char *)malloc (length);
1089
- if (buildLog == (char *)nullptr ) {
1090
- return 0 ;
1091
- }
1078
+ std::vector<char > buildLog (length);
1092
1079
if (!gpuInfo->mnIsUserCreated ) {
1093
1080
clStatus = clGetProgramBuildInfo (
1094
1081
gpuInfo->mpArryPrograms [idx], gpuInfo->mpArryDevsID [0 ],
1095
- CL_PROGRAM_BUILD_LOG, length, buildLog, &length);
1082
+ CL_PROGRAM_BUILD_LOG, length, & buildLog[ 0 ] , &length);
1096
1083
} else {
1097
1084
clStatus = clGetProgramBuildInfo (gpuInfo->mpArryPrograms [idx],
1098
1085
gpuInfo->mpDevID , CL_PROGRAM_BUILD_LOG,
1099
- length, buildLog, &length);
1086
+ length, & buildLog[ 0 ] , &length);
1100
1087
}
1101
1088
if (clStatus != CL_SUCCESS) {
1102
1089
printf (" opencl program build info fail\n " );
@@ -1105,11 +1092,10 @@ int OpenclDevice::CompileKernelFile(GPUEnv* gpuInfo, const char* buildOption) {
1105
1092
1106
1093
fd1 = fopen (" kernel-build.log" , " w+" );
1107
1094
if (fd1 != nullptr ) {
1108
- fwrite (buildLog, sizeof (char ), length, fd1);
1095
+ fwrite (& buildLog[ 0 ] , sizeof (char ), length, fd1);
1109
1096
fclose (fd1);
1110
1097
}
1111
1098
1112
- free (buildLog);
1113
1099
// PERF_COUNT_SUB("build error log")
1114
1100
return 0 ;
1115
1101
}
0 commit comments