Stop using custom FindOpenCL.cmake, per TODO
authorAleksei Iupinov <a.yupinov@gmail.com>
Tue, 27 Feb 2018 16:55:31 +0000 (17:55 +0100)
committerSzilárd Páll <pall.szilard@gmail.com>
Mon, 5 Mar 2018 16:28:23 +0000 (17:28 +0100)
It was originally taken from cmake 3.1.0 and modified to produce
all-uppercase variable names (with OPENCL_ instead of OpenCL_),
so the surrounding cmake code is now changed to expect exact-case names.

Another (undocumented) modification was that it took into account
CUDA_HOME env.var. when searching for OpenCL, while standard cmake
only looks at seemingly less useful CUDA_PATH. This useful trick is
preserved by temporarily appending $ENV{CUDA_HOME} to CMAKE_PREFIX_PATH.

Change-Id: I5ca60f88e657b064fb6f98b268c2c48e10f00986

cmake/FindOpenCL.cmake [deleted file]
cmake/gmxManageOpenCL.cmake
src/buildinfo.h.cmakein
src/gromacs/CMakeLists.txt
src/gromacs/gpu_utils/tests/CMakeLists.txt

diff --git a/cmake/FindOpenCL.cmake b/cmake/FindOpenCL.cmake
deleted file mode 100644 (file)
index 4542403..0000000
+++ /dev/null
@@ -1,247 +0,0 @@
-#
-# This file is part of the GROMACS molecular simulation package.
-#
-# Copyright (c) 2012,2013,2014,2015, 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.
-#
-# GROMACS is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public License
-# as published by the Free Software Foundation; either version 2.1
-# of the License, or (at your option) any later version.
-#
-# GROMACS is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with GROMACS; if not, see
-# http://www.gnu.org/licenses, or write to the Free Software Foundation,
-# Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
-#
-# If you want to redistribute modifications to GROMACS, please
-# consider that scientific software is very special. Version
-# control is crucial - bugs must be traceable. We will be happy to
-# consider code for inclusion in the official distribution, but
-# derived work must not be called official GROMACS. Details are found
-# in the README & COPYING files - if they are missing, get the
-# official version at http://www.gromacs.org.
-#
-# To help us fund GROMACS development, we humbly ask that you cite
-# the research papers on the package. Check out http://www.gromacs.org.
-
-#.rst:
-# FindOPENCL
-# ----------
-#
-# Try to find OPENCL
-#
-# Once done this will define::
-#
-#   OPENCL_FOUND          - True if OPENCL was found
-#   OPENCL_INCLUDE_DIRS   - include directories for OPENCL
-#   OPENCL_LIBRARIES      - link against this library to use OPENCL
-#   OPENCL_VERSION_STRING - Highest supported OPENCL version (eg. 1.2)
-#   OPENCL_VERSION_MAJOR  - The major version of the OPENCL implementation
-#   OPENCL_VERSION_MINOR  - The minor version of the OPENCL implementation
-#
-# The module will also define two cache variables::
-#
-#   OPENCL_INCLUDE_DIR    - the OPENCL include directory
-#   OPENCL_LIBRARY        - the path to the OPENCL library
-#
-# This is a modified version of FindOpenCL.cmake from cmake v3.1.0
-# (see comments at the end of the file).
-# The following changes have been made:
-#     1. OpenCL is written in all caps (OPENCL)
-#     2. The following block has been modified:
-#include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
-#find_package_handle_standard_args(
-#  OpenCL
-#  FOUND_VAR OpenCL_FOUND
-#  REQUIRED_VARS OpenCL_LIBRARY OpenCL_INCLUDE_DIR
-#  VERSION_VAR OpenCL_VERSION_STRING)
-#     has been replaced by:
-#include(FindPackageHandleStandardArgs)
-#FIND_PACKAGE_HANDLE_STANDARD_ARGS(OPENCL
-#  REQUIRED_VARS OPENCL_LIBRARY OPENCL_INCLUDE_DIR
-#  VERSION_VAR OPENCL_VERSION_STRING)
-#     3. The following block has been modified:
-#  find_library(OPENCL_LIBRARY
-#   NAMES OPENCL)
-#     has been replaced by:
-#  find_library(OPENCL_LIBRARY
-#   NAMES OpenCL)
-
-function(_FIND_OPENCL_VERSION)
-  include(CheckSymbolExists)
-  include(CMakePushCheckState)
-  set(CMAKE_REQUIRED_QUIET ${OPENCL_FIND_QUIETLY})
-
-  CMAKE_PUSH_CHECK_STATE()
-  foreach(VERSION "2_0" "1_2" "1_1" "1_0")
-    set(CMAKE_REQUIRED_INCLUDES "${OPENCL_INCLUDE_DIR}")
-
-    if(APPLE)
-      CHECK_SYMBOL_EXISTS(
-        CL_VERSION_${VERSION}
-        "OpenCL/cl.h"
-        OPENCL_VERSION_${VERSION})
-    else()
-      CHECK_SYMBOL_EXISTS(
-        CL_VERSION_${VERSION}
-        "CL/cl.h"
-        OPENCL_VERSION_${VERSION})
-    endif()
-
-    if(OPENCL_VERSION_${VERSION})
-      string(REPLACE "_" "." VERSION "${VERSION}")
-      set(OPENCL_VERSION_STRING ${VERSION} PARENT_SCOPE)
-      string(REGEX MATCHALL "[0-9]+" version_components "${VERSION}")
-      list(GET version_components 0 major_version)
-      list(GET version_components 1 minor_version)
-      set(OPENCL_VERSION_MAJOR ${major_version} PARENT_SCOPE)
-      set(OPENCL_VERSION_MINOR ${minor_version} PARENT_SCOPE)
-      break()
-    endif()
-  endforeach()
-  CMAKE_POP_CHECK_STATE()
-endfunction()
-
-find_path(OPENCL_INCLUDE_DIR
-  NAMES
-    CL/cl.h OpenCL/cl.h
-  PATHS
-    ENV "PROGRAMFILES(X86)"
-    ENV AMDAPPSDKROOT
-    ENV INTELOCLSDKROOT
-    ENV NVSDKCOMPUTE_ROOT
-    ENV CUDA_PATH
-    ENV CUDA_HOME
-    ENV ATISTREAMSDKROOT
-  PATH_SUFFIXES
-    include
-    OPENCL/common/inc
-    "AMD APP/include")
-
-if(CMAKE_SIZEOF_VOID_P EQUAL 4)
-    find_library(OPENCL_LIBRARY
-        NAMES OPENCL OpenCL
-        PATHS
-        ENV "PROGRAMFILES(X86)"
-        ENV AMDAPPSDKROOT
-        ENV INTELOCLSDKROOT
-        ENV CUDA_PATH
-        ENV CUDA_HOME
-        ENV NVSDKCOMPUTE_ROOT
-        ENV ATISTREAMSDKROOT
-        PATH_SUFFIXES
-        "AMD APP/lib/x86"
-        lib/x86
-        lib/Win32
-        lib
-        OPENCL/common/lib/Win32)
-elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
-    find_library(OPENCL_LIBRARY
-        NAMES OPENCL OpenCL
-        PATHS
-        ENV "PROGRAMFILES(X86)"
-        ENV AMDAPPSDKROOT
-        ENV INTELOCLSDKROOT
-        ENV CUDA_PATH
-        ENV CUDA_HOME
-        ENV NVSDKCOMPUTE_ROOT
-        ENV ATISTREAMSDKROOT
-        PATH_SUFFIXES
-        "AMD APP/lib/x86_64"
-        lib/x86_64
-        lib/x64
-        lib64
-        OPENCL/common/lib/x64)
-endif()
-
-_FIND_OPENCL_VERSION()
-
-set(OPENCL_LIBRARIES ${OPENCL_LIBRARY})
-set(OPENCL_INCLUDE_DIRS ${OPENCL_INCLUDE_DIR})
-
-include(FindPackageHandleStandardArgs)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(OPENCL
-  REQUIRED_VARS OPENCL_LIBRARY OPENCL_INCLUDE_DIR
-  VERSION_VAR OPENCL_VERSION_STRING)
-
-mark_as_advanced(
-  OPENCL_INCLUDE_DIR
-  OPENCL_LIBRARY)
-#=============================================================================
-# Copyright 2014 Matthaeus G. Chajdas
-#
-# Distributed under the OSI-approved BSD License (the "License");
-# see accompanying file Copyright.txt for details.
-#
-# This software is distributed WITHOUT ANY WARRANTY; without even the
-# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-# See the License for more information.
-#=============================================================================
-# cmake 3.1.0 Copyright.txt file content is attached below:
-#
-#CMake - Cross Platform Makefile Generator
-#Copyright 2000-2014 Kitware, Inc.
-#Copyright 2000-2011 Insight Software Consortium
-#All rights reserved.
-#
-#Redistribution and use in source and binary forms, with or without
-#modification, are permitted provided that the following conditions
-#are met:
-#
-#* Redistributions of source code must retain the above copyright
-#  notice, this list of conditions and the following disclaimer.
-#
-#* Redistributions in binary form must reproduce the above copyright
-#  notice, this list of conditions and the following disclaimer in the
-#  documentation and/or other materials provided with the distribution.
-#
-#* Neither the names of Kitware, Inc., the Insight Software Consortium,
-#  nor the names of their contributors may be used to endorse or promote
-#  products derived from this software without specific prior written
-#  permission.
-#
-#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-#"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-#LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-#A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-#HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-#SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-#LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-#DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-#THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-#(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-#OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-#------------------------------------------------------------------------------
-#
-#The above copyright and license notice applies to distributions of
-#CMake in source and binary form.  Some source files contain additional
-#notices of original copyright by their contributors; see each source
-#for details.  Third-party software packages supplied with CMake under
-#compatible licenses provide their own copyright notices documented in
-#corresponding subdirectories.
-#
-#------------------------------------------------------------------------------
-#
-#CMake was initially developed by Kitware with the following sponsorship:
-#
-# * National Library of Medicine at the National Institutes of Health
-#   as part of the Insight Segmentation and Registration Toolkit (ITK).
-#
-# * US National Labs (Los Alamos, Livermore, Sandia) ASC Parallel
-#   Visualization Initiative.
-#
-# * National Alliance for Medical Image Computing (NAMIC) is funded by the
-#   National Institutes of Health through the NIH Roadmap for Medical Research,
-#   Grant U54 EB005149.
-#
-# * Kitware, Inc.
index 48bf0baafccb62fc318e186b1e6f113f9929db12..4b77330a12c97cd0255b8222e2119e7f1edb39fa 100644 (file)
@@ -1,7 +1,7 @@
 #
 # This file is part of the GROMACS molecular simulation package.
 #
-# Copyright (c) 2012,2013,2014,2015, by the GROMACS development team, led by
+# Copyright (c) 2012,2013,2014,2015,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.
@@ -36,15 +36,13 @@ if(GMX_DOUBLE)
     message(FATAL_ERROR "OpenCL not available in double precision - Yet!")
 endif()
 
-# Look for OpenCL
-# TODO: FindOpenCL module is available in cmake starting with version 3.1.0.
-# A modified version of that module is used here.
-# Remove FindOpenCL.cmake file when GROMACS switches to cmake 3.1.0 or higher.
+# for some reason FindOpenCL checks CUDA_PATH but not CUDA_HOME
+set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH};$ENV{CUDA_HOME})
 find_package(OpenCL)
 
-if (OPENCL_FOUND)
-    if (OPENCL_VERSION_STRING VERSION_LESS REQUIRED_OPENCL_MIN_VERSION)
-        message(FATAL_ERROR "OpenCL " "${OPENCL_VERSION_STRING}" " is not supported. OpenCL version " "${REQUIRED_OPENCL_MIN_VERSION}" " or newer is required.")
+if (OpenCL_FOUND)
+    if (OpenCL_VERSION_STRING VERSION_LESS REQUIRED_OPENCL_MIN_VERSION)
+        message(FATAL_ERROR "OpenCL " "${OpenCL_VERSION_STRING}" " is not supported. OpenCL version " "${REQUIRED_OPENCL_MIN_VERSION}" " or newer is required.")
         return ()
     endif()
 else ()
