luqmana / rust-opencl

OpenCL bindings for Rust.
Other
170 stars 42 forks source link

Implementing multiple GPU support? #48

Open edude03 opened 9 years ago

edude03 commented 9 years ago

I'm trying to write some quick example code using rust + opencl, I'm pretty new to rust but when I run

let (device, ctx, queue) = opencl::util::create_compute_context_prefer(opencl::util::PreferedType::GPUPrefered).unwrap();
let (device1, ctx1, queue1) = opencl::util::create_compute_context_prefer(opencl::util::PreferedType::GPUPrefered).unwrap();

println!("{}", device.name()); //GT120
println!("{}", device1.name()); //GT120

Both of my device names are "Geforce GT120". In my PC however I have a GT120 in addition to a Radeon 7970.

Looking at the code I see that multiple devices are a TODO, what needs to be done to implement this?

ghost commented 9 years ago

opencl::util::create_compute_context_prefer just selects the first GPU and platform that match its requirement. You will probably want to manually select the GPU you want. Since you have both a GT120 and a Radeon 7970 you can't actually use both with the same OpenCL context. But you should be able to select the OpenCL device you want. You will just have to do it manually.

If you look at https://github.com/luqmana/rust-opencl/blob/master/tests/test.rs#L22 shows you how to create a context for every possible compute device connected to your system. We use this for testing, but you should be able to modify it to select the Radeon 7970.