A lazily-evaluated list of available CUDA devices.
This list has a length property, and each available active Device can be accessed by device
ordinal (via Array-style subscript-accesses).
This list implements the Iterable protocol, meaning it can be enumerated in a for..of
loop, or with the [...] iterable expansion syntax.
note
While this list may seem like an Array, it is a JavaScript Proxy that only creates and
returns a Device instance for a given device ordinal the first time it's accessed.
note
Enumerating the devices list (i.e. [...devices]) will create and cache Device instances
for all CUDA devices available to the current process.
example
import {Device, devices} from'@rapidsai/cuda';
console.log(`Number of devices: ${devices.length}`);
// CUDA Device 0 is automatically activated by default console.log(`Active device id: ${Device.activeDeviceId}`); // 0
A function to override the default device memory allocation behavior.
The supplied function will be called to create the underlying Memory instances
when constructing one of the CUDAMemoryView in JavaScript.
// The default allocator creates `DeviceMemory` instances, // which can only be accessed directly from the GPU device. // An expensive copy from GPU to CPU memory must be performed // in order to read the data in JavaScript. constdbuf = newFloat32Buffer([1.0, 2.0, 3.0]); assert(dbuf.bufferinstanceofDeviceMemory);
// Override allocate function to create `ManagedMemory` instances. setDefaultAllocator((byteLength) =>newManagedMemory(byteLength));
// Now the allocator uses the supplied function to create // `ManagedMemory` instances. This kind of memory can be accessed // by both the CPU and GPU, because the CUDA driver automatically // migrates the data from the CPU <-> GPU as required. constmbuf = newFloat32Buffer([1.0, 2.0, 3.0]); assert(mbuf.bufferinstanceofManagedMemory);
A lazily-evaluated list of available CUDA devices.
protocol, meaning it can be enumerated in a
This list has a
length
property, and each available active Device can be accessed by device ordinal (via Array-style subscript-accesses).This list implements the Iterable
for..of
loop, or with the[...]
iterable expansion syntax.While this list may seem like an Array, it is a JavaScript Proxy that only creates and returns a Device instance for a given device ordinal the first time it's accessed.
Enumerating the
devices
list (i.e.[...devices]
) will create and cache Device instances for all CUDA devices available to the current process.