Компиляция JIT в библиотеке numba
Есть некоторый код, который считает число Пи.
@numba.njit(parallel=True)
def calc(iter_count):
result = 1
for i in numba.prange(1, iter_count):
result += ((-1)**i)/(2*i+1)
return result
Возможно ли вынести компиляцию, когда программа только запускается, а не во время первого вызова метода calc()?
Ответы (1 шт):
Автор решения: MaxU
→ Ссылка
Выдержка из документации:
While Numba’s main use case is Just-in-Time compilation, it also provides a facility for Ahead-of-Time compilation (AOT).
Benefits
- AOT compilation produces a compiled extension module which does not depend on Numba: you can distribute the module on machines which do not have Numba installed (but Numpy is required).
- There is no compilation overhead at runtime (but see the @jit cache option), nor any overhead of importing Numba.
Limitations
- AOT compilation only allows for regular functions, not ufuncs.
- You have to specify function signatures explicitly.
- Each exported function can have only one signature (but you can export several different signatures under different names).
- AOT compilation produces generic code for your CPU’s architectural family (for example “x86-64”), while JIT compilation produces code optimized for your particular CPU model.