Skip to content

Commit 4185e93

Browse files
Maintain separate extension_cpp and extension_cpp_stable
1 parent 0ec4969 commit 4185e93

File tree

18 files changed

+567
-64
lines changed

18 files changed

+567
-64
lines changed

.github/scripts/setup-env.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,23 @@ echo '::group::Install third party dependencies prior to extension-cpp install'
9393
# - It happily pulls in pre-releases, which can lead to more problems down the line.
9494
# `pip` does not unless explicitly told to do so.
9595
# Thus, we use `easy_install` to extract the third-party dependencies here and install them upfront with `pip`.
96+
pushd extension_cpp
9697
python setup.py egg_info
9798
# The requires.txt cannot be used with `pip install -r` directly. The requirements are listed at the top and the
9899
# optional dependencies come in non-standard syntax after a blank line. Thus, we just extract the header.
99100
sed -e '/^$/,$d' *.egg-info/requires.txt | tee requirements.txt
100101
pip install --progress-bar=off -r requirements.txt
101102
echo '::endgroup::'
102103

103-
echo '::group::Install extension-cpp'
104-
python setup.py develop
104+
echo '::group::Install extension_cpp (standard ATen API)'
105+
pip install -e . --no-build-isolation
106+
popd
107+
echo '::endgroup::'
108+
109+
echo '::group::Install extension_cpp_stable (stable ABI)'
110+
pushd extension_cpp_stable
111+
pip install -e . --no-build-isolation
112+
popd
105113
echo '::endgroup::'
106114

107115
echo '::group::Collect environment information'

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- python-version: 3.13
2020
runner: linux.g5.4xlarge.nvidia.gpu
2121
gpu-arch-type: cuda
22-
gpu-arch-version: "12.4"
22+
gpu-arch-version: "12.9"
2323
fail-fast: false
2424
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
2525
permissions:

README.md

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,42 @@
11
# C++/CUDA Extensions in PyTorch
22

3-
An example of writing a C++/CUDA extension for PyTorch. See
4-
[here](https://pytorch.org/tutorials/advanced/cpp_custom_ops.html) for the accompanying tutorial.
5-
This repo demonstrates how to write an example `extension_cpp.ops.mymuladd`
6-
custom op that has both custom CPU and CUDA kernels.
3+
This repository contains two example C++/CUDA extensions for PyTorch:
74

8-
The examples in this repo work with PyTorch 2.4+.
5+
1. **extension_cpp** - Uses the standard ATen/LibTorch API
6+
2. **extension_cpp_stable** - Uses the [LibTorch Stable ABI](https://pytorch.org/docs/main/notes/libtorch_stable_abi.html)
97

10-
To build:
8+
Both extensions demonstrate how to write an example `mymuladd` custom op that has both
9+
custom CPU and CUDA kernels.
10+
11+
## extension_cpp (Standard ATen API)
12+
13+
Uses the full ATen/LibTorch API. This is the traditional way of writing PyTorch extensions.
14+
See [this tutorial](https://pytorch.org/tutorials/advanced/cpp_custom_ops.html) for more details.
15+
16+
## extension_cpp_stable (Stable ABI)
17+
18+
Uses the LibTorch Stable ABI to ensure that the extension built can be run with any version
19+
of PyTorch >= 2.10.0, without needing to recompile for each PyTorch version.
20+
21+
The `extension_cpp_stable` examples require PyTorch 2.10+.
22+
23+
## Building
24+
25+
To build extension_cpp (standard API):
26+
```
27+
cd extension_cpp
28+
pip install --no-build-isolation -e .
1129
```
30+
31+
To build extension_cpp_stable (stable ABI):
32+
```
33+
cd extension_cpp_stable
1234
pip install --no-build-isolation -e .
1335
```
1436

15-
To test:
37+
## Testing
38+
39+
To test both extensions:
1640
```
1741
python test/test_extension.py
1842
```
File renamed without changes.
File renamed without changes.

setup.py renamed to extension_cpp/setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ def get_extensions():
7979
ext_modules=get_extensions(),
8080
install_requires=["torch"],
8181
description="Example of PyTorch C++ and CUDA extensions",
82-
long_description=open("README.md").read(),
82+
long_description=open(
83+
os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "README.md")
84+
).read(),
8385
long_description_content_type="text/markdown",
8486
url="https://github.com/pytorch/extension-cpp",
8587
cmdclass={"build_ext": BuildExtension},

0 commit comments

Comments
 (0)