From 336509be44a6b04782ed549b509899f1c49ba895 Mon Sep 17 00:00:00 2001 From: Yixing Lao Date: Sun, 22 May 2022 10:29:00 -0700 Subject: [PATCH] initial SYCL build system and examples (#5081) --- .github/workflows/macos.yml | 12 +- .github/workflows/ubuntu-sycl.yml | 57 +++ .github/workflows/ubuntu.yml | 32 +- .github/workflows/windows.yml | 30 +- 3rdparty/README_SYCL.md | 88 ++++ 3rdparty/assimp/assimp.cmake | 11 +- .../benchmark/MakeAvailable/CMakeLists.txt | 5 + 3rdparty/embree/embree.cmake | 6 +- 3rdparty/find_dependencies.cmake | 337 ++++++++----- CMakeLists.txt | 42 +- cmake/Open3DLink3rdpartyLibraries.cmake | 12 + cmake/Open3DMakeHardeningFlags.cmake | 10 + cmake/Open3DSYCLTargetSources.cmake | 41 ++ cmake/Open3DSetGlobalProperties.cmake | 10 + cpp/open3d/core/CMakeLists.txt | 49 +- cpp/open3d/core/SYCLUtils.cpp | 93 ++++ cpp/open3d/core/SYCLUtils.h | 37 ++ cpp/open3d/core/TensorFunction.h | 2 + cpp/open3d/core/linalg/LinalgHeadersCPU.h | 3 - .../registration/FastGlobalRegistration.cpp | 1 + cpp/open3d/utility/ParallelScan.h | 48 +- cpp/pybind/_build_config.py.in | 1 + cpp/pybind/core/CMakeLists.txt | 1 + cpp/pybind/core/core.cpp | 1 + cpp/pybind/core/core.h | 1 + cpp/pybind/core/sycl_utils.cpp | 37 ++ cpp/pybind/t/geometry/tensormap.cpp | 2 +- cpp/tests/core/CMakeLists.txt | 6 + cpp/tests/core/SYCLUtils.cpp | 45 ++ cpp/tests/core/TensorFunction.cpp | 1 + docker/Dockerfile.ci | 94 ++-- docker/Dockerfile.openblas | 16 +- docker/Dockerfile.wheel | 12 +- docker/docker_build.sh | 477 ++++++++++-------- docker/docker_test.sh | 117 +++-- examples/cpp/CMakeLists.txt | 1 + examples/cpp/SYCLDemo.cpp | 32 ++ python/test/conftest.py | 27 + python/test/core/test_sycl_utils.py | 39 ++ util/ci_utils.sh | 8 +- 40 files changed, 1310 insertions(+), 534 deletions(-) create mode 100644 .github/workflows/ubuntu-sycl.yml create mode 100644 3rdparty/README_SYCL.md create mode 100644 cmake/Open3DSYCLTargetSources.cmake create mode 100644 cpp/open3d/core/SYCLUtils.cpp create mode 100644 cpp/open3d/core/SYCLUtils.h create mode 100644 cpp/pybind/core/sycl_utils.cpp create mode 100644 cpp/tests/core/SYCLUtils.cpp create mode 100644 examples/cpp/SYCLDemo.cpp create mode 100644 python/test/conftest.py create mode 100644 python/test/core/test_sycl_utils.py diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 81d2e2b7e38..0439234ce87 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -31,7 +31,7 @@ jobs: matrix: CONFIG: [ON, OFF] env: - SHARED: ${{ matrix.CONFIG }} + BUILD_SHARED_LIBS: ${{ matrix.CONFIG }} BUILD_CUDA_MODULE: OFF BUILD_TENSORFLOW_OPS: ${{ matrix.CONFIG }} BUILD_PYTORCH_OPS: ${{ matrix.CONFIG }} @@ -68,7 +68,7 @@ jobs: DEVEL_PKG_NAME="$(basename package/open3d-devel-*.tar.xz)" echo "DEVEL_PKG_NAME=$DEVEL_PKG_NAME" >> $GITHUB_ENV - name: Build Open3D viewer app - if: ${{ env.SHARED == 'OFF' }} + if: ${{ env.BUILD_SHARED_LIBS == 'OFF' }} run: | PATH=/usr/local/var/homebrew/linked/ccache/libexec:$PATH pushd build @@ -78,7 +78,7 @@ jobs: ccache -s - name: Upload package - if: ${{ env.SHARED == 'ON' }} + if: ${{ env.BUILD_SHARED_LIBS == 'ON' }} uses: actions/upload-artifact@v2 with: name: open3d-devel-macosx @@ -86,7 +86,7 @@ jobs: if-no-files-found: error - name: GCloud CLI setup - if: ${{ github.ref == 'refs/heads/master' && env.SHARED == 'ON' }} + if: ${{ github.ref == 'refs/heads/master' && env.BUILD_SHARED_LIBS == 'ON' }} # https://github.com/GoogleCloudPlatform/github-actions/issues/100#issuecomment-650798308 uses: google-github-actions/setup-gcloud@v0.2.1 with: @@ -96,14 +96,14 @@ jobs: export_default_credentials: true - name: Upload package to GCS bucket - if: ${{ github.ref == 'refs/heads/master' && env.SHARED == 'ON' }} + if: ${{ github.ref == 'refs/heads/master' && env.BUILD_SHARED_LIBS == 'ON' }} run: | gsutil cp build/package/${{ env.DEVEL_PKG_NAME }} gs://open3d-releases-master/devel/ echo "Download devel package at: https://storage.googleapis.com/open3d-releases-master/devel/${{ env.DEVEL_PKG_NAME }}" - name: Upload Open3D viewer app uses: actions/upload-artifact@v2 - if: ${{ env.SHARED == 'OFF' }} + if: ${{ env.BUILD_SHARED_LIBS == 'OFF' }} with: name: open3d-app-macosx-10_15 path: build/bin/open3d-app-macosx-10_15.zip diff --git a/.github/workflows/ubuntu-sycl.yml b/.github/workflows/ubuntu-sycl.yml new file mode 100644 index 00000000000..13c330856a2 --- /dev/null +++ b/.github/workflows/ubuntu-sycl.yml @@ -0,0 +1,57 @@ +name: Ubuntu SYCL + +on: + push: + branches: + - master + pull_request: + types: [opened, reopened, synchronize] + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +env: + NPROC: 2 + GCE_CLI_GHA_VERSION: "302.0.0" + +jobs: + ubuntu-sycl: + runs-on: ubuntu-20.04 + strategy: + fail-fast: false + matrix: + BUILD_SHARED_LIBS: [ON, OFF] + steps: + - name: Checkout source code + uses: actions/checkout@v2 + - name: Maximize build space + run: | + source util/ci_utils.sh + maximize_ubuntu_github_actions_build_space + - name: Docker build + run: | + if [ "${{ matrix.BUILD_SHARED_LIBS }}" = "ON" ]; then + docker/docker_build.sh sycl-shared + else + docker/docker_build.sh sycl-static + fi + - name: Docker test + run: | + if [ "${{ matrix.BUILD_SHARED_LIBS }}" = "ON" ]; then + docker/docker_test.sh sycl-shared + else + docker/docker_test.sh sycl-static + fi + - name: GCloud CLI setup + if: ${{ github.ref == 'refs/heads/master' }} + uses: google-github-actions/setup-gcloud@v0.2.1 + with: + version: ${{ env.GCE_CLI_GHA_VERSION }} + service_account_key: ${{ secrets.GCE_SA_KEY_DOCS_CI }} + project_id: ${{ secrets.GCE_DOCS_PROJECT }} + export_default_credentials: true + - name: Upload ccache to GCS + if: ${{ github.ref == 'refs/heads/master' }} + run: | + gsutil cp ${GITHUB_WORKSPACE}/open3d-ci-sycl.tar.gz gs://open3d-ci-cache/ || true diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 96d7c5c049b..0a3fd66f6f8 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -27,13 +27,13 @@ jobs: strategy: fail-fast: false matrix: - SHARED: [ON, OFF] + BUILD_SHARED_LIBS: [ON, OFF] MLOPS: [ON, OFF] exclude: - - SHARED: OFF + - BUILD_SHARED_LIBS: OFF MLOPS: ON env: - SHARED: ${{ matrix.SHARED }} + BUILD_SHARED_LIBS: ${{ matrix.BUILD_SHARED_LIBS }} BUILD_CUDA_MODULE: OFF BUILD_TENSORFLOW_OPS: ${{ matrix.MLOPS }} BUILD_PYTORCH_OPS: ${{ matrix.MLOPS }} @@ -47,39 +47,39 @@ jobs: maximize_ubuntu_github_actions_build_space - name: Docker build run: | - if [ "${{ matrix.SHARED }}" = "OFF" ] && [ "${{ matrix.MLOPS }}" = "OFF" ]; then + if [ "${{ matrix.BUILD_SHARED_LIBS }}" = "OFF" ] && [ "${{ matrix.MLOPS }}" = "OFF" ]; then docker/docker_build.sh cpu-static - elif [ "${{ matrix.SHARED }}" = "ON" ] && [ "${{ matrix.MLOPS }}" = "OFF" ] && [ "${{ env.DEVELOPER_BUILD }}" = "ON" ]; then + elif [ "${{ matrix.BUILD_SHARED_LIBS }}" = "ON" ] && [ "${{ matrix.MLOPS }}" = "OFF" ] && [ "${{ env.DEVELOPER_BUILD }}" = "ON" ]; then docker/docker_build.sh cpu-shared - elif [ "${{ matrix.SHARED }}" = "ON" ] && [ "${{ matrix.MLOPS }}" = "OFF" ] && [ "${{ env.DEVELOPER_BUILD }}" = "OFF" ]; then + elif [ "${{ matrix.BUILD_SHARED_LIBS }}" = "ON" ] && [ "${{ matrix.MLOPS }}" = "OFF" ] && [ "${{ env.DEVELOPER_BUILD }}" = "OFF" ]; then docker/docker_build.sh cpu-shared-release - elif [ "${{ matrix.SHARED }}" = "ON" ] && [ "${{ matrix.MLOPS }}" = "ON" ] && [ "${{ env.DEVELOPER_BUILD }}" = "ON" ]; then + elif [ "${{ matrix.BUILD_SHARED_LIBS }}" = "ON" ] && [ "${{ matrix.MLOPS }}" = "ON" ] && [ "${{ env.DEVELOPER_BUILD }}" = "ON" ]; then docker/docker_build.sh cpu-shared-ml - elif [ "${{ matrix.SHARED }}" = "ON" ] && [ "${{ matrix.MLOPS }}" = "ON" ] && [ "${{ env.DEVELOPER_BUILD }}" = "OFF" ]; then + elif [ "${{ matrix.BUILD_SHARED_LIBS }}" = "ON" ] && [ "${{ matrix.MLOPS }}" = "ON" ] && [ "${{ env.DEVELOPER_BUILD }}" = "OFF" ]; then docker/docker_build.sh cpu-shared-ml-release fi - name: Docker test run: | - if [ "${{ matrix.SHARED }}" = "OFF" ] && [ "${{ matrix.MLOPS }}" = "OFF" ]; then + if [ "${{ matrix.BUILD_SHARED_LIBS }}" = "OFF" ] && [ "${{ matrix.MLOPS }}" = "OFF" ]; then docker/docker_test.sh cpu-static - elif [ "${{ matrix.SHARED }}" = "ON" ] && [ "${{ matrix.MLOPS }}" = "OFF" ] && [ "${{ env.DEVELOPER_BUILD }}" = "ON" ]; then + elif [ "${{ matrix.BUILD_SHARED_LIBS }}" = "ON" ] && [ "${{ matrix.MLOPS }}" = "OFF" ] && [ "${{ env.DEVELOPER_BUILD }}" = "ON" ]; then docker/docker_test.sh cpu-shared - elif [ "${{ matrix.SHARED }}" = "ON" ] && [ "${{ matrix.MLOPS }}" = "OFF" ] && [ "${{ env.DEVELOPER_BUILD }}" = "OFF" ]; then + elif [ "${{ matrix.BUILD_SHARED_LIBS }}" = "ON" ] && [ "${{ matrix.MLOPS }}" = "OFF" ] && [ "${{ env.DEVELOPER_BUILD }}" = "OFF" ]; then docker/docker_test.sh cpu-shared-release - elif [ "${{ matrix.SHARED }}" = "ON" ] && [ "${{ matrix.MLOPS }}" = "ON" ] && [ "${{ env.DEVELOPER_BUILD }}" = "ON" ]; then + elif [ "${{ matrix.BUILD_SHARED_LIBS }}" = "ON" ] && [ "${{ matrix.MLOPS }}" = "ON" ] && [ "${{ env.DEVELOPER_BUILD }}" = "ON" ]; then docker/docker_test.sh cpu-shared-ml - elif [ "${{ matrix.SHARED }}" = "ON" ] && [ "${{ matrix.MLOPS }}" = "ON" ] && [ "${{ env.DEVELOPER_BUILD }}" = "OFF" ]; then + elif [ "${{ matrix.BUILD_SHARED_LIBS }}" = "ON" ] && [ "${{ matrix.MLOPS }}" = "ON" ] && [ "${{ env.DEVELOPER_BUILD }}" = "OFF" ]; then docker/docker_test.sh cpu-shared-ml-release fi - name: Upload package to GitHub artifacts - if: ${{ env.SHARED == 'ON' }} + if: ${{ env.BUILD_SHARED_LIBS == 'ON' }} uses: actions/upload-artifact@v2 with: name: open3d-devel-linux-x86_64 path: open3d-devel-*.tar.xz if-no-files-found: error - name: GCloud CLI setup - if: ${{ github.ref == 'refs/heads/master' && env.SHARED == 'ON' }} + if: ${{ github.ref == 'refs/heads/master' && env.BUILD_SHARED_LIBS == 'ON' }} # https://github.com/GoogleCloudPlatform/github-actions/issues/100#issuecomment-650798308 uses: google-github-actions/setup-gcloud@v0.2.1 with: @@ -88,7 +88,7 @@ jobs: project_id: ${{ secrets.GCE_DOCS_PROJECT }} export_default_credentials: true - name: Upload package to GCS bucket - if: ${{ github.ref == 'refs/heads/master' && env.SHARED == 'ON' }} + if: ${{ github.ref == 'refs/heads/master' && env.BUILD_SHARED_LIBS == 'ON' }} run: | gsutil cp open3d-devel-*.tar.xz gs://open3d-releases-master/devel/ echo "Download devel package at: https://storage.googleapis.com/open3d-releases-master/devel/${{ env.DEVEL_PKG_NAME }}" diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 20b99e4ccde..ba53f3acf7e 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -38,25 +38,25 @@ jobs: strategy: fail-fast: false matrix: - SHARED: [ON, OFF] + BUILD_SHARED_LIBS: [ON, OFF] STATIC_RUNTIME: [ON, OFF] - BUILD_CUDA: [ON, OFF] + BUILD_CUDA_MODULE: [ON, OFF] CONFIG: [Release, Debug] exclude: - - SHARED: ON + - BUILD_SHARED_LIBS: ON STATIC_RUNTIME: ON include: - - BUILD_CUDA: ON + - BUILD_CUDA_MODULE: ON CUDA_VERSION: 11.0.3 env: - BUILD_WEBRTC: ${{ ( matrix.SHARED == 'OFF' && matrix.STATIC_RUNTIME == 'ON' ) && 'ON' || 'OFF' }} + BUILD_WEBRTC: ${{ ( matrix.BUILD_SHARED_LIBS == 'OFF' && matrix.STATIC_RUNTIME == 'ON' ) && 'ON' || 'OFF' }} steps: - name: Disk space used run: Get-PSDrive - name: Install CUDA - if: ${{ matrix.BUILD_CUDA == 'ON' }} + if: ${{ matrix.BUILD_CUDA_MODULE == 'ON' }} run: | # Define variables $CUDA_VER_FULL = "${{ matrix.CUDA_VERSION }}" @@ -109,13 +109,13 @@ jobs: -DDEVELOPER_BUILD="${env:DEVELOPER_BUILD}" ` -DBUILD_EXAMPLES=OFF ` -DCMAKE_INSTALL_PREFIX="C:\Program Files\Open3D" ` - -DBUILD_SHARED_LIBS=${{ matrix.SHARED }} ` + -DBUILD_SHARED_LIBS=${{ matrix.BUILD_SHARED_LIBS }} ` -DSTATIC_WINDOWS_RUNTIME=${{ matrix.STATIC_RUNTIME }} ` -DBUILD_COMMON_ISPC_ISAS=ON ` -DBUILD_LIBREALSENSE=ON ` -DBUILD_WEBRTC=${{ env.BUILD_WEBRTC }} ` -DBUILD_UNIT_TESTS=ON ` - -DBUILD_CUDA_MODULE=${{ matrix.BUILD_CUDA }} ` + -DBUILD_CUDA_MODULE=${{ matrix.BUILD_CUDA_MODULE }} ` ${{ env.SRC_DIR }} - name: Build @@ -129,7 +129,7 @@ jobs: - name: Package working-directory: ${{ env.BUILD_DIR }} - if: ${{ matrix.SHARED == 'ON' && matrix.BUILD_CUDA == 'OFF' }} + if: ${{ matrix.BUILD_SHARED_LIBS == 'ON' && matrix.BUILD_CUDA_MODULE == 'OFF' }} run: | $ErrorActionPreference = 'Stop' cmake --build . --parallel ${{ env.NPROC }} --config ${{ matrix.CONFIG }} ` @@ -143,7 +143,7 @@ jobs: $env:GITHUB_ENV -Encoding utf8 -Append - name: Upload package - if: ${{ matrix.SHARED == 'ON' && matrix.BUILD_CUDA == 'OFF' }} + if: ${{ matrix.BUILD_SHARED_LIBS == 'ON' && matrix.BUILD_CUDA_MODULE == 'OFF' }} uses: actions/upload-artifact@v2 with: name: open3d-devel-windows @@ -151,7 +151,7 @@ jobs: if-no-files-found: error - name: GCloud CLI setup - if: ${{ github.ref == 'refs/heads/master' && matrix.SHARED == 'ON' && matrix.BUILD_CUDA == 'OFF' }} + if: ${{ github.ref == 'refs/heads/master' && matrix.BUILD_SHARED_LIBS == 'ON' && matrix.BUILD_CUDA_MODULE == 'OFF' }} # https://github.com/GoogleCloudPlatform/github-actions/issues/100#issuecomment-650798308 uses: google-github-actions/setup-gcloud@v0.2.1 env: @@ -163,7 +163,7 @@ jobs: export_default_credentials: true - name: Upload package to GCS bucket - if: ${{ github.ref == 'refs/heads/master' && matrix.SHARED == 'ON' && matrix.BUILD_CUDA == 'OFF' }} + if: ${{ github.ref == 'refs/heads/master' && matrix.BUILD_SHARED_LIBS == 'ON' && matrix.BUILD_CUDA_MODULE == 'OFF' }} env: CLOUDSDK_PYTHON: ${{env.PYTHON_EXECUTABLE}} run: | @@ -176,7 +176,7 @@ jobs: } - name: Run C++ unit tests - if: ${{ matrix.BUILD_CUDA == 'OFF' }} + if: ${{ matrix.BUILD_CUDA_MODULE == 'OFF' }} working-directory: ${{ env.BUILD_DIR }} run: | echo "Add --gtest_random_seed=SEED to the test command to repeat this test sequence." @@ -206,8 +206,8 @@ jobs: idna==${{ env.IDNA_VER }} cmake --build . --config ${{ matrix.CONFIG }} --target install-pip-package - name: Import python package - # If SHARED == ON, Open3D.dll needs to be copied, which is not recommended for python. - if: ${{ matrix.SHARED == 'OFF' && matrix.BUILD_CUDA == 'OFF' }} + # If BUILD_SHARED_LIBS == ON, Open3D.dll needs to be copied, which is not recommended for python. + if: ${{ matrix.BUILD_SHARED_LIBS == 'OFF' && matrix.BUILD_CUDA_MODULE == 'OFF' }} run: | python -c "import open3d; print('Imported:', open3d)" python -c "import open3d; print('CUDA enabled: ', open3d.core.cuda.is_available())" diff --git a/3rdparty/README_SYCL.md b/3rdparty/README_SYCL.md new file mode 100644 index 00000000000..2d95f8f9088 --- /dev/null +++ b/3rdparty/README_SYCL.md @@ -0,0 +1,88 @@ +# Open3D SYCL + +Note: this file will be moved to the `docs` folder once SYCL support is mature. + +## Concepts + +- **OpenCL**: Low-level programming interface for heterogeneous platforms. +- **SYCL**: High-level programming interface for heterogeneous platforms. SYCL + was originally based on OpenCL but now SYCL is an independent standard. +- **DPC++**: Intel's implementation of the SYCL standard. +- **oneAPI**: A collection of open standards, including DPC++, oneMKL, oneTBB, etc. + +Open3D's SYCL support runs on DPC++ and requires oneAPI dependencies. For +convenience, in the source code, we use the term "SYCL" although we may be +referring to "DPC++". + +## Setup + +1. Install oneAPI for Linux: [install via apt-get](https://www.intel.com/content/www/us/en/develop/documentation/installation-guide-for-intel-oneapi-toolkits-linux/top/installation/install-using-package-managers/apt.html) +2. Prepare environment + ```bash + # Source environments + source /opt/intel/oneapi/setvars.sh + + # We'll be using oneAPI's distribution of conda and Python + # Python 3.6+ will work + conda create -n sycl python=3.8 + conda activate sycl + ``` +3. Check your environment + ```bash + which icx # /opt/intel/oneapi/compiler//linux/bin/icx + which icpx # /opt/intel/oneapi/compiler//linux/bin/icpx + which python # ${HOME}/.conda/envs/sycl/bin/python + python --version # Python 3.8.12 :: Intel Corporation + ``` +4. Config and build + ```bash + cmake -DBUILD_SYCL_MODULE=ON -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx .. + make -j$(nproc) + ``` +5. Run demos + We provide several ways to run SYCL demos. This ensures the linking are + correct and all run-time dependencies are satisfied. + ```bash + # C++ test + make tests -j$(nproc) + ./bin/tests --gtest_filter="*SYCLDemo*" + + # C++ example + make SYCLDemo -j$(nproc) + ./bin/examples/SYCLDemo + + # Python + make install-pip-package -j$(nproc) + pytest ../python/test/core/test_sycl_utils.py -s + ``` + +## Known limitations/requirement + +- Limitations (not implemented yet) + - Only supports Linux + - Only supports `BUILD_CUDA_MODULE=OFF` + - ML ops not supported (C++17 cannot be enabled for TF) +- Requirements (required by DPC++) + - Only supports `GLIBCXX_USE_CXX11_ABI=ON` + - Only supports `set(CMAKE_CXX_STANDARD 17)` + + +## List of oneAPI Python packages + +To make `pip install open3d` works out-of-the box on SYCL-enabled platforms, +we can utilize runtime libraries released via PyPI. This feature needs to be +implemented. + +User: +- https://pypi.org/user/IntelAutomationEngineering/ + +Libraries: +- dpcpp-cpp-rt https://pypi.org/project/dpcpp-cpp-rt/#history +- mkl https://pypi.org/project/mkl/#history +- mkl-static https://pypi.org/project/mkl-static/#history +- mkl-include https://pypi.org/project/mkl-include/#history +- mkl-dpcpp https://pypi.org/project/mkl-dpcpp/#history +- mkl-devel-dpcpp https://pypi.org/project/mkl-devel-dpcpp/#history +- ipp https://pypi.org/project/ipp/#history +- ipp-static https://pypi.org/project/ipp-static/#history +- tbb https://pypi.org/project/tbb/#history diff --git a/3rdparty/assimp/assimp.cmake b/3rdparty/assimp/assimp.cmake index 2d5f04067f5..08c22f24a5f 100644 --- a/3rdparty/assimp/assimp.cmake +++ b/3rdparty/assimp/assimp.cmake @@ -6,6 +6,14 @@ else() set(lib_name assimp) endif() +# IntelLLVM (SYCL) compiler defaults to fast math, causing NaN comparison code +# compilation error. +if(CMAKE_CXX_COMPILER_ID MATCHES "IntelLLVM") + set(assimp_cmake_cxx_flags "${CMAKE_CXX_FLAGS} -ffp-contract=on -fno-fast-math") +else() + set(assimp_cmake_cxx_flags "${CMAKE_CXX_FLAGS}") +endif() + ExternalProject_Add( ext_assimp PREFIX assimp @@ -14,6 +22,8 @@ ExternalProject_Add( DOWNLOAD_DIR "${OPEN3D_THIRD_PARTY_DOWNLOAD_DIR}/assimp" UPDATE_COMMAND "" CMAKE_ARGS + ${ExternalProject_CMAKE_ARGS_hidden} + -DCMAKE_CXX_FLAGS:STRING=${assimp_cmake_cxx_flags} -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX= -DASSIMP_NO_EXPORT=ON @@ -23,7 +33,6 @@ ExternalProject_Add( -DASSIMP_BUILD_ZLIB=ON -DHUNTER_ENABLED=OFF # Renamed to "ASSIMP_HUNTER_ENABLED" in newer assimp. -DCMAKE_DEBUG_POSTFIX= - ${ExternalProject_CMAKE_ARGS_hidden} BUILD_BYPRODUCTS /${Open3D_INSTALL_LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}${lib_name}${CMAKE_STATIC_LIBRARY_SUFFIX} /${Open3D_INSTALL_LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}IrrXML${CMAKE_STATIC_LIBRARY_SUFFIX} diff --git a/3rdparty/benchmark/MakeAvailable/CMakeLists.txt b/3rdparty/benchmark/MakeAvailable/CMakeLists.txt index f48f1d7e1a1..d9ed37c51a0 100644 --- a/3rdparty/benchmark/MakeAvailable/CMakeLists.txt +++ b/3rdparty/benchmark/MakeAvailable/CMakeLists.txt @@ -9,6 +9,11 @@ else() add_compile_definitions(_GLIBCXX_USE_CXX11_ABI=0) endif() +# IntelLLVM (SYCL) compiler defaults to fast math, causing NaN comparison +# code compilation error. +add_compile_options($<$:-ffp-contract=on>) +add_compile_options($<$:-fno-fast-math>) + FetchContent_MakeAvailable(ext_benchmark) # Set the cache vars introduced by the benchmark lib as advanced to not diff --git a/3rdparty/embree/embree.cmake b/3rdparty/embree/embree.cmake index c9da60577b3..4e93eadf19e 100644 --- a/3rdparty/embree/embree.cmake +++ b/3rdparty/embree/embree.cmake @@ -69,11 +69,12 @@ endif() ExternalProject_Add( ext_embree PREFIX embree - URL https://github.com/embree/embree/archive/refs/tags/v3.13.0.tar.gz - URL_HASH SHA256=4d86a69508a7e2eb8710d571096ad024b5174834b84454a8020d3a910af46f4f + URL https://github.com/embree/embree/archive/refs/tags/v3.13.3.tar.gz + URL_HASH SHA256=74ec785afb8f14d28ea5e0773544572c8df2e899caccdfc88509f1bfff58716f DOWNLOAD_DIR "${OPEN3D_THIRD_PARTY_DOWNLOAD_DIR}/embree" UPDATE_COMMAND "" CMAKE_ARGS + ${ExternalProject_CMAKE_ARGS_hidden} -DCMAKE_INSTALL_PREFIX= ${ISA_ARGS} -DEMBREE_ISPC_SUPPORT=OFF @@ -85,7 +86,6 @@ ExternalProject_Add( -DEMBREE_GEOMETRY_QUAD=OFF -DEMBREE_GEOMETRY_SUBDIVISION=OFF -DEMBREE_TASKING_SYSTEM=INTERNAL - ${ExternalProject_CMAKE_ARGS_hidden} ${WIN_CMAKE_ARGS} BUILD_BYPRODUCTS /${Open3D_INSTALL_LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}embree3${CMAKE_STATIC_LIBRARY_SUFFIX} diff --git a/3rdparty/find_dependencies.cmake b/3rdparty/find_dependencies.cmake index dcd2dd5852c..f95e216b977 100644 --- a/3rdparty/find_dependencies.cmake +++ b/3rdparty/find_dependencies.cmake @@ -356,10 +356,13 @@ endif() # INCLUDE_ALL # install all files in the include directories. Default is *.h, *.hpp # HIDDEN -# Symbols from this library will not be exported to client code during -# linking with Open3D. This is the opposite of the VISIBLE option in -# open3d_build_3rdparty_library. Prefer hiding symbols during building 3rd -# party libraries, since this option is not supported by the MSVC linker. +# Symbols from this library will not be exported to client code during +# linking with Open3D. This is the opposite of the VISIBLE option in +# open3d_build_3rdparty_library. Prefer hiding symbols during building 3rd +# party libraries, since this option is not supported by the MSVC linker. +# GROUPED +# add "-Wl,--start-group" libx.a liby.a libz.a "-Wl,--end-group" around +# the libraries. # INCLUDE_DIRS # the temporary location where the library headers have been installed. # Trailing slashes have the same meaning as with install(DIRECTORY). @@ -378,7 +381,7 @@ endif() # targets on which depends on and that must be built before. # function(open3d_import_3rdparty_library name) - cmake_parse_arguments(arg "PUBLIC;HEADER;INCLUDE_ALL;HIDDEN" "LIB_DIR" "INCLUDE_DIRS;LIBRARIES;DEPENDS" ${ARGN}) + cmake_parse_arguments(arg "PUBLIC;HEADER;INCLUDE_ALL;HIDDEN;GROUPED" "LIB_DIR" "INCLUDE_DIRS;LIBRARIES;DEPENDS" ${ARGN}) if(arg_UNPARSED_ARGUMENTS) message(STATUS "Unparsed: ${arg_UNPARSED_ARGUMENTS}") message(FATAL_ERROR "Invalid syntax: open3d_import_3rdparty_library(${name} ${ARGN})") @@ -419,6 +422,9 @@ function(open3d_import_3rdparty_library name) else() set(HIDDEN 0) endif() + if(arg_GROUPED) + target_link_libraries(${name} INTERFACE "-Wl,--start-group") + endif() foreach(arg_LIBRARY IN LISTS arg_LIBRARIES) set(library_filename ${CMAKE_STATIC_LIBRARY_PREFIX}${arg_LIBRARY}${CMAKE_STATIC_LIBRARY_SUFFIX}) if(libcount EQUAL 1) @@ -445,6 +451,9 @@ function(open3d_import_3rdparty_library name) ${OPEN3D_HIDDEN_3RDPARTY_LINK_OPTIONS} PARENT_SCOPE) endif() endforeach() + if(arg_GROUPED) + target_link_libraries(${name} INTERFACE "-Wl,--end-group") + endif() endif() if(NOT BUILD_SHARED_LIBS OR arg_PUBLIC) install(TARGETS ${name} EXPORT ${PROJECT_NAME}Targets) @@ -1341,155 +1350,215 @@ open3d_import_3rdparty_library(3rdparty_vtk ) list(APPEND Open3D_3RDPARTY_PRIVATE_TARGETS_FROM_CUSTOM Open3D::3rdparty_vtk) -# TBB -if(USE_SYSTEM_TBB) +if(BUILD_SYCL_MODULE) + add_library(3rdparty_sycl INTERFACE) + target_link_libraries(3rdparty_sycl INTERFACE + $<$,$>>:sycl>) + target_link_options(3rdparty_sycl INTERFACE + $<$,$>>:-fsycl -fsycl-targets=spir64_x86_64>) + if(NOT BUILD_SHARED_LIBS OR arg_PUBLIC) + install(TARGETS 3rdparty_sycl EXPORT Open3DTargets) + endif() + add_library(Open3D::3rdparty_sycl ALIAS 3rdparty_sycl) + list(APPEND Open3D_3RDPARTY_PRIVATE_TARGETS_FROM_SYSTEM Open3D::3rdparty_sycl) +endif() + +if(BUILD_SYCL_MODULE) + option(OPEN3D_USE_ONEAPI_PACKAGES "Use the oneAPI distribution of MKL/TBB/DPL." ON) +else() + option(OPEN3D_USE_ONEAPI_PACKAGES "Use the oneAPI distribution of MKL/TBB/DPL." OFF) +endif() +mark_as_advanced(OPEN3D_USE_ONEAPI_PACKAGES) + +if(OPEN3D_USE_ONEAPI_PACKAGES) + # 1. oneTBB + # /opt/intel/oneapi/tbb/latest/lib/cmake/tbb open3d_find_package_3rdparty_library(3rdparty_tbb PACKAGE TBB TARGETS TBB::tbb ) - if(NOT 3rdparty_tbb_FOUND) - set(USE_SYSTEM_TBB OFF) - endif() -endif() -if(NOT USE_SYSTEM_TBB) - include(${Open3D_3RDPARTY_DIR}/mkl/tbb.cmake) - open3d_import_3rdparty_library(3rdparty_tbb - INCLUDE_DIRS ${STATIC_TBB_INCLUDE_DIR} - LIB_DIR ${STATIC_TBB_LIB_DIR} - LIBRARIES ${STATIC_TBB_LIBRARIES} - DEPENDS ext_tbb - ) - list(APPEND Open3D_3RDPARTY_PRIVATE_TARGETS_FROM_CUSTOM Open3D::3rdparty_tbb) -else() list(APPEND Open3D_3RDPARTY_PRIVATE_TARGETS_FROM_SYSTEM Open3D::3rdparty_tbb) -endif() -# parallelstl -include(${Open3D_3RDPARTY_DIR}/parallelstl/parallelstl.cmake) -open3d_import_3rdparty_library(3rdparty_parallelstl + # 2. oneDPL + # /opt/intel/oneapi/dpl/latest/lib/cmake/oneDPL + open3d_find_package_3rdparty_library(3rdparty_onedpl + PACKAGE oneDPL + TARGETS oneDPL + ) + target_compile_definitions(3rdparty_onedpl INTERFACE _GLIBCXX_USE_TBB_PAR_BACKEND=0) + target_compile_definitions(3rdparty_onedpl INTERFACE PSTL_USE_PARALLEL_POLICIES=0) + list(APPEND Open3D_3RDPARTY_PRIVATE_TARGETS_FROM_SYSTEM Open3D::3rdparty_onedpl) + + # 3. oneMKL + # /opt/intel/oneapi/mkl/latest/lib/cmake/mkl + set(MKL_THREADING tbb_thread) + set(MKL_LINK static) + find_package(MKL REQUIRED) + open3d_import_3rdparty_library(3rdparty_mkl + HIDDEN + GROUPED + INCLUDE_DIRS ${MKL_INCLUDE}/ + LIB_DIR ${MKL_ROOT}/lib/intel64 + LIBRARIES mkl_intel_ilp64 mkl_tbb_thread mkl_core + ) + # MKL definitions + target_compile_options(3rdparty_mkl INTERFACE "$<$:$<$:-m64>>") + target_compile_definitions(3rdparty_mkl INTERFACE "$<$:MKL_ILP64>") + # Other global macros + target_compile_definitions(3rdparty_mkl INTERFACE OPEN3D_USE_ONEAPI_PACKAGES) + list(APPEND Open3D_3RDPARTY_PRIVATE_TARGETS_FROM_SYSTEM Open3D::3rdparty_mkl) + +else() # if(OPEN3D_USE_ONEAPI_PACKAGES) + # TBB + if(USE_SYSTEM_TBB) + open3d_find_package_3rdparty_library(3rdparty_tbb + PACKAGE TBB + TARGETS TBB::tbb + ) + if(NOT 3rdparty_tbb_FOUND) + set(USE_SYSTEM_TBB OFF) + endif() + endif() + if(NOT USE_SYSTEM_TBB) + include(${Open3D_3RDPARTY_DIR}/mkl/tbb.cmake) + open3d_import_3rdparty_library(3rdparty_tbb + INCLUDE_DIRS ${STATIC_TBB_INCLUDE_DIR} + LIB_DIR ${STATIC_TBB_LIB_DIR} + LIBRARIES ${STATIC_TBB_LIBRARIES} + DEPENDS ext_tbb + ) + list(APPEND Open3D_3RDPARTY_PRIVATE_TARGETS_FROM_CUSTOM Open3D::3rdparty_tbb) + else() + list(APPEND Open3D_3RDPARTY_PRIVATE_TARGETS_FROM_SYSTEM Open3D::3rdparty_tbb) + endif() + + # parallelstl + include(${Open3D_3RDPARTY_DIR}/parallelstl/parallelstl.cmake) + open3d_import_3rdparty_library(3rdparty_parallelstl PUBLIC INCLUDE_DIRS ${PARALLELSTL_INCLUDE_DIRS} INCLUDE_ALL DEPENDS ext_parallelstl -) -list(APPEND Open3D_3RDPARTY_PUBLIC_TARGETS_FROM_CUSTOM Open3D::3rdparty_parallelstl) - -# MKL/BLAS -if(USE_BLAS) - if (USE_SYSTEM_BLAS) - find_package(BLAS) - find_package(LAPACK) - find_package(LAPACKE) - if(BLAS_FOUND AND LAPACK_FOUND AND LAPACKE_FOUND) - message(STATUS "System BLAS/LAPACK/LAPACKE found.") - list(APPEND Open3D_3RDPARTY_PRIVATE_TARGETS_FROM_SYSTEM - ${BLAS_LIBRARIES} - ${LAPACK_LIBRARIES} - ${LAPACKE_LIBRARIES} - ) - else() - message(STATUS "System BLAS/LAPACK/LAPACKE not found, setting USE_SYSTEM_BLAS=OFF.") - set(USE_SYSTEM_BLAS OFF) + ) + list(APPEND Open3D_3RDPARTY_PUBLIC_TARGETS_FROM_SYSTEM Open3D::3rdparty_parallelstl) + + # MKL/BLAS + if(USE_BLAS) + if (USE_SYSTEM_BLAS) + find_package(BLAS) + find_package(LAPACK) + find_package(LAPACKE) + if(BLAS_FOUND AND LAPACK_FOUND AND LAPACKE_FOUND) + message(STATUS "System BLAS/LAPACK/LAPACKE found.") + list(APPEND Open3D_3RDPARTY_PRIVATE_TARGETS_FROM_SYSTEM + ${BLAS_LIBRARIES} + ${LAPACK_LIBRARIES} + ${LAPACKE_LIBRARIES} + ) + else() + message(STATUS "System BLAS/LAPACK/LAPACKE not found, setting USE_SYSTEM_BLAS=OFF.") + set(USE_SYSTEM_BLAS OFF) + endif() endif() - endif() - if (NOT USE_SYSTEM_BLAS) - # Install gfortran first for compiling OpenBLAS/Lapack from source. - message(STATUS "Building OpenBLAS with LAPACK from source") + if (NOT USE_SYSTEM_BLAS) + # Install gfortran first for compiling OpenBLAS/Lapack from source. + message(STATUS "Building OpenBLAS with LAPACK from source") - find_program(gfortran_bin "gfortran") - if (gfortran_bin) - message(STATUS "gfortran found at ${gfortran}") - else() - message(FATAL_ERROR "gfortran is required to compile LAPACK from source. " - "On Ubuntu, please install by `apt install gfortran`. " - "On macOS, please install by `brew install gfortran`. ") - endif() + find_program(gfortran_bin "gfortran") + if (gfortran_bin) + message(STATUS "gfortran found at ${gfortran}") + else() + message(FATAL_ERROR "gfortran is required to compile LAPACK from source. " + "On Ubuntu, please install by `apt install gfortran`. " + "On macOS, please install by `brew install gfortran`. ") + endif() - include(${Open3D_3RDPARTY_DIR}/openblas/openblas.cmake) - open3d_import_3rdparty_library(3rdparty_blas - HIDDEN - INCLUDE_DIRS ${OPENBLAS_INCLUDE_DIR} - LIB_DIR ${OPENBLAS_LIB_DIR} - LIBRARIES ${OPENBLAS_LIBRARIES} - DEPENDS ext_openblas - ) - # Get gfortran library search directories. - execute_process(COMMAND ${gfortran_bin} -print-search-dirs - OUTPUT_VARIABLE gfortran_search_dirs - RESULT_VARIABLE RET - OUTPUT_STRIP_TRAILING_WHITESPACE - ) - if(RET AND NOT RET EQUAL 0) - message(FATAL_ERROR "Failed to run `${gfortran_bin} -print-search-dirs`") - endif() + include(${Open3D_3RDPARTY_DIR}/openblas/openblas.cmake) + open3d_import_3rdparty_library(3rdparty_blas + HIDDEN + INCLUDE_DIRS ${OPENBLAS_INCLUDE_DIR} + LIB_DIR ${OPENBLAS_LIB_DIR} + LIBRARIES ${OPENBLAS_LIBRARIES} + DEPENDS ext_openblas + ) + # Get gfortran library search directories. + execute_process(COMMAND ${gfortran_bin} -print-search-dirs + OUTPUT_VARIABLE gfortran_search_dirs + RESULT_VARIABLE RET + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if(RET AND NOT RET EQUAL 0) + message(FATAL_ERROR "Failed to run `${gfortran_bin} -print-search-dirs`") + endif() - # Parse gfortran library search directories into CMake list. - string(REGEX MATCH "libraries: =(.*)" match_result ${gfortran_search_dirs}) - if (match_result) - string(REPLACE ":" ";" gfortran_lib_dirs ${CMAKE_MATCH_1}) - else() - message(FATAL_ERROR "Failed to parse gfortran_search_dirs: ${gfortran_search_dirs}") - endif() + # Parse gfortran library search directories into CMake list. + string(REGEX MATCH "libraries: =(.*)" match_result ${gfortran_search_dirs}) + if (match_result) + string(REPLACE ":" ";" gfortran_lib_dirs ${CMAKE_MATCH_1}) + else() + message(FATAL_ERROR "Failed to parse gfortran_search_dirs: ${gfortran_search_dirs}") + endif() - if(LINUX_AARCH64 OR APPLE_AARCH64) - # Find libgfortran.a and libgcc.a inside the gfortran library search - # directories. This ensures that the library matches the compiler. - # On ARM64 Ubuntu and ARM64 macOS, libgfortran.a is compiled with `-fPIC`. - find_library(gfortran_lib NAMES libgfortran.a PATHS ${gfortran_lib_dirs} REQUIRED) - find_library(gcc_lib NAMES libgcc.a PATHS ${gfortran_lib_dirs} REQUIRED) - target_link_libraries(3rdparty_blas INTERFACE - ${gfortran_lib} - ${gcc_lib} - ) - if(APPLE_AARCH64) - # Suppress Apple compiler warnigns. - target_link_options(3rdparty_blas INTERFACE "-Wl,-no_compact_unwind") + if(LINUX_AARCH64 OR APPLE_AARCH64) + # Find libgfortran.a and libgcc.a inside the gfortran library search + # directories. This ensures that the library matches the compiler. + # On ARM64 Ubuntu and ARM64 macOS, libgfortran.a is compiled with `-fPIC`. + find_library(gfortran_lib NAMES libgfortran.a PATHS ${gfortran_lib_dirs} REQUIRED) + find_library(gcc_lib NAMES libgcc.a PATHS ${gfortran_lib_dirs} REQUIRED) + target_link_libraries(3rdparty_blas INTERFACE + ${gfortran_lib} + ${gcc_lib} + ) + if(APPLE_AARCH64) + # Suppress Apple compiler warnigns. + target_link_options(3rdparty_blas INTERFACE "-Wl,-no_compact_unwind") + endif() + elseif(UNIX AND NOT APPLE) + # On Ubuntu 20.04 x86-64, libgfortran.a is not compiled with `-fPIC`. + # The temporary solution is to link the shared library libgfortran.so. + # If we distribute a Python wheel, the user's system will also need + # to have libgfortran.so preinstalled. + # + # If you have to link libgfortran.a statically + # - Read https://gcc.gnu.org/wiki/InstallingGCC + # - Run `gfortran --version`, e.g. you get 9.3.0 + # - Checkout gcc source code to the corresponding version + # - Configure with + # ${PWD}/../gcc/configure --prefix=${HOME}/gcc-9.3.0 \ + # --enable-languages=c,c++,fortran \ + # --with-pic --disable-multilib + # - make install -j$(nproc) # This will take a while + # - Change this cmake file to libgfortran.a statically. + # - Link + # - libgfortran.a + # - libgcc.a + # - libquadmath.a + target_link_libraries(3rdparty_blas INTERFACE gfortran) endif() - elseif(UNIX AND NOT APPLE) - # On Ubuntu 20.04 x86-64, libgfortran.a is not compiled with `-fPIC`. - # The temporary solution is to link the shared library libgfortran.so. - # If we distribute a Python wheel, the user's system will also need - # to have libgfortran.so preinstalled. - # - # If you have to link libgfortran.a statically - # - Read https://gcc.gnu.org/wiki/InstallingGCC - # - Run `gfortran --version`, e.g. you get 9.3.0 - # - Checkout gcc source code to the corresponding version - # - Configure with - # ${PWD}/../gcc/configure --prefix=${HOME}/gcc-9.3.0 \ - # --enable-languages=c,c++,fortran \ - # --with-pic --disable-multilib - # - make install -j$(nproc) # This will take a while - # - Change this cmake file to libgfortran.a statically. - # - Link - # - libgfortran.a - # - libgcc.a - # - libquadmath.a - target_link_libraries(3rdparty_blas INTERFACE gfortran) + list(APPEND Open3D_3RDPARTY_PRIVATE_TARGETS_FROM_CUSTOM Open3D::3rdparty_blas) endif() + else() + include(${Open3D_3RDPARTY_DIR}/mkl/mkl.cmake) + # MKL, cuSOLVER, cuBLAS + # We link MKL statically. For MKL link flags, refer to: + # https://software.intel.com/content/www/us/en/develop/articles/intel-mkl-link-line-advisor.html + message(STATUS "Using MKL to support BLAS and LAPACK functionalities.") + open3d_import_3rdparty_library(3rdparty_blas + HIDDEN + INCLUDE_DIRS ${STATIC_MKL_INCLUDE_DIR} + LIB_DIR ${STATIC_MKL_LIB_DIR} + LIBRARIES ${STATIC_MKL_LIBRARIES} + DEPENDS ext_tbb ext_mkl_include ext_mkl + ) + if(UNIX) + target_compile_options(3rdparty_blas INTERFACE "$<$:-m64>") + target_link_libraries(3rdparty_blas INTERFACE Open3D::3rdparty_threads ${CMAKE_DL_LIBS}) + endif() + target_compile_definitions(3rdparty_blas INTERFACE "$<$:MKL_ILP64>") list(APPEND Open3D_3RDPARTY_PRIVATE_TARGETS_FROM_CUSTOM Open3D::3rdparty_blas) endif() -else() # if(USE_BLAS) - include(${Open3D_3RDPARTY_DIR}/mkl/mkl.cmake) - # MKL, cuSOLVER, cuBLAS - # We link MKL statically. For MKL link flags, refer to: - # https://software.intel.com/content/www/us/en/develop/articles/intel-mkl-link-line-advisor.html - message(STATUS "Using MKL to support BLAS and LAPACK functionalities.") - open3d_import_3rdparty_library(3rdparty_blas - HIDDEN - INCLUDE_DIRS ${STATIC_MKL_INCLUDE_DIR} - LIB_DIR ${STATIC_MKL_LIB_DIR} - LIBRARIES ${STATIC_MKL_LIBRARIES} - DEPENDS ext_tbb ext_mkl_include ext_mkl - ) - if(UNIX) - target_compile_options(3rdparty_blas INTERFACE "$<$:-m64>") - target_link_libraries(3rdparty_blas INTERFACE Open3D::3rdparty_threads ${CMAKE_DL_LIBS}) - endif() - target_compile_definitions(3rdparty_blas INTERFACE "$<$:MKL_ILP64>") - list(APPEND Open3D_3RDPARTY_PRIVATE_TARGETS_FROM_CUSTOM Open3D::3rdparty_blas) -endif() +endif() # if(OPEN3D_USE_ONEAPI_PACKAGES) # cuBLAS if(BUILD_CUDA_MODULE) diff --git a/CMakeLists.txt b/CMakeLists.txt index 38571974181..1283fa18c96 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,16 @@ -cmake_minimum_required(VERSION 3.19.2) +cmake_minimum_required(VERSION 3.20) # If you're using Ubuntu 18.04, we suggest you install the latest CMake from the -# official repository https://apt.kitware.com/. CMake 3.19+ is required to: +# official repository https://apt.kitware.com/. +# +# CMake 3.19+ is required to: # - allow linking with OBJECT libraries # - prevent erroneous -gencode option deduplication with CUDA # - simplify generator expressions for selecting compile flags and setting # global hardened link flags # - use first-class language support for ISPC (3.19.2 patch release required) +# +# CMake 3.20+ is required to: +# - detect IntelLLVM compiler for SYCL if (APPLE) set (CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE STRING @@ -59,7 +64,12 @@ if(BUILD_SHARED_LIBS) else() option(STATIC_WINDOWS_RUNTIME "Use static (MT/MTd) Windows runtime" ON ) endif() -option(GLIBCXX_USE_CXX11_ABI "Set -D_GLIBCXX_USE_CXX11_ABI=1" ON ) +option(BUILD_SYCL_MODULE "Build SYCL module with Intel oneAPI" OFF) +if(BUILD_SYCL_MODULE) + option(GLIBCXX_USE_CXX11_ABI "Set -D_GLIBCXX_USE_CXX11_ABI=1" ON ) +else() + option(GLIBCXX_USE_CXX11_ABI "Set -D_GLIBCXX_USE_CXX11_ABI=1" OFF) +endif() if(BUILD_GUI AND (WIN32 OR UNIX AND NOT LINUX_AARCH64 AND NOT APPLE_AARCH64)) option(BUILD_WEBRTC "Build WebRTC visualizer" ON ) else() @@ -248,9 +258,32 @@ project(Open3D LANGUAGES C CXX) message(STATUS "Open3D ${OPEN3D_VERSION_FULL}") +# Check SYCL compatiblility +if (BUILD_SYCL_MODULE AND NOT CMAKE_CXX_COMPILER_ID MATCHES "IntelLLVM") + message(FATAL_ERROR "BUILD_SYCL_MODULE requires IntelLLVM (DPC++) compiler, " + "but got CMAKE_CXX_COMPILER_ID: ${CMAKE_CXX_COMPILER_ID} " + "and CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}.") +endif() +if (BUILD_SYCL_MODULE AND (NOT UNIX OR APPLE)) + message(FATAL_ERROR "Open3D SYCL support is only available on Linux") +endif() +if(BUILD_SYCL_MODULE AND NOT GLIBCXX_USE_CXX11_ABI) + message(FATAL_ERROR "BUILD_SYCL_MODULE=ON requires GLIBCXX_USE_CXX11_ABI=ON") +endif() +if(BUILD_SYCL_MODULE AND BUILD_TENSORFLOW_OPS) + message(FATAL_ERROR "BUILD_SYCL_MODULE=ON requires BUILD_TENSORFLOW_OPS=OFF") +endif() +if(BUILD_SYCL_MODULE AND BUILD_PYTORCH_OPS) + message(FATAL_ERROR "BUILD_SYCL_MODULE=ON requires BUILD_PYTORCH_OPS=OFF") +endif() + # Global flag to set CXX standard. # This does not affect 3rd party libraries. -set(CMAKE_CXX_STANDARD 14) +if (BUILD_SYCL_MODULE) + set(CMAKE_CXX_STANDARD 17) +else() + set(CMAKE_CXX_STANDARD 14) +endif() # FIXME: Remove this workaround once a fixed Visual Studio 16.10 version is released. if (BUILD_CUDA_MODULE @@ -440,6 +473,7 @@ endmacro() include(Open3DLink3rdpartyLibraries) include(Open3DSetGlobalProperties) include(Open3DShowAndAbortOnWarning) +include(Open3DSYCLTargetSources) # Enumerate all third-party libraries which we need later # This creates the necessary targets and sets the diff --git a/cmake/Open3DLink3rdpartyLibraries.cmake b/cmake/Open3DLink3rdpartyLibraries.cmake index 4a05aaf1788..0df457eb884 100644 --- a/cmake/Open3DLink3rdpartyLibraries.cmake +++ b/cmake/Open3DLink3rdpartyLibraries.cmake @@ -24,7 +24,19 @@ function(open3d_link_3rdparty_libraries target) message(WARNING "Skipping non-existent header dependency ${dep}") endif() endforeach() + # Link header dependencies privately. target_link_libraries(${target} PRIVATE ${Open3D_3RDPARTY_HEADER_TARGETS}) + # Avoid duplicate linking SYCL when building BUILD_SHARED_LIBS. + if (TARGET Open3D::Open3D AND BUILD_SHARED_LIBS AND BUILD_SYCL_MODULE) + get_target_property(open3d_link_libs Open3D::Open3D LINK_LIBRARIES) + get_target_property(target_link_libs ${target} LINK_LIBRARIES) + if ((Open3D::Open3D IN_LIST target_link_libs) AND + (Open3D::3rdparty_sycl IN_LIST target_link_libs) AND + (Open3D::3rdparty_sycl IN_LIST open3d_link_libs)) + list(REMOVE_ITEM target_link_libs Open3D::3rdparty_sycl) + set_property(TARGET ${target} PROPERTY LINK_LIBRARIES ${target_link_libs}) + endif() + endif() endfunction() diff --git a/cmake/Open3DMakeHardeningFlags.cmake b/cmake/Open3DMakeHardeningFlags.cmake index cb0e0adb79d..dab703fb16a 100644 --- a/cmake/Open3DMakeHardeningFlags.cmake +++ b/cmake/Open3DMakeHardeningFlags.cmake @@ -35,6 +35,15 @@ function(open3d_make_hardening_flags hardening_cflags hardening_ldflags) list(APPEND ${hardening_cflags} -fsanitize=safe-stack) # Stack execution protection list(APPEND ${hardening_ldflags} -fsanitize=safe-stack) # only static libraries supported endif() + elseif (CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM") + set(${hardening_cflags} + -fstack-protector # Stack-based buffer overrun detection + -Wformat -Wformat-security # Format string vulnerability + ) + set(${hardening_ldflags} + -Wl,-z,relro,-z,now # Data relocation protection + $<$:LINKER:-S> # Exclude debug info + ) elseif (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") set(${hardening_cflags} -fstack-protector # Stack-based buffer overrun detection @@ -111,6 +120,7 @@ function(open3d_make_hardening_definitions hardening_definitions) if (MSVC) # No flags added for MSVC elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR + CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU") set(${hardening_definitions} _FORTIFY_SOURCE=2) # Buffer overflow detection diff --git a/cmake/Open3DSYCLTargetSources.cmake b/cmake/Open3DSYCLTargetSources.cmake new file mode 100644 index 00000000000..9b0220c10ab --- /dev/null +++ b/cmake/Open3DSYCLTargetSources.cmake @@ -0,0 +1,41 @@ +# open3d_sycl_target_sources(name ...) +# +# When BUILD_SYCL_MODULE=ON, set SYCL-specific compile flags for the listed +# source files and call target_sources(). If BUILD_SYCL_MODULE=OFF, this +# function directly calls target_sources(). +# +# Note: this is not a perfect forwarding to target_sources(), as it only support +# limited set of arguments. See the example usage below. +# +# Example usage: +# open3d_sycl_target_sources(core PRIVATE a.cpp b.cpp) +# open3d_sycl_target_sources(core PUBLIC a.cpp b.cpp) +# open3d_sycl_target_sources(core VERBOSE PRIVATE a.cpp b.cpp) +# open3d_sycl_target_sources(core VERBOSE PUBLIC a.cpp b.cpp) +function(open3d_sycl_target_sources target) + cmake_parse_arguments(arg "PUBLIC;PRIVATE;INTERFACE;VERBOSE" "" "" ${ARGN}) + if(arg_UNPARSED_ARGUMENTS) + if(arg_PUBLIC) + target_sources(${target} PUBLIC ${arg_UNPARSED_ARGUMENTS}) + message(STATUS "open3d_sycl_target_sources(${target}): PUBLIC") + elseif (arg_PRIVATE) + target_sources(${target} PRIVATE ${arg_UNPARSED_ARGUMENTS}) + message(STATUS "open3d_sycl_target_sources(${target}): PRIVATE") + elseif (arg_INTERFACE) + target_sources(${target} INTERFACE ${arg_UNPARSED_ARGUMENTS}) + message(STATUS "open3d_sycl_target_sources(${target}): INTERFACE") + else() + message(FATAL_ERROR "Invalid syntax: open3d_sycl_target_sources(${name} ${ARGN})") + endif() + + if(BUILD_SYCL_MODULE) + foreach(sycl_file IN LISTS arg_UNPARSED_ARGUMENTS) + set_source_files_properties(${sycl_file} PROPERTIES + COMPILE_OPTIONS -fsycl -fsycl-unnamed-lambda -fsycl-targets=spir64_x86_64) + if(arg_VERBOSE) + message(STATUS "open3d_sycl_target_sources(${target}): marked ${sycl_file} as SYCL code") + endif() + endforeach() + endif() + endif() +endfunction() diff --git a/cmake/Open3DSetGlobalProperties.cmake b/cmake/Open3DSetGlobalProperties.cmake index e60f1f9bee5..cdca1d661f2 100644 --- a/cmake/Open3DSetGlobalProperties.cmake +++ b/cmake/Open3DSetGlobalProperties.cmake @@ -94,6 +94,9 @@ function(open3d_set_global_properties target) if (BUILD_ISPC_MODULE) target_compile_definitions(${target} PRIVATE BUILD_ISPC_MODULE) endif() + if (BUILD_SYCL_MODULE) + target_compile_definitions(${target} PRIVATE BUILD_SYCL_MODULE) + endif() if (BUILD_GUI) target_compile_definitions(${target} PRIVATE BUILD_GUI) endif() @@ -170,6 +173,13 @@ function(open3d_set_global_properties target) target_compile_options(${target} PRIVATE $<$:--arch=x86-64>) endif() + # Turn off fast math for IntelLLVM DPC++ compiler. + # Fast math does not work with some of our NaN handling logics. + target_compile_options(${target} PRIVATE + $<$,$>>:-ffp-contract=on>) + target_compile_options(${target} PRIVATE + $<$,$>>:-fno-fast-math>) + # TBB static version is used # See: https://github.com/wjakob/tbb/commit/615d690c165d68088c32b6756c430261b309b79c target_compile_definitions(${target} PRIVATE __TBB_LIB_NAME=tbb_static) diff --git a/cpp/open3d/core/CMakeLists.txt b/cpp/open3d/core/CMakeLists.txt index 34d4aec83bb..fe9ceb6e96c 100644 --- a/cpp/open3d/core/CMakeLists.txt +++ b/cpp/open3d/core/CMakeLists.txt @@ -12,6 +12,7 @@ target_sources(core PRIVATE MemoryManagerStatistic.cpp ShapeUtil.cpp SizeVector.cpp + SYCLUtils.cpp Tensor.cpp TensorCheck.cpp TensorFunction.cpp @@ -19,19 +20,17 @@ target_sources(core PRIVATE TensorList.cpp ) -target_sources(core PRIVATE - hashmap/DeviceHashBackend.cpp - hashmap/HashMap.cpp - hashmap/HashSet.cpp - hashmap/HashBackendBuffer.cpp +open3d_sycl_target_sources(core PRIVATE VERBOSE + SYCLUtils.cpp ) target_sources(core PRIVATE - hashmap/CPU/CreateCPUHashBackend.cpp hashmap/CPU/CPUHashBackendBuffer.cpp -) - -target_sources(core PRIVATE + hashmap/CPU/CreateCPUHashBackend.cpp + hashmap/DeviceHashBackend.cpp + hashmap/HashBackendBuffer.cpp + hashmap/HashMap.cpp + hashmap/HashSet.cpp kernel/Arange.cpp kernel/ArangeCPU.cpp kernel/BinaryEW.cpp @@ -45,9 +44,8 @@ target_sources(core PRIVATE kernel/ReductionCPU.cpp kernel/UnaryEW.cpp kernel/UnaryEWCPU.cpp -) - -target_sources(core PRIVATE + linalg/AddMM.cpp + linalg/AddMMCPU.cpp linalg/Det.cpp linalg/Inverse.cpp linalg/InverseCPU.cpp @@ -63,16 +61,11 @@ target_sources(core PRIVATE linalg/SVDCPU.cpp linalg/Tri.cpp linalg/TriCPU.cpp - linalg/AddMM.cpp - linalg/AddMMCPU.cpp -) - -target_sources(core PRIVATE - nns/FixedRadiusSearchOps.cpp nns/FixedRadiusIndex.cpp + nns/FixedRadiusSearchOps.cpp + nns/KnnIndex.cpp nns/NanoFlannIndex.cpp nns/NearestNeighborSearch.cpp - nns/KnnIndex.cpp nns/NNSIndex.cpp ) @@ -80,23 +73,17 @@ if (BUILD_CUDA_MODULE) target_sources(core PRIVATE MemoryManagerCUDA.cpp ) - target_sources(core PRIVATE hashmap/CUDA/CreateCUDAHashBackend.cu hashmap/CUDA/CUDAHashBackendBuffer.cu hashmap/CUDA/SlabNodeManager.cu - ) - - target_sources(core PRIVATE kernel/ArangeCUDA.cu kernel/BinaryEWCUDA.cu kernel/IndexGetSetCUDA.cu kernel/NonZeroCUDA.cu kernel/ReductionCUDA.cu kernel/UnaryEWCUDA.cu - ) - - target_sources(core PRIVATE + linalg/AddMMCUDA.cpp linalg/InverseCUDA.cpp linalg/LeastSquaresCUDA.cpp linalg/LinalgUtils.cpp @@ -105,29 +92,21 @@ if (BUILD_CUDA_MODULE) linalg/SolveCUDA.cpp linalg/SVDCUDA.cpp linalg/TriCUDA.cu - linalg/AddMMCUDA.cpp - ) - - target_sources(core PRIVATE - nns/KnnSearchOps.cu nns/FixedRadiusSearchOps.cu nns/kernel/BlockSelectFloat32.cu nns/kernel/BlockSelectFloat64.cu + nns/KnnSearchOps.cu ) endif() if (BUILD_ISPC_MODULE) target_sources(core PRIVATE Indexer.ispc - ) - - target_sources(core PRIVATE kernel/BinaryEWCPU.ispc kernel/UnaryEWCPU.ispc ) endif() - open3d_show_and_abort_on_warning(core) open3d_set_global_properties(core) open3d_set_open3d_lib_properties(core) diff --git a/cpp/open3d/core/SYCLUtils.cpp b/cpp/open3d/core/SYCLUtils.cpp new file mode 100644 index 00000000000..bce56b32b05 --- /dev/null +++ b/cpp/open3d/core/SYCLUtils.cpp @@ -0,0 +1,93 @@ +// ---------------------------------------------------------------------------- +// - Open3D: www.open3d.org - +// ---------------------------------------------------------------------------- +// The MIT License (MIT) +// +// Copyright (c) 2018-2021 www.open3d.org +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +// ---------------------------------------------------------------------------- + +#include "open3d/core/SYCLUtils.h" + +#ifdef BUILD_SYCL_MODULE +#include +#endif + +#include + +#include "open3d/utility/Logging.h" + +namespace open3d { +namespace core { + +int SYCLDemo() { +#ifdef BUILD_SYCL_MODULE + // Ref: https://intel.github.io/llvm-docs/GetStartedGuide.html + // Creating buffer of 4 ints to be used inside the kernel code. + cl::sycl::buffer buffer(4); + + // Creating SYCL queue. + cl::sycl::queue q; + + // Size of index space for kernel. + cl::sycl::range<1> num_workloads{buffer.size()}; + + // Submitting command group(work) to q. + q.submit([&](cl::sycl::handler& cgh) { + // Getting write only access to the buffer on a device. + auto accessor = buffer.get_access(cgh); + // Execute kernel. + cgh.parallel_for( + num_workloads, [=](cl::sycl::id<1> WIid) { + // Fill buffer with indexes. + accessor[WIid] = (cl::sycl::cl_int)WIid.get(0); + }); + }); + + // Getting read only access to the buffer on the host. + // Implicit barrier waiting for q to complete the work. + const auto host_accessor = + buffer.get_access(); + + // Check the results. + bool mismatch_found = false; + for (size_t i = 0; i < buffer.size(); ++i) { + if (host_accessor[i] != i) { + utility::LogInfo("Mismatch found at index {}: expected {}, got {}.", + i, i, host_accessor[i]); + mismatch_found = true; + } + } + + if (mismatch_found) { + utility::LogInfo("SYCLDemo failed!"); + return -1; + } else { + utility::LogInfo("SYCLDemo passed!"); + return 0; + } +#else + utility::LogInfo("SYCLDemo is not compiled with BUILD_SYCL_MODULE=ON."); + return -1; +#endif +} + +} // namespace core +} // namespace open3d diff --git a/cpp/open3d/core/SYCLUtils.h b/cpp/open3d/core/SYCLUtils.h new file mode 100644 index 00000000000..58528d51a57 --- /dev/null +++ b/cpp/open3d/core/SYCLUtils.h @@ -0,0 +1,37 @@ +// ---------------------------------------------------------------------------- +// - Open3D: www.open3d.org - +// ---------------------------------------------------------------------------- +// The MIT License (MIT) +// +// Copyright (c) 2018-2021 www.open3d.org +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +// ---------------------------------------------------------------------------- + +#pragma once + +namespace open3d { +namespace core { + +/// Runs simple SYCL test program for sanity checks. +/// \return Retuns 0 if successful. +int SYCLDemo(); + +} // namespace core +} // namespace open3d diff --git a/cpp/open3d/core/TensorFunction.h b/cpp/open3d/core/TensorFunction.h index 14bfd2f0c25..d240133b6d8 100644 --- a/cpp/open3d/core/TensorFunction.h +++ b/cpp/open3d/core/TensorFunction.h @@ -110,5 +110,7 @@ Tensor Append(const Tensor& self, const Tensor& other, const utility::optional& axis = utility::nullopt); +void SYCLDemo(); + } // namespace core } // namespace open3d diff --git a/cpp/open3d/core/linalg/LinalgHeadersCPU.h b/cpp/open3d/core/linalg/LinalgHeadersCPU.h index dacb09e1ac0..baec0c7746e 100644 --- a/cpp/open3d/core/linalg/LinalgHeadersCPU.h +++ b/cpp/open3d/core/linalg/LinalgHeadersCPU.h @@ -39,8 +39,5 @@ #include #else #include -static_assert( - sizeof(MKL_INT) == 8, - "MKL_INT must be 8 bytes: please link with MKL 64-bit int library."); #define OPEN3D_CPU_LINALG_INT MKL_INT #endif diff --git a/cpp/open3d/pipelines/registration/FastGlobalRegistration.cpp b/cpp/open3d/pipelines/registration/FastGlobalRegistration.cpp index d1b2acfbb28..137a71aed71 100644 --- a/cpp/open3d/pipelines/registration/FastGlobalRegistration.cpp +++ b/cpp/open3d/pipelines/registration/FastGlobalRegistration.cpp @@ -259,6 +259,7 @@ static Eigen::Matrix4d OptimizePairwiseRegistration( r2 += r * r * s[c2]; r2 += (par * (1.0 - sqrt(s[c2])) * (1.0 - sqrt(s[c2]))); } + (void)r2; // Fix warning in Clang. bool success; Eigen::VectorXd result; std::tie(success, result) = utility::SolveLinearSystemPSD(-JTJ, JTr); diff --git a/cpp/open3d/utility/ParallelScan.h b/cpp/open3d/utility/ParallelScan.h index 30fa025ef17..d6c3448d276 100644 --- a/cpp/open3d/utility/ParallelScan.h +++ b/cpp/open3d/utility/ParallelScan.h @@ -29,28 +29,33 @@ #include #include +// clang-format off #if TBB_INTERFACE_VERSION >= 10000 - -// Check if the C++ standard library implements parallel algorithms -// and use this over parallelstl to avoid conflicts. -// Clang does not implement it so far, so checking for C++17 is not sufficient. -#ifdef __cpp_lib_parallel_algorithm -#include -#include -#else -#include -#include - -// parallelstl incorrectly assumes MSVC to unconditionally implement -// parallel algorithms even if __cpp_lib_parallel_algorithm is not defined. -// So manually include the header which pulls all "pstl::execution" definitions -// into the "std" namespace. -#if __PSTL_CPP17_EXECUTION_POLICIES_PRESENT -#include + #ifdef OPEN3D_USE_ONEAPI_PACKAGES + #include + #include + #else + // Check if the C++ standard library implements parallel algorithms + // and use this over parallelstl to avoid conflicts. + // Clang does not implement it so far, so checking for C++17 is not sufficient. + #ifdef __cpp_lib_parallel_algorithm + #include + #include + #else + #include + #include + // parallelstl incorrectly assumes MSVC to unconditionally implement + // parallel algorithms even if __cpp_lib_parallel_algorithm is not + // defined. So manually include the header which pulls all + // "pstl::execution" definitions into the "std" namespace. + #if __PSTL_CPP17_EXECUTION_POLICIES_PRESENT + #include + #endif + #endif + #endif #endif -#endif -#endif +// clang-format on namespace open3d { namespace utility { @@ -85,7 +90,12 @@ template void InclusivePrefixSum(const Tin* first, const Tin* last, Tout* out) { #if TBB_INTERFACE_VERSION >= 10000 // use parallelstl if we have TBB 2018 or later +#ifdef OPEN3D_USE_ONEAPI_PACKAGES + std::inclusive_scan(oneapi::dpl::execution::par_unseq, first, last, out); + +#else std::inclusive_scan(std::execution::par_unseq, first, last, out); +#endif #else ScanSumBody body(out, first); size_t n = std::distance(first, last); diff --git a/cpp/pybind/_build_config.py.in b/cpp/pybind/_build_config.py.in index 25c887cf9d7..6c32224de02 100644 --- a/cpp/pybind/_build_config.py.in +++ b/cpp/pybind/_build_config.py.in @@ -2,6 +2,7 @@ _build_config = { "BUILD_TENSORFLOW_OPS" : $,True,False>, "BUILD_PYTORCH_OPS" : $,True,False>, "BUILD_CUDA_MODULE" : $,True,False>, + "BUILD_SYCL_MODULE" : $,True,False>, "BUILD_AZURE_KINECT" : $,True,False>, "BUILD_LIBREALSENSE" : $,True,False>, "BUILD_SHARED_LIBS" : $,True,False>, diff --git a/cpp/pybind/core/CMakeLists.txt b/cpp/pybind/core/CMakeLists.txt index 4109d34a1e7..511fe4dfdd7 100644 --- a/cpp/pybind/core/CMakeLists.txt +++ b/cpp/pybind/core/CMakeLists.txt @@ -9,6 +9,7 @@ target_sources(pybind PRIVATE linalg.cpp scalar.cpp size_vector.cpp + sycl_utils.cpp tensor_accessor.cpp tensor_converter.cpp tensor_function.cpp diff --git a/cpp/pybind/core/core.cpp b/cpp/pybind/core/core.cpp index ea6ec1d76af..0277e466a68 100644 --- a/cpp/pybind/core/core.cpp +++ b/cpp/pybind/core/core.cpp @@ -40,6 +40,7 @@ void pybind_core(py::module& m) { // opn3d::core namespace. pybind_cuda_utils(m_core); + pybind_sycl_utils(m_core); pybind_core_blob(m_core); pybind_core_dtype(m_core); pybind_core_device(m_core); diff --git a/cpp/pybind/core/core.h b/cpp/pybind/core/core.h index 835f14104d3..77f4e4dcb22 100644 --- a/cpp/pybind/core/core.h +++ b/cpp/pybind/core/core.h @@ -34,6 +34,7 @@ namespace core { void pybind_core(py::module& m); void pybind_cuda_utils(py::module& m); +void pybind_sycl_utils(py::module& m); void pybind_core_blob(py::module& m); void pybind_core_dtype(py::module& m); void pybind_core_device(py::module& m); diff --git a/cpp/pybind/core/sycl_utils.cpp b/cpp/pybind/core/sycl_utils.cpp new file mode 100644 index 00000000000..2a5d17d1619 --- /dev/null +++ b/cpp/pybind/core/sycl_utils.cpp @@ -0,0 +1,37 @@ +// ---------------------------------------------------------------------------- +// - Open3D: www.open3d.org - +// ---------------------------------------------------------------------------- +// The MIT License (MIT) +// +// Copyright (c) 2018-2021 www.open3d.org +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +// ---------------------------------------------------------------------------- + +#include "open3d/core/SYCLUtils.h" +#include "open3d/utility/Optional.h" +#include "pybind/core/core.h" + +namespace open3d { +namespace core { + +void pybind_sycl_utils(py::module& m) { m.def("sycl_demo", &SYCLDemo); } + +} // namespace core +} // namespace open3d diff --git a/cpp/pybind/t/geometry/tensormap.cpp b/cpp/pybind/t/geometry/tensormap.cpp index dcb93265af6..4bfd512c0f9 100644 --- a/cpp/pybind/t/geometry/tensormap.cpp +++ b/cpp/pybind/t/geometry/tensormap.cpp @@ -119,7 +119,7 @@ static py::class_ bind_tensor_map(py::handle scope, // Deleted the "__delitem__" function. // This will be implemented in `pybind_tensormap()`. - cl.def("__len__", &Map::size); + cl.def("__len__", [](const Map &m) -> size_t { return m.size(); }); return cl; } diff --git a/cpp/tests/core/CMakeLists.txt b/cpp/tests/core/CMakeLists.txt index 3dd09f9860f..9d9e128968d 100644 --- a/cpp/tests/core/CMakeLists.txt +++ b/cpp/tests/core/CMakeLists.txt @@ -34,3 +34,9 @@ if (BUILD_ISPC_MODULE) ParallelFor.ispc ) endif() + +if (BUILD_SYCL_MODULE) + target_sources(tests PRIVATE + SYCLUtils.cpp + ) +endif() diff --git a/cpp/tests/core/SYCLUtils.cpp b/cpp/tests/core/SYCLUtils.cpp new file mode 100644 index 00000000000..c741e05db23 --- /dev/null +++ b/cpp/tests/core/SYCLUtils.cpp @@ -0,0 +1,45 @@ +// ---------------------------------------------------------------------------- +// - Open3D: www.open3d.org - +// ---------------------------------------------------------------------------- +// The MIT License (MIT) +// +// Copyright (c) 2018-2021 www.open3d.org +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +// ---------------------------------------------------------------------------- + +#include "open3d/core/SYCLUtils.h" + +#include "open3d/utility/Helper.h" +#include "open3d/utility/Timer.h" +#include "tests/Tests.h" +#include "tests/core/CoreTest.h" + +namespace open3d { +namespace tests { + +class SYCLUtilsPermuteDevices : public PermuteDevices {}; +INSTANTIATE_TEST_SUITE_P(SYCLUtils, + SYCLUtilsPermuteDevices, + testing::ValuesIn(PermuteDevices::TestCases())); + +TEST_P(SYCLUtilsPermuteDevices, SYCLDemo) { EXPECT_EQ(core::SYCLDemo(), 0); } + +} // namespace tests +} // namespace open3d diff --git a/cpp/tests/core/TensorFunction.cpp b/cpp/tests/core/TensorFunction.cpp index 1426c2407d2..171799a0be9 100644 --- a/cpp/tests/core/TensorFunction.cpp +++ b/cpp/tests/core/TensorFunction.cpp @@ -27,6 +27,7 @@ #include "open3d/core/TensorFunction.h" #include "open3d/utility/Helper.h" +#include "open3d/utility/Timer.h" #include "tests/Tests.h" #include "tests/core/CoreTest.h" diff --git a/docker/Dockerfile.ci b/docker/Dockerfile.ci index d638c64eaa0..123a7f9ed6b 100644 --- a/docker/Dockerfile.ci +++ b/docker/Dockerfile.ci @@ -2,7 +2,7 @@ ARG BASE_IMAGE FROM ${BASE_IMAGE} -# For miniconda and the rest of this Dockerfile +# For bash-specific commands SHELL ["/bin/bash", "-c"] # Required build args, should be specified in docker_build.sh @@ -11,22 +11,24 @@ ARG CCACHE_TAR_NAME ARG CMAKE_VERSION ARG CCACHE_VERSION ARG PYTHON_VERSION -ARG SHARED +ARG BUILD_SHARED_LIBS ARG BUILD_CUDA_MODULE ARG BUILD_TENSORFLOW_OPS ARG BUILD_PYTORCH_OPS ARG PACKAGE +ARG BUILD_SYCL_MODULE RUN if [ -z "${DEVELOPER_BUILD}" ]; then echo "Error: ARG DEVELOPER_BUILD not specified."; exit 1; fi \ && if [ -z "${CCACHE_TAR_NAME}" ]; then echo "Error: ARG CCACHE_TAR_NAME not specified."; exit 1; fi \ && if [ -z "${CMAKE_VERSION}" ]; then echo "Error: ARG CMAKE_VERSION not specified."; exit 1; fi \ && if [ -z "${CCACHE_VERSION}" ]; then echo "Error: ARG CCACHE_VERSION not specified."; exit 1; fi \ && if [ -z "${PYTHON_VERSION}" ]; then echo "Error: ARG PYTHON_VERSION not specified."; exit 1; fi \ - && if [ -z "${SHARED}" ]; then echo "Error: ARG SHARED not specified."; exit 1; fi \ + && if [ -z "${BUILD_SHARED_LIBS}" ]; then echo "Error: ARG BUILD_SHARED_LIBS not specified."; exit 1; fi \ && if [ -z "${BUILD_CUDA_MODULE}" ]; then echo "Error: ARG BUILD_CUDA_MODULE not specified."; exit 1; fi \ && if [ -z "${BUILD_TENSORFLOW_OPS}" ]; then echo "Error: ARG BUILD_TENSORFLOW_OPS not specified."; exit 1; fi \ && if [ -z "${BUILD_PYTORCH_OPS}" ]; then echo "Error: ARG BUILD_PYTORCH_OPS not specified."; exit 1; fi \ - && if [ -z "${PACKAGE}" ]; then echo "Error: ARG PACKAGE not specified."; exit 1; fi + && if [ -z "${PACKAGE}" ]; then echo "Error: ARG PACKAGE not specified."; exit 1; fi \ + && if [ -z "${BUILD_SYCL_MODULE}" ]; then echo "Error: ARG BUILD_SYCL_MODULE not specified."; exit 1; fi # Fix Nvidia repo key rotation issue # https://forums.developer.nvidia.com/t/notice-cuda-linux-repository-key-rotation/212771 @@ -40,21 +42,30 @@ RUN if [ "${BUILD_CUDA_MODULE}" = "ON" ]; then \ fi # Forward all ARG to ENV -# ci_utils.sh requires these environment variables +# ci_utils.sh may require these environment variables ENV DEVELOPER_BUILD=${DEVELOPER_BUILD} ENV CCACHE_TAR_NAME=${CCACHE_TAR_NAME} ENV CMAKE_VERSION=${CMAKE_VERSION} ENV CCACHE_VERSION=${CCACHE_VERSION} ENV PYTHON_VERSION=${PYTHON_VERSION} -ENV SHARED=${SHARED} +ENV BUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} +ENV BUILD_CUDA_MODULE=${BUILD_CUDA_MODULE} ENV BUILD_TENSORFLOW_OPS=${BUILD_TENSORFLOW_OPS} ENV BUILD_PYTORCH_OPS=${BUILD_PYTORCH_OPS} +ENV PACKAGE=${PACKAGE} +ENV BUILD_SYCL_MODULE=${BUILD_SYCL_MODULE} # Prevent interactive inputs when installing packages ENV DEBIAN_FRONTEND=noninteractive ENV TZ=America/Los_Angeles ENV SUDO=command +# The base image already contains the oneAPI packages. +# Having this in the list can cause checksum errors when apt-get update. +RUN if [ "${BUILD_SYCL_MODULE}" = "ON" ]; then \ + rm -rf /etc/apt/sources.list.d/oneAPI.list; \ + fi + # Dependencies: basic RUN apt-get update && apt-get install -y \ git \ @@ -64,12 +75,33 @@ RUN apt-get update && apt-get install -y \ pkg-config \ && rm -rf /var/lib/apt/lists/* +# Miniconda or Intel conda +# The **/open3d/bin paths are used during docker run, in this way docker run +# does not need to activate the environment again. +ENV PATH="/root/miniconda3/bin:${PATH}" +ENV PATH="/root/miniconda3/envs/open3d/bin:${PATH}" +ENV PATH="/opt/intel/oneapi/intelpython/latest/bin:${PATH}" +ENV PATH="/opt/intel/oneapi/intelpython/latest/envs/open3d/bin:${PATH}" +RUN if [ "${BUILD_SYCL_MODULE}" = "OFF" ]; then \ + wget -q https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh; \ + bash Miniconda3-latest-Linux-x86_64.sh -b; \ + rm Miniconda3-latest-Linux-x86_64.sh; \ + fi +RUN conda --version \ + && conda create -y -n open3d python=${PYTHON_VERSION} + +# Activate open3d virtualenv +# This works during docker build. It becomes the prefix of all RUN commands. +# Ref: https://stackoverflow.com/a/60148365/1255535 +SHELL ["conda", "run", "-n", "open3d", "/bin/bash", "-c"] + # Dependencies: cmake +ENV PATH=${HOME}/${CMAKE_VERSION}/bin:${PATH} RUN CMAKE_VERSION_NUMBERS=$(echo "${CMAKE_VERSION}" | cut -d"-" -f2) \ && wget -q https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION_NUMBERS}/${CMAKE_VERSION}.tar.gz \ && tar -xf ${CMAKE_VERSION}.tar.gz \ - && cp -ar ${CMAKE_VERSION} ${HOME} -ENV PATH=${HOME}/${CMAKE_VERSION}/bin:${PATH} + && cp -ar ${CMAKE_VERSION} ${HOME} \ + && cmake --version # Dependencies: ccache WORKDIR /root @@ -90,6 +122,8 @@ RUN git clone https://github.com/ccache/ccache.git \ # - CCACHE_DIR = ~/.cache/ccache # - CCACHE_DIR_NAME = ccache # - CCACHE_DIR_PARENT = ~/.cache +# We need to set ccache size explicitly with -M, otherwise the defualt size is +# *not* determined by ccache's default, but the downloaded ccache file's config. RUN CCACHE_DIR=$(ccache -p | grep cache_dir | grep -oE "[^ ]+$") \ && CCACHE_DIR_NAME=$(basename ${CCACHE_DIR}) \ && CCACHE_DIR_PARENT=$(dirname ${CCACHE_DIR}) \ @@ -97,24 +131,10 @@ RUN CCACHE_DIR=$(ccache -p | grep cache_dir | grep -oE "[^ ]+$") \ && cd ${CCACHE_DIR_PARENT} \ && (wget -q https://storage.googleapis.com/open3d-ci-cache/${CCACHE_TAR_NAME}.tar.gz || true) \ && if [ -f ${CCACHE_TAR_NAME}.tar.gz ]; then tar -xf ${CCACHE_TAR_NAME}.tar.gz; fi \ - && mkdir -p ${CCACHE_DIR} -# We need to set ccache size explicitly with -M, otherwise the default size is -# *not* determined by ccache's default, but the downloaded ccache file's config. -RUN ccache -M 5G \ + && mkdir -p ${CCACHE_DIR} \ + && ccache -M 5G \ && ccache -s -# Miniconda -ENV PATH="/root/miniconda3/bin:${PATH}" -RUN wget -q https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh \ - && bash Miniconda3-latest-Linux-x86_64.sh -b \ - && rm Miniconda3-latest-Linux-x86_64.sh \ - && conda --version -ENV PATH="/root/miniconda3/envs/open3d/bin:${PATH}" -RUN conda create -y -n open3d python=${PYTHON_VERSION} \ - && source activate open3d -RUN which python \ - && python --version - # Checkout Open3D-ML master branch # TODO: We may add support for local Open3D-ML repo or pinned ML repo tag ENV OPEN3D_ML_ROOT=/root/Open3D-ML @@ -142,8 +162,8 @@ RUN source util/ci_utils.sh \ RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash - \ && apt-get install -y nodejs \ && rm -rf /var/lib/apt/lists/* \ - && node --version -RUN npm install -g yarn \ + && node --version \ + && npm install -g yarn \ && yarn --version # Build all @@ -152,18 +172,28 @@ RUN if [ "${BUILD_PYTORCH_OPS}" = "ON" ] || [ "${BUILD_TENSORFLOW_OPS}" = "ON" ] else \ export GLIBCXX_USE_CXX11_ABI=ON; \ fi \ + && if [ "${BUILD_SYCL_MODULE}" = "ON" ]; then \ + export CMAKE_CXX_COMPILER=icpx; \ + export CMAKE_C_COMPILER=icx; \ + else \ + export CMAKE_CXX_COMPILER=g++; \ + export CMAKE_C_COMPILER=gcc; \ + fi \ && mkdir build \ && cd build \ - && cmake -DBUILD_SHARED_LIBS="${SHARED}" \ + && cmake -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} \ -DCMAKE_BUILD_TYPE=Release \ - -DDEVELOPER_BUILD="${DEVELOPER_BUILD}" \ + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} \ + -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} \ + -DBUILD_SYCL_MODULE=${BUILD_SYCL_MODULE} \ + -DDEVELOPER_BUILD=${DEVELOPER_BUILD} \ -DBUILD_LIBREALSENSE=ON \ - -DBUILD_CUDA_MODULE="${BUILD_CUDA_MODULE}" \ + -DBUILD_CUDA_MODULE=${BUILD_CUDA_MODULE} \ -DBUILD_COMMON_CUDA_ARCHS=ON \ -DBUILD_COMMON_ISPC_ISAS=ON \ - -DGLIBCXX_USE_CXX11_ABI="${GLIBCXX_USE_CXX11_ABI}" \ - -DBUILD_TENSORFLOW_OPS="${BUILD_TENSORFLOW_OPS}" \ - -DBUILD_PYTORCH_OPS="${BUILD_PYTORCH_OPS}" \ + -DGLIBCXX_USE_CXX11_ABI=${GLIBCXX_USE_CXX11_ABI} \ + -DBUILD_TENSORFLOW_OPS=${BUILD_TENSORFLOW_OPS} \ + -DBUILD_PYTORCH_OPS=${BUILD_PYTORCH_OPS} \ -DBUILD_UNIT_TESTS=ON \ -DBUILD_BENCHMARKS=ON \ -DBUILD_EXAMPLES=ON \ diff --git a/docker/Dockerfile.openblas b/docker/Dockerfile.openblas index d7729e957a6..1b1d8e9bb42 100644 --- a/docker/Dockerfile.openblas +++ b/docker/Dockerfile.openblas @@ -6,11 +6,11 @@ FROM ${BASE_IMAGE} SHELL ["/bin/bash", "-c"] # Required build args, should be specified in docker_build.sh -ARG CMAKE_VER +ARG CMAKE_VERSION ARG CCACHE_TAR_NAME ARG PYTHON_VERSION ARG DEVELOPER_BUILD -RUN if [ -z "${CMAKE_VER}" ]; then echo "Error: ARG CMAKE_VER not specified."; exit 1; fi \ +RUN if [ -z "${CMAKE_VERSION}" ]; then echo "Error: ARG CMAKE_VERSION not specified."; exit 1; fi \ && if [ -z "${CCACHE_TAR_NAME}" ]; then echo "Error: ARG CCACHE_TAR_NAME not specified."; exit 1; fi \ && if [ -z "${PYTHON_VERSION}" ]; then echo "Error: ARG PYTHON_VERSION not specified."; exit 1; fi \ && if [ -z "${DEVELOPER_BUILD}" ]; then echo "Error: ARG DEVELOPER_BUILD not specified."; exit 1; fi @@ -103,12 +103,12 @@ ENV PYENV_ROOT="/root/.pyenv" ENV PATH="${PYENV_ROOT}/bin:${PYENV_ROOT}/shims:${PATH}" # CMake -# PWD is /, cmake will be installed to /root/${CMAKE_VER}/bin/cmake -RUN CMAKE_VER_NUMBERS=$(echo "${CMAKE_VER}" | cut -d"-" -f2) \ - && wget -q https://github.com/Kitware/CMake/releases/download/v${CMAKE_VER_NUMBERS}/${CMAKE_VER}.tar.gz \ - && tar -xf ${CMAKE_VER}.tar.gz \ - && cp -ar ${CMAKE_VER} ${HOME} -ENV PATH=${HOME}/${CMAKE_VER}/bin:${PATH} +# PWD is /, cmake will be installed to /root/${CMAKE_VERSION}/bin/cmake +RUN CMAKE_VER_NUMBERS=$(echo "${CMAKE_VERSION}" | cut -d"-" -f2) \ + && wget -q https://github.com/Kitware/CMake/releases/download/v${CMAKE_VER_NUMBERS}/${CMAKE_VERSION}.tar.gz \ + && tar -xf ${CMAKE_VERSION}.tar.gz \ + && cp -ar ${CMAKE_VERSION} ${HOME} +ENV PATH=${HOME}/${CMAKE_VERSION}/bin:${PATH} # Open3D C++ dependencies # Done before copying the full Open3D directory for better Docker caching diff --git a/docker/Dockerfile.wheel b/docker/Dockerfile.wheel index fea848abe78..ba50de79687 100644 --- a/docker/Dockerfile.wheel +++ b/docker/Dockerfile.wheel @@ -3,11 +3,11 @@ ARG BASE_IMAGE=nvidia/cuda:11.0.3-cudnn8-devel-ubuntu18.04 FROM ${BASE_IMAGE} # Customizable build arguments from cuda.yml -ARG DEVELOPER_BUILD=ON -ARG CCACHE_TAR_NAME=open3d-ubuntu-1804-cuda-ci-ccache -ARG CMAKE_VERSION=cmake-3.19.7-Linux-x86_64 -ARG CCACHE_VERSION=4.3 -ARG PYTHON_VERSION=3.6 +ARG DEVELOPER_BUILD +ARG CCACHE_TAR_NAME +ARG CMAKE_VERSION +ARG CCACHE_VERSION +ARG PYTHON_VERSION # Forward all ARG to ENV # ci_utils.sh requires these environment variables @@ -124,7 +124,7 @@ WORKDIR /root/Open3D # Build python wheel RUN export NPROC=$(nproc) \ - && export SHARED=OFF \ + && export BUILD_SHARED_LIBS=OFF \ && export BUILD_TENSORFLOW_OPS=ON \ && export BUILD_PYTORCH_OPS=ON \ && source /root/Open3D/util/ci_utils.sh \ diff --git a/docker/docker_build.sh b/docker/docker_build.sh index d7413bbfe6b..c0f067d0c9e 100755 --- a/docker/docker_build.sh +++ b/docker/docker_build.sh @@ -21,41 +21,35 @@ __usage_docker_build="USAGE: OPTION: # OpenBLAS AMD64 (Dockerfile.openblas) - openblas-amd64-py36-dev: OpenBLAS AMD64 3.6 wheel, developer mode - openblas-amd64-py37-dev: OpenBLAS AMD64 3.7 wheel, developer mode - openblas-amd64-py38-dev: OpenBLAS AMD64 3.8 wheel, developer mode - openblas-amd64-py39-dev: OpenBLAS AMD64 3.9 wheel, developer mode - openblas-amd64-py36 : OpenBLAS AMD64 3.6 wheel, release mode - openblas-amd64-py37 : OpenBLAS AMD64 3.7 wheel, release mode - openblas-amd64-py38 : OpenBLAS AMD64 3.8 wheel, release mode - openblas-amd64-py39 : OpenBLAS AMD64 3.9 wheel, release mode + openblas-amd64-py36-dev : OpenBLAS AMD64 3.6 wheel, developer mode + openblas-amd64-py37-dev : OpenBLAS AMD64 3.7 wheel, developer mode + openblas-amd64-py38-dev : OpenBLAS AMD64 3.8 wheel, developer mode + openblas-amd64-py39-dev : OpenBLAS AMD64 3.9 wheel, developer mode + openblas-amd64-py36 : OpenBLAS AMD64 3.6 wheel, release mode + openblas-amd64-py37 : OpenBLAS AMD64 3.7 wheel, release mode + openblas-amd64-py38 : OpenBLAS AMD64 3.8 wheel, release mode + openblas-amd64-py39 : OpenBLAS AMD64 3.9 wheel, release mode # OpenBLAS ARM64 (Dockerfile.openblas) - openblas-arm64-py36-dev: OpenBLAS ARM64 3.6 wheel, developer mode - openblas-arm64-py37-dev: OpenBLAS ARM64 3.7 wheel, developer mode - openblas-arm64-py38-dev: OpenBLAS ARM64 3.8 wheel, developer mode - openblas-arm64-py39-dev: OpenBLAS ARM64 3.9 wheel, developer mode - openblas-arm64-py36 : OpenBLAS ARM64 3.6 wheel, release mode - openblas-arm64-py37 : OpenBLAS ARM64 3.7 wheel, release mode - openblas-arm64-py38 : OpenBLAS ARM64 3.8 wheel, release mode - openblas-arm64-py39 : OpenBLAS ARM64 3.9 wheel, release mode + openblas-arm64-py36-dev : OpenBLAS ARM64 3.6 wheel, developer mode + openblas-arm64-py37-dev : OpenBLAS ARM64 3.7 wheel, developer mode + openblas-arm64-py38-dev : OpenBLAS ARM64 3.8 wheel, developer mode + openblas-arm64-py39-dev : OpenBLAS ARM64 3.9 wheel, developer mode + openblas-arm64-py36 : OpenBLAS ARM64 3.6 wheel, release mode + openblas-arm64-py37 : OpenBLAS ARM64 3.7 wheel, release mode + openblas-arm64-py38 : OpenBLAS ARM64 3.8 wheel, release mode + openblas-arm64-py39 : OpenBLAS ARM64 3.9 wheel, release mode # Ubuntu CPU CI (Dockerfile.ci) - cpu-static : Ubuntu CPU static - cpu-shared : Ubuntu CPU shared - cpu-shared-release : Ubuntu CPU shared, release mode - cpu-shared-ml : Ubuntu CPU shared with ML - cpu-shared-ml-release : Ubuntu CPU shared with ML, release mode + cpu-static : Ubuntu CPU static + cpu-shared : Ubuntu CPU shared + cpu-shared-release : Ubuntu CPU shared, release mode + cpu-shared-ml : Ubuntu CPU shared with ML + cpu-shared-ml-release : Ubuntu CPU shared with ML, release mode - # CUDA wheels (Dockerfile.wheel) - cuda_wheel_py36_dev : CUDA Python 3.6 wheel, developer mode - cuda_wheel_py37_dev : CUDA Python 3.7 wheel, developer mode - cuda_wheel_py38_dev : CUDA Python 3.8 wheel, developer mode - cuda_wheel_py39_dev : CUDA Python 3.9 wheel, developer mode - cuda_wheel_py36 : CUDA Python 3.6 wheel, release mode - cuda_wheel_py37 : CUDA Python 3.7 wheel, release mode - cuda_wheel_py38 : CUDA Python 3.8 wheel, release mode - cuda_wheel_py39 : CUDA Python 3.9 wheel, release mode + # Sycl CPU CI (Dockerfile.ci) + sycl-shared : SYCL (oneAPI) with shared lib + sycl-static : SYCL (oneAPI) with static lib # ML CIs (Dockerfile.ci) 2-bionic : CUDA CI, 2-bionic, developer mode @@ -64,13 +58,24 @@ OPTION: 4-shared-bionic : CUDA CI, 4-shared-bionic, developer mode 4-shared-bionic-release : CUDA CI, 4-shared-bionic, release mode 5-ml-focal : CUDA CI, 5-ml-focal, developer mode + + # CUDA wheels (Dockerfile.wheel) + cuda_wheel_py36_dev : CUDA Python 3.6 wheel, developer mode + cuda_wheel_py37_dev : CUDA Python 3.7 wheel, developer mode + cuda_wheel_py38_dev : CUDA Python 3.8 wheel, developer mode + cuda_wheel_py39_dev : CUDA Python 3.9 wheel, developer mode + cuda_wheel_py36 : CUDA Python 3.6 wheel, release mode + cuda_wheel_py37 : CUDA Python 3.7 wheel, release mode + cuda_wheel_py38 : CUDA Python 3.8 wheel, release mode + cuda_wheel_py39 : CUDA Python 3.9 wheel, release mode " HOST_OPEN3D_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. >/dev/null 2>&1 && pwd)" # Shared variables CCACHE_VERSION=4.3 -CMAKE_VERSION=cmake-3.19.7-Linux-x86_64 +CMAKE_VERSION=cmake-3.20.6-linux-x86_64 +CMAKE_VERSION_AARCH64=cmake-3.20.6-linux-aarch64 print_usage_and_exit_docker_build() { echo "$__usage_docker_build" @@ -80,7 +85,7 @@ print_usage_and_exit_docker_build() { openblas_print_env() { echo "[openblas_print_env()] DOCKER_TAG: ${DOCKER_TAG}" echo "[openblas_print_env()] BASE_IMAGE: ${BASE_IMAGE}" - echo "[openblas_print_env()] CMAKE_VER: ${CMAKE_VER}" + echo "[openblas_print_env()] CMAKE_VERSION: ${CMAKE_VERSION}" echo "[openblas_print_env()] CCACHE_TAR_NAME: ${CCACHE_TAR_NAME}" echo "[openblas_print_env()] PYTHON_VERSION: ${PYTHON_VERSION}" echo "[openblas_print_env()] DEVELOPER_BUILD: ${DEVELOPER_BUILD}" @@ -94,13 +99,13 @@ openblas_export_env() { echo "[openblas_export_env()] platform AMD64" export DOCKER_TAG=open3d-ci:openblas-amd64 export BASE_IMAGE=ubuntu:18.04 - export CMAKE_VER=cmake-3.19.7-Linux-x86_64 + export CMAKE_VERSION=${CMAKE_VERSION} export CCACHE_TAR_NAME=open3d-ci-openblas-amd64 elif [[ "arm64" =~ ^($options)$ ]]; then echo "[openblas_export_env()] platform ARM64" export DOCKER_TAG=open3d-ci:openblas-arm64 export BASE_IMAGE=arm64v8/ubuntu:18.04 - export CMAKE_VER=cmake-3.19.7-Linux-aarch64 + export CMAKE_VERSION=${CMAKE_VERSION_AARCH64} export CCACHE_TAR_NAME=open3d-ci-openblas-arm64 else echo "Invalid platform." @@ -133,31 +138,32 @@ openblas_export_env() { fi # For docker_test.sh + export BUILD_SHARED_LIBS=OFF export BUILD_CUDA_MODULE=OFF export BUILD_PYTORCH_OPS=OFF export BUILD_TENSORFLOW_OPS=OFF + export BUILD_SYCL_MODULE=OFF } openblas_build() { openblas_print_env - # Docker build pushd "${HOST_OPEN3D_ROOT}" - docker build --build-arg BASE_IMAGE="${BASE_IMAGE}" \ - --build-arg CMAKE_VER="${CMAKE_VER}" \ - --build-arg CCACHE_TAR_NAME="${CCACHE_TAR_NAME}" \ - --build-arg PYTHON_VERSION="${PYTHON_VERSION}" \ - --build-arg DEVELOPER_BUILD="${DEVELOPER_BUILD}" \ - -t "${DOCKER_TAG}" \ - -f docker/Dockerfile.openblas . + docker build \ + --progress plain \ + --build-arg BASE_IMAGE="${BASE_IMAGE}" \ + --build-arg CMAKE_VERSION="${CMAKE_VERSION}" \ + --build-arg CCACHE_TAR_NAME="${CCACHE_TAR_NAME}" \ + --build-arg PYTHON_VERSION="${PYTHON_VERSION}" \ + --build-arg DEVELOPER_BUILD="${DEVELOPER_BUILD}" \ + -t "${DOCKER_TAG}" \ + -f docker/Dockerfile.openblas . popd - # Extract ccache docker run -v "${PWD}:/opt/mount" --rm "${DOCKER_TAG}" \ bash -c "cp /${CCACHE_TAR_NAME}.tar.gz /opt/mount \ && chown $(id -u):$(id -g) /opt/mount/${CCACHE_TAR_NAME}.tar.gz" - # Extract wheels docker run -v "${PWD}:/opt/mount" --rm "${DOCKER_TAG}" \ bash -c "cp /*.whl /opt/mount \ && chown $(id -u):$(id -g) /opt/mount/*.whl" @@ -166,8 +172,6 @@ openblas_build() { cuda_wheel_build() { BASE_IMAGE=nvidia/cuda:11.0.3-cudnn8-devel-ubuntu18.04 CCACHE_TAR_NAME=open3d-ubuntu-1804-cuda-ci-ccache - CMAKE_VERSION=cmake-3.19.7-Linux-x86_64 - CCACHE_VERSION=4.3 options="$(echo "$@" | tr ' ' '|')" echo "[cuda_wheel_build()] options: ${options}" @@ -191,9 +195,9 @@ cuda_wheel_build() { echo "[cuda_wheel_build()] PYTHON_VERSION: ${PYTHON_VERSION}" echo "[cuda_wheel_build()] DEVELOPER_BUILD: ${DEVELOPER_BUILD}" - # Docker build pushd "${HOST_OPEN3D_ROOT}" docker build \ + --progress plain \ --build-arg BASE_IMAGE="${BASE_IMAGE}" \ --build-arg DEVELOPER_BUILD="${DEVELOPER_BUILD}" \ --build-arg CCACHE_TAR_NAME="${CCACHE_TAR_NAME}" \ @@ -204,7 +208,6 @@ cuda_wheel_build() { -f docker/Dockerfile.wheel . popd - # Extract pip wheel, ccache python_package_dir=/root/Open3D/build/lib/python_package docker run -v "${PWD}:/opt/mount" --rm open3d-ci:wheel \ bash -c "cp ${python_package_dir}/pip_package/open3d*.whl /opt/mount \ @@ -221,25 +224,28 @@ ci_build() { echo "[ci_build()] CMAKE_VERSION=${CMAKE_VERSION}" echo "[ci_build()] CCACHE_VERSION=${CCACHE_VERSION}" echo "[ci_build()] PYTHON_VERSION=${PYTHON_VERSION}" - echo "[ci_build()] SHARED=${SHARED}" + echo "[ci_build()] BUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}" echo "[ci_build()] BUILD_CUDA_MODULE=${BUILD_CUDA_MODULE}" echo "[ci_build()] BUILD_TENSORFLOW_OPS=${BUILD_TENSORFLOW_OPS}" echo "[ci_build()] BUILD_PYTORCH_OPS=${BUILD_PYTORCH_OPS}" echo "[ci_build()] PACKAGE=${PACKAGE}" + echo "[ci_build()] BUILD_SYCL_MODULE=${BUILD_SYCL_MODULE}" pushd "${HOST_OPEN3D_ROOT}" docker build \ + --progress plain \ --build-arg BASE_IMAGE="${BASE_IMAGE}" \ --build-arg DEVELOPER_BUILD="${DEVELOPER_BUILD}" \ --build-arg CCACHE_TAR_NAME="${CCACHE_TAR_NAME}" \ --build-arg CMAKE_VERSION="${CMAKE_VERSION}" \ --build-arg CCACHE_VERSION="${CCACHE_VERSION}" \ --build-arg PYTHON_VERSION="${PYTHON_VERSION}" \ - --build-arg SHARED="${SHARED}" \ + --build-arg BUILD_SHARED_LIBS="${BUILD_SHARED_LIBS}" \ --build-arg BUILD_CUDA_MODULE="${BUILD_CUDA_MODULE}" \ --build-arg BUILD_TENSORFLOW_OPS="${BUILD_TENSORFLOW_OPS}" \ --build-arg BUILD_PYTORCH_OPS="${BUILD_PYTORCH_OPS}" \ --build-arg PACKAGE="${PACKAGE}" \ + --build-arg BUILD_SYCL_MODULE="${BUILD_SYCL_MODULE}" \ -t "${DOCKER_TAG}" \ -f docker/Dockerfile.ci . popd @@ -256,11 +262,12 @@ ci_build() { export DEVELOPER_BUILD=ON export CCACHE_TAR_NAME=open3d-ci-2-bionic export PYTHON_VERSION=3.6 - export SHARED=OFF + export BUILD_SHARED_LIBS=OFF export BUILD_CUDA_MODULE=ON export BUILD_TENSORFLOW_OPS=OFF export BUILD_PYTORCH_OPS=OFF export PACKAGE=OFF + export BUILD_SYCL_MODULE=OFF } 3-ml-shared-bionic_export_env() { @@ -270,11 +277,12 @@ ci_build() { export DEVELOPER_BUILD=ON export CCACHE_TAR_NAME=open3d-ci-3-ml-shared-bionic export PYTHON_VERSION=3.6 - export SHARED=ON + export BUILD_SHARED_LIBS=ON export BUILD_CUDA_MODULE=ON export BUILD_TENSORFLOW_OPS=ON export BUILD_PYTORCH_OPS=ON export PACKAGE=ON + export BUILD_SYCL_MODULE=OFF } 3-ml-shared-bionic-release_export_env() { @@ -284,11 +292,12 @@ ci_build() { export DEVELOPER_BUILD=OFF export CCACHE_TAR_NAME=open3d-ci-3-ml-shared-bionic export PYTHON_VERSION=3.6 - export SHARED=ON + export BUILD_SHARED_LIBS=ON export BUILD_CUDA_MODULE=ON export BUILD_TENSORFLOW_OPS=ON export BUILD_PYTORCH_OPS=ON export PACKAGE=ON + export BUILD_SYCL_MODULE=OFF } 4-shared-bionic_export_env() { @@ -298,11 +307,12 @@ ci_build() { export DEVELOPER_BUILD=ON export CCACHE_TAR_NAME=open3d-ci-4-shared-bionic export PYTHON_VERSION=3.6 - export SHARED=ON + export BUILD_SHARED_LIBS=ON export BUILD_CUDA_MODULE=ON export BUILD_TENSORFLOW_OPS=OFF export BUILD_PYTORCH_OPS=OFF export PACKAGE=ON + export BUILD_SYCL_MODULE=OFF } 4-shared-bionic-release_export_env() { @@ -312,11 +322,12 @@ ci_build() { export DEVELOPER_BUILD=OFF export CCACHE_TAR_NAME=open3d-ci-4-shared-bionic export PYTHON_VERSION=3.6 - export SHARED=ON + export BUILD_SHARED_LIBS=ON export BUILD_CUDA_MODULE=ON export BUILD_TENSORFLOW_OPS=OFF export BUILD_PYTORCH_OPS=OFF export PACKAGE=ON + export BUILD_SYCL_MODULE=OFF } 5-ml-focal_export_env() { @@ -326,11 +337,12 @@ ci_build() { export DEVELOPER_BUILD=ON export CCACHE_TAR_NAME=open3d-ci-5-ml-focal export PYTHON_VERSION=3.6 - export SHARED=OFF + export BUILD_SHARED_LIBS=OFF export BUILD_CUDA_MODULE=ON export BUILD_TENSORFLOW_OPS=ON export BUILD_PYTORCH_OPS=ON export PACKAGE=OFF + export BUILD_SYCL_MODULE=OFF } cpu-static_export_env() { @@ -340,11 +352,12 @@ cpu-static_export_env() { export DEVELOPER_BUILD=ON export CCACHE_TAR_NAME=open3d-ci-cpu export PYTHON_VERSION=3.6 - export SHARED=OFF + export BUILD_SHARED_LIBS=OFF export BUILD_CUDA_MODULE=OFF export BUILD_TENSORFLOW_OPS=OFF export BUILD_PYTORCH_OPS=OFF export PACKAGE=OFF + export BUILD_SYCL_MODULE=OFF } cpu-shared_export_env() { @@ -354,11 +367,12 @@ cpu-shared_export_env() { export DEVELOPER_BUILD=ON export CCACHE_TAR_NAME=open3d-ci-cpu export PYTHON_VERSION=3.6 - export SHARED=ON + export BUILD_SHARED_LIBS=ON export BUILD_CUDA_MODULE=OFF export BUILD_TENSORFLOW_OPS=OFF export BUILD_PYTORCH_OPS=OFF export PACKAGE=ON + export BUILD_SYCL_MODULE=OFF } cpu-shared-ml_export_env() { @@ -368,11 +382,12 @@ cpu-shared-ml_export_env() { export DEVELOPER_BUILD=ON export CCACHE_TAR_NAME=open3d-ci-cpu export PYTHON_VERSION=3.6 - export SHARED=ON + export BUILD_SHARED_LIBS=ON export BUILD_CUDA_MODULE=OFF export BUILD_TENSORFLOW_OPS=ON export BUILD_PYTORCH_OPS=ON export PACKAGE=ON + export BUILD_SYCL_MODULE=OFF } cpu-shared-release_export_env() { @@ -382,11 +397,12 @@ cpu-shared-release_export_env() { export DEVELOPER_BUILD=OFF export CCACHE_TAR_NAME=open3d-ci-cpu export PYTHON_VERSION=3.6 - export SHARED=ON + export BUILD_SHARED_LIBS=ON export BUILD_CUDA_MODULE=OFF export BUILD_TENSORFLOW_OPS=OFF export BUILD_PYTORCH_OPS=OFF export PACKAGE=ON + export BUILD_SYCL_MODULE=OFF } cpu-shared-ml-release_export_env() { @@ -396,170 +412,215 @@ cpu-shared-ml-release_export_env() { export DEVELOPER_BUILD=OFF export CCACHE_TAR_NAME=open3d-ci-cpu export PYTHON_VERSION=3.6 - export SHARED=ON + export BUILD_SHARED_LIBS=ON export BUILD_CUDA_MODULE=OFF export BUILD_TENSORFLOW_OPS=ON export BUILD_PYTORCH_OPS=ON export PACKAGE=ON + export BUILD_SYCL_MODULE=OFF } -function main () { +sycl-shared_export_env() { + export DOCKER_TAG=open3d-ci:sycl-shared + + # https://hub.docker.com/r/intel/oneapi-basekit + # https://github.com/intel/oneapi-containers/blob/master/images/docker/basekit/Dockerfile.ubuntu-18.04 + export BASE_IMAGE=intel/oneapi-basekit:2022.1.2-devel-ubuntu18.04 + export DEVELOPER_BUILD=ON + export CCACHE_TAR_NAME=open3d-ci-sycl + export PYTHON_VERSION=3.6 + export BUILD_SHARED_LIBS=ON + export BUILD_CUDA_MODULE=OFF + export BUILD_TENSORFLOW_OPS=OFF + export BUILD_PYTORCH_OPS=OFF + export PACKAGE=OFF + export BUILD_SYCL_MODULE=ON +} + +sycl-static_export_env() { + export DOCKER_TAG=open3d-ci:sycl-static + + # https://hub.docker.com/r/intel/oneapi-basekit + # https://github.com/intel/oneapi-containers/blob/master/images/docker/basekit/Dockerfile.ubuntu-18.04 + export BASE_IMAGE=intel/oneapi-basekit:2022.1.2-devel-ubuntu18.04 + export DEVELOPER_BUILD=ON + export CCACHE_TAR_NAME=open3d-ci-sycl + export PYTHON_VERSION=3.6 + export BUILD_SHARED_LIBS=OFF + export BUILD_CUDA_MODULE=OFF + export BUILD_TENSORFLOW_OPS=OFF + export BUILD_PYTORCH_OPS=OFF + export PACKAGE=OFF + export BUILD_SYCL_MODULE=ON +} + +function main() { if [[ "$#" -ne 1 ]]; then echo "Error: invalid number of arguments: $#." >&2 print_usage_and_exit_docker_build fi echo "[$(basename $0)] building $1" case "$1" in - # OpenBLAS AMD64 - openblas-amd64-py36-dev) - openblas_export_env amd64 py36 dev - openblas_build - ;; - openblas-amd64-py37-dev) - openblas_export_env amd64 py37 dev - openblas_build - ;; - openblas-amd64-py38-dev) - openblas_export_env amd64 py38 dev - openblas_build - ;; - openblas-amd64-py39-dev) - openblas_export_env amd64 py39 dev - openblas_build - ;; - openblas-amd64-py36) - openblas_export_env amd64 py36 - openblas_build - ;; - openblas-amd64-py37) - openblas_export_env amd64 py37 - openblas_build - ;; - openblas-amd64-py38) - openblas_export_env amd64 py38 - openblas_build - ;; - openblas-amd64-py39) - openblas_export_env amd64 py39 - openblas_build - ;; - - # OpenBLAS ARM64 - openblas-arm64-py36-dev) - openblas_export_env arm64 py36 dev - openblas_build - ;; - openblas-arm64-py37-dev) - openblas_export_env arm64 py37 dev - openblas_build - ;; - openblas-arm64-py38-dev) - openblas_export_env arm64 py38 dev - openblas_build - ;; - openblas-arm64-py39-dev) - openblas_export_env arm64 py39 dev - openblas_build - ;; - openblas-arm64-py36) - openblas_export_env arm64 py36 - openblas_build - ;; - openblas-arm64-py37) - openblas_export_env arm64 py37 - openblas_build - ;; - openblas-arm64-py38) - openblas_export_env arm64 py38 - openblas_build - ;; - openblas-arm64-py39) - openblas_export_env arm64 py39 - openblas_build - ;; - - # CPU CI - cpu-static) - cpu-static_export_env - ci_build - ;; - cpu-shared) - cpu-shared_export_env - ci_build - ;; - cpu-shared-release) - cpu-shared-release_export_env - ci_build - ;; - cpu-shared-ml) - cpu-shared-ml_export_env - ci_build - ;; - cpu-shared-ml-release) - cpu-shared-ml-release_export_env - ci_build - ;; - - # CUDA wheels - cuda_wheel_py36_dev) - cuda_wheel_build py36 dev - ;; - cuda_wheel_py37_dev) - cuda_wheel_build py37 dev - ;; - cuda_wheel_py38_dev) - cuda_wheel_build py38 dev - ;; - cuda_wheel_py39_dev) - cuda_wheel_build py39 dev - ;; - cuda_wheel_py36) - cuda_wheel_build py36 - ;; - cuda_wheel_py37) - cuda_wheel_build py37 - ;; - cuda_wheel_py38) - cuda_wheel_build py38 - ;; - cuda_wheel_py39) - cuda_wheel_build py39 - ;; - - # ML CIs - 2-bionic) - 2-bionic_export_env - ci_build - ;; - 3-ml-shared-bionic-release) - 3-ml-shared-bionic-release_export_env - ci_build - ;; - 3-ml-shared-bionic) - 3-ml-shared-bionic_export_env - ci_build - ;; - 4-shared-bionic-release) - 4-shared-bionic-release_export_env - ci_build - ;; - 4-shared-bionic) - 4-shared-bionic_export_env - ci_build - ;; - 5-ml-focal) - 5-ml-focal_export_env - ci_build - ;; - *) - echo "Error: invalid argument: ${1}." >&2 - print_usage_and_exit_docker_build - ;; + # OpenBLAS AMD64 + openblas-amd64-py36-dev) + openblas_export_env amd64 py36 dev + openblas_build + ;; + openblas-amd64-py37-dev) + openblas_export_env amd64 py37 dev + openblas_build + ;; + openblas-amd64-py38-dev) + openblas_export_env amd64 py38 dev + openblas_build + ;; + openblas-amd64-py39-dev) + openblas_export_env amd64 py39 dev + openblas_build + ;; + openblas-amd64-py36) + openblas_export_env amd64 py36 + openblas_build + ;; + openblas-amd64-py37) + openblas_export_env amd64 py37 + openblas_build + ;; + openblas-amd64-py38) + openblas_export_env amd64 py38 + openblas_build + ;; + openblas-amd64-py39) + openblas_export_env amd64 py39 + openblas_build + ;; + + # OpenBLAS ARM64 + openblas-arm64-py36-dev) + openblas_export_env arm64 py36 dev + openblas_build + ;; + openblas-arm64-py37-dev) + openblas_export_env arm64 py37 dev + openblas_build + ;; + openblas-arm64-py38-dev) + openblas_export_env arm64 py38 dev + openblas_build + ;; + openblas-arm64-py39-dev) + openblas_export_env arm64 py39 dev + openblas_build + ;; + openblas-arm64-py36) + openblas_export_env arm64 py36 + openblas_build + ;; + openblas-arm64-py37) + openblas_export_env arm64 py37 + openblas_build + ;; + openblas-arm64-py38) + openblas_export_env arm64 py38 + openblas_build + ;; + openblas-arm64-py39) + openblas_export_env arm64 py39 + openblas_build + ;; + + # CPU CI + cpu-static) + cpu-static_export_env + ci_build + ;; + cpu-shared) + cpu-shared_export_env + ci_build + ;; + cpu-shared-release) + cpu-shared-release_export_env + ci_build + ;; + cpu-shared-ml) + cpu-shared-ml_export_env + ci_build + ;; + cpu-shared-ml-release) + cpu-shared-ml-release_export_env + ci_build + ;; + + # SYCL CI + sycl-shared) + sycl-shared_export_env + ci_build + ;; + sycl-static) + sycl-static_export_env + ci_build + ;; + + # CUDA wheels + cuda_wheel_py36_dev) + cuda_wheel_build py36 dev + ;; + cuda_wheel_py37_dev) + cuda_wheel_build py37 dev + ;; + cuda_wheel_py38_dev) + cuda_wheel_build py38 dev + ;; + cuda_wheel_py39_dev) + cuda_wheel_build py39 dev + ;; + cuda_wheel_py36) + cuda_wheel_build py36 + ;; + cuda_wheel_py37) + cuda_wheel_build py37 + ;; + cuda_wheel_py38) + cuda_wheel_build py38 + ;; + cuda_wheel_py39) + cuda_wheel_build py39 + ;; + + # ML CIs + 2-bionic) + 2-bionic_export_env + ci_build + ;; + 3-ml-shared-bionic-release) + 3-ml-shared-bionic-release_export_env + ci_build + ;; + 3-ml-shared-bionic) + 3-ml-shared-bionic_export_env + ci_build + ;; + 4-shared-bionic-release) + 4-shared-bionic-release_export_env + ci_build + ;; + 4-shared-bionic) + 4-shared-bionic_export_env + ci_build + ;; + 5-ml-focal) + 5-ml-focal_export_env + ci_build + ;; + *) + echo "Error: invalid argument: ${1}." >&2 + print_usage_and_exit_docker_build + ;; esac } # main() will be executed when ./docker_build.sh is called directly. # main() will not be executed when ./docker_build.sh is sourced. -if [ "$0" = "$BASH_SOURCE" ] ; then +if [ "$0" = "$BASH_SOURCE" ]; then main "$@" fi diff --git a/docker/docker_test.sh b/docker/docker_test.sh index a74f1f98fd4..182eeaf971f 100755 --- a/docker/docker_test.sh +++ b/docker/docker_test.sh @@ -15,33 +15,44 @@ __usage_docker_test="USAGE: $(basename $0) [OPTION] OPTION: - # OpenBLAS AMD64 - openblas-amd64-py36-dev: OpenBLAS AMD64 3.6 wheel, developer mode - openblas-amd64-py37-dev: OpenBLAS AMD64 3.7 wheel, developer mode - openblas-amd64-py38-dev: OpenBLAS AMD64 3.8 wheel, developer mode - openblas-amd64-py39-dev: OpenBLAS AMD64 3.9 wheel, developer mode - openblas-amd64-py36 : OpenBLAS AMD64 3.6 wheel, release mode - openblas-amd64-py37 : OpenBLAS AMD64 3.7 wheel, release mode - openblas-amd64-py38 : OpenBLAS AMD64 3.8 wheel, release mode - openblas-amd64-py39 : OpenBLAS AMD64 3.9 wheel, release mode + # OpenBLAS AMD64 (Dockerfile.openblas) + openblas-amd64-py36-dev : OpenBLAS AMD64 3.6 wheel, developer mode + openblas-amd64-py37-dev : OpenBLAS AMD64 3.7 wheel, developer mode + openblas-amd64-py38-dev : OpenBLAS AMD64 3.8 wheel, developer mode + openblas-amd64-py39-dev : OpenBLAS AMD64 3.9 wheel, developer mode + openblas-amd64-py36 : OpenBLAS AMD64 3.6 wheel, release mode + openblas-amd64-py37 : OpenBLAS AMD64 3.7 wheel, release mode + openblas-amd64-py38 : OpenBLAS AMD64 3.8 wheel, release mode + openblas-amd64-py39 : OpenBLAS AMD64 3.9 wheel, release mode - # OpenBLAS ARM64 - openblas-arm64-py36-dev: OpenBLAS ARM64 3.6 wheel, developer mode - openblas-arm64-py37-dev: OpenBLAS ARM64 3.7 wheel, developer mode - openblas-arm64-py38-dev: OpenBLAS ARM64 3.8 wheel, developer mode - openblas-arm64-py39-dev: OpenBLAS ARM64 3.9 wheel, developer mode - openblas-arm64-py36 : OpenBLAS ARM64 3.6 wheel, release mode - openblas-arm64-py37 : OpenBLAS ARM64 3.7 wheel, release mode - openblas-arm64-py38 : OpenBLAS ARM64 3.8 wheel, release mode - openblas-arm64-py39 : OpenBLAS ARM64 3.9 wheel, release mode + # OpenBLAS ARM64 (Dockerfile.openblas) + openblas-arm64-py36-dev : OpenBLAS ARM64 3.6 wheel, developer mode + openblas-arm64-py37-dev : OpenBLAS ARM64 3.7 wheel, developer mode + openblas-arm64-py38-dev : OpenBLAS ARM64 3.8 wheel, developer mode + openblas-arm64-py39-dev : OpenBLAS ARM64 3.9 wheel, developer mode + openblas-arm64-py36 : OpenBLAS ARM64 3.6 wheel, release mode + openblas-arm64-py37 : OpenBLAS ARM64 3.7 wheel, release mode + openblas-arm64-py38 : OpenBLAS ARM64 3.8 wheel, release mode + openblas-arm64-py39 : OpenBLAS ARM64 3.9 wheel, release mode - # ML CIs - 2-bionic : CUDA CI, 2-bionic - 3-ml-shared-bionic : CUDA CI, 3-ml-shared-bionic - 3-ml-shared-bionic-release : CUDA CI, 3-ml-shared-bionic-release (same as above) - 4-shared-bionic : CUDA CI, 4-shared-bionic - 4-shared-bionic-release : CUDA CI, 4-shared-bionic-release (same as above) - 5-ml-focal : CUDA CI, 5-ml-focal + # Ubuntu CPU CI (Dockerfile.ci) + cpu-static : Ubuntu CPU static + cpu-shared : Ubuntu CPU shared + cpu-shared-release : Ubuntu CPU shared, release mode + cpu-shared-ml : Ubuntu CPU shared with ML + cpu-shared-ml-release : Ubuntu CPU shared with ML, release mode + + # Sycl CPU CI (Dockerfile.ci) + sycl-shared : SYCL (oneAPI) with shared lib + sycl-static : SYCL (oneAPI) with static lib + + # ML CIs (Dockerfile.ci) + 2-bionic : CUDA CI, 2-bionic, developer mode + 3-ml-shared-bionic-release : CUDA CI, 3-ml-shared-bionic, release mode + 3-ml-shared-bionic : CUDA CI, 3-ml-shared-bionic, developer mode + 4-shared-bionic : CUDA CI, 4-shared-bionic, developer mode + 4-shared-bionic-release : CUDA CI, 4-shared-bionic, release mode + 5-ml-focal : CUDA CI, 5-ml-focal, developer mode " HOST_OPEN3D_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. >/dev/null 2>&1 && pwd)" @@ -59,7 +70,7 @@ ci_print_env() { echo "[ci_print_env()] CMAKE_VERSION=${CMAKE_VERSION}" echo "[ci_print_env()] CCACHE_VERSION=${CCACHE_VERSION}" echo "[ci_print_env()] PYTHON_VERSION=${PYTHON_VERSION}" - echo "[ci_print_env()] SHARED=${SHARED}" + echo "[ci_print_env()] BUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}" echo "[ci_print_env()] BUILD_CUDA_MODULE=${BUILD_CUDA_MODULE}" echo "[ci_print_env()] BUILD_TENSORFLOW_OPS=${BUILD_TENSORFLOW_OPS}" echo "[ci_print_env()] BUILD_PYTORCH_OPS=${BUILD_PYTORCH_OPS}" @@ -90,13 +101,17 @@ restart_docker_daemon_if_on_gcloud() { cpp_python_linking_uninstall_test() { # Expects the following environment variables to be set: # - DOCKER_TAG + # - BUILD_SHARED_LIBS # - BUILD_CUDA_MODULE # - BUILD_PYTORCH_OPS # - BUILD_TENSORFLOW_OPS + # - BUILD_SYCL_MODULE echo "[cpp_python_linking_uninstall_test()] DOCKER_TAG=${DOCKER_TAG}" + echo "[cpp_python_linking_uninstall_test()] BUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}" echo "[cpp_python_linking_uninstall_test()] BUILD_CUDA_MODULE=${BUILD_CUDA_MODULE}" echo "[cpp_python_linking_uninstall_test()] BUILD_PYTORCH_OPS=${BUILD_PYTORCH_OPS}" echo "[cpp_python_linking_uninstall_test()] BUILD_TENSORFLOW_OPS=${BUILD_TENSORFLOW_OPS}" + echo "[cpp_python_linking_uninstall_test()] BUILD_SYCL_MODULE=${BUILD_SYCL_MODULE}" # Config-dependent argument: gpu_run_args if [ "${BUILD_CUDA_MODULE}" == "ON" ]; then @@ -111,12 +126,11 @@ cpp_python_linking_uninstall_test() { else pytest_args="" fi - restart_docker_daemon_if_on_gcloud # C++ test echo "gtest is randomized, add --gtest_random_seed=SEED to repeat the test sequence." - ${docker_run} -i --rm ${DOCKER_TAG} /bin/bash -c "\ + ${docker_run} -i --rm ${DOCKER_TAG} /bin/bash -c " \ cd build \ && ./bin/tests --gtest_shuffle --gtest_filter=-*Reduce*Sum* \ " @@ -124,8 +138,8 @@ cpp_python_linking_uninstall_test() { # Python test echo "pytest is randomized, add --randomly-seed=SEED to repeat the test sequence." - ${docker_run} -i --rm "${DOCKER_TAG}" /bin/bash -c "\ - python -m pytest python/test ${pytest_args} \ + ${docker_run} -i --rm "${DOCKER_TAG}" /bin/bash -c " \ + python -m pytest python/test ${pytest_args} -s \ " restart_docker_daemon_if_on_gcloud @@ -147,24 +161,37 @@ cpp_python_linking_uninstall_test() { && open3d example --show io/image_io \ " - # C++ linking: CMake and pkg-config + # C++ linking with new project + if [ "${BUILD_SYCL_MODULE}" == "ON" ]; then + cmake_compiler_args="-DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx" + else + cmake_compiler_args="" + fi + ${docker_run} -i --rm "${DOCKER_TAG}" /bin/bash -c "\ git clone https://github.com/isl-org/open3d-cmake-find-package.git \ && cd open3d-cmake-find-package \ && mkdir build \ && pushd build \ && echo Testing build with cmake \ - && cmake -DCMAKE_INSTALL_PREFIX=~/open3d_install .. \ + && cmake ${cmake_compiler_args} -DCMAKE_INSTALL_PREFIX=~/open3d_install .. \ && make -j$(nproc) VERBOSE=1 \ && ./Draw --skip-for-unit-test \ - && [ ${SHARED:-OFF} == OFF ] \ - || { rm -r ./* \ - && echo Testing build with pkg-config \ - && export PKG_CONFIG_PATH=~/open3d_install/lib/pkgconfig \ - && echo Open3D build options: \$(pkg-config --cflags --libs Open3D) \ - && c++ ../Draw.cpp -o Draw \$(pkg-config --cflags --libs Open3D) \ - && ./Draw --skip-for-unit-test ; } \ " + + if [ "${BUILD_SHARED_LIBS}" == "ON" ] && [ "${BUILD_SYCL_MODULE}" == "OFF" ]; then + ${docker_run} -i --rm "${DOCKER_TAG}" /bin/bash -c "\ + git clone https://github.com/isl-org/open3d-cmake-find-package.git \ + && cd open3d-cmake-find-package \ + && mkdir build \ + && pushd build \ + && echo Testing build with pkg-config \ + && export PKG_CONFIG_PATH=~/open3d_install/lib/pkgconfig \ + && echo Open3D build options: \$(pkg-config --cflags --libs Open3D) \ + && c++ ../Draw.cpp -o Draw \$(pkg-config --cflags --libs Open3D) \ + && ./Draw --skip-for-unit-test \ + " + fi restart_docker_daemon_if_on_gcloud # Uninstall @@ -292,6 +319,18 @@ cpu-shared-ml-release) cpp_python_linking_uninstall_test ;; +# SYCL CI +sycl-shared) + sycl-shared_export_env + ci_print_env + cpp_python_linking_uninstall_test + ;; +sycl-static) + sycl-static_export_env + ci_print_env + cpp_python_linking_uninstall_test + ;; + # ML CIs 2-bionic) 2-bionic_export_env diff --git a/examples/cpp/CMakeLists.txt b/examples/cpp/CMakeLists.txt index e6408fa90f6..a9191434b5e 100644 --- a/examples/cpp/CMakeLists.txt +++ b/examples/cpp/CMakeLists.txt @@ -69,6 +69,7 @@ open3d_add_example(ViewDistances) open3d_add_example(ViewPCDMatch) open3d_add_example(Visualizer) open3d_add_example(Voxelization) +open3d_add_example(SYCLDemo) if (BUILD_GUI) open3d_add_example(Draw) diff --git a/examples/cpp/SYCLDemo.cpp b/examples/cpp/SYCLDemo.cpp new file mode 100644 index 00000000000..9288087b9c4 --- /dev/null +++ b/examples/cpp/SYCLDemo.cpp @@ -0,0 +1,32 @@ +// ---------------------------------------------------------------------------- +// - Open3D: www.open3d.org - +// ---------------------------------------------------------------------------- +// The MIT License (MIT) +// +// Copyright (c) 2018-2021 www.open3d.org +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +// ---------------------------------------------------------------------------- + +#include "open3d/core/TensorFunction.h" + +int main() { + open3d::core::SYCLDemo(); + return 0; +} diff --git a/python/test/conftest.py b/python/test/conftest.py new file mode 100644 index 00000000000..b2cf516c6a7 --- /dev/null +++ b/python/test/conftest.py @@ -0,0 +1,27 @@ +# ---------------------------------------------------------------------------- +# - Open3D: www.open3d.org - +# ---------------------------------------------------------------------------- +# The MIT License (MIT) +# +# Copyright (c) 2018-2021 www.open3d.org +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# ---------------------------------------------------------------------------- + +import pytest diff --git a/python/test/core/test_sycl_utils.py b/python/test/core/test_sycl_utils.py new file mode 100644 index 00000000000..d11386f92e2 --- /dev/null +++ b/python/test/core/test_sycl_utils.py @@ -0,0 +1,39 @@ +# ---------------------------------------------------------------------------- +# - Open3D: www.open3d.org - +# ---------------------------------------------------------------------------- +# The MIT License (MIT) +# +# Copyright (c) 2018-2021 www.open3d.org +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# ---------------------------------------------------------------------------- + +import open3d as o3d +import pytest +import tempfile + +import sys +import os +sys.path.append(os.path.dirname(os.path.realpath(__file__)) + "/..") + + +@pytest.mark.skipif(not o3d._build_config["BUILD_SYCL_MODULE"], + reason="Skip if SYCL not enabled.") +def test_run_sycl_demo(): + assert o3d.core.sycl_demo() == 0 diff --git a/util/ci_utils.sh b/util/ci_utils.sh index 9e67957f639..ba696876cc6 100644 --- a/util/ci_utils.sh +++ b/util/ci_utils.sh @@ -9,7 +9,7 @@ DEVELOPER_BUILD="${DEVELOPER_BUILD:-ON}" if [[ "$DEVELOPER_BUILD" != "OFF" ]]; then # Validate input coming from GHA input field DEVELOPER_BUILD="ON" fi -SHARED=${SHARED:-OFF} +BUILD_SHARED_LIBS=${BUILD_SHARED_LIBS:-OFF} NPROC=${NPROC:-$(getconf _NPROCESSORS_ONLN)} # POSIX: MacOS + Linux if [ -z "${BUILD_CUDA_MODULE:+x}" ]; then if [[ "$OSTYPE" == "linux-gnu"* ]]; then @@ -126,7 +126,7 @@ build_all() { cmakeOptions=( -DDEVELOPER_BUILD=$DEVELOPER_BUILD - -DBUILD_SHARED_LIBS="$SHARED" + -DBUILD_SHARED_LIBS="$BUILD_SHARED_LIBS" -DCMAKE_BUILD_TYPE=Release -DBUILD_LIBREALSENSE=ON -DBUILD_CUDA_MODULE="$BUILD_CUDA_MODULE" @@ -148,7 +148,7 @@ build_all() { echo "Build & install Open3D..." make VERBOSE=1 -j"$NPROC" make VERBOSE=1 install -j"$NPROC" - if [[ "$SHARED" == "ON" ]]; then + if [[ "$BUILD_SHARED_LIBS" == "ON" ]]; then make package fi make VERBOSE=1 install-pip-package -j"$NPROC" @@ -333,7 +333,7 @@ test_cpp_example() { if [ "$runExample" == ON ]; then ./Draw --skip-for-unit-test fi - if [ $SHARED == ON ]; then + if [ $BUILD_SHARED_LIBS == ON ]; then rm -r ./* echo Testing build with pkg-config export PKG_CONFIG_PATH=${OPEN3D_INSTALL_DIR}/lib/pkgconfig