Move vectype_ops.clh into gpu_utils
authorAleksei Iupinov <a.yupinov@gmail.com>
Fri, 25 May 2018 13:46:06 +0000 (15:46 +0200)
committerSzilárd Páll <pall.szilard@gmail.com>
Mon, 25 Jun 2018 13:12:34 +0000 (15:12 +0200)
OpenCL compilation now uses gpu_utils as an include directory in source.
All the OpenCL sources are still installed into one directory.

Change-Id: Ib8f4b441867b685d774202319a7d54fd085d1a9b

src/gromacs/gpu_utils/CMakeLists.txt
src/gromacs/gpu_utils/ocl_compiler.cpp
src/gromacs/gpu_utils/vectype_ops.clh [moved from src/gromacs/mdlib/nbnxn_ocl/vectype_ops.clh with 100% similarity]

index 1ee6f7d5aded67c9232b6b31b775df1e7e05b0e6..b90471dd91ff4f0d1bc9b458b58940b18bcf17a5 100644 (file)
@@ -60,6 +60,11 @@ else()
         )
 endif()
 
+if(GMX_USE_OPENCL)
+    file(GLOB OPENCL_COMMON_HEADERS vectype_ops.clh)
+    set(MDLIB_OPENCL_KERNELS ${MDLIB_OPENCL_KERNELS} ${OPENCL_COMMON_HEADERS} PARENT_SCOPE)
+endif()
+
 # workaround for the state - host allocator dependency
 gmx_install_headers(hostallocator.h)
 
index b58501913b1c0ac6ef6229711cd48895633386a5..3384e20772e2d11eff4b37d108a35966bc98b0bd 100644 (file)
@@ -203,24 +203,24 @@ selectCompilerOptions(ocl_vendor_id_t deviceVendorId)
     return compilerOptions;
 }
 
-/*! \brief Get the path to the folder storing an OpenCL kernel.
+/*! \brief Get the path to the folder storing an OpenCL source file.
  *
  * 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.
  *
- * \param[in] kernelRelativePath    Relative path to the kernel in the source tree,
+ * \param[in] sourceRelativePath    Relative path to the kernel or other file 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
+ * \return OS-normalized path string to the folder storing OpenCL source file
  *
  * \throws std::bad_alloc    if out of memory.
  *         FileIOError  if GMX_OCL_FILE_PATH does not specify a readable path
  */
 static std::string
-getKernelRootPath(const std::string &kernelRelativePath)
+getSourceRootPath(const std::string &sourceRelativePath)
 {
-    std::string kernelRootPath;
+    std::string sourceRootPath;
     /* Use GMX_OCL_FILE_PATH if the user has defined it */
     const char *gmxOclFilePath = getenv("GMX_OCL_FILE_PATH");
 
@@ -230,9 +230,9 @@ getKernelRootPath(const std::string &kernelRelativePath)
            root path from the path to the binary that is running. */
         InstallationPrefixInfo      info           = getProgramContext().installationPrefix();
         std::string                 dataPathSuffix = (info.bSourceLayout ?
-                                                      kernelRelativePath :
+                                                      sourceRelativePath :
                                                       OCL_INSTALL_DIR);
-        kernelRootPath = Path::join(info.path, dataPathSuffix);
+        sourceRootPath = Path::join(info.path, dataPathSuffix);
     }
     else
     {
@@ -241,11 +241,11 @@ getKernelRootPath(const std::string &kernelRelativePath)
             GMX_THROW(FileIOError(formatString("GMX_OCL_FILE_PATH must point to the directory where OpenCL"
                                                "kernels are found, but '%s' does not exist", gmxOclFilePath)));
         }
-        kernelRootPath = gmxOclFilePath;
+        sourceRootPath = gmxOclFilePath;
     }
 
     // Make sure we return an OS-correct path format
-    return Path::normalize(kernelRootPath);
+    return Path::normalize(sourceRootPath);
 }
 
 /*!  \brief Get the warp size reported by device
@@ -390,6 +390,7 @@ removeExtraSpaces(std::string *str)
  * \throws std::bad_alloc  if out of memory. */
 static std::string
 makePreprocessorOptions(const std::string   &kernelRootPath,
+                        const std::string   &includeRootPath,
                         size_t               warpSize,
                         ocl_vendor_id_t      deviceVendorId,
                         const std::string   &extraDefines)
@@ -406,6 +407,8 @@ makePreprocessorOptions(const std::string   &kernelRootPath,
     preprocessorOptions += selectCompilerOptions(deviceVendorId);
     preprocessorOptions += ' ';
     preprocessorOptions += makeKernelIncludePathOption(kernelRootPath);
+    preprocessorOptions += ' ';
+    preprocessorOptions += makeKernelIncludePathOption(includeRootPath);
 
     // Mac OS (and maybe some other implementations) does not accept double spaces in options
     removeExtraSpaces(&preprocessorOptions);
@@ -423,7 +426,8 @@ compileProgram(FILE              *fplog,
                ocl_vendor_id_t    deviceVendorId)
 {
     cl_int      cl_error;
-    std::string kernelRootPath = getKernelRootPath(kernelRelativePath);
+    std::string kernelRootPath  = getSourceRootPath(kernelRelativePath);
+    std::string includeRootPath = getSourceRootPath("src/gromacs/gpu_utils");
 
     GMX_RELEASE_ASSERT(fplog != nullptr, "Need a valid log file for building OpenCL programs");
 
@@ -433,6 +437,7 @@ compileProgram(FILE              *fplog,
 
     /* Make the build options */
     std::string preprocessorOptions = makePreprocessorOptions(kernelRootPath,
+                                                              includeRootPath,
                                                               getWarpSize(context, deviceId),
                                                               deviceVendorId,
                                                               extraDefines);