Overview
TheDevice class abstracts computational hardware, allowing tensors and models to run on different devices without code changes. Neurenix automatically detects available hardware and provides a unified API across all backends.
Device Types
Neurenix supports a comprehensive range of hardware backends through theDeviceType enum:
- General Purpose
- Cross-Platform
- Specialized
Creating Devices
From DeviceType
From String
Device strings follow the format
type:index, where the index defaults to 0 if omitted.Device Properties
Hardware Detection
Checking Device Availability
Listing Available Devices
Total Device Count
Using Devices with Tensors
Creating Tensors on Specific Devices
Moving Between Devices
- Standard Transfer
- Hot-Swap (In-Place)
- Async Transfer
Device-Specific Features
CUDA Devices
WebGPU for Browser Deployment
WebGPU support is automatically detected when running in a WebAssembly environment with GPU access.
TPU Devices
Device Comparison
Multi-Device Training
Distribute workload across multiple devices:Best Practices
Check Availability
Always check device availability before use with
get_device_count()Consistent Device Placement
Keep tensors and models on the same device to avoid transfer overhead
Use Genesis
Let the Genesis system handle device selection for optimal performance
Profile Memory
Monitor GPU memory usage with
DeviceManager.get_memory_stats()Common Patterns
Automatic Fallback
Device-Agnostic Code
API Reference
Device Properties
Related Documentation
- Architecture - Hot-swappable backends and Genesis system
- Tensors - Creating and moving tensors across devices
- Neural Networks - Moving models to devices