Skip to content

Commit 371a064

Browse files
author
Kevin
committed
Enhance CMake configuration for CUDA and HIP support, add new examples
- Updated CMakeLists.txt to conditionally include CUDA and HIP source files for various examples. - Added new example executables for advanced threading, dynamic memory, and FFT implementations under HIP. - Improved installation targets to accommodate new examples based on the selected GPU platform. - Introduced platform-agnostic utility functions in common headers for better code maintainability.
1 parent 46131a4 commit 371a064

77 files changed

Lines changed: 11369 additions & 209 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakeLists.txt

Lines changed: 99 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -105,57 +105,109 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
105105

106106
# Common utilities library
107107
add_library(cuda_common STATIC
108-
src/common/cuda_utils.cu
109108
src/common/timer.cpp
110109
src/common/helper_functions.cpp
111110
)
112111

113-
target_link_libraries(cuda_common CUDA::cudart)
112+
# Add platform-specific source files
113+
if(USE_CUDA)
114+
target_sources(cuda_common PRIVATE src/common/cuda_utils.cu)
115+
target_link_libraries(cuda_common ${GPU_RUNTIME_LIB})
116+
elseif(USE_HIP)
117+
target_sources(cuda_common PRIVATE src/common/hip_utils.cpp)
118+
target_link_libraries(cuda_common ${GPU_RUNTIME_LIB})
119+
endif()
114120

115-
# Example 1: Vector Addition
116-
add_executable(vector_addition
117-
src/01_vector_addition/vector_addition.cu
118-
src/01_vector_addition/main.cpp
119-
)
120-
target_link_libraries(vector_addition cuda_common CUDA::cudart)
121+
# Example 1: Vector Addition (has HIP version)
122+
if(USE_CUDA)
123+
add_executable(vector_addition
124+
src/01_vector_addition/vector_addition.cu
125+
src/01_vector_addition/main.cpp
126+
)
127+
elseif(USE_HIP)
128+
add_executable(vector_addition
129+
src/01_vector_addition/vector_addition_hip.hip
130+
src/01_vector_addition/main_hip.cpp
131+
)
132+
endif()
133+
target_link_libraries(vector_addition cuda_common ${GPU_RUNTIME_LIB})
121134

122-
# Example 2: Matrix Multiplication
123-
add_executable(matrix_multiplication
124-
src/02_matrix_multiplication/matrix_mul.cu
125-
src/02_matrix_multiplication/main.cpp
126-
)
127-
target_link_libraries(matrix_multiplication cuda_common CUDA::cudart CUDA::cublas)
135+
# Note: Examples 2-5 don't have HIP versions yet, so they're skipped for HIP builds
128136

129-
# Example 3: Parallel Reduction
130-
add_executable(parallel_reduction
131-
src/03_parallel_reduction/reduction.cu
132-
src/03_parallel_reduction/main.cpp
133-
)
134-
target_link_libraries(parallel_reduction cuda_common CUDA::cudart)
137+
# Example 7: Advanced Threading (has HIP version)
138+
if(USE_CUDA)
139+
# Skip for now - no CUDA version
140+
elseif(USE_HIP)
141+
add_executable(advanced_threading
142+
src/07_advanced_threading/advanced_threading_hip.hip
143+
src/07_advanced_threading/main_hip.cpp
144+
)
145+
target_link_libraries(advanced_threading cuda_common ${GPU_RUNTIME_LIB})
146+
endif()
135147

136-
# Example 4: 2D Convolution
137-
add_executable(convolution_2d
138-
src/04_convolution_2d/convolution.cu
139-
src/04_convolution_2d/main.cpp
140-
)
141-
target_link_libraries(convolution_2d cuda_common CUDA::cudart)
148+
# Example 8: Dynamic Memory (has HIP version)
149+
if(USE_CUDA)
150+
# Skip for now - no CUDA version
151+
elseif(USE_HIP)
152+
add_executable(dynamic_memory
153+
src/08_dynamic_memory/dynamic_memory_hip.hip
154+
src/08_dynamic_memory/main_hip.cpp
155+
)
156+
target_link_libraries(dynamic_memory cuda_common ${GPU_RUNTIME_LIB})
157+
endif()
142158

