Skip to content

Commit 368a87c

Browse files
jiel-nvgmarkall
andauthored
Remove customized address space tracking and address class emission in debug info (#669)
Fix issue [#627](#627) Remove the dwarfAddressSpace attribute from DIDerivedType for shared memory pointers; DCE cleanup since customized address space tracking is no longer needed. The Enum data structure of DwarfAddressClass and the corrsponding mapping function (map NVVM address space to DWARF address class) are intentionly retained for potential future usage. --------- Co-authored-by: Graham Markall <gmarkall@nvidia.com>
1 parent 5ad2291 commit 368a87c

File tree

3 files changed

+22
-114
lines changed

3 files changed

+22
-114
lines changed

numba_cuda/numba/cuda/debuginfo.py

Lines changed: 10 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -646,11 +646,6 @@ def __init__(self, module, filepath, cgctx, directives_only):
646646
super().__init__(module, filepath, cgctx, directives_only)
647647
# Cache for local variable metadata type and line deduplication
648648
self._vartypelinemap = {}
649-
# Variable address space dictionary
650-
self._var_addrspace_map = {}
651-
652-
def _set_addrspace_map(self, map):
653-
self._var_addrspace_map = map
654649

655650
def _var_type(self, lltype, size, datamodel=None):
656651
is_bool = False
@@ -826,64 +821,6 @@ def _var_type(self, lltype, size, datamodel=None):
826821
is_distinct=True,
827822
)
828823

829-
# Check if there's actually address space info to handle
830-
addrspace = getattr(self, "_addrspace", None)
831-
if (
832-
isinstance(lltype, ir.LiteralStructType)
833-
and datamodel is not None
834-
and datamodel.inner_models()
835-
and addrspace not in (None, 0)
836-
):
837-
# Process struct with datamodel that has address space info
838-
meta = []
839-
offset = 0
840-
for element, field, model in zip(
841-
lltype.elements, datamodel._fields, datamodel.inner_models()
842-
):
843-
size_field = self.cgctx.get_abi_sizeof(element)
844-
if isinstance(element, ir.PointerType) and field == "data":
845-
# Create pointer type with correct address space
846-
pointee_size = self.cgctx.get_abi_sizeof(element.pointee)
847-
pointee_model = getattr(model, "_pointee_model", None)
848-
pointee_type = self._var_type(
849-
element.pointee, pointee_size, datamodel=pointee_model
850-
)
851-
meta_ptr = {
852-
"tag": ir.DIToken("DW_TAG_pointer_type"),
853-
"baseType": pointee_type,
854-
"size": _BYTE_SIZE * size_field,
855-
}
856-
dwarf_addrclass = self.get_dwarf_address_class(addrspace)
857-
if dwarf_addrclass is not None:
858-
meta_ptr["dwarfAddressSpace"] = int(dwarf_addrclass)
859-
basetype = m.add_debug_info("DIDerivedType", meta_ptr)
860-
else:
861-
basetype = self._var_type(
862-
element, size_field, datamodel=model
863-
)
864-
derived_type = m.add_debug_info(
865-
"DIDerivedType",
866-
{
867-
"tag": ir.DIToken("DW_TAG_member"),
868-
"name": field,
869-
"baseType": basetype,
870-
"size": _BYTE_SIZE * size_field,
871-
"offset": offset,
872-
},
873-
)
874-
meta.append(derived_type)
875-
offset += _BYTE_SIZE * size_field
876-
877-
return m.add_debug_info(
878-
"DICompositeType",
879-
{
880-
"tag": ir.DIToken("DW_TAG_structure_type"),
881-
"name": f"{datamodel.fe_type}",
882-
"elements": m.add_metadata(meta),
883-
"size": offset,
884-
},
885-
is_distinct=True,
886-
)
887824
# For other cases, use upstream Numba implementation
888825
return super()._var_type(lltype, size, datamodel=datamodel)
889826

@@ -936,22 +873,16 @@ def mark_variable(
936873
# to llvm.dbg.value
937874
return
938875
else:
939-
# Look up address space for this variable
940-
self._addrspace = self._var_addrspace_map.get(name)
941-
try:
942-
return super().mark_variable(
943-
builder,
944-
allocavalue,
945-
name,
946-
lltype,
947-
size,
948-
line,
949-
datamodel,
950-
argidx,
951-
)
952-
finally:
953-
# Clean up address space info
954-
self._addrspace = None
876+
return super().mark_variable(
877+
builder,
878+
allocavalue,
879+
name,
880+
lltype,
881+
size,
882+
line,
883+
datamodel,
884+
argidx,
885+
)
955886

956887
def update_variable(
957888
self,

numba_cuda/numba/cuda/lowering.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from numba.cuda import HAS_NUMBA
1212
from numba.cuda.core import ir
1313
from numba.cuda import debuginfo, cgutils, utils, typing, types
14-
from numba import cuda
1514
from numba.cuda.core import (
1615
ir_utils,
1716
targetconfig,
@@ -1684,31 +1683,10 @@ def decref(self, typ, val):
16841683

16851684

16861685
class CUDALower(Lower):
1687-
def _is_shared_array_call(self, fnty):
1688-
# Check if function type is a cuda.shared.array call
1689-
if not hasattr(fnty, "typing_key"):
1690-
return False
1691-
return fnty.typing_key is cuda.shared.array
1692-
1693-
def _lower_call_normal(self, fnty, expr, signature):
1694-
# Set flag for subsequent store to track shared address space
1695-
if self.context.enable_debuginfo and self._is_shared_array_call(fnty):
1696-
self._pending_shared_store = True
1697-
1698-
return super()._lower_call_normal(fnty, expr, signature)
1699-
17001686
def storevar(self, value, name, argidx=None):
17011687
"""
17021688
Store the value into the given variable.
17031689
"""
1704-
# Track address space for debug info
1705-
if self.context.enable_debuginfo and self._pending_shared_store:
1706-
from numba.cuda.cudadrv import nvvm
1707-
1708-
self._addrspace_map[name] = nvvm.ADDRSPACE_SHARED
1709-
if not name.startswith("$") and not name.startswith("."):
1710-
self._pending_shared_store = False
1711-
17121690
# Handle polymorphic variables with CUDA_DEBUG_POLY enabled
17131691
if config.CUDA_DEBUG_POLY:
17141692
src_name = name.split(".")[0]
@@ -1834,12 +1812,6 @@ def pre_lower(self):
18341812
"""
18351813
super().pre_lower()
18361814

1837-
# Track address space for debug info
1838-
self._addrspace_map = {}
1839-
self._pending_shared_store = False
1840-
if self.context.enable_debuginfo:
1841-
self.debuginfo._set_addrspace_map(self._addrspace_map)
1842-
18431815
# Track polymorphic variables for debug info
18441816
self.poly_var_typ_map = {}
18451817
self.poly_var_loc_map = {}

numba_cuda/numba/cuda/tests/cudapy/test_debuginfo.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -885,29 +885,34 @@ def foo():
885885
""",
886886
)
887887

888-
# shared_arr -> composite -> elements[4] (data field at index 4) -> pointer with dwarfAddressSpace: 8
889-
# local_arr -> composite -> elements[4] (data field at index 4) -> pointer without dwarfAddressSpace: 8
888+
# shared_arr -> composite -> elements[4] (data field at index 4) -> pointer without dwarfAddressSpace
889+
# local_arr -> composite -> elements[4] (data field at index 4) -> pointer without dwarfAddressSpace
890+
# Note: Shared memory pointers don't have dwarfAddressSpace because they are
891+
# cast to generic address space via addrspacecast in cudaimpl.py
890892
address_class_filechecks = r"""
891893
CHECK-DAG: [[SHARED_VAR:![0-9]+]] = !DILocalVariable({{.*}}name: "shared_arr"{{.*}}type: [[SHARED_COMPOSITE:![0-9]+]]
892894
CHECK-DAG: [[SHARED_COMPOSITE]] = {{.*}}!DICompositeType(elements: [[SHARED_ELEMENTS:![0-9]+]]
893895
CHECK-DAG: [[SHARED_ELEMENTS]] = !{{{.*}}, {{.*}}, {{.*}}, {{.*}}, [[SHARED_DATA:![0-9]+]], {{.*}}, {{.*}}}
894896
CHECK-DAG: [[SHARED_DATA]] = !DIDerivedType(baseType: [[SHARED_PTR:![0-9]+]], name: "data"
895-
CHECK-DAG: [[SHARED_PTR]] = !DIDerivedType({{.*}}dwarfAddressSpace: 8{{.*}}tag: DW_TAG_pointer_type
897+
CHECK-DAG: [[SHARED_PTR]] = !DIDerivedType({{.*}}tag: DW_TAG_pointer_type
898+
CHECK-NOT: [[SHARED_PTR]]{{.*}}dwarfAddressSpace
896899
897900
CHECK-DAG: [[LOCAL_VAR:![0-9]+]] = !DILocalVariable({{.*}}name: "local_arr"{{.*}}type: [[LOCAL_COMPOSITE:![0-9]+]]
898901
CHECK-DAG: [[LOCAL_COMPOSITE]] = {{.*}}!DICompositeType(elements: [[LOCAL_ELEMENTS:![0-9]+]]
899902
CHECK-DAG: [[LOCAL_ELEMENTS]] = !{{{.*}}, {{.*}}, {{.*}}, {{.*}}, [[LOCAL_DATA:![0-9]+]], {{.*}}, {{.*}}}
900903
CHECK-DAG: [[LOCAL_DATA]] = !DIDerivedType(baseType: [[LOCAL_PTR:![0-9]+]], name: "data"
901904
CHECK-DAG: [[LOCAL_PTR]] = !DIDerivedType(baseType: {{.*}}tag: DW_TAG_pointer_type
902-
CHECK-NOT: [[LOCAL_PTR]]{{.*}}dwarfAddressSpace: 8
905+
CHECK-NOT: [[LOCAL_PTR]]{{.*}}dwarfAddressSpace
903906
"""
904907

905908
def _test_shared_memory_address_class(self, dtype):
906909
"""Test that shared memory arrays have correct DWARF address class.
907910
908-
Shared memory pointers should have addressClass: 8 (DW_AT_address_class
909-
for CUDA shared memory) in their debug metadata, while regular local
910-
arrays should not have this annotation.
911+
Shared memory pointers should NOT have dwarfAddressSpace attribute
912+
because they are cast to generic address space via addrspacecast.
913+
The runtime pointer type is generic, not shared, so cuda-gdb can
914+
correctly dereference them. Local arrays also should not have this
915+
attribute.
911916
"""
912917
sig = (numpy_support.from_dtype(dtype),)
913918

0 commit comments

Comments
 (0)