utils: internal utilities for developing¶
moraine.api.utils_(源码)。这些名字没有被重新导出:从 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).
示例¶
构建本手册时运行;输出紧随每段代码。
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).