Skip to content

Commit

Permalink
chore: upgrade to WGPU 0.16.0 and other newer crates
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelspark committed Apr 20, 2023
1 parent bb5f57f commit a01c322
Show file tree
Hide file tree
Showing 12 changed files with 962 additions and 788 deletions.
1,677 changes: 921 additions & 756 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions wonnx-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ path = "src/main.rs"

[dependencies]
async-trait = "0.1.53"
env_logger = "0.9.0"
env_logger = "0.10.0"
log = "0.4.17"
ndarray = "0.15.4"
prettytable-rs = "^0.10.0"
protobuf = { version = "2.27.1", features = ["with-bytes"] }
structopt = { version = "0.3.26", features = [ "paw" ] }
thiserror = "1.0.31"
tract-onnx = { version = "0.16.7", optional = true }
wgpu = "0.14.0"
tract-onnx = { version = "0.19.12", optional = true }
wgpu = "0.16.0"
wonnx = { version = "^0.4.0" }
wonnx-preprocessing = { version = "^0.4.0" }
human_bytes = "0.3.1"
pollster = "0.2.5"
human_bytes = "0.4.1"
pollster = "0.3.0"

[dev-dependencies]
assert_cmd = "2.0.4"
4 changes: 2 additions & 2 deletions wonnx-cli/src/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ impl Inferer for CPUInferer {
cpu_inputs.insert(input_index.0, input_tensor.to_tract_tensor(&dims)?);
}

let mut cpu_inputs_ordered = TVec::new();
let mut cpu_inputs_ordered = TVec::<TValue>::new();
for i in 0..inputs.len() {
cpu_inputs_ordered.push(cpu_inputs.get(&i).unwrap().clone());
cpu_inputs_ordered.push(TValue::Const(Arc::new(cpu_inputs.get(&i).unwrap().clone())));
}

