Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-detect compilation settings based on present compilers/libraries #435

Merged
merged 5 commits into from Jan 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 8 additions & 13 deletions CMakeLists.txt
Expand Up @@ -4,15 +4,19 @@ project(Ginkgo LANGUAGES C CXX VERSION 1.1.1 DESCRIPTION "A numerical linear alg
set(Ginkgo_VERSION_TAG "develop")
set(PROJECT_VERSION_TAG ${Ginkgo_VERSION_TAG})

# Determine which executors can be compiled
include(cmake/hip_path.cmake)
include(cmake/autodetect_executors.cmake)

# Ginkgo configuration options
option(GINKGO_DEVEL_TOOLS "Add development tools to the build system" ON)
option(GINKGO_BUILD_TESTS "Generate build files for unit tests" ON)
option(GINKGO_BUILD_EXAMPLES "Build Ginkgo's examples" ON)
option(GINKGO_BUILD_BENCHMARKS "Build Ginkgo's benchmarks" ON)
option(GINKGO_BUILD_REFERENCE "Compile reference CPU kernels" ON)
option(GINKGO_BUILD_OMP "Compile OpenMP kernels for CPU" OFF)
option(GINKGO_BUILD_CUDA "Compile kernels for NVIDIA GPUs" OFF)
option(GINKGO_BUILD_HIP "Compile kernels for AMD or NVIDIA GPUs" OFF)
option(GINKGO_BUILD_OMP "Compile OpenMP kernels for CPU" ${GINKGO_HAS_OMP})
option(GINKGO_BUILD_CUDA "Compile kernels for NVIDIA GPUs" ${GINKGO_HAS_CUDA})
option(GINKGO_BUILD_HIP "Compile kernels for AMD or NVIDIA GPUs" ${GINKGO_HAS_HIP})
option(GINKGO_BUILD_DOC "Generate documentation" OFF)
option(GINKGO_SKIP_DEPENDENCY_UPDATE
"Do not update dependencies each time the project is rebuilt" ON)
Expand Down Expand Up @@ -120,16 +124,7 @@ set(GINKGO_HIP_PLATFORM_NVCC 0)
set(GINKGO_HIP_PLATFORM_HCC 0)

if (GINKGO_BUILD_HIP)
if(NOT DEFINED HIP_PATH)
if(NOT DEFINED ENV{HIP_PATH})
set(HIP_PATH "/opt/rocm/hip" CACHE PATH "Path to which HIP has been installed")
set(ENV{HIP_PATH} ${HIP_PATH})
else()
set(HIP_PATH $ENV{HIP_PATH} CACHE PATH "Path to which HIP has been installed")
endif()
endif()

find_program(GINKGO_HIPCONFIG_PATH hipconfig HINTS "${HIP_PATH}/bin")
# GINKGO_HIPCONFIG_PATH and HIP_PATH are set in cmake/hip_path.cmake
if(GINKGO_HIPCONFIG_PATH)
execute_process(COMMAND ${GINKGO_HIPCONFIG_PATH} --platform OUTPUT_VARIABLE GINKGO_HIP_PLATFORM)
elseif(DEFINED ENV{HIP_PLATFORM})
Expand Down
16 changes: 10 additions & 6 deletions INSTALL.md
Expand Up @@ -28,11 +28,13 @@ Ginkgo adds the following additional switches to control what is being built:
* `-DGINKGO_BUILD_REFERENCE={ON, OFF}` build reference implementations of the
kernels, useful for testing, default is `ON`
* `-DGINKGO_BUILD_OMP={ON, OFF}` builds optimized OpenMP versions of the kernels,
default is `OFF`
default is `ON` if the selected C++ compiler supports OpenMP, `OFF` otherwise.
* `-DGINKGO_BUILD_CUDA={ON, OFF}` builds optimized cuda versions of the kernels
(requires CUDA), default is `OFF`
(requires CUDA), default is `ON` if a CUDA compiler could be detected,
`OFF` otherwise.
* `-DGINKGO_BUILD_HIP={ON, OFF}` builds optimized HIP versions of the kernels
(requires HIP), default is `OFF`
(requires HIP), default is `ON` if an installation of HIP could be detected,
`OFF` otherwise.
* `-DGINKGO_HIP_AMDGPU="gpuarch1;gpuarch2"` the amdgpu_target(s) variable
passed to hipcc for the `hcc` HIP backend. The default is none (auto).
* `-DGINKGO_BUILD_DOC={ON, OFF}` creates an HTML version of Ginkgo's documentation
Expand Down Expand Up @@ -104,7 +106,7 @@ For example, to build everything (in debug mode), use:
```cmake
cmake -G "Unix Makefiles" -H. -BDebug -DCMAKE_BUILD_TYPE=Debug -DGINKGO_DEVEL_TOOLS=ON \
-DGINKGO_BUILD_TESTS=ON -DGINKGO_BUILD_REFERENCE=ON -DGINKGO_BUILD_OMP=ON \
-DGINKGO_BUILD_CUDA=ON -DGINKGO_BUILD_HIP=ON \
-DGINKGO_BUILD_CUDA=ON -DGINKGO_BUILD_HIP=ON
cmake --build Debug
```

Expand All @@ -114,8 +116,10 @@ generators. Other CMake generators are untested.
### Building Ginkgo with HIP support
Ginkgo provides a [HIP](https://github.com/ROCm-Developer-Tools/HIP) backend.
This allows to compile optimized versions of the kernels for either AMD or
NVIDIA GPUs. To build Ginkgo with this backend, use the CMake option
`-DGINKGO_BUILD_HIP=ON`.
NVIDIA GPUs. The CMake configuration step will try to auto-detect the presence
of HIP either at `/opt/rocm/hip` or at the path specified by `HIP_PATH` as a
CMake parameter (`-DHIP_PATH=`) or environment variable (`export HIP_PATH=`),
unless `-DGINKGO_BUILD_HIP=ON/OFF` is set explicitly.

#### Correctly installing HIP toolkits and dependencies for Ginkgo
In general, Ginkgo's HIP backend requires the following packages:
Expand Down
27 changes: 27 additions & 0 deletions cmake/autodetect_executors.cmake
@@ -0,0 +1,27 @@
set(GINKGO_HAS_OMP OFF)
set(GINKGO_HAS_CUDA OFF)
set(GINKGO_HAS_HIP OFF)
find_package(OpenMP)
include(CheckLanguage)
check_language(CUDA)

if(OpenMP_CXX_FOUND)
if(NOT DEFINED GINKGO_BUILD_OMP)
message(STATUS "Enabling OpenMP executor")
endif()
set(GINKGO_HAS_OMP ON)
endif()
upsj marked this conversation as resolved.
Show resolved Hide resolved

if(CMAKE_CUDA_COMPILER)
if(NOT DEFINED GINKGO_BUILD_CUDA)
message(STATUS "Enabling CUDA executor")
endif()
set(GINKGO_HAS_CUDA ON)
endif()

if(GINKGO_HIPCONFIG_PATH)
if(NOT DEFINED GINKGO_BUILD_HIP)
message(STATUS "Enabling HIP executor")
endif()
set(GINKGO_HAS_HIP ON)
endif()
13 changes: 13 additions & 0 deletions cmake/hip_path.cmake
@@ -0,0 +1,13 @@
if(NOT DEFINED HIP_PATH)
if(NOT DEFINED ENV{HIP_PATH})
set(HIP_PATH "/opt/rocm/hip" CACHE PATH "Path to which HIP has been installed")
set(ENV{HIP_PATH} ${HIP_PATH})
else()
set(HIP_PATH $ENV{HIP_PATH} CACHE PATH "Path to which HIP has been installed")
endif()
endif()

find_program(GINKGO_HIPCONFIG_PATH hipconfig HINTS "${HIP_PATH}/bin")
if(GINKGO_HIPCONFIG_PATH)
message(STATUS "Found hipconfig: ${GINKGO_HIPCONFIG_PATH}")
endif()