supranational / supra_seal

Apache License 2.0
32 stars 21 forks source link

PC1/PC2: linker issues on compile time #22

Closed vmx closed 1 year ago

vmx commented 1 year ago

I currently try to get PC1/PC2 compiled. Though I get linker errors like this (full log):

  = note: /usr/bin/ld.bfd: /home/vmx/src/pl/filecoin/upstream/supra_seal/obj/libsupraseal.a(pc2.o): in function `__device_stub__Z15poseidon_hash_2ILi12EEvP4fr_t15kernel_params_tiii(fr_t*, kernel_params_t const&, int, int, int)':
          /tmp/tmpxft_001162d9_00000000-6_pc2.compute_70.cudafe1.stub.c:30:(.text+0x95): undefined reference to `__cudaPopCallConfiguration'
          /usr/bin/ld.bfd: /home/vmx/src/pl/filecoin/upstream/supra_seal/obj/libsupraseal.a(pc2.o): in function `__device_stub__Z15poseidon_hash_2ILi12EEvP4fr_t15kernel_params_tiii(fr_t*, kernel_params_t const&, int, int, int)':
          /usr/local/cuda/bin/../targets/x86_64-linux/include/cuda_runtime.h:216:(.text+0xc8): undefined reference to `cudaLaunchKernel'
          /usr/bin/ld.bfd: /home/vmx/src/pl/filecoin/upstream/supra_seal/obj/libsupraseal.a(pc2.o): in function `__device_stub__Z15poseidon_hash_3ILi12EEvP4fr_t15kernel_params_tiii(fr_t*, kernel_params_t const&, int, int, int)':
          /tmp/tmpxft_001162d9_00000000-6_pc2.compute_70.cudafe1.stub.c:32:(.text+0x165): undefined reference to `__cudaPopCallConfiguration'
          /usr/bin/ld.bfd: /home/vmx/src/pl/filecoin/upstream/supra_seal/obj/libsupraseal.a(pc2.o): in function `__device_stub__Z15poseidon_hash_3ILi12EEvP4fr_t15kernel_params_tiii(fr_t*, kernel_params_t const&, int, int, int)':
          /usr/local/cuda/bin/../targets/x86_64-linux/include/cuda_runtime.h:216:(.text+0x198): undefined reference to `cudaLaunchKernel'
          /usr/bin/ld.bfd: /home/vmx/src/pl/filecoin/upstream/supra_seal/obj/libsupraseal.a(pc2.o): in function `__device_stub__Z15poseidon_hash_4ILi12EEvPK4fr_tPS0_S2_ib(fr_t const*, fr_t*, fr_t const*, int, bool)':
          /tmp/tmpxft_001162d9_00000000-6_pc2.compute_70.cudafe1.stub.c:34:(.text+0x24c): undefined reference to `__cudaPopCallConfiguration'
          /usr/bin/ld.bfd: /home/vmx/src/pl/filecoin/upstream/supra_seal/obj/libsupraseal.a(pc2.o): in function `__device_stub__Z15poseidon_hash_4ILi12EEvPK4fr_tPS0_S2_ib(fr_t const*, fr_t*, fr_t const*, int, bool)':
          /usr/local/cuda/bin/../targets/x86_64-linux/include/cuda_runtime.h:216:(.text+0x27f): undefined reference to `cudaLaunchKernel'
          /usr/bin/ld.bfd: /home/vmx/src/pl/filecoin/upstream/supra_seal/obj/libsupraseal.a(pc2.o): in function `__device_stub__Z15poseidon_hash_2ILi9EEvP4fr_t15kernel_params_tiii(fr_t*, kernel_params_t const&, int, int, int)':
          /tmp/tmpxft_001162d9_00000000-6_pc2.compute_70.cudafe1.stub.c:38:(.text+0x315): undefined reference to `__cudaPopCallConfiguration'
          /usr/bin/ld.bfd: /home/vmx/src/pl/filecoin/upstream/supra_seal/obj/libsupraseal.a(pc2.o): in function `__device_stub__Z15poseidon_hash_2ILi9EEvP4fr_t15kernel_params_tiii(fr_t*, kernel_params_t const&, int, int, int)':
          /usr/local/cuda/bin/../targets/x86_64-linux/include/cuda_runtime.h:216:(.text+0x348): undefined reference to `cudaLaunchKernel'

Steps to reproduce:

-[[bin]] -name = "c2" -path = "src/c2.rs" +#[[bin]] +#name = "c2" +#path = "src/c2.rs"

[features] default = ["32GiB"] @@ -21,7 +21,7 @@ chrono = "0.4" filecoin-proofs-api = {version = "14.0.0", default-features = false } filecoin-proofs-v1 = { package = "filecoin-proofs", version = "~14.0.0", default-features = false } storage-proofs-core = { version = "~14.0.0", default-features = false } -supraseal-c2 = { path = "../../c2/" } +#supraseal-c2 = { path = "../../c2/" }

[target."cfg(target_arch = \"aarch64\")".dependencies] sha2 = { version = "0.10.2", features = ["compress", "asm"] }

 - Then run:
  cd demos/rust
  cargo update
  CXX='/usr/bin/g++-12' RUSTFLAGS='-C target-cpu=native' cargo +nightly build --release
  ````
