Example #1
0
def _check_tbb_version_compatible():
    """
    Checks that if TBB is present it is of a compatible version.
    """
    try:
        # first check that the TBB version is new enough
        if _IS_WINDOWS:
            libtbb_name = 'tbb12.dll'
        elif _IS_OSX:
            libtbb_name = 'libtbb.12.dylib'
        elif _IS_LINUX:
            libtbb_name = 'libtbb.so.12'
        else:
            raise ValueError("Unknown operating system")
        libtbb = CDLL(libtbb_name)
        version_func = libtbb.TBB_runtime_interface_version
        version_func.argtypes = []
        version_func.restype = c_int
        tbb_iface_ver = version_func()
        if tbb_iface_ver < 12010: # magic number from TBB
            msg = ("The TBB threading layer requires TBB "
                   "version 2021 update 1 or later i.e., "
                   "TBB_INTERFACE_VERSION >= 12010. Found "
                   "TBB_INTERFACE_VERSION = %s. The TBB "
                   "threading layer is disabled.") % tbb_iface_ver
            problem = errors.NumbaWarning(msg)
            warnings.warn(problem)
            raise ImportError("Problem with TBB. Reason: %s" % msg)
    except (ValueError, OSError) as e:
        # Translate as an ImportError for consistent error class use, this error
        # will never materialise
        raise ImportError("Problem with TBB. Reason: %s" % e)
Example #2
0
def _warn_about_uninitialized_variable(varname, loc):
    if config.ALWAYS_WARN_UNINIT_VAR:
        warnings.warn(
            errors.NumbaWarning(
                f"Detected uninitialized variable {varname}",
                loc=loc),
        )
Example #3
0
def get_numbapro_envvar(envvar, default=None):
    # use vanilla get here so as to use `None` as a signal for not-set
    value = os.environ.get(envvar)
    if value is not None:
        url = ("https://numba.pydata.org/numba-doc/latest/cuda/overview.html",
               "#cudatoolkit-lookup")
        msg = ("\nEnvironment variables with the 'NUMBAPRO' prefix are "
               "deprecated and consequently ignored, found use of %s=%s.\n\n"
               "For more information about alternatives visit: %s" %
               (envvar, value, url))
        warnings.warn(errors.NumbaWarning(msg))
    return default
Example #4
0
    def test_warnings_fixer(self):
        # For some context, see #4083

        wfix = errors.WarningsFixer(errors.NumbaWarning)
        with wfix.catch_warnings('foo', 10):
            warnings.warn(errors.NumbaWarning('same'))
            warnings.warn(errors.NumbaDeprecationWarning('same'))

        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter('always')
            wfix.flush()

            self.assertEqual(len(w), 2)
            # the order of these will be backwards to the above, the
            # WarningsFixer flush method sorts with a key based on str
            # comparison
            self.assertEqual(w[0].category, NumbaDeprecationWarning)
            self.assertEqual(w[1].category, NumbaWarning)
            self.assertIn('same', str(w[0].message))
            self.assertIn('same', str(w[1].message))
Example #5
0
    def run_pass(self, state):
        """
        Lowering for object mode
        """

        if state.library is None:
            codegen = state.targetctx.codegen()
            state.library = codegen.create_library(state.func_id.func_qualname)
            # Enable object caching upfront, so that the library can
            # be later serialized.
            state.library.enable_object_caching()

        def backend_object_mode():
            """
            Object mode compilation
            """
            with giveup_context(
                    state, "Function %s failed at object mode lowering" %
                (state.func_id.func_name, )):
                if len(state.args) != state.nargs:
                    # append missing
                    # BUG?: What's going on with nargs here?
                    # check state.nargs vs self.nargs on original code
                    state.args = (tuple(state.args) + (types.pyobject, ) *
                                  (state.nargs - len(state.args)))

                return self._py_lowering_stage(state.targetctx, state.library,
                                               state.func_ir, state.flags)

        lowered = backend_object_mode()
        signature = typing.signature(state.return_type, *state.args)
        from numba.core.compiler import compile_result
        state.cr = compile_result(
            typing_context=state.typingctx,
            target_context=state.targetctx,
            entry_point=lowered.cfunc,
            typing_error=state.status.fail_reason,
            type_annotation=state.type_annotation,
            library=state.library,
            call_helper=lowered.call_helper,
            signature=signature,
            objectmode=True,
            interpmode=False,
            lifted=state.lifted,
            fndesc=lowered.fndesc,
            environment=lowered.env,
            metadata=state.metadata,
            reload_init=state.reload_init,
        )

        # Warn, deprecated behaviour, code compiled in objmode without
        # force_pyobject indicates fallback from nopython mode
        if not state.flags.force_pyobject:
            # first warn about object mode and yes/no to lifted loops
            if len(state.lifted) > 0:
                warn_msg = ('Function "%s" was compiled in object mode without'
                            ' forceobj=True, but has lifted loops.' %
                            (state.func_id.func_name, ))
            else:
                warn_msg = ('Function "%s" was compiled in object mode without'
                            ' forceobj=True.' % (state.func_id.func_name, ))
            warnings.warn(errors.NumbaWarning(warn_msg, state.func_ir.loc))

            url = ("http://numba.pydata.org/numba-doc/latest/reference/"
                   "deprecation.html#deprecation-of-object-mode-fall-"
                   "back-behaviour-when-using-jit")
            msg = ("\nFall-back from the nopython compilation path to the "
                   "object mode compilation path has been detected, this is "
                   "deprecated behaviour.\n\nFor more information visit %s" %
                   url)
            warnings.warn(
                errors.NumbaDeprecationWarning(msg, state.func_ir.loc))
            if state.flags.release_gil:
                warn_msg = ("Code running in object mode won't allow parallel"
                            " execution despite nogil=True.")
                warnings.warn_explicit(warn_msg, errors.NumbaWarning,
                                       state.func_id.filename,
                                       state.func_id.firstlineno)
        return True