Skip to content

Error compiling example: couldn't load codegen backend symbol #163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
igor-semyonov opened this issue Mar 16, 2025 · 12 comments
Closed

Error compiling example: couldn't load codegen backend symbol #163

igor-semyonov opened this issue Mar 16, 2025 · 12 comments

Comments

@igor-semyonov
Copy link

Hi,

I am trying to compile the cpu add example using cargo build.

First I had to uncomment this line:

// "x86_64-unknown-linux-gnu" => "linux-x86_64",

This fixed the error of no prebuilt supported LLVM target.

rustc_codegen_nvvm now builds successfully.

Then I did cargo build again on the cpu add example.
I got the following error:

    error: couldn't load codegen backend /home/kdcadet/code/Rust-CUDA/target/debug/deps/librustc_codegen_nvvm.so: undefined symbol: _ZN4llvm6Triple9normalizeB5cxx11ENS_9StringRefE

Then I checked that so file for that symbol:

~ via 🐍 v3.12.9
❯ readelf -Ws /home/kdcadet/code/Rust-CUDA/target/debug/deps/librustc_codegen_nvvm.so|grep _ZN4llvm6Triple9normalizeB5cxx11ENS_9StringRefE
   716: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND _ZN4llvm6Triple9normalizeB5cxx11ENS_9StringRefE
 71968: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND _ZN4llvm6Triple9normalizeB5cxx11ENS_9StringRefE

~ via 🐍 v3.12.9
❯ nm -gD /home/kdcadet/code/Rust-CUDA/target/debug/deps/librustc_codegen_nvvm.so|grep _ZN4llvm6Triple9normalizeB5cxx11ENS_9StringRefE
                 U _ZN4llvm6Triple9normalizeB5cxx11ENS_9StringRefE

I am not that familiar with elf or so files, but it seems like the symbol is, in fact, present.

My OS: Gentoo Linux

cuda/cpu/add on  main [$!] is 📦 v0.1.0 via 🦀 v1.87.0-nightly took 6s
➜ rustc -Vv
rustc 1.87.0-nightly (8c392966a 2025-03-01)
binary: rustc
commit-hash: 8c392966a013fd8a09e6b78b3c8d6e442bc278e1
commit-date: 2025-03-01
host: x86_64-unknown-linux-gnu
release: 1.87.0-nightly
LLVM version: 20.1.0

cuda/cpu/add on  main [$!] is 📦 v0.1.0 via 🦀 v1.87.0-nightly took 3s
❯ git log --oneline -1
1083480 (HEAD -> main, origin/main, origin/HEAD) Fix optix examples (#160)

I am on the latest commit, as of writing, on the main branch.

@LegNeato
Copy link
Contributor

Hello! Thanks for trying the project. We are still in the process of cleaning it up after rebooting it (#130), I apologize for you hitting this issue!

We haven't taken a look a the prebuilt yet, as it was disabled in the past due to weirdness and I am not sure what that was or if it still matters. That could be what you are experiencing (or not!). As of now the best way that works with main is building LLVM (note it is v 7 / an old version) and using linux rather than windows (which you are of course).

@igor-semyonov
Copy link
Author

I suppose my LLVM20 is a bit too new then.
I will build LLVM 7 and try that.

How do I specify which LLVM to use?

@Schmiedium
Copy link
Contributor

There are a few environment variables you'll want to set to point to LLVM v7 for this project. The main one LLVM_CONFIG, and that'll be the full path to the llvm_config executable from LLVM v7 that you build. The other one if you're trying to build some of the optix examples is LIBCLANG_PATH. That will point to a directory where libclang can be found. That one can be a newer version though, at least I haven't run into issues using the latest version of clang for that.

Hope this helps!

@igor-semyonov
Copy link
Author

igor-semyonov commented Mar 16, 2025 via email

@Schmiedium
Copy link
Contributor

Yeah, it has to do with nvvm. see this issue here for a bit more info and discussion. #154

The long and short of it is that we need llvm 7 because that's what libnvvm version 1 expects. Version 2, which is available, only supports Blackwell+ cards. There also doesn't seem to be a good way to get prebuilt llvm 7 automatically, since it needs to target the nvptx component as well

@igor-semyonov
Copy link
Author

Well, I compiled LLVM7 and set the LLVM_CONFIG variable and got further to this error:

     Compiling add_gpu v0.1.0 (/home/kdcadet/code/Rust-CUDA/examples/cuda/gpu/add_gpu)
  error: rustc_codegen_nvvm requires at least libnvvm 1.6 (CUDA 11.2)

  error: could not compile `add_gpu` (lib) due to 1 previous error

Do I need to install nvvm or is it packaged with rust_cuda?

@LegNeato
Copy link
Contributor

LegNeato commented Mar 17, 2025

It might help to look at what CI does, as it installs / gets everything on stock ubuntu images:

- name: Checkout repository

nvvm comes with the CUDA install, but note CI installs CUDA 11.2.2. From this CI job:

Run Jimver/[email protected]
  with:
    cuda: 11.2.2
    sub-packages: []
    non-cuda-sub-packages: []
    method: local
    linux-local-args: ["--toolkit", "--samples"]
    use-github-cache: true
    use-local-cache: true
    log-file-suffix: log.txt
  env:

If you are using the latest CUDA toolkit, you are probably hitting #100 (comment).

Are you using nix? If so you may be hitting #135.

Here is how nvidia's sample code finds nvvm with cmake fwiw.

@LegNeato
Copy link
Contributor

(apologies for the jankiness, we are still digging out / rebooting the project!)

@Schmiedium
Copy link
Contributor

Are you using CUDA 12.8? If so, I think I see the issue. In the find_cuda_helper crate, where we check the version of libnvvm, it'll fail if the minor version is below 6. CUDA 12.8 ships libnvvm version 2.0, which fails that check and gives the error message you're seeing.

I'll send a fix for that in a couple minutes.

The relevant place is in rustc_codegen_nvvm/src/nvvm.rs line 66

@igor-semyonov
Copy link
Author

Thank you for the detailed responses.
Checking the CI is a really good hint that I should have thought of.

No worries about the jankiness! Thank you for the work you all are putting into this!

@LegNeato
Copy link
Contributor

@igor-semyonov can you try main and if it fixes this close it? Thanks!

@igor-semyonov
Copy link
Author

igor-semyonov commented Mar 18, 2025

Wow. It worked. This is just like magic!
Thank you!

The add example worked!

By the way, this are my driver and CUDA versions.
| NVIDIA-SMI 570.124.04 Driver Version: 570.124.04 CUDA Version: 12.8 |

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

No branches or pull requests

3 participants