utils: internal utilities for developing¶
moraine.api.utils_ (source). These names are not re-exported: import them from moraine.api.utils_.
mjit
¶
numba.jit with the compiled code cached in moraine's numba cache directory; use it (or ngjit, ngpjit)
instead of cache=True
get_mem_avail
¶
Memory available to this process in bytes: the free memory of the machine, or less under a cgroup limit (e.g. a SLURM job).
Examples¶
Run when this manual is built; the output follows each snippet.
import numpy as np
from moraine.api.utils_ import get_array_module, is_cuda_available, get_n_cpus_avail
print(is_cuda_available()) # True only when CUDA_VISIBLE_DEVICES names a GPU and cupy imports
xp = get_array_module(np.zeros(3)) # numpy for numpy arrays, cupy for cupy arrays
print(xp.__name__)
print(get_n_cpus_avail() >= 1)
Functions dispatch on the kind of their input with get_array_module; mjit, ngjit and ngpjit are the numba
decorators of moraine (compiled code cached by a hash of the sources, decision 0029).