Skip to content

Commit cbd1c0c

Browse files
committed
FxHashSet
1 parent 5d8e6f3 commit cbd1c0c

27 files changed

Lines changed: 91 additions & 89 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/llm-bench/src/bin/nchwc_coverage.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_hash::FxHashMap;
88
/// Usage:
99
/// cargo run --release --no-default-features -p yscv-llm-bench --bin nchwc_coverage \
1010
/// -- private/private/model.onnx
11-
use std::collections::HashSet;
11+
use rustc_hash::FxHashSet;
1212
use yscv_onnx::{OnnxAttribute, OnnxModel, OnnxNode, load_onnx_model_from_file};
1313

1414
fn main() {
@@ -421,8 +421,8 @@ fn run_coverage_probe(model: &OnnxModel) {
421421
// And number of exit converters (nchwc tensors consumed by non-nchwc non-Conv nodes)
422422

423423
// Use effective_weights keys as the "static" set (includes Identity-aliased weights)
424-
let static_names: HashSet<&str> = effective_weights.keys().map(|s| s.as_str()).collect();
425-
let initializer_names: HashSet<&str> = static_names.clone();
424+
let static_names: FxHashSet<&str> = effective_weights.keys().map(|s| s.as_str()).collect();
425+
let initializer_names: FxHashSet<&str> = static_names.clone();
426426
let dynamic_inputs: Vec<&str> = model
427427
.inputs
428428
.iter()
@@ -437,7 +437,7 @@ fn run_coverage_probe(model: &OnnxModel) {
437437
}
438438

439439
// Mark which tensors are in nchwc domain (after potential converter)
440-
let mut nchwc_tensors: HashSet<String> = HashSet::new();
440+
let mut nchwc_tensors: FxHashSet<String> = FxHashSet::default();
441441
// Graph inputs start as NHWC; we will count converters needed for them
442442
// if any eligible node consumes them directly.
443443

@@ -446,7 +446,7 @@ fn run_coverage_probe(model: &OnnxModel) {
446446
let mut internal_boundaries = 0usize;
447447

448448
// Track which dynamic inputs get a converter
449-
let mut converted_inputs: HashSet<String> = HashSet::new();
449+
let mut converted_inputs: FxHashSet<String> = FxHashSet::default();
450450

451451
for (i, node) in model.nodes.iter().enumerate() {
452452
if !node_eligible[i] && !matches!(node.op_type.as_str(), "Conv" | "Conv_Relu" | "Conv_SiLU")

crates/yscv-eval/src/dataset/helpers.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ pub(crate) fn parse_image_id_manifest(
4343
text: &str,
4444
format: &'static str,
4545
) -> Result<Vec<String>, EvalError> {
46-
use std::collections::HashSet;
46+
use rustc_hash::FxHashSet;
4747
let mut image_ids = Vec::new();
48-
let mut seen = HashSet::new();
48+
let mut seen = FxHashSet::default();
4949
for (line_idx, raw_line) in text.lines().enumerate() {
5050
let line_no = line_idx + 1;
5151
let line = raw_line.trim();

crates/yscv-eval/src/dataset/widerface.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
use rustc_hash::FxHashSet;
12
use rustc_hash::{FxBuildHasher, FxHashMap};
2-
use std::collections::HashSet;
33

44
use yscv_detect::{BoundingBox, CLASS_ID_FACE, Detection};
55

@@ -63,7 +63,7 @@ fn parse_widerface_ground_truth(text: &str) -> Result<Vec<WiderFaceGroundTruthFr
6363
let lines = widerface_significant_lines(text);
6464
let mut cursor = 0usize;
6565
let mut frames = Vec::new();
66-
let mut seen_ids = HashSet::new();
66+
let mut seen_ids = FxHashSet::default();
6767

6868
while cursor < lines.len() {
6969
let (image_line_no, image_id_raw) = lines[cursor];
@@ -160,7 +160,7 @@ fn parse_widerface_predictions(text: &str) -> Result<Vec<WiderFacePredictionFram
160160
let lines = widerface_significant_lines(text);
161161
let mut cursor = 0usize;
162162
let mut frames = Vec::new();
163-
let mut seen_ids = HashSet::new();
163+
let mut seen_ids = FxHashSet::default();
164164

165165
while cursor < lines.len() {
166166
let (image_line_no, image_id_raw) = lines[cursor];

crates/yscv-eval/src/dataset/yolo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::collections::HashSet;
1+
use rustc_hash::FxHashSet;
22
use std::path::Path;
33

44
use yscv_detect::{BoundingBox, Detection};
@@ -42,7 +42,7 @@ pub(crate) fn load_yolo_label_dirs(
4242

4343
fn parse_yolo_manifest(text: &str) -> Result<Vec<YoloManifestEntry>, EvalError> {
4444
let mut entries = Vec::new();
45-
let mut seen_ids = HashSet::new();
45+
let mut seen_ids = FxHashSet::default();
4646
for (line_idx, raw_line) in text.lines().enumerate() {
4747
let line_no = line_idx + 1;
4848
let line = raw_line.trim();

crates/yscv-imgproc/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ yscv-tensor = { version = "0.1", path = "../yscv-tensor" }
1515
yscv-cpu = { version = "0.1", path = "../yscv-cpu" }
1616
image = { version = "0.25", default-features = false, features = ["png", "jpeg", "bmp", "webp"] }
1717
thiserror.workspace = true
18+
rustc-hash.workspace = true
1819
rayon = "1.11"
1920

2021
[dev-dependencies]

crates/yscv-imgproc/src/ops/features.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1586,7 +1586,7 @@ pub fn hough_circles(
15861586
// Generate circle points using angular discretisation
15871587
let circumference = (2.0 * std::f32::consts::PI * r as f32).ceil() as usize;
15881588
let num_steps = circumference.max(36);
1589-
let mut visited = std::collections::HashSet::new();
1589+
let mut visited = rustc_hash::FxHashSet::default();
15901590

15911591
for step in 0..num_steps {
15921592
let angle = 2.0 * std::f32::consts::PI * step as f32 / num_steps as f32;

crates/yscv-model/src/tests/data_loader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ fn test_data_loader_multi_worker() {
7171
assert_eq!(batches.len(), 8);
7272

7373
// Verify all samples are covered (each sample has a unique fill value).
74-
let mut seen = std::collections::HashSet::new();
74+
let mut seen = rustc_hash::FxHashSet::default();
7575
for batch in &batches {
7676
let batch_size = batch.inputs.shape()[0];
7777
let sample_len = 3;

crates/yscv-onnx/src/cpu_topology.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ fn detect_linux_big_cores() -> Option<Vec<usize>> {
106106

107107
#[cfg(target_os = "linux")]
108108
fn detect_linux_physical_cores() -> Option<usize> {
109-
use std::collections::HashSet;
110-
let mut cores: HashSet<(usize, usize)> = HashSet::new();
109+
use rustc_hash::FxHashSet;
110+
let mut cores: FxHashSet<(usize, usize)> = FxHashSet::default();
111111
for id in 0..1024usize {
112112
let cpu_dir = format!("/sys/devices/system/cpu/cpu{id}");
113113
if !std::path::Path::new(&cpu_dir).exists() {

crates/yscv-onnx/src/exporter.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use prost::Message;
2-
use std::collections::HashSet;
2+
use rustc_hash::FxHashSet;
33
use yscv_tensor::Tensor;
44

55
use crate::error::OnnxError;
@@ -273,8 +273,8 @@ pub fn onnx_model_to_export_graph(model: &crate::loader::OnnxModel) -> OnnxExpor
273273
}
274274
}
275275

276-
fn infer_int64_tensor_names(nodes: &[crate::loader::OnnxNode]) -> HashSet<String> {
277-
let mut names = HashSet::new();
276+
fn infer_int64_tensor_names(nodes: &[crate::loader::OnnxNode]) -> FxHashSet<String> {
277+
let mut names = FxHashSet::default();
278278
for node in nodes {
279279
match node.op_type.as_str() {
280280
"Reshape" | "Expand" | "Tile" | "Gather" | "GatherElements" | "GatherND" => {

0 commit comments

Comments
 (0)