Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove lazy_static dependency #195

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading