Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions numba/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ def optional_str(x):
# (up to and including IR generation)
DEBUG_FRONTEND = _readenv("NUMBA_DEBUG_FRONTEND", int, 0)

# Enable debug prints in nrtdynmod
DEBUG_NRT = _readenv("NUMBA_DEBUG_NRT", int, 0)

# How many recently deserialized functions to retain regardless
# of external references
FUNCTION_CACHE_SIZE = _readenv("NUMBA_FUNCTION_CACHE_SIZE", int, 128)
Expand Down
24 changes: 13 additions & 11 deletions numba/core/runtime/nrtdynmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
"""


from numba.core.config import MACHINE_BITS
from numba.core import config
from numba.core import types, cgutils
from llvmlite import ir, binding

# Flag to enable debug print in NRT_incref and NRT_decref
_debug_print = False

_word_type = ir.IntType(MACHINE_BITS)
_word_type = ir.IntType(config.MACHINE_BITS)
_pointer_type = ir.PointerType(ir.IntType(8))

_meminfo_struct_type = ir.LiteralStructType([
Expand Down Expand Up @@ -54,10 +52,11 @@ def _define_nrt_incref(module, atomic_incr):
with cgutils.if_unlikely(builder, is_null):
builder.ret_void()

if _debug_print:
cgutils.printf(builder, "*** NRT_Incref %zu [%p]\n", builder.load(ptr),
word_ptr = builder.bitcast(ptr, atomic_incr.args[0].type)
if config.DEBUG_NRT:
cgutils.printf(builder, "*** NRT_Incref %zu [%p]\n", builder.load(word_ptr),
ptr)
builder.call(atomic_incr, [builder.bitcast(ptr, atomic_incr.args[0].type)])
builder.call(atomic_incr, [word_ptr])
builder.ret_void()


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

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

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

# A release fence is used before the relevant write operation.
# No-op on x86. On POWER, it lowers to lwsync.
builder.fence("release")

word_ptr = builder.bitcast(ptr, atomic_decr.args[0].type)

if config.DEBUG_NRT:
cgutils.printf(builder, "*** NRT_Decref %zu [%p]\n", builder.load(word_ptr),
ptr)
newrefct = builder.call(atomic_decr,
[builder.bitcast(ptr, atomic_decr.args[0].type)])
[word_ptr])

refct_eq_0 = builder.icmp_unsigned("==", newrefct,
ir.Constant(newrefct.type, 0))
Expand Down