From f703750d2cd611f54457583f3459f198dff55a5a Mon Sep 17 00:00:00 2001 From: Vijay Kandiah Date: Wed, 6 Aug 2025 10:26:42 -0700 Subject: [PATCH 1/2] Add locals attribute to _FunctionCompiler --- numba_cuda/numba/cuda/dispatcher.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/numba_cuda/numba/cuda/dispatcher.py b/numba_cuda/numba/cuda/dispatcher.py index 9f69955b7..78d777227 100644 --- a/numba_cuda/numba/cuda/dispatcher.py +++ b/numba_cuda/numba/cuda/dispatcher.py @@ -773,6 +773,7 @@ def __init__(self, py_func, targetdescr, targetoptions, pipeline_class): self.py_func = py_func self.targetdescr = targetdescr self.targetoptions = targetoptions + self.locals = {} self.pysig = utils.pysignature(self.py_func) self.pipeline_class = pipeline_class # Remember key=(args, return_type) combinations that will fail @@ -843,7 +844,7 @@ def _compile_core(self, args, return_type): args=args, return_type=return_type, flags=flags, - locals={}, + locals=self.locals, pipeline_class=self.pipeline_class, ) # Check typing error if object mode is used From 64faef997e4627ab97e847b322c41af41fae5895 Mon Sep 17 00:00:00 2001 From: Graham Markall Date: Thu, 7 Aug 2025 22:36:45 +0100 Subject: [PATCH 2/2] Add test for fix in #381 --- .../numba/cuda/tests/cudapy/test_compiler.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/numba_cuda/numba/cuda/tests/cudapy/test_compiler.py b/numba_cuda/numba/cuda/tests/cudapy/test_compiler.py index 62cc40df5..c219251a1 100644 --- a/numba_cuda/numba/cuda/tests/cudapy/test_compiler.py +++ b/numba_cuda/numba/cuda/tests/cudapy/test_compiler.py @@ -252,6 +252,21 @@ def test_compile_to_invalid_error(self): output=illegal_output, ) + def test_functioncompiler_locals(self): + # Tests against regression fixed in: + # https://github.com/NVIDIA/numba-cuda/pull/381 + # + # "AttributeError: '_FunctionCompiler' object has no attribute + # 'locals'" + cond = None + + @cuda.jit("void(float32[::1])") + def f(b_arg): + b_smem = cuda.shared.array(shape=(1,), dtype=float32) + + if cond: + b_smem[0] = b_arg[0] + @skip_on_cudasim("Compilation unsupported in the simulator") class TestCompileForCurrentDevice(CUDATestCase):