Skip to content

Commit

Permalink
Build with libomp 11.1 and package it in the macOS wheel
Browse files Browse the repository at this point in the history
  • Loading branch information
ssheorey committed Nov 12, 2022
1 parent fc89656 commit 1d6feb8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
30 changes: 19 additions & 11 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ jobs:
- name: Install dependencies
run: |
brew install ccache pkg-config
brew link --force libomp # needed for cmake to find OpenMP
# Install libomp 11.1.0
# https://github.com/microsoft/LightGBM/issues/4229
brew unlink libomp
wget https://raw.githubusercontent.com/Homebrew/homebrew-core/fb8323f2b170bd4ae97e1bac9bf3e2983af3fdb0/Formula/libomp.rb
brew install--formula libomp.rb
ccache -M 2G # See .github/workflows/readme.md for ccache strategy.
- name: Config and build
run: |
Expand Down Expand Up @@ -118,15 +122,15 @@ jobs:
# https://git.luolix.topmunity/t/how-to-conditionally-include-exclude-items-in-matrix-eg-based-on-branch/16853/6
matrix:
python_version: ['3.7', '3.8', '3.9', '3.10']
# is_master:
# - ${{ github.ref == 'refs/heads/master' }}
# exclude:
# - is_master: false
# python_version: '3.7'
# - is_master: false
# python_version: '3.8'
# - is_master: false
# python_version: '3.9'
is_master:
- ${{ github.ref == 'refs/heads/master' }}
exclude:
- is_master: false
python_version: '3.7'
- is_master: false
python_version: '3.8'
- is_master: false
python_version: '3.9'

env:
BUILD_CUDA_MODULE: OFF
Expand Down Expand Up @@ -170,8 +174,12 @@ jobs:
cmake --version
source util/ci_utils.sh
install_python_dependencies
# Install libomp 11.1.0
# https://github.com/microsoft/LightGBM/issues/4229
brew install ccache
brew link --force libomp # needed for cmake to find OpenMP
brew unlink libomp
wget https://raw.githubusercontent.com/Homebrew/homebrew-core/fb8323f2b170bd4ae97e1bac9bf3e2983af3fdb0/Formula/libomp.rb
brew install --formula libomp.rb
ccache -M 2G # See .github/workflows/readme.md for ccache strategy.
- name: Config and build wheel
Expand Down
20 changes: 17 additions & 3 deletions cpp/pybind/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,23 @@ if (BUILD_GUI AND CMAKE_SYSTEM_NAME STREQUAL "Linux")
list(APPEND PYTHON_EXTRA_LIBRARIES ${CPP_LIBRARY}.1 ${CPPABI_LIBRARY}
${MESA_CPU_GL_LIBRARY})
endif()
if (WITH_OPENMP AND APPLE)
# Package libomp v11.1.0, if it is not installed. Later version cause crash on
# x86_64 if PyTorch is already imported.
# https://github.com/microsoft/LightGBM/issues/4229
list(APPEND PYTHON_EXTRA_LIBRARIES ${OpenMP_libomp_LIBRARY})
file(GENERATE OUTPUT update_pybind_libomp.sh
CONTENT [=[libomp_library=$(dyld_info -dependents "$<TARGET_FILE:pybind>" |
grep libomp | tr -d '[:space:]')
install_name_tool -change $libomp_library @loader_path/../libomp.dylib \
"$<TARGET_FILE:pybind>"]=])
add_custom_command(TARGET pybind POST_BUILD
COMMAND bash update_pybind_libomp.sh
COMMENT "Updating pybind to use packaged libomp")
endif()

# Use `make python-package` to create the python package in the build directory
# The python package will be created at PYTHON_PACKAGE_DIR. It contains:
# The python package will be created at PYTHON_PACKAGE_DST_DIR. It contains:
# 1) Pure-python code and misc files, copied from python/package
# 2) The compiled python-C++ module, i.e. open3d.so (or the equivalents)
# 3) Configured files and supporting files
Expand All @@ -84,8 +98,8 @@ set(GENERATED_OUTPUTS "")

# add additional optional compiled modules
if (BUILD_TENSORFLOW_OPS)
list( APPEND COMPILED_MODULE_PATH_LIST $<TARGET_FILE:open3d_tf_ops> )
add_custom_command( OUTPUT "${CMAKE_BINARY_DIR}/lib/ml/tf/python/ops/ops.py"
list(APPEND COMPILED_MODULE_PATH_LIST $<TARGET_FILE:open3d_tf_ops> )
add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/lib/ml/tf/python/ops/ops.py"
COMMAND ${Python3_EXECUTABLE} generate_tf_ops_wrapper.py --input "${PYTHON_PACKAGE_SRC_DIR}/open3d/ml/tf/python/ops/ops.py.in" --output "${CMAKE_BINARY_DIR}/lib/ml/tf/python/ops/ops.py" --lib $<TARGET_FILE:open3d_tf_ops>
DEPENDS open3d_tf_ops
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
Expand Down

0 comments on commit 1d6feb8

Please sign in to comment.