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 23798b596817..9ecbd0b886e3 100644 --- a/test/cpp_extensions/open_registration_extension/torch_openreg/README.md +++ b/test/cpp_extensions/open_registration_extension/torch_openreg/README.md @@ -47,6 +47,7 @@ torch_openreg/ │ ├── OpenRegHostAllocator.cpp │ ├── OpenRegHostAllocator.h │ └── ... +├── pyproject.toml ├── README.md ├── setup.py ├── third_party @@ -144,9 +145,8 @@ There are 4 DSOs in torch_openreg, and the dependencies between them are as foll ### Installation ```python -pip3 install -r requirements.txt - -python setup.py develop/install +pip3 install --no-build-isolation -e . # for develop +pip3 install --no-build-isolation . # for install ``` ### Usage Example diff --git a/test/cpp_extensions/open_registration_extension/torch_openreg/pyproject.toml b/test/cpp_extensions/open_registration_extension/torch_openreg/pyproject.toml new file mode 100644 index 000000000000..774fe5cdf83d --- /dev/null +++ b/test/cpp_extensions/open_registration_extension/torch_openreg/pyproject.toml @@ -0,0 +1,35 @@ +[build-system] +requires = [ + "setuptools", + "wheel", + "torch", # Needed by setup.py for getting include of PyTorch +] + +build-backend = "setuptools.build_meta" + +[project] +name = "torch_openreg" +version = "0.0.1" +description = "A minimal reference implementation of an out-of-tree backend" +readme = "README.md" +requires-python = ">=3.9" +license = { text = "BSD-3-Clause" } +authors = [{ name = "PyTorch Team", email = "packages@pytorch.org" }] +dependencies = [ + "torch", +] +# Add classifiers info for making lint happy +classifiers = [ + "Development Status :: 4 - Beta", + "Topic :: Software Development", + "Topic :: Software Development :: Libraries", + "Topic :: Software Development :: Libraries :: Python Modules", + "Programming Language :: C++", + "Programming Language :: Python :: 3 :: Only", +] + +[project.urls] +Homepage = "https://pytorch.org" +Repository = "https://github.com/pytorch/pytorch" +Documentation = "https://pytorch.org/docs" +Forum = "https://discuss.pytorch.org" diff --git a/test/cpp_extensions/open_registration_extension/torch_openreg/requirements.txt b/test/cpp_extensions/open_registration_extension/torch_openreg/requirements.txt deleted file mode 100644 index 12c6d5d5eac2..000000000000 --- a/test/cpp_extensions/open_registration_extension/torch_openreg/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -torch diff --git a/test/cpp_extensions/open_registration_extension/torch_openreg/setup.py b/test/cpp_extensions/open_registration_extension/torch_openreg/setup.py index 38a866e4ce21..07d31e73d76b 100644 --- a/test/cpp_extensions/open_registration_extension/torch_openreg/setup.py +++ b/test/cpp_extensions/open_registration_extension/torch_openreg/setup.py @@ -9,8 +9,8 @@ from setuptools import Extension, find_packages, setup -PACKAGE_NAME = "torch_openreg" BASE_DIR = os.path.dirname(os.path.realpath(__file__)) +RUN_BUILD_DEPS = any(arg in {"clean", "dist_info"} for arg in sys.argv) def get_pytorch_dir(): @@ -49,7 +49,7 @@ def build_deps(): class BuildClean(clean): def run(self): - for i in ["build", "install", "torch_openreg.egg-info", "torch_openreg/lib"]: + for i in ["build", "install", "torch_openreg/lib"]: dirs = os.path.join(BASE_DIR, i) if os.path.exists(dirs) and os.path.isdir(dirs): shutil.rmtree(dirs) @@ -60,9 +60,6 @@ def run(self): os.remove(os.path.join(dirpath, filename)) -RUN_BUILD_DEPS = any(arg == "clean" for arg in sys.argv) - - def main(): if not RUN_BUILD_DEPS: build_deps() @@ -71,6 +68,7 @@ def main(): Extension( name="torch_openreg._C", sources=["torch_openreg/csrc/stub.c"], + language="c", extra_compile_args=["-g", "-Wall", "-Werror"], libraries=["torch_bindings"], library_dirs=[os.path.join(BASE_DIR, "torch_openreg/lib")], @@ -78,20 +76,12 @@ def main(): ) ] - package_data = {PACKAGE_NAME: ["lib/*.so*"]} + package_data = {"torch_openreg": ["lib/*.so*"]} setup( - name=PACKAGE_NAME, - version="0.0.1", - author="PyTorch Core Team", - description="Example for PyTorch out of tree registration", - packages=find_packages(exclude=("test",)), + packages=find_packages(), package_data=package_data, - install_requires=[ - "torch", - ], ext_modules=ext_modules, - python_requires=">=3.8", cmdclass={ "clean": BuildClean, # type: ignore[misc] }, diff --git a/test/cpp_extensions/open_registration_extension/torch_openreg/torch_openreg/__init__.py b/test/cpp_extensions/open_registration_extension/torch_openreg/torch_openreg/__init__.py index 32bb170075ef..3ed73794b06d 100644 --- a/test/cpp_extensions/open_registration_extension/torch_openreg/torch_openreg/__init__.py +++ b/test/cpp_extensions/open_registration_extension/torch_openreg/torch_openreg/__init__.py @@ -1,4 +1,5 @@ import torch + import torch_openreg._C # type: ignore[misc] import torch_openreg.openreg diff --git a/test/cpp_extensions/open_registration_extension/torch_openreg/torch_openreg/openreg/__init__.py b/test/cpp_extensions/open_registration_extension/torch_openreg/torch_openreg/openreg/__init__.py index 177468b8f41b..6757fc669c20 100644 --- a/test/cpp_extensions/open_registration_extension/torch_openreg/torch_openreg/openreg/__init__.py +++ b/test/cpp_extensions/open_registration_extension/torch_openreg/torch_openreg/openreg/__init__.py @@ -1,4 +1,5 @@ import torch + import torch_openreg._C # type: ignore[misc] diff --git a/test/cpp_extensions/open_registration_extension/torch_openreg/torch_openreg/openreg/random.py b/test/cpp_extensions/open_registration_extension/torch_openreg/torch_openreg/openreg/random.py index 5202145a5552..6817bd7962b0 100644 --- a/test/cpp_extensions/open_registration_extension/torch_openreg/torch_openreg/openreg/random.py +++ b/test/cpp_extensions/open_registration_extension/torch_openreg/torch_openreg/openreg/random.py @@ -1,4 +1,5 @@ import torch + import torch_openreg._C # type: ignore[misc] from . import _lazy_init, current_device, device_count