GPU Compile Flags Explained: What They Change in a CUDA Simulation Port

Which nvcc flags change speed, which change numerical results, and how to choose and validate a starting flag set for a CUDA simulation port.

GPU Compile Flags Explained: What They Change in a CUDA Simulation Port
Written by TechnoLynx Published on 11 Jul 2026

nvcc flags fall into three groups, and a simulation port has to treat each one differently. Architecture flags (-arch, -code, -gencode) decide which GPUs the binary runs on and whether it pays a just-in-time compile at start-up. Floating-point flags (-ftz, -prec-div, -prec-sqrt, -fmad and the --use_fast_math bundle) change the numbers the kernels produce. The rest (-G, -maxrregcount, -dlto, the fast-compile levels) are chosen for debugging, speed or build time. The order of work for a port follows from that split: keep the floating-point defaults, validate against the CPU reference within a stated tolerance, and profile before touching any flag that only affects speed. Our write-up of a GPU RF propagation simulation shows where this matters: a large speedup only counts once the GPU results still agree with the validated CPU model.

How Does a Compile Flag Work in Nvcc, and What Does It Mean in Practice?

A compile flag is an instruction to one stage of the compiler about what code to produce. With nvcc there are several stages to instruct. nvcc first separates device code from host code and hands each to its own compiler, the GPU compiler for kernels and the host compiler (GCC, Clang or MSVC) for everything else. Device code is then compiled in two steps: first to PTX, which NVIDIA describes as assembly for a virtual GPU architecture, and then to binary code for a real GPU.

Each flag acts on one of those stages. -Xcompiler passes arguments through to the host compiler, and -Xptxas passes arguments to ptxas, the PTX assembler, so -Xptxas=-maxrregcount=N caps registers per thread. Host-side arguments such as -O3 pass through to the host compiler; our explainer on GCC compiler flags for inference and WASM builds is about that side, and this page stays with the device side.

Two builds of the same source with different flags are different programs: NVIDIA’s own definition of a deterministic result lists the compiler version and the compiler flags among the conditions that must match. That is why the flag set of a simulation port belongs to the validated artefact, recorded and versioned with the code, and not as boilerplate copied from a tutorial.

Which Nvcc Flags Actually Affect Performance Versus Just Correctness?

The table below sorts the flags a simulation port usually meets by what they change. “Results” means the floating-point output of a correct program can differ; “runs” means whether the binary loads on a given GPU at all.

Flag Changes speed Changes results What to know
-O3 No, already the default No nvcc uses -O3 for GPU code by default, so adding it changes nothing.
-G Yes, slower Use as a comparison build Turns off device optimisations unless --dopt is given; not meant for profiling.
-lineinfo No No The flag to use for profiling builds, so metrics map to source lines.
-arch, -code, -gencode Yes (JIT start-up, missing architecture features) Re-validate Decide which cubin and PTX go into the binary.
-ftz=true Yes Yes Flushes subnormal (denormalized) numbers to zero.
-prec-div=false, -prec-sqrt=false Yes Yes Less precise division and square root.
-fmad=true No, already the default; faster than -fmad=false Yes, usually more accurate Fuses multiplies and adds into FMA; already on by default.
--use_fast_math Yes Yes Bundles the above and swaps math calls for intrinsics; single precision only.
-maxrregcount Yes, either way Re-validate Trades per-thread registers against occupancy.
-dlto Yes Needs matching -use_fast_math across files Link-time optimisation for separately compiled device code.
-Ofast-compile, split compilation Can lower runtime speed Re-validate Trades runtime performance for compile speed.

One reading of the table matters more than the rest. -O3 is not where numerical risk comes from in nvcc, because the default build already uses it; the floating-point behaviour is set by the separate group of precision flags.

What Does Targeting a Specific GPU Architecture Change, and What Happens If It’s Wrong?

Targeting an architecture decides which compiled forms of each kernel end up in the binary. Every NVIDIA GPU has a compute capability in the form major.minor, where the major number identifies the generation. A binary can carry each kernel as cubin (machine code) and as PTX, both generated for a target compute capability. A cubin runs on GPUs with the same major revision and the same or a higher minor revision. PTX is forward-compatible: the driver compiles it to cubin at run time on any GPU with a higher compute capability than the one the PTX assumed.

In -gencode=arch=...,code=..., the arch= clause is the front-end target and must always be a PTX (compute_) version, while code= names the back-end targets, cubin (sm_), PTX or both; only the code= targets are kept in the binary, and NVIDIA recommends that at least one be PTX for future architectures. NVIDIA’s own documentation gives the multi-target pattern --gpu-architecture=compute_80 --gpu-code=compute_80,sm_86,sm_89, which embeds exact code for two GPUs plus PTX for a next-generation one in a single fat binary, with the driver picking the best match at launch. The virtual architecture should be as low as the code allows, since a higher one only narrows the set of GPUs the build can serve.

