Skip to content

Commit

Permalink
[difftest] draft vcs linking
Browse files Browse the repository at this point in the history
Failed to link due to snps doesn't implement the IEEE 1800-2023:
= note: /nix/store/2p1sq1nr09xr3xb1a9lrjgdanvk1aakb-binutils-2.42/bin/ld: warning: type of symbol `cosim_init' changed from 1 to 2 in /home/sequencer/t1/difftest/target/debug/deps/libonline_dpi-e08daffbb814a8db.rlib(online_dpi-e08daffbb814a8db.4twjnztmhnh46d6z.rcgu.o)
/nix/store/2p1sq1nr09xr3xb1a9lrjgdanvk1aakb-binutils-2.42/bin/ld: /home/sequencer/t1/difftest/target/debug/deps/libonline_dpi-e08daffbb814a8db.rlib(online_dpi-e08daffbb814a8db.3wnd5deuga8hai4e.rcgu.o): in function `online_dpi::svdpi::get_time':
/home/sequencer/t1/difftest/online_dpi/src/svdpi.rs:9:(.text._ZN10online_dpi5svdpi8get_time17hc271602d89503b28E+0x56): undefined reference to `svGetTime'
collect2: error: ld returned 1 exit status
= note: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
= note: use the `-l` flag to specify native libraries to link
= note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#rustc-link-lib)

cosim_init is conflict with SNPS symbol, we need to change ours

Reproduce via:
- nix develop --impure  .#t1.blastoise.ip.vcs-emu
- cd difftest/
- cargo run --bin online_vcs -- --elf-file $(nix build --no-link --print-out-paths .#t1.blastoise.cases.intrinsic.softmax)/bin/* --timeout 10000 --log-level trace
  • Loading branch information
sequencer committed Jul 21, 2024
1 parent 9825501 commit f640c16
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 9 deletions.
10 changes: 10 additions & 0 deletions difftest/online_vcs/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
use std::path::Path;
use std::env;

fn main() {
let vcs_lib_dir = env::var("VCS_LIB_DIR").unwrap();
println!("cargo:rustc-link-search=native={}", Path::new(&vcs_lib_dir).display());
let vcs_compiled_lib_dir = env::var("VCS_COMPILED_LIB_DIR").unwrap();
println!("cargo:rustc-link-search=native={}", Path::new(&vcs_compiled_lib_dir).display());
println!("cargo::rustc-link-lib=TestBench");
println!("cargo::rustc-link-lib=vcsnew64");
println!("cargo::rustc-link-lib=vcs_tls");
println!("cargo::rustc-link-lib=vfs");
}
15 changes: 13 additions & 2 deletions difftest/online_vcs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
extern crate online_dpi;

use std::{
ffi::{c_char, c_int, CString},
ffi::{c_char, c_int, c_void, CString},
ptr,
};

Expand All @@ -15,5 +15,16 @@ fn main() {
let argc = c_args.len() as c_int;
let argv = c_args_ptr.as_ptr() as *mut *mut c_char;

// TODO
unsafe {
vcs_main(argc, argv);
VcsInit();
VcsSimUntilInterrupt();
}
}

extern "C" {
fn vcs_main(argc: c_int, argv: *mut *mut c_char) -> c_int;
fn VcsInit() -> c_void;
fn VcsSimUntilInterrupt() -> c_void;
}

68 changes: 68 additions & 0 deletions difftest/vcs-emu.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{ lib
, callPackage
, elaborateConfig

, rustPlatform

, rust-analyzer
, rust-bindgen

, vcStaticInstallPath
, vcs-lib

, cmake
, clang-tools
}:

let
spike_interfaces = callPackage ./spike_interfaces { };

self = rustPlatform.buildRustPackage {
name = "t1-vcs-emu";
src = with lib.fileset; toSource {
root = ./.;
fileset = unions [
./spike_rs
./offline
./online_dpi
./online_drive
./online_vcs
./test_common
./Cargo.lock
./Cargo.toml
];
};

buildInputs = [
spike_interfaces
vcs-lib
];

buildFeatures = lib.optionals vcs-lib.enable-trace [ "trace" ];

env = {
VCS_LIB_DIR = "${vcStaticInstallPath}/vcs-mx/linux64/lib";
VCS_COMPILED_LIB_DIR = "${vcs-lib}/lib";
DESIGN_VLEN = elaborateConfig.parameter.vLen;
DESIGN_DLEN = elaborateConfig.parameter.dLen;
};

cargoLock = {
lockFile = ./Cargo.lock;
};

dontUseCmakeConfigure = true;

passthru = {
devShell = self.overrideAttrs (old: {
nativeBuildInputs = old.nativeBuildInputs ++ [
rust-analyzer
rust-bindgen
clang-tools
];
});
inherit spike_interfaces;
};
};
in
self
5 changes: 0 additions & 5 deletions ipemu/src/TestBench.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ class TestBench(generator: SerializableModuleGenerator[T1, T1Parameter]) extends
| export "DPI-C" function dump_wave;
| function dump_wave(input string file);
|`ifdef VCS
| $$fsdbDumpfile(file);
| $$fsdbDumpvars("+all");
| $$fsdbDumpSVA();
| $$fsdbDumpvars(0);
| $$fsdbDumpon;
|`endif
|`ifdef VERILATOR
| $$dumpfile(file);
Expand Down
4 changes: 2 additions & 2 deletions nix/t1/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ lib.makeScope newScope
};
vcs-emu-compiled = innerSelf.callPackage ./vcs.nix { rtl = vcs-emu-rtl; };
vcs-emu-compiled-trace = innerSelf.callPackage ./vcs.nix { rtl = vcs-emu-rtl; enable-trace = true; };
vcs-emu = innerSelf.callPackage ../../difftest/default.nix { verilated = vcs-emu-compiled; };
vcs-emu-trace = innerSelf.callPackage ../../difftest/default.nix { verilated = vcs-emu-compiled-trace; };
vcs-emu = innerSelf.callPackage ../../difftest/vcs-emu.nix { vcs-lib = vcs-emu-compiled; vcStaticInstallPath = builtins.getEnv "VC_STATIC_HOME"; };
vcs-emu-trace = innerSelf.callPackage ../../difftest/vcs-emu.nix { vcs-lib = vcs-emu-compiled-trace; vcStaticInstallPath = builtins.getEnv "VC_STATIC_HOME"; };
};

subsystem = rec {
Expand Down

0 comments on commit f640c16

Please sign in to comment.