Skip to content

Commit a5f774b

Browse files
committed
ENH: Add TBB support to Linux wheels
1 parent 37645e7 commit a5f774b

File tree

5 files changed

+52
-8
lines changed

5 files changed

+52
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ develop-eggs
4242
lib
4343
lib64
4444
MANIFEST
45+
oneTBB-prefix/
4546

4647
# Installer logs
4748
pip-log.txt

CMakeLists.txt

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.3)
1+
cmake_minimum_required(VERSION 3.16.3 FATAL_ERROR)
22

33
project(ITKPythonPackage CXX)
44

@@ -14,6 +14,8 @@ if(NOT DEFINED ITKPythonPackage_WHEEL_NAME)
1414
endif()
1515
message(STATUS "SuperBuild - ITKPythonPackage_WHEEL_NAME:${ITKPythonPackage_WHEEL_NAME}")
1616

17+
option(ITKPythonPackage_USE_TBB "Build and use oneTBB in the ITK python package" ON)
18+
1719
if(ITKPythonPackage_SUPERBUILD)
1820

1921
#-----------------------------------------------------------------------------
@@ -44,8 +46,8 @@ if(ITKPythonPackage_SUPERBUILD)
4446
# ITK_SOURCE_DIR: Path to an existing source directory
4547
#
4648

47-
option ( ITKPythonPackage_BUILD_PYTHON "Build ITK python module" ON )
48-
mark_as_advanced( ITKPythonPackage_BUILD_PYTHON )
49+
option(ITKPythonPackage_BUILD_PYTHON "Build ITK python module" ON)
50+
mark_as_advanced(ITKPythonPackage_BUILD_PYTHON)
4951

5052
if(CMAKE_OSX_DEPLOYMENT_TARGET)
5153
list(APPEND ep_common_cmake_cache_args
@@ -89,6 +91,39 @@ if(ITKPythonPackage_SUPERBUILD)
8991
message(FATAL_ERROR "ITK_SOURCE_DIR variable is defined but corresponds to nonexistent directory")
9092
endif()
9193

94+
set(tbb_args )
95+
if(ITKPythonPackage_USE_TBB)
96+
ExternalProject_add(oneTBB
97+
GIT_REPOSITORY "https://github.com/oneapi-src/oneTBB.git"
98+
GIT_TAG "v2021.3.0"
99+
CMAKE_ARGS
100+
-DTBB_TEST:BOOL=OFF
101+
-DCMAKE_BUILD_TYPE:STRING=Release
102+
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_BINARY_DIR}/../oneTBB-prefix
103+
${ep_common_cmake_cache_args}
104+
USES_TERMINAL_DOWNLOAD 1
105+
USES_TERMINAL_UPDATE 1
106+
USES_TERMINAL_CONFIGURE 1
107+
USES_TERMINAL_BUILD 1
108+
)
109+
if(ITK_SOURCE_DIR)
110+
set(TBB_DIR "${ITK_SOURCE_DIR}/../oneTBB-prefix/lib64/cmake/TBB")
111+
else()
112+
set(TBB_DIR "${CMAKE_BINARY_DIR}/../oneTBB-prefix/lib64/cmake/TBB")
113+
endif()
114+
set(tbb_args
115+
-DModule_ITKTBB:BOOL=ON
116+
-DTBB_DIR:PATH=${TBB_DIR}
117+
)
118+
message(STATUS "SuperBuild - TBB: Enabled")
119+
message(STATUS "SuperBuild - TBB_DIR: ${TBB_DIR}")
120+
endif()
121+
set(tbb_depends "")
122+
if(ITKPythonPackage_USE_TBB)
123+
set(tbb_depends oneTBB)
124+
endif()
125+
126+
92127
if(NOT DEFINED ITK_SOURCE_DIR)
93128

94129
set(ITK_SOURCE_DIR ${CMAKE_BINARY_DIR}/ITK)
@@ -101,6 +136,7 @@ if(ITKPythonPackage_SUPERBUILD)
101136
CONFIGURE_COMMAND ""
102137
BUILD_COMMAND ""
103138
INSTALL_COMMAND ""
139+
DEPENDS ${tbb_depends}
104140
)
105141
set(proj_status "")
106142

