Skip to content

Commit e314821

Browse files
authored
Merge pull request #7027 from MegaIng/fix_nrt_debug_print
Fix nrt debug print
2 parents 0c33c33 + e6f6d9b commit e314821

2 files changed

Lines changed: 16 additions & 11 deletions

File tree

‎numba/core/config.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ def optional_str(x):
176176
# (up to and including IR generation)
177177
DEBUG_FRONTEND = _readenv("NUMBA_DEBUG_FRONTEND", int, 0)
178178

179+
# Enable debug prints in nrtdynmod
180+
DEBUG_NRT = _readenv("NUMBA_DEBUG_NRT", int, 0)
181+
179182
# How many recently deserialized functions to retain regardless
180183
# of external references
181184
FUNCTION_CACHE_SIZE = _readenv("NUMBA_FUNCTION_CACHE_SIZE", int, 128)

‎numba/core/runtime/nrtdynmod.py‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
"""
44

55

6-
from numba.core.config import MACHINE_BITS
6+
from numba.core import config
77
from numba.core import types, cgutils
88
from llvmlite import ir, binding
99

10-
# Flag to enable debug print in NRT_incref and NRT_decref
11-
_debug_print = False
1210

13-
_word_type = ir.IntType(MACHINE_BITS)
11+
_word_type = ir.IntType(config.MACHINE_BITS)
1412
_pointer_type = ir.PointerType(ir.IntType(8))
1513

1614
_meminfo_struct_type = ir.LiteralStructType([
@@ -54,10 +52,11 @@ def _define_nrt_incref(module, atomic_incr):
5452
with cgutils.if_unlikely(builder, is_null):
5553
builder.ret_void()
5654

57-
if _debug_print:
58-
cgutils.printf(builder, "*** NRT_Incref %zu [%p]\n", builder.load(ptr),
55+
word_ptr = builder.bitcast(ptr, atomic_incr.args[0].type)
56+
if config.DEBUG_NRT:
57+
cgutils.printf(builder, "*** NRT_Incref %zu [%p]\n", builder.load(word_ptr),
5958
ptr)
60-
builder.call(atomic_incr, [builder.bitcast(ptr, atomic_incr.args[0].type)])
59+
builder.call(atomic_incr, [word_ptr])
6160
builder.ret_void()
6261

6362

@@ -79,17 +78,20 @@ def _define_nrt_decref(module, atomic_decr):
7978
with cgutils.if_unlikely(builder, is_null):
8079
builder.ret_void()
8180

82-
if _debug_print:
83-
cgutils.printf(builder, "*** NRT_Decref %zu [%p]\n", builder.load(ptr),
84-
ptr)
8581

8682
# For memory fence usage, see https://llvm.org/docs/Atomics.html
8783

8884
# A release fence is used before the relevant write operation.
8985
# No-op on x86. On POWER, it lowers to lwsync.
9086
builder.fence("release")
87+
88+
word_ptr = builder.bitcast(ptr, atomic_decr.args[0].type)
89+
90+
if config.DEBUG_NRT:
91+
cgutils.printf(builder, "*** NRT_Decref %zu [%p]\n", builder.load(word_ptr),
92+
ptr)
9193
newrefct = builder.call(atomic_decr,
92-
[builder.bitcast(ptr, atomic_decr.args[0].type)])
94+
[word_ptr])
9395

9496
refct_eq_0 = builder.icmp_unsigned("==", newrefct,
9597
ir.Constant(newrefct.type, 0))

0 commit comments

Comments
 (0)