Skip to content

Commit 085aabc

Browse files
abrownalexcrichton
andcommitted
fix: allow wasi-nn to compile with threads changes
Co-authored-by: Alex Crichton <[email protected]>
1 parent 8f8ce2e commit 085aabc

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

crates/wasi-nn/src/api.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use thiserror::Error;
77
use wiggle::GuestError;
88

99
/// A [Backend] contains the necessary state to load [BackendGraph]s.
10-
pub(crate) trait Backend: Send {
10+
pub(crate) trait Backend: Send + Sync {
1111
fn name(&self) -> &str;
1212
fn load(
1313
&mut self,
@@ -18,7 +18,7 @@ pub(crate) trait Backend: Send {
1818

1919
/// A [BackendGraph] can create [BackendExecutionContext]s; this is the backing
2020
/// implementation for a [crate::witx::types::Graph].
21-
pub(crate) trait BackendGraph: Send {
21+
pub(crate) trait BackendGraph: Send + Sync {
2222
fn init_execution_context(&mut self) -> Result<Box<dyn BackendExecutionContext>, BackendError>;
2323
}
2424

crates/wasi-nn/src/openvino.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//! Implements the wasi-nn API.
2+
23
use crate::api::{Backend, BackendError, BackendExecutionContext, BackendGraph};
34
use crate::witx::types::{ExecutionTarget, GraphBuilderArray, Tensor, TensorType};
45
use openvino::{InferenceError, Layout, Precision, SetupError, TensorDesc};
@@ -7,6 +8,9 @@ use std::sync::Arc;
78
#[derive(Default)]
89
pub(crate) struct OpenvinoBackend(Option<openvino::Core>);
910

11+
unsafe impl Send for OpenvinoBackend {}
12+
unsafe impl Sync for OpenvinoBackend {}
13+
1014
impl Backend for OpenvinoBackend {
1115
fn name(&self) -> &str {
1216
"openvino"
@@ -65,6 +69,9 @@ impl Backend for OpenvinoBackend {
6569

6670
struct OpenvinoGraph(Arc<openvino::CNNNetwork>, openvino::ExecutableNetwork);
6771

72+
unsafe impl Send for OpenvinoGraph {}
73+
unsafe impl Sync for OpenvinoGraph {}
74+
6875
impl BackendGraph for OpenvinoGraph {
6976
fn init_execution_context(&mut self) -> Result<Box<dyn BackendExecutionContext>, BackendError> {
7077
let infer_request = self.1.create_infer_request()?;

0 commit comments

Comments
 (0)