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

Build errors integrating wonnx main into rust project #203

Closed
astnmsn opened this issue Mar 15, 2024 · 3 comments
Closed

Build errors integrating wonnx main into rust project #203

astnmsn opened this issue Mar 15, 2024 · 3 comments

Comments

@astnmsn
Copy link

astnmsn commented Mar 15, 2024

Describe the bug
Hello. I am running into an error building project that depends on latest main.

wonnx = { git = "https://github.com/webonnx/wonnx.git", branch = "master"}

For context, I am attempting to integrate wonnx into an existing wasm package that utilizes wgpu for graphics.
It's very possible that this is a simple discrepancy in configuration/dependencies. I have included relevant details from my cargo.toml below. Please let me know if I can provide any more detail/context that would be helpful. Thank you!

error: future cannot be sent between threads safely
   --> /wonnx-bca7827a70163d40/7880ed8/wonnx/src/optimizer.rs:313:5
    |
313 |     #[async_recursion]
    |     ^^^^^^^^^^^^^^^^^^ future created by async block is not `Send`
    |
    = help: the trait `Sync` is not implemented for `(dyn wgpu::context::DynContext + 'static)`, which is required by `{async block@/wonnx-bca7827a70163d40/7880ed8/wonnx/src/optimizer.rs:313:5: 313:23}: std::marker::Send`
note: future is not `Send` as this value is used across an await
   --> /wonnx-bca7827a70163d40/7880ed8/wonnx/src/optimizer.rs:268:57
    |
266 | ...       let gm = GpuModel::from(out_node, device, queue, self.onnx_opset_ver...
    |               -- has type `GpuModel` which is not `Send`
267 | ...           .map_err(OptimizerError::ConstantFoldingError)?;
268 | ...       let mut outputs = gm.infer(&HashMap::new()).await?;
    |                                                       ^^^^^ await occurs here, with `gm` maybe used later
    = note: required for the cast from `Pin<Box<...>>` to `Pin<Box<dyn Future<Output = Result<..., ...>> + Send>>`

...

error[E0277]: `(dyn futures::Future<Output = std::result::Result<wgpu::context::DeviceRequest, wgpu::RequestDeviceError>> + 'static)` cannot be sent between threads safely
    --> /wonnx-bca7827a70163d40/7880ed8/wonnx/src/optimizer.rs:313:5
     |
313  |     #[async_recursion]
     |     ^^^^^^^^^^^^^^^^^^ `(dyn futures::Future<Output = std::result::Result<wgpu::context::DeviceRequest, wgpu::RequestDeviceError>> + 'static)` cannot be sent between threads safely
     |
     = help: the trait `std::marker::Send` is not implemented for `dyn Future<Output = Result<DeviceRequest, ...>>`, which is required by std::marker::Send`
     = note: required for `Unique<dyn Future<Output = Result<DeviceRequest, ...>>>` to implement `std::marker::Send`

...

error[E0277]: `dyn wgpu::WindowHandle` cannot be shared between threads safely
   --> /wonnx-bca7827a70163d40/7880ed8/wonnx/src/optimizer.rs:313:5
    |
313 |     #[async_recursion]
    |     ^^^^^^^^^^^^^^^^^^ `dyn wgpu::WindowHandle` cannot be shared between threads safely
    |
    = help: the trait `Sync` is not implemented for `dyn wgpu::WindowHandle`, which is required by `{async block@/wonnx-bca7827a70163d40/7880ed8/wonnx/src/optimizer.rs:313:5: 313:23}: std::marker::Send`
    = note: required for `Unique<dyn wgpu::WindowHandle>` to implement `Sync`
note: required because it appears within the type `Box<dyn wgpu::WindowHandle>`

...

error[E0277]: `(dyn futures::Future<Output = std::option::Option<(wgpu::context::ObjectId, Box<(dyn std::any::Any + 'static)>)>> + 'static)` cannot be sent between threads safely
    --> /wonnx-bca7827a70163d40/7880ed8/wonnx/src/optimizer.rs:313:5

Desktop (please complete the following information):

  • OS: MacOS
  • rustc: 1.76.0

Additional context
Other relevant info from my cargo.toml

[package]
...
edition = "2021"
resolver = "2"
version = "0.1.0"

[lib]
crate-type = ["cdylib", "rlib"]

[features]
default = []

[dependencies]
...
egui-wgpu = { version = "0.26" }
js-sys = "0.3"
wasm-bindgen = "0.2.92"
wasm-bindgen-futures = "0.4.42"
wasm_thread = {version = "0.2", features = ["es_modules"]}
web-time = { version = "1.1" }
wgpu = { version = "0.19", default-features = false, features = ["wgsl", "webgpu", "webgl", "metal"] }
wonnx = { git = "https://github.com/webonnx/wonnx.git", branch = "master"}
@pixelspark
Copy link
Collaborator

pixelspark commented Mar 17, 2024

Hm, this is weird. What happens when you clone the wonnx repository and attempt to build that on your machine?

I am seeing errors when building just wonnx as well when building for wasm (but not for macOS natively) with the following command line:

RUSTFLAGS=--cfg=web_sys_unstable_apis wasm-pack build --target web -d `pwd`/target/pkg --out-name wonnx --scope webonnx ./wonnx-wasm

This probably happened after upgrading the wgpu dependency. It appears a wgpu type (dyn wgpu::WindowHandle at least) is not Sync while we do need that due to async-recursion in the optimizer. Curiously this is not an issue when not building for WASM.

I currently do not have time to dive into this but hopefully this helps you figure out the issue (PRs welcome).

@astnmsn
Copy link
Author

astnmsn commented Mar 18, 2024

Thank you for the response!
For what it’s worth, I didn’t have any problems building wonnx when I cloned the repo and ran the basic cargo build command.

I’ll rerun tomorrow morning (GMT-7) with the command you posted to validate I see the same output. My hunch is that my particular issue is directly related.

I don’t have great familiarity with the wonnx code base, but would be happy to work with you and give a PR a go!

@astnmsn
Copy link
Author

astnmsn commented Mar 19, 2024

Fix seems to be fairly simple: #204

Please let me know if there are any edits or anything else I can do 🙂

@astnmsn astnmsn closed this as completed Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants