Skip to content
This repository has been archived by the owner on Mar 28, 2022. It is now read-only.

Build core with nvptx target #45

Closed
wants to merge 5 commits into from
Closed

Build core with nvptx target #45

wants to merge 5 commits into from

Conversation

termoshtt
Copy link
Owner

@termoshtt termoshtt commented Jul 14, 2018

Experiment to use nvptx-enabled rustc at https://github.com/rust-accel/rust

Features

  • Use libstd (based on wasm implementations)
  • Linking LLVM bitcodes by llvm-link in rustc
  • Compile into a linked LLVM bitcode

Links

See also #31

@termoshtt
Copy link
Owner Author

There is no [lib] section in Cargo.toml, i.e. this crate is compiled as rlib:

# rust-accel/rust:llvm-link has been compiled as +nvptx target
$ cargo +nvptx build -vv
   Compiling accel-core v0.2.0-alpha (file:///accel/accel-core)
     Running `rustc --crate-name accel_core src/lib.rs
 --crate-type lib --emit=dep-info,link -C debuginfo=2
 -C metadata=89823dc66a8c0ad6
 -C extra-filename=-89823dc66a8c0ad6
 --out-dir /accel/accel-core/target/nvptx64-nvidia-cuda/debug/deps
 --target nvptx64-nvidia-cuda
 -C incremental=/accel/accel-core/target/nvptx64-nvidia-cuda/debug/incremental
 -L dependency=/accel/accel-core/target/nvptx64-nvidia-cuda/debug/deps
 -L dependency=/accel/accel-core/target/debug/deps`

This creates target/nvptx64-nvidia-cuda/debug/libaccel_core.rlib, which is an ar archive:

$ ar t libaccel_core.rlib
accel_core-89823dc66a8c0ad6.524p119z00bm6tv7.rcgu.o       # LLVM bitcode
rust.metadata.bin
accel_core-89823dc66a8c0ad6.524p119z00bm6tv7.rcgu.bc.z   # Rust Object
$ xxd accel_core-89823dc66a8c0ad6.524p119z00bm6tv7.rcgu.o | head -1
00000000: 4243 c0de 3514 0000 0500 0000 620c 3024  BC..5.......b.0$
$ xxd accel_core-89823dc66a8c0ad6.524p119z00bm6tv7.rcgu.bc.z | head -n1
00000000: 5255 5354 5f4f 424a 4543 5402 0000 0034  RUST_OBJECT....4

@termoshtt
Copy link
Owner Author

What we need is the LLVM bitcode (*.o files), but it is composed in ar archive. The ar archive is a simple archive format like zip, and it can compose any files. However, it is not natural to compose bitcodes as an ar archive, it should be linked by llvm-link

@termoshtt
Copy link
Owner Author

Furthermore, there only one bitcode file. It may be due to the intriniscs.rs module contains intrinsics only. We need another code :<

@termoshtt
Copy link
Owner Author

$ ar t libaccel_core.rlib
accel_core-89823dc66a8c0ad6.2wq0crelc49frk0q.rcgu.o
accel_core-89823dc66a8c0ad6.524p119z00bm6tv7.rcgu.o
rust.metadata.bin
accel_core-89823dc66a8c0ad6.2wq0crelc49frk0q.rcgu.bc.z
accel_core-89823dc66a8c0ad6.524p119z00bm6tv7.rcgu.bc.z

Two bitcodes corresponding to lib.rs and indexing.rs

@termoshtt
Copy link
Owner Author

$ cargo +nvptx build -vv
   Compiling accel-core v0.2.0-alpha (file://accel/accel-core)
     Running `rustc --crate-name accel_core src/lib.rs --crate-type cdylib --emit=dep-info,link
 -C debuginfo=2
 -C metadata=085c35af2a1f581a
 --out-dir /accel/accel-core/target/nvptx64-nvidia-cuda/debug/deps
 --target nvptx64-nvidia-cuda
 -C incremental=/accel/accel-core/target/nvptx64-nvidia-cuda/debug/incremental
 -L dependency=/accel/accel-core/target/nvptx64-nvidia-cuda/debug/deps
 -L dependency=/accel/accel-core/target/debug/deps`

error: linking with `llvm-link` failed: exit code: 1
  = note: "llvm-link" "/accel/accel-core/target/nvptx64-nvidia-cuda/debug/deps/accel_core.1y16o1qfye96o7m0.rcgu.o"
 "-o" "/accel/accel-core/target/nvptx64-nvidia-cuda/debug/deps/libaccel_core.bc"
 "/accel/accel-core/target/nvptx64-nvidia-cuda/debug/deps/accel_core.crate.allocator.rcgu.o"
 "/stage1/lib/rustlib/nvptx64-nvidia-cuda/lib/libstd-73892a84db388a4b.rlib"
 "/stage1/lib/rustlib/nvptx64-nvidia-cuda/lib/libpanic_abort-dbdbba248951650b.rlib"
 "/stage1/lib/rustlib/nvptx64-nvidia-cuda/lib/libunwind-e8ee297dbe25844d.rlib"
 "/stage1/lib/rustlib/nvptx64-nvidia-cuda/lib/liballoc_system-5e948e8e93b206b3.rlib"
 "/stage1/lib/rustlib/nvptx64-nvidia-cuda/lib/liblibc-8a689bacec06a191.rlib"
 "/stage1/lib/rustlib/nvptx64-nvidia-cuda/lib/liballoc-057d09441be39ab5.rlib"
 "/stage1/lib/rustlib/nvptx64-nvidia-cuda/lib/libcore-b8b7fb254e56b0ab.rlib"
 "/stage1/lib/rustlib/nvptx64-nvidia-cuda/lib/libcompiler_builtins-371c588c1a3805de.rlib"

  = note: llvm-link: /stage1/lib/rustlib/nvptx64-nvidia-cuda/lib/libstd-73892a84db388a4b.rlib:1:2: error: expected integer
          !<arch>
           ^
          llvm-link: error:  loading file '/stage1/lib/rustlib/nvptx64-nvidia-cuda/lib/libstd-73892a84db388a4b.rlib'

This means that the compiler-runtime (+nvptx = /stage1 on my machine) are compiled into rlib, and llvm-link cannot be linked them. These rlibs are generated while x.py to build rustc. We need to fix it...

@termoshtt
Copy link
Owner Author

Give up to link by llvm-link (´・ω・`)

@termoshtt termoshtt closed this Jul 14, 2018
termoshtt added a commit that referenced this pull request Apr 23, 2020
Add cargo-clippy and cargo-fmt on CI

Closes #45 and #44

See merge request termoshtt/accel!65
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant