Prefer to read without ads? Become a member — from $10/month — and support the work. Already a member? Log in to read ad-free on this device.

4.2 ptxas, The PTX Assembler

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

--abi-compile <yes|no>

(-abi)

Enable or disable the compiling of functions using the Application Binary Interface (ABI). The default is yes.

--allow-expensive-optimizations <true|false>

(-allow-expensive-optimizations)

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.

--compile-only

(-c)

Generate a relocatable object.

--def-load-cache [ca|cg|cs|lu|cv]

-dlcm

Default cache modifier on global load. Default value: ca.

--device-debug

(-g)

Generate debug information for device code.

--device-function-maxregcount <archmax/archmin/N>

(-func-maxregcount)

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.

--dont-merge-basicblocks

(-no-bb-merge)

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 <entry function>

(-e)

Entry function name.

--fmad <true|false>

(-fmad)

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-info

(-lineinfo)

Generate line-number information for device code.

--gpu-name <gpu name>

(-arch)

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.

--input-as-string <ptx-string>

(-ias)

Specifies the string containing the PTX module to compile on the command line.

--machine [32:64]

(-m)

Compile for 32-bit versus 64-bit architecture.

--maxrregcount <archmax/archmin/N>

-maxrregcount

Specify the maximum amount of registers that GPU functions can use.

--opt-level <N>

(-O)

Specifies the optimization level (0-3).

--options-file <filename>

(-optf)

Include command-line options from the specified file.

--output-file <filename>

(-o)

Specify name of output file. (Default: elf.o)

--return-at-end

-ret-end

Suppresses the default ptxas behavior of optimizing out return instructions at the end of the program, for improved debuggability.

--sp-bounds-check

(-sp-bounds-check)

Generate a stack-pointer bounds-checking code sequence. Automatically enabled when --device-debug (-g) or --generate-line-info (-lineinfo) is specified.

--suppress-double-demote-warning

-suppress-double-demote-warning

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.

--verbose

-v

Enable verbose mode.
--version Print version information.

--warning-as-error

-Werror

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_TARGET_COMPUTE_10, CU_TARGET_COMPUTE_11, CU_TARGET_COMPUTE_12, CU_TARGET_COMPUTE_13, CU_TARGET_COMPUTE_20, CU_TARGET_COMPUTE_21, CU_TARGET_COMPUTE_30,

CU_TARGET_COMPUTE_35.

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().