Fix OpenCL binary cache file name generation
authorSzilárd Páll <pall.szilard@gmail.com>
Mon, 30 May 2016 15:52:18 +0000 (17:52 +0200)
committerErik Lindahl <erik.lindahl@gmail.com>
Thu, 2 Jun 2016 11:22:41 +0000 (13:22 +0200)
The binary cache names was generated from the full path prefixed
with a constant string which is a not a valid filename.

Also added assertion on the file pointer passed to fclose.

Change-Id: I838cf9a2e19385afaf26b80a15be2b74973d3a4c

src/gromacs/gpu_utils/ocl_caching.cpp
src/gromacs/gpu_utils/ocl_compiler.cpp

index 88cc863c3993bcd478b5efa8f4612e1444d5cab9..250df5cb8af77bfec066f11d4848c6cb1c06575a 100644 (file)
@@ -45,6 +45,8 @@
 
 #include "ocl_caching.h"
 
+#include <assert.h>
+
 #include <cstdio>
 
 #include <string>
@@ -73,6 +75,7 @@ namespace ocl
  */
 static void fclose_wrapper(FILE *fp)
 {
+    assert(fp != NULL);
     fclose(fp);
 }
 
@@ -85,9 +88,15 @@ std::string makeBinaryCacheFilename(const std::string &kernelFilename,
     {
         GMX_THROW(InternalError(formatString("Could not get OpenCL device name, error was %s", ocl_get_error_string(cl_error).c_str())));
     }
-    std::string cacheFilename = "OpenCL_cache_" + kernelFilename + "_" + deviceName;
+
+    std::string cacheFilename = "OCL-cache";
+    /* remove the kernel source suffix */
+    cacheFilename += "_" + stripSuffixIfPresent(kernelFilename, ".cl");
+    /* the device name often contains spaces, we don't like those */
+    cacheFilename += "_" + replaceAll(stripString(deviceName), " ", "-");
     cacheFilename  = replaceAll(cacheFilename, ".", "_");
     cacheFilename += ".bin";
+
     return cacheFilename;
 }
 
index e87dd7034ed81b0833674b35f611d84b1afc97d0..99470907d66bd8f04ce60d2948ae022104398db2 100644 (file)
@@ -414,7 +414,7 @@ compileProgram(FILE              *fplog,
     std::string cacheFilename;
     if (useBuildCache)
     {
-        cacheFilename = makeBinaryCacheFilename(kernelFilename, deviceId);
+        cacheFilename = makeBinaryCacheFilename(kernelBaseFilename, deviceId);
     }
 
     /* Create OpenCL program */