修复了必须使用amd显卡的问题(逃

This commit is contained in:
shenjack 2024-10-16 21:35:18 +08:00
parent 11f0df1254
commit ea7a1c212e
Signed by: shenjack
GPG Key ID: 7B1134A979775551

View File

@ -1,6 +1,6 @@
use opencl3::command_queue::{CommandQueue, CL_QUEUE_PROFILING_ENABLE};
use opencl3::context::Context;
use opencl3::device::{get_all_devices, get_device_info, Device, CL_DEVICE_MAX_WORK_GROUP_SIZE_AMD, CL_DEVICE_TYPE_GPU};
use opencl3::device::{get_all_devices, get_device_info, Device, CL_DEVICE_MAX_WORK_GROUP_SIZE, CL_DEVICE_MAX_WORK_GROUP_SIZE_AMD, CL_DEVICE_TYPE_GPU};
use opencl3::kernel::{ExecuteKernel, Kernel};
use opencl3::memory::{Buffer, CL_MAP_WRITE, CL_MEM_READ_ONLY};
use opencl3::program::Program;
@ -19,14 +19,24 @@ fn main() -> anyhow::Result<()> {
let device_id = *get_all_devices(CL_DEVICE_TYPE_GPU)?
.first()
.expect("no device found in platform");
let size = match get_device_info(device_id, CL_DEVICE_MAX_WORK_GROUP_SIZE_AMD) {
let size = {
match get_device_info(device_id, CL_DEVICE_MAX_WORK_GROUP_SIZE_AMD) {
Ok(size) => {
size.to_size()
},
Err(err) => {
println!("get_device_info failed: {}", err);
println!("警告: get_device_info failed: {}\n也许是你没有一张AMD显卡,让我们试试非AMD", err);
match get_device_info(device_id, CL_DEVICE_MAX_WORK_GROUP_SIZE) {
Ok(size) => {
size.to_size()
},
Err(err) => {
println!("错误: get_device_info failed: {}\n", err);
panic!();
}
}
}
}
};
let device = Device::new(device_id);