Skip to content

Commit b887e58

Browse files
authored
Merge pull request #2960 from ilyasher/release/8.6.1-github
Fix python bindings build and README
2 parents a25ca8b + 25e2139 commit b887e58

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

python/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ endif()
4545

4646
# -------- PATHS --------
4747
message(STATUS "EXT_PATH: ${EXT_PATH}")
48-
message(STATUS "TENSORRT_BUILD: ${TENSORRT_BUILD}")
48+
message(STATUS "TENSORRT_LIBPATH: ${TENSORRT_LIBPATH}")
4949
message(STATUS "CMAKE_BINARY_DIR: ${CMAKE_BINARY_DIR}")
5050
message(STATUS "CUDA_ROOT: ${CUDA_ROOT}")
5151
message(STATUS "CUDA_INCLUDE_DIRS: ${CUDA_INCLUDE_DIRS}")
@@ -111,7 +111,7 @@ message(STATUS "PY_CONFIG_INCLUDE: ${PY_CONFIG_INCLUDE}")
111111
# -------- GLOBAL COMPILE OPTIONS --------
112112

113113
include_directories(${TENSORRT_ROOT}/include ${PROJECT_SOURCE_DIR}/include ${CUDA_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/docstrings ${ONNX_INC_DIR} ${PYBIND11_DIR})
114-
link_directories(${TENSORRT_BUILD})
114+
link_directories(${TENSORRT_LIBPATH})
115115

116116
if (MSVC)
117117
message(STATUS "include_dirs: ${MSVC_COMPILER_DIR}/include ${MSVC_COMPILER_DIR}/../ucrt/include ${NV_WDKSDK_INC}/um ${NV_WDKSDK_INC}/shared")

python/README.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,36 @@ git clone https://github.com/pybind/pybind11.git
1919
1. Get the source code from the official [python sources](https://www.python.org/downloads/source/)
2020
2. Copy the contents of the `Include/` directory into `$EXT_PATH/pythonX.Y/include/` directory.
2121

22+
Example: Python 3.9
23+
```bash
24+
wget https://www.python.org/ftp/python/3.9.16/Python-3.9.16.tgz
25+
tar -xvf Python-3.9.16.tgz
26+
mkdir -p $EXT_PATH/python3.9
27+
cp -r Python-3.9.16/Include/ $EXT_PATH/python3.9/include
28+
```
29+
2230
#### Add PyConfig.h
2331

2432
1. Download the deb package for the desired platform from [here](https://packages.debian.org/search?searchon=contents&keywords=pyconfig.h&mode=path&suite=unstable&arch=any).
25-
Typical plaforms include `x86_64` (`amd64`), `aarch64` (`arm64`), and `ppc64le` (`ppc64el`)
33+
Typical plaforms include `x86_64` (`amd64`), `aarch64` (`arm64`), and `ppc64le` (`ppc64el`).
34+
For older versions of Python, you may need to select a different suite.
2635
2. Unpack the debian with `ar x <libpython...>.deb`
2736
3. Unpack the contained `data.tar.xz` with `tar -xvf`
28-
4. Copy the `./usr/include/<platform>/` directory into the `$$EXT_PATH/pythonX.Y/include/` directory here.
29-
It should only contain a single file - `pyconfig.h`
37+
4. Find `pyconfig.h` in the `./usr/include/<platform>/pythonX.Y/` directory and copy it into `$EXT_PATH/pythonX.Y/include/`.
3038

3139

3240
### Build Python bindings
3341

3442
Use `build.sh` to generate the installable wheels for intended python version and target architecture.
3543

36-
Example: for python 3.8 `x86_64` wheel,
44+
Example: for Python 3.9 `x86_64` wheel,
3745
```bash
3846
cd $TRT_OSSPATH/python
39-
PYTHON_MAJOR_VERSION=3 PYTHON_MINOR_VERSION=8 TARGET_ARCHITECTURE=x86_64 ./build.sh
47+
TENSORRT_MODULE=tensorrt PYTHON_MAJOR_VERSION=3 PYTHON_MINOR_VERSION=9 TARGET_ARCHITECTURE=x86_64 ./build.sh
4048
```
4149

4250
### Install the python wheel
4351

4452
```bash
45-
python3 -m pip install build/dist/tensorrt-*.whl
53+
python3 -m pip install ./build/bindings_wheel/dist/tensorrt-*.whl
4654
```

python/build.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ cmake .. -DCMAKE_BUILD_TYPE=Release \
3535
-DEXT_PATH=${EXT_PATH} \
3636
-DCUDA_INCLUDE_DIRS=${CUDA_ROOT}/include \
3737
-DTENSORRT_ROOT=${ROOT_PATH} \
38-
-DTENSORRT_BUILD=${ROOT_PATH}/build/
38+
-DTENSORRT_MODULE=${TENSORRT_MODULE} \
39+
-DTENSORRT_LIBPATH=${TRT_LIBPATH}
3940
make -j12
4041

4142
# Generate wheel
@@ -52,13 +53,19 @@ expand_vars_cp () {
5253
test -f ${1} || (echo "ERROR: File: ${1} does not exist!" && exit 1); \
5354
sed -e "s|\#\#TENSORRT_VERSION\#\#|${TRT_VERSION}|g" \
5455
-e "s|\#\#TENSORRT_MAJMINPATCH\#\#|${TRT_MAJMINPATCH}|g" \
56+
-e "s|\#\#TENSORRT_PYTHON_VERSION\#\#|${TRT_MAJMINPATCH}|g" \
57+
-e "s|\#\#TENSORRT_MODULE\#\#|${TENSORRT_MODULE}|g" \
5558
${1} > ${2}
5659
}
5760

5861
pushd ${ROOT_PATH}/python/packaging
5962
for dir in $(find . -type d); do mkdir -p ${WHEEL_OUTPUT_DIR}/$dir; done
6063
for file in $(find . -type f); do expand_vars_cp $file ${WHEEL_OUTPUT_DIR}/${file}; done
6164
popd
65+
cp tensorrt/tensorrt.so bindings_wheel/tensorrt/tensorrt.so
66+
67+
pushd ${WHEEL_OUTPUT_DIR}/bindings_wheel
68+
6269
python3 setup.py -q bdist_wheel --python-tag=cp${PYTHON_MAJOR_VERSION}${PYTHON_MINOR_VERSION} --plat-name=linux_${TARGET}
6370

6471
popd

0 commit comments

Comments
 (0)