let result = self.model.run(cpu_inputs_ordered)?;
Expand Down
7 changes: 6 additions & 1 deletion wonnx-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ async fn run() -> Result<(), NNXError> {

match opt.cmd {
Command::Devices => {
let instance = wgpu::Instance::new(wgpu::Backends::all());
let backends = wgpu::util::backend_bits_from_env().unwrap_or(wgpu::Backends::PRIMARY);
let instance_descriptor = wgpu::InstanceDescriptor {
backends,
dx12_shader_compiler: wgpu::Dx12Compiler::Fxc,
};
let instance = wgpu::Instance::new(instance_descriptor);
let adapters = instance.enumerate_adapters(wgpu::Backends::all());
let mut adapters_table = Table::new();
adapters_table.add_row(row![b->"Adapter", b->"Vendor", b->"Backend"]);
Expand Down
10 changes: 5 additions & 5 deletions wonnx-preprocessing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ log = "0.4.17"
ndarray = "0.15.4"
protobuf = { version = "2.27.1", features = ["with-bytes"] }
thiserror = "1.0.31"
tokenizers = "0.11.3"
tract-onnx = { version = "^0.17.0", optional = true }
wgpu = "0.14.0"
tokenizers = "0.13.3"
tract-onnx = { version = "0.19.2", optional = true }
wgpu = "0.16.0"
wonnx = { version = "^0.4.0" }
serde_json = "^1.0"
bytemuck = "1.9.1"

[dev-dependencies]
env_logger = "0.9.0"
pollster = "0.2.5"
env_logger = "0.10.0"
pollster = "0.3.0"
4 changes: 2 additions & 2 deletions wonnx-preprocessing/src/shape_inference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ pub(crate) fn infer_output_shapes(
axis += r;
}
let out_rank = q + r - 1;
return Ok(vec![Shape::from(
Ok(vec![Shape::from(
input_shapes[0].data_type,
(0..out_rank)
.map(|idx| {
Expand All @@ -588,7 +588,7 @@ pub(crate) fn infer_output_shapes(
})
.collect::<Vec<i64>>()
.as_ref(),
)]);
)])
}

("Shape", 1, 1) => {
Expand Down
4 changes: 2 additions & 2 deletions wonnx-py/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ homepage = "https://github.com/webonnx/wonnx"
wonnx = { version = "^0.4.0" }
protobuf = { version = "2.27.1", features = ["with-bytes"] }
pyo3 = { version = "0.18.1", features = ["abi3-py37"] }
pollster = "0.2.5"
env_logger = "0.9.0"
pollster = "0.3.0"
env_logger = "0.10.0"

# prevents package from thinking it's in the workspace

Expand Down
4 changes: 2 additions & 2 deletions wonnx-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ crate-type = ["cdylib"]
[dependencies]
wonnx = { version = "^0.4.0" }
log = "0.4.17"
console_log = "0.2.0"
console_log = "0.2.2"
console_error_panic_hook = "0.1.7"
getrandom = { version = "0.2.6", features = ["js"] }
wasm-bindgen = { version = "0.2.80", features = ["serde-serialize"] } # remember to change version in wiki as well
wasm-bindgen-futures = "0.4.30"
wasm-bindgen-test = "0.3.30"
serde-wasm-bindgen = "0.4"
serde-wasm-bindgen = "0.5.0"
js-sys = "0.3.57"
web-sys = { version = "0.3.58", features = [
"Document",
Expand Down
6 changes: 3 additions & 3 deletions wonnx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ exclude = [
]

[dependencies]
wgpu = "0.14.0"
wgpu = "0.16.0"
bytemuck = { version = "1.9.1", features = ["extern_crate_alloc"] }
protobuf = { version = "2.27.1", features = ["with-bytes"] }
log = "0.4.17"
Expand All @@ -41,5 +41,5 @@ parking_lot = { version = "0.11.1", features = ["wasm-bindgen"]}
image = "0.24.2"
ndarray = "0.15.4"
approx = "0.5.1"
pollster = "0.2.5"
env_logger = "0.9.0"
pollster = "0.3.0"
env_logger = "0.10.0"
6 changes: 5 additions & 1 deletion wonnx/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ use wgpu::{util::DeviceExt, BufferUsages};
// Get a device and a queue, honoring WGPU_ADAPTER_NAME and WGPU_BACKEND environment variables
pub async fn request_device_queue() -> (wgpu::Device, wgpu::Queue) {
let backends = wgpu::util::backend_bits_from_env().unwrap_or(wgpu::Backends::PRIMARY);
let instance = wgpu::Instance::new(backends);
let instance_descriptor = wgpu::InstanceDescriptor {
backends,
dx12_shader_compiler: wgpu::Dx12Compiler::Fxc,
};
let instance = wgpu::Instance::new(instance_descriptor);
let adapter = wgpu::util::initialize_adapter_from_env_or_default(&instance, backends, None)
.await
.expect("No GPU found given preference");
Expand Down
6 changes: 3 additions & 3 deletions wonnx/templates/matrix/gemm.wgsl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
type Scalar = {{ scalar_type }};
type GemmVec = vec{{ kernel_size }}<{{ scalar_type }}>;
type GemmMat = mat{{ kernel_size }}x{{ kernel_size }}<{{ scalar_type }}>;
alias Scalar = {{ scalar_type }};
alias GemmVec = vec{{ kernel_size }}<{{ scalar_type }}>;
alias GemmMat = mat{{ kernel_size }}x{{ kernel_size }}<{{ scalar_type }}>;

struct GemmArrayVector {
data: array<GemmVec>
Expand Down
12 changes: 6 additions & 6 deletions wonnx/templates/structs.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// Operations usually work with a single scalar data type (typically f32). This data type is set by the compiler as the
// 'scalar_type' variable. Here we define several other useful data types that shader code can use to make it more portable.
#}
type Scalar = {{ scalar_type }};
type Vec3 = vec3<{{ scalar_type }}>;
type Vec4 = vec4<{{ scalar_type }}>;
alias Scalar = {{ scalar_type }};
alias Vec3 = vec3<{{ scalar_type }}>;
alias Vec4 = vec4<{{ scalar_type }}>;

struct Array {
data: array<Scalar>
Expand All @@ -18,9 +18,9 @@ struct ArrayVector {
// WGSL only supports matrixes for floating point types at this point
#}
{% if scalar_type_is_float %}
type Mat3x3 = mat3x3<{{ scalar_type }}>;
type Mat4x4 = mat4x4<{{ scalar_type }}>;
type Mat4x3 = mat4x3<{{ scalar_type }}>;
alias Mat3x3 = mat3x3<{{ scalar_type }}>;
alias Mat4x4 = mat4x4<{{ scalar_type }}>;
alias Mat4x3 = mat4x3<{{ scalar_type }}>;

struct ArrayMatrix {
data: array<Mat4x4>
Expand Down

0 comments on commit a01c322

Please sign in to comment.