kernels
Numba kernels that run in parallel only when the work pays for it.
jit
jit(
function: Callable | None = None,
*,
parallel: bool = False,
contract: bool = False
) -> Callable
Compile function with numba, cached on disk where numba can write.
The compiled function releases the GIL, so Python threads can run it at once. Numba refuses to define a cached function when no cache directory is writable (e.g. a read-only install without NUMBA_CACHE_DIR), so such installs compile in every process instead. With contract, LLVM may fuse the function's multiplies and adds.
Source code in src/tsim/utils/kernels.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
kernel
kernel(function: Callable) -> Callable
Compile function serially and in parallel; run(work, *args) picks one.
work estimates the call's cost in simple operations; calls below PARALLEL_WORK run serially, and so do calls on the worker threads of run_tasks and calls while numba has one thread. In the serial compilation every numba.prange is a plain range, so both compute the same result.
Source code in src/tsim/utils/kernels.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | |
run_tasks
run_tasks(
function: Callable[[_Task], _Result],
tasks: Iterable[_Task],
threads: int,
) -> list[_Result]
Return [function(task) for task in tasks], on up to threads threads.
With more than one thread the tasks run on worker threads, and every kernel in them runs serially: the tasks keep the cores busy, and independent tasks scale far better than numba's threads inside each kernel. Otherwise, and in a task, the tasks run in the calling thread. Every task finishes before the first error, if any, is raised.
Source code in src/tsim/utils/kernels.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |