RAII guard that pins libtorch's intra-op thread count for the current scope and restores the previous value on destruction.
More...
RAII guard that pins libtorch's intra-op thread count for the current scope and restores the previous value on destruction.
NEML2 models are evaluated with MPI as the parallelism axis (each rank owns a slice of the element batch), and the AOTI-compiled graphs get essentially no speedup from libtorch's intra-op threads. Left at libtorch's default (the core count), those per-rank thread pools oversubscribe the node under MPI and degrade strong scaling – so NEML2 pins the count around each evaluation. We save and restore rather than set-once because other parts of MOOSE/libtorch may change the global value, and we do not want to disturb it outside NEML2's evaluation.
Intra-op only: at::set_num_interop_threads is one-shot (it throws once the interop pool has been used) and so cannot be scoped; the interop count is left to the application-level setup.
Definition at line 214 of file NEML2Utils.h.