Make in-source OpenCL kernel path a per-module parameter
authorAleksei Iupinov <a.yupinov@gmail.com>
Thu, 12 Apr 2018 14:31:43 +0000 (16:31 +0200)
committerAleksei Iupinov <a.yupinov@gmail.com>
Thu, 12 Apr 2018 19:35:30 +0000 (21:35 +0200)
Change-Id: I19cd66b441fec6ceba74eb648bea3409b6521917

src/gromacs/gpu_utils/ocl_compiler.cpp
src/gromacs/gpu_utils/ocl_compiler.h
src/gromacs/mdlib/nbnxn_ocl/nbnxn_ocl_jit_support.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");
 
index 33e64941ceb107215c8ab192608ede8319ca1fb4..c25e4d6c27143b8dd9d5ff20e12fe78c835a3347 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2012,2013,2014,2015,2016,2017, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -56,6 +56,8 @@ namespace ocl
 /*! \brief Compile the specified kernel for the context and device.
  *
  * \param[out] fplog                 Open file pointer for log output
+ * \param[in]  kernelRelativePath    Relative path to the kernel in the source tree,
+ *                                   e.g. "src/gromacs/mdlib/nbnxn_ocl" for NB kernels.
  * \param[in]  kernelBaseFilename    The name of the kernel source file to compile, e.g. "nbnxn_ocl_kernels.cl"
  * \param[in]  extraDefines          Preprocessor defines required by the calling code, e.g. for configuring the kernels
  * \param[in]  context               OpenCL context on the device to compile for
@@ -74,6 +76,7 @@ namespace ocl
  *         InternalError   if an OpenCL API error prevents returning a valid compiled program. */
 cl_program
 compileProgram(FILE              *fplog,
+               const std::string &kernelRelativePath,
                const std::string &kernelBaseFilename,
                const std::string &extraDefines,
                cl_context         context,
index 61eb5f0e7790f5a7888ca63c6f05728e1bb6e659..874869a2f3ad84ef65f9150f61259946f0c245c7 100644 (file)
@@ -218,6 +218,7 @@ nbnxn_gpu_compile_kernels(gmx_nbnxn_ocl_t *nb)
             /* TODO when we have a proper MPI-aware logging module,
                the log output here should be written there */
             program = gmx::ocl::compileProgram(stderr,
+                                               "src/gromacs/mdlib/nbnxn_ocl",
                                                "nbnxn_ocl_kernels.cl",
                                                extraDefines,
                                                nb->dev_rundata->context,