Skip to content

Commit

Permalink
feat(weights-diff): Add memory weights
Browse files Browse the repository at this point in the history
  • Loading branch information
ukint-vs committed Jul 27, 2023
1 parent c28aa50 commit eca801d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions utils/weight-diff/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ enum Runtime {
enum WeightsKind {
Instruction,
HostFn,
Memory,
}

#[derive(Debug, Serialize)]
Expand All @@ -97,6 +98,7 @@ struct DeserializableDump {
struct DeserializableSchedule {
instruction_weights: IndexMap<String, serde_json::Value>,
host_fn_weights: IndexMap<String, serde_json::Value>,
memory_weights: IndexMap<String, serde_json::Value>,
}

impl DeserializableSchedule {
Expand Down Expand Up @@ -127,6 +129,18 @@ impl DeserializableSchedule {

map
}

fn memory_weights(&self) -> IndexMap<String, u64> {
let mut map = IndexMap::new();

for (k, v) in self.memory_weights.clone() {
if let Ok(v) = serde_json::from_value::<Weight>(v) {
map.insert(k, v.ref_time());
}
}

map
}
}

fn format_weight(weight: u64) -> String {
Expand Down Expand Up @@ -214,6 +228,7 @@ fn main() {
schedule2.instruction_weights(),
),
WeightsKind::HostFn => (schedule1.host_fn_weights(), schedule2.host_fn_weights()),
WeightsKind::Memory => (schedule1.memory_weights(), schedule2.memory_weights()),
};

let mut result_map = IndexMap::new();
Expand Down

0 comments on commit eca801d

Please sign in to comment.