]> granicus.if.org Git - imagemagick/commitdiff
Disabled benchmarking when result cannot not be saved on disk.
authordirk <dirk@git.imagemagick.org>
Wed, 27 Aug 2014 15:30:53 +0000 (15:30 +0000)
committerdirk <dirk@git.imagemagick.org>
Wed, 27 Aug 2014 15:30:53 +0000 (15:30 +0000)
MagickCore/opencl.c

index 1d2c056bcbd9a196da6a9c1a5a5a98ea66c8387a..8e0c73781ba5638481bd9458e495f28291521188 100644 (file)
@@ -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;
+      }
     }
   }