typedef struct {
ds_device_type type;
+ cl_device_type oclDeviceType;
cl_device_id oclDeviceID;
char* oclDeviceName;
char* oclDriverVersion;
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);
}
}
}
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"
,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;
+ }
}
}