Skip to content

Commit

Permalink
Extract FFI functions to another file
Browse files Browse the repository at this point in the history
  • Loading branch information
minseongg committed Oct 29, 2024
1 parent b0c3a70 commit 1470ffd
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 44 deletions.
12 changes: 1 addition & 11 deletions hazardflow-designs/src/gemmini/execute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1292,16 +1292,6 @@ fn acc_read_req<const EX_QUEUE_LENGTH: usize>(
array_map!(reqs, filter_req)
}

/// TODO: Documentation
#[magic(ffi::MeshWithDelaysWrapper())]
#[allow(clippy::type_complexity)]
pub fn mesh_with_delays_chisel<const LATENCY: usize>(
_input: (Vr<A>, Vr<B>, Vr<D>, I<VrH<MeshReq, TagsInProgress>, { Dep::Helpful }>),
) -> Valid<MeshResp>
where [(); 1 + LATENCY]: {
todo!("MeshWithDelaysWrapper.v")
}

#[allow(unused)]
fn mesh_with_delays_wrapper<const LATENCY: usize>(
a: Vr<A>,
Expand All @@ -1312,7 +1302,7 @@ fn mesh_with_delays_wrapper<const LATENCY: usize>(
where
[(); 1 + LATENCY]:,
{
(a, b, d, req).comb(mesh_with_delays_chisel::<LATENCY>)
mesh_with_delays_ffi::<LATENCY>(a, b, d, req)
}

/// Execute the mesh computation.
Expand Down
8 changes: 0 additions & 8 deletions hazardflow-designs/src/gemmini/execute/systolic_array/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,3 @@ where [(); 1 + LATENCY]: {
pub fn mesh_4_4(in_left: MeshRowData, in_top: MeshColData) -> (MeshRowData, MeshColData) {
mesh::<1>(in_left, in_top)
}

/// Chisel Mesh Wrapper.
///
/// This module allows students to proceed with future assignments even if they have not completed assignment 5.
#[magic(ffi::MeshWrapper())]
pub fn mesh_chisel(_in_left: MeshRowData, _in_top: MeshColData) -> (MeshRowData, MeshColData) {
todo!("MeshWrapper.v")
}
11 changes: 0 additions & 11 deletions hazardflow-designs/src/gemmini/execute/systolic_array/pe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,3 @@ pub fn pe(
) -> (Valid<PeRowData>, (Valid<PeColData>, Valid<PeColControl>)) {
todo!("assignment 4")
}

/// Chisel PE Wrapper.
///
/// This module allows students to proceed with future assignments even if they have not completed assignment 4.
#[magic(ffi::PE256Wrapper())]
pub fn pe_256_chisel(
_in_left: Valid<PeRowData>,
(_in_top_data, _in_top_control): (Valid<PeColData>, Valid<PeColControl>),
) -> (Valid<PeRowData>, (Valid<PeColData>, Valid<PeColControl>)) {
todo!("PE256Wrapper.v")
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub type TileColData = [(Valid<PeColData>, Valid<PeColControl>); TILE_COLS];
/// Tile.
pub fn tile(in_left: TileRowData, in_top: TileColData) -> (TileRowData, TileColData) {
// Constructs row of the tile, which has `1 x TILE_COLS` size.
let row = flip(seq(from_fn(flip(pe_256_chisel)))); // Using `pe_256_chisel` instead of `pe` for now.
let row = flip(seq(from_fn(flip(pe_ffi)))); // Using `pe_ffi` instead of `pe` for now.

// Constructs tile, which has `TILE_ROWS x TILE_COLS` size.
let tile = seq(from_fn(row));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,3 @@ where
pub fn transposer_default(in_row: Valid<Array<U<INPUT_BITS>, 16>>) -> Valid<Array<U<INPUT_BITS>, 16>> {
transposer::<16>(in_row)
}

/// Chisel Transposer Wrapper.
///
/// This module allows students to proceed with future assignments even if they have not completed assignment 5.
#[magic(ffi::TransposerWrapper())]
pub fn transposer_chisel(_in_row: Valid<Array<U<INPUT_BITS>, 16>>) -> Valid<Array<U<INPUT_BITS>, 16>> {
todo!("TransposerWrapper.v")
}
49 changes: 49 additions & 0 deletions hazardflow-designs/src/gemmini/ffis.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//! Modules implemented as FFI.
#![allow(unused_variables)]

use super::execute::systolic_array::mesh::*;
use super::execute::systolic_array::mesh_with_delays::*;
use super::execute::systolic_array::pe::*;
use super::*;

/// Chisel MeshWithDelays Wrapper.
#[magic(ffi::MeshWithDelaysWrapper())]
pub fn mesh_with_delays_ffi<const LATENCY: usize>(
a: Vr<A>,
b: Vr<B>,
d: Vr<D>,
req: I<VrH<MeshReq, TagsInProgress>, { Dep::Helpful }>,
) -> Valid<MeshResp>
where
[(); 1 + LATENCY]:,
{
ffi!("MeshWithDelaysWrapper.v")
}

/// Chisel Mesh Wrapper.
///
/// This module allows students to proceed with future assignments even if they have not completed assignment 5.
#[magic(ffi::MeshWrapper())]
pub fn mesh_ffi(in_left: MeshRowData, in_top: MeshColData) -> (MeshRowData, MeshColData) {
ffi!("MeshWrapper.v")
}

/// Chisel Transposer Wrapper.
///
/// This module allows students to proceed with future assignments even if they have not completed assignment 5.
#[magic(ffi::TransposerWrapper())]
pub fn transposer_ffi(in_row: Valid<Array<U<INPUT_BITS>, 16>>) -> Valid<Array<U<INPUT_BITS>, 16>> {
ffi!("TransposerWrapper.v")
}

/// Chisel PE Wrapper.
///
/// This module allows students to proceed with future assignments even if they have not completed assignment 4.
#[magic(ffi::PE256Wrapper())]
pub fn pe_ffi(
in_left: Valid<PeRowData>,
(in_top_data, in_top_control): (Valid<PeColData>, Valid<PeColControl>),
) -> (Valid<PeRowData>, (Valid<PeColData>, Valid<PeColControl>)) {
ffi!("PE256Wrapper.v")
}
2 changes: 2 additions & 0 deletions hazardflow-designs/src/gemmini/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::std::*;
pub mod arithmetic;
pub mod configs;
pub mod execute;
pub mod ffis;
pub mod isa;
pub mod load;
pub mod local_addr;
Expand All @@ -16,6 +17,7 @@ pub mod store;
use arithmetic::*;
use configs::*;
use execute::*;
use ffis::*;
use isa::*;
use load::*;
use reservation_station::*;
Expand Down
2 changes: 1 addition & 1 deletion hazardflow-designs/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
pub use hazardflow_macro::*;

pub use crate::std::value::*;
pub use crate::{compiler_magic, display, hassert, hpanic};
pub use crate::{compiler_magic, display, ffi, hassert, hpanic};
13 changes: 9 additions & 4 deletions hazardflow-designs/src/std/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,15 @@ pub use value::*;
/// Indicates that the function is implemented as a compiler magic.
#[macro_export]
macro_rules! compiler_magic {
() => {
todo!()
($($msg:expr)?) => {
todo!($($msg)?)
};
($msg:expr) => {
todo!($msg)
}

/// Indicates that the function is implemented as a FFI.
#[macro_export]
macro_rules! ffi {
($($msg:expr)?) => {
todo!($($msg)?)
};
}

0 comments on commit 1470ffd

Please sign in to comment.