@@ -54,7 +52,7 @@ endif()
 
 # Tell compiler to hide warnings for comments caused by cl_gl_ext.h on Linux
 if (UNIX)
-    set(OPENCL_DEFINITIONS ${OPENCL_DEFINITIONS} " -Wno-comment")
+    set(OpenCL_DEFINITIONS ${OpenCL_DEFINITIONS} " -Wno-comment")
 endif()
 
 # Yes Virginia, Darwin kernel version 14.4 corresponds to OS X 10.4.
@@ -62,9 +60,9 @@ if(APPLE AND ${CMAKE_SYSTEM_VERSION} VERSION_LESS "14.4")
         message(WARNING "OS X prior to version 10.10.4 produces incorrect AMD OpenCL code at runtime. You will not be able to use AMD GPUs on this host unless you upgrade your operating system.")
 endif()
 
-add_definitions(${OPENCL_DEFINITIONS})
+add_definitions(${OpenCL_DEFINITIONS})
 
-include_directories(SYSTEM ${OPENCL_INCLUDE_DIRS})
+include_directories(SYSTEM ${OpenCL_INCLUDE_DIRS})
 
 macro(gmx_gpu_setup)
     # no OpenMP is no good!
index 21a31e23b30cc861776f29acb8de9d78f1c436d9..7712e6f46bcb56c9c4bf6c21fabcc2a80bb64058 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2012,2013,2014,2015,2017, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014,2015,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.
 #define CUDA_COMPILER_FLAGS "@CUDA_COMPILER_FLAGS@"
 
 /** OpenCL include dir */
