From f1a1aa9490cb24d74717b8369c29e82eb319a47e Mon Sep 17 00:00:00 2001 From: FFFrog Date: Thu, 24 Jul 2025 11:46:10 +0800 Subject: [PATCH] [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 --- .../torch_openreg/README.md | 36 +++++++++++-------- .../torch_openreg/requirements.txt | 1 - test/test_openreg.py | 4 +-- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/test/cpp_extensions/open_registration_extension/torch_openreg/README.md b/test/cpp_extensions/open_registration_extension/torch_openreg/README.md index e59013cea440..23798b596817 100644 --- a/test/cpp_extensions/open_registration_extension/torch_openreg/README.md +++ b/test/cpp_extensions/open_registration_extension/torch_openreg/README.md @@ -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 diff --git a/test/cpp_extensions/open_registration_extension/torch_openreg/requirements.txt b/test/cpp_extensions/open_registration_extension/torch_openreg/requirements.txt index 42d5e8d799f4..12c6d5d5eac2 100644 --- a/test/cpp_extensions/open_registration_extension/torch_openreg/requirements.txt +++ b/test/cpp_extensions/open_registration_extension/torch_openreg/requirements.txt @@ -1,2 +1 @@ torch -pybind11 diff --git a/test/test_openreg.py b/test/test_openreg.py index dc52231ff7bf..6350f6ef08fa 100644 --- a/test/test_openreg.py +++ b/test/test_openreg.py @@ -15,7 +15,6 @@ import torch_openreg # noqa: F401 import torch from torch.serialization import safe_globals from torch.testing._internal.common_utils import ( - IS_LINUX, run_tests, skipIfTorchDynamo, skipIfXpu, @@ -583,5 +582,4 @@ class TestOpenReg(TestCase): if __name__ == "__main__": - if IS_LINUX: - run_tests() + run_tests()