aboutsummaryrefslogtreecommitdiffhomepage
path: root/zluda
diff options
context:
space:
mode:
Diffstat (limited to 'zluda')
-rw-r--r--zluda/src/impl/function.rs18
1 files changed, 10 insertions, 8 deletions
diff --git a/zluda/src/impl/function.rs b/zluda/src/impl/function.rs
index 4f2006c..638d08a 100644
--- a/zluda/src/impl/function.rs
+++ b/zluda/src/impl/function.rs
@@ -110,23 +110,24 @@ pub fn launch_kernel(
match (buffer_size, buffer_ptr) {
(Some(buffer_size), Some(buffer_ptr)) => {
let sum_of_kernel_argument_sizes =
- func.arg_size.iter().fold(0, |offset, size_of_arg| {
- size_of_arg + round_up_to_multiple(offset, *size_of_arg)
- });
+ func.arg_size
+ .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(CUresult::CUDA_ERROR_INVALID_VALUE);
}
let mut offset = 0;
for (i, arg_size) in func.arg_size.iter().enumerate() {
- let buffer_offset = round_up_to_multiple(offset, *arg_size);
unsafe {
func.base.set_arg_raw(
i as u32,
*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(CUresult::CUDA_ERROR_INVALID_VALUE),
@@ -159,8 +160,9 @@ pub fn launch_kernel(
})?
}
-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
}
pub(crate) fn get_attribute(