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
12 changes: 12 additions & 0 deletions docs/source/developer/numba-runtime.rst
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,18 @@ Here is an example that uses the ``nrt_external.h``:
return mi;
}

It is important to ensure that the NRT is initialized prior to making calls to
it, calling ``numba.core.runtime.nrt.rtsys.initialize(context)`` from Python
will have the desired effect. Similarly the code snippet:

.. code-block:: Python

from numba.core.registry import cpu_target # Get the CPU target singleton
cpu_target.target_context # Access the target_context property to initialize

will achieve the same specifically for Numba's CPU target (the default). Failure
to initialize the NRT will result in access violations as function pointers for
various internal atomic operations will be missing in the ``NRT_MemSys`` struct.

Future Plan
===========
Expand Down
10 changes: 7 additions & 3 deletions numba/tests/test_nrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import numpy as np

from numba import njit
from numba.core import typing, types
from numba.core import types
from numba.core.compiler import compile_isolated, Flags
from numba.core.runtime import (
rtsys,
Expand All @@ -25,7 +25,7 @@

from numba.tests.support import (MemoryLeakMixin, TestCase, temp_directory,
import_dynamic)
from numba.core import cpu
from numba.core.registry import cpu_target
import unittest

enable_nrt_flags = Flags()
Expand Down Expand Up @@ -82,7 +82,7 @@ def setUp(self):
# Reset the Dummy class
Dummy.alive = 0
# initialize the NRT (in case the tests are run in isolation)
cpu.CPUContext(typing.Context())
cpu_target.target_context

def test_meminfo_refct_1(self):
d = Dummy()
Expand Down Expand Up @@ -554,6 +554,10 @@ def foo(x):
class TestNrtExternalCFFI(MemoryLeakMixin, TestCase):
"""Testing the use of externally compiled C code that use NRT
"""
def setUp(self):
# initialize the NRT (in case the tests are run in isolation)
super(TestNrtExternalCFFI, self).setUp()
cpu_target.target_context

def compile_cffi_module(self, name, source, cdef):
from cffi import FFI
Expand Down