评估CUDA算子适配性

更新时间:
复制 MD 格式

PPU芯片支持CUDA算子,可在PPU上编译并运行CUDA程序。通过运行NVIDIA CUDA Samples的典型用例,可评估PPU对CUDA 12.4的兼容性,当前支持率达87.6%。

背景

真武810E支持CUDA算子,用户可使用CUDA语言编写程序,在PPU上编译运行。CUDA Samples是NVIDIA提供的示例程序集,涵盖内存管理、线程操作、数学运算、图像处理等主题。我们在PPU上运行这些用例,评估PPU对CUDA的兼容性。

  • 机型:真武810E 16卡

  • 存储:智算CPFS/NAS

  • 镜像:dsw-registry-vpc.cn-wulanchabu.cr.aliyuncs.com/pai/training-xpu-pytorch:pai-ppu-llm-1.0

  • git仓库:https://github.com/NVIDIA/cuda-samples

  • 使用产品组件:PAI-DSW

环境构建

  1. 构建DSW:基于上述步骤中的镜像构建DSW实例,详细步骤请参考在PAI上使用PPU开发训练模型。

  2. 下载代码

    cd /path/to/your/workspace/cuda # 此处替换为您的实际路径
    git clone https://github.com/NVIDIA/cuda-samples.git 
    git checkout -b v12.4

操作命令

