How to package project with pytorch CUDA/CPP extension through setuptools

Hello. I want to package my project and upload to pypi.

My project contains some CUDA/CPP files, and I complie it as the tutorial. It works well.

In my project, I run setup.py for roi_align and then run another setup.py for rod_align. The files are listed as follows. Note that I used PyTorch to confirm whether GPU is available, then choose to build CPP extension or CUDA extension.

├── autocrop
│   ├── __init__.py
│   ├── cropper.py
│   ├── model
│   │   ├── __init__.py
│   │   ├── cropping_model.py
│   │   ├── moblienetv2.py
│   │   ├── rod_align
│   │   │   ├── __init__.py
│   │   │   ├── build
│   │   │   ├── functions
│   │   │   │   ├── __init__.py
│   │   │   │   └── rod_align.py
│   │   │   ├── modules
│   │   │   │   ├── __init__.py
│   │   │   │   └── rod_align.py
│   │   │   ├── setup.py # for rod_align
│   │   │   └── src
│   │   │       ├── rod_align.cpp
│   │   │       ├── rod_align.h
│   │   │       ├── rod_align_cuda.cpp
│   │   │       ├── rod_align_cuda.h
│   │   │       ├── rod_align_kernel.cu
│   │   │       └── rod_align_kernel.h
│   │   ├── roi_align
│   │   │   ├── __init__.py
│   │   │   ├── functions
│   │   │   │   ├── __init__.py
│   │   │   │   └── roi_align.py
│   │   │   ├── modules
│   │   │   │   ├── __init__.py
│   │   │   │   └── roi_align.py
│   │   │   ├── setup.py # for roi_align
│   │   │   └── src
│   │   │       ├── roi_align.cpp
│   │   │       ├── roi_align.h
│   │   │       ├── roi_align_cuda.cpp
│   │   │       ├── roi_align_cuda.h
│   │   │       ├── roi_align_kernel.cu
│   │   │       └── roi_align_kernel.h
│   │   └── shufflenetv2.py
│   └── utils.py
├── demo.py
├── imgs
│   └── demo.jpg
└── setup.py # This is the file I want to write, run once to package all the project

Now I want to package my whole project. I am confused about how to write the setup file. (just run once).

Can I copy the code setup(xxxx) from roi and rod setup.py to the final setup.py and write another setup(xxxx) after them, just like:

from setuptools import setup
setup(roi)
setup(rod)
setuptools.setup(
    name="autocrop",
    python_requires='>=3.6',
    install_requires=[
        "torch>=1.1",
        "torchvision>=0.3.0",
        "numpy",
    ]
xxxxxxx
)

1 Like

Hey @ptrblck, do you know who can answer packaging questions?

@seemethere might be the right person.
Also, Nikita Shulda, but I cannot find his user name (and unsure, if he’s registered here).

1 Like