Options
All
  • Public
  • Public/Protected
  • All
Menu

Module cuda/src

Index

References

CUDA

Renames and re-exports addon

DeviceFlags

Re-exports DeviceFlags

DeviceMemory

Re-exports DeviceMemory

IpcMemory

Re-exports IpcMemory

ManagedMemory

Re-exports ManagedMemory

MappedGLMemory

Re-exports MappedGLMemory

Memory

Re-exports Memory

PinnedMemory

Re-exports PinnedMemory

driver

Re-exports driver

runtime

Re-exports runtime

Type aliases

CUDAMemoryView

Variables

devices

devices: DeviceList = ...
summary

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

// Access (and create) Devices 0,1
const [device0, device1] = devices;

console.log(device0);
// > CUDADevice {"id":0,"name":"Quadro RTX 8000","compute_capability":[7,5]}

console.log(device0.pciBusName);
// > '0000:15:00.0'

console.log(device0.canAccessPeerDevice(device1));
// > true

console.log(device0.getProperties());
// > {
// > name: 'Quadro RTX 8000',
// > totalGlobalMem: 50944540672,
// > sharedMemPerBlock: 49152,
// > regsPerBlock: 65536,
// > warpSize: 32,
// > memPitch: 2147483647,
// > maxThreadsPerBlock: 1024,
// > ...
// > }

// Device 0 remains the active device until `device1` is made active
console.log(`Active device id: ${Device.activeDeviceId}`);
// > 0

device1.activate();
console.log(`Active device id: ${Device.activeDeviceId}`);
// > 1

// Set Device 0 to the active device again
device0.activate();
console.log(`Active device id: ${Device.activeDeviceId}`);
// > 0

Functions

clampRange

  • clampRange(len: number, lhs?: number, rhs?: number): [begin: number, end: number]
  • summary

    Clamp begin and end ranges similar to Array.prototype.slice.

    description

    Normalizes begin/end to between 0 and length, and wrap around on negative indices.

    example
    import {clampRange} from '@rapidsai/cuda';

    clampRange(5) // [0, 5]
    clampRange(5, 0, -1) // [0, 4]
    clampRange(5, -1) // [4, 5]
    clampRange(5, -1, 0) // [4, 4]

    const ary = Array.from({length: 5}, (_, i) => i);

    assert(ary.slice() == ary.slice(...clampRange(ary.length)))
    // > [0, 1, 2, 3, 4]
    assert(ary.slice(0, -1) == ary.slice(...clampRange(ary.length, 0, -1)))
    // > [0, 1, 2, 3]
    assert(ary.slice(-1) == ary.slice(...clampRange(ary.length, -1)))
    // > [4]
    assert(ary.slice(-1, 0) == ary.slice(...clampRange(ary.length, -1, 0)))
    // > []

    Parameters

    • len: number

      The total number of elements.

    • lhs: number = 0

      The beginning of the range to clamp.

    • rhs: number = len

      The end of the range to clamp (Default: len).

    Returns [begin: number, end: number]

    An Array of the normalized begin and end positions.

setDefaultAllocator

  • setDefaultAllocator(allocate?: null | ((byteLength: number) => Memory)): void
  • summary

    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.

    example
    import {
    DeviceMemory,
    ManagedMemory,
    Float32Buffer,
    setDefaultAllocator
    } from '@rapidsai/cuda';

    // 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.
    const dbuf = new Float32Buffer([1.0, 2.0, 3.0]);
    assert(dbuf.buffer instanceof DeviceMemory);

    // Override allocate function to create `ManagedMemory` instances.
    setDefaultAllocator((byteLength) => new ManagedMemory(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.
    const mbuf = new Float32Buffer([1.0, 2.0, 3.0]);
    assert(mbuf.buffer instanceof ManagedMemory);

    Parameters

    • Optional allocate: null | ((byteLength: number) => Memory)

      Function to use for device Memory allocations.

    Returns void