tracel-ai / burn

Burn is a new comprehensive dynamic Deep Learning Framework built using Rust with extreme flexibility, compute efficiency and portability as its primary goals.
https://burn.dev
Apache License 2.0
8.2k stars 401 forks source link

No adapter found for graphics API AutoGraphicsApi #1691

Open wangjiawen2013 opened 4 months ago

wangjiawen2013 commented 4 months ago

Hi, I am trying to run burn according to the burn book example (https://burn.dev/book/getting-started.html), but it displayed "No adapter found for graphics API AutoGraphicsApi".

this is the Cargo.toml:

[package]
name = "my_burn_app"
version = "0.1.0"
edition = "2021"

[dependencies]
burn = { version = "0.13.0", features = ["wgpu"] }

And this is the main function:

use burn::tensor::Tensor;
use burn::backend::Wgpu;

// Type alias for the backend to use.
type Backend = Wgpu;

fn main() {
    let device = Default::default();
    // Creation of two tensors, the first with explicit values and the second one with ones, with the same shape as the first
    let tensor_1 = Tensor::<Backend, 2>::from_data([[2., 3.], [4., 5.]], &device);
    let tensor_2 = Tensor::<Backend, 2>::ones_like(&tensor_1);

    // Print the element-wise addition (done with the WGPU backend) of the two tensors.
    println!("{}", tensor_1 + tensor_2);
}

When I run it using cargo run, the following error occurred:

[wangjw@localhost my_burn_app]$ cargo run
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.23s
     Running `target/debug/my_burn_app`
thread 'main' panicked at /home/wangjw/.cargo/registry/src/index.crates.io-6f17d22bba15001f/burn-wgpu-0.13.0/src/runtime.rs:278:17:
No adapter found for graphics API AutoGraphicsApi
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
laggui commented 4 months ago

For wgpu you might need to install the correct graphics drivers depending on what you want to target. By default, the AutoGraphicsApi targets metal on MacOs and vulkan on other operating systems. For vulkan you can do apt install vulkan (and possibly vulkan-tools if you want to validate the installation).

If you want to use another graphics API you can be explicit when using the wgpu backend. For example, the guide defines the backend as

type MyBackend = Wgpu<AutoGraphicsApi, f32, i32>;

But if you explicitly want to target OpenGl, you can use this instead

type MyBackend = Wgpu<OpenGl, f32, i32>;

with use burn::backend::wgpu::OpenGl;.