Skip to content

Commit aeab82f

Browse files
authored
CUDA 13.2 samples update (#432)
- Added Python samples for CUDA Python 1.0 release - Renamed top-level `Samples` directory to `cpp` to accommodate Python samples.
1 parent a4526d5 commit aeab82f

2,072 files changed

Lines changed: 15077 additions & 1970 deletions

File tree

Some content is hidden

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

.pre-commit-config.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,13 @@ repos:
104104
Common/.*
105105
)
106106
args: ["-fallback-style=none", "-style=file", "-i"]
107+
- repo: https://github.com/astral-sh/ruff-pre-commit
108+
rev: v0.8.4
109+
hooks:
110+
- id: ruff
111+
name: ruff lint
112+
args: [--fix]
113+
files: ^python/.*\.py$
114+
- id: ruff-format
115+
name: ruff format
116+
files: ^python/.*\.py$

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## Changelog
22

3+
### CUDA 13.2 (update)
4+
* Added **CUDA Python samples** under `python/`. These scripts use [CUDA Python](https://nvidia.github.io/cuda-python/) (including `cuda.core`) and are organized like the C++ tree: `1_GettingStarted`, `2_CoreConcepts`, `3_FrameworkInterop`, and `4_DistributedComputing`, plus shared helpers in `python/Utilities`. Each sample includes a `README.md` and `requirements.txt`. They are **not** built by the root CMake project; install dependencies with `pip install -r requirements.txt` in the sample directory, then run the corresponding `.py` file as documented in that sample’s README.
5+
* Renamed top-level `Samples` directory to `cpp` to accommodate Python samples alongside existing C++ samples; updated path references in `CMakeLists.txt`, `README.md`, and `Common` headers accordingly.
6+
37
### CUDA 13.2
48
* Added the MSVC compile flag `-Xcompiler=/Zc:preprocessor` in CMakeLists.txt to comply with CUDA13.2 CCCL. Previously, using the traditional preprocessor triggered the warning “MSVC/cl.exe with traditional preprocessor is used…”, which now leads to a build error.
59

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ endif()
3030
# Include installation configuration before processing samples
3131
include(cmake/InstallSamples.cmake)
3232

33-
add_subdirectory(Samples)
33+
add_subdirectory(cpp)

Common/helper_nvJPEG.hxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,9 +400,9 @@ int getInputDir(std::string &input_dir, const char *executable_path) {
400400
std::string pathname = "";
401401
const char *searchPath[] = {
402402
"./images",
403-
"../../../../Samples/4_CUDA_Libraries/<executable_name>/images",
404-
"../../../Samples/4_CUDA_Libraries/<executable_name>/images",
405-
"../../Samples/4_CUDA_Libraries/<executable_name>/images"};
403+
"../../../../cpp/4_CUDA_Libraries/<executable_name>/images",
404+
"../../../cpp/4_CUDA_Libraries/<executable_name>/images",
405+
"../../cpp/4_CUDA_Libraries/<executable_name>/images"};
406406

407407
for (unsigned int i = 0; i < sizeof(searchPath) / sizeof(char *); ++i) {
408408
std::string pathname(searchPath[i]);

Common/helper_string.h

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -288,69 +288,69 @@ inline char *sdkFindFilePath(const char *filename,
288288
"./", // same dir
289289
"./data/", // same dir
290290

291-
"../../../../Samples/<executable_name>/", // up 4 in tree
292-
"../../../Samples/<executable_name>/", // up 3 in tree
293-
"../../Samples/<executable_name>/", // up 2 in tree
291+
"../../../../cpp/<executable_name>/", // up 4 in tree
292+
"../../../cpp/<executable_name>/", // up 3 in tree
293+
"../../cpp/<executable_name>/", // up 2 in tree
294294

295-
"../../../../Samples/<executable_name>/data/", // up 4 in tree
296-
"../../../Samples/<executable_name>/data/", // up 3 in tree
297-
"../../Samples/<executable_name>/data/", // up 2 in tree
295+
"../../../../cpp/<executable_name>/data/", // up 4 in tree
296+
"../../../cpp/<executable_name>/data/", // up 3 in tree
297+
"../../cpp/<executable_name>/data/", // up 2 in tree
298298

299-
"../../../../Samples/0_Introduction/<executable_name>/", // up 4 in tree
300-
"../../../Samples/0_Introduction/<executable_name>/", // up 3 in tree
301-
"../../Samples/0_Introduction/<executable_name>/", // up 2 in tree
299+
"../../../../cpp/0_Introduction/<executable_name>/", // up 4 in tree
300+
"../../../cpp/0_Introduction/<executable_name>/", // up 3 in tree
301+
"../../cpp/0_Introduction/<executable_name>/", // up 2 in tree
302302

303-
"../../../../Samples/1_Utilities/<executable_name>/", // up 4 in tree
304-
"../../../Samples/1_Utilities/<executable_name>/", // up 3 in tree
305-
"../../Samples/1_Utilities/<executable_name>/", // up 2 in tree
303+
"../../../../cpp/1_Utilities/<executable_name>/", // up 4 in tree
304+
"../../../cpp/1_Utilities/<executable_name>/", // up 3 in tree
305+
"../../cpp/1_Utilities/<executable_name>/", // up 2 in tree
306306

307-
"../../../../Samples/2_Concepts_and_Techniques/<executable_name>/", // up 4 in tree
308-
"../../../Samples/2_Concepts_and_Techniques/<executable_name>/", // up 3 in tree
309-
"../../Samples/2_Concepts_and_Techniques/<executable_name>/", // up 2 in tree
307+
"../../../../cpp/2_Concepts_and_Techniques/<executable_name>/", // up 4 in tree
308+
"../../../cpp/2_Concepts_and_Techniques/<executable_name>/", // up 3 in tree
309+
"../../cpp/2_Concepts_and_Techniques/<executable_name>/", // up 2 in tree
310310

311-
"../../../../Samples/3_CUDA_Features/<executable_name>/", // up 4 in tree
312-
"../../../Samples/3_CUDA_Features/<executable_name>/", // up 3 in tree
313-
"../../Samples/3_CUDA_Features/<executable_name>/", // up 2 in tree
311+
"../../../../cpp/3_CUDA_Features/<executable_name>/", // up 4 in tree
312+
"../../../cpp/3_CUDA_Features/<executable_name>/", // up 3 in tree
313+
"../../cpp/3_CUDA_Features/<executable_name>/", // up 2 in tree
314314

315-
"../../../../Samples/4_CUDA_Libraries/<executable_name>/", // up 4 in tree
316-
"../../../Samples/4_CUDA_Libraries/<executable_name>/", // up 3 in tree
317-
"../../Samples/4_CUDA_Libraries/<executable_name>/", // up 2 in tree
315+
"../../../../cpp/4_CUDA_Libraries/<executable_name>/", // up 4 in tree
316+
"../../../cpp/4_CUDA_Libraries/<executable_name>/", // up 3 in tree
317+
"../../cpp/4_CUDA_Libraries/<executable_name>/", // up 2 in tree
318318

319-
"../../../../Samples/5_Domain_Specific/<executable_name>/", // up 4 in tree
320-
"../../../Samples/5_Domain_Specific/<executable_name>/", // up 3 in tree
321-
"../../Samples/5_Domain_Specific/<executable_name>/", // up 2 in tree
319+
"../../../../cpp/5_Domain_Specific/<executable_name>/", // up 4 in tree
320+
"../../../cpp/5_Domain_Specific/<executable_name>/", // up 3 in tree
321+
"../../cpp/5_Domain_Specific/<executable_name>/", // up 2 in tree
322322

323-
"../../../../Samples/6_Performance/<executable_name>/", // up 4 in tree
324-
"../../../Samples/6_Performance/<executable_name>/", // up 3 in tree
325-
"../../Samples/6_Performance/<executable_name>/", // up 2 in tree
323+
"../../../../cpp/6_Performance/<executable_name>/", // up 4 in tree
324+
"../../../cpp/6_Performance/<executable_name>/", // up 3 in tree
325+
"../../cpp/6_Performance/<executable_name>/", // up 2 in tree
326326

327-
"../../../../Samples/0_Introduction/<executable_name>/data/", // up 4 in tree
328-
"../../../Samples/0_Introduction/<executable_name>/data/", // up 3 in tree
329-
"../../Samples/0_Introduction/<executable_name>/data/", // up 2 in tree
327+
"../../../../cpp/0_Introduction/<executable_name>/data/", // up 4 in tree
328+
"../../../cpp/0_Introduction/<executable_name>/data/", // up 3 in tree
329+
"../../cpp/0_Introduction/<executable_name>/data/", // up 2 in tree
330330

331-
"../../../../Samples/1_Utilities/<executable_name>/data/", // up 4 in tree
332-
"../../../Samples/1_Utilities/<executable_name>/data/", // up 3 in tree
333-
"../../Samples/1_Utilities/<executable_name>/data/", // up 2 in tree
331+
"../../../../cpp/1_Utilities/<executable_name>/data/", // up 4 in tree
332+
"../../../cpp/1_Utilities/<executable_name>/data/", // up 3 in tree
333+
"../../cpp/1_Utilities/<executable_name>/data/", // up 2 in tree
334334

335-
"../../../../Samples/2_Concepts_and_Techniques/<executable_name>/data/", // up 4 in tree
336-
"../../../Samples/2_Concepts_and_Techniques/<executable_name>/data/", // up 3 in tree
337-
"../../Samples/2_Concepts_and_Techniques/<executable_name>/data/", // up 2 in tree
335+
"../../../../cpp/2_Concepts_and_Techniques/<executable_name>/data/", // up 4 in tree
336+
"../../../cpp/2_Concepts_and_Techniques/<executable_name>/data/", // up 3 in tree
337+
"../../cpp/2_Concepts_and_Techniques/<executable_name>/data/", // up 2 in tree
338338

339-
"../../../../Samples/3_CUDA_Features/<executable_name>/data/", // up 4 in tree
340-
"../../../Samples/3_CUDA_Features/<executable_name>/data/", // up 3 in tree
341-
"../../Samples/3_CUDA_Features/<executable_name>/data/", // up 2 in tree
339+
"../../../../cpp/3_CUDA_Features/<executable_name>/data/", // up 4 in tree
340+
"../../../cpp/3_CUDA_Features/<executable_name>/data/", // up 3 in tree
341+
"../../cpp/3_CUDA_Features/<executable_name>/data/", // up 2 in tree
342342

343-
"../../../../Samples/4_CUDA_Libraries/<executable_name>/data/", // up 4 in tree
344-
"../../../Samples/4_CUDA_Libraries/<executable_name>/data/", // up 3 in tree
345-
"../../Samples/4_CUDA_Libraries/<executable_name>/data/", // up 2 in tree
343+
"../../../../cpp/4_CUDA_Libraries/<executable_name>/data/", // up 4 in tree
344+
"../../../cpp/4_CUDA_Libraries/<executable_name>/data/", // up 3 in tree
345+
"../../cpp/4_CUDA_Libraries/<executable_name>/data/", // up 2 in tree
346346

347-
"../../../../Samples/5_Domain_Specific/<executable_name>/data/", // up 4 in tree
348-
"../../../Samples/5_Domain_Specific/<executable_name>/data/", // up 3 in tree
349-
"../../Samples/5_Domain_Specific/<executable_name>/data/", // up 2 in tree
347+
"../../../../cpp/5_Domain_Specific/<executable_name>/data/", // up 4 in tree
348+
"../../../cpp/5_Domain_Specific/<executable_name>/data/", // up 3 in tree
349+
"../../cpp/5_Domain_Specific/<executable_name>/data/", // up 2 in tree
350350

351-
"../../../../Samples/6_Performance/<executable_name>/data/", // up 4 in tree
352-
"../../../Samples/6_Performance/<executable_name>/data/", // up 3 in tree
353-
"../../Samples/6_Performance/<executable_name>/data/", // up 2 in tree
351+
"../../../../cpp/6_Performance/<executable_name>/data/", // up 4 in tree
352+
"../../../cpp/6_Performance/<executable_name>/data/", // up 3 in tree
353+
"../../cpp/6_Performance/<executable_name>/data/", // up 2 in tree
354354

355355
"../../../../Common/data/", // up 4 in tree
356356
"../../../Common/data/", // up 3 in tree

README.md

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,12 @@ $ make -j$(nproc) --ignore-errors # or --keep-going
159159
```
160160

161161
```
162-
# In Samples/5_Domain_Specific/CMakeList.txt
162+
# In cpp/5_Domain_Specific/CMakeList.txt
163163
# add_subdirectory(simpleGL)
164164
# add_subdirectory(simpleVulkan)
165165
# add_subdirectory(simpleVulkanMMAP)
166166
167-
# In Samples/8_Platform_Specific/Tegra/CMakeList.txt
167+
# In cpp/8_Platform_Specific/Tegra/CMakeList.txt
168168
# add_subdirectory(simpleGLES_EGLOutput)
169169
```
170170

@@ -195,6 +195,30 @@ 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+
## CUDA Python samples
199+
200+
The repository includes **Python** examples under the [`python/`](./python) directory. **These samples are cuda.core–focused:** they use [CUDA Python](https://nvidia.github.io/cuda-python/), with [`cuda.core`](https://nvidia.github.io/cuda-python/cuda-core/latest/) for devices, programs, launches, and memory, alongside NumPy, CuPy, or framework interop where each sample notes.
201+
202+
**Layout (same themes as the C++ samples):**
203+
204+
| Directory | Contents |
205+
|-----------|----------|
206+
| `python/1_GettingStarted/` | Introductory scripts (e.g. `vectorAdd`, `deviceQuery`, `systemInfo`, image blur with unified memory, NumPy vs CuPy). |
207+
| `python/2_CoreConcepts/` | Algorithms and techniques (e.g. reductions, histograms, FFT, stream overlap, `memoryResources`, `cudaGraphs`, `jitLtoLinking`, `tmaTensorMap`). |
208+
| `python/3_FrameworkInterop/` | Integration with PyTorch and TensorFlow. |
209+
| `python/4_DistributedComputing/` | Multi-GPU, peer-to-peer, and IPC patterns (`ipcMemoryPool`). |
210+
| `python/Utilities/` | Shared helpers imported by some samples. |
211+
212+
**How to run:** The top-level CMake build does **not** compile these samples. For each sample, use a Python 3.10+ environment with a matching [CUDA Toolkit](https://developer.nvidia.com/cuda-downloads) (the samples target CUDA 13.x and document exact package pins in `requirements.txt`):
213+
214+
```bash
215+
cd python/<category>/<sampleName>
216+
pip install -r requirements.txt
217+
python <sampleScript>.py
218+
```
219+
220+
Use each sample’s `README.md` for prerequisites, CLI options, and expected output.
221+
198222
## Install Samples
199223

200224
### Installation Path Structure
@@ -272,7 +296,7 @@ the following command line arguments:
272296

273297
| Switch | Purpose | Example |
274298
| ---------- | -------------------------------------------------------------------------------------------------------------- | ----------------------- |
275-
| --dir | Specify the root directory to search for executables (recursively) | --dir ./build/Samples |
299+
| --dir | Specify the root directory to search for executables (recursively) | --dir ./build/cpp |
276300
| --config | JSON configuration file for executable arguments | --config test_args.json |
277301
| --output | Output directory for test results (stdout saved to .txt files - directory will be created if it doesn't exist) | --output ./test |
278302
| --args | Global arguments to pass to all executables (not currently used) | --args arg_1 arg_2 ... |
@@ -397,7 +421,7 @@ make -j$(nproc)
397421
Now, return to the samples root directory and run the test script:
398422
```bash
399423
cd ..
400-
python3 run_tests.py --output ./test --dir ./build/Samples --config test_args.json
424+
python3 run_tests.py --output ./test --dir ./build/cpp --config test_args.json
401425
```
402426

403427
If all applications run successfully, you will see something similar to this (the specific number of samples will depend on your build type
@@ -425,31 +449,31 @@ incorrectly on your system.
425449

426450
## Samples list
427451

428-
### [0. Introduction](./Samples/0_Introduction/README.md)
452+
### [0. Introduction](./cpp/0_Introduction/README.md)
429453
Basic CUDA samples for beginners that illustrate key concepts with using CUDA and CUDA runtime APIs.
430454

431-
### [1. Utilities](./Samples/1_Utilities/README.md)
455+
### [1. Utilities](./cpp/1_Utilities/README.md)
432456
Utility samples that demonstrate how to query device capabilities and measure GPU/CPU bandwidth.
433457

434-
### [2. Concepts and Techniques](./Samples/2_Concepts_and_Techniques/README.md)
458+
### [2. Concepts and Techniques](./cpp/2_Concepts_and_Techniques/README.md)
435459
Samples that demonstrate CUDA related concepts and common problem solving techniques.
436460

437-
### [3. CUDA Features](./Samples/3_CUDA_Features/README.md)
461+
### [3. CUDA Features](./cpp/3_CUDA_Features/README.md)
438462
Samples that demonstrate CUDA Features (Cooperative Groups, CUDA Dynamic Parallelism, CUDA Graphs etc).
439463

440-
### [4. CUDA Libraries](./Samples/4_CUDA_Libraries/README.md)
464+
### [4. CUDA Libraries](./cpp/4_CUDA_Libraries/README.md)
441465
Samples that demonstrate how to use CUDA platform libraries (NPP, NVJPEG, NVGRAPH cuBLAS, cuFFT, cuSPARSE, cuSOLVER and cuRAND).
442466

443-
### [5. Domain Specific](./Samples/5_Domain_Specific/README.md)
467+
### [5. Domain Specific](./cpp/5_Domain_Specific/README.md)
444468
Samples that are specific to domain (Graphics, Finance, Image Processing).
445469

446-
### [6. Performance](./Samples/6_Performance/README.md)
470+
### [6. Performance](./cpp/6_Performance/README.md)
447471
Samples that demonstrate performance optimization.
448472

449-
### [7. libNVVM](./Samples/7_libNVVM/README.md)
473+
### [7. libNVVM](./cpp/7_libNVVM/README.md)
450474
Samples that demonstrate the use of libNVVVM and NVVM IR.
451475

452-
### [8. Platform Specific](./Samples/8_Platform_Specific/Tegra/README.md)
476+
### [8. Platform Specific](./cpp/8_Platform_Specific/Tegra/README.md)
453477
Samples that are specific to certain platforms (Tegra, cuDLA, NvMedia, NvSci, OpenGL ES).
454478

455479
## Dependencies
@@ -514,7 +538,7 @@ To set up GLFW on a Windows system, Download the pre-built binaries from [GLFW w
514538

515539
#### OpenMP
516540

517-
OpenMP is an API for multiprocessing programming. OpenMP can be installed using your Linux distribution's package manager system. It usually comes preinstalled with GCC. It can also be found at the [OpenMP website](http://openmp.org/). For compilers such as clang, `libomp.so` and other components for LLVM must be installed separated. You will also need to set additional flags in your CMake configuration files, such as: `-DOpenMP_CXX_FLAGS="-fopenmp=libomp" -DOpenMP_CXX_LIB_NAMES="omp" -DOpenMP_omp_LIBRARY="/path/to/libomp.so"`.
541+
OpenMP is an API for multiprocessing programming. OpenMP can be installed using your Linux distribution's package manager system. It usually comes preinstalled with GCC. It can also be found at the [OpenMP website](http://openmp.org/). For compilers such as clang, make sure OpenMP is enabled when building LLVM by including `openmp` in `LLVM_ENABLE_PROJECTS`. If you use clang (from an installed prefix or directly from an LLVM build tree) with OpenMP enabled, set CMAKE_CXX_COMPILER and CMAKE_CUDA_HOST_COMPILER to that clang++ and let CMake detect OpenMP; extra OpenMP_* CMake variables are usually not needed. When using clang++ directly from an LLVM build tree, you may need to copy the generated `omp.h` into the `include/` directory under the path reported by `clang++ --print-resource-dir` before building the samples. When using an installed clang with OpenMP, if you see libomp.so: cannot open shared object file at runtime, add the directory that contains libomp.so to LD_LIBRARY_PATH (or configure it via ld.so.conf.d) so the dynamic linker can locate the OpenMP runtime.
518542

519543
#### Screen
520544

Samples/0_Introduction/UnifiedMemoryStreams/.vscode/launch.json

Lines changed: 0 additions & 10 deletions
This file was deleted.

Samples/0_Introduction/asyncAPI/.vscode/launch.json

Lines changed: 0 additions & 10 deletions
This file was deleted.

Samples/0_Introduction/clock/.vscode/launch.json

Lines changed: 0 additions & 10 deletions
This file was deleted.

Samples/0_Introduction/clock_nvrtc/.vscode/launch.json

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)