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.
This commit is contained in:
shenjack 2024-10-16 22:12:28 +08:00
parent 2f27ea2b69
commit d145450403
Signed by: shenjack
GPG Key ID: 7B1134A979775551

View File

@ -82,7 +82,16 @@ fn main() -> anyhow::Result<()> {
panic!(); 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 team_raw_vec = vec!["x"; worker_count as usize];
let name_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(); let work_count = team_bytes_vec.len();
println!("开始准备buffer");
// Create OpenCL device buffers // Create OpenCL device buffers
let mut team = unsafe { let mut team = unsafe {
Buffer::<cl_uchar>::create( Buffer::<cl_uchar>::create(
@ -150,6 +161,8 @@ fn main() -> anyhow::Result<()> {
vec vec
}; };
println!("开始写入buffer");
// 阻塞写 // 阻塞写
let _team_write_event = let _team_write_event =
unsafe { queue.enqueue_write_buffer(&mut team, CL_BLOCKING, 0, &team_data_vec, &[]) }?; 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 = let _n_len_write_event =
unsafe { queue.enqueue_write_buffer(&mut n_len, CL_BLOCKING, 0, &n_len_vec, &[]) }?; unsafe { queue.enqueue_write_buffer(&mut n_len, CL_BLOCKING, 0, &n_len_vec, &[]) }?;
println!("开始执行kernel");
// println!("output: {:?} {}", output, output.len()); // println!("output: {:?} {}", output, output.len());
let kernel_event = unsafe { let kernel_event = unsafe {
ExecuteKernel::new(&kernel) ExecuteKernel::new(&kernel)