cutcutcodec.core.opti.parallel.threading

Thread utils.

Classes

TorchThreads(threads)

Context manager to set the number of torch threads.

Functions

get_num_threads(threads)

Return the number of threads.

Details

class cutcutcodec.core.opti.parallel.threading.TorchThreads(threads: Integral)[source]

Context manager to set the number of torch threads.

Examples

>>> import torch
>>> from cutcutcodec.core.opti.parallel.threading import TorchThreads
>>> (t := torch.get_num_threads()) != 1
True
>>> with TorchThreads(1):
...     torch.get_num_threads()
...
1
>>> torch.get_num_threads() == t
True
>>>

Initialise the thread setter.

Parameters

threadsint

The number of threads, same as get_num_threads.

cutcutcodec.core.opti.parallel.threading.get_num_threads(threads: Integral) int[source]

Return the number of threads.