Skip to content

Commit bd7f107

Browse files
committed
l_copy_and_adjust_arguments_for_device: constify variables
This improves readability and potentially avoids future mistakes. Signed-off-by: Peter Colberg <[email protected]>
1 parent dabca21 commit bd7f107

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/acl_kernel.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2755,8 +2755,8 @@ l_copy_and_adjust_arguments_for_device(cl_kernel kernel, cl_device_id device,
27552755
// with a base address of 0
27562756

27572757
// Need to determine sizeof device's pointers.
2758-
cl_uint dev_local_ptr_size = 4; // Always.
2759-
cl_uint dev_global_ptr_size = device->address_bits >> 3;
2758+
const cl_uint dev_local_ptr_size = 4; // Always.
2759+
const cl_uint dev_global_ptr_size = device->address_bits >> 3;
27602760

27612761
// Bump allocator pointer for each local aspace
27622762
// Maps the aspace ID to the next available local memory address.
@@ -2790,7 +2790,8 @@ l_copy_and_adjust_arguments_for_device(cl_kernel kernel, cl_device_id device,
27902790
printf("local");
27912791
#endif
27922792

2793-
unsigned this_aspace = kernel->accel_def->iface.args[iarg].aspace_number;
2793+
const unsigned int this_aspace =
2794+
kernel->accel_def->iface.args[iarg].aspace_number;
27942795

27952796
// This arg is a pointer to __local.
27962797
cl_ulong local_size = 0;
@@ -2812,7 +2813,8 @@ l_copy_and_adjust_arguments_for_device(cl_kernel kernel, cl_device_id device,
28122813

28132814
// On the emulator, the argument size of a pipe (which is a mem object) is
28142815
// 0. Since we copy in 0 bytes, we should read out 0 bytes.
2815-
size_t copy_sz = (arg_info->size == 0) ? arg_info->size : sizeof(cl_mem);
2816+
const size_t copy_sz =
2817+
(arg_info->size == 0) ? arg_info->size : sizeof(cl_mem);
28162818
safe_memcpy(&mem_obj, &(kernel->arg_value[host_idx]), copy_sz,
28172819
sizeof(cl_mem), copy_sz);
28182820

@@ -2832,7 +2834,7 @@ l_copy_and_adjust_arguments_for_device(cl_kernel kernel, cl_device_id device,
28322834
value for the argument declared as a pointer to global or constant
28332835
memory in the kernel."
28342836
*/
2835-
cl_ulong null_ptr = 0;
2837+
const cl_ulong null_ptr = 0;
28362838
safe_memcpy(buf + device_idx, &null_ptr, dev_global_ptr_size,
28372839
dev_global_ptr_size, dev_global_ptr_size);
28382840
// Shared physical memory:
@@ -2902,7 +2904,7 @@ l_copy_and_adjust_arguments_for_device(cl_kernel kernel, cl_device_id device,
29022904

29032905
// copy the address of the reserved allocation into the invocation
29042906
// image:
2905-
void *mem_addr =
2907+
const void *mem_addr =
29062908
mem_obj->reserved_allocations[needed_physical_id][needed_mem_id]
29072909
->range.begin;
29082910
safe_memcpy(buf + device_idx, &mem_addr, dev_global_ptr_size,
@@ -2911,7 +2913,7 @@ l_copy_and_adjust_arguments_for_device(cl_kernel kernel, cl_device_id device,
29112913
if (memory_migration->num_mem_objects == 0) {
29122914
// First time allocation, 128 was chosen because previously, number of
29132915
// kernel arguments were set to an hardcoded limit of 128
2914-
const unsigned initial_alloc = 128;
2916+
const unsigned int initial_alloc = 128;
29152917

29162918
memory_migration->src_mem_list =
29172919
(acl_mem_migrate_wrapper_t *)acl_malloc(
@@ -2923,7 +2925,7 @@ l_copy_and_adjust_arguments_for_device(cl_kernel kernel, cl_device_id device,
29232925
memory_migration->num_alloc = initial_alloc;
29242926
} else if (memory_migration->num_mem_objects >=
29252927
memory_migration->num_alloc) {
2926-
const unsigned next_alloc = memory_migration->num_alloc * 2;
2928+
const unsigned int next_alloc = memory_migration->num_alloc * 2;
29272929
// check for overflow, num_alloc is a 32-bit unsigned integer and
29282930
// unsigned integer overflow is defined behaviour
29292931
if (next_alloc < memory_migration->num_alloc)

0 commit comments

Comments
 (0)