From d145450403ede10368af84aba92748b8ddf3da18 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Wed, 16 Oct 2024 22:12:28 +0800 Subject: [PATCH] Refactor OpenCL kernel creation and buffer preparation This commit refactors the code related to creating the OpenCL kernel and preparing the device buffers. Instead of using a single line of code to create the kernel, it now uses a match statement to handle both success and failure cases. Additionally, print statements are added to indicate the success or failure of the kernel creation. The code for preparing the device buffers is also modified to include print statements for better visibility during execution. --- src/main.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 7f885de..b825bab 100644 --- a/src/main.rs +++ b/src/main.rs @@ -82,7 +82,16 @@ fn main() -> anyhow::Result<()> { panic!(); } }; - let kernel = Kernel::create(&program, KERNEL_NAME).expect("Kernel::create failed"); + let kernel = match Kernel::create(&program, KERNEL_NAME) { + Ok(k) => { + println!("内核创建成功"); + k + } + Err(err) => { + println!("OpenCL Kernel::create failed: {}", err); + panic!(); + } + }; let team_raw_vec = vec!["x"; worker_count as usize]; let name_raw_vec = vec!["x"; worker_count as usize]; @@ -105,6 +114,8 @@ fn main() -> anyhow::Result<()> { let work_count = team_bytes_vec.len(); + println!("开始准备buffer"); + // Create OpenCL device buffers let mut team = unsafe { Buffer::::create( @@ -150,6 +161,8 @@ fn main() -> anyhow::Result<()> { vec }; + println!("开始写入buffer"); + // 阻塞写 let _team_write_event = unsafe { queue.enqueue_write_buffer(&mut team, CL_BLOCKING, 0, &team_data_vec, &[]) }?; @@ -160,6 +173,8 @@ fn main() -> anyhow::Result<()> { let _n_len_write_event = unsafe { queue.enqueue_write_buffer(&mut n_len, CL_BLOCKING, 0, &n_len_vec, &[]) }?; + println!("开始执行kernel"); + // println!("output: {:?} {}", output, output.len()); let kernel_event = unsafe { ExecuteKernel::new(&kernel)