# CUDA_Samples **Repository Path**: xdltek/CUDA_Samples ## Basic Information - **Project Name**: CUDA_Samples - **Description**: This repository provides a compact set of CUDA-style samples for RPP. - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-07-10 - **Last Updated**: 2026-07-10 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # CUDA Sample Demo on RPP Language switch: click [English](#english) or [中文](#chinese) to jump to the corresponding section. ![XDL Logo](docs/logo/logo_color_horizontal.png) This repository provides a compact set of CUDA-style samples for RPP. It is intended to help users build, run, benchmark, and inspect representative examples for basic kernels, SRAM data movement, common algorithms, and RPP library APIs. **Table Of Contents** Click a section link below to jump within this README: - [Quick Start](#quick-start) - [Repository Layout](#repository-layout) - [Sample Guides](#sample-guides) - [Documentation](#documentation) - [Prerequisites](#prerequisites) - [How to Build](#how-to-build) - [How to Run](#how-to-run) - [Benchmark](#benchmark) - [Direct Binary Usage](#direct-binary-usage) - [Code Execution Workflow](#code-execution-workflow) - [Key Source Files](#key-source-files) - [How to Adapt This Demo](#how-to-adapt-this-demo) ## Quick Start Run from the repository root: ```shell scripts/build.sh scripts/run.sh ``` Successful execution should print each sample name and a PASS/FAIL-style result or the sample's own correctness output. The standard scripts are: | Script | Purpose | |---|---| | `scripts/build.sh` | Cleans previous build outputs, configures CMake, and builds all samples. | | `scripts/run.sh` | Runs the default sample set, one category, or one selected sample. It also protects the `rpp_server` startup flow when the server binary exists. | | `scripts/benchmark.sh` | Runs samples through `scripts/run.sh` and saves a timestamped console log under `build/logs/`. | Common first checks: ```shell scripts/run.sh basic scripts/run.sh library_api scripts/benchmark.sh ``` `scripts/run.sh` resolves binaries from `build/bin/`. If `/usr/local/rpp/bin/rpp_server` exists, the script ensures it is running before launching a sample and writes the server log to `build/logs/rpp_server.log`. `scripts/benchmark.sh` saves the full console log to `build/logs/benchmark__.log`. ## Repository Layout - `CMakeLists.txt` Root build entry. Configures the RPP toolchain and adds all sample targets. - [`samples/basic/`](samples/basic/) Minimal kernel and select examples. - [`samples/memory_tensor/`](samples/memory_tensor/) SRAM and 2D load/store examples. - [`samples/algorithm/`](samples/algorithm/) Reduction and prefix sum examples. - [`samples/library_api/`](samples/library_api/) RPP FFT and RPP BLAS GEMM examples. - `docs/logo/` Logo assets used by this README. - `scripts/` Standard build, run, and benchmark command entry points. ## Sample Guides The root README is the single documentation entry. The following list points to the main source file of each sample: - [vector_add](samples/basic/vector_add/src/vector_add.cu): minimal vector addition sample. - [vec_select](samples/basic/vec_select/src/vec_select.cu): predicate/select sample. - [vec_sram_fuse](samples/memory_tensor/vec_sram_fuse/src/vec_sram_fuse.cu): SRAM fusion sample. - [vec_load2d](samples/memory_tensor/vec_load2d/src/vec_load2d.cu): 2D load/store sample. - [vec_reduce_max](samples/algorithm/vec_reduce_max/src/vec_reduce_max.cu): reduction sample. - [prefix_sum](samples/algorithm/prefix_sum/src/prefix_sum.cu): prefix sum sample. - [rpp_fft_v4](samples/library_api/rpp_fft_v4/src/simpleRPPFFT_v4.cpp): RPP FFT API sample. - [rpp_gemm](samples/library_api/rpp_gemm/src/simpleGemm.cpp): RPP BLAS GEMM sample. ## Documentation Public usage documentation is kept in this root README. The `docs/logo/` directory only stores README display assets. ## Prerequisites Before building this demo, make sure the following dependencies are available: - Linux development environment - CMake `>= 3.10` - `/usr/local/bin/clang++` - RPP SDK installed under `/usr/local/rpp` - Runtime libraries required by the target RPP accelerator environment ## How to Build Run the following command from the repository root: ```shell scripts/build.sh ``` `scripts/build.sh` removes the previous build directory before configuring CMake, then builds all samples. Manual build: ```shell mkdir -p build cd build cmake .. make -j8 ``` After the build completes successfully, executables are generated under: ```text build/bin/ ``` ## How to Run Run samples from the repository root after building the project: ```shell scripts/run.sh ``` By default, `scripts/run.sh` runs the basic and library API samples. Use a category or sample name when running a narrower check: ```shell scripts/run.sh basic scripts/run.sh memory_tensor scripts/run.sh algorithm scripts/run.sh library_api scripts/run.sh vector_add scripts/run.sh samples/library_api/rpp_gemm ``` Each script supports `-h` and `--help` where applicable. ## Benchmark Benchmark runs use the same sample selection style as `scripts/run.sh`: ```shell scripts/benchmark.sh scripts/benchmark.sh library_api scripts/benchmark.sh samples/library_api/rpp_gemm ``` Benchmark logs are saved under `build/logs/`. Benchmark output records sample-defined timing and validation output; this README does not state fixed performance numbers. ## Direct Binary Usage The scripts are the recommended first-use entry point because they resolve paths and protect the `rpp_server` startup flow. After building, users can also run binaries directly: ```shell build/bin/vector_add build/bin/vec_select build/bin/simpleRPPFFT_v4 build/bin/simpleGemm -m 128 -n 128 -k 1024 -bf16 ``` When running binaries directly, make sure `rpp_server` is already running if the installed RPP environment requires it. ## Code Execution Workflow ```text +--------------------+ | Prepare host input | +--------------------+ | v +--------------------+ | Copy input to DDR | +--------------------+ | v +--------------------+ | Move data to SRAM | +--------------------+ | v +--------------------+ | Run kernel/API | +--------------------+ | v +--------------------+ | Copy result back | +--------------------+ | v +--------------------+ | Verify output | +--------------------+ ``` ## Key Source Files - `samples/basic/vector_add/src/vector_add.cu` Minimal RPP CUDA-style kernel sample. - `samples/memory_tensor/vec_sram_fuse/src/vec_sram_fuse.cu` SRAM data movement and fused compute sample. - `samples/algorithm/vec_reduce_max/src/vec_reduce_max.cu` Reduction sample. - `samples/library_api/rpp_gemm/src/simpleGemm.cpp` RPP BLAS GEMM API sample. - `samples/library_api/rpp_fft_v4/src/simpleRPPFFT_v4.cpp` RPP FFT API sample. - `scripts/build.sh` Cleans previous build outputs, configures CMake, and builds the repository. - `scripts/run.sh` Runs all, category, or single sample targets. - `scripts/benchmark.sh` Runs samples and saves benchmark logs. ## How to Adapt This Demo 1. Copy a sample under the closest `samples//` directory. 2. Rename the sample directory and target name. 3. Update the source logic, input size, kernel, or RPP library API call. 4. Add the new sample directory to the category `CMakeLists.txt`. 5. Add a run mapping in `scripts/run.sh`. 6. Build, run, benchmark, and check correctness output. # RPP CUDA Sample 示例仓库 语言切换:点击 [English](#english) 或 [中文](#chinese) 跳转到对应章节。 ![XDL Logo](docs/logo/logo_color_horizontal.png) 本仓库提供一组精简的 RPP CUDA-style sample,用于帮助用户构建、运行、benchmark 和阅读基础 kernel、SRAM 数据搬移、常见算法以及 RPP 库 API 的代表性示例。 **目录** 点击以下链接可在 README 内跳转: - [快速开始](#快速开始) - [仓库结构](#仓库结构) - [Sample 说明](#sample-说明) - [项目文档](#项目文档) - [环境依赖](#环境依赖) - [构建方式](#构建方式) - [运行方式](#运行方式) - [Benchmark](#benchmark-1) - [直接运行二进制](#直接运行二进制) - [代码执行流程](#代码执行流程) - [关键源码](#关键源码) - [如何适配自己的示例](#如何适配自己的示例) ## 快速开始 在仓库根目录执行: ```shell scripts/build.sh scripts/run.sh ``` 执行成功后,程序会打印每个 sample 名称,并输出 PASS/FAIL 风格结果或 sample 自身的正确性校验信息。 标准脚本如下: | 脚本 | 用途 | |---|---| | `scripts/build.sh` | 清理上一次构建产物,执行 CMake 配置,并编译全部 sample。 | | `scripts/run.sh` | 运行默认 sample 集合、指定分类或指定单个 sample;当 `rpp_server` 存在时,会保护 server 启动流程。 | | `scripts/benchmark.sh` | 通过 `scripts/run.sh` 运行 sample,并将带时间戳的完整控制台日志保存到 `build/logs/`。 | 常用首次检查命令: ```shell scripts/run.sh basic scripts/run.sh library_api scripts/benchmark.sh ``` `scripts/run.sh` 会从 `build/bin/` 解析可执行文件。如果 `/usr/local/rpp/bin/rpp_server` 存在,脚本会在启动 sample 前保证该服务已运行,并将 server 日志写入 `build/logs/rpp_server.log`。 `scripts/benchmark.sh` 会将完整控制台日志保存到 `build/logs/benchmark__.log`。 ## 仓库结构 - `CMakeLists.txt` 根构建入口。负责配置 RPP 工具链并纳入所有 sample target。 - [`samples/basic/`](samples/basic/) 最小 kernel 和 select 示例。 - [`samples/memory_tensor/`](samples/memory_tensor/) SRAM 和二维 load/store 示例。 - [`samples/algorithm/`](samples/algorithm/) reduction 和 prefix sum 示例。 - [`samples/library_api/`](samples/library_api/) RPP FFT 和 RPP BLAS GEMM 示例。 - `docs/logo/` 根 README 使用的 logo 资源。 - `scripts/` 标准构建、运行和 benchmark 命令入口。 ## Sample 说明 根 README 是当前唯一文档入口。以下列表指向每个 sample 的主源码文件: - [vector_add](samples/basic/vector_add/src/vector_add.cu):最小向量加法 sample。 - [vec_select](samples/basic/vec_select/src/vec_select.cu):predicate/select sample。 - [vec_sram_fuse](samples/memory_tensor/vec_sram_fuse/src/vec_sram_fuse.cu):SRAM 融合计算 sample。 - [vec_load2d](samples/memory_tensor/vec_load2d/src/vec_load2d.cu):二维 load/store sample。 - [vec_reduce_max](samples/algorithm/vec_reduce_max/src/vec_reduce_max.cu):归约 sample。 - [prefix_sum](samples/algorithm/prefix_sum/src/prefix_sum.cu):前缀和 sample。 - [rpp_fft_v4](samples/library_api/rpp_fft_v4/src/simpleRPPFFT_v4.cpp):RPP FFT API sample。 - [rpp_gemm](samples/library_api/rpp_gemm/src/simpleGemm.cpp):RPP BLAS GEMM sample。 ## 项目文档 公开使用说明统一保留在根 README 中。`docs/logo/` 目录仅保存 README 展示所需资源。 ## 环境依赖 构建前请确认环境中已具备: - Linux 开发环境 - CMake `>= 3.10` - `/usr/local/bin/clang++` - 安装在 `/usr/local/rpp` 下的 RPP SDK - 目标 RPP 加速器运行所需的运行时库 ## 构建方式 在仓库根目录执行: ```shell scripts/build.sh ``` `scripts/build.sh` 会先删除上一次构建目录,再执行 CMake 配置并编译全部 sample。 手动构建方式: ```shell mkdir -p build cd build cmake .. make -j8 ``` 构建完成后,可执行文件默认生成在: ```text build/bin/ ``` ## 运行方式 构建完成后,在仓库根目录运行 sample: ```shell scripts/run.sh ``` 默认情况下,`scripts/run.sh` 会运行基础样例和库 API 样例。需要缩小检查范围时,可以指定分类或 sample 名称: ```shell scripts/run.sh basic scripts/run.sh memory_tensor scripts/run.sh algorithm scripts/run.sh library_api scripts/run.sh vector_add scripts/run.sh samples/library_api/rpp_gemm ``` 每个脚本在适用场景下支持 `-h` 和 `--help`。 ## Benchmark Benchmark 使用与 `scripts/run.sh` 相同的 sample 选择方式: ```shell scripts/benchmark.sh scripts/benchmark.sh library_api scripts/benchmark.sh samples/library_api/rpp_gemm ``` Benchmark 日志会保存到 `build/logs/`。Benchmark 输出记录 sample 自身定义的耗时和校验信息;本文档不声明固定性能指标。 ## 直接运行二进制 推荐第一次使用时通过脚本运行,因为脚本会统一解析路径并保护 `rpp_server` 启动流程。构建完成后,也可以直接运行二进制: ```shell build/bin/vector_add build/bin/vec_select build/bin/simpleRPPFFT_v4 build/bin/simpleGemm -m 128 -n 128 -k 1024 -bf16 ``` 直接运行二进制时,如果当前 RPP 环境需要 `rpp_server`,请先确认该服务已在后台运行。 ## 代码执行流程 ```text +--------------------+ | 准备 host 输入 | +--------------------+ | v +--------------------+ | 拷贝输入到 DDR | +--------------------+ | v +--------------------+ | 搬移数据到 SRAM | +--------------------+ | v +--------------------+ | 执行 kernel/API | +--------------------+ | v +--------------------+ | 拷贝结果回 host | +--------------------+ | v +--------------------+ | 校验输出结果 | +--------------------+ ``` ## 关键源码 - `samples/basic/vector_add/src/vector_add.cu` 最小 RPP CUDA-style kernel sample。 - `samples/memory_tensor/vec_sram_fuse/src/vec_sram_fuse.cu` SRAM 数据搬移和融合计算 sample。 - `samples/algorithm/vec_reduce_max/src/vec_reduce_max.cu` 归约 sample。 - `samples/library_api/rpp_gemm/src/simpleGemm.cpp` RPP BLAS GEMM API sample。 - `samples/library_api/rpp_fft_v4/src/simpleRPPFFT_v4.cpp` RPP FFT API sample。 - `scripts/build.sh` 清理上一次构建产物,执行 CMake 配置并编译仓库。 - `scripts/run.sh` 运行全部、分类或单个 sample target。 - `scripts/benchmark.sh` 运行 sample 并保存 benchmark 日志。 ## 如何适配自己的示例 1. 在最接近的 `samples//` 目录下复制一个 sample。 2. 修改 sample 目录名和 target 名称。 3. 更新源码逻辑、输入规模、kernel 或 RPP 库 API 调用。 4. 将新的 sample 目录加入对应分类的 `CMakeLists.txt`。 5. 在 `scripts/run.sh` 中添加运行映射。 6. 构建、运行、benchmark,并检查正确性输出。