Skip to content

Commit

Permalink
feat(weights-diff): Add memory weights (#2995)
Browse files Browse the repository at this point in the history
  • Loading branch information
ukint-vs authored Jul 28, 2023
1 parent f2c7aa6 commit 51d77aa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions scripts/weight-diff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,4 @@ git checkout "$current_branch"

cargo run --package gear-weight-diff --release -- diff "$dump_path1" "$dump_path2" "$runtime" "instruction" $flag
cargo run --package gear-weight-diff --release -- diff "$dump_path1" "$dump_path2" "$runtime" "host-fn" $flag
cargo run --package gear-weight-diff --release -- diff "$dump_path1" "$dump_path2" "$runtime" "memory" $flag
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 51d77aa

Please sign in to comment.