-#define OPENCL_INCLUDE_DIR "@OPENCL_INCLUDE_DIR@"
+#define OPENCL_INCLUDE_DIR "@OpenCL_INCLUDE_DIR@"
 
 /** OpenCL library */
-#define OPENCL_LIBRARY "@OPENCL_LIBRARY@"
+#define OPENCL_LIBRARY "@OpenCL_LIBRARY@"
 
 /** OpenCL version */
-#define OPENCL_VERSION_STRING "@OPENCL_VERSION_STRING@"
+#define OPENCL_VERSION_STRING "@OpenCL_VERSION_STRING@"
index a88015302587636c593e91149a664756f292b4da..bd23b141e59e751490d666282d5952eb834d8840 100644 (file)
@@ -1,7 +1,7 @@
 #
 # This file is part of the GROMACS molecular simulation package.
 #
-# Copyright (c) 2010,2011,2012,2013,2014,2015,2016,2017, by the GROMACS development team, led by
+# Copyright (c) 2010,2011,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.
@@ -206,7 +206,7 @@ target_link_libraries(libgromacs
                       ${GMX_COMMON_LIBRARIES}
                       ${FFT_LIBRARIES} ${LINEAR_ALGEBRA_LIBRARIES}
                       ${LMFIT_LIBRARIES_TO_LINK}
-                      ${THREAD_LIB} ${GMX_SHARED_LINKER_FLAGS} ${OPENCL_LIBRARIES}
+                      ${THREAD_LIB} ${GMX_SHARED_LINKER_FLAGS} ${OpenCL_LIBRARIES}
                       ${GMX_STDLIB_LIBRARIES}
                       PUBLIC
                       ${GMX_PUBLIC_LIBRARIES}
index 8b4b8bc16895a0d0c872d836b1b0a01682bbb3ce..b6c24d0bf1dde5a19a554b91f85b1e8fec6fbeff 100644 (file)
@@ -1,7 +1,7 @@
 #
 # This file is part of the GROMACS molecular simulation package.
 #
-# Copyright (c) 2017, by the GROMACS development team, led by
+# Copyright (c) 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.
@@ -93,5 +93,5 @@ if(GMX_USE_CUDA)
     target_link_libraries(gpu_utils-test gpu_utilstest_cuda)
 endif()
 if(GMX_USE_OPENCL)
-    target_link_libraries(gpu_utils-test ${OPENCL_LIBRARIES})
+    target_link_libraries(gpu_utils-test ${OpenCL_LIBRARIES})
 endif()