TypeTensor - v0.1.0
    Preparing search index...

    Interface Device

    Device interface for tensor computation

    Represents a compute device (CPU, GPU, etc.) that can execute tensor operations. Devices are responsible for:

    • Executing tensor operations described by StorageTransformation
    • Managing device memory allocation and deallocation
    • Transferring data between host and device
    class CPUDevice implements Device {
    readonly id = 'cpu:0';
    readonly type = 'cpu';

    async execute(op, inputs) {
    switch (op.__op) {
    case 'neg': return this.executeNeg(op, inputs[0]);
    case 'add': return this.executeAdd(op, inputs[0], inputs[1]);
    // ... more operations
    }
    }
    }
    interface Device {
        id: string;
        type: string;
        createData(byteLength: number): DeviceData;
        disposeData(data: DeviceData): void;
        execute<T extends AnyStorageTransformation>(
            op: T,
            inputs: DeviceData[],
            output?: DeviceData,
        ): Promise<DeviceData>;
        readData(data: DeviceData): Promise<ArrayBuffer>;
        supportsNonContiguous(op: AllOperationTypes): boolean;
        writeData(data: DeviceData, buffer: ArrayBuffer): Promise<void>;
    }

    Implemented by

    Index

    Properties

    id: string

    Unique identifier for this device instance

    type: string

    Device type identifier (e.g., 'cpu', 'webgpu', 'cuda')

    Methods

    • Read data from device to host memory

      Parameters

      Returns Promise<ArrayBuffer>

      Promise resolving to data as ArrayBuffer

      If data is not from this device

    • Check if this device supports non-contiguous tensors for a specific operation

      Parameters

      Returns boolean

      True if the operation can handle non-contiguous inputs, false otherwise

      // CPU device might not support non-contiguous for most ops
      cpuDevice.supportsNonContiguous('matmul'); // false
      cpuDevice.supportsNonContiguous('neg'); // false

      // GPU device might support non-contiguous for all ops
      gpuDevice.supportsNonContiguous('matmul'); // true
      gpuDevice.supportsNonContiguous('neg'); // true
    • Write data from host to device memory

      Parameters

      • data: DeviceData

        Device data handle to write to

      • buffer: ArrayBuffer

        Source data as ArrayBuffer

      Returns Promise<void>

      Promise resolving when write is complete

      If data is not from this device

      If buffer size doesn't match data size