CUDA compiler driver nvcc 散点 part 1

▶ 参考【https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html】

▶ nvcc 预定义的宏

__NVCC__                        // 编译 C/C++/CUDA 源文件时有定义
__CUDACC__                      // 编译 CUDA 源文件时有定义
__CUDACC_RDC__                  // 使用选项 --relocatable-device-code true 时有定义
__CUDACC_DEBUG__                // 使用选项 --device-debug 时有定义
__CUDACC_RELAXED_CONSTEXPR__    // 使用选项 --expt-relaxed-constexpr 时有定义
__CUDACC_EXTENDED_LAMBDA__      // 使用选项 --expt-extended-lambda 时有定义
__CUDACC_VER_MAJOR__            // nvcc 主版本号
__CUDACC_VER_MINOR__            // nvcc 次版本号
__CUDACC_VER_BUILD__            // nvcc build 号

▶ nvcc 接受的文件类型

.cu                 // CUDA 源文件,包含主机代码和设备函数
.c                  // C 源文件
.cc, .cxx,  .cpp    // C++ 源文件
.ptx                // 中间汇编文件
.o , .obj           // 目标文件
.a , .lib           // 库文件
.res                // 资源文件
.so                 // 共享目标文件

▶ nvcc 编译流程选项

--cuda/-cuda                // xxx.cu/ -> xxx.cpp.ii,Output file can be compiled by the host compiler that was used by nvcc to preprocess the .cu file.
--ptx/-ptx                  // xxx.cu/ -> xxx.ptx,生成设备代码,抛弃主机代码
--cubin/-cubin              // xxx.cu/xxx.ptx -> xxx.cubin,生成设备代码,抛弃主机代码
--fatbin/-fatbin            // xxx.cu/xxx.ptx/xxx.cubin -> xxx.cfatbin,生成设备代码,抛弃主机代码
-preporcess/-E              // 预处理输入文件(直接输出到屏幕上)
--generate-dependencies/-M  // 生成输入文件的依赖文件列表,可用于 make file
--compile/-c                // xxx.c/xxx.cc/xxx.cpp/xxx.cxx/xxx.cu -> .obj
--device-c/-dc              // xxx.c/xxx.cc/xxx.cpp/xxx.cxx/xxx.cu -> .obj,含有重定位设备代码,等价于 -c --relocatable-device-code=true
--device-w/-dw              // xxx.c/xxx.cc/xxx.cpp/xxx.cxx/xxx.cu -> .obj,含有可执行目标代码,等价于 -c --relocatable-device-code=false
--device-link/-dlink        // xxx.obj(含重定位设备代码) + .ptx/.cubin/.fatbin -> xxx.obj(含可执行设备代码)
--link/-link                // 默认选项,源文件编译 + 连接
--lib/-lib                  // 生成 .obj 加入指定的库文件中
--run/-run                  // 源文件编译 + 连接 + 执行或可执行文件执行,不使用含环境变量

▶ nvcc 编译动作选项

--profile/-pg                                       // 生成代码/可执行文件可用 gprof 分析性能
--debug/-g                                          // 生成主机代码调试信息
--device-debug/-G                                   // 生成设备代码调试信息,并关闭所有优化,不使用性能分析
--extencible-whole-program/-ewp                     // 生成可扩展设备代码,与 libcudadevrt 链接之前就能解析某些调用
--generate-line-info/-lineinfo                      // 设备代码生成行号信息
--optimize/-O $level                                            // 指定主机代码优化等级为 $level
--ftemplate-backtrace-limit/-ftemplate-backtrace-limit $limit   // 设置模板实例化的最大警告或错误的数量为 $limit,值 0 表示不强制执行限制,主机编译器支持则会收到等效选项
--ftemplate-depth/-ftemplate-depth $limit                       // 设置模板类实例化的最大深度为 $limit,主机编译器支持则会收到等效选项
--shared/-shared                                    // 连接时生成共享库
--x/-x {c|c++|cu}                                   // 显示指定输入文件的类型
--std/-std {c++03|c++11|c++14}                      // 指定使用的 C++ 标准
-no-host-device-move-forward/-nohdmoveforward       // 不要隐式使用 std::move 和 std::forward 作为主机或设备代码
--expt-relaxed-constexpr/-expt-relaxed-constexpr    // 允许主机代码调用 __device__ constexpr 函数
--expt-extended-lambda/-expt-extended-lambda        // 允许 lambda 声明中使用 __host__ 和 __device__
--machine/-m {32|64}                                // 指定处理器架构

▶ nvcc 编译工具选项

--compiler-options/-Xcompiler $options  // 指定编译器选项
--linker-options/-Xlinker $options      // 指定连接器选项
--archive-options/-Xarchive             // 指定库管理器选项
--ptxas-options/-Xptxas                 // 指定 PTX 优化汇编器(ptxas)选项
--nvlink-options/-Xnvlink               // 指定 nvlink 选项

▶ nvcc 编译驱动指导选项

--dont-use-profile/-noprof              // 不使用 nvcc.profile 来进行编译
--dryrun/-dryrun/-dryrun                // 列出不执行 nvcc 生成的编译命令
--verbose/-v                            // 列出并执行 nvcc 生成的编译命令,可以看出编译卡在哪一步
--keep/-keep                            // 保留所有编译的中间文件
--keep-dir/-keep-dir $directory         // 指定保留的中间文件的存放目录
--save-temps/-save-temps                // 同 --keep
--clean-targets/-clean                  // 清除中间文件,要求其它选项与上一次编译时一模一样
--run-args/-run-args $arguments         // 指定可执行文件运行参数
--input-drive-prefix/-idp $prefix       // 指定当前开发环境绝对路径前缀,如 Windows 中使用 /cygwin/ (cygwin)或 / (MinGW)
--dependency-drive-prefix/-ddp $prefix  // 指定当依赖文件绝对路径的前缀,与 make 有关
--drive-prefix/-dp $prefix              // 指定上面两者
--dependency-target-name/-MT $target    // 指定生成的依赖文件在规则下的目标名
--no-align-double                       // 不传给 32 位平台的编译器 -malign-double 选项
--no-device-link/-nodlink               // 生成目标文件时跳过设备连接步骤

▶ nvcc 文件及目录选项(默认多参数)

--outputfile/-o                         // 指定输出文件名,单参数
--output-directory/-odir                // 指定输出文件目录
--pre-include/-include                  // 指定预包含的头文件
--library/-l                            // 指定指定库文件(注意命名)
--define-macro/-D                       // 指定宏
--undefine-macro/-U                     // 取消宏
--system-include/-isystem               // 指定系统包含路径
--include-path/-I                       // 指定头文件目录
--library-path/-L                       // 指定库文件目录
--compiler-bindir/-ccbin                //
--cudart/-cudart {none|shared|static}   // 指定 CUDA 运行时库,无库、分享/动态库、静态库
--libdevice-directory/ldir              // 当使用 --dont-use-profile 选项时指定设备库(默认 nvvm/libdevice)

▶ CUDA 兼容性选项

--default-stream/-default-stream {legacy|null|per-thread}   // 指定默认流:legacy(默认选项,null 为废弃的同义词,同一上下文的流之间隐式同步)
                                                            //     per-thread(普通流,同一上下文的流之间隐式同步)
--gpu-architecture/-arch $arch              // 指定虚 GPU 架构,compute_XX,默认唯一实架构值
--gpu-code/-code $code                      // 指定实 GPU 架构(多参数),sm_XX,也可同时指定虚架构,sm_XX,compute_YY
--generate-code/-gencode $specification     // 组合上面两个选项,允许出现多个虚架构值
--relocatable-device-code/-rdc {true|false} // 是否生成重定位设备代码 
--entries/-e $entry                         // 设置入口函数
--maxrregcount/-maxrregcount $amount        // 指定单 GPU 函数最大寄存器数量
--ftz/-ftz {true|false}                     // 单精度非正规值刷成 0 或保存原有值(?)
--prec-div/-prec-div {true|false}           // 除法使用 IEEE 舍入或快速算法
--prec-sqrt/-prec-sqrt {true|false}         // 开根使用 IEEE 舍入或快速算法
--fmad/-fmad {true|false}                   // 是否启用融合乘加指令(FMAD,FFMA,DFMA)
--use_fast_math/-use_fast_math              // 使用快速数学算法,等价于 -ftz=true -prec-div=false -prec-sqrt=false -fmad=true

