From ea7a1c212e2fb292126af96f19d855911373b706 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Wed, 16 Oct 2024 21:35:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E5=BF=85=E9=A1=BB?= =?UTF-8?q?=E4=BD=BF=E7=94=A8amd=E6=98=BE=E5=8D=A1=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=88=E9=80=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.rs | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3da9b11..9ba6c19 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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,13 +19,23 @@ 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) { - Ok(size) => { - size.to_size() - }, - Err(err) => { - println!("get_device_info failed: {}", err); - panic!(); + 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: {}\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);