@@ -68,8 +68,8 @@ typedef struct {
68
68
typedef ds_status (* ds_score_release )(void * score );
69
69
static ds_status releaseDSProfile (ds_profile * profile , ds_score_release sr ) {
70
70
ds_status status = DS_SUCCESS ;
71
- if (profile != nullptr ) {
72
- if (profile -> devices != nullptr && sr != nullptr ) {
71
+ if (profile != nullptr ) {
72
+ if (profile -> devices != nullptr && sr != nullptr ) {
73
73
unsigned int i ;
74
74
for (i = 0 ; i < profile -> numDevices ; i ++ ) {
75
75
free (profile -> devices [i ].oclDeviceName );
@@ -90,18 +90,16 @@ static ds_status initDSProfile(ds_profile** p, const char* version) {
90
90
int numDevices ;
91
91
cl_uint numPlatforms ;
92
92
cl_platform_id * platforms = nullptr ;
93
- cl_device_id * devices = nullptr ;
93
+ cl_device_id * devices = nullptr ;
94
94
ds_status status = DS_SUCCESS ;
95
95
unsigned int next ;
96
96
unsigned int i ;
97
97
98
- if (p == nullptr )
99
- return DS_INVALID_PROFILE ;
98
+ if (p == nullptr ) return DS_INVALID_PROFILE ;
100
99
101
100
ds_profile * profile = (ds_profile * )malloc (sizeof (ds_profile ));
102
- if (profile == nullptr )
103
- return DS_MEMORY_ERROR ;
104
-
101
+ if (profile == nullptr ) return DS_MEMORY_ERROR ;
102
+
105
103
memset (profile , 0 , sizeof (ds_profile ));
106
104
107
105
clGetPlatformIDs (0 , nullptr , & numPlatforms );
@@ -131,7 +129,8 @@ static ds_status initDSProfile(ds_profile** p, const char* version) {
131
129
}
132
130
133
131
profile -> numDevices = numDevices + 1 ; // +1 to numDevices to include the native CPU
134
- profile -> devices = (ds_device * )malloc (profile -> numDevices * sizeof (ds_device ));
132
+ profile -> devices =
133
+ (ds_device * )malloc (profile -> numDevices * sizeof (ds_device ));
135
134
if (profile -> devices == nullptr ) {
136
135
profile -> numDevices = 0 ;
137
136
status = DS_MEMORY_ERROR ;
@@ -151,14 +150,14 @@ static ds_status initDSProfile(ds_profile** p, const char* version) {
151
150
profile -> devices [next ].type = DS_DEVICE_OPENCL_DEVICE ;
152
151
profile -> devices [next ].oclDeviceID = devices [j ];
153
152
154
- clGetDeviceInfo (profile -> devices [next ].oclDeviceID , CL_DEVICE_NAME
155
- , DS_DEVICE_NAME_LENGTH , & buffer , nullptr );
153
+ clGetDeviceInfo (profile -> devices [next ].oclDeviceID , CL_DEVICE_NAME ,
154
+ DS_DEVICE_NAME_LENGTH , & buffer , nullptr );
156
155
length = strlen (buffer );
157
156
profile -> devices [next ].oclDeviceName = (char * )malloc (length + 1 );
158
157
memcpy (profile -> devices [next ].oclDeviceName , buffer , length + 1 );
159
158
160
- clGetDeviceInfo (profile -> devices [next ].oclDeviceID , CL_DRIVER_VERSION
161
- , DS_DEVICE_NAME_LENGTH , & buffer , nullptr );
159
+ clGetDeviceInfo (profile -> devices [next ].oclDeviceID , CL_DRIVER_VERSION ,
160
+ DS_DEVICE_NAME_LENGTH , & buffer , nullptr );
162
161
length = strlen (buffer );
163
162
profile -> devices [next ].oclDriverVersion = (char * )malloc (length + 1 );
164
163
memcpy (profile -> devices [next ].oclDriverVersion , buffer , length + 1 );
@@ -213,8 +212,7 @@ static ds_status profileDevices(ds_profile* profile,
213
212
214
213
switch (type ) {
215
214
case DS_EVALUATE_NEW_ONLY :
216
- if (profile -> devices [i ].score != nullptr )
217
- break ;
215
+ if (profile -> devices [i ].score != nullptr ) break ;
218
216
// else fall through
219
217
case DS_EVALUATE_ALL :
220
218
evaluatorStatus = evaluator (profile -> devices + i , evaluatorData );
@@ -260,11 +258,10 @@ static ds_status writeProfileToFile(ds_profile* profile,
260
258
const char * file ) {
261
259
ds_status status = DS_SUCCESS ;
262
260
263
- if (profile == nullptr )
264
- return DS_INVALID_PROFILE ;
261
+ if (profile == nullptr ) return DS_INVALID_PROFILE ;
265
262
266
263
FILE * profileFile = fopen (file , "wb" );
267
- if (profileFile == nullptr ) {
264
+ if (profileFile == nullptr ) {
268
265
status = DS_FILE_ERROR ;
269
266
}
270
267
else {
@@ -327,7 +324,8 @@ static ds_status writeProfileToFile(ds_profile* profile,
327
324
fwrite (DS_TAG_SCORE , sizeof (char ), strlen (DS_TAG_SCORE ), profileFile );
328
325
status = serializer (profile -> devices + i , & serializedScore ,
329
326
& serializedScoreSize );
330
- if (status == DS_SUCCESS && serializedScore != nullptr && serializedScoreSize > 0 ) {
327
+ if (status == DS_SUCCESS && serializedScore != nullptr &&
328
+ serializedScoreSize > 0 ) {
331
329
fwrite (serializedScore , sizeof (char ), serializedScoreSize , profileFile );
332
330
free (serializedScore );
333
331
}
@@ -349,15 +347,15 @@ static ds_status readProFile(const char* fileName, char** content,
349
347
* content = nullptr ;
350
348
351
349
FILE * input = fopen (fileName , "rb" );
352
- if (input == nullptr ) {
350
+ if (input == nullptr ) {
353
351
return DS_FILE_ERROR ;
354
352
}
355
353
356
354
fseek (input , 0L , SEEK_END );
357
355
size = ftell (input );
358
356
rewind (input );
359
357
char * binary = (char * )malloc (size );
360
- if (binary == nullptr ) {
358
+ if (binary == nullptr ) {
361
359
fclose (input );
362
360
return DS_FILE_ERROR ;
363
361
}
@@ -403,8 +401,7 @@ static ds_status readProfileFromFile(ds_profile* profile,
403
401
const char * contentEnd = nullptr ;
404
402
size_t contentSize ;
405
403
406
- if (profile == nullptr )
407
- return DS_INVALID_PROFILE ;
404
+ if (profile == nullptr ) return DS_INVALID_PROFILE ;
408
405
409
406
status = readProFile (file , & contentStart , & contentSize );
410
407
if (status == DS_SUCCESS ) {
@@ -426,7 +423,7 @@ static ds_status readProfileFromFile(ds_profile* profile,
426
423
dataStart += strlen (DS_TAG_VERSION );
427
424
428
425
dataEnd = findString (dataStart , contentEnd , DS_TAG_VERSION_END );
429
- if (dataEnd == nullptr ) {
426
+ if (dataEnd == nullptr ) {
430
427
status = DS_PROFILE_FILE_ERROR ;
431
428
goto cleanup ;
432
429
}
@@ -458,27 +455,27 @@ static ds_status readProfileFromFile(ds_profile* profile,
458
455
const char * deviceDriverEnd ;
459
456
460
457
dataStart = findString (currentPosition , contentEnd , DS_TAG_DEVICE );
461
- if (dataStart == nullptr ) {
458
+ if (dataStart == nullptr ) {
462
459
// nothing useful remain, quit...
463
460
break ;
464
461
}
465
462
dataStart += strlen (DS_TAG_DEVICE );
466
463
dataEnd = findString (dataStart , contentEnd , DS_TAG_DEVICE_END );
467
- if (dataEnd == nullptr ) {
464
+ if (dataEnd == nullptr ) {
468
465
status = DS_PROFILE_FILE_ERROR ;
469
466
goto cleanup ;
470
467
}
471
468
472
469
// parse the device type
473
470
deviceTypeStart = findString (dataStart , contentEnd , DS_TAG_DEVICE_TYPE );
474
- if (deviceTypeStart == nullptr ) {
471
+ if (deviceTypeStart == nullptr ) {
475
472
status = DS_PROFILE_FILE_ERROR ;
476
473
goto cleanup ;
477
474
}
478
475
deviceTypeStart += strlen (DS_TAG_DEVICE_TYPE );
479
476
deviceTypeEnd = findString (deviceTypeStart , contentEnd ,
480
477
DS_TAG_DEVICE_TYPE_END );
481
- if (deviceTypeEnd == nullptr ) {
478
+ if (deviceTypeEnd == nullptr ) {
482
479
status = DS_PROFILE_FILE_ERROR ;
483
480
goto cleanup ;
484
481
}
@@ -489,29 +486,29 @@ static ds_status readProfileFromFile(ds_profile* profile,
489
486
if (deviceType == DS_DEVICE_OPENCL_DEVICE ) {
490
487
491
488
deviceNameStart = findString (dataStart , contentEnd , DS_TAG_DEVICE_NAME );
492
- if (deviceNameStart == nullptr ) {
489
+ if (deviceNameStart == nullptr ) {
493
490
status = DS_PROFILE_FILE_ERROR ;
494
491
goto cleanup ;
495
492
}
496
493
deviceNameStart += strlen (DS_TAG_DEVICE_NAME );
497
494
deviceNameEnd = findString (deviceNameStart , contentEnd ,
498
495
DS_TAG_DEVICE_NAME_END );
499
- if (deviceNameEnd == nullptr ) {
496
+ if (deviceNameEnd == nullptr ) {
500
497
status = DS_PROFILE_FILE_ERROR ;
501
498
goto cleanup ;
502
499
}
503
500
504
501
505
502
deviceDriverStart = findString (dataStart , contentEnd ,
506
503
DS_TAG_DEVICE_DRIVER_VERSION );
507
- if (deviceDriverStart == nullptr ) {
504
+ if (deviceDriverStart == nullptr ) {
508
505
status = DS_PROFILE_FILE_ERROR ;
509
506
goto cleanup ;
510
507
}
511
508
deviceDriverStart += strlen (DS_TAG_DEVICE_DRIVER_VERSION );
512
509
deviceDriverEnd = findString (deviceDriverStart , contentEnd ,
513
510
DS_TAG_DEVICE_DRIVER_VERSION_END );
514
- if (deviceDriverEnd == nullptr ) {
511
+ if (deviceDriverEnd == nullptr ) {
515
512
status = DS_PROFILE_FILE_ERROR ;
516
513
goto cleanup ;
517
514
}
@@ -532,7 +529,7 @@ static ds_status readProfileFromFile(ds_profile* profile,
532
529
&& strncmp (profile -> devices [i ].oclDriverVersion , deviceDriverStart ,
533
530
driverVersionLength )== 0 ) {
534
531
deviceScoreStart = findString (dataStart , contentEnd , DS_TAG_SCORE );
535
- if (deviceNameStart == nullptr ) {
532
+ if (deviceNameStart == nullptr ) {
536
533
status = DS_PROFILE_FILE_ERROR ;
537
534
goto cleanup ;
538
535
}
@@ -554,7 +551,7 @@ static ds_status readProfileFromFile(ds_profile* profile,
554
551
for (i = 0 ; i < profile -> numDevices ; i ++ ) {
555
552
if (profile -> devices [i ].type == DS_DEVICE_NATIVE_CPU ) {
556
553
deviceScoreStart = findString (dataStart , contentEnd , DS_TAG_SCORE );
557
- if (deviceScoreStart == nullptr ) {
554
+ if (deviceScoreStart == nullptr ) {
558
555
status = DS_PROFILE_FILE_ERROR ;
559
556
goto cleanup ;
560
557
}
0 commit comments