Skip to content

Commit

Permalink
channge readme
Browse files Browse the repository at this point in the history
  • Loading branch information
hercule-karuha committed May 25, 2024
1 parent 5837a9a commit 847c947
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 14 deletions.
53 changes: 43 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ This framework includes the following components:

### Uasge

First, you need to write BSV code and instantiate RProbe within it.
First, you need to write BSV code and instantiate `RProbe ` within it.

the example located at: examples/AdderPipeline/AdderPipeline.bsv

```
import RProbe::*;
Expand All @@ -29,7 +31,7 @@ module mkAdderPipeline(Empty);
rule doGet if (fetch_times < 10);
Bit#(32) data = probe.get_data();
Bit#(32) data = probe.get_data;
f2d.enq(data);
fetch_times <= fetch_times + 1;
endrule
Expand All @@ -40,6 +42,7 @@ module mkAdderPipeline(Empty);
probe.put_data(data + 1);
put_times <= put_times + 1;
if(put_times == 9) begin
probe.shut_down_server();
$finish;
end
endrule
Expand All @@ -51,35 +54,44 @@ You need to link the Rust library file when linking Bluesim.
```
$ cd bluesim-rilb
$ cargo build
$ cd <your bsv projest path>
$ cd ../examples/AdderPipeline/
$ bsc -u -sim -bdir build -p .:%/Libraries:../../probe-blue/ -simdir build AdderPipeline.bsv
// add the .a file after the link command
$ <your link command> ../../bluesim-rlib/target/debug/libblue.a
$ bsc -sim -e mkAdderPipeline -bdir build -simdir build -o adder.out ../../bluesim-rlib/target/debug/libblue.a
```

Next, write your Rust code for analyzing the data.

the example located at: examples/adder_analysis/

```
use rb_link::*;
use std::thread;
use std::time::Duration;
fn main() {
let mut server = B2RServer::new();
// ensure the data length equal to the defination in bsv
let mut server = B2RServer::new_with("/tmp/adder");
// the getter used to get data from bluesim
let mut id_getter = IDGetter::new(&server);
for i in 0..10 {
let num: u32 = i;
server.put(0, num.to_le_bytes().to_vec())
}
let handlle = server.serve();
//start a new thread to receive the data
let _ = server.serve();
thread::sleep(Duration::from_secs(3));
// get data from bluesim
let msg_vec = server.get_id_all(0);
let msg_vec = id_getter.get_id_all(0);
for msg in msg_vec {
println!(
"get from blue id:{}, cycle:{}, data:{}",
msg.id,
msg.cycles,
u32::from_le_bytes([
msg.message[0],
msg.message[1],
msg.message[1],
msg.message[2],
msg.message[3]
])
Expand All @@ -88,3 +100,24 @@ fn main() {
}
```

Please ensure the rust program runs before the bliuesim

```
$ cd examples/adder_analysis/
$ cargo run
```



The path for the socket used for communication by default is `/tmp/b2rr2b`.

You can set the desired path by configuring the `B2R_SOCKET` variable.

In another terminal:

```
B2R_SOCKET=/tmp/adder ./adder.out
```



File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "pipeline-analyzer"
name = "adder_analysis"
version = "0.1.0"
edition = "2021"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ use std::time::Duration;

fn main() {
let mut server = B2RServer::new_with("/tmp/adder");
// the getter used to get data from bluesim
let mut id_getter = IDGetter::new(&server);
for i in 0..10 {
let num: u32 = i;
server.put(0, num.to_le_bytes().to_vec())
}

//start a new thread to receive the data
let _ = server.serve();

thread::sleep(Duration::from_secs(3));
Expand Down
9 changes: 6 additions & 3 deletions examples/ten_stage_analysis/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ fn main() {
let mut server = B2RServer::new_with("/tmp/ten_stage");
let mut pipe_getter = PipeLineGetter::new(&server);

// marked probes
for i in 0..9 {
let id: u32 = i;
pipe_getter.add_fifo_probe(id);
Expand All @@ -17,6 +18,7 @@ fn main() {
pipe_getter.add_rule_probe(id);
}

// set input
for i in input_data {
server.put(20, i.to_le_bytes().to_vec())
}
Expand All @@ -25,11 +27,12 @@ fn main() {

thread::sleep(Duration::from_secs(5));

let mut fired: u32 = 0;
let mut _fired: u32 = 0;
loop {
let state = pipe_getter.get_pipeline_state();
if state.fire_rules.len() as u32 > fired {
fired = state.fire_rules.len() as u32;
// if rules fired in cycle i+1 > if rules fired in cycle i the pipeline is not stuck
if state.fire_rules.len() as u32 > _fired {
_fired = state.fire_rules.len() as u32;
} else if state.empty_fifos.len() + state.full_fifos.len() == 9 { // if all fifos is empty or full the pipeline is stuck
println!("pipeline stuck at cycle: {}", state.cycle);
print!("full fifos:");
Expand Down

0 comments on commit 847c947

Please sign in to comment.