Skip to content

Commit

Permalink
CMake: Use CMAKE_CUDA_ARCHITECTURES rather than CUDA_ARCH
Browse files Browse the repository at this point in the history
  • Loading branch information
ptheywood committed Nov 28, 2022
1 parent 922ea7a commit 64997bb
Show file tree
Hide file tree
Showing 9 changed files with 321 additions and 148 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/Manylinux2014.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ jobs:
-Werror=dev
-DCMAKE_WARN_DEPRECATED="OFF"
-DFLAMEGPU_WARNINGS_AS_ERRORS="OFF"
-DCUDA_ARCH="${{ env.CUDA_ARCH }}"
-DCMAKE_CUDA_ARCHITECTURES="${{ env.CUDA_ARCH }}"
-DGLEW_USE_STATIC_LIBS="${{ env.USE_STATIC_GLEW }}"
-DOpenGL_GL_PREFERENCE:STRING=LEGACY
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/Ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:
-Werror=dev
-DCMAKE_WARN_DEPRECATED="OFF"
-DFLAMEGPU_WARNINGS_AS_ERRORS="ON"
-DCUDA_ARCH="${{ env.CUDA_ARCH }}"
-DCMAKE_CUDA_ARCHITECTURES="${{ env.CUDA_ARCH }}"
- name: Build
working-directory: ${{ env.BUILD_DIR }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/Windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
-Werror=dev
-DCMAKE_WARN_DEPRECATED="OFF"
-DFLAMEGPU_WARNINGS_AS_ERRORS="ON"
-DCUDA_ARCH="${{ env.CUDA_ARCH }}"
-DCMAKE_CUDA_ARCHITECTURES="${{ env.CUDA_ARCH }}"
- name: Build
working-directory: ${{ env.BUILD_DIR }}
Expand Down
3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,5 @@ mark_as_advanced(CMAKE_USE_FOLDERS)
option(FLAMEGPU_ALLOW_LINT_ONLY "Allow the project to be configured for lint-only builds" OFF)
mark_as_advanced(FLAMEGPU_ALLOW_LINT_ONLY)

# Control target CUDA_ARCH to compile for
SET(CUDA_ARCH "${CUDA_ARCH}" CACHE STRING "List of CUDA Architectures to target. E.g. 61;70" FORCE)

# Add the src subdirectory cmake project.
add_subdirectory(src "${PROJECT_BINARY_DIR}/FLAMEGPU_visualiser")
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ To build the visualiser under linux in Release mode using the command line:
# Create a build directory
mkdir -p build
cd build
# Configure CMake, i.e. for Release builds for Pascal and newer GPUs
cmake .. -DCUDA_ARCH=61 -DCMAKE_BUILD_TYPE=Release
# Configure CMake, i.e. for Release builds for consumer Pascal and newer GPUs
cmake .. -DCMAKE_CUDA_ARCHITECTURES=61 -DCMAKE_BUILD_TYPE=Release
# Build all targets using 8 threads.
cmake --build . --target all -j 8
# Or directly via make
Expand Down
299 changes: 299 additions & 0 deletions cmake/CUDAArchitectures.cmake

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions cmake/CUDAArchitecturesProjectInclude.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# CMake file to be injected into a project via CMAKE_PROJECT<PROJECT-NAME>_INCLUDE
# If CUDA is enabled, call a CMake function which gracefully sets a library-useful

# Set a locally scoped cmake variable, to alter the error message within.
set(flamegpu_visualiser_IN_PROJECT_INCLUDE ON)
# Call the appropraite command to set CMAKE_CUDA_ARCHITECTURES to the user-provided value, the exising value, or a sane libray-provided defualt
flamegpu_visualiser_set_cuda_architectures()
# Unset the variable used to alter behaviour in set_cuda_architectures
unset(flamegpu_visualiser_IN_PROJECT_INCLUDE)
134 changes: 0 additions & 134 deletions cmake/cuda_arch.cmake

This file was deleted.

14 changes: 8 additions & 6 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ if (NOT GIT_FOUND)
message(FATAL_ERROR "git is required for building")
endif ()

# Record the user-provided CMAKE_CUDA_ARCHITECTURES if provided, to be applied later
include(${CMAKE_CURRENT_SOURCE_DIR}/../cmake/CUDAArchitectures.cmake)
flamegpu_visualiser_init_cuda_architectures()

# Set the project name, but do not specify languages immediately so we can have lint only builds.
project(flamegpu_visualiser)
project(flamegpu_visualiser LANGUAGES NONE)

# handle cpplint.
include(${CMAKE_CURRENT_LIST_DIR}/../cmake/cpplint.cmake)
Expand All @@ -23,6 +27,9 @@ if(CMAKE_CUDA_COMPILER)
enable_language(C)
enable_language(CXX)
enable_language(CUDA)
# Apply CMAKE_CUDA_ARCHITECTUES if the language was enabled
flamegpu_visualiser_set_cuda_architectures()
message(STATUS "Using CUDA_ARCHITECTURES ${CMAKE_CUDA_ARCHITECTURES}")
endif()

# Openg GL is required, unless doing a lint only build.
Expand Down Expand Up @@ -213,9 +220,6 @@ set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)

# CUDA_ARCH is used to control the compute capabilities to build for, via cmake/cuda_arch.cmake.
# @todo - use the same value as the parent project if imported.
include(${CMAKE_CURRENT_LIST_DIR}/../cmake/cuda_arch.cmake)
# Import function to set compiler settings for the target
include(${CMAKE_CURRENT_LIST_DIR}/../cmake/CommonCompilerSettings.cmake)

Expand All @@ -234,8 +238,6 @@ set_property(TARGET ${PROJECT_NAME} PROPERTY CUDA_STANDARD_REQUIRED ON)
flamegpu_visuaiser_enable_compiler_warnings(TARGET "${PROJECT_NAME}")
# Apply common compiler settings
flamegpu_visualiser_common_compiler_settings(TARGET "${PROJECT_NAME}")
# Set the cuda gencodes, potentially using the user-provided CUDA_ARCH
flamegpu_set_cuda_gencodes(TARGET "${PROJECT_NAME}")

# Prevent fscanf warnings for msvc.
if (WIN32)
Expand Down

0 comments on commit 64997bb

Please sign in to comment.