Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
396c7ec
Ignore target directory
oluwatimilehin Nov 3, 2025
7a13643
First pass: monitor from transfer_from_hbm function
oluwatimilehin Nov 3, 2025
13bb972
Add memory usage statistics to memory traits
oluwatimilehin Nov 4, 2025
ff43a8e
Revert changes from initial implementation
oluwatimilehin Nov 4, 2025
09baa05
Report bytes per second
oluwatimilehin Nov 5, 2025
39a74c6
Review comments: Remove HBM lock, introduce WithStats struct
oluwatimilehin Nov 12, 2025
5297f6b
Merge branch 'main' into statistics-monitor
oluwatimilehin Nov 12, 2025
dadb446
fix bmm test bugs
GeorgeWu1204 Nov 12, 2025
a688bf8
Simplify logic: wrap WithTiming in WithStats
oluwatimilehin Nov 12, 2025
3982e9b
Address review comment: make WithStats impl more generic
oluwatimilehin Nov 12, 2025
baf4745
latency evaluation
GeorgeWu1204 Nov 13, 2025
d83a726
cost model for paper
GeorgeWu1204 Nov 19, 2025
7f82284
fix simulation bugs for linear and flashattn
GeorgeWu1204 Nov 19, 2025
7e52514
S_MAP_V_TEST
GeorgeWu1204 Nov 19, 2025
e64a5f1
mask for rest vec operation
GeorgeWu1204 Nov 20, 2025
e6676dd
Merge pull request #32 from GeorgeWu1204/statistics-monitor
GeorgeWu1204 Nov 21, 2025
d46df13
fix preload multi preload_len load bugs
GeorgeWu1204 Nov 22, 2025
ef340a7
test for ffn
GeorgeWu1204 Nov 24, 2025
c79d74e
fix weight memory mismatch bugs in matmul, pass check for linear
GeorgeWu1204 Nov 24, 2025
fd54752
fix rms norm bugs caused by new preload function
GeorgeWu1204 Nov 25, 2025
de7e221
fix up and gate proj asm bug in ffn
GeorgeWu1204 Nov 26, 2025
2958d30
silu pass acc check
GeorgeWu1204 Nov 26, 2025
508d58a
preload for batch = 1
GeorgeWu1204 Nov 26, 2025
cd52ed5
update plena isa spec
GeorgeWu1204 Dec 1, 2025
ca3c7ce
hbm int fetch and extend operand function field for prefetch_v
GeorgeWu1204 Dec 1, 2025
30ecd71
replace original fp vect based vsram with binary based one
GeorgeWu1204 Dec 2, 2025
a0f1517
vsram support write int
GeorgeWu1204 Dec 2, 2025
ab6cba8
include int type in behave simulator
GeorgeWu1204 Dec 2, 2025
799c2ad
scripts to create hbm sim mem for int
GeorgeWu1204 Dec 2, 2025
5415396
pass check int load
GeorgeWu1204 Dec 2, 2025
d2f2fbd
dllm1_test case update
GeorgeWu1204 Dec 5, 2025
eb11dbd
fix bugs related to mx data gen
GeorgeWu1204 Dec 6, 2025
99b0076
linear test pass
GeorgeWu1204 Dec 6, 2025
ec16ccc
solve bugs for memory alignment
GeorgeWu1204 Dec 8, 2025
f566d8c
fix view mem bugs for int
GeorgeWu1204 Dec 8, 2025
f90b6b5
fix error for int load, add strided load for dllm_test
GeorgeWu1204 Dec 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ build/

