Skip to content

Commit

Permalink
Add UAMMDSetup.cmake (#42)
Browse files Browse the repository at this point in the history
* Add the uammd_setup_target cmake function

* Update UAMMDSetup.cmake

* test

* test

* test

* test

* test

* cleanup

* Tweak

* Update

* update

* Update

* Update findUAMMD and UAMMDSetup

* Update examples

* Remove old code

* Update some CMakeLists.txt

* Update

* Try CI fix

* Disable CUDA 10
  • Loading branch information
RaulPPelaez authored Feb 13, 2025
1 parent ad96364 commit 068b3a9
Show file tree
Hide file tree
Showing 23 changed files with 113 additions and 584 deletions.
23 changes: 3 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,15 @@ defaults:
jobs:
build:
name: ${{ matrix.name }}
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:

# Oldest supported versions
- name: Linux (CUDA 10.2)
cuda: "10.*"
gcc: "7.*"
cuda12: 'false'

# Latest supported versions
- name: Linux (CUDA 12)
cuda: "12.*"
gcc: "11.*"
cuda12: 'true'
gcc: "13.*"
steps:
- name: Check out
uses: actions/checkout@v2
Expand All @@ -58,17 +50,8 @@ jobs:
sudo apt-get autoclean -y >& /dev/null
sudo docker image prune --all --force
df -h
- name: Prepare dependencies (CUDA <12)
if: ${{ matrix.cuda12 == 'false'}}
run: |
sed -i -e "/cuda-version/c\ - cudatoolkit-dev ${{ matrix.cuda }}" \
-e "/cuda-libraries-dev/d" \
-e "/cuda-nvcc/d" \
-e "/gxx_linux-64/c\ - gxx_linux-64 ${{ matrix.gcc }}\n - gcc_linux-64" \
environment.yml
- name: Prepare dependencies (CUDA >=12)
if: ${{ matrix.cuda12 == 'true' }}
- name: Prepare dependencies
run: |
sed -i -e "/cuda-version/c\ - cuda-version ${{ matrix.cuda }}" \
-e "/gxx_linux-64/c\ - gxx_linux-64 ${{ matrix.gcc }}" \
Expand Down
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ endforeach()

# Install FindUAMMD.cmake
install(FILES cmake/FindUAMMD.cmake DESTINATION share/cmake/Modules)

include(${CMAKE_CURRENT_LIST_DIR}/cmake/UAMMDSetup.cmake)
install(FILES
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/UAMMDSetup.cmake"
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cmake/UAMMD
)
30 changes: 14 additions & 16 deletions cmake/FindUAMMD.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,22 @@
# find_package(UAMMD REQUIRED)
# include_directories(${UAMMD_INCLUDE_DIRS})
# The include folder can be in the following locations:
# 1. In the system include folder: /usr/include/uammd
# 2. In the user's home folder: ~/uammd/include/uammd
# 3. In the conda environment: $ENV{CONDA_PREFIX}/include/uammd

# First, look for the include folder in the system.
find_path(UAMMD_INCLUDE_DIRS uammd.cuh HINTS /usr/include/uammd)

# If the include folder is not found, look for it in the user's home folder.
if(NOT UAMMD_INCLUDE_DIRS)
find_path(UAMMD_INCLUDE_DIRS uammd.cuh HINTS $ENV{HOME}/uammd/include/uammd)
endif()

# If the include folder is not found, look for it in the conda environment.
if(NOT UAMMD_INCLUDE_DIRS)
find_path(UAMMD_INCLUDE_DIRS uammd.cuh HINTS $ENV{CONDA_PREFIX}/include/uammd)
endif()
# - In the CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}/include/uammd
# - In the CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}/include/uammd
# - In the system include folder: /usr/include/uammd
# - In the user's home folder: ~/uammd/include/uammd
# - In the conda environment: $ENV{CONDA_PREFIX}/include/uammd
# - In the root folder of the project (we are now inside the cmake/ folder).
find_path(UAMMD_INCLUDE_DIRS uammd.cuh HINTS
${CMAKE_PREFIX_PATH}/include/uammd
${CMAKE_INSTALL_PREFIX}/include/uammd
$ENV{CONDA_PREFIX}/include/uammd
/usr/include/uammd
$ENV{HOME}/uammd/include/uammd
../src)

# Add also the folder UAMMD_INCLUDE_DIRS/third_party to the include directories.
if(UAMMD_INCLUDE_DIRS)
set(UAMMD_INCLUDE_DIRS ${UAMMD_INCLUDE_DIRS} ${UAMMD_INCLUDE_DIRS}/third_party)
endif()
include(UAMMDSetup)
54 changes: 54 additions & 0 deletions cmake/UAMMDSetup.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
include_guard(GLOBAL)

function(uammd_setup_target target_name)
if (NOT CMAKE_CUDA_COMPILER)
message(FATAL_ERROR "CUDA is required but not enabled! \
You must call enable_language(CUDA) in your main CMakeLists.txt BEFORE calling uammd_setup_target().")
endif()
if (NOT TARGET BLAS::BLAS)
message(FATAL_ERROR "BLAS is required but not enabled! \
You must call find_package(BLAS) in your main CMakeLists.txt BEFORE calling uammd_setup_target().")
endif()
# Ensure the target has C++ and CUDA standards
target_compile_features(${target_name} PUBLIC cxx_std_14)
target_compile_features(${target_name} PUBLIC cuda_std_14)

if(CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA")
target_compile_options(${target_name} PRIVATE --expt-relaxed-constexpr -extended-lambda)
endif()

# Find and link necessary libraries
if(BLAS_FOUND)
message(DEBUG "MKL environment detected")
target_compile_definitions(${target_name} PUBLIC USE_MKL)
target_link_libraries(${target_name} PUBLIC BLAS::BLAS)
find_path(BLAS_INCLUDE_DIRS mkl.h PATHS $ENV{CONDA_PREFIX}/include /usr/include /usr/local/include $ENV{MKLROOT}/include $ENV{BLAS_HOME}/include)
else()
unset(BLA_VENDOR)
find_package(LAPACK REQUIRED)
find_package(LAPACKE REQUIRED)
target_link_libraries(${target_name} PUBLIC ${LAPACK_LIBRARIES} ${LAPACKE_LIBRARIES})
endif()

# Set include paths
target_include_directories(${target_name} PUBLIC ${BLAS_INCLUDE_DIRS} ${LAPACKE_INCLUDE_DIRS})
target_link_libraries(${target_name} PUBLIC ${CUDA_LIBRARY} cufft cublas cusolver curand)
if (NOT DEFINED UAMMD_INCLUDE_DIRS)
if (DEFINED uammd_SOURCE_DIR)
set(UAMMD_INCLUDE_DIRS "${uammd_SOURCE_DIR}/src" "${uammd_SOURCE_DIR}/src/third_party")
else()
find_path(UAMMD_INCLUDE_DIR
NAMES uammd.h
PATHS ${CMAKE_INSTALL_PREFIX}/include ${CMAKE_PREFIX_PATH}/include
NO_DEFAULT_PATH
)
if (UAMMD_INCLUDE_DIR)
set(UAMMD_INCLUDE_DIRS "${UAMMD_INCLUDE_DIR}")
else()
message(FATAL_ERROR "Could not find UAMMD include directories! \
Make sure UAMMD is installed or fetched correctly.")
endif()
endif()
endif()
target_include_directories(${target_name} PUBLIC ${UAMMD_INCLUDE_DIRS})
endfunction()
59 changes: 6 additions & 53 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,62 +1,15 @@
cmake_minimum_required(VERSION 3.22)
project(examples)
enable_language(CUDA)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/../cmake/")
set(CMAKE_BUILD_TYPE Release)

#add_compile_definitions(PUBLIC MAXLOGLEVEL=15)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
message(${CMAKE_MODULE_PATH})
find_package(UAMMD REQUIRED)
find_package(BLAS REQUIRED)
# #add_compile_definitions(PUBLIC MAXLOGLEVEL=15)
# #add_compile_definitions(PUBLIC DOUBLE_PRECISION)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CUDA_STANDARD 14)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
set(CMAKE_CUDA_SEPARABLE_COMPILATION OFF)
#add_compile_definitions(PUBLIC DOUBLE_PRECISION)
set(UAMMD_INCLUDE ../src ../src/third_party)
set(BLA_STATIC OFF)
set(BLA_VENDOR Intel10_64lp)
find_package(BLAS)
if(BLAS_FOUND)
message("mkl environment detected")
add_compile_definitions(PUBLIC USE_MKL)
link_libraries(
BLAS::BLAS
)
find_path(BLAS_INCLUDE_DIRS mkl.h
$ENV{CONDA_PREFIX}/include
/usr/include
/usr/local/include
$ENV{MKLROOT}/include
$ENV{BLAS_HOME}/include
)
else()
unset(BLA_VENDOR)
find_package(LAPACK REQUIRED)
find_package(LAPACKE REQUIRED)
find_package(BLAS REQUIRED)
link_libraries(${LAPACK_LIBRARIES} ${LAPACKE_LIBRARIES})
find_path(BLAS_INCLUDE_DIRS cblas.h
$ENV{CONDA_PREFIX}/include
/usr/include
/usr/local/include
$ENV{MKLROOT}/include
$ENV{BLAS_HOME}/include
)
find_path(LAPACKE_INCLUDE_DIRS lapacke.h
$ENV{CONDA_PREFIX}/include
/usr/include
/usr/local/include
$ENV{MKLROOT}/include
$ENV{LAPACKE_HOME}/include
)

endif()

include_directories(${UAMMD_INCLUDE} ${BLAS_INCLUDE_DIRS} ${LAPACKE_INCLUDE_DIRS})
link_libraries(${CUDA_LIBRARY})
if(CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA")
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --expt-relaxed-constexpr -extended-lambda")
endif()

add_subdirectory(generic_md)
add_subdirectory(advanced)
add_subdirectory(basic_concepts)
Expand Down
1 change: 1 addition & 0 deletions examples/advanced/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ foreach( testsourcefile ${SOURCES} )
# I used a simple string replace, to cut off .cpp.
string( REPLACE ".cu" "" testname ${testsourcefile} )
add_executable( ${testname} ${testsourcefile} )
uammd_setup_target( ${testname} )
set_target_properties(${testname} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
endforeach( testsourcefile ${SOURCES} )
5 changes: 1 addition & 4 deletions examples/basic_concepts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ foreach( testsourcefile ${SOURCES} )
# I used a simple string replace, to cut off .cpp.
string( REPLACE ".cu" "" testname ${testsourcefile} )
add_executable( ${testname} ${testsourcefile} )
uammd_setup_target( ${testname} )
set_target_properties(${testname} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
endforeach( testsourcefile ${SOURCES} )


target_link_libraries(12-your-first-integrator cufft)
target_link_libraries(13-your-first-interactor cufft)
Loading

0 comments on commit 068b3a9

Please sign in to comment.