-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pull request to a new branch #1
Open
hercule-karuha
wants to merge
48
commits into
mastesr
Choose a base branch
from
main
base: mastesr
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 45 commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
3efccb2
Update README.md
hercule-karuha 8c236b2
blue probe
hercule-karuha 6abe977
Create LICENSE
hercule-karuha 2bea3b6
add put_t and get_t
hercule-karuha c4d9c79
add ignore
hercule-karuha 261a6fa
bluesim probe ilb
hercule-karuha adfb73a
rb-link
hercule-karuha 17b899e
add examples
hercule-karuha a127a7f
clippy fix
hercule-karuha b9f4b30
remove warning
hercule-karuha 7a362ef
add ignore
hercule-karuha feccc7a
change to server
hercule-karuha 79428ef
change RProbe type
hercule-karuha dd60176
pass simple test
hercule-karuha b30ad1f
reduce nest
hercule-karuha 678315f
add get by id and bycle
hercule-karuha 097754b
remove debug message
hercule-karuha 43bbd59
add tenstage
hercule-karuha 5db36e7
fix tenstage error
hercule-karuha cc2b1ae
add simple doc and test
hercule-karuha 1624a37
remove log file
hercule-karuha f87343c
clippy fix
hercule-karuha 5dbcd91
add defaule
hercule-karuha 06c07d6
add ci
hercule-karuha 3136b8e
fmt
hercule-karuha 632c964
change to deafult
hercule-karuha 73a1294
remove parentheses
hercule-karuha ab365e7
remove cargo lock
hercule-karuha efe0538
bule to blue
hercule-karuha 9840cf0
blue typo in ci and readme
hercule-karuha f19ea40
fmt
hercule-karuha b1eec7b
use OnceLock
hercule-karuha c54e01b
change to signle stream && remove sleep
hercule-karuha 4da6837
add width defination
hercule-karuha 9f15eda
change test to pass
hercule-karuha 153db15
allow clippy in test
hercule-karuha 37b1e0b
add fifo probe type
hercule-karuha 28f49aa
add pipeline analysis
hercule-karuha d390d01
refactor add getter
hercule-karuha 9aef4c1
add shut down & new_with
hercule-karuha b3ee694
add new test
hercule-karuha 5837a9a
ci fix
hercule-karuha 847c947
channge readme
hercule-karuha 1db7f0c
add makefile
hercule-karuha 56199e3
add example readme
hercule-karuha 55e4b57
add Publisher & Subscriber
hercule-karuha 0f8954a
test Publisher
hercule-karuha 2eba386
change shutdown
hercule-karuha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
name: "A+: CI" | ||
|
||
permissions: | ||
contents: write | ||
|
||
on: | ||
workflow_dispatch: | ||
workflow_call: | ||
pull_request: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
cargo-build: | ||
name: Cargo Build | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Fetch Repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install stable toolchain | ||
uses: actions-rust-lang/setup-rust-toolchain@v1 | ||
|
||
- name: Build rlib | ||
run: cd bluesim-rlib && cargo b --workspace --all-targets --all-features | ||
|
||
- name: Build rb_link | ||
run: cd rb_link && cargo b --workspace --all-targets --all-features | ||
|
||
cargo-fmt: | ||
name: Cargo fmt | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Fetch Repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install stable toolchain | ||
uses: actions-rust-lang/setup-rust-toolchain@v1 | ||
with: | ||
components: rustfmt | ||
|
||
- name: Rustfmt Check rlib | ||
run: cd bluesim-rlib && cargo fmt --all --check | ||
|
||
- name: Rustfmt Check rb_link | ||
run: cd rb_link && cargo fmt --all --check | ||
|
||
cargo-clippy: | ||
name: Cargo clippy | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Fetch Repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install stable toolchain | ||
uses: actions-rust-lang/setup-rust-toolchain@v1 | ||
with: | ||
components: clippy | ||
|
||
- name: Clippy Check rlib | ||
run: cd bluesim-rlib && cargo clippy --workspace --all-targets --all-features -- -Dwarnings | ||
|
||
- name: Clippy Check rb_link | ||
run: cd rb_link && cargo clippy --workspace --all-targets --all-features -- -Dwarnings | ||
|
||
cargo-test: | ||
name: Cargo test | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Fetch Repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install stable toolchain | ||
uses: actions-rust-lang/setup-rust-toolchain@v1 | ||
|
||
- name: Cargo test rb_link | ||
run: cd rb_link && cargo test | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/examples/AdderPipeline/build/ | ||
/examples/TenStage/build/ | ||
/probe-blue/build/ | ||
**/target/ | ||
**.out** | ||
command | ||
log | ||
Cargo.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 hercule-karuha | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,123 @@ | ||
# b2rr2b | ||
# b2rr2b | ||
## A Bluesim simulation probe framework. | ||
|
||
|
||
|
||
This framework includes the following components: | ||
|
||
- `/bluesim-rlib` : A Rust library called by the Bluesim program for receiving and sending data. | ||
- `/probe-blue` : BSV code for the probe, calling Rust functions through the BDPI interface. | ||
- `/rb_link` :A Rust framework for interacting with probes, capable of getting and sending data. | ||
|
||
|
||
|
||
### Uasge | ||
|
||
First, you need to write BSV code and instantiate `RProbe ` within it. | ||
|
||
the example located at: examples/AdderPipeline/AdderPipeline.bsv | ||
|
||
``` | ||
import RProbe::*; | ||
import FIFOF::*; | ||
|
||
(* synthesize *) | ||
module mkAdderPipeline(Empty); | ||
FIFOF#(Bit#(32)) f2d <- mkFIFOF; | ||
RProbe#(Bit#(32), Bit#(32)) probe <- mkRProbe(0); | ||
|
||
Reg#(Bit#(32)) fetch_times <- mkReg(0); | ||
Reg#(Bit#(32)) put_times <- mkReg(0); | ||
|
||
|
||
rule doGet if (fetch_times < 10); | ||
Bit#(32) data = probe.get_data; | ||
f2d.enq(data); | ||
fetch_times <= fetch_times + 1; | ||
endrule | ||
|
||
rule doPut; | ||
Bit#(32) data = f2d.first; | ||
f2d.deq; | ||
probe.put_data(data + 1); | ||
put_times <= put_times + 1; | ||
if(put_times == 9) begin | ||
probe.shut_down_server(); | ||
$finish; | ||
end | ||
endrule | ||
endmodule | ||
``` | ||
|
||
You need to link the Rust library file when linking Bluesim. | ||
|
||
``` | ||
$ cd bluesim-rilb | ||
$ cargo build | ||
$ cd ../examples/AdderPipeline/ | ||
$ bsc -u -sim -bdir build -p .:%/Libraries:../../probe-blue/ -simdir build AdderPipeline.bsv | ||
// add the .a file after the link command | ||
$ 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_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)); | ||
|
||
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[2], | ||
msg.message[3] | ||
]) | ||
); | ||
} | ||
} | ||
``` | ||
|
||
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 | ||
``` | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "bluesim-rlib" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[lib] | ||
crate-type = ["staticlib"] | ||
name = "blue" | ||
|
||
[dependencies] | ||
rb_link = { path = "../rb_link" } | ||
bincode = "1.3.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
//! The Rust library called by bluesim. | ||
//! If you want to use RProbe in your bluespec project, | ||
//! please compile this crate into an .a file and then link it to your bluesim executable. | ||
#![warn(clippy::unwrap_used)] | ||
use rb_link::{B2RMessage, GetPutMessage, MsgSizeType, MSG_SIZE_BYTES}; | ||
use std::env; | ||
use std::io::{Read, Write}; | ||
use std::os::unix::net::UnixStream; | ||
use std::sync::OnceLock; | ||
|
||
static mut STREAM: OnceLock<UnixStream> = OnceLock::new(); | ||
|
||
/// # Safety | ||
/// This function should not be called by Rust code. | ||
/// Get data from your rust program. | ||
/// called by RProbe::get_data() | ||
#[no_mangle] | ||
pub unsafe extern "C" fn get(res_ptr: *mut u8, id: u32, _cycles: u32, size: u32) { | ||
// println!("send get"); | ||
// check the ptr is not null | ||
if res_ptr.is_null() { | ||
panic!("res_ptr is a null pointer!"); | ||
} | ||
if _cycles == u32::MAX { | ||
panic!("cycles over flow!"); | ||
} | ||
let mut stream = STREAM.get_or_init(|| { | ||
let socket = match env::var("B2R_SOCKET") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. duplicated code should go into a function |
||
Ok(path) => path, | ||
Err(_) => "/tmp/b2rr2b".to_string(), | ||
}; | ||
UnixStream::connect(socket).expect("Failed to connect to socket") | ||
}); | ||
|
||
let get_message = GetPutMessage::Get(id); | ||
let serialized = bincode::serialize(&get_message).expect("Serialization failed"); | ||
|
||
// The initial 4-byte data specifies the byte count of the message in the u32 format. | ||
let msg_size = serialized.len() as MsgSizeType; | ||
let mut msg_with_size = Vec::with_capacity(MSG_SIZE_BYTES + serialized.len()); | ||
msg_with_size.extend_from_slice(&msg_size.to_le_bytes()); | ||
msg_with_size.extend(serialized.iter()); | ||
stream | ||
.write_all(&msg_with_size) | ||
.expect("Failed to write to stream"); | ||
|
||
let res_slice = std::slice::from_raw_parts_mut(res_ptr, size as usize); | ||
stream | ||
.read_exact(res_slice) | ||
.expect("Failed to read from stream"); | ||
} | ||
|
||
/// # Safety | ||
/// This function should not be called by Rust code. | ||
/// Put data to your rust program. | ||
/// called by RProbe::put_data() | ||
#[no_mangle] | ||
pub unsafe extern "C" fn put(id: u32, cycles: u32, data_ptr: *mut u8, size: u32) { | ||
// println!("send put"); | ||
// check the ptr is not null | ||
if data_ptr.is_null() { | ||
panic!("data_ptr is a null pointer!"); | ||
} | ||
if cycles == u32::MAX { | ||
panic!("cycles over flow!"); | ||
} | ||
|
||
let mut stream = STREAM.get_or_init(|| { | ||
let socket = match env::var("B2R_SOCKET") { | ||
Ok(path) => path, | ||
Err(_) => "/tmp/b2rr2b".to_string(), | ||
}; | ||
UnixStream::connect(socket).expect("Failed to connect to socket") | ||
}); | ||
|
||
let data_slice = std::slice::from_raw_parts(data_ptr, size as usize); | ||
let b2r_message = B2RMessage { | ||
id, | ||
cycles, | ||
message: data_slice.to_vec(), | ||
}; | ||
let put_message = GetPutMessage::Put(b2r_message); | ||
let serialized = bincode::serialize(&put_message).expect("Serialization failed"); | ||
|
||
// The initial 4-byte data specifies the byte count of the message in the u32 format. | ||
let msg_size = serialized.len() as MsgSizeType; | ||
let mut msg_with_size = Vec::with_capacity(MSG_SIZE_BYTES + serialized.len()); | ||
msg_with_size.extend_from_slice(msg_size.to_le_bytes().as_slice()); | ||
msg_with_size.extend(serialized.iter()); | ||
|
||
stream | ||
.write_all(&msg_with_size) | ||
.expect("Failed to write to stream"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import RProbe::*; | ||
import FIFOF::*; | ||
|
||
(* synthesize *) | ||
module mkAdderPipeline(Empty); | ||
FIFOF#(Bit#(32)) f2d <- mkFIFOF; | ||
RProbe#(Bit#(32), Bit#(32)) probe <- mkRProbe(0); | ||
|
||
Reg#(Bit#(32)) fetch_times <- mkReg(0); | ||
Reg#(Bit#(32)) put_times <- mkReg(0); | ||
|
||
|
||
rule doGet if (fetch_times < 10); | ||
Bit#(32) data = probe.get_data; | ||
f2d.enq(data); | ||
fetch_times <= fetch_times + 1; | ||
endrule | ||
|
||
rule doPut; | ||
Bit#(32) data = f2d.first; | ||
f2d.deq; | ||
probe.put_data(data + 1); | ||
put_times <= put_times + 1; | ||
if(put_times == 9) begin | ||
probe.shut_down_server(); | ||
$finish; | ||
end | ||
endrule | ||
endmodule |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No parentheses here