denzp / rust-ptx-linker

The missing puzzle piece for NVPTX experience with Rust
MIT License
53 stars 11 forks source link

Linker fails on Windows #17

Closed bheisler closed 6 years ago

bheisler commented 6 years ago

I tried to compile some of the code from rust-inline-cuda-tutorial on Windows, and encountered this error:

error: failed to run custom build command for `chapter-1 v0.1.0 (file:///C:/Users/Brook/workspace/rust-inline-cuda-tutorial/chapter-1/host)`
process didn't exit successfully: `C:\Users\Brook\workspace\rust-inline-cuda-tutorial\target\release\build\chapter-1-f350df76ca927b39\build-script-build` (exit code: 1)
--- stderr
[PTX] Unable to build a PTX crate!
[PTX]    Compiling proxy v0.0.0 (file:///C:/Users/Brook/AppData/Local/Temp/ptx-builder/chapter_1_kernel/2777747bd38bda2e)
[PTX] error: linking with `ptx-linker` failed: exit code: 101
[PTX]   |
[PTX]   = note: "ptx-linker" "-L" "C:\\Users\\Brook\\.xargo\\lib\\rustlib\\nvptx64-nvidia-cuda\\lib" "C:\\Users\\Brook\\AppData\\Local\\Temp\\ptx-builder\\chapter_1_kernel\\2777747bd38bda2e\\target\\nvptx64-nvidia-cuda\\release\\deps\\proxy.3rg6oty3sxxix4x5.rcgu.o" "-o" "C:\\Users\\Brook\\AppData\\Local\\Temp\\ptx-builder\\chapter_1_kernel\\2777747bd38bda2e\\target\\nvptx64-nvidia-cuda\\release\\deps\\proxy.ptx" "C:\\Users\\Brook\\AppData\\Local\\Temp\\ptx-builder\\chapter_1_kernel\\2777747bd38bda2e\\target\\nvptx64-nvidia-cuda\\release\\deps\\proxy.crate.metadata.rcgu.o" "-O1" "-L" "C:\\Users\\Brook\\AppData\\Local\\Temp\\ptx-builder\\chapter_1_kernel\\2777747bd38bda2e\\target\\nvptx64-nvidia-cuda\\release\\deps" "-L" "C:\\Users\\Brook\\AppData\\Local\\Temp\\ptx-builder\\chapter_1_kernel\\2777747bd38bda2e\\target\\release\\deps" "-L" "C:\\Users\\Brook\\.xargo\\lib\\rustlib\\nvptx64-nvidia-cuda\\lib" "-Bstatic" "--whole-archive" "C:\\Users\\Brook\\AppData\\Local\\Temp\\rustcD6eN9t\\libchapter_1_kernel-f74b1c8db75e0ae3.rlib" "--no-whole-archive" "--whole-archive" "C:\\Users\\Brook\\AppData\\Local\\Temp\\rustcD6eN9t\\libmath-86f691a12c8816dd.rlib" "--no-whole-archive" "--whole-archive" "C:\\Users\\Brook\\AppData\\Local\\Temp\\rustcD6eN9t\\libcty-77e4626992983622.rlib" "--no-whole-archive" "--whole-archive" "C:\\Users\\Brook\\AppData\\Local\\Temp\\rustcD6eN9t\\libnvptx_builtins-80d5f762aa9da22c.rlib" "--no-whole-archive" "--whole-archive" "C:\\Users\\Brook\\AppData\\Local\\Temp\\rustcD6eN9t\\libcore-e6982899dc4034c4.rlib" "--no-whole-archive" "C:\\Users\\Brook\\AppData\\Local\\Temp\\rustcD6eN9t\\libcompiler_builtins-663e743ee2409b7f.rlib" "-shared" "-Bdynamic"
[PTX]   = note: Unable to find symbol 'LLVMContextCreate' in the LLVM shared lib
[PTX]           thread 'main' panicked at 'explicit panic', C:\Users\Brook\AppData\Local\Temp\cargo-installaOfHDV\release\build\rustc-llvm-proxy-8b11c485c2cc7120\out/llvm_gen.rs:4:1
[PTX]           note: Run with `RUST_BACKTRACE=1` for a backtrace.
[PTX]
[PTX]
[PTX] error: aborting due to previous error
[PTX]
[PTX] error: Could not compile `proxy`.
[PTX]
[PTX] To learn more, run the command again with --verbose.

I think this is the important bit: Unable to find symbol 'LLVMContextCreate' in the LLVM shared lib

denzp commented 6 years ago

Unfortunately, it's known limitation of *-pc-windows-msvc Rustc targets. Can you please try *-pc-windows-gnu?

The problem originates in rustc-llvm-proxy and I created a ticket there: https://github.com/denzp/rustc-llvm-proxy/issues/1

bheisler commented 6 years ago

Tried using nightly-x86_64-pc-windows-gnu - that causes it to fail in a different way:

error: failed to run custom build command for `chapter-1 v0.1.0 (file:///C:/Users/Brook/workspace/rust-inline-cuda-tutorial/chapter-1/host)`
process didn't exit successfully: `C:\Users\Brook\workspace\rust-inline-cuda-tutorial\target\debug\build\chapter-1-11d782cbdb9b9a40\build-script-build` (exit code: 1)
--- stdout
cargo:rustc-env=KERNEL_PTX_PATH=C:\Users\Brook\AppData\Local\Temp\ptx-builder\chapter_1_kernel\2777747bd38bda2e\target\nvptx64-nvidia-cuda/release/proxy.ptx

--- stderr
[PTX] Internal error: Paths misalignment in deps file
denzp commented 6 years ago

Sorry, it took me a while to fix this and pass all test without access to the real Windows environment.

I published ptx-builder version 0.4.0 with x86_64-pc-windows-gnu support.

TuckerBMorgan commented 6 years ago

It would be nice if this was listed in the README, the issue is hidden and you have to search for the error message to find it.

TuckerBMorgan commented 6 years ago

also @bheisler how did you handle the error "note: ld: cannot find -lcuda" for windows?

bheisler commented 6 years ago

@TuckerBMorgan I'm using git-bash(/MinGW) as my shell, so I just used export LIBRARY_PATH="C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1\lib\x64". Of course, you'll need to install the CUDA toolkit. If you're using Powershell or something you'll need to adapt this to however you set environment variables.

TuckerBMorgan commented 6 years ago

@bheisler Thanks!, I am trying to run your code and I will get "LaunchFailure", or "LaunchTimeout" after it runs for a little bit, and I never get a output image.

bheisler commented 6 years ago

That sounds like the watchdog timer killing the CUDA kernel. If you're running a kernel on the same GPU as your display, most operating systems will reset the card and kill the kernel if it runs longer than a few seconds. The screen can't update while the kernel is running, so this helps ensure that a long-running (or infinite-looping) kernel doesn't lock up the machine.

If you're using my path tracer code, you might have to play around with the complexity of the scene or the ROUND_COUNT/RAY_COUNT constants in the kernel to find a workload that your card can complete without hitting the timeout.