NVCC官网解析:http://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/#nvcc-command-options

GCC : https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html

nvcc命令选项:

选项命令有长名和短名,通常我们使用是用短名,长名主要用于描述。

1.指定编译阶段

主要指定编译的阶段以及要编译的输入文件。

-cuda  -cubin  -fatbin  -ptx  -gpu  -E 

-c :最常使用,编译每个.c/.cc/.cpp/.cxx/.cu输入文件为object文件

-dc  -dw  -dlink  -link 

-lib :编译所有的输入文件为object文件,并且把结果添加到指定的library输出文件

-run

2.文件和路径配置

-o :指定输出文件的位置和名称

-include  :指定预处理和编译时预先需要包含的头文件

-l  :指定链接时需要的库文件

-D :指定预处理和编译时需要的宏

-U  :取消宏定义

-I :指定包含文件的搜索路径

-isystem :指定系统包含的引用文件的搜索路径

-L :指定库文件的搜索路径

-odir :指定输出文件的目录

-ccbin :指定host编译器所在路径

-cudart :指定CUDA runtime library使用类型(none,shared,static),默认为static

-ldir  :指定包含libdevice库文件目录

3.指定编译器、连接器的行为

-pg 

-g  :产生可调式代码,调试模式下必须的

-G  :产生可调式的设备代码

-lineinfo :为设备代码产生行number信息

-O  :产生优化代码 ,包括O0,O1,O2,O3,用于产生不同的指令集

-ftemplate-backtrace-limit  -shared  -x  -std  -nohdinitlist  -nohdmoveforward  -expt-relaxed-constexpr 

-m  :指定平台结构32 vs 64

4.编译工具内部选项

-Xcompiler  -Xlinker  -Xarchive  -Xptxas  -Xnvlink

-Xptxas -v:显示代码生成的统计结果

-Xptxas -dlcm=cg:关闭L1cache

-Xptxas -dlcm=ca:将L1cache增加到48KB(默认为16KB,和shared memory一共64KB)

5.编译驱动引导选项

-noprof  -dryrun 

-v  :列出nvcc产生的编译命令,不影响其执行

-keep  :保留各步骤产生的中间文件,用于调试

-keep-dir  -save-temps 

-clean  :逆转nvcc的行为

-run-args  -idp  -ddp  -dp  -MT  -nodlink

6.CUDA编译方式选项

-default-stream

7.驾驭GPU代码生成选项

-arch :指定GPU架构

-code  -gencode  -rdc  -e 

-maxrregcount  :指定GPU函数可使用的最大寄存器数量

-use_fast_math  -ftz  -prec-div  -prec-sqrt  -fmad

8.ptxas选项

-allow-expensive-optimizations  -c  -dlcm  -dscm  -g  -disable-optimizer-consts  -e  -fmad  -flcm  -fscm  -lineinfo  -arch  -h  -m  -maxrregcount  -O  -optf  -o  -preserve-relocs  -sp-bound-check  -v  -V  -Werror  -warn-double-usage  -warn-spills

扩展:

(1)--std {c++03|c++11|c++14}-std

Select a particular C++ dialect.

Allowed values for this option: c++03,c++11,c++14

(2)--expt-relaxed-constexpr

-expt-relaxed-constexpr

Experimental flag: Allow host code to invoke __device__constexpr functions, and device code to invoke __host__constexprfunctions.

(3)--x {c|c++|cu}-x

Explicitly specify thelanguage for the input files, rather than letting the compiler choose a default based on the file name suffix.Allowed values for this option: c, c++, cu.

(4)--compiler-options options,...

-Xcompiler : Specify options directly to the compiler/preprocessor.

(5)--gpu-architecture arch

-arch :Specify the name of the class of NVIDIA virtual GPU architecture for which the CUDA input files must be compiled.

The architecture specified with this option must be a virtualarchitecturereal 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 realarchitecture (such as a sm_50), in which case nvcc uses the specified real architecture and its closest virtualarchitecture as effective architecture values. 

For example, nvcc --gpu-architecture=sm_50is equivalent tonvcc --gpu-architecture=compute_50 --gpu-code=sm_50,compute_50.

Virtual Architecture Feature List


compute_30 and compute_32

Basic features

+ Kepler support

+ Unified memory programming

compute_35

+ Dynamic parallelism support

compute_50, compute_52, and compute_53

+ Maxwell support

compute_60, compute_61, and compute_62

+ Pascal support

compute_70

+ Volta support


(6)GCC 5的 Dual ABI [1][2] 的存在,GCC 5与 GCC 4.X 系列的ABI是不兼容的,所以GCC 5编译出来的库混合GCC 4.X编译的库是会出现链接符号找不到的,其中最大的影响就是std::string,使用统一版本的编译器编译是最好的处理方式,越简单越暴力越美好。

(7)_GLIBCXX_USE_CXX11_ABI 

controls whether the declarations in the library headers use the old or new ABI. So the decision of which ABI to use can be made separately for each source file being compiled. Using the default configuration options for GCC the default value _GLIBCXX_USE_CXX11_ABI =1 which causes the new ABI to be active, so to use the old ABI you must explicitly define the _GLIBCXX_USE_CXX11_ABI =0 before including any library headers.