Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build with libomp 11.1 and package it in the macOS wheel #5679

Merged
merged 3 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .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 @@ -170,7 +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 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
27 changes: 24 additions & 3 deletions cpp/pybind/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,30 @@ 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 AND NOT BUILD_SHARED_LIBS)
# Package libomp v11.1.0, if it is not installed. Later version cause crash on
# x86_64 if PyTorch is already imported. Case of shared libopen3d.dylib is not
# handled.
# https://github.com/microsoft/LightGBM/issues/4229
list(APPEND PYTHON_EXTRA_LIBRARIES ${OpenMP_libomp_LIBRARY})
execute_process(COMMAND brew list --versions libomp
COMMAND cut "-d\ " -f2
OUTPUT_VARIABLE libomp_ver OUTPUT_STRIP_TRAILING_WHITESPACE)
if(libomp_ver VERSION_GREATER_EQUAL 12.0.0)
message(SEND_ERROR "libomp ${libomp_ver} found, which can lead to interoperability problems with other Python libraries using libomp. Please use libomp v11.1 to build Open3D.")
endif()
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 +105,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
10 changes: 0 additions & 10 deletions docs/getting_started.in.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,6 @@ Pip (PyPI)

``pip install -U pip>=20.3``

.. note::
In MacOS, please install ``libomp`` (OpenMP) on your system before installing
Open3D.

``brew install libomp``

We do not package OpenMP runtime with Open3D since a system OpenMP runtime
ensures more reliable interoperation with other Python packages (e.g.
PyTorch) that also use OpenMP.

.. note::
In general, we recommend using a
`virtual environment <https://docs.python-guide.org/dev/virtualenvs/>`_
Expand Down