Skip to content

Commit

Permalink
Modernize extension-cpp; refactor code
Browse files Browse the repository at this point in the history
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: a31d059ed3f83118513791e712a394713e07a96b
Pull Request resolved: #86
  • Loading branch information
zou3519 committed Apr 24, 2024
1 parent 1031028 commit ec66d01
Show file tree
Hide file tree
Showing 24 changed files with 334 additions and 582 deletions.
24 changes: 16 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
# C++/CUDA Extensions in PyTorch

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

There are a few "sights" you can metaphorically visit in this repository:
To build:
```
pip install .
```

- Inspect the C++ and CUDA extensions in the `cpp/` and `cuda/` folders,
- Build C++ and/or CUDA extensions by going into the `cpp/` or `cuda/` folder and executing `python setup.py install`,
- 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,
- Benchmark Python vs. C++ vs. CUDA by running `python benchmark.py {py, cpp, cuda} [--cuda]`,
- Run gradient checks on the code by running `python grad_check.py {py, cpp, cuda} [--cuda]`.
- Run output checks on the code by running `python check.py {forward, backward} [--cuda]`.
To test:
```
python test/test_extension.py
```

To benchmark Python vs. C++ vs. CUDA:
```
python test/benchmark.py
```

## Authors

Expand Down
73 changes: 0 additions & 73 deletions benchmark.py

This file was deleted.

107 changes: 0 additions & 107 deletions check.py

This file was deleted.

Empty file removed cpp/__init__.py
Empty file.
3 changes: 0 additions & 3 deletions cpp/jit.py

This file was deleted.

44 changes: 0 additions & 44 deletions cpp/lltm.py

This file was deleted.

11 changes: 0 additions & 11 deletions cpp/setup.py

This file was deleted.

Empty file removed cuda/__init__.py
Empty file.
4 changes: 0 additions & 4 deletions cuda/jit.py

This file was deleted.

45 changes: 0 additions & 45 deletions cuda/lltm.py

This file was deleted.

Loading

0 comments on commit ec66d01

Please sign in to comment.