以下示例完全遵循CUDA的编译和执行方式。(用例仅验证兼容性与可用性,性能数据不代表真实性能。)

  1. 以vectorAdd为例。

    cd /path/to/your/workspace/cuda/cuda-samples/Samples/0_Introduction/vectorAdd # 此处替换为您的实际路径
    #编译并运行测试
    make
    ./vectorAdd
    root@dsw-96554-86b68c9cc-wf4cf:/mnt/workspace/zack/cuda/cuda-samples/Samples/0_Introduction# cd vectorAdd
    root@dsw-96554-86b68c9cc-wf4cf:/mnt/workspace/zack/cuda/cuda-samples/Samples/0_Introduction/vectorAdd# ls
    Makefile           README. md    vectorAdd_vs2017.sln     vectorAdd_vS2019.sln       vectorAdd_vs2022.sln
    NsightEclipse.xml  vectorAdd.cu  vectorAdd_vs2017.vcxproj vectorAdd_vs2019. vcxproj  vectorAdd_vs2022. voxproj
    
    root@dsw-96554-86b68c9cc-wf4cf:/mnt/workspace/zack/cuda/cuda-samples/Samples/0_Introduction/vectorAdd#
    ront@dsw_06554-2h68cacc-uf4cf:/mnt/warkspace/zack/cuda/cuda-samples/Samples/a_Introduction/vectorAdddt
    root@dsw-96554-86b68c9cc-wf4cf:/mnt/workspace/zack/cuda/cuda-samples/Samples/0_Introduction/vectorAdd# make
    /usr/Local/cuda/bin/nvcc -ccbin g++ -I../.•/../Common -m64 --threads 0 --std=c++11 -gencode arch=compute_50, code=sm_50 -gencode ar
    te_52, code=sm_52 -gecode arch=compute_60, code=sm_60 -gencode arch=compute_61, code=sm_61 -gecode arch=compute_70, code=sm_70 -genc
    =compute_75, code=sm_75 -gecode arch=compute_80, code=sm_80 -gencode arch=compute_86, code=sm_86 -gencode arch=compute_89, code=sm_89
    e arch=compute_90, code=sm_90 -gencode arch=compute_90, code=compute_90 -0 vectorAdd.o -c vectorAdd. cu
    /usr/local/cuda/bin/nvcc -ccbin g++ -m64 -gencode arch=compute_50, code=sm_50 -gencode arch=compute_52, code=sm_52 -gencode arch=com
    code=sm_60 -gencode arch=compute_61, code=sm_61 -gencode arch=compute_70, code=sm_70 -gencode arch=compute_75, code=sm_75 -gencode ar
    te_80, code=sm_80 -genode arch=compute_86, code=sm_86 -gencode arch=compute_89, code=sm_89 -gecode arch=compute_90, code=sm_90 -genc
    =compute_90, code=compute_90 -o vectorAdd vectorAdd.o
    mkdir -p ///bin/x86_64/Linux/release
    cp vectorAdd
    .-/../../bin/x86_64/linux/release
    root@dsw-96554-86b68c9cc-wt4ct:/mnt/workspace/zack/cuda/cuda-samples/Samples/0_Introduction/vectorAdd#
    root@dsw-96554-86b68c9cc-wf4cf:/mnt/workspace/zack/cuda/cuda-samples/Samples/0_Introduction/vectorAdd#
    root@dsw-96554-86b68c9cc-wf4cf:/mnt/workspace/zack/cuda/cuda-samples/Samples/0_Introduction/vectorAdd# vectorAdd
    bash: vectorAdd: command not found
    root@dsw-96554-86b68c9cc-wf4cf:/mnt/workspace/zack/cuda/cuda-samples/Samples/0_Introduction/vectorAdd# -/vectorAdd
    [Vector addition of 50000 elements]
    Copy input data from the host memory to the CUDA device
    CUDA kernel launch with 196 blocks of 256 threads
    Copy output data from the CUDA device to the host memory
    Test PASSED
    Done
    root@dsw-96554-86b68c9cc-wf4cf:/mnt/workspace/zack/cuda/cuda-sampLes/Samples/0_Introduction/vectorAdd#
  2. 以matrixMul_nvrtc为例。

    cd /path/to/your/workspace/cuda/cuda-samples/Samples/0_Introduction/matrixMul_nvrtc # 此处替换为您的实际路径
    make
    ./matrixMul_nvrtc
    root@dsw-122523-579dc59fb8-gxbkk:/mnt/workspace/zack/cuda/cuda-samples/Samples/0_Introduction/matrixMul_nvrtc# make
    cp "/usr/local/PPU_SDK/CUDA_SDK/include/cooperative_groups.h"
    cp -r "/usr/local/PPU_SDK/CUDA_SDK/include/cooperative_groups"
    root@dsw-122523-579dc59fb8-gxbkk:/mnt/workspace/zack/cuda/cuda-samples/Samples/_Introduction/matrixMul_nvrtc# ./matrixMul_nvrtc
    [Matrix Multiply Using CUDA] - Starting...
    MatrixA(320,320), MatrixB(640,320)
    > Using CUDA Device [0]: PPU-ZW810E
    > Using CUDA Device [0]: PPU-ZW810E
    > GPU Device has SM 8.0 compute capability
    Computing result using CUDA Kernel...
    Checking computed result for correctness: Result = PASS
  3. 以cudaTensorCoreGemm为例。

    cd /path/to/your/workspace/cuda/cuda-samples/Samples/3_CUDA_Features/cudaTensorCoreGemm # 此处替换为您的实际路径
    make
    ./cudaTensorCoreGemm
    cp cudaTensorCoreGemm././../bin/x86_64/linux/release
    root@dsw-122523-579dc59fb8-gxbkk:/mnt/workspace/zack/cuda/cuda-samples/Samples/3_CUDA_Features/cudaTensorCoreGemm# ./cudaTensorCoreGemm
    Initializing...
    GPU Device 0: "Ampere" with compute capability 8.0
    M: 4096 (16 x 256)
    N: 4096 (16 x 256)
    K: 4096 (16 x 256)
    Preparing data for GPU..•
    Required shared memory size: 64 Kb
    116 ta for GPU. ize: 64 Kb
    Computing... using high performance kernel compute_gemm
    Time: 5.749840 ms
    TFLOPS: 23.90
    root@dsw-122523-579dc59fb8-gxbkk:/mnt/workspace/zack/cuda/cuda-samples/Samples/3_CUDA_Features/cudaTensorCoreGemm#
  4. 以bf16TensorCoreGemm为例。

    cd /path/to/your/workspace/cuda/cuda-samples/Samples/3_CUDA_Features/cudaTensorCoreGemm # 此处替换为您的实际路径
    make
    ./bf16TensorCoreGemm
    root@dsw-122523-579dc59fb8-gxbkk:/mnt/workspace/zack/cuda/cuda-samples/Samples/3_CUDA_Features/bf16TensorCoreGemm#
    root@dsw-122523-579dc59fb8-gxbkk:/mnt/workspace/zack/cuda/cuda-samples/Samples/3_CUDA_Features/bf16TensorCoreGemm# ./bf16TensorCoreGemm
    Initializing...
    GPU Device 0:
    "Ampere" with compute capability 8.0
    M: 8192 (16 x 512)
    N: 8192 (16 x 512)
    K: 8192 (16 x 512)
    Preparing data
    for GPU...
    Required shared memory size: 72 Kb
    Computing using high performance kernel = 0 - compute_bf16gemm_async_copy
    Time: 46.036961 ms
    TFLOPS: 23.88
  5. 以reduction为例。

    cd /path/to/your/workspace/cuda/cuda-samples/Samples/2_Concepts_and_Techniques/reduction # 此处替换为您的实际路径
    make
    ./reduction
    cp reduction ///bin/x86_64/linux/release
    root@dsw-122523-579dc59fb8-gxbkk:/mnt/workspace/zack/cuda/cuda-samples/Samples/2_Concepts_and_Techniques/reduction# ./reduction
    •/reduction Starting...
    GPU Device 0: "Ampere" with compute capability 8.0
    Using Device 0: PPU-ZW810E
    Reducing array of type int
    16777216 elements
    256 threads (max)
    64 blocks
    Reduction, Throughput = 248.2112 GB/s, Time = 0.00027 s, Size = 16777216 Elements, NumDevsUsed = 1, Workgroup = 256
    GPU result = 2139353471
    CPU result = 2139353471
    Test passed
    root@dsw-122523-579dc59fb8-gxbkk:/mnt/workspace/zack/cuda/cuda-samples/Samples/2_Concepts_and_Techniques/reduction#
  6. 以tf32TensorCoreGemm算子为例。

    cd /path/to/your/workspace/cuda/cuda-samples/Samples/3_CUDA_Features/cudaTensorCoreGemm # 此处替换为您的实际路径
    make
    ./tf32TensorCoreGemm
    root@dsw-122523-579dc59fb8-gxbkk:/mnt/workspace/zack/cuda/cuda-samples/Samples/3_CUDA_Features/tf32TensorCoreGemm#
    root@dsw-122523-579dc59fb8-gxbkk:/mnt/workspace/zack/cuda/cuda-samples/Samples/3_CUDA_Features/tf32TensorCoreGemm# ./tf32TensorCoreGemm
    Initializing...
    GPU Device 0: "Ampere" with compute capability 8.0
    M: 8192 (16 x 512)
    N: 8192 (16 x 512)
    K: 4096 (8 x 512)
    Preparing data for GPU...
    Required shared memory size: 72 Kb
    Computing using high performance kernel = 0 - compute_tf32gemm_async_copy
    Time: 40.634399 ms
    TFLOPS: 13.53
    root@dsw-122523-579dc59fb8-gxbkk:/mnt/workspace/zack/cuda/cuda-samples/Samples/3_CUDA_Features/tf32TensorCoreGemm#
  7. 以bandwidthTest为例。

    cd /path/to/your/workspace/cuda/cuda-samples/Samples/3_CUDA_Features/cudaTensorCoreGemm # 此处替换为您的实际路径
    make
    ./bandwidthTest
    root@d-122523-579d59fb8-gxbkk:/mnt/workspace/zack/cuda/cuda-samples/Samples/1_Utilities/bandwidthTest# ./bandwidthTest
    [CUDA Bandwidth Test] - Starting...
    Running on...
    Device 0: PPU-ZW810E
    Quick Mode
    Host to Device Bandwidth, 1 Device(s)
    PINNED Memory Transfers
    Transfer Size (Bytes)   Bandwidth (GB/s)
    32000000                29.0
    
    Device to Host Bandwidth, 1 Device(s)
    PINNED Memory Transfers
    Transfer Size (Bytes)   Bandwidth (GB/s)
    32000000                28.3
    
    Device to Device Bandwidth, 1 Device(s)
    PINNED Memory Transfers
    Transfer Size (Bytes)   Bandwidth (GB/s)
    32000000                2699.1
    
    Result = PASS
    NOTE: The CUDA Samples are not meant for performance measurements. Results may vary when GPU Boost is enabled.
    root@dsw-122523-579dc59fb8-gxbkk:/mnt/workspace/zack/cuda/cuda-samples/Samples/1_Utilities/bandwidthTest#

总结

PPU芯片已支持CUDA 12.4。在121项大语言模型相关的CUDA Sample中,PPU支持106项,支持率达87.6%。