@@ -234,6 +270,7 @@ if(ITKPythonPackage_SUPERBUILD)
234270
-DPython3_EXECUTABLE:FILEPATH=${Python3_EXECUTABLE}
235271
${ep_common_cmake_cache_args}
236272
${ep_itk_cmake_cache_args}
273+
${tbb_args}
237274
USES_TERMINAL_DOWNLOAD 1
238275
USES_TERMINAL_UPDATE 1
239276
USES_TERMINAL_CONFIGURE 1

scripts/dockcross-manylinux-build-module-wheels.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# scripts/dockcross-manylinux-build-module-wheels.sh cp39
1010

1111
# Generate dockcross scripts
12-
docker run --rm dockcross/manylinux2014-x64:20201015-96d8741 > /tmp/dockcross-manylinux-x64
12+
docker run --rm dockcross/manylinux2014-x64:20210823-d7b98b4 > /tmp/dockcross-manylinux-x64
1313
chmod u+x /tmp/dockcross-manylinux-x64
1414

1515
script_dir=$(cd $(dirname $0) || exit 1; pwd)

scripts/dockcross-manylinux-build-wheels.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
# Versions can be restricted by passing them in as arguments to the script
66
# For example,
77
#
8-
# scripts/dockcross-manylinux-build-wheels.sh cp35
8+
# scripts/dockcross-manylinux-build-wheels.sh cp39
99

1010
# Generate dockcross scripts
11-
docker run --rm dockcross/manylinux2014-x64:20201015-96d8741 > /tmp/dockcross-manylinux-x64
11+
docker run --rm dockcross/manylinux2014-x64:20210823-d7b98b4 > /tmp/dockcross-manylinux-x64
1212
chmod u+x /tmp/dockcross-manylinux-x64
1313

1414
script_dir=$(cd $(dirname $0) || exit 1; pwd)

scripts/internal/manylinux-build-wheels.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ pushd /work/ITK-source > /dev/null 2>&1
1818
cmake -DITKPythonPackage_BUILD_PYTHON:PATH=0 -G Ninja ../
1919
ninja
2020
popd > /dev/null 2>&1
21+
tbb_dir=/work/oneTBB-prefix/lib64/cmake/TBB
22+
# So auditwheel can find the libs
23+
export LD_LIBRARY_PATH=/work/oneTBB-prefix/lib64
2124

2225
SINGLE_WHEEL=0
2326

@@ -67,6 +70,8 @@ for PYBIN in "${PYBINARIES[@]}"; do
6770
-DCMAKE_BUILD_TYPE:STRING="${build_type}" \
6871
-DPython3_EXECUTABLE:FILEPATH=${Python3_EXECUTABLE} \
6972
-DPython3_INCLUDE_DIR:PATH=${Python3_INCLUDE_DIR} \
73+
-DModule_ITKTBB:BOOL=ON \
74+
-DTBB_DIR:PATH=${tbb_dir} \
7075
-DITK_WRAP_DOC:BOOL=ON
7176
# Cleanup
7277
${PYBIN}/python setup.py clean
@@ -102,6 +107,8 @@ for PYBIN in "${PYBINARIES[@]}"; do
102107
-DITK_LEGACY_SILENT:BOOL=ON \
103108
-DITK_WRAP_PYTHON:BOOL=ON \
104109
-DITK_WRAP_DOC:BOOL=ON \
110+
-DModule_ITKTBB:BOOL=ON \
111+
-DTBB_DIR:PATH=${tbb_dir} \
105112
-G Ninja \
106113
${source_path} \
107114
&& ninja \
@@ -143,8 +150,7 @@ done
143150

144151
if test "${ARCH}" == "x64"; then
145152
/opt/python/cp37-cp37m/bin/pip3 install auditwheel wheel
146-
# Since there are no external shared libraries to bundle into the wheels
147-
# this step will fixup the wheel switching from 'linux' to 'manylinux2014' tag
153+
# This step will fixup the wheel switching from 'linux' to 'manylinux2014' tag
148154
for whl in dist/itk_*linux_$(uname -p).whl; do
149155
/opt/python/cp37-cp37m/bin/auditwheel repair --plat manylinux2014_x86_64 ${whl} -w /work/dist/
150156
rm ${whl}

0 commit comments

Comments
 (0)