Skip to content

Commit

Permalink
Avoid host allocations for by-offload arguments to GPU kernels
Browse files Browse the repository at this point in the history
Signed-off-by: Engin Kayraklioglu <e-kayrakli@users.noreply.github.com>
  • Loading branch information
e-kayrakli committed Aug 29, 2024
1 parent 11683ed commit 8e4afeb
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions runtime/src/chpl-gpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,14 +411,19 @@ static void cfg_add_offload_param(kernel_cfg* cfg, void* arg, size_t size) {

cfg->param_dyn_allocated[i] = true;

// the kernel_params array must store the addresses of things that will be
// copied to the device memory before the kernel launch. For by-offload
// params, we need it to store the address of the pointer generated by
// chpl_gpu_mem_array_alloc. We need to allocate dynamic memory for that
// address-to-pointer as well, because otherwise the address (which is just
// another void*) will go out of scope at the end of this function.
cfg->kernel_params[i] = chpl_mem_alloc(sizeof(void*),
CHPL_RT_MD_GPU_KERNEL_PARAM, cfg->ln,
cfg->fn);

// TODO this doesn't work on EX, why?
// *kernel_params[i] = chpl_gpu_impl_mem_array_alloc(cur_arg_size, stream);
*(cfg->kernel_params[i]) = chpl_gpu_mem_alloc(size, CHPL_RT_MD_GPU_KERNEL_ARG,
cfg->ln, cfg->fn);
*(cfg->kernel_params[i]) = chpl_gpu_mem_array_alloc(size,
CHPL_RT_MD_GPU_KERNEL_ARG,
cfg->ln, cfg->fn);

chpl_gpu_impl_copy_host_to_device(*(cfg->kernel_params[i]), arg, size,
cfg->stream);
Expand Down

0 comments on commit 8e4afeb

Please sign in to comment.