A wrong target fails in three distinct ways:

  • No compatible code at all. Binary compatibility is not guaranteed across major compute capabilities; NVIDIA’s example is that code compiled for CC 9.0 will not run on a CC 10.0 GPU, and vice versa. A kernel with no matching cubin and no embedded PTX fails to load.
  • A silent JIT penalty. When only older PTX matches, the driver JIT-compiles it at start-up. In an NVIDIA example, a library built for older SM versions took about 75 seconds of JIT at start-up on a newer GPU and was recompiled on every run because the kernels did not fit the JIT cache, which then defaulted to 32 MiB. The cache now defaults to 256 MiB and can be raised to 4 GiB through CUDA_CACHE_MAXSIZE. On clusters with the cache on a slow NFS home directory, start-up can vary from node to node, and NVIDIA’s advice is to build for the right SM version and avoid JIT entirely.
  • Missing features. Plain compute_100 excludes architecture-specific features, the f suffix allows features common to a GPU family, and the a suffix unlocks the full architecture-specific set on a specific GPU.

The default is the cautious one: without an explicit target, nvcc generates PTX and cubin for the earliest architecture the toolkit supports. nvidia-smi --query-gpu=name,compute_cap reports the compute capability of each installed GPU, and setting CUDA_FORCE_PTX_JIT confirms that the embedded PTX actually works as a fallback.

Setting Architectures from CMake

Most simulation codes build through CMake, where the CUDA_ARCHITECTURES target property lists the architectures to generate, each optionally suffixed -real or -virtual, with both generated when no suffix is given. The value native compiles for the host’s own GPUs, all covers every supported real architecture plus the highest major virtual one, and all-major limits the real set to major versions. We would set targets through this property rather than appending raw -gencode strings to a flags variable, so the architecture list lives in one place. native suits a developer workstation; for a production cluster with several GPU generations, an explicit list is easier to audit.

When Do Fast-Math or Floating-Point Flags Matter for a Physics-Based Simulation’s Numerical Fidelity?

Floating-point flags matter in a simulation because small floating-point differences integrate over a run into drift. The useful move is to take --use_fast_math apart. It includes -ftz=true and -fmad=true, lowers single-precision division accuracy, and replaces each functionName() call with the faster __functionName() intrinsic. NVIDIA’s Best Practices Guide calls it an aggressive optimisation that can reduce accuracy and change special-case handling, and notes it affects only single precision. A concrete case from the CUDA Programming Guide: sqrtf is correctly rounded (0 ULP error) by default and has up to 1 ULP of error under --use_fast_math.

The parts behave differently:

  • -ftz=true disables subnormal numbers, flushing them to zero.
  • -prec-div=false and -prec-sqrt=false give less precise division and square root.
  • -fmad=true is the outlier. FMA rounds once instead of twice and so produces a more accurate result. It is also on by default, since nvcc allows contractions unless told otherwise. What it changes is agreement with the CPU: GPU results with FMA will often differ slightly from a CPU computing the multiply and add separately.
  • Intrinsics called directly are unaffected by -prec-div, -prec-sqrt and -fmad, but are still affected by -ftz.

For maximum portability of results, NVIDIA recommends keeping -ftz=false, -prec-div=true, -prec-sqrt=true and not using --use_fast_math. The Best Practices Guide suggests a more selective route: introduce fast intrinsics by hand only where profiling shows a gain and the changed behaviour can be tolerated.

Two physics studies show how much the stakes depend on the model. In GPU molecular dynamics of a supercooled Lennard-Jones mixture, Colberg and Höfling (2009) found single precision gave quantitatively and even physically wrong results, with the diffusion coefficient deviating by up to 40%. Their double-single arithmetic also had to avoid FMA contraction, because the fused multiply does not round its intermediate product the way the algorithm assumed. By contrast, Karp et al. (2025) found standard FP32 usable for whole turbulence simulations across several solvers with no significant discrepancy from FP64. They also warn that systems with several attractors, or a symmetry sensitive to small disturbances, can be harmed by lower precision, and one of their codes developed nonphysical artefacts until its geometric quantities went back to FP64.

Those studies change precision rather than flags, but compiler choices also produce small floating-point differences that accumulate into drift. Optimisation levels can do it too. In the FLiT study by Bentley et al. (2019), moving a compressible gas dynamics code from -O2 to -O3 on IBM’s xlc changed the energy norm by 11.2% in one iteration and produced negative density, a physical impossibility. That example involves a CPU compiler, not nvcc, but it shows that “faster and still plausible” is not the same as “still correct”. The same study found that in 14 of 19 MFEM examples the fastest build was also bitwise reproducible, so reproducibility is not always the price of speed.

How Do I Tell Whether Slow Kernel Performance Is a Flag Problem or an Algorithm Problem?

Profile the kernel first. Its position on the roofline and its register behaviour guide what to change. NVIDIA’s Best Practices Guide makes the same first step its high-priority recommendation: profile a realistic workload to find where the time goes.

