Configuration
The options that decide where, in which precision and in how much memory a computation runs. See Estimators for how they combine.
config
config(**options)
Bases: ContextDecorator
Temporarily override options.
Usable as a context manager (with optix.config(device="cuda"):) or
as a decorator. Overrides apply to the current thread / asyncio task
only: threads started inside the block see the process-wide defaults.
Note
Nesting works, and an instance may be re-entered (but not used concurrently from several threads).
Validate the overrides.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**options
|
object
|
Any field of |
{}
|
set_config
set_config(**options)
Set process-wide defaults.
Note
An active with config(...) block keeps shadowing the options it
overrides.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**options
|
object
|
Any field of |
{}
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If an option name is unknown. |
ValueError
|
If a value is invalid. |
get_config
get_config()
Return the active configuration.
Returns:
| Type | Description |
|---|---|
Config
|
The innermost |
Config
dataclass
Config(dtype=None, device=None, memory=256 * 2 ** 20, batch=None, compile=True, prefetch=0)
Immutable set of options.
Attributes:
| Name | Type | Description |
|---|---|---|
dtype |
dtype or None
|
Working floating-point dtype. |
device |
device or None
|
Working device. |
memory |
int
|
Budget, in bytes, of one loaded chunk on the working device. |
batch |
int or None
|
Explicit number of frames per chunk. Overrides |
compile |
bool
|
Whether kernels decorated with |
prefetch |
int
|
Number of chunks read ahead in a background thread (0 = off). |
Backend
resolve_backend
resolve_backend(dtype=None, device=None, like=None)
Resolve the working dtype and device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dtype
|
dtype or str
|
Explicit dtype. Default: configuration, else
|
None
|
device
|
device or str
|
Explicit device. Default: configuration, else the device of
|
None
|
like
|
object
|
Input data whose device is followed when no device is set. |
None
|
Returns:
| Type | Description |
|---|---|
Backend
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If float64 is requested on an MPS device, or a value is invalid. |
parse_bytes
parse_bytes(value)
Convert a memory size to a number of bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
int or float or str
|
A number of bytes ( |
required |
Returns:
| Type | Description |
|---|---|
int
|
Number of bytes (strictly positive). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the value cannot be parsed or is not positive. |