build error `*mut cuda_driver_sys::CUctx_st` cannot be sent between threads safely
hunjixin opened this issue · comments
It is very strange that when I use sea-orm's mysql feature and rust-gpu-tool to compile together, an error will pop up, but when i remove mysql feature, build can be success.
this is a mininal repro example.
create empty project and modify cargo toml like below
[package]
name = "testp"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rust-gpu-tools = { version = "0.6", default-features = false }
[dependencies.sea-orm]
version ="0.6.0"
features = [
"runtime-tokio-native-tls",
"sqlx-mysql",
]
default-features = false
[features]
default = ["rust-gpu-tools/cuda"]
cargo build, got error like below
root@200-6:~/lijunlong/testp# cargo build
Compiling temp-env v0.2.0
Compiling chrono v0.4.19
Compiling uuid v0.8.2
Compiling futures-executor v0.3.21
Compiling sqlx-core v0.5.13
Compiling rust-gpu-tools v0.6.0
Compiling futures v0.3.21
error[E0277]: `*mut cuda_driver_sys::CUctx_st` cannot be sent between threads safely
--> /root/.cargo/registry/src/mirrors.sjtug.sjtu.edu.cn-7a04d2510079875b/rust-gpu-tools-0.6.0/src/device.rs:29:1
|
29 | / lazy_static! {
30 | | // The owned CUDA contexts are stored globally. Each devives contains an unowned reference,
31 | | // so that devices can be cloned.
32 | | static ref DEVICES: (Vec<Device>, cuda::utils::CudaContexts) = build_device_list();
33 | | }
| |_^ `*mut cuda_driver_sys::CUctx_st` cannot be sent between threads safely
|
= help: within `fil_rustacuda::context::Context`, the trait `Send` is not implemented for `*mut cuda_driver_sys::CUctx_st`
= note: required because it appears within the type `fil_rustacuda::context::Context`
= note: required because of the requirements on the impl of `Send` for `Unique<fil_rustacuda::context::Context>`
= note: required because it appears within the type `alloc::raw_vec::RawVec<fil_rustacuda::context::Context>`
= note: required because it appears within the type `Vec<fil_rustacuda::context::Context>`
note: required because it appears within the type `CudaContexts`
--> /root/.cargo/registry/src/mirrors.sjtug.sjtu.edu.cn-7a04d2510079875b/rust-gpu-tools-0.6.0/src/cuda/utils.rs:14:19
|
14 | pub(crate) struct CudaContexts(Vec<rustacuda::context::Context>);
| ^^^^^^^^^^^^
= note: required because it appears within the type `(Vec<device::Device>, CudaContexts)`
= note: required because of the requirements on the impl of `Sync` for `spin::once::Once<(Vec<device::Device>, CudaContexts)>`
= note: required because it appears within the type `lazy_static::lazy::Lazy<(Vec<device::Device>, CudaContexts)>`
= note: shared static variables must have a type that implements `Sync`
= note: this error originates in the macro `__lazy_static_create` (in Nightly builds, run with -Z macro-backtrace for more info)
For more information about this error, try `rustc --explain E0277`.
error: could not compile `rust-gpu-tools` due to previous error
warning: build failed, waiting for other jobs to finish...
error: build failed
but if remove sqlx-mysql featurem build can be pass,
how can i deal with this problem
I met the same questions recently, how to fix it~
Some deeply nested dependency enables the spin_no_std
feature of lazy_static!
. That causes the problem. To see who enables it you can run cargo tree -e features
.
@hunjixin @Akariya777 I've just released version 0.7.1 that should fix the issue.