---
title: NVCC编译参数优化
description: "当前已知对GPU计算性能影响较大的编译选项如表1所示，可在编译时添加。"
url: https://www.hikunpeng.com/document/detail/zh/perftuning/gputuing-wp/kunpenggpu_19_0015.html
sourcePath: /source/zh/perftuning/gputuing-wp/kunpenggpu_19_0015.html
indexId: 398df65dbf52f6e4e5e7b80ee12c59bb31324cd59fbabe890b797f25990e02b157
---
# NVCC编译参数优化

当前已知对GPU计算性能影响较大的编译选项如表1所示，可在编译时添加。


**表1 NVCC编译参数**

| 编译选项 | 选项描述 |
| --- | --- |
| \-gencode;arch=compute\_xx,code=sm\_xx | 指定对应GPU卡类型和架构，以获取更好的兼容性和性能，比如A100的典型配置为\-gencode;arch=compute\_80,code=sm\_80。 |
| \-\-ftz=false/true | 是否将极小值置为0，减少计算，默认false。 |
| \-\-prec\-sqrt=true/false | 是否使用精确的平方根函数，默认true。 |
| \-\-prec\-div=true/false | 是否使用精确的除法计算，默认true。 |
| \-\-fmad=true/false | 是否使能乘加合并计算，默认true。 |
| \-\-use\_fast\_math | 是否开启快速计算模式，开启时相当于\-\-ftz=true \-\-prec\-div=false \-\-prec\-sqrt=false \-\-fmad=true。 |
| \-O 0 1 2 3 4 | 代码优化级别，O0为不优化，O1到O4优化操作逐渐增多，建议O4。 |
| \-Xptxas \-allow\-expensive\-optimizations | 用最大资源来实现优化。 |
| \-Xptxas \-dlcm=ca/cg | 是否开启L1 cache，ca为开启，cg为关闭，默认ca。 |


参考文档：《NVIDIA HPC Compilers Reference Guide(https://docs.nvidia.com/hpc-sdk/compilers/hpc-compilers-ref-guide/index.html)》
