Skip to content
This repository was archived by the owner on May 7, 2025. It is now read-only.

Commit ec54ef7

Browse files
authored
Merge pull request #195 from SludgePhD/rm-lazystatic
Remove `lazy_static` dependency
2 parents c65c3e0 + 7c54730 commit ec54ef7

File tree

4 files changed

+11
-12
lines changed

4 files changed

+11
-12
lines changed

Cargo.lock

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

wonnx/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ bytemuck = { version = "1.9.1", features = ["extern_crate_alloc"] }
2727
protobuf = { version = "2.27.1", features = ["with-bytes"] }
2828
log = "0.4.17"
2929
tera = { version = "1.15.0", default-features = false }
30-
lazy_static = "1.4.0"
3130
thiserror = "1.0.31"
3231
serde_derive = "1.0.137"
3332
serde = { version = "1.0.137", features = ["derive"] }

wonnx/src/compiler.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
//! Compiles individual ONNX ops to a WebGPU shader using WGSL templates
2+
use std::sync::OnceLock;
3+
24
use crate::utils::{
35
ceil, AttributeNotFoundError, DataTypeError, MultiType, NodeAttributes, ScalarType, Shape,
46
};
@@ -15,9 +17,10 @@ pub const MAX_WORKGROUP_SIZE_X: u32 = 256;
1517
pub const MAX_WORKGROUP_SIZE_Y: u32 = 256;
1618
// pub const MAX_WORKGROUP_SIZE_Z: u32 = 64;
1719

18-
lazy_static! {
19-
// Templates for shader source code that we generate for nodes
20-
pub static ref TEMPLATES: Tera = {
20+
static TEMPLATES: OnceLock<Tera> = OnceLock::new();
21+
22+
fn get_templates() -> &'static Tera {
23+
TEMPLATES.get_or_init(|| {
2124
let mut tera = Tera::default();
2225
tera.add_raw_template(
2326
"endomorphism/activation.wgsl",
@@ -66,8 +69,9 @@ lazy_static! {
6669
.unwrap();
6770
tera.add_raw_template(
6871
"matrix/pad.wgsl",
69-
include_str!("../templates/matrix/pad.wgsl")
70-
).unwrap();
72+
include_str!("../templates/matrix/pad.wgsl"),
73+
)
74+
.unwrap();
7175
tera.add_raw_template(
7276
"matrix/resize.wgsl",
7377
include_str!("../templates/matrix/resize.wgsl"),
@@ -136,7 +140,7 @@ lazy_static! {
136140
)
137141
.unwrap();
138142
tera
139-
};
143+
})
140144
}
141145

142146
pub struct CompiledNode {
@@ -1428,7 +1432,7 @@ pub fn compile(
14281432
context.insert("mat3x3_stride", &(48));
14291433

14301434
// Render template
1431-
let shader = TEMPLATES
1435+
let shader = get_templates()
14321436
.render(node_template.template, &context)
14331437
.expect("failed to render shader");
14341438

wonnx/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ mod optimizer;
66
mod resource;
77
pub mod utils;
88

9-
#[macro_use]
10-
extern crate lazy_static;
11-
129
pub use compiler::CompileError;
1310
pub use gpu::GpuError;
1411
use ir::IrError;

0 commit comments

Comments
 (0)