Skip to content

Latest commit

 

History

History
61 lines (43 loc) · 2.5 KB

target_extension.rst

File metadata and controls

61 lines (43 loc) · 2.5 KB

Notes on Target Extensions

Warning

All features and APIs described in this page are in-development and may change at any time without deprecation notices being issued.

Inheriting compiler flags from the caller

Compiler flags, i.e. options such as fastmath, nrt in @jit(nrt=True, fastmath=True)) are specified per-function but their effects are not well-defined---some flags affect the entire callgraph, some flags affect only the current function. Sometimes it is necessary for callees to inherit flags from the caller; for example the fastmath flag should be infectious.

To address the problem, the following are needed:

  1. Better definitions for the semantics of compiler flags. Preferably, all flags should limit their effect to the current function. (TODO)
  2. Allow compiler flags to be inherited from the caller. (Done)
  3. Consider compiler flags in function resolution. (TODO)

numba.core.targetconfig.ConfigStack is used to propagate the compiler flags throughout the compiler. At the start of the compilation, the flags are pushed into the ConfigStack, which maintains a thread-local stack for the compilation. Thus, callees can check the flags in the caller.

numba.core.targetconfig.ConfigStack

Compiler flags

Compiler flags are defined as a subclass of TargetConfig:

numba.core.targetconfig.TargetConfig

These are internal compiler flags and they are different from the user-facing options used in the jit decorators.

Internally, the user-facing options are mapped to the internal compiler flags by numba.core.options.TargetOptions. Each target can override the default compiler flags and control the flag inheritance in TargetOptions.finalize. The CPU target overrides it.

numba.core.options.TargetOptions

In numba.core.options.TargetOptions.finalize, use numba.core.targetconfig.TargetConfig.inherit_if_not_set to request a compiler flag from the caller if it is not set for the current function.