Skip to content

[HIPIFY][#2340][feature] Add implicit CUDA header inclusion to mimic nvcc behavior#2349

Merged
emankov merged 2 commits intoROCm:amd-developfrom
ranapratap55:users/ranapratap55/implicit-cuda-header
Feb 19, 2026
Merged

[HIPIFY][#2340][feature] Add implicit CUDA header inclusion to mimic nvcc behavior#2349
emankov merged 2 commits intoROCm:amd-developfrom
ranapratap55:users/ranapratap55/implicit-cuda-header

Conversation

@ranapratap55
Copy link
Collaborator

@ranapratap55 ranapratap55 commented Feb 1, 2026

Purpose

Add implicit CUDA header pre-inclusion to hipify-clang to mimic nvcc's automatic header inclusion behavior.

Problem Statement

nvcc automatically pre-includes cuda_runtime.h at the beginning of any CUDA compilation unit. This allows CUDA code to compile without explicit #include directives.

hipify-clang uses clang for parsing, which does not perform this implicit inclusion. This causes hipification to fail for some of the source files that rely on nvcc's implicit behavior.

Solution

Introduce implicit CUDA header inclusion by adding -include cuda_runtime.h to clang's argument list during hipification. cuda_runtime.h is nvcc's single implicit entry point which transitively includes all necessary headers such as

  • crt/host_config.h (System check)
  • builtin_types.h (Basic types)
  • device_types.h (enums and structs)
  • host_defines.h (Macro definitions)

Fixes #2340

@ranapratap55 ranapratap55 self-assigned this Feb 1, 2026
@ranapratap55 ranapratap55 changed the title [HIPIFY][feature] Add implicit CUDA header inclusion to mimic nvcc be… [HIPIFY][feature] Add implicit CUDA header inclusion to mimic nvcc behavior Feb 1, 2026
@emankov emankov requested review from SyamaAmd and kzhuravl February 2, 2026 16:58
@emankov emankov added the feature Feature request or implementation label Feb 2, 2026
@emankov emankov changed the title [HIPIFY][feature] Add implicit CUDA header inclusion to mimic nvcc behavior [HIPIFY][#2340][feature] Add implicit CUDA header inclusion to mimic nvcc behavior Feb 2, 2026
@ranapratap55 ranapratap55 marked this pull request as ready for review February 9, 2026 08:50
@ranapratap55 ranapratap55 force-pushed the users/ranapratap55/implicit-cuda-header branch from 1852012 to 805b7d3 Compare February 9, 2026 09:37
@ranapratap55 ranapratap55 requested a review from emankov February 9, 2026 09:39
@emankov
Copy link
Collaborator

emankov commented Feb 10, 2026

Hi @ranapratap55,

Perhaps the last question here. Have you had a chance to try this change on the examples that were going to be "fixed" by your previous PR #2275?

@emankov emankov added the CUDA CUDA-related label Feb 11, 2026
@ranapratap55
Copy link
Collaborator Author

Hi @ranapratap55,

Perhaps the last question here. Have you had a chance to try this change on the examples that were going to be "fixed" by your previous PR #2275?

Hi @emankov,

Yes, I have tested this change against the examples from #2275 and changes from the #2349(this PR) alone did not fix that issue.

CudaMath.h Fails helper_math.h (float3 +=, -, * operators)
fastWalshTransform_kernel.cuh Fails helper_cuda.h (getLastCudaError macro)
bicubicTexture_kernel.cuh Fails helper_math.h (lerp, uchar)
MonteCarlo_reduction.cuh Fails MonteCarlo_common.h (project-specific __TOptionValue type)

Additionally, I also tested cuda-samples in 0_Introduction (46 samples, 66 source files), 1_Utilities (3 samples), and 5_Domain_Specific. The implicit cuda_runtime.h inclusion is working on all of them and no existing passing test is broken.

In summary:
PR #2349(this PR) solves the nvcc implicitly pre-inclusion errors, even for source files that don't explicitly include them. This is the fix for the root cause you identified.

PR #2275 solves the non-self-contained headers that depend on project-specific includes (like helper_math.h, helper_cuda.h). These are provided by the specific project. The --local-headers header injection addresses this by injecting the preceding system includes from the main source file when hipifying individual local headers.

@emankov
Copy link
Collaborator

emankov commented Feb 19, 2026

Thank you, @ranapratap55 , for your research and explanations. So let's ship this one.

Copy link
Collaborator

@emankov emankov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Thanks! Please add a couple of (synthetic) tests on this feature in a separate PR.

@emankov emankov merged commit 9122b69 into ROCm:amd-develop Feb 19, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CUDA CUDA-related feature Feature request or implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[HIPIFY][#2275][feature] Implement nvcc behavior with implicit CUDA headers

2 participants