▶ 原生编译器选项

--disable-warnings/-w                       // 关闭警告
--source-in-ptx/-src-in-ptx                 // PTX 交错,仅当与 --device-debug 或--generate-line-info 连用时可用(?)
--restrict/-restrict                                        // 声明所有核函数指针都是 restrict 的
--Wno-deprecated-gpu-targets/-Wno-deprecated-gpu-targets    // 关闭已弃用 GPU 目标体系结构的警告
--Wno-deprecated-declarations/-Who-deprecated-declarations  // 关闭已弃用实体的警告
--Wreorder/-Wreorder                                        // 成员初始化器重排时生成警告
--Werror/-Werror $kind                      // 将特定类型的警告转成报错,有下列选项
                                            //     cross-execution-space-call:从 __host__ __device__ 函数调用 __host__ 函数时报错
                                            //     reorder:成员初始化器重排时生成警告
                                            //     deprecated-declarations:使用了已经废弃的函数
--resource-usage/-res-usage                 // 显示硬件资源使用量,寄存器、显存等  
--help/-h                                   // 显示帮助
--version/-V                                // 显示版本
--options-file/-optf $file                  // 从文件中读取命令行选项

▶ PTX选项,使用 -Xptxas 时配合使用

--allow-expensive-optimizations/-allow-expensive-optimizations  // 编译器高级优化(≥O2 时自动使用)
--compile-only/-c                                               // 生成重定位目标文件
--def-load-cache/-dlcm                                          // 默认全局缓存读优化
--def-store-cache/-dscm                                         // 默认全局缓存写优化
--device-debug/-g                                               // 同 --device-debug/-G
--disable-optimizer-constants -disable-optimizer-consts         // 关闭常量优化器                       
--entry/-e $entry                                               // 同 --entries/-e
--fmad -fmad                            // 同 --fmad/-fmad
--force-load-cache/-flcm                // 强制全局缓存读优化
--force-store-cache/-fscm               // 强制全局缓存读优化
--generate-line-info/-lineinfo          // 同 --generate-line-info/-lineinfo
--gpu-name/-arch $gpuname               // GPU版本号,默认值 sm_30,可用:compute_30, compute_35, compute_50, compute_52, sm_30, sm_32, sm_35, sm_50, sm_52
--help -h                               // 同 --help/-h 
--machine -m                            // 同 --machine/-m
--maxrregcount/-maxrregcount $amount    // 同 --maxrregcount/-maxrregcount
--opt-level/-O $N                       // 优化等级,默认值 3
--options-file/-optf $file              // 同 --options-file/-optf
--output-file/-o $file                  // 指定输出文件名,默认值 elf.o
--preserve-relocs/-preserve-relocs      // This option will make  ptxas to generate relocatable references for variables and preserve relocations generated for them in linked executable.
--sp-bound-check/-sp-bound-check        // Generate stack-pointer bounds-checking code sequence. This option is turned on automatically when --device-debug or --opt-level=0 is specified.
--verbose -v                            // 输出编译统计信息
--version -V                            // 同 --version/-V
--warning-as-error/-Werror                                      // 所有警告转报错
--warn-on-double-precision-use/-warn-double-usage               // 当指令用到 double 时警告
--warn-on-local-memory-usage/-warn-lmem-usage                   // 当使用了局部内存时警告
--warn-on-spills/-warn-spills                                   // 当寄存器溢出到局部内存时警告

▶ NVLINK 选项,使用 -Xnvlink 时配合使用

--disable-warnings/-w               // 关闭警告
--preserve-relocs/-preserve-relocs  // Preserve resolved relocations in linked executable.(?)
--verbose/-v                        // 输出编译统计信息
--warning-as-error/-Werror          // 所有警告转报错
原文地址:https://www.cnblogs.com/cuancuancuanhao/p/10386483.html