vmx commented 1 year ago

I think I got a step further. I think it's important to be on the exact same blst version. That can be done with using filecoin proofs version 0.15.0 and patching blst to current HEAD. The error I then get is

  = note: /usr/bin/ld.bfd: /home/simon/vmx/supra_seal/obj/libsupraseal.a(sector_parameters.o): undefined reference to symbol '_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE7compareEPKc@@GLIBCXX_3.4.21'
          /usr/bin/ld.bfd: /lib/x86_64-linux-gnu/libstdc++.so.6: error adding symbols: DSO missing from command line
          collect2: error: ld returned 1 exit status

which sounds more like a systems/environment/compiler issue.

vmx commented 1 year ago

I managed to get it compiled cudart_static was missing.

This is the diff I ended up with:

--- a/.cargo/config.toml
+++ b/.cargo/config.toml
@@ -1,4 +1,4 @@
-[patch.crates-io]
-blst = { git = "https://github.com/supranational/blst" }
-sppark = { git = "https://github.com/supranational/sppark" }
-bellperson = { path = "c2/bellperson", version = "0.24.1"}
+#[patch.crates-io]
+#blst = { git = "https://github.com/supranational/blst" }
+#sppark = { git = "https://github.com/supranational/sppark" }
+#bellperson = { path = "c2/bellperson", version = "0.24.1"}
diff --git a/demos/rust/Cargo.toml b/demos/rust/Cargo.toml
index 375c74b..e6c597a 100644
--- a/demos/rust/Cargo.toml
+++ b/demos/rust/Cargo.toml
@@ -5,9 +5,9 @@ edition = "2021"

 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

-[[bin]]
-name = "c2"
-path = "src/c2.rs"
+#[[bin]]
+#name = "c2"
+#path = "src/c2.rs"

 [features]
 default = ["32GiB"]
@@ -18,12 +18,18 @@ default = ["32GiB"]
 anyhow = "1.0.26"
 bincode = "1.1.2"
 chrono = "0.4"
-filecoin-proofs-api = {version = "14.0.0", default-features = false }
-filecoin-proofs-v1 = { package = "filecoin-proofs", version = "~14.0.0", default-features = false }
-storage-proofs-core = { version = "~14.0.0", default-features = false }
-supraseal-c2 = { path = "../../c2/" }
+filecoin-proofs-api = {version = "15.0.0", default-features = false }
+filecoin-proofs-v1 = { package = "filecoin-proofs", version = "15.0.0", default-features = false }
+storage-proofs-core = { version = "15.0.0", default-features = false }
+#supraseal-c2 = { path = "../../c2/" }
+
+[build-dependencies]
+find_cuda_helper = "0.2.0"

 [target."cfg(target_arch = \"aarch64\")".dependencies]
 sha2 = { version = "0.10.2", features = ["compress", "asm"] }
 [target."cfg(not(target_arch = \"aarch64\"))".dependencies]
 sha2 = { version = "0.10.2", features = ["compress"] }
+
+[patch.crates-io]
+blst = { git = "https://github.com/supranational/blst" }
diff --git a/demos/rust/build.rs b/demos/rust/build.rs
index 1655943..f30c44e 100644
--- a/demos/rust/build.rs
+++ b/demos/rust/build.rs
@@ -21,8 +21,16 @@ fn main() {
         .canonicalize()
         .expect("cannot canonicalize path");

+    // Use the first directory that was found.
+    let cuda_lib_dir = find_cuda_helper::find_cuda_lib_dirs()
+        .first()
+        .expect("CUDA not found")
+        .canonicalize()
+        .expect("cannot canonicalize path");
+
     println!("cargo:rustc-link-search={}", cpp_lib_dir.to_str().unwrap());
     println!("cargo:rustc-link-search={}", spdk_lib_dir);
+    println!("cargo:rustc-link-search={}", cuda_lib_dir.to_str().unwrap());

     println!("cargo:rustc-link-arg=-fno-omit-frame-pointer");
     println!("cargo:rustc-link-arg=-Wl,-z,relro,-z,now");
@@ -113,6 +121,7 @@ fn main() {
     println!("cargo:rustc-link-arg=-laio");
     println!("cargo:rustc-link-arg=-lc");
     println!("cargo:rustc-link-arg=-lgcc");
+    println!("cargo:rustc-link-arg=-lcudart_static");

     println!("cargo:rustc-link-lib=supraseal");
     println!("cargo:rustc-link-lib=gmp");

It compiles PC1/PC2 without the C2 part.

dot-asm commented 1 year ago

Man, it's all over the place... And none of them are expected to occur. First one looks like linking errors we had prior initial sppark release, 2nd - as if cc-rs has forgotten that it compiles c++, and 3rd - shouldn't happen if there is reference to sppark. But let's put it aside. See if you have any of the referred problems with #26 and we take it from there.

vmx commented 1 year ago

See if you have any of the referred problems with #26 and we take it from there.

Agreed to start there. Let me try it out.

dot-asm commented 1 year ago

Assumed to be resolved now. If not, reopen or open new issue.