TECHNOLOGY

__CUDA_ARCH__ is a compilation-pass choice, not a runtime GPU query

In this article
THE QUICK TAKE

Architecture macros describe the device code being compiled; runtime discovery and cross-object definition consistency are separate responsibilities.

Identify the compile-time question

The NVCC manual defines __CUDA_ARCH__ for device compilation according to the virtual architecture being compiled. It is not a runtime query of the GPU currently running the application. A fat binary can contain code prepared for several targets, while a preprocessing decision belongs to a particular compilation pass. Keep build-target selection separate from runtime device inspection when designing architecture-specific helpers.

Separate host and device branches

The CUDA language guide demonstrates host/device functions using the macro to distinguish their compiled implementations. This does not authorize host behavior to depend on an assumed device-pass value. A host-side launch wrapper should use a supported runtime discovery mechanism for runtime decisions. A preprocessor branch can select source implementation during compilation, but it cannot inspect which GPU a later process invocation will select.

Preserve shared-header definitions

The NVCC manual also warns about architecture-dependent weak or template functions defined in shared headers during separate compilation. If participating objects instantiate the same function with different behavior because they used different compute targets, linking can retain a definition inconsistent with another object’s expectation. This is more than a missing binary-architecture problem. It concerns agreement about the definition of a shared device symbol across translation units that eventually participate in the same program.

Review the build target explicitly

The CMake architecture property distinguishes real and virtual code-generation targets. Consider a library refactor where targets inherited different architecture settings. Record the effective compilation flags and shared template instantiations rather than assuming a successful final link proves semantic agreement. Use a small fixture whose architecture branches produce distinguishable results, then verify the intended selected definition on the supported deployment path.

Keep three evidence layers visible

Record preprocessing target, linked device-code contents, and runtime selected device separately. Guides to CUDA version scopes and GPU acceptance evidence provide context. Test shared-header consistency before interpreting target-specific performance. A reliable architecture branch answers a precise compile-time question without substituting for runtime discovery or silently making separately compiled objects disagree about the behavior of the same device function.

Earn rental income from GPUs

Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.

Explore GPU hosting
← All articles