diff --git a/CMakeLists.txt b/CMakeLists.txt index 044a71aec..63ba4f9e4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,3 +7,6 @@ set(WITH_2DECOMPFFT ON CACHE BOOL add_subdirectory(src) add_subdirectory(tests) + +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") +include(SelectBackend) diff --git a/cmake/SelectBackend.cmake b/cmake/SelectBackend.cmake new file mode 100644 index 000000000..5cd205326 --- /dev/null +++ b/cmake/SelectBackend.cmake @@ -0,0 +1,25 @@ +# Defines the backend selection for x3d2. +# +# Currently available backends +# - GPU/CUDAFortran (nvfort only) +# - CPU/OMP (all) + +set(X3D2_BACKEND_OPTIONS "OMP/CPU") +if (${CMAKE_Fortran_COMPILER_ID} STREQUAL "PGI" OR + ${CMAKE_Fortran_COMPILER_ID} STREQUAL "NVHPC") + set(X3D2_BACKEND_DEFAULT "CUDA/GPU") + list(APPEND X3D2_BACKEND_OPTIONS ${X3D2_BACKEND_DEFAULT}) +else() + set(X3D2_BACKEND_DEFAULT "OMP/CPU") +endif() + +set(X3D2_BACKEND + ${X3D2_BACKEND_DEFAULT} + CACHE + STRING + "Select the backend. Current options are ${X3D2_BACKEND_OPTIONS}") +set_property(CACHE + X3D2_BACKEND + PROPERTY STRINGS + ${X3D2_BACKEND_OPTIONS}) +message(STATUS "Using ${X3D2_BACKEND} backend")