ptxas, the tool that compiles PTX into GPU-specific microcode,
occupies a unique place in the CUDA ecosystem, in that NVIDIA makes it
available both in the offline tools (which developers compile into
applications) and as part of the driver, enabling so-called “online” or
“just-in-time” (JIT) compilation (which occurs at runtime).
When compiling offline, ptxas generally is invoked by nvcc, if any
actual GPU architectures are specified with the --gpu-code command-line
option. In that case, command-line options (summarized in Table 4-8) can
be passed to ptxas via the -Xptxas command line option to nvcc.
| Option | Description |
|---|---|
( |
Enable or disable the compiling of functions using the Application Binary Interface (ABI). The default is yes. |
( |
Enable or disable expensive compile-time optimizations that use maximum available resources (memory and compile time). If unspecified, the default behavior is to enable this feature for optimization level >=O2. |
( |
Generate a relocatable object. |
|
Default cache modifier on global load. Default value: ca. |
( |
Generate debug information for device code. |
( |
When compiling with --compile-only, specify the maximum number of
registers that device functions can use. This option is ignored for
whole-program compilation and does not affect the number of registers
used by entry functions. For device functions, this option overrides the
value specified by --maxrregcount. If neither
--device-function-maxrregcount nor --maxrregcount is specified, then no
maximum is assumed. |
( |
Normally, ptxas attempts to merge consecutive basic blocks as part
of its optimization process. This option inhibits basic block merging,
improving the debuggability of generated code at a slight perfomance
cost. |
( |
Entry function name. |
( |
Enables or disables the contraction of floating-point multiplies and
adds/subtracts into floating-point multiply-add operations (FMAD, FFMA,
or DFMA). Default value: true. |
( |
Generate line-number information for device code. |
( |
Specify the SM version for which to generate code. This option also takes virtual compute architectures, in which case code generation is suppressed. This can be used for parsing only. Allowed values for this option: compute_10, compute_11, compute_12, compute_13, compute_20, compute_30, compute_35, sm_10, sm_11, sm_12, sm_13, sm_20, sm_21, sm_30, sm_35. Default value: sm_10. |
( |
Specifies the string containing the PTX module to compile on the command line. |
( |
Compile for 32-bit versus 64-bit architecture. |
|
Specify the maximum amount of registers that GPU functions can use. |
( |
Specifies the optimization level (0-3). |
( |
Include command-line options from the specified file. |
( |
Specify name of output file. (Default: elf.o) |
|
Suppresses the default ptxas behavior of optimizing out return
instructions at the end of the program, for improved debuggability. |
( |
Generate a stack-pointer bounds-checking code sequence.
Automatically enabled when --device-debug (-g) or --generate-line-info
(-lineinfo) is specified. |
|
Suppress the warning when a double precision instruction is encountered in PTX being compiled for an SM version that does not include double precision support. |
|
Enable verbose mode. |
--version |
Print version information. |
|
Make all warnings into errors. |
Table 4-8. Command-line options for ptxas.
Developers also can load PTX code dynamically by invoking
cuModuleLoadDataEx():
CUresult cuModuleLoadDataEx (
CUmodule * module,
const void * image,
unsigned int numOptions,
CUjit_option * options,
void ** optionValues
);
cuModuleLoadDataEx() takes a pointer image and loads the
corresponding module into the current context. The pointer may be
obtained by mapping a cubin or PTX or fatbin file, passing a cubin or
PTX or fatbin file as a NULL-terminated text string, or incorporating a
cubin or fatbin object into the executable resources and using operating
system calls such as Windows FindResource() to obtain the pointer.
Options are passed as an array via options and any corresponding
parameters are passed in optionValues. The number of total options is
specified by numOptions. Any outputs will be returned via optionValues.
Supported options are given in Table 4-9.
| Option | Description |
|---|---|
CU_JIT_MAX_REGISTERS |
Specifies the maximum number of registers per thread. |
CU_JIT_THREADS_PER_BLOCK |
|
CU_JIT_WALL_TIME |
Passes back a float containing the wall clock time (in milliseconds) spent compiling the PTX code. |
CU_JIT_INFO_LOG_BUFFER |
Input is a pointer to a buffer in which to print any informational
log messages from PTX assembly (the buffer size is specified via option
CU_JIT_INFO_LOG_BUFFER_SIZE_BYTES). |
CU_JIT_INFO_LOG_BUFFER_SIZE_BYTES |
Input buffer size in bytes; passes back the number of bytes filled with messages. |
CU_JIT_ERROR_LOG_BUFFER |
Input is a pointer to a buffer in which to print any error log
messages from PTX assembly (the buffer size is specified via option
CU_JIT_ERROR_LOG_BUFFER_SIZE_BYTES); |
CU_JIT_ERROR_LOG_BUFFER_BYTES |
input is the size in bytes of the buffer; output is the number of bytes filled with messages |
CU_JIT_OPTIMIZATION_LEVEL |
Level of optimization to apply to generated code (0-4), with 4 being the default. |
CU_JIT_TARGET_FROM_CUCONTEXT |
Infers compilation target from the current CUDA context. This is the
default behavior, if CU_JIT_TARGET is not specified. |
CU_JIT_TARGET |
CUjit_target_enum: Specifies the compilation target. Maybe any
of:
|
CU_JIT_TARGET_FALLBACK_STRATEGY |
CUjit_fallback_enum: Specifies fallback strategy of matching cubin
is not found; possibly values are CU_PREFER_PTX or
CU_PREFER_BINARY. |
Table 4-9. Options for cuModuleLoadDataEx().