Skip to content

Commit 4ff5522

Browse files
committed
Merge branch 'make_install' into 'master'
Add make install feature and fix some minor bugs See merge request cuda-samples/cuda-samples!138
2 parents 9df0ef6 + df6edf6 commit 4ff5522

File tree

210 files changed

+1314
-91
lines changed

Some content is hidden

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

210 files changed

+1314
-91
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,7 @@ endif()
2222

2323
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --extended-lambda")
2424

25+
# Include installation configuration before processing samples
26+
include(cmake/InstallSamples.cmake)
27+
2528
add_subdirectory(Samples)

Common/helper_multiprocess.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,14 @@
5454
#endif
5555
#include <vector>
5656

57+
// The Unix domain sockets creating folder on QNX has been restricted to qnx6-mounted directories since QNX SDP 8.0.3.
58+
#if defined(__QNX__)
59+
#include <string>
60+
inline std::string getSocketFolder() {
61+
return "/storage";
62+
}
5763
// Simple filesystem compatibility for GCC 8.x
58-
#if defined(__GNUC__) && __GNUC__ < 9
64+
#elif defined(__GNUC__) && __GNUC__ < 9
5965
#include <cstdlib>
6066
#include <string>
6167
inline std::string getSocketFolder() {

README.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,72 @@ To build samples with new CUDA Toolkit(CUDA 13.0 or later) and UMD(Version 580 o
195195
cmake -DCMAKE_PREFIX_PATH=/usr/local/cuda/lib64/stubs/ ..
196196
```
197197

198+
## Install Samples
199+
200+
### Installation Path Structure
201+
202+
The installation system automatically organizes samples into a structured directory layout based on:
203+
- **Target Architecture**: ${CMAKE_SYSTEM_PROCESSOR}, e.g. `x64`, `aarch64`, `amd64`, etc.
204+
- **Target OS**: `linux`, `windows`, `darwin`, `qnx`
205+
- **Build Type**: `release`, `debug`, etc.
206+
207+
The default installation path is: `build/bin/${TARGET_ARCH}/${TARGET_OS}/${BUILD_TYPE}`
208+
209+
**Examples:**
210+
- Linux x86_64 Release: `build/bin/x64/linux/release`
211+
- Linux aarch64 Release: `build/bin/aarch64/linux/release`
212+
- Windows amd64 Release: `build/bin/amd64/windows/release`
213+
214+
### Customizing Installation Paths
215+
216+
You can customize the installation location using CMake variables during the configuration step:
217+
218+
- `CMAKE_INSTALL_PREFIX`: Changes the root installation directory (default: `build/bin`)
219+
```
220+
cmake -DCMAKE_INSTALL_PREFIX=/custom/path ..
221+
```
222+
This will install to: `/custom/path/${TARGET_ARCH}/${TARGET_OS}/${BUILD_TYPE}`
223+
224+
- `CUDA_SAMPLES_INSTALL_DIR`: Specifies the exact final installation directory (overrides the structured path)
225+
```
226+
cmake -DCUDA_SAMPLES_INSTALL_DIR=/exact/install/path ..
227+
```
228+
229+
### Install Samples on Linux
230+
231+
**Prerequisites:** You must first configure the project with CMake as described in the [Building CUDA Samples - Linux](#linux) or [Building]section.
232+
233+
After configuring and building, install the samples:
234+
235+
```
236+
cd build/
237+
make install
238+
```
239+
240+
### Install Samples on Windows
241+
242+
**Prerequisites:** You must first configure the project with CMake as described in the [Building CUDA Samples - Windows](#windows) section.
243+
244+
#### Using Command Line
245+
246+
After configuring with CMake, build and install from the `x64 Native Tools Command Prompt for VS`:
247+
248+
```cmd
249+
cd build
250+
cmake --build . --config Release
251+
cmake --install . --config Release
252+
```
253+
254+
**Note:** Replace `Release` with `Debug` if you want to install debug builds. For multi-configuration generators (like Visual Studio), the `--config` flag determines which build type to install.
255+
256+
#### Using Visual Studio IDE
257+
258+
Alternatively, open the generated solution file `CUDA_Samples.sln` in Visual Studio:
259+
1. Select the desired configuration (`Release` or `Debug`)
260+
2. Build the solution (F7 or Build > Build Solution)
261+
3. Right-click on the `INSTALL` target under `CMakePredefinedTargets` in Solution Explorer
262+
4. Select "Build"
263+
198264
## Running All Samples as Tests
199265

200266
It's important to note that the CUDA samples are _not_ intended as a validation suite for CUDA. They do not cover corner cases, they do not completely cover the
@@ -383,6 +449,9 @@ Samples that demonstrate performance optimization.
383449
### [7. libNVVM](./Samples/7_libNVVM/README.md)
384450
Samples that demonstrate the use of libNVVVM and NVVM IR.
385451

452+
### [8. Platform Specific](./Samples/8_Platform_Specific/Tegra/README.md)
453+
Samples that are specific to certain platforms (Tegra, cuDLA, NvMedia, NvSci, OpenGL ES).
454+
386455
## Dependencies
387456

388457
Some CUDA Samples rely on third-party applications and/or libraries, or features provided by the CUDA Toolkit and Driver, to either build or execute. These dependencies are listed below.

Samples/0_Introduction/UnifiedMemoryStreams/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,7 @@ target_compile_features(UnifiedMemoryStreams PRIVATE cxx_std_17 cuda_std_17)
4949
else()
5050
message(STATUS "OpenMP not found - will not build sample 'UnifiedMemoryStreams'")
5151
endif()
52+
53+
# Include installation configuration
54+
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/InstallSamples.cmake)
55+
setup_samples_install()

Samples/0_Introduction/asyncAPI/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,7 @@ target_compile_options(asyncAPI PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-la
2828
target_compile_features(asyncAPI PRIVATE cxx_std_17 cuda_std_17)
2929

3030
set_target_properties(asyncAPI PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
31+
32+
# Include installation configuration
33+
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/InstallSamples.cmake)
34+
setup_samples_install()

Samples/0_Introduction/clock/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,7 @@ target_compile_options(clock PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambd
2828
target_compile_features(clock PRIVATE cxx_std_17 cuda_std_17)
2929

3030
set_target_properties(clock PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
31+
32+
# Include installation configuration
33+
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/InstallSamples.cmake)
34+
setup_samples_install()

Samples/0_Introduction/clock_nvrtc/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,7 @@ add_custom_command(TARGET clock_nvrtc POST_BUILD
3737
COMMAND ${CMAKE_COMMAND} -E copy_if_different
3838
${CMAKE_CURRENT_SOURCE_DIR}/clock_kernel.cu ${CMAKE_CURRENT_BINARY_DIR}
3939
)
40+
41+
# Include installation configuration
42+
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/InstallSamples.cmake)
43+
setup_samples_install()

Samples/0_Introduction/cudaOpenMP/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,7 @@ target_compile_features(cudaOpenMP PRIVATE cxx_std_17 cuda_std_17)
3737
else()
3838
message(STATUS "OpenMP not found - will not build sample 'cudaOpenMP'")
3939
endif()
40+
41+
# Include installation configuration
42+
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/InstallSamples.cmake)
43+
setup_samples_install()

Samples/0_Introduction/fp16ScalarProduct/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@ target_compile_options(fp16ScalarProduct PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--ex
2727
target_compile_features(fp16ScalarProduct PRIVATE cxx_std_17 cuda_std_17)
2828

2929
set_target_properties(fp16ScalarProduct PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
30+
31+
# Include installation configuration
32+
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/InstallSamples.cmake)
33+
setup_samples_install()

Samples/0_Introduction/matrixMul/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,7 @@ target_compile_options(matrixMul PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-l
2828
target_compile_features(matrixMul PRIVATE cxx_std_17 cuda_std_17)
2929

3030
set_target_properties(matrixMul PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
31+
32+
# Include installation configuration
33+
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/InstallSamples.cmake)
34+
setup_samples_install()

0 commit comments

Comments
 (0)