Dynamically adjust size of cuda.local.array without environment variables

Are you looking for something that varies the size of a local array in a kernel? e.g.:

from numba import cuda, types


def gen_kernel(local_size):
    @cuda.jit
    def f():
        x = cuda.local.array(local_size, types.int32)
        print("Length of local array is", len(x))

    return f


# Generate kernels with different sized local arrays and launch them with a
# single thread
gen_kernel(2)[1, 1]()
gen_kernel(3)[1, 1]()

# Synchronize to make sure we don't exit before the output can be printed
cuda.synchronize()

which outputs:

Length of local array is 2
Length of local array is 3