Skip to content

Conversation

@romerojosh
Copy link
Collaborator

Our current torchfort.h and torchfort_rl.h header files use #ifdef ENABLE_GPU preprocessor macros to control whether cudaStream_t is redefined to enable CPU only builds. The issue is that this macro is only defined when building the library, so users building external applications with CUDA can run into problems when including these headers. In particular, if they don't also define ENABLE_GPU in their compilation, they will run into redefinition errors.

For example, compiling the following program:

#include <torchfort.h>
#include <cuda_runtime.h>

int main(int argc, char* argv[]) {
}

using a typical compilation line like:

mpicxx -I${TORCHFORT_ROOT}/include -I${CUDA_ROOT}/include example.cpp

results in the following error:

"/opt/nvidia/hpc_sdk/Linux_x86_64/25.7/cuda/include/driver_types.h", line 3035: error: invalid redeclaration of type name "cudaStream_t" (declared at line 23 of "/opt/torchfort/include/torchfort.h")
  typedef __device_builtin__ struct CUstream_st *cudaStream_t;

which can be resolved by adding -DENABLE_GPU to the compile line, which is not great user experience.

To fix this, this PR introduces a build time created torch_config.h which will define TORCHFORT_ENABLE_GPU to indicate whether TorchFort was built with GPU support or not. This configuration header is then included in torchfort.h and torchfort_rl.h to control whether cudaStream_t is redefined or not, removing the need for users to define ENABLE_GPU themselves anymore.

…t in build.

Signed-off-by: Josh Romero <joshr@nvidia.com>
Signed-off-by: Josh Romero <joshr@nvidia.com>
@romerojosh
Copy link
Collaborator Author

/build_and_test

@github-actions
Copy link

github-actions bot commented Oct 2, 2025

🚀 Build workflow triggered! View run

@github-actions
Copy link

github-actions bot commented Oct 2, 2025

✅ Build workflow passed! View run

Copy link
Collaborator

@azrael417 azrael417 left a comment

Choose a reason for hiding this comment

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

this is elegant, thanks for fixing this.

@azrael417 azrael417 merged commit 8cd8802 into master Oct 3, 2025
4 checks passed
@romerojosh romerojosh deleted the fix_headers branch November 24, 2025 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants