当前位置: 首页 > news >正文

--gpu-architecture <arch> (-arch)

–gpu-architecture (-arch)
Specify the name of the class of NVIDIA ‘virtual’ GPU architecture for which
the CUDA input files must be compiled.
With the exception as described for the shorthand below, the architecture
specified with this option must be a ‘virtual’ architecture (such as compute_100).
Normally, this option alone does not trigger assembly of the generated PTX
for a ‘real’ architecture (that is the role of nvcc option ‘–gpu-code’,
see below); rather, its purpose is to control preprocessing and compilation
of the input to PTX.
For convenience, in case of simple nvcc compilations, the following shorthand
is supported. If no value for option ‘–gpu-code’ is specified, then the
value of this option defaults to the value of ‘–gpu-architecture’. In this
situation, as only exception to the description above, the value specified
for ‘–gpu-architecture’ may be a ‘real’ architecture (such as a sm_100),
in which case nvcc uses the specified ‘real’ architecture and its closest
‘virtual’ architecture as effective architecture values. For example, ‘nvcc
–gpu-architecture=sm_100’ is equivalent to ‘nvcc --gpu-architecture=compute_100
–gpu-code=sm_100,compute_100’.
-arch=all build for all supported architectures (sm_*), and add PTX
for the highest major architecture to the generated code.
-arch=all-major build for just supported major versions (sm_0), plus the
earliest supported, and add PTX for the highest major architecture to the
generated code.
-arch=native build for all architectures (sm_
) on the current system
Note: -arch=native, -arch=all, -arch=all-major cannot be used with the -code
option, but can be used with -gencode options.
Allowed values for this option: ‘all’,‘all-major’,‘compute_100’,‘compute_100a’,
‘compute_100f’,‘compute_103’,‘compute_103a’,‘compute_103f’,‘compute_110’,
‘compute_110a’,‘compute_110f’,‘compute_120’,‘compute_120a’,‘compute_120f’,
‘compute_121’,‘compute_121a’,‘compute_121f’,‘compute_75’,‘compute_80’,‘compute_86’,
‘compute_87’,‘compute_88’,‘compute_89’,‘compute_90’,‘compute_90a’,‘lto_100’,
‘lto_100a’,‘lto_100f’,‘lto_103’,‘lto_103a’,‘lto_103f’,‘lto_110’,‘lto_110a’,
‘lto_110f’,‘lto_120’,‘lto_120a’,‘lto_120f’,‘lto_121’,‘lto_121a’,‘lto_121f’,
‘lto_75’,‘lto_80’,‘lto_86’,‘lto_87’,‘lto_88’,‘lto_89’,‘lto_90’,‘lto_90a’,
‘native’,‘sm_100’,‘sm_100a’,‘sm_100f’,‘sm_103’,‘sm_103a’,‘sm_103f’,‘sm_110’,
‘sm_110a’,‘sm_110f’,‘sm_120’,‘sm_120a’,‘sm_120f’,‘sm_121’,‘sm_121a’,‘sm_121f’,
‘sm_75’,‘sm_80’,‘sm_86’,‘sm_87’,‘sm_88’,‘sm_89’,‘sm_90’,‘sm_90a’.

--gpu-architecture(或简写为-arch)是NVIDIA CUDA编译器(nvcc)的核心选项,用于指定编译时针对的虚拟GPU架构,直接影响代码生成、优化及兼容性。以下从技术原理、参数解析、使用场景及最佳实践四方面深度解析:

一、核心作用与原理

  • 虚拟架构(Compute Capability)
    指定编译时使用的“计算能力”(如compute_80对应Turing架构),控制编译器如何将CUDA C++代码转换为PTX(并行线程执行代码)。PTX是中间表示,需通过JIT(即时编译)在运行时转换为特定GPU的机器码。

    • 示例:--gpu-architecture=compute_80生成针对Turing架构优化的PTX,可在所有支持计算能力8.0的GPU(如RTX 30系列)上运行。
  • 真实架构(Real Architecture)
    通过--gpu-code(或-code)指定目标“真实架构”(如sm_80),直接生成特定GPU的机器码。若仅用-arch而未用-code,编译器会自动将-arch的值映射为真实架构(如-arch=sm_80等效于-arch=compute_80 -code=sm_80,compute_80)。

二、参数值详解与使用场景

1. 基础虚拟架构(compute_*)
  • 格式compute_<主版本><次版本>(如compute_80compute_90)。
  • 作用:控制编译器优化级别、指令选择及内存访问模式。
  • 示例
    • compute_80:针对Turing架构优化,支持FP16/INT8加速。
    • compute_90:针对Ampere架构优化,支持第三代Tensor Core及多实例GPU(MIG)。
2. 特殊值(all/all-major/native)
  • -arch=all

    • 所有支持的架构(sm_*)生成机器码,并添加最高主版本架构的PTX(如同时生成sm_80、sm_86、sm_90的代码,并附加compute_90的PTX)。
    • 适用场景:需广泛兼容不同GPU(如从Kepler到Ampere)的应用程序。
    • 限制:无法与-code选项共用。
  • -arch=all-major

    • 仅针对主版本架构(如sm_*0)生成代码,并附加最高主版本PTX。例如,若支持sm_70、sm_80、sm_90,则生成sm_70、sm_80、sm_90的代码及compute_90的PTX。
    • 适用场景:减少二进制体积,适用于仅需覆盖主要架构的场景。
  • -arch=native

    • 自动检测当前系统中所有GPU的架构,并生成对应的机器码及最高主版本PTX。
    • 适用场景:本地开发时快速适配当前硬件。
    • 示例:若系统有RTX 3090(sm_86)和A100(sm_80),则生成sm_80、sm_86的代码及compute_90的PTX。
3. 真实架构(sm_)与链接优化(lto_
  • sm_*(如sm_80):直接生成特定GPU的机器码,需与-code配合使用或通过短手写法自动映射。
  • lto_*(如lto_80):启用链接时间优化(LTO),跨模块优化代码,提升性能但增加编译时间。

三、与--gpu-code的交互逻辑

  • 默认行为:若仅用-arch(如-arch=compute_80)而未用-code,则自动添加-code=sm_80,compute_80,生成机器码+PTX。

  • 显式指定:通过-code覆盖默认行为,例如:

    nvcc --gpu-architecture=compute_80 --gpu-code=sm_80,sm_90 ...
    

    生成针对Turing(sm_80)和Ampere(sm_90)的机器码,并保留compute_80的PTX。

  • 冲突限制allall-majornative不能与-code共用,但可与多个-gencode选项组合(如-gencode=arch=compute_80,code=sm_80)。

四、最佳实践与性能优化

  1. 明确目标架构

    • 开发时:使用-arch=native快速适配本地硬件。
    • 部署时:根据目标GPU指定具体架构(如-arch=compute_90 -code=sm_90)。
  2. 平衡兼容性与体积

    • 需广泛兼容:用-arch=all,但注意二进制体积会增大。
    • 需精简代码:用-arch=all-major或指定具体架构。
  3. 利用PTX JIT优化

    • 在未知用户GPU的场景(如分发应用),可仅生成最高主版本PTX(如-arch=compute_90),由运行时JIT编译为当前GPU的机器码,兼顾兼容性与性能。
  4. 链接时间优化(LTO)

    • 对性能敏感的代码,启用lto_*选项(如-arch=lto_90),跨模块优化指令调度与内存访问。

五、常见问题与陷阱

  • 架构不匹配:若运行环境GPU的计算能力低于编译时指定的虚拟架构(如用compute_90编译但在Turing GPU运行),JIT可能无法完全优化代码,导致性能下降。
  • 冗余代码:过度使用allall-major可能导致二进制包含未用架构的代码,增加加载时间与内存占用。
  • 版本兼容性:CUDA工具链版本需与目标GPU架构匹配(如CUDA 11.x支持Ampere,而CUDA 10.x不支持)。

通过合理配置--gpu-architecture,开发者可在兼容性、性能与二进制体积之间取得平衡,最大化CUDA应用的效率与适应性。

以下是 sm_xx 与 NVIDIA 显卡型号的对应关系及架构解析:

一、Pascal 架构(sm_6x)

  • sm_60:Tesla P100(数据中心 GPU,无消费级显卡)
  • sm_61GTX 1080Ti、Titan Xp(核心代号 GP102)
  • sm_62:Tesla P40(数据中心 GPU,无消费级显卡)

二、Volta 架构(sm_7x)

  • sm_70:Tesla V100(数据中心 GPU,无消费级显卡)
  • sm_75RTX 2080 Ti(核心代号 TU102,实际为 Turing 架构,但部分文档误标为 Volta)

三、Turing 架构(sm_7x/sm_8x)

  • sm_75RTX 2080 Ti、RTX 2080 SUPER(核心代号 TU102/TU104)
  • sm_86RTX 3060(核心代号 GA106)
  • sm_89RTX 3080 Ti、RTX 3090(核心代号 GA102)

四、Ampere 架构(sm_8x/sm_9x)

  • sm_80:Tesla A100(数据中心 GPU,无消费级显卡)
  • sm_86RTX 3060(与 Turing 架构重名,但实际为 Ampere)
  • sm_89**:RTX 3080 Ti**(与 Turing 架构重名,但实际为 Ampere)
  • sm_90RTX 4090、RTX 4080(核心代号 AD102/AD103)

五、Hopper 架构(sm_9x)

  • sm_90:H100(数据中心 GPU,无消费级显卡)
  • sm_90a:H200(数据中心 GPU,无消费级显卡)

六、Blackwell 架构(sm_10x/sm_12x)

  • sm_100RTX 5090(核心代号 GB202,2025 年发布)
  • sm_103:RTX 5080(核心代号 GB203)
  • sm_120:RTX 5090(部分文档中用于区分不同变体,如 Blackwell 架构的增强版)
  • sm_121:RTX 5080(同上)

关键说明

  1. 命名冲突

    • sm_75sm_86 在 Turing 和 Ampere 架构中重复出现,需结合显卡型号(如 RTX 2080 Ti vs. RTX 3060)区分。
    • sm_90 既用于 Ampere 架构的 RTX 4090,也用于 Hopper 架构的 H100,但后者为数据中心 GPU。
  2. 新架构特性

    • Blackwell 架构(sm_100/sm_120):支持 CUDA 12.8+,专为 AI 和高性能计算优化,例如 RTX 5090 的 4-bit/8-bit 量化加速。
    • Hopper 架构(sm_90):引入 FP8 数据类型,提升 AI 训练效率。
  3. 编译建议

    • 若为 RTX 5090 编译代码,需指定 --gpu-architecture=sm_120(或 sm_100,具体取决于 CUDA 版本和编译器支持)。
    • 跨架构兼容时,可组合多个 -gencode 选项,例如:
      nvcc --gpu-architecture=compute_120 \--gencode=arch=compute_120,code=sm_120 \--gencode=arch=compute_90,code=sm_90 \your_code.cu
      

文章转载自:

http://U9pdqYy7.xdpjf.cn
http://ccfAxcBc.xdpjf.cn
http://GH7nlVNI.xdpjf.cn
http://y2rpFhp2.xdpjf.cn
http://hR8WWc3H.xdpjf.cn
http://FqXXmzmi.xdpjf.cn
http://KLcDX7mW.xdpjf.cn
http://FzLCPTGr.xdpjf.cn
http://6qvVjFwH.xdpjf.cn
http://utThuXl0.xdpjf.cn
http://zIwT88WA.xdpjf.cn
http://0LhDLNhi.xdpjf.cn
http://b5MQHOtv.xdpjf.cn
http://boH2wfSm.xdpjf.cn
http://9Nx81Cnl.xdpjf.cn
http://7OXBrL75.xdpjf.cn
http://9PrNj7KZ.xdpjf.cn
http://FhGeJShy.xdpjf.cn
http://t02dJ4H9.xdpjf.cn
http://q4xciiqr.xdpjf.cn
http://3nR8iZlK.xdpjf.cn
http://uJkb6JPK.xdpjf.cn
http://5uRIqIoR.xdpjf.cn
http://0p7cRlTu.xdpjf.cn
http://tNQhD4mm.xdpjf.cn
http://uXZRb54T.xdpjf.cn
http://YCq4O2T5.xdpjf.cn
http://DHmQ55iy.xdpjf.cn
http://rK5EHHa2.xdpjf.cn
http://3KgNoVCd.xdpjf.cn
http://www.dtcms.com/a/381521.html

相关文章:

  • uniapp动态修改tabbar
  • Spring Boot 集成 Flowable 7.1.0 完整教程
  • 教你使用服务器如何搭建数据库
  • Kafka如何配置生产者拦截器和消费者拦截器
  • uniapp:根据目的地经纬度,名称,唤起高德/百度地图来导航,兼容App,H5,小程序
  • 欧拉函数 | 定义 / 性质 / 应用
  • 【更新至2024年】1996-2024年各省农业总产值数据(无缺失)
  • 财报季观察|消费“分野”,燕之屋(1497.HK)们向上生长
  • 机械制造专属ERP:降本增效与数字转型的关键
  • 基于node.js+vue的医院陪诊系统的设计与实现(源码+论文+部署+安装)
  • 【大语言模型 59】监控与日志系统:训练过程全面监控
  • HIS架构智能化升级编程路径:从底层原理到临床实践的深度解析(下)
  • Node.js中package.json详解
  • 当AI遇上数据库:Text2Sql.Net如何让“说人话查数据“成为现实
  • 数据结构8——双向链表
  • 问卷系统自动化测试报告
  • Python 的函数柯里化(Currying)
  • 渗透测试信息收集详解
  • 【连载3】C# MVC 异常日志进阶:结构化日志与性能优化技巧
  • 冯诺依曼体系:现代计算机的基石与未来展望
  • 关于在阿里云DMS误操作后如何恢复数据的记录
  • 贪心算法应用:神经网络剪枝详解
  • 灵活学习PyTorch算法:从动态计算图到领域最佳实践
  • [code-review] 部署配置 | Docker+PM2 | AWS Lambda | Vercel+边缘函数
  • 递归,搜索与回溯算法
  • 31.网络基础概念(一)
  • 贪心算法应用:信用卡还款优化问题详解
  • Linux的多线程
  • 《链式二叉树常用操作全解析》
  • ——贪心算法——