A Diagnostic Checklist Before Tuning Flags

  1. Is the profiled build a release build? Debug builds change code generation and timing; profile an optimised build compiled with -lineinfo, not -G.
  2. Is start-up time hiding in the measurement? In NVIDIA’s example, kernels without code for the GPU’s SM version were JIT-compiled at start-up. Time the first launch separately from steady state.
  3. Is the kernel spilling registers? -Xptxas -v lists per-kernel register, shared and constant memory use, and --warn-on-spills flags spills to local memory.
  4. Is a register cap causing the spills? In an NVIDIA training example, removing -maxrregcount=32 let a kernel use 46 registers with no spilling and improved performance by 1.22x. If a cap increases spills, it is trading occupancy for spill traffic.
  5. Where does the kernel sit on the roofline? If it is clearly memory-bandwidth bound, the access pattern is what to look at next. If occupancy and utilisation are both high, the hardware is saturated and the remedy is less algorithmic work or a restructured kernel.
  6. Did the change make the kernel faster? Kernel duration is the ground truth, not speed-of-light percentages, which can drop while a kernel gets faster.

Steps 1 to 4 look for build and flag problems. Step 5 points to the access pattern or the algorithm. That fits the position of our GPU performance engineering work: the largest gains usually come from restructuring what is computed, not from tuning how a fixed computation is compiled.

A Sensible Starting Flag Set for a CUDA Simulation Port, and How to Validate It

A defensible starting set changes as little as possible from the defaults.

Worked Example: A Starting Build

Assumptions: kernels sit in several source files, and correctness against an existing CPU code comes first.

nvcc -dc \
  -gencode arch=compute_80,code=sm_80 \
  -gencode arch=compute_90,code=sm_90 \
  -gencode arch=compute_80,code=compute_80 \
  -lineinfo -Xptxas -v \
  -c propagate.cu -o propagate.o
  • No -O3, no fast-math flags. The default is already -O3, and the floating-point defaults are the ones NVIDIA recommends for portable results.
  • One cubin per deployed architecture plus low PTX. Exact code avoids JIT, and the PTX keeps the binary forward-compatible.
  • -dc. -dc (--device-c) turns on --relocatable-device-code=true for separate compilation. Device LTO (-dlto) is an option for recovering cross-file inlining, but it must appear at both compile and link time and does not combine with JIT compilation. NVIDIA reported an average speedup of around 25% on a CUDA application suite, with little benefit where device code sits in one file or calls go through function pointers.
  • Consistent file-scope flags if LTO is added. -maxrregcount and -use_fast_math must match across files under device LTO, or be set once at link time, and LTO cannot be combined with -G.
  • No -maxrregcount yet. A cap is a tuning decision that should follow profiling, for the reasons in the checklist above.

Validating the Build Against the CPU Reference

Before the build is trusted, validating ported CUDA kernels needs known-good reference outputs from representative inputs and a comparison after every change, with bitwise identity often impossible for floating-point code and a small epsilon used instead. That comparison is part of what software porting involves; for numerical codes it needs four extra pieces of care.

First, set the tolerance with both a relative and an absolute part. In a trace-comparison study of the WRF weather model, Ciampi and colleagues (2013) used a 0.1% relative criterion plus an absolute floor of 1.0E-10, because values near zero produce large percentage differences by chance. Second, compare like with like: double and single precision results differ, an x86 host using 80-bit extended precision can differ from 64-bit GPU arithmetic, and parallel reductions change operation order and therefore rounding. Third, compare the optimised GPU build against one with device optimisations disabled (-G), as the CUDA Programming Guide recommends. Fourth, expect drift and judge whether it is acceptable. Small, acceptable differences integrated over a run make results drift apart, which need not make them invalid. In a physics model, the test is whether conserved quantities and the outputs decisions depend on stay inside the tolerance over a full-length run.

When one flag change breaks the tolerance, isolate it instead of reverting everything. In its evaluation, FLiT’s bisection compiled subsets of files with the suspect flags and the rest with the baseline, locating variability to a file 80% of the time and to a function in 75% of those cases. One fix it surfaced is worth checking in any port: an exact comparison against 0.0 in a branch turned tiny numerical differences into large output differences, and an epsilon comparison removed the problem.

What the Flag Set Costs at Build Time

Flags also affect compile time. Each architecture in a -gencode list repeats the second compilation stage, and LTO increases total compilation time while recovering performance. Device LTO shifts that cost from compile to link. For iteration builds, -Ofast-compile offers max, mid and min levels that disable optimisations in exchange for build speed, and split compilation runs optimisation passes concurrently, with the extended form able to affect binary performance. Use these for development builds, never for the binary you validate or measure.

Treat the Flag Set as Part of the Validated Model

NVIDIA defines a deterministic result as identical bitwise output under the same conditions, including compiler version, flags, hardware and inputs. Changing the architecture list or the register cap usually means re-profiling. Turning on any part of --use_fast_math means re-running the full-length comparison against the CPU reference. The question still open for each port is how much numerical difference its outputs can tolerate. The sources show the answer varies from model to model, from turbulence statistics that hold up in FP32 to glassy dynamics that break in single precision. The GPU RF propagation simulation is the case behind this page: choosing the flags deliberately is what lets a speedup like that be trusted.