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:
parent
2f27ea2b69
commit
d145450403
17
src/main.rs
17
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::<cl_uchar>::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)
|
||||
|
Loading…
Reference in New Issue
Block a user