doc/figure_gen/*

tools/cost_model/latency/*.png
tools/cost_model/utilisation/*.png

moduleparamid
default.svf

Expand Down Expand Up @@ -61,6 +64,7 @@ ckpts_*
*.db
*.db-journal
co_design/interface/config.toml
target/

# behavioral simulator
behavioral_simulator/target
Expand Down
10 changes: 10 additions & 0 deletions behavioral_simulator/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions behavioral_simulator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ memory = { path = "lib/memory" }
ramulator = { path = "lib/ramulator" }
buddy = { path = "lib/buddy" }
quantize = { path = "lib/quantize" }
vector_sram = { path = "lib/vector_sram" }
tokio = { version = "1.45.1", features = ["macros", "rt", "rt-multi-thread", "sync"] }
anyhow = "1"
async-trait = "0.1.88"
Expand All @@ -26,6 +27,7 @@ members = [
"lib/ramulator",
"lib/buddy",
"lib/quantize",
"lib/vector_sram",
]

[profile.release]
Expand Down
52 changes: 52 additions & 0 deletions behavioral_simulator/lib/memory/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
use std::mem::ManuallyDrop;
use std::sync::Mutex;

#[derive(Copy, Clone)]
pub struct Statistics {
pub total_bytes_read: u64,
pub total_bytes_written: u64,
}

#[async_trait::async_trait]
pub trait MemoryTimingModel: Send + Sync {
/// Read 64-bytes of memory.
Expand Down Expand Up @@ -114,3 +120,49 @@ impl<T: MemoryTimingModel, M: MemoryModel> MemoryModel for WithTiming<T, M> {
self.data.write(addr, bytes).await
}
}

// Memory model with utilization statistics
pub struct WithStats<T> {
model: T,
statistics: Mutex<Statistics>,
}

impl<T> WithStats<T> {
pub fn new(model: T) -> Self {
let stats = Statistics {
total_bytes_read: 0,
total_bytes_written: 0,
};
WithStats {
model,
statistics: Mutex::new(stats),
}
}

pub fn model(&self) -> &T {
&self.model
}

pub fn statistics(&self) -> Statistics {
self.statistics.lock().unwrap().clone()
}
}

#[async_trait::async_trait]
impl<T: MemoryModel> MemoryModel for WithStats<T> {
async fn read(&self, addr: u64) -> [u8; 64] {
{
let mut guard = self.statistics.lock().unwrap();
guard.total_bytes_read += 64;
}
self.model.read(addr).await
}

async fn write(&self, addr: u64, bytes: [u8; 64]) {
{
let mut guard = self.statistics.lock().unwrap();
guard.total_bytes_written += 64;
}
self.model.write(addr, bytes).await
}
}
49 changes: 49 additions & 0 deletions behavioral_simulator/lib/quantize/src/dtype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,44 @@ fn test_f16() {
);
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct IntType {
pub width: u32,
}

impl IntType {
pub const fn size_in_bits(self) -> u8 {
self.width as u8
}

/// Convert f32 to integer bits. Truncates the float to an integer.
pub const fn bits_from_f32(self, float: f32) -> u32 {
let int_val = float as i32;
let mask = if self.width >= 32 {
0xFFFFFFFFu32
} else {
((1u64 << self.width) - 1) as u32
};
(int_val as u32) & mask
}

/// Convert integer bits to f32. Interprets bits as unsigned integer.
pub const fn convert_bits_to_f32(self, bits: u32) -> f32 {
let mask = if self.width >= 32 {
0xFFFFFFFFu32
} else {
((1u64 << self.width) - 1) as u32
};
let masked_bits = bits & mask;
masked_bits as f32
}
}


#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DataType {
Fp(FpType),
Int(IntType),
}

impl From<FpType> for DataType {
Expand All @@ -173,22 +208,27 @@ impl From<FpType> for DataType {
}
}



impl DataType {
pub fn size_in_bits(self) -> u8 {
match self {
DataType::Fp(fp_type) => fp_type.size_in_bits(),
DataType::Int(int_type) => int_type.size_in_bits(),
}
}

pub const fn bits_from_f32(self, float: f32) -> u32 {
match self {
DataType::Fp(fp_type) => fp_type.bits_from_f32(float),
DataType::Int(int_type) => int_type.bits_from_f32(float),
}
}

pub const fn convert_bits_to_f32(self, bits: u32) -> f32 {
match self {
DataType::Fp(fp_type) => fp_type.convert_bits_to_f32(bits),
DataType::Int(int_type) => int_type.convert_bits_to_f32(bits),
}
}

Expand Down Expand Up @@ -259,6 +299,15 @@ impl MxDataType {
MxDataType::Mx { elem, .. } => elem,
}
}

/// Returns the size in bits of the element type
/// Works for both Plain (FP and Int) and Mx variants
pub fn size_in_bits(self) -> u8 {
match self {
MxDataType::Plain(data_type) => data_type.size_in_bits(),
MxDataType::Mx { elem, .. } => elem.size_in_bits(),
}
}
}

impl From<FpType> for MxDataType {
Expand Down
2 changes: 1 addition & 1 deletion behavioral_simulator/lib/quantize/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod dtype;
mod tensor;

pub use dtype::{DataType, FpType, MxDataType};
pub use dtype::{DataType, FpType, IntType, MxDataType};
pub use tensor::QuantTensor;
4 changes: 4 additions & 0 deletions behavioral_simulator/lib/runtime/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ impl Instant {
///
/// Effectively means "never".
pub const ETERNITY: Self = Self(u64::MAX);

pub const fn to_secs(&self) -> f64 {
self.0 as f64 / (1_000_000_000_000_u64 as f64)
}
}

pub trait Deadline {
Expand Down
10 changes: 10 additions & 0 deletions behavioral_simulator/lib/vector_sram/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "vector_sram"
version = "0.1.0"
edition = "2021"

[dependencies]
tokio = { version = "1.45.1", features = ["macros", "rt", "rt-multi-thread", "sync"] }
quantize = { path = "../quantize" }
tch = { version = "0.20.0", features = ["download-libtorch"] }

Loading