[OpenReg] Add DeviceTypeTestBase example with instantiate_device_type_tests
- Dominant language
- Python
- Stars
- 103k
- Forks
- 29.5k
- PR merge metrics
- PR metrics pending
Description
### 🚀 The feature, motivation and pitch
## Summary
Add a working example of `DeviceTypeTestBase` and `instantiate_device_type_tests()` to OpenReg, providing a documented reference for backend authors on how to implement device-agnostic tests.
## Background
As outlined in [#158917](https://github.com/pytorch/pytorch/issues/158917), OpenReg aims to serve as the official reference implementation for new device integration into PyTorch. A key part of this is demonstrating how to use PyTorch's standardized testing infrastructure.
[DeviceTypeTestBase](https://github.com/pytorch/pytorch/blob/main/torch/testing/_internal/common_device_type.py#L317) allows writing tests once that automatically generate `_cpu`, `_cuda`, `_openreg` (and other device) variants.
Parent issue: [169597](https://github.com/pytorch/pytorch/issues/169597)
## Proposed Tests
The example should include tests for:
- Basic tensor creation
- `test_basic_tensor_creation` - Create tensors on device
- `test_empty_tensor` - `torch.empty()` semantics
- `test_zeros_ones` - `torch.zeros()` and `torch.ones()`
- Core elementwise operations
- Dtype support and propagation
- Device transfer/copy correctness
- Device-specific skip patterns
- ...
## Expected Outcome
- Tests are device-agnostic and generate `_cpu`, `_cuda`, `_openreg` variants automatically
- Validates that OpenReg correctly integrates with PyTorch's test infrastructure
## CC
@parsshar-RH @ahkush @groenenboomj
### Alternatives
_No response_
### Additional context
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.