pytorch/test/cpp_extensions
can-gaa-hou 95191522e0 [OpenReg] Implement device autoload mechanism (#158555)
# Implement OpenReg device autoload mechanism

## Overview
The **Autoload** mechanism in PyTorch simplifies the integration of third-party device backends by enabling automatic discovery and initialization at runtime. Traditionally, integrating a new backend required explicit imports or manual initialization, which could be cumbersome and error-prone. With Autoload, PyTorch dynamically detects and initializes device backends, providing a seamless user experience.

This mechanism leverages Python entry points (e.g., `torch.backends`) and dynamic module loading. When PyTorch starts, it scans for registered entry points and invokes their initialization hooks, ensuring that all available backends are ready for use without requiring explicit imports.

## Motivation

This PR aims to apply [device autoload mechanism](https://github.com/pytorch/pytorch/issues/122468) to the OpenReg module with some simple changes.

## Change
### Before
```python
import torch
import torch_openreg

x = torch.tensor([1, 2, 3], device="openreg")
print(x)
```
### After
```python
import torch

# No need to import torch_openreg manually!
x = torch.tensor([1, 2, 3], device="openreg")
print(x)
```

Pull Request resolved: https://github.com/pytorch/pytorch/pull/158555
Approved by: https://github.com/FFFrog, https://github.com/albanD

Co-authored-by: Jiawei Li <ljw1101.vip@gmail.com>
2025-09-12 04:24:11 +00:00
..
libtorch_agnostic_extension Add new_zeros dtype variant to the shim and as a stable op (#161597) 2025-08-28 13:57:24 +00:00
no_python_abi_suffix_test
open_registration_extension/torch_openreg [OpenReg] Implement device autoload mechanism (#158555) 2025-09-12 04:24:11 +00:00
python_agnostic_extension Make python_agnostic cpp extension tests standalone (#153274) 2025-05-20 19:18:09 +00:00
self_compiler_include_dirs_test
torch_stable_test_extension Error when TORCH_STABLE_ONLY is defined in TensorBase.h (#161658) 2025-08-28 04:36:31 +00:00
torch_test_cpp_extension
cpp_c10d_extension.cpp
cpp_c10d_extension.hpp
cpp_frontend_extension.cpp
cublas_extension.cpp
cuda_dlink_extension_add.cu
cuda_dlink_extension_add.cuh
cuda_dlink_extension_kernel.cu
cuda_dlink_extension.cpp
cuda_extension_kernel.cu
cuda_extension_kernel2.cu
cuda_extension.cpp
cuda_extension.cu
cudnn_extension.cpp
cusolver_extension.cpp
dangling_impl_extension.cpp
doubler.h
extension.cpp
identity.cpp
jit_extension.cpp
jit_extension2.cpp
maia_extension.cpp
mps_extension.mm
mtia_extension.cpp
open_registration_extension.cpp [OpenReg][1/N] Migrate cpp_extensions_open_device_registration to OpenReg (#156588) 2025-06-26 03:59:50 +00:00
rng_extension.cpp
setup.py
torch_library.cu
xpu_extension.sycl