Skip to content

Commit

Permalink
Merge pull request #7386 from stuartarchibald/fix/7385
Browse files Browse the repository at this point in the history
Ensure the NRT is initialized prior to use in external NRT tests.
  • Loading branch information
sklam committed Sep 22, 2021
1 parent 5dbcadb commit fed8949
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
12 changes: 12 additions & 0 deletions docs/source/developer/numba-runtime.rst
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
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

0 comments on commit fed8949

Please sign in to comment.