Skip to content

[clang, CUDA, modules] Issues Compiling a CUDA Source File with C++ Modules #126500

Open
@LukasBreitwieser

Description

@LukasBreitwieser

Hi All,

I ran into issues compiling a simple CUDA source file that includes a header (see mymodule.h) if modules are enabled. Further investigation showed that the issue persists even after removing all CUDA related code (see main.cu). Compiling it with c++20 errors out due to an ambiguous call to operator new, while the compiler crashes with c++17. Here the compilation logs and generated *.pcm files: logs-and-module-cache.tar.gz

File main.cu

#include "mymodule.h"
#include <iostream>

int main() {
  std::cout << GetMessage() << std::endl;
  // Problem shows up even with all CUDA related code removed.
  return 0;
}

File mymodule.h

#ifndef MYMODULE_H
#define MYMODULE_H
#include <string>
// uncommenting the following line somehow "fixes" the issue.
//#include <iostream> 

inline std::string GetMessage() { 
  return "Hello world!";
}

#endif // MYMODULE_H

File module.modulemap

module mymodule {
  header "mymodule.h"
  export *
}

Compiler invocation:

clang++ \
  -v \
  -std=c++20 \
  -x cuda \
  --cuda-gpu-arch=sm_86 \
  -lcuda \
  -lcudart \
  -fmodules \
  -fmodule-map-file=module.modulemap \
  -fmodules-cache-path=/tmp/clang-modules \
  -o main \
  main.cu

LLVM commit

commit 2b55ef187cb6029eed43d7f4c0a3640c32691b31 (HEAD -> main, origin/main, origin/HEAD)
Author: Florian Hahn <[email protected]>
Date:   Wed Jan 29 10:50:01 2025 +0000

    [VPlan] Add helper to run VPlan passes, verify after run (NFC). (#123640)
...

LLVM configuration

cmake -G Ninja \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
    -DLLVM_ENABLE_PROJECTS="clang" \
    -DLLVM_TARGETS_TO_BUILD="host;NVPTX" \
    <path-to-llvm-project-dir>/llvm

System Info

  • OS: Ubuntu 20.04.1 LTS
  • Compiler used to compile llvm: g++ (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
  • CUDA: 12.6
  • GPU: single NVIDIA Geforce RTX 3060 with compute capability 8.6

I am happy to provide more information if needed.
Thank you in advance for taking a look and any hints on how to best debug and fix it.

Best,
Lukas

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:modulesC++20 modules and Clang Header Modulescuda

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions