Skip to content

Commit d53254e

Browse files
committed
opencl: Add 'static' attributes for local functions and variables
Signed-off-by: Stefan Weil <[email protected]>
1 parent 8e79297 commit d53254e

File tree

1 file changed

+31
-29
lines changed

1 file changed

+31
-29
lines changed

opencl/openclwrapper.cpp

+31-29
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ static struct tiff_transform tiff_orientation_transforms[] = {
7979

8080
static const l_int32 MAX_PAGES_IN_TIFF_FILE = 3000;
8181

82-
cl_mem pixsCLBuffer, pixdCLBuffer, pixdCLIntermediate; //Morph operations buffers
83-
cl_mem pixThBuffer; //output from thresholdtopix calculation
84-
cl_int clStatus;
85-
KernelEnv rEnv;
82+
static cl_mem pixsCLBuffer, pixdCLBuffer, pixdCLIntermediate; //Morph operations buffers
83+
static cl_mem pixThBuffer; //output from thresholdtopix calculation
84+
static cl_int clStatus;
85+
static KernelEnv rEnv;
8686

8787
#define DS_TAG_VERSION "<version>"
8888
#define DS_TAG_VERSION_END "</version>"
@@ -602,7 +602,7 @@ static ds_status writeProfileToFile(ds_profile *profile,
602602
}
603603

604604
// substitute invalid characters in device name with _
605-
void legalizeFileName( char *fileName) {
605+
static void legalizeFileName( char *fileName) {
606606
//printf("fileName: %s\n", fileName);
607607
const char *invalidChars =
608608
"/\?:*\"><| "; // space is valid but can cause headaches
@@ -625,7 +625,7 @@ void legalizeFileName( char *fileName) {
625625
}
626626
}
627627

628-
void populateGPUEnvFromDevice( GPUEnv *gpuInfo, cl_device_id device ) {
628+
static void populateGPUEnvFromDevice( GPUEnv *gpuInfo, cl_device_id device ) {
629629
//printf("[DS] populateGPUEnvFromDevice\n");
630630
size_t size;
631631
gpuInfo->mnIsUserCreated = 1;
@@ -682,14 +682,17 @@ int OpenclDevice::SetKernelEnv( KernelEnv *envInfo )
682682
return 1;
683683
}
684684

685-
cl_mem allocateZeroCopyBuffer(KernelEnv rEnv, l_uint32 *hostbuffer, size_t nElements, cl_mem_flags flags, cl_int *pStatus)
685+
static cl_mem allocateZeroCopyBuffer(KernelEnv rEnv, l_uint32 *hostbuffer,
686+
size_t nElements, cl_mem_flags flags,
687+
cl_int *pStatus)
686688
{
687689
cl_mem membuffer = clCreateBuffer( rEnv.mpkContext, (cl_mem_flags) (flags),
688690
nElements * sizeof(l_uint32), hostbuffer, pStatus);
689691

690692
return membuffer;
691693
}
692694

695+
static
693696
Pix *mapOutputCLBuffer(KernelEnv rEnv, cl_mem clbuffer, Pix *pixd, Pix *pixs,
694697
int elements, cl_mem_flags flags, bool memcopy = false,
695698
bool sync = true) {
@@ -724,7 +727,9 @@ Pix *mapOutputCLBuffer(KernelEnv rEnv, cl_mem clbuffer, Pix *pixd, Pix *pixs,
724727
return pixd;
725728
}
726729

727-
cl_mem allocateIntBuffer( KernelEnv rEnv, const l_uint32 *_pValues, size_t nElements, cl_int *pStatus , bool sync = false)
730+
static cl_mem allocateIntBuffer(KernelEnv rEnv, const l_uint32 *_pValues,
731+
size_t nElements, cl_int *pStatus,
732+
bool sync = false)
728733
{
729734
cl_mem xValues =
730735
clCreateBuffer(rEnv.mpkContext, (cl_mem_flags)(CL_MEM_READ_WRITE),
@@ -1297,8 +1302,7 @@ PERF_COUNT_END
12971302
}
12981303

12991304
//Morphology Dilate operation for 5x5 structuring element. Invokes the relevant OpenCL kernels
1300-
cl_int
1301-
pixDilateCL_55(l_int32 wpl, l_int32 h)
1305+
static cl_int pixDilateCL_55(l_int32 wpl, l_int32 h)
13021306
{
13031307
size_t globalThreads[2];
13041308
cl_mem pixtemp;
@@ -1365,8 +1369,7 @@ pixDilateCL_55(l_int32 wpl, l_int32 h)
13651369
}
13661370

13671371
//Morphology Erode operation for 5x5 structuring element. Invokes the relevant OpenCL kernels
1368-
cl_int
1369-
pixErodeCL_55(l_int32 wpl, l_int32 h)
1372+
static cl_int pixErodeCL_55(l_int32 wpl, l_int32 h)
13701373
{
13711374
size_t globalThreads[2];
13721375
cl_mem pixtemp;
@@ -1439,7 +1442,7 @@ pixErodeCL_55(l_int32 wpl, l_int32 h)
14391442
}
14401443

14411444
//Morphology Dilate operation. Invokes the relevant OpenCL kernels
1442-
cl_int
1445+
static cl_int
14431446
pixDilateCL(l_int32 hsize, l_int32 vsize, l_int32 wpl, l_int32 h)
14441447
{
14451448
l_int32 xp, yp, xn, yn;
@@ -1546,7 +1549,7 @@ pixDilateCL(l_int32 hsize, l_int32 vsize, l_int32 wpl, l_int32 h)
15461549
}
15471550

15481551
//Morphology Erode operation. Invokes the relevant OpenCL kernels
1549-
cl_int pixErodeCL(l_int32 hsize, l_int32 vsize, l_uint32 wpl, l_uint32 h) {
1552+
static cl_int pixErodeCL(l_int32 hsize, l_int32 vsize, l_uint32 wpl, l_uint32 h) {
15501553
l_int32 xp, yp, xn, yn;
15511554
SEL *sel;
15521555
size_t globalThreads[2];
@@ -1653,8 +1656,7 @@ cl_int pixErodeCL(l_int32 hsize, l_int32 vsize, l_uint32 wpl, l_uint32 h) {
16531656
}
16541657

16551658
//Morphology Open operation. Invokes the relevant OpenCL kernels
1656-
cl_int
1657-
pixOpenCL(l_int32 hsize, l_int32 vsize, l_int32 wpl, l_int32 h)
1659+
static cl_int pixOpenCL(l_int32 hsize, l_int32 vsize, l_int32 wpl, l_int32 h)
16581660
{
16591661
cl_int status;
16601662
cl_mem pixtemp;
@@ -1672,8 +1674,7 @@ pixOpenCL(l_int32 hsize, l_int32 vsize, l_int32 wpl, l_int32 h)
16721674
}
16731675

16741676
//Morphology Close operation. Invokes the relevant OpenCL kernels
1675-
cl_int
1676-
pixCloseCL(l_int32 hsize, l_int32 vsize, l_int32 wpl, l_int32 h)
1677+
static cl_int pixCloseCL(l_int32 hsize, l_int32 vsize, l_int32 wpl, l_int32 h)
16771678
{
16781679
cl_int status;
16791680
cl_mem pixtemp;
@@ -1691,7 +1692,7 @@ pixCloseCL(l_int32 hsize, l_int32 vsize, l_int32 wpl, l_int32 h)
16911692
}
16921693

16931694
//pix OR operation: outbuffer = buffer1 | buffer2
1694-
cl_int
1695+
static cl_int
16951696
pixORCL_work(l_uint32 wpl, l_uint32 h, cl_mem buffer1, cl_mem buffer2, cl_mem outbuffer)
16961697
{
16971698
cl_int status;
@@ -1729,6 +1730,7 @@ pixORCL_work(l_uint32 wpl, l_uint32 h, cl_mem buffer1, cl_mem buffer2, cl_mem ou
17291730
}
17301731

17311732
//output = buffer1 & ~(buffer2)
1733+
static
17321734
cl_int pixSubtractCL_work(l_uint32 wpl, l_uint32 h, cl_mem buffer1,
17331735
cl_mem buffer2, cl_mem outBuffer = nullptr) {
17341736
cl_int status;
@@ -2140,7 +2142,7 @@ typedef struct _TessScoreEvaluationInputData {
21402142
Pix *pix;
21412143
} TessScoreEvaluationInputData;
21422144

2143-
void populateTessScoreEvaluationInputData( TessScoreEvaluationInputData *input ) {
2145+
static void populateTessScoreEvaluationInputData(TessScoreEvaluationInputData *input) {
21442146
srand(1);
21452147
// 8.5x11 inches @ 300dpi rounded to clean multiples
21462148
int height = 3328; // %256
@@ -2229,7 +2231,7 @@ typedef struct _TessDeviceScore {
22292231
* Micro Benchmarks for Device Selection
22302232
*****************************************************************************/
22312233

2232-
double composeRGBPixelMicroBench( GPUEnv *env, TessScoreEvaluationInputData input, ds_device_type type ) {
2234+
static double composeRGBPixelMicroBench(GPUEnv *env, TessScoreEvaluationInputData input, ds_device_type type) {
22332235
double time = 0;
22342236
#if ON_WINDOWS
22352237
LARGE_INTEGER freq, time_funct_start, time_funct_end;
@@ -2314,7 +2316,7 @@ double composeRGBPixelMicroBench( GPUEnv *env, TessScoreEvaluationInputData inpu
23142316
return time;
23152317
}
23162318

2317-
double histogramRectMicroBench( GPUEnv *env, TessScoreEvaluationInputData input, ds_device_type type ) {
2319+
static double histogramRectMicroBench( GPUEnv *env, TessScoreEvaluationInputData input, ds_device_type type ) {
23182320
double time;
23192321
#if ON_WINDOWS
23202322
LARGE_INTEGER freq, time_funct_start, time_funct_end;
@@ -2397,7 +2399,7 @@ double histogramRectMicroBench( GPUEnv *env, TessScoreEvaluationInputData input,
23972399
}
23982400

23992401
//Reproducing the ThresholdRectToPix native version
2400-
void ThresholdRectToPix_Native(const unsigned char* imagedata,
2402+
static void ThresholdRectToPix_Native(const unsigned char* imagedata,
24012403
int bytes_per_pixel,
24022404
int bytes_per_line,
24032405
const int* thresholds,
@@ -2434,7 +2436,7 @@ void ThresholdRectToPix_Native(const unsigned char* imagedata,
24342436
}
24352437
}
24362438

2437-
double thresholdRectToPixMicroBench( GPUEnv *env, TessScoreEvaluationInputData input, ds_device_type type ) {
2439+
static double thresholdRectToPixMicroBench(GPUEnv *env, TessScoreEvaluationInputData input, ds_device_type type) {
24382440
double time;
24392441
int retVal = 0;
24402442
#if ON_WINDOWS
@@ -2530,7 +2532,7 @@ double thresholdRectToPixMicroBench( GPUEnv *env, TessScoreEvaluationInputData i
25302532
return time;
25312533
}
25322534

2533-
double getLineMasksMorphMicroBench( GPUEnv *env, TessScoreEvaluationInputData input, ds_device_type type ) {
2535+
static double getLineMasksMorphMicroBench(GPUEnv *env, TessScoreEvaluationInputData input, ds_device_type type) {
25342536

25352537
double time = 0;
25362538
#if ON_WINDOWS
@@ -2628,28 +2630,28 @@ double getLineMasksMorphMicroBench( GPUEnv *env, TessScoreEvaluationInputData in
26282630
#include "stdlib.h"
26292631

26302632
// encode score object as byte string
2631-
ds_status serializeScore( ds_device* device, void **serializedScore, unsigned int* serializedScoreSize ) {
2633+
static ds_status serializeScore( ds_device* device, void **serializedScore, unsigned int* serializedScoreSize ) {
26322634
*serializedScoreSize = sizeof(TessDeviceScore);
26332635
*serializedScore = new unsigned char[*serializedScoreSize];
26342636
memcpy(*serializedScore, device->score, *serializedScoreSize);
26352637
return DS_SUCCESS;
26362638
}
26372639

26382640
// parses byte string and stores in score object
2639-
ds_status deserializeScore( ds_device* device, const unsigned char* serializedScore, unsigned int serializedScoreSize ) {
2641+
static ds_status deserializeScore( ds_device* device, const unsigned char* serializedScore, unsigned int serializedScoreSize ) {
26402642
// check that serializedScoreSize == sizeof(TessDeviceScore);
26412643
device->score = new TessDeviceScore;
26422644
memcpy(device->score, serializedScore, serializedScoreSize);
26432645
return DS_SUCCESS;
26442646
}
26452647

2646-
ds_status releaseScore(void *score) {
2648+
static ds_status releaseScore(void *score) {
26472649
delete (TessDeviceScore *)score;
26482650
return DS_SUCCESS;
26492651
}
26502652

26512653
// evaluate devices
2652-
ds_status evaluateScoreForDevice( ds_device *device, void *inputData) {
2654+
static ds_status evaluateScoreForDevice( ds_device *device, void *inputData) {
26532655
// overwrite statuc gpuEnv w/ current device
26542656
// so native opencl calls can be used; they use static gpuEnv
26552657
printf("\n[DS] Device: \"%s\" (%s) evaluation...\n", device->oclDeviceName, device->type==DS_DEVICE_OPENCL_DEVICE ? "OpenCL" : "Native" );

0 commit comments

Comments
 (0)