diff options
author | Andrzej Janik <[email protected]> | 2021-06-27 13:08:46 +0200 |
---|---|---|
committer | Andrzej Janik <[email protected]> | 2021-06-27 13:08:46 +0200 |
commit | d7d38256e0580c3cfb649a641d9ed62c6ff0fc20 (patch) | |
tree | 886fc195af96df37075b4f7b5664bf755ef872ae /zluda_dump | |
parent | b2765370e5ba86f21f6c4758817b3464c52150e5 (diff) | |
download | ZLUDA-d7d38256e0580c3cfb649a641d9ed62c6ff0fc20.tar.gz ZLUDA-d7d38256e0580c3cfb649a641d9ed62c6ff0fc20.zip |
Fix offset calculation in kernel launch
Diffstat (limited to 'zluda_dump')
-rw-r--r-- | zluda_dump/src/lib.rs | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/zluda_dump/src/lib.rs b/zluda_dump/src/lib.rs index b5a1e3a..450a00a 100644 --- a/zluda_dump/src/lib.rs +++ b/zluda_dump/src/lib.rs @@ -573,24 +573,24 @@ fn dump_arguments( } match (buffer_size, buffer_ptr) { (Some(buffer_size), Some(buffer_ptr)) => { - let sum_of_kernel_argument_sizes = args.iter().fold(0, |offset, size_of_arg| { - size_of_arg + round_up_to_multiple(offset, *size_of_arg) - }); + let sum_of_kernel_argument_sizes = + args.iter().fold(0, |sum_of_arg_sizes, size_of_arg| { + sum_of_arg_sizes + align_to_usize(*size_of_arg) + }); if buffer_size != sum_of_kernel_argument_sizes { return Err("Malformed `extra` parameter to kernel launch")?; } let mut offset = 0; for (i, arg_size) in args.iter().enumerate() { - let buffer_offset = round_up_to_multiple(offset, *arg_size); unsafe { dump_argument_to_file( &dump_dir, i, *arg_size, - buffer_ptr.add(buffer_offset) as *const _, + buffer_ptr.add(offset) as *const _, )? }; - offset = buffer_offset + *arg_size; + offset += align_to_usize(*arg_size); } } _ => return Err("Malformed `extra` parameter to kernel launch")?, @@ -599,8 +599,9 @@ fn dump_arguments( Ok(()) } -fn round_up_to_multiple(x: usize, multiple: usize) -> usize { - ((x + multiple - 1) / multiple) * multiple +fn align_to_usize(value: usize) -> usize { + let multiple = std::mem::size_of::<usize>(); + ((value + multiple - 1) / multiple) * multiple } unsafe fn dump_argument_to_file( |