Skip to content

Commit ec66d01

Browse files
committed
Modernize extension-cpp; refactor code
This PR: - creates a single unified build for extension-cpp (instead of having separate cpu/cuda setup.pys). - Updates the build system to use pyproject.toml (instead of only setup.py) - Uses TORCH_LIBRARY to bind operators (instead of using PyBind) There will be more future work to add improvements (e.g. torch.compile support) and also fix up the corresponding C++ extensions tutorial. Test Plan: - Refactored all of the tests under test/ ghstack-source-id: a31d059 Pull Request resolved: #86
1 parent 1031028 commit ec66d01

24 files changed

+334
-582
lines changed

README.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
# C++/CUDA Extensions in PyTorch
22

3-
An example of writing a C++ extension for PyTorch. See
3+
An example of writing a C++/CUDA extension for PyTorch. See
44
[here](http://pytorch.org/tutorials/advanced/cpp_extension.html) for the accompanying tutorial.
5+
This repo demonstrates how to write an example `extension_cpp.ops.lltm`
6+
custom op that has both custom CPU and CUDA kernels.
57

6-
There are a few "sights" you can metaphorically visit in this repository:
8+
To build:
9+
```
10+
pip install .
11+
```
712

8-
- Inspect the C++ and CUDA extensions in the `cpp/` and `cuda/` folders,
9-
- Build C++ and/or CUDA extensions by going into the `cpp/` or `cuda/` folder and executing `python setup.py install`,
10-
- JIT-compile C++ and/or CUDA extensions by going into the `cpp/` or `cuda/` folder and calling `python jit.py`, which will JIT-compile the extension and load it,
11-
- Benchmark Python vs. C++ vs. CUDA by running `python benchmark.py {py, cpp, cuda} [--cuda]`,
12-
- Run gradient checks on the code by running `python grad_check.py {py, cpp, cuda} [--cuda]`.
13-
- Run output checks on the code by running `python check.py {forward, backward} [--cuda]`.
13+
To test:
14+
```
15+
python test/test_extension.py
16+
```
17+
18+
To benchmark Python vs. C++ vs. CUDA:
19+
```
20+
python test/benchmark.py
21+
```
1422

1523
## Authors
1624

benchmark.py

Lines changed: 0 additions & 73 deletions
This file was deleted.

check.py

Lines changed: 0 additions & 107 deletions
This file was deleted.

cpp/__init__.py

Whitespace-only changes.

cpp/jit.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

cpp/lltm.py

Lines changed: 0 additions & 44 deletions
This file was deleted.

cpp/setup.py

Lines changed: 0 additions & 11 deletions
This file was deleted.

cuda/__init__.py

Whitespace-only changes.

cuda/jit.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

cuda/lltm.py

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)