Skip to content

joflucki/python-interop

Repository files navigation

Python Interoperability - How to leverage C++ and CUDA 🔌

This repository contains a set of examples on how to achieve Python interoperability with C++ and CUDA, for basic operations, or PyTorch tensor operations.

Examples

1. Vector Addition with C++

Example code showcasing how to perform vector addition using Pybind11, a lightweight header-only library that exposes C++ functions to Python.

2. Tensor Addition with C++

Example code demonstrating how to perform tensor addition using PyTorch, a popular deep learning framework, and its C++ API for interoperability with Python.

3. CUDA Tensor Addition

Example code illustrating how to perform vector addition using CUDA (NVIDIA's parallel computing platform) with PyTorch's C++ API for GPU acceleration.

4. CUDA Vector Addition

Example code showcasing how to perform vector addition using CUDA with native data structures (without PyTorch).

5. C++ integration with PyTorch (LLTM)

Example code showcasing how to integrate C++ code in a PyTorch machine learning context. This is taken from Custom C++ and CUDA Extensions from the PyTorch documentation.

Usage

Each example directory contains the necessary source files and a setup script (setup.py) for compilation if applicable. Each folder contains a use.py or main.py file that can be used as the main process to run the example.

Requirements

  • Python 3 (Tested on Python 3.10)
  • Pybind11 (for Pybind11 examples)
  • PyTorch (for PyTorch examples)
  • CUDA Toolkit (for CUDA examples)
  • C++ compiler (e.g., g++) and development tools

License

This project is released under the MIT license.

About

A set of examples of Python and Pytorch interoperability with C++ and CUDA

Topics

Resources

License

Stars

Watchers

Forks