Make in-source OpenCL kernel path a per-module parameter
[alexxy/gromacs.git] / src / gromacs / gpu_utils / ocl_compiler.cpp
index 950c323fab7c79e87a71ece156046b987a36e117..182ec20192e01d2a490a6ba0bc3a0a22bd0e5f72 100644 (file)
@@ -203,20 +203,22 @@ selectCompilerOptions(ocl_vendor_id_t deviceVendorId)
     return compilerOptions;
 }
 
-/*! \brief Get the path to the main folder storing OpenCL kernels.
+/*! \brief Get the path to the folder storing an OpenCL kernel.
  *
  * By default, this function constructs the full path to the OpenCL from
  * the known location of the binary that is running, so that we handle
  * both in-source and installed builds. The user can override this
  * behavior by defining GMX_OCL_FILE_PATH environment variable.
  *
- * \return OS-normalized path string to the main folder storing OpenCL kernels
+ * \param[in] kernelRelativePath    Relative path to the kernel in the source tree,
+ *                                  e.g. "src/gromacs/mdlib/nbnxn_ocl" for NB kernels.
+ * \return OS-normalized path string to the folder storing OpenCL kernel
  *
  * \throws std::bad_alloc    if out of memory.
  *         FileIOError  if GMX_OCL_FILE_PATH does not specify a readable path
  */
 static std::string
-getKernelRootPath()
+getKernelRootPath(const std::string &kernelRelativePath)
 {
     std::string kernelRootPath;
     /* Use GMX_OCL_FILE_PATH if the user has defined it */
@@ -228,7 +230,7 @@ getKernelRootPath()
            root path from the path to the binary that is running. */
         InstallationPrefixInfo      info           = getProgramContext().installationPrefix();
         std::string                 dataPathSuffix = (info.bSourceLayout ?
-                                                      "src/gromacs/mdlib/nbnxn_ocl" :
+                                                      kernelRelativePath :
                                                       OCL_INSTALL_DIR);
         kernelRootPath = Path::join(info.path, dataPathSuffix);
     }
@@ -410,6 +412,7 @@ makePreprocessorOptions(const std::string   &kernelRootPath,
 
 cl_program
 compileProgram(FILE              *fplog,
+               const std::string &kernelRelativePath,
                const std::string &kernelBaseFilename,
                const std::string &extraDefines,
                cl_context         context,
@@ -417,7 +420,7 @@ compileProgram(FILE              *fplog,
                ocl_vendor_id_t    deviceVendorId)
 {
     cl_int      cl_error;
-    std::string kernelRootPath = getKernelRootPath();
+    std::string kernelRootPath = getKernelRootPath(kernelRelativePath);
 
     GMX_RELEASE_ASSERT(fplog != nullptr, "Need a valid log file for building OpenCL programs");