﻿# Keep device-debug compilation separate from a performance baseline

Preserve effective device compilation flags; use the documented line mapping for profiling and compare the actual optimized executable.

Author: Retrivium editorial team
Updated: 2026-11-03
Canonical URL: https://retrivium.ai/journal/guide-perf-debug-build-codegen/
Language: en

A custom kernel becomes slower when a build gains useful source-level profiler information. The build also enabled device debugging, changing optimization rather than merely adding line mapping. Inspect the effective compilation contract before blaming the new kernel source. Device-debug code and an optimized performance baseline answer different questions even when both produce numerically correct outputs.

## Recover the effective command

Preserve the compiler version, device target, command and injected environment flags. NVCC documents environment variables that can prepend or append options, so the visible build file may not show the complete invocation. A generic release label does not establish the device flags used by every translation unit or a prebuilt dependency.

## Separate host and device options

Host debugging and host optimization do not by themselves describe device code generation. NVCC gives device-debug and device-optimization controls their own semantics. Read the installed compiler's documentation rather than assuming that a host optimization option cancels a device-debug flag. Save the final artifact identity so that the profile is attached to the binary actually executed.

## Use the documented mapping option

NVCC describes --generate-line-info as generating device line-number information for profiling. Its device-debug option disables device optimizations when the corresponding device-optimization control is absent. The documentation also defines their explicit combined behavior. Preserve the exact combination instead of reducing it to a slogan that all debug information always prevents optimization.

## Compare generated evidence

Inspect the target's generated instructions, function resources and profiler source correlation for both builds. Optimization can combine, move or eliminate source operations, so a line is not a fixed-duration instruction. A larger debug instruction stream can change registers and memory behavior as well as raw instruction count. These changes belong to the compilation experiment, not automatically to an algorithmic regression.

## Maintain separate baselines

Keep a reproducible correctness-debug build and a justified optimized measurement build. Run the same checked inputs and report ordinary execution timing for the latter, preserving any profiler instrumentation separately. If source correlation is incomplete, state that limit rather than silently substituting a different build. Acceptance identifies comparable executable code; it does not guarantee identical floating-point ordering across compiler options or predict the size of a speed difference.

## Primary references

[CUDA Compiler Driver Options](https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/).

[Nsight Compute Report and Source Views](https://docs.nvidia.com/nsight-compute/NsightCompute/index.html).

[CUDA Function Resource Attributes](https://docs.nvidia.com/cuda/cuda-runtime-api/cuda_runtime_api/structcudaFuncAttributes.html).

Related reading: [Reproducible inference stacks: preserving a GPU pilot’s result](/journal/software-stack-reproducibility/); [GPU profiling: sampling and instrumentation observe different events](/journal/learn-gpu-profiler-sampling-instrumentation/).
