Skip to content

Device

Device wrapper.

This module provides a thin Python wrapper around OIDN's device API.

Typical usage:

.. code-block:: python

import pyoidn

with pyoidn.Device() as device:
    device.commit()
    # create filters / buffers
    assert device.get_error() is None

Notes

  • The wrapper is intentionally minimal and mirrors OIDN's lifecycle.
  • Error handling: call :meth:Device.get_error after creating/committing/executing.
  • Refer to https://github.com/RenderKit/oidn?tab=readme-ov-file#devices for the OIDN property settings.

Device

Device(device_type=OIDN_DEVICE_TYPE_CPU)

Logical OIDN device.

A device owns OIDN resources (filters, buffers) and provides synchronization.

Parameters:

Name Type Description Default
device_type

One of OIDN_DEVICE_TYPE_*. The default is CPU. .. important:: This class does not automatically call :meth:commit. You should call :meth:commit before executing filters.

OIDN_DEVICE_TYPE_CPU

Create a new device.

Parameters:

Name Type Description Default
device_type

One of OIDN_DEVICE_TYPE_*.

OIDN_DEVICE_TYPE_CPU

__enter__

__enter__() -> Device

Enter a context manager.

Returns:

Type Description
Device

This device.

__exit__

__exit__(exc_type, exc_val, exc_tb) -> None

Exit a context manager and release the device.

commit

commit() -> None

Commit device parameters.

After setting device parameters (e.g., thread count), call this to apply them.

from_torch classmethod

from_torch(device: Any = None, stream: Any = None) -> Device

Create an OIDN device from a PyTorch device/tensor.

This enables: - CPU: creates an OIDN CPU device - CUDA: creates an OIDN CUDA device bound to a torch CUDA stream

Parameters

device: A torch.device / torch.Tensor / device string (e.g. "cuda:0", "cpu") or None (defaults to current CUDA device if available, else CPU). stream: A torch.cuda.Stream to bind to (CUDA only). If None, uses torch.cuda.current_stream(device).

get_bool

get_bool(name: str) -> bool

Get a boolean device parameter.

Parameters:

Name Type Description Default
name str

Parameter name (OIDN string).

required

Returns:

Type Description
bool

The boolean value.

get_error

get_error() -> Optional[str]

Get the last device error message.

Returns:

Type Description
Optional[str]

None if there is no error; otherwise a human-readable error message. .. note:: OIDN reports errors asynchronously in some cases, so you may want to call :meth:wait before checking.

get_int

get_int(name: str) -> int

Get an integer device parameter.

Parameters:

Name Type Description Default
name str

Parameter name (OIDN string).

required

Returns:

Type Description
int

The integer value.

get_uint

get_uint(name: str) -> int

Get an unsigned integer device parameter.

Parameters:

Name Type Description Default
name str

Parameter name (OIDN string).

required

Returns:

Type Description
int

The value as a Python int.

is_cpu_available staticmethod

is_cpu_available()

Return whether the CPU device backend is supported on this machine.

is_cuda_available staticmethod

is_cuda_available(device_id: int = 0)

Return whether a CUDA device backend is supported.

Parameters:

Name Type Description Default
device_id int

CUDA device index.

0

Returns:

Type Description

True if supported, otherwise False.

release

release() -> None

Release the underlying OIDN device handle.

set_bool

set_bool(name: str, value: bool) -> None

Set a boolean device parameter.

Parameters:

Name Type Description Default
name str

Parameter name (OIDN string).

required
value bool

Boolean value.

required

set_int

set_int(name: str, value: int) -> None

Set an integer device parameter.

Parameters:

Name Type Description Default
name str

Parameter name (OIDN string).

required
value int

Integer value.

required

set_uint

set_uint(name: str, value: int) -> None

Set an unsigned integer device parameter.

Parameters:

Name Type Description Default
name str

Parameter name (OIDN string).

required
value int

Unsigned integer value.

required

Raises:

Type Description
ValueError

If value is negative.

wait

wait() -> None

Wait for all async tasks to finish.