@@ -553,30 +553,30 @@ static ds_status writeProfileToFile(ds_profile* profile,
553
553
554
554
// substitute invalid characters in device name with _
555
555
static void legalizeFileName (char * fileName) {
556
- // printf ("fileName: %s\n", fileName);
556
+ // tprintf ("fileName: %s\n", fileName);
557
557
const char * invalidChars =
558
558
" /\? :*\" ><| " ; // space is valid but can cause headaches
559
559
// for each invalid char
560
560
for (unsigned i = 0 ; i < strlen (invalidChars); i++) {
561
561
char invalidStr[4 ];
562
562
invalidStr[0 ] = invalidChars[i];
563
563
invalidStr[1 ] = ' \0 ' ;
564
- // printf ("eliminating %s\n", invalidStr);
564
+ // tprintf ("eliminating %s\n", invalidStr);
565
565
// char *pos = strstr(fileName, invalidStr);
566
566
// initial ./ is valid for present directory
567
567
// if (*pos == '.') pos++;
568
568
// if (*pos == '/') pos++;
569
569
for (char * pos = strstr (fileName, invalidStr); pos != nullptr ;
570
570
pos = strstr (pos + 1 , invalidStr)) {
571
- // printf ("\tfound: %s, ", pos);
571
+ // tprintf ("\tfound: %s, ", pos);
572
572
pos[0 ] = ' _' ;
573
- // printf ("fileName: %s\n", fileName);
573
+ // tprintf ("fileName: %s\n", fileName);
574
574
}
575
575
}
576
576
}
577
577
578
578
static void populateGPUEnvFromDevice (GPUEnv* gpuInfo, cl_device_id device) {
579
- // printf ("[DS] populateGPUEnvFromDevice\n");
579
+ // tprintf ("[DS] populateGPUEnvFromDevice\n");
580
580
size_t size;
581
581
gpuInfo->mnIsUserCreated = 1 ;
582
582
// device
@@ -713,7 +713,7 @@ int OpenclDevice::initMorphCLAllocations(l_int32 wpl, l_int32 h, Pix* pixs) {
713
713
714
714
int OpenclDevice::InitEnv () {
715
715
// PERF_COUNT_START("OD::InitEnv")
716
- // printf ("[OD] OpenclDevice::InitEnv()\n");
716
+ // tprintf ("[OD] OpenclDevice::InitEnv()\n");
717
717
#ifdef SAL_WIN32
718
718
while (1 ) {
719
719
if (1 == LoadOpencl ()) break ;
@@ -763,7 +763,7 @@ int OpenclDevice::InitOpenclRunEnv_DeviceSelection(int argc) {
763
763
cl_device_id bestDevice = bestDevice_DS.oclDeviceID ;
764
764
// overwrite global static GPUEnv with new device
765
765
if (selectedDeviceIsOpenCL ()) {
766
- // printf ("[DS] InitOpenclRunEnv_DS::Calling populateGPUEnvFromDevice()
766
+ // tprintf ("[DS] InitOpenclRunEnv_DS::Calling populateGPUEnvFromDevice()
767
767
// for selected device\n");
768
768
populateGPUEnvFromDevice (&gpuEnv, bestDevice);
769
769
gpuEnv.mnFileCount = 0 ; // argc;
@@ -772,7 +772,7 @@ int OpenclDevice::InitOpenclRunEnv_DeviceSelection(int argc) {
772
772
CompileKernelFile (&gpuEnv, " " );
773
773
// PERF_COUNT_SUB("CompileKernelFile")
774
774
} else {
775
- // printf ("[DS] InitOpenclRunEnv_DS::Skipping populateGPUEnvFromDevice()
775
+ // tprintf ("[DS] InitOpenclRunEnv_DS::Skipping populateGPUEnvFromDevice()
776
776
// b/c native cpu selected\n");
777
777
}
778
778
isInited = 1 ;
@@ -925,10 +925,10 @@ int OpenclDevice::GeneratBinFromKernelSource(cl_program program,
925
925
sprintf (fileName, " %s-%s.bin" , cl_name, deviceName);
926
926
legalizeFileName (fileName);
927
927
if (!WriteBinaryToFile (fileName, binaries[i], binarySizes[i])) {
928
- printf (" [OD] write binary[%s] failed\n " , fileName);
928
+ tprintf (" [OD] write binary[%s] failed\n " , fileName);
929
929
return 0 ;
930
930
} // else
931
- printf (" [OD] write binary[%s] successfully\n " , fileName);
931
+ tprintf (" [OD] write binary[%s] successfully\n " , fileName);
932
932
}
933
933
}
934
934
@@ -1017,7 +1017,7 @@ int OpenclDevice::CompileKernelFile(GPUEnv* gpuInfo, const char* buildOption) {
1017
1017
1018
1018
// char options[512];
1019
1019
// create a cl program executable for all the devices specified
1020
- // printf ("[OD] BuildProgram.\n");
1020
+ // tprintf ("[OD] BuildProgram.\n");
1021
1021
PERF_COUNT_START (" OD::CompileKernel::clBuildProgram" )
1022
1022
if (!gpuInfo->mnIsUserCreated ) {
1023
1023
clStatus =
@@ -1032,7 +1032,7 @@ int OpenclDevice::CompileKernelFile(GPUEnv* gpuInfo, const char* buildOption) {
1032
1032
}
1033
1033
PERF_COUNT_END
1034
1034
if (clStatus != CL_SUCCESS) {
1035
- printf (" BuildProgram error!\n " );
1035
+ tprintf (" BuildProgram error!\n " );
1036
1036
size_t length;
1037
1037
if (!gpuInfo->mnIsUserCreated ) {
1038
1038
clStatus = clGetProgramBuildInfo (
@@ -1044,7 +1044,7 @@ int OpenclDevice::CompileKernelFile(GPUEnv* gpuInfo, const char* buildOption) {
1044
1044
CL_PROGRAM_BUILD_LOG, 0 , nullptr , &length);
1045
1045
}
1046
1046
if (clStatus != CL_SUCCESS) {
1047
- printf (" opencl create build log fail\n " );
1047
+ tprintf (" opencl create build log fail\n " );
1048
1048
return 0 ;
1049
1049
}
1050
1050
std::vector<char > buildLog (length);
@@ -1058,7 +1058,7 @@ int OpenclDevice::CompileKernelFile(GPUEnv* gpuInfo, const char* buildOption) {
1058
1058
length, &buildLog[0 ], &length);
1059
1059
}
1060
1060
if (clStatus != CL_SUCCESS) {
1061
- printf (" opencl program build info fail\n " );
1061
+ tprintf (" opencl program build info fail\n " );
1062
1062
return 0 ;
1063
1063
}
1064
1064
@@ -1890,7 +1890,7 @@ int OpenclDevice::ThresholdRectToPixOCL(unsigned char* imageData,
1890
1890
clFinish (rEnv.mpkCmdQueue );
1891
1891
PERF_COUNT_SUB (" kernel" )
1892
1892
if (clStatus != 0 ) {
1893
- printf (" Setting return value to -1\n " );
1893
+ tprintf (" Setting return value to -1\n " );
1894
1894
retVal = -1 ;
1895
1895
}
1896
1896
/* map results back from gpu */
@@ -1954,7 +1954,7 @@ static void populateTessScoreEvaluationInputData(
1954
1954
for (int i = 0 ; i < numLines; i++) {
1955
1955
int lineWidth = rand () % maxLineWidth;
1956
1956
int vertLinePos = lineWidth + rand () % (width - 2 * lineWidth);
1957
- // printf ("[PI] VerticalLine @ %i (w=%i)\n", vertLinePos, lineWidth);
1957
+ // tprintf ("[PI] VerticalLine @ %i (w=%i)\n", vertLinePos, lineWidth);
1958
1958
for (int row = vertLinePos - lineWidth / 2 ;
1959
1959
row < vertLinePos + lineWidth / 2 ; row++) {
1960
1960
for (int col = 0 ; col < height; col++) {
@@ -1970,13 +1970,13 @@ static void populateTessScoreEvaluationInputData(
1970
1970
for (int i = 0 ; i < numLines; i++) {
1971
1971
int lineWidth = rand () % maxLineWidth;
1972
1972
int horLinePos = lineWidth + rand () % (height - 2 * lineWidth);
1973
- // printf ("[PI] HorizontalLine @ %i (w=%i)\n", horLinePos, lineWidth);
1973
+ // tprintf ("[PI] HorizontalLine @ %i (w=%i)\n", horLinePos, lineWidth);
1974
1974
for (int row = 0 ; row < width; row++) {
1975
1975
for (int col = horLinePos - lineWidth / 2 ;
1976
1976
col < horLinePos + lineWidth / 2 ;
1977
1977
col++) { // for (int row = vertLinePos-lineWidth/2; row <
1978
1978
// vertLinePos+lineWidth/2; row++) {
1979
- // printf ("[PI] HoizLine pix @ (%3i, %3i)\n", row, col);
1979
+ // tprintf ("[PI] HoizLine pix @ (%3i, %3i)\n", row, col);
1980
1980
// imageData4[row*width+col] = pixelBlack;
1981
1981
imageData4[row * width + col][0 ] = pixelBlack[0 ];
1982
1982
imageData4[row * width + col][1 ] = pixelBlack[1 ];
@@ -1993,10 +1993,10 @@ static void populateTessScoreEvaluationInputData(
1993
1993
int lineWidth = rand () % maxLineWidth;
1994
1994
int col = lineWidth + rand () % (width - 2 * lineWidth);
1995
1995
int row = lineWidth + rand () % (height - 2 * lineWidth);
1996
- // printf ("[PI] Spot[%i/%i] @ (%3i, %3i)\n", i, numSpots, row, col );
1996
+ // tprintf ("[PI] Spot[%i/%i] @ (%3i, %3i)\n", i, numSpots, row, col );
1997
1997
for (int r = row - lineWidth / 2 ; r < row + lineWidth / 2 ; r++) {
1998
1998
for (int c = col - lineWidth / 2 ; c < col + lineWidth / 2 ; c++) {
1999
- // printf ("[PI] \tSpot[%i/%i] @ (%3i, %3i)\n", i, numSpots, r, c );
1999
+ // tprintf ("[PI] \tSpot[%i/%i] @ (%3i, %3i)\n", i, numSpots, r, c );
2000
2000
// imageData4[row*width+col] = pixelBlack;
2001
2001
imageData4[r * width + c][0 ] = pixelBlack[0 ];
2002
2002
imageData4[r * width + c][1 ] = pixelBlack[1 ];
@@ -2444,17 +2444,17 @@ static ds_status releaseScore(TessDeviceScore* score) {
2444
2444
static ds_status evaluateScoreForDevice (ds_device* device, void * inputData) {
2445
2445
// overwrite statuc gpuEnv w/ current device
2446
2446
// so native opencl calls can be used; they use static gpuEnv
2447
- printf (" \n [DS] Device: \" %s\" (%s) evaluation...\n " , device->oclDeviceName ,
2447
+ tprintf (" \n [DS] Device: \" %s\" (%s) evaluation...\n " , device->oclDeviceName ,
2448
2448
device->type == DS_DEVICE_OPENCL_DEVICE ? " OpenCL" : " Native" );
2449
2449
GPUEnv* env = nullptr ;
2450
2450
if (device->type == DS_DEVICE_OPENCL_DEVICE) {
2451
2451
env = &OpenclDevice::gpuEnv;
2452
2452
memset (env, 0 , sizeof (*env));
2453
- // printf ("[DS] populating tmp GPUEnv from device\n");
2453
+ // tprintf ("[DS] populating tmp GPUEnv from device\n");
2454
2454
populateGPUEnvFromDevice (env, device->oclDeviceID );
2455
2455
env->mnFileCount = 0 ; // argc;
2456
2456
env->mnKernelCount = 0UL ;
2457
- // printf ("[DS] compiling kernels for tmp GPUEnv\n");
2457
+ // tprintf ("[DS] compiling kernels for tmp GPUEnv\n");
2458
2458
OpenclDevice::CompileKernelFile (env, " " );
2459
2459
}
2460
2460
@@ -2490,17 +2490,17 @@ static ds_status evaluateScoreForDevice(ds_device* device, void* inputData) {
2490
2490
device->score = new TessDeviceScore;
2491
2491
device->score ->time = weightedTime;
2492
2492
2493
- printf (" [DS] Device: \" %s\" (%s) evaluated\n " , device->oclDeviceName ,
2493
+ tprintf (" [DS] Device: \" %s\" (%s) evaluated\n " , device->oclDeviceName ,
2494
2494
device->type == DS_DEVICE_OPENCL_DEVICE ? " OpenCL" : " Native" );
2495
- printf (" [DS]%25s: %f (w=%.1f)\n " , " composeRGBPixel" , composeRGBPixelTime,
2495
+ tprintf (" [DS]%25s: %f (w=%.1f)\n " , " composeRGBPixel" , composeRGBPixelTime,
2496
2496
composeRGBPixelWeight);
2497
- printf (" [DS]%25s: %f (w=%.1f)\n " , " HistogramRect" , histogramRectTime,
2497
+ tprintf (" [DS]%25s: %f (w=%.1f)\n " , " HistogramRect" , histogramRectTime,
2498
2498
histogramRectWeight);
2499
- printf (" [DS]%25s: %f (w=%.1f)\n " , " ThresholdRectToPix" ,
2499
+ tprintf (" [DS]%25s: %f (w=%.1f)\n " , " ThresholdRectToPix" ,
2500
2500
thresholdRectToPixTime, thresholdRectToPixWeight);
2501
- printf (" [DS]%25s: %f (w=%.1f)\n " , " getLineMasksMorph" , getLineMasksMorphTime,
2501
+ tprintf (" [DS]%25s: %f (w=%.1f)\n " , " getLineMasksMorph" , getLineMasksMorphTime,
2502
2502
getLineMasksMorphWeight);
2503
- printf (" [DS]%25s: %f\n " , " Score" , device->score ->time );
2503
+ tprintf (" [DS]%25s: %f\n " , " Score" , device->score ->time );
2504
2504
return DS_SUCCESS;
2505
2505
}
2506
2506
@@ -2522,7 +2522,7 @@ ds_device OpenclDevice::getDeviceSelection() {
2522
2522
status = readProfileFromFile (profile, deserializeScore, fileName);
2523
2523
if (status != DS_SUCCESS) {
2524
2524
// need to run evaluation
2525
- printf (" [DS] Profile file not available (%s); performing profiling.\n " ,
2525
+ tprintf (" [DS] Profile file not available (%s); performing profiling.\n " ,
2526
2526
fileName);
2527
2527
2528
2528
// create input data
@@ -2539,21 +2539,21 @@ ds_device OpenclDevice::getDeviceSelection() {
2539
2539
status = writeProfileToFile (profile, serializeScore, fileName);
2540
2540
PERF_COUNT_SUB (" writeProfileToFile" )
2541
2541
if (status == DS_SUCCESS) {
2542
- printf (" [DS] Scores written to file (%s).\n " , fileName);
2542
+ tprintf (" [DS] Scores written to file (%s).\n " , fileName);
2543
2543
} else {
2544
- printf (
2544
+ tprintf (
2545
2545
" [DS] Error saving scores to file (%s); scores not written to "
2546
2546
" file.\n " ,
2547
2547
fileName);
2548
2548
}
2549
2549
} else {
2550
- printf (
2550
+ tprintf (
2551
2551
" [DS] Unable to evaluate performance; scores not written to "
2552
2552
" file.\n " );
2553
2553
}
2554
2554
} else {
2555
2555
PERF_COUNT_SUB (" readProfileFromFile" )
2556
- printf (" [DS] Profile read from file (%s).\n " , fileName);
2556
+ tprintf (" [DS] Profile read from file (%s).\n " , fileName);
2557
2557
}
2558
2558
2559
2559
// we now have device scores either from file or evaluation
@@ -2566,14 +2566,14 @@ ds_device OpenclDevice::getDeviceSelection() {
2566
2566
TessDeviceScore score = *device.score ;
2567
2567
2568
2568
float time = score.time ;
2569
- printf (" [DS] Device[%u] %i:%s score is %f\n " , d + 1 , device.type ,
2569
+ tprintf (" [DS] Device[%u] %i:%s score is %f\n " , d + 1 , device.type ,
2570
2570
device.oclDeviceName , time );
2571
2571
if (time < bestTime) {
2572
2572
bestTime = time ;
2573
2573
bestDeviceIdx = d;
2574
2574
}
2575
2575
}
2576
- printf (" [DS] Selected Device[%i]: \" %s\" (%s)\n " , bestDeviceIdx + 1 ,
2576
+ tprintf (" [DS] Selected Device[%i]: \" %s\" (%s)\n " , bestDeviceIdx + 1 ,
2577
2577
profile->devices [bestDeviceIdx].oclDeviceName ,
2578
2578
profile->devices [bestDeviceIdx].type == DS_DEVICE_OPENCL_DEVICE
2579
2579
? " OpenCL"
@@ -2586,22 +2586,22 @@ ds_device OpenclDevice::getDeviceSelection() {
2586
2586
if (overrideDeviceStr != nullptr ) {
2587
2587
int overrideDeviceIdx = atoi (overrideDeviceStr);
2588
2588
if (overrideDeviceIdx > 0 && overrideDeviceIdx <= profile->numDevices ) {
2589
- printf (
2589
+ tprintf (
2590
2590
" [DS] Overriding Device Selection (TESSERACT_OPENCL_DEVICE=%s, "
2591
2591
" %i)\n " ,
2592
2592
overrideDeviceStr, overrideDeviceIdx);
2593
2593
bestDeviceIdx = overrideDeviceIdx - 1 ;
2594
2594
overridden = true ;
2595
2595
} else {
2596
- printf (
2596
+ tprintf (
2597
2597
" [DS] Ignoring invalid TESSERACT_OPENCL_DEVICE=%s ([1,%i] are "
2598
2598
" valid devices).\n " ,
2599
2599
overrideDeviceStr, profile->numDevices );
2600
2600
}
2601
2601
}
2602
2602
2603
2603
if (overridden) {
2604
- printf (" [DS] Overridden Device[%i]: \" %s\" (%s)\n " , bestDeviceIdx + 1 ,
2604
+ tprintf (" [DS] Overridden Device[%i]: \" %s\" (%s)\n " , bestDeviceIdx + 1 ,
2605
2605
profile->devices [bestDeviceIdx].oclDeviceName ,
2606
2606
profile->devices [bestDeviceIdx].type == DS_DEVICE_OPENCL_DEVICE
2607
2607
? " OpenCL"
@@ -2612,7 +2612,7 @@ ds_device OpenclDevice::getDeviceSelection() {
2612
2612
releaseDSProfile (profile, releaseScore);
2613
2613
} else {
2614
2614
// opencl isn't available at runtime, select native cpu device
2615
- printf (" [DS] OpenCL runtime not available.\n " );
2615
+ tprintf (" [DS] OpenCL runtime not available.\n " );
2616
2616
selectedDevice.type = DS_DEVICE_NATIVE_CPU;
2617
2617
selectedDevice.oclDeviceName = " (null)" ;
2618
2618
selectedDevice.score = nullptr ;
0 commit comments