Constructs a backend-specific device object.
A device identifies a compute resources, such as CPU, or a specific GPU.
It is relevant for data allocation (e.g. via nv_array()) but also compilation (jit).
Arguments
- x
(
character(1)| device object)
Identifier for the device (e.g."cpu","cuda","cuda:<n>"), or an existing device object (returned as-is).- backend
(
NULL|character(1))
The backend for which to create the device. Defaults todefault_backend()whenNULL.
Value
A backend-specific device object (e.g. PJRTDevice for "xla",
quickr_device for "quickr").
Examples
# Create CPU device for xla backend:
nv_device("cpu", "xla")
#> <CpuDevice(id=0)>
# Create CPU device for quickr backend:
nv_device("cpu", "quickr")
#> QuickrDevice(cpu)
# Pass through an existing device:
dev <- nv_device("cpu")
identical(nv_device(dev), dev)
#> [1] TRUE