From: dirk Date: Wed, 27 Aug 2014 15:30:53 +0000 (+0000) Subject: Disabled benchmarking when result cannot not be saved on disk. X-Git-Tag: 7.0.1-0~2062 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b05dcc98d31306c326538effc895c502fb0be0ca;p=imagemagick Disabled benchmarking when result cannot not be saved on disk. --- diff --git a/MagickCore/opencl.c b/MagickCore/opencl.c index 1d2c056bc..8e0c73781 100644 --- a/MagickCore/opencl.c +++ b/MagickCore/opencl.c @@ -1470,6 +1470,7 @@ typedef enum { typedef struct { ds_device_type type; + cl_device_type oclDeviceType; cl_device_id oclDeviceID; char* oclDeviceName; char* oclDriverVersion; @@ -1608,6 +1609,9 @@ static ds_status initDSProfile(ds_profile** p, const char* version) { OpenCLLib->clGetDeviceInfo(profile->devices[next].oclDeviceID, CL_DEVICE_MAX_COMPUTE_UNITS , sizeof(cl_uint), &profile->devices[next].oclMaxComputeUnits, NULL); + + OpenCLLib->clGetDeviceInfo(profile->devices[next].oclDeviceID, CL_DEVICE_TYPE + , sizeof(cl_device_type), &profile->devices[next].oclDeviceType, NULL); } } } @@ -2253,6 +2257,16 @@ ds_status AccelerateScoreRelease(void* score) { return DS_SUCCESS; } +ds_status canWriteProfileToFile(path) +{ + FILE* profileFile = fopen(path, "wb"); + + if (profileFile==NULL) + return DS_FILE_ERROR; + + fclose(profileFile); + return DS_SUCCESS; +} #define IMAGEMAGICK_PROFILE_VERSION "ImageMagick Device Selection v0.9" #define IMAGEMAGICK_PROFILE_FILE "ImagemagickOpenCLDeviceProfile" @@ -2294,34 +2308,48 @@ static MagickBooleanType autoSelectDevice(MagickCLEnv clEnv, ExceptionInfo* exce ,GetOpenCLCachedFilesDirectory() ,DirectorySeparator,IMAGEMAGICK_PROFILE_FILE); - if (clEnv->regenerateProfile != MagickFalse) { - profileType = DS_EVALUATE_ALL; + if (canWriteProfileToFile(path) != DS_SUCCESS) { + /* We can not write out a device profile, so don't run the benchmark */ + /* select the first GPU device */ + + bestDeviceIndex = 0; + for (i = 1; i < profile->numDevices; i++) { + if ((profile->devices[i].type == DS_DEVICE_OPENCL_DEVICE) && (profile->devices[i].oclDeviceType == CL_DEVICE_TYPE_GPU)) { + bestDeviceIndex = i; + break; + } + } } else { - readProfileFromFile(profile, AccelerateScoreDeserializer, path); - profileType = DS_EVALUATE_NEW_ONLY; - } - status = profileDevices(profile, profileType, AcceleratePerfEvaluator, NULL, &numDeviceProfiled); + if (clEnv->regenerateProfile != MagickFalse) { + profileType = DS_EVALUATE_ALL; + } + else { + readProfileFromFile(profile, AccelerateScoreDeserializer, path); + profileType = DS_EVALUATE_NEW_ONLY; + } + status = profileDevices(profile, profileType, AcceleratePerfEvaluator, NULL, &numDeviceProfiled); - if (status!=DS_SUCCESS) { - (void) ThrowMagickException(exception, GetMagickModule(), ModuleFatalError, "Error when initializing the profile", "'%s'", "."); - goto cleanup; - } - if (numDeviceProfiled > 0) { - status = writeProfileToFile(profile, AccelerateScoreSerializer, path); if (status!=DS_SUCCESS) { - (void) ThrowMagickException(exception, GetMagickModule(), ModuleWarning, "Error when saving the profile into a file", "'%s'", "."); + (void) ThrowMagickException(exception, GetMagickModule(), ModuleFatalError, "Error when initializing the profile", "'%s'", "."); + goto cleanup; + } + if (numDeviceProfiled > 0) { + status = writeProfileToFile(profile, AccelerateScoreSerializer, path); + if (status!=DS_SUCCESS) { + (void) ThrowMagickException(exception, GetMagickModule(), ModuleWarning, "Error when saving the profile into a file", "'%s'", "."); + } } - } - /* pick the best device */ - bestDeviceIndex = 0; - bestScore = *(AccelerateScoreType*)profile->devices[bestDeviceIndex].score; - for (i = 1; i < profile->numDevices; i++) { - AccelerateScoreType score = *(AccelerateScoreType*)profile->devices[i].score; - if (score < bestScore) { - bestDeviceIndex = i; - bestScore = score; + /* pick the best device */ + bestDeviceIndex = 0; + bestScore = *(AccelerateScoreType*)profile->devices[bestDeviceIndex].score; + for (i = 1; i < profile->numDevices; i++) { + AccelerateScoreType score = *(AccelerateScoreType*)profile->devices[i].score; + if (score < bestScore) { + bestDeviceIndex = i; + bestScore = score; + } } }