Skip to content

Commit

Permalink
Merge pull request #195 from SludgePhD/rm-lazystatic
Browse files Browse the repository at this point in the history
Remove `lazy_static` dependency
  • Loading branch information
pixelspark authored Nov 7, 2023
2 parents c65c3e0 + 7c54730 commit ec54ef7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion wonnx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ bytemuck = { version = "1.9.1", features = ["extern_crate_alloc"] }
protobuf = { version = "2.27.1", features = ["with-bytes"] }
log = "0.4.17"
tera = { version = "1.15.0", default-features = false }
lazy_static = "1.4.0"
thiserror = "1.0.31"
serde_derive = "1.0.137"
serde = { version = "1.0.137", features = ["derive"] }
Expand Down
18 changes: 11 additions & 7 deletions wonnx/src/compiler.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//! Compiles individual ONNX ops to a WebGPU shader using WGSL templates
use std::sync::OnceLock;

use crate::utils::{
ceil, AttributeNotFoundError, DataTypeError, MultiType, NodeAttributes, ScalarType, Shape,
};
Expand All @@ -15,9 +17,10 @@ pub const MAX_WORKGROUP_SIZE_X: u32 = 256;
pub const MAX_WORKGROUP_SIZE_Y: u32 = 256;
// pub const MAX_WORKGROUP_SIZE_Z: u32 = 64;

lazy_static! {
// Templates for shader source code that we generate for nodes
pub static ref TEMPLATES: Tera = {
static TEMPLATES: OnceLock<Tera> = OnceLock::new();

fn get_templates() -> &'static Tera {
TEMPLATES.get_or_init(|| {
let mut tera = Tera::default();
tera.add_raw_template(
"endomorphism/activation.wgsl",
Expand Down Expand Up @@ -66,8 +69,9 @@ lazy_static! {
.unwrap();
tera.add_raw_template(
"matrix/pad.wgsl",
include_str!("../templates/matrix/pad.wgsl")
).unwrap();
include_str!("../templates/matrix/pad.wgsl"),
)
.unwrap();
tera.add_raw_template(
"matrix/resize.wgsl",
include_str!("../templates/matrix/resize.wgsl"),
Expand Down Expand Up @@ -136,7 +140,7 @@ lazy_static! {
)
.unwrap();
tera
};
})
}

pub struct CompiledNode {
Expand Down Expand Up @@ -1428,7 +1432,7 @@ pub fn compile(
context.insert("mat3x3_stride", &(48));

// Render template
let shader = TEMPLATES
let shader = get_templates()
.render(node_template.template, &context)
.expect("failed to render shader");

Expand Down
3 changes: 0 additions & 3 deletions wonnx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ mod optimizer;
mod resource;
pub mod utils;

#[macro_use]
extern crate lazy_static;

pub use compiler::CompileError;
pub use gpu::GpuError;
use ir::IrError;
Expand Down

0 comments on commit ec54ef7

Please sign in to comment.