143-
# Example 5: Monte Carlo Simulation
144-
add_executable(monte_carlo
145-
src/05_monte_carlo/monte_carlo.cu
146-
src/05_monte_carlo/main.cpp
147-
)
148-
target_link_libraries(monte_carlo cuda_common CUDA::cudart CUDA::curand)
159+
# Example 9: Warp Primitives (has HIP version)
160+
if(USE_CUDA)
161+
# Skip for now - no CUDA version
162+
elseif(USE_HIP)
163+
add_executable(warp_primitives
164+
src/09_warp_primitives/warp_primitives_hip.hip
165+
src/09_warp_primitives/main_hip.cpp
166+
)
167+
target_link_libraries(warp_primitives cuda_common ${GPU_RUNTIME_LIB})
168+
endif()
169+
170+
# Example 10: Advanced FFT (has HIP version)
171+
if(USE_CUDA)
172+
# Skip for now - no CUDA version
173+
elseif(USE_HIP)
174+
add_executable(advanced_fft
175+
src/10_advanced_fft/fft3d_hip.hip
176+
)
177+
target_link_libraries(advanced_fft cuda_common ${GPU_RUNTIME_LIB})
178+
endif()
179+
180+
# Example 11: N-Body Simulation (has HIP version)
181+
if(USE_CUDA)
182+
# Skip for now - no CUDA version
183+
elseif(USE_HIP)
184+
add_executable(nbody_simulation
185+
src/11_nbody_simulation/nbody_hip.hip
186+
)
187+
target_link_libraries(nbody_simulation cuda_common ${GPU_RUNTIME_LIB})
188+
endif()
149189

150190
# Install targets
151-
install(TARGETS
152-
vector_addition
153-
matrix_multiplication
154-
parallel_reduction
155-
convolution_2d
156-
monte_carlo
157-
DESTINATION bin
158-
)
191+
if(USE_CUDA)
192+
install(TARGETS
193+
vector_addition
194+
matrix_multiplication
195+
parallel_reduction
196+
convolution_2d
197+
monte_carlo
198+
DESTINATION bin
199+
)
200+
elseif(USE_HIP)
201+
install(TARGETS
202+
vector_addition
203+
advanced_threading
204+
dynamic_memory
205+
warp_primitives
206+
advanced_fft
207+
nbody_simulation
208+
DESTINATION bin
209+
)
210+
endif()
159211

160212
# Testing (optional)
161213
option(BUILD_TESTS "Build tests" OFF)
@@ -164,8 +216,15 @@ if(BUILD_TESTS)
164216
add_subdirectory(tests)
165217
endif()
166218

219+
# GUI (optional)
220+
option(BUILD_GUI "Build GUI application" ON)
221+
if(BUILD_GUI)
222+
add_subdirectory(gui)
223+
endif()
224+
167225
# Print configuration info
168226
message(STATUS "CUDA Version: ${CMAKE_CUDA_COMPILER_VERSION}")
169227
message(STATUS "CUDA Architectures: ${CMAKE_CUDA_ARCHITECTURES}")
170228
message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}")
171229
message(STATUS "Profiling Enabled: ${ENABLE_PROFILING}")
230+
message(STATUS "GUI Enabled: ${BUILD_GUI}")
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
cmake_minimum_required(VERSION 3.16...3.21)
2+
3+
# These are part of the public API. Projects should use them to provide a
4+
# consistent set of prefix-relative destinations.
5+
if(NOT QT_DEPLOY_BIN_DIR)
6+
set(QT_DEPLOY_BIN_DIR "bin")
7+
endif()
8+
if(NOT QT_DEPLOY_LIB_DIR)
9+
set(QT_DEPLOY_LIB_DIR "lib")
10+
endif()
11+
if(NOT QT_DEPLOY_PLUGINS_DIR)
12+
set(QT_DEPLOY_PLUGINS_DIR "plugins")
13+
endif()
14+
if(NOT QT_DEPLOY_QML_DIR)
15+
set(QT_DEPLOY_QML_DIR "qml")
16+
endif()
17+
if(NOT QT_DEPLOY_PREFIX)
18+
set(QT_DEPLOY_PREFIX "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}")
19+
endif()
20+
if(QT_DEPLOY_PREFIX STREQUAL "")
21+
set(QT_DEPLOY_PREFIX .)
22+
endif()
23+
24+
# These are internal implementation details. They may be removed at any time.
25+
set(__QT_DEPLOY_SYSTEM_NAME "Linux")
26+
set(__QT_DEPLOY_IS_SHARED_LIBS_BUILD "ON")
27+
set(__QT_DEPLOY_TOOL "")
28+
set(__QT_DEPLOY_IMPL_DIR "/home/kevin/Projects/cuda-kernel/build_simple/.qt")
29+
set(__QT_DEPLOY_VERBOSE "")
30+
set(__QT_CMAKE_EXPORT_NAMESPACE "Qt6")
31+
set(__QT_DEPLOY_GENERATOR_IS_MULTI_CONFIG "0")
32+
set(__QT_DEPLOY_ACTIVE_CONFIG "")
33+
set(__QT_NO_CREATE_VERSIONLESS_FUNCTIONS "")
34+
set(__QT_DEFAULT_MAJOR_VERSION "6")
35+
36+
# Define the CMake commands to be made available during deployment.
37+
set(__qt_deploy_support_files
38+
"/usr/lib/x86_64-linux-gnu/cmake/Qt6Core/Qt6CoreDeploySupport.cmake"
39+
)
40+
foreach(__qt_deploy_support_file IN LISTS __qt_deploy_support_files)
41+
include("${__qt_deploy_support_file}")
42+
endforeach()
43+
44+
unset(__qt_deploy_support_file)
45+
unset(__qt_deploy_support_files)

0 commit comments

Comments
 (0)