Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/MilesONerd/neurenix/llms.txt

Use this file to discover all available pages before exploring further.

Overview

The Device class abstracts computational hardware, allowing Neurenix to run on various platforms including CPU, CUDA, ROCm, TPU, NPU, WebGPU, and more.

DeviceType Enum

class DeviceType(Enum):
    CPU = "cpu"
    CUDA = "cuda"
    ROCM = "rocm"
    WEBGPU = "webgpu"
    TPU = "tpu"
    NPU = "npu"
    VULKAN = "vulkan"
    OPENCL = "opencl"
    ONEAPI = "oneapi"
    DIRECTML = "directml"
    ONEDNN = "onednn"
    MKLDNN = "mkldnn"
    TENSORRT = "tensorrt"
    QUANTUM = "quantum"
    ARM = "arm"

Device Class

class Device:
    def __init__(self, device_type: DeviceType, index: int = 0)

Parameters

device_type
DeviceType
required
The type of the device (CPU, CUDA, TPU, etc.).
index
int
default:"0"
The index of the device (for multiple devices of the same type).

Properties

type

@property
def type(self) -> DeviceType
Get the type of the device.
return
DeviceType
The device type.

index

@property
def index(self) -> int
Get the index of the device.

name

@property
def name(self) -> str
Get the name of the device.
return
str
Device name string (e.g., “CUDA:0”, “CPU”).

Class Methods

device_count

@classmethod
def device_count(cls) -> int
Get the total number of devices available.
return
int
The total number of devices available.

Module Functions

get_device

def get_device(device_str: str) -> Device
Get a device from a string representation.
device_str
str
required
String representation of the device (e.g., ‘cpu’, ‘cuda:0’, ‘tpu:1’).
return
Device
The corresponding device object.

get_device_count

def get_device_count(device_type: DeviceType) -> int
Get the number of devices of the given type.
device_type
DeviceType
required
The type of device to count.
return
int
The number of devices of the given type.

get_available_devices

def get_available_devices() -> List[Device]
Get a list of all available devices.
return
List[Device]
A list of available devices.

Example Usage

import neurenix as nx
from neurenix.device import Device, DeviceType, get_device, get_available_devices

# Create a CPU device
cpu = Device(DeviceType.CPU)
print(cpu.name)  # "CPU"

# Create a CUDA device
cuda = Device(DeviceType.CUDA, index=0)
print(cuda.name)  # "CUDA:0"

# Create a TPU device
tpu = Device(DeviceType.TPU, index=0)

# Get device from string
device = get_device("cuda:1")
print(device.type)  # DeviceType.CUDA
print(device.index)  # 1

# Get available devices
devices = get_available_devices()
for dev in devices:
    print(f"Available: {dev.name}")

# Get device count
cuda_count = get_device_count(DeviceType.CUDA)
print(f"CUDA devices: {cuda_count}")

# Use device with tensors
tensor = nx.Tensor([1, 2, 3], device=cuda)
print(tensor.device.name)  # "CUDA:0"

# Move tensor to different device
tensor_cpu = tensor.to(cpu)
print(tensor_cpu.device.name)  # "CPU"

# Create WebGPU device for edge deployment
webgpu = Device(DeviceType.WEBGPU, index=0)

# Create NPU device for mobile AI
npu = Device(DeviceType.NPU, index=0)

Supported Devices

CPU

Standard CPU execution

CUDA

NVIDIA GPU acceleration

ROCm

AMD GPU acceleration

TPU

Google Tensor Processing Units

NPU

Neural Processing Units

WebGPU

Browser-based GPU acceleration

Vulkan

Cross-platform GPU API

OpenCL

Open Computing Language

oneAPI

Intel unified programming model

Build docs developers (and LLMs) love