[OpenReg] Improve README.md and optimize some codes for OpenReg (#158415)

----

- add description for DSO dependencies
- remove unnecessary code
Pull Request resolved: https://github.com/pytorch/pytorch/pull/158415
Approved by: https://github.com/albanD
This commit is contained in:
FFFrog
2025-07-24 11:46:10 +08:00
committed by PyTorch MergeBot
parent 6fc0ad22f0
commit f1a1aa9490
3 changed files with 22 additions and 19 deletions

View File

@ -75,10 +75,20 @@ graph LR
A --> B --> C --> D --> E
```
- `_C.so`: torch\_openreg/csrc/stub.c
- `libtorch_bindings.so`: torch\_openreg/csrc/\*.cpp
- `libtorch_openreg.so`: csrc
- `libopenreg.so`: third\_party/openreg
There are 4 DSOs in torch_openreg, and the dependencies between them are as follows:
- `_C.so`:
- **sources**: torch_openreg/csrc/stub.c
- **description**: Python C module entry point.
- `libtorch_bindings.so`: The bridging code between Python and C++ should go here.
- **sources**: torch_openreg/csrc
- **description**: A thin glue layer between Python and C++.
- `libtorch_openreg.so`: All core implementations should go here.
- **sources**: csrc
- **description**: All core functionality, such as device runtime, operators, etc.
- `libopenreg.so`: A DSO that uses the CPU to emulate a CUDA-like device, you can ignore it.
- **sources**: third_party/openreg
- **description**: Provides low-level device functionality similar to libcudart.so.
**Key Directories**:
@ -155,18 +165,14 @@ print("OpenReg backend is available!")
device = torch.device("openreg")
try:
x = torch.tensor([[1., 2.], [3., 4.]], device=device)
y = x + 2
print("Result y:\n", y)
print(f"Device of y: {y.device}")
x = torch.tensor([[1., 2.], [3., 4.]], device=device)
y = x + 2
print("Result y:\n", y)
print(f"Device of y: {y.device}")
z = y.cpu()
print("Result z:\n", z)
print(f"Device of z: {z.device}")
except Exception as e:
print(f"\nAn error occurred: {e}")
z = y.cpu()
print("Result z:\n", z)
print(f"Device of z: {z.device}")
```
## Future Plans