diff --git a/CMakeLists.txt b/CMakeLists.txt index 6d5b97205..4f002b5d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -135,7 +135,8 @@ if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") set(CMAKE_BUILD_RPATH "\$ORIGIN") endif() -set(TARGET_ARCH ${CMAKE_SYSTEM_PROCESSOR}) +include(DetermineTargetArch) +determine_target_arch(TARGET_ARCH) # CMake doesn't set the target processor correctly for MSVC if ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC") @@ -149,16 +150,14 @@ if ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC") # Check what architecture we are building for. This assumes all 64-bit architectures are amd64, which will break # if we decide to support arm. - if ("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8") - set(TARGET_ARCH "amd64") + if ("${TARGET_ARCH}" STREQUAL "x86_64") configure_file(k4a.props.in ${CMAKE_CURRENT_SOURCE_DIR}/src/csharp/k4a.x64.props) configure_file(StubGenerator.xml.in ${CMAKE_CURRENT_SOURCE_DIR}/src/csharp/StubGenerator.x64.xml) - elseif("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4") - set(TARGET_ARCH "x86") + elseif("${TARGET_ARCH}" STREQUAL "i686") configure_file(k4a.props.in ${CMAKE_CURRENT_SOURCE_DIR}/src/csharp/k4a.x86.props) configure_file(StubGenerator.xml.in ${CMAKE_CURRENT_SOURCE_DIR}/src/csharp/StubGenerator.x86.xml) else() - message(FATAL_ERROR "Unknown architecture with size of void* = ${CMAKE_SIZEOF_VOID_P}") + message(FATAL_ERROR "Unknown architecture for MSVC: ${TARGET_ARCH}") endif() endif() diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 337ee5f6f..c0014e00e 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -369,9 +369,6 @@ jobs: - job: LinuxK4ABuildTest displayName: Linux - pool: - vmImage: 'ubuntu-16.04' - container: mcr.microsoft.com/akbuilder-linux:v3 strategy: maxParallel: 100 matrix: @@ -379,18 +376,40 @@ jobs: CMakeLinuxTargetTriple: 'x86_64-linux-clang' CMakeConfiguration: 'debug' UsesOpenCV: 'TRUE' + container: 'mcr.microsoft.com/akbuilder-linux:v5-amd64' x64-gnu_debug_ninja: CMakeLinuxTargetTriple: 'x86_64-linux-gnu' CMakeConfiguration: 'debug' UsesOpenCV: 'TRUE' + container: 'mcr.microsoft.com/akbuilder-linux:v5-amd64' x64-clang_rel_ninja: CMakeLinuxTargetTriple: 'x86_64-linux-clang' CMakeConfiguration: 'relwithdebinfo' UsesOpenCV: 'TRUE' + container: 'mcr.microsoft.com/akbuilder-linux:v5-amd64' x64-gnu_rel_ninja: CMakeLinuxTargetTriple: 'x86_64-linux-gnu' CMakeConfiguration: 'relwithdebinfo' UsesOpenCV: 'TRUE' + container: 'mcr.microsoft.com/akbuilder-linux:v5-amd64' + # arm64-clang_debug_ninja: + # CMakeLinuxTargetTriple: 'arm64-linux-clang' + # CMakeConfiguration: 'debug' + # UsesOpenCV: 'FALSE' + arm64-gnu_debug_ninja: + CMakeLinuxTargetTriple: 'arm64-linux-gnu' + CMakeConfiguration: 'debug' + UsesOpenCV: 'FALSE' + container: 'mcr.microsoft.com/akbuilder-linux:v5-arm64' + # arm64-clang_rel_ninja: + # CMakeLinuxTargetTriple: 'arm64-linux-clang' + # CMakeConfiguration: 'relwithdebinfo' + # UsesOpenCV: 'FALSE' + arm64-gnu_rel_ninja: + CMakeLinuxTargetTriple: 'arm64-linux-gnu' + CMakeConfiguration: 'relwithdebinfo' + UsesOpenCV: 'FALSE' + container: 'mcr.microsoft.com/akbuilder-linux:v5-arm64' # 32-bit builds are currently broken # i386-unknown-linux-clang_debug_ninja: @@ -405,6 +424,9 @@ jobs: # i386-unknown-linux-gnu_relwithdebinfo_ninja: # CMakeLinuxTargetTriple: 'i386-linux-gnu' # CMakeConfiguration: 'relwithdebinfo' + pool: + vmImage: 'ubuntu-18.04' + container: $[ variables['container'] ] steps: - checkout: self @@ -470,7 +492,7 @@ jobs: ArtifactName: '$(CMakeLinuxTargetTriple)-$(CMakeConfiguration)' parallel: true parallelCount: 8 - condition: and(succeeded(), contains(variables['CMakeLinuxTargetTriple'], 'clang')) + condition: and(succeeded(), contains(variables['CMakeLinuxTargetTriple'], 'gnu')) - job: DocumentationBuild displayName: Documentation Build @@ -657,7 +679,7 @@ jobs: inputs: sourceFolder: "$(System.ArtifactsDirectory)/depthengineplugin/windows/amd64/release/" contents: "depthengine*.dll" - targetFolder: "$(System.ArtifactsDirectory)/amd64-windows-msvc-RelWithDebInfo/bin" + targetFolder: "$(System.ArtifactsDirectory)/amd64-windows-msvc-relwithdebinfo/bin" flattenFolders: true - task: CopyFiles@2 @@ -665,33 +687,33 @@ jobs: inputs: sourceFolder: "$(System.ArtifactsDirectory)/depthengineplugin/windows/amd64/release/" contents: "depthengine*.dll" - targetFolder: "$(System.ArtifactsDirectory)/amd64-windows-msvc-RelWithDebInfo/bin/Release/Microsoft.AzureKinect.FunctionalTests/netcoreapp2.1/" + targetFolder: "$(System.ArtifactsDirectory)/amd64-windows-msvc-relwithdebinfo/bin/Release/Microsoft.AzureKinect.FunctionalTests/netcoreapp2.1/" flattenFolders: true - - script: '.\amd64-windows-msvc-RelWithDebInfo\bin\AzureKinectFirmwareTool.exe -r' + - script: '.\amd64-windows-msvc-relwithdebinfo\bin\AzureKinectFirmwareTool.exe -r' workingDirectory: '$(System.ArtifactsDirectory)' displayName: 'Reset K4A Device' - - script: '.\amd64-windows-msvc-RelWithDebInfo\bin\AzureKinectFirmwareTool.exe -u firmware/AzureKinectDK_Fw_$(firmware_version).bin' + - script: '.\amd64-windows-msvc-relwithdebinfo\bin\AzureKinectFirmwareTool.exe -u firmware/AzureKinectDK_Fw_$(firmware_version).bin' workingDirectory: '$(System.ArtifactsDirectory)' displayName: 'Update Device' - - script: '.\amd64-windows-msvc-RelWithDebInfo\bin\enumerate_devices.exe' + - script: '.\amd64-windows-msvc-relwithdebinfo\bin\enumerate_devices.exe' workingDirectory: '$(System.ArtifactsDirectory)' displayName: 'Check Device Health' - script: 'python $(Build.SourcesDirectory)/scripts/RunTestList.py --list bin/functional_test_list.txt --bin bin/ --output=xml --gtest_filter=-*ONBOARDING*' - workingDirectory: '$(System.ArtifactsDirectory)/amd64-windows-msvc-RelWithDebInfo' + workingDirectory: '$(System.ArtifactsDirectory)/amd64-windows-msvc-relwithdebinfo' displayName: 'Run Functional Tests' timeoutInMinutes: 15 - script: 'python $(Build.SourcesDirectory)/scripts/RunTestList.py --list bin/functional_custom_test_list.txt --bin bin/ --output=xml --gtest_filter=-*ONBOARDING*' - workingDirectory: '$(System.ArtifactsDirectory)/amd64-windows-msvc-RelWithDebInfo' + workingDirectory: '$(System.ArtifactsDirectory)/amd64-windows-msvc-relwithdebinfo' displayName: 'Run Custom Functional Tests' timeoutInMinutes: 15 - script: 'python $(Build.SourcesDirectory)/scripts/RunTestList.py --list bin/functional_test_list.txt --bin bin/ --output=xml --gtest_filter=*ONBOARDING*' - workingDirectory: '$(System.ArtifactsDirectory)/amd64-windows-msvc-RelWithDebInfo' + workingDirectory: '$(System.ArtifactsDirectory)/amd64-windows-msvc-relwithdebinfo' displayName: 'Run Functional Tests - Onboarding' timeoutInMinutes: 15 continueOnError: true @@ -714,10 +736,19 @@ jobs: dependsOn: LinuxK4ABuildTest variables: firmware_version: "$(linux_firmware_version)" + strategy: + maxParallel: 100 + matrix: + x86_64: + CMakeLinuxTargetTriple: 'x86_64-linux-gnu' + EdenArch: 'x64' + arm64: + CMakeLinuxTargetTriple: 'arm64-linux-gnu' + EdenArch: 'arm64' pool: name: Analog-FwConnected demands: - - Eden + - EdenArch -equals $(EdenArch) - Agent.OS -equals Linux steps: @@ -730,7 +761,7 @@ jobs: - task: DownloadBuildArtifacts@0 displayName: 'Download Build Artifacts' inputs: - artifactName: 'x86_64-linux-clang-RelWithDebInfo' + artifactName: '$(CMakeLinuxTargetTriple)-relwithdebinfo' parallelizationLimit: 8 - task: NuGetToolInstaller@0 @@ -755,19 +786,19 @@ jobs: displayName: "Temp List files" - task: CopyFiles@2 - displayName: "Copy DepthEngine into amd64/debug artifacts folder" + displayName: "Copy DepthEngine into $(EdenArch)/debug artifacts folder" inputs: - sourceFolder: "$(System.ArtifactsDirectory)/NugetOutputDir/Microsoft.Azure.Kinect.Sensor.$(NuGetPackageVersion)/linux/lib/native/x64/release/" + sourceFolder: "$(System.ArtifactsDirectory)/NugetOutputDir/Microsoft.Azure.Kinect.Sensor.$(NuGetPackageVersion)/linux/lib/native/$(EdenArch)/release/" contents: "libdepthengine*" - targetFolder: "$(System.ArtifactsDirectory)/depthengineplugin/linux/x86_64/debug" + targetFolder: "$(System.ArtifactsDirectory)/depthengineplugin/linux/$(EdenArch)/debug" flattenFolders: true - task: CopyFiles@2 - displayName: "Copy DepthEngine into amd64/release artifacts folder" + displayName: "Copy DepthEngine into $(EdenArch)/release artifacts folder" inputs: - sourceFolder: "$(System.ArtifactsDirectory)/NugetOutputDir/Microsoft.Azure.Kinect.Sensor.$(NuGetPackageVersion)/linux/lib/native/x64/release/" + sourceFolder: "$(System.ArtifactsDirectory)/NugetOutputDir/Microsoft.Azure.Kinect.Sensor.$(NuGetPackageVersion)/linux/lib/native/$(EdenArch)/release/" contents: "libdepthengine*" - targetFolder: "$(System.ArtifactsDirectory)/depthengineplugin/linux/x86_64/release" + targetFolder: "$(System.ArtifactsDirectory)/depthengineplugin/linux/$(EdenArch)/release" flattenFolders: true - task: CopyFiles@2 @@ -788,17 +819,22 @@ jobs: - task: CopyFiles@2 displayName: "Copy DepthEnginePlugin into Build Artifacts" inputs: - sourceFolder: "$(System.ArtifactsDirectory)/depthengineplugin/linux/x86_64/release/" + sourceFolder: "$(System.ArtifactsDirectory)/depthengineplugin/linux/$(EdenArch)/release/" contents: "libdepthengine.so*" - targetFolder: "$(System.ArtifactsDirectory)/x86_64-linux-clang-relwithdebinfo/bin/" + targetFolder: "$(System.ArtifactsDirectory)/$(CMakeLinuxTargetTriple)-relwithdebinfo/bin/" flattenFolders: true - - script: 'chmod +x ./x86_64-linux-clang-relwithdebinfo/bin/*' + - script: 'chmod +x ./$(CMakeLinuxTargetTriple)-relwithdebinfo/bin/*' workingDirectory: '$(System.ArtifactsDirectory)' displayName: 'Add execution property to binary files' # Set the DISPLAY variable since DepthEngine needs to open a display window (even there is no visual display). - - script: 'echo "##vso[task.setvariable variable=DISPLAY]:0"' + - script: | + if [ $(EdenArch) == "arm64" ]; then + echo "##vso[task.setvariable variable=DISPLAY]:1" + else + echo "##vso[task.setvariable variable=DISPLAY]:0" + fi workingDirectory: '$(System.ArtifactsDirectory)' displayName: 'set DISPLAY variable' @@ -807,34 +843,38 @@ jobs: displayName: 'Check openGL version' timeoutInMinutes: 5 - - script: './x86_64-linux-clang-relwithdebinfo/bin/AzureKinectFirmwareTool -r' + - script: './$(CMakeLinuxTargetTriple)-relwithdebinfo/bin/AzureKinectFirmwareTool -r' workingDirectory: '$(System.ArtifactsDirectory)' displayName: 'Reset K4A Device' env: K4A_LOG_LEVEL: 'I' - - script: './x86_64-linux-clang-relwithdebinfo/bin/AzureKinectFirmwareTool -u firmware/AzureKinectDK_Fw_$(firmware_version).bin' + - script: './$(CMakeLinuxTargetTriple)-relwithdebinfo/bin/AzureKinectFirmwareTool -u firmware/AzureKinectDK_Fw_$(firmware_version).bin' workingDirectory: '$(System.ArtifactsDirectory)' displayName: 'Update Device' env: K4A_LOG_LEVEL: 'I' - - script: './x86_64-linux-clang-relwithdebinfo/bin/enumerate_devices' + - script: './$(CMakeLinuxTargetTriple)-relwithdebinfo/bin/enumerate_devices' workingDirectory: '$(System.ArtifactsDirectory)' displayName: 'Check Device Health' - script: 'python $(Build.SourcesDirectory)/scripts/RunTestList.py --list bin/functional_test_list.txt --bin bin/ --output=xml --gtest_filter=-*ONBOARDING*' - workingDirectory: '$(System.ArtifactsDirectory)/x86_64-linux-clang-relwithdebinfo' + workingDirectory: '$(System.ArtifactsDirectory)/$(CMakeLinuxTargetTriple)-relwithdebinfo' displayName: 'Run Functional Tests' timeoutInMinutes: 15 - - script: 'python $(Build.SourcesDirectory)/scripts/RunTestList.py --list bin/functional_custom_test_list.txt --bin bin/ --output=xml --gtest_filter=-*ONBOARDING*' - workingDirectory: '$(System.ArtifactsDirectory)/x86_64-linux-clang-relwithdebinfo' + - script: | + # skip testing on ARM64 Jetson Nano doesn't like 2 USB devices running at once. + if [ $(EdenArch) == "x64" ]; then + python $(Build.SourcesDirectory)/scripts/RunTestList.py --list bin/functional_custom_test_list.txt --bin bin/ --output=xml --gtest_filter=-*ONBOARDING* + fi + workingDirectory: '$(System.ArtifactsDirectory)/$(CMakeLinuxTargetTriple)-relwithdebinfo' displayName: 'Run Custom Functional Tests' timeoutInMinutes: 15 - script: 'python $(Build.SourcesDirectory)/scripts/RunTestList.py --list bin/functional_test_list.txt --bin bin/ --output=xml --gtest_filter=*ONBOARDING*' - workingDirectory: '$(System.ArtifactsDirectory)/x86_64-linux-clang-relwithdebinfo' + workingDirectory: '$(System.ArtifactsDirectory)/$(CMakeLinuxTargetTriple)-relwithdebinfo' displayName: 'Run Functional Tests - Onboarding' timeoutInMinutes: 15 continueOnError: true diff --git a/cmake/DetermineTargetArch.cmake b/cmake/DetermineTargetArch.cmake new file mode 100644 index 000000000..7eaf56c3d --- /dev/null +++ b/cmake/DetermineTargetArch.cmake @@ -0,0 +1,53 @@ +function(determine_target_arch OUTPUT_VARIABLE) + if("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC") + if("${MSVC_C_ARCHITECTURE_ID}" STREQUAL "X86") + set(ARCH "i686") + elseif("${MSVC_C_ARCHITECTURE_ID}" STREQUAL "x64") + set(ARCH "x86_64") + elseif("${MSVC_C_ARCHITECTURE_ID}" STREQUAL "ARM") + set(ARCH "arm") + elseif("${MSVC_C_ARCHITECTURE_ID}" STREQUAL "ARM64") + set(ARCH "arm64") + else() + message(FATAL_ERROR "Unrecognized architecture ${MSVC_C_ARCHITECTURE_ID} from ${CMAKE_C_COMPILER}") + endif() + elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") + if("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") + set(CMD_ARGS "-target" "${CMAKE_C_COMPILER_TARGET}" "-dumpmachine") + else() + set(CMD_ARGS "-dumpmachine") + endif() + execute_process( + COMMAND + ${CMAKE_C_COMPILER} ${CMD_ARGS} + RESULT_VARIABLE + RESULT + OUTPUT_VARIABLE + ARCH + ERROR_QUIET) + if(RESULT) + message(FATAL_ERROR "Failed to determine target architecture triplet: ${RESULT}") + endif() + string(REGEX MATCH "([^-]+).*" ARCH_MATCH ${ARCH}) + if(NOT CMAKE_MATCH_1 OR NOT ARCH_MATCH) + message(FATAL_ERROR "Failed to match the target architecture triplet: ${ARCH}") + endif() + set(ARCH ${CMAKE_MATCH_1}) + + if("${ARCH}" STREQUAL "x86_64") + # Do nothing + elseif("${ARCH}" STREQUAL "aarch64") + set(ARCH "arm64") + elseif("${ARCH}" STREQUAL "i686") + # Do nothing + elseif("${ARCH}" STREQUAL "i386") + # Do nothing + else() + message(FATAL_ERROR "Unrecognized architecture ${ARCH} from ${CMAKE_C_COMPILER}") + endif() + else() + message(FATAL_ERROR "Unrecognized Compiler ${CMAKE_C_COMPILER_ID}") + endif() + message(STATUS "Target architecture - ${ARCH}") + set(${OUTPUT_VARIABLE} ${ARCH} PARENT_SCOPE) +endfunction() diff --git a/cmake/toolchains/arm64-linux-clang.cmake b/cmake/toolchains/arm64-linux-clang.cmake new file mode 100644 index 000000000..6a9f2b463 --- /dev/null +++ b/cmake/toolchains/arm64-linux-clang.cmake @@ -0,0 +1,22 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +# the name of the target OS and arch +SET(CMAKE_SYSTEM_NAME Linux) +SET(CMAKE_SYSTEM_PROCESSOR arm64) +SET(triple aarch64-linux-gnu) + +# which compilers to use +SET(CMAKE_C_COMPILER "clang-6.0") +SET(CMAKE_C_COMPILER_TARGET ${triple}) +SET(CMAKE_CXX_COMPILER "clang++-6.0") +SET(CMAKE_CXX_COMPILER_TARGET ${triple}) + +# Tell pkgconfig to use aarch64 +SET(ENV{PKG_CONFIG_PATH} "/usr/lib/aarch64-linux-gnu/pkgconfig") + +# Tell CMake to use qemu to emulate +# Note: This should be automatically done by Ubuntu using binfmt_misc, but that +# seems to be broken on WSL (https://github.com/microsoft/WSL/issues/2620) so +# explicitly setting the emulator for now. +SET(CMAKE_CROSSCOMPILING_EMULATOR qemu-aarch64-static) diff --git a/cmake/toolchains/arm64-linux-gnu.cmake b/cmake/toolchains/arm64-linux-gnu.cmake new file mode 100644 index 000000000..73d076241 --- /dev/null +++ b/cmake/toolchains/arm64-linux-gnu.cmake @@ -0,0 +1,19 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +# the name of the target OS and arch +SET(CMAKE_SYSTEM_NAME Linux) +SET(CMAKE_SYSTEM_PROCESSOR arm64) + +# which compilers to use +SET(CMAKE_C_COMPILER aarch64-linux-gnu-gcc) +SET(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++) + +# Tell pkgconfig to use arm64 +SET(ENV{PKG_CONFIG_PATH} "/usr/lib/aarch64-linux-gnu/pkgconfig") + +# Tell CMake to use qemu to emulate +# Note: This should be automatically done by Ubuntu using binfmt_misc, but that +# seems to be broken on WSL (https://github.com/microsoft/WSL/issues/2620) so +# explicitly setting the emulator for now. +SET(CMAKE_CROSSCOMPILING_EMULATOR qemu-aarch64-static) diff --git a/cmake/toolchains/x86_64-linux-clang.cmake b/cmake/toolchains/x86_64-linux-clang.cmake index 78cc3931f..2a810e192 100644 --- a/cmake/toolchains/x86_64-linux-clang.cmake +++ b/cmake/toolchains/x86_64-linux-clang.cmake @@ -4,12 +4,13 @@ # the name of the target OS and arch SET(CMAKE_SYSTEM_NAME Linux) SET(CMAKE_SYSTEM_PROCESSOR x86_64) +SET(triple x86_64-linux-gnu) # which compilers to use SET(CMAKE_C_COMPILER "clang-6.0") -SET(CMAKE_C_FLAGS -m64) +SET(CMAKE_C_COMPILER_TARGET ${triple}) SET(CMAKE_CXX_COMPILER "clang++-6.0") -SET(CMAKE_CXX_FLAGS -m64) +SET(CMAKE_CXX_COMPILER_TARGET ${triple}) # save flags to cache SET(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} CACHE STRING "C Flags" FORCE) diff --git a/scripts/Dockerfile b/scripts/Dockerfile deleted file mode 100644 index b77b9c5bb..000000000 --- a/scripts/Dockerfile +++ /dev/null @@ -1,34 +0,0 @@ -# Use the official ubuntu:18.04 image as the parent image -FROM ubuntu:18.04 - -# Tell Ubuntu non-interactive install -ARG DEBIAN_FRONTEND=noninteractive - -# Set the working directory to /app -WORKDIR /app - -# Run apt-get steps -RUN apt-get update && apt-get install -y \ - pkg-config \ - ninja-build \ - doxygen \ - clang \ - gcc-multilib \ - g++-multilib \ - python3 \ - git-lfs \ - nasm \ - cmake \ - libgl1-mesa-dev \ - libsoundio-dev \ - libvulkan-dev \ - libx11-dev \ - libxcursor-dev \ - libxinerama-dev \ - libxrandr-dev \ - libusb-1.0-0-dev \ - libssl-dev \ - libudev-dev \ - mesa-common-dev \ - uuid-dev \ - libopencv-dev diff --git a/scripts/docker/Dockerfile b/scripts/docker/Dockerfile new file mode 100644 index 000000000..a0006c0ba --- /dev/null +++ b/scripts/docker/Dockerfile @@ -0,0 +1,20 @@ +ARG UBUNTU_VERSION=18.04 +# Use the official ubuntu:18.04 image as the parent image +FROM ubuntu:${UBUNTU_VERSION} + +# Set the working directory to /app +WORKDIR /app + +ARG ARCH=amd64 + +ADD setup-ubuntu.sh /app +ADD sources.list /app + +# Tell Ubuntu non-interactive install +ARG DEBIAN_FRONTEND=noninteractive + + +RUN ./setup-ubuntu.sh ${ARCH} + +RUN apt-get install -y ca-certificates +RUN update-ca-certificates \ No newline at end of file diff --git a/scripts/docker/setup-ubuntu.sh b/scripts/docker/setup-ubuntu.sh new file mode 100644 index 000000000..9bf440bfc --- /dev/null +++ b/scripts/docker/setup-ubuntu.sh @@ -0,0 +1,75 @@ +#!/bin/bash + +# Usage: +# ./setup-ubuntu.sh [arm64 | amd64] + +# Warning! This will override your sources.list file!! + +arch=amd64 + +# Copy off old sources.list file +cp /etc/apt/sources.list /etc/apt/sources.list.old +echo "Backed up /etc/apt/sources.list to /etc/apt/sources.list.old" + +# Copy over the new file +cp sources.list /etc/apt/sources.list +echo "Overwrote /etc/apt/sources.list with sources.list" + +apt-get update + +apt-get install wget -y + +# Add Public microsoft repo keys to the image +wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb +dpkg -i packages-microsoft-prod.deb + +if [ "$1" = "arm64" ]; then + arch="arm64" +fi + +echo "Setting up for building $arch binaries" + +dpkg --add-architecture amd64 +dpkg --add-architecture arm64 + +apt-get update + +packages=(\ + gcc-aarch64-linux-gnu \ + g++-aarch64-linux-gnu \ + file \ + dpkg-dev \ + qemu \ + binfmt-support \ + qemu-user-static \ + pkg-config \ + ninja-build \ + doxygen \ + clang \ + python3 \ + gcc \ + g++ \ + git \ + git-lfs \ + nasm \ + cmake \ + powershell \ + libgl1-mesa-dev:$arch \ + libsoundio-dev:$arch \ + libjpeg-dev:$arch \ + libvulkan-dev:$arch \ + libx11-dev:$arch \ + libxcursor-dev:$arch \ + libxinerama-dev:$arch \ + libxrandr-dev:$arch \ + libusb-1.0-0-dev:$arch \ + libssl-dev:$arch \ + libudev-dev:$arch \ + mesa-common-dev:$arch \ + uuid-dev:$arch ) + +if [ "$arch" = "amd64" ]; then + packages+=(libopencv-dev:$arch) +fi + +apt-get install -y --no-install-recommends ${packages[@]} \ No newline at end of file diff --git a/scripts/docker/sources.list b/scripts/docker/sources.list new file mode 100644 index 000000000..28fe9d19d --- /dev/null +++ b/scripts/docker/sources.list @@ -0,0 +1,26 @@ + +deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ bionic main restricted +deb [arch=arm64] http://ports.ubuntu.com/ bionic main restricted + +deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ bionic-updates main restricted +deb [arch=arm64] http://ports.ubuntu.com/ bionic-updates main restricted + +deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ bionic universe +deb [arch=arm64] http://ports.ubuntu.com/ bionic universe +deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ bionic-updates universe +deb [arch=arm64] http://ports.ubuntu.com/ bionic-updates universe + +deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ bionic multiverse +deb [arch=arm64] http://ports.ubuntu.com/ bionic multiverse +deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ bionic-updates multiverse +deb [arch=arm64] http://ports.ubuntu.com/ bionic-updates multiverse + +deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ bionic-backports main restricted universe multiverse +deb [arch=arm64] http://ports.ubuntu.com/ bionic-backports main restricted universe multiverse + +deb [arch=amd64] http://security.ubuntu.com/ubuntu/ bionic-security main restricted +deb [arch=arm64] http://ports.ubuntu.com/ bionic-security main restricted +deb [arch=amd64] http://security.ubuntu.com/ubuntu/ bionic-security universe +deb [arch=arm64] http://ports.ubuntu.com/ bionic-security universe +deb [arch=amd64] http://security.ubuntu.com/ubuntu/ bionic-security multiverse +deb [arch=arm64] http://ports.ubuntu.com/ bionic-security multiverse \ No newline at end of file diff --git a/src/transformation/rgbz.c b/src/transformation/rgbz.c index bdffbad3c..1cc4afac6 100644 --- a/src/transformation/rgbz.c +++ b/src/transformation/rgbz.c @@ -8,9 +8,12 @@ #include #include +#if defined(__amd64__) || defined(_M_AMD64) || defined(__i386__) || defined(_M_X86) +#define K4A_USING_SSE #include // SSE2 #include // SSE3 #include // SSE4.1 +#endif typedef struct _k4a_transformation_input_image_t { @@ -1055,42 +1058,45 @@ k4a_buffer_result_t transformation_color_image_to_depth_camera_internal( return K4A_BUFFER_RESULT_SUCCEEDED; } +#if !defined(K4A_USING_SSE) // This is the same function as transformation_depth_to_xyz without the SSE // instructions. This code is kept here for readability. -// static void transformation_depth_to_xyz(k4a_transformation_xy_tables_t *xy_tables, -// const void *depth_image_data, -// void *xyz_image_data) -// { -// const uint16_t *depth_image_data_uint16 = (const uint16_t *)depth_image_data; -// int16_t *xyz_data_int16 = (int16_t *)xyz_image_data; -// int16_t x, y, z; - -// for (int i = 0; i < xy_tables->width * xy_tables->height; i++) -// { -// float x_tab = xy_tables->x_table[i]; - -// if (!isnan(x_tab)) -// { -// z = (int16_t)depth_image_data_uint16[i]; -// x = (int16_t)(floorf(x_tab * (float)z + 0.5f)); -// y = (int16_t)(floorf(xy_tables->y_table[i] * (float)z + 0.5f)); -// } -// else -// { -// x = 0; -// y = 0; -// z = 0; -// } - -// xyz_data_int16[3 * i + 0] = x; -// xyz_data_int16[3 * i + 1] = y; -// xyz_data_int16[3 * i + 2] = z; -// } -// } - -static void transformation_depth_to_xyz_sse(k4a_transformation_xy_tables_t *xy_tables, - const void *depth_image_data, - void *xyz_image_data) +static void transformation_depth_to_xyz(k4a_transformation_xy_tables_t *xy_tables, + const void *depth_image_data, + void *xyz_image_data) +{ + const uint16_t *depth_image_data_uint16 = (const uint16_t *)depth_image_data; + int16_t *xyz_data_int16 = (int16_t *)xyz_image_data; + int16_t x, y, z; + + for (int i = 0; i < xy_tables->width * xy_tables->height; i++) + { + float x_tab = xy_tables->x_table[i]; + + if (!isnan(x_tab)) + { + z = (int16_t)depth_image_data_uint16[i]; + x = (int16_t)(floorf(x_tab * (float)z + 0.5f)); + y = (int16_t)(floorf(xy_tables->y_table[i] * (float)z + 0.5f)); + } + else + { + x = 0; + y = 0; + z = 0; + } + + xyz_data_int16[3 * i + 0] = x; + xyz_data_int16[3 * i + 1] = y; + xyz_data_int16[3 * i + 2] = z; + } +} + +#else + +static void transformation_depth_to_xyz(k4a_transformation_xy_tables_t *xy_tables, + const void *depth_image_data, + void *xyz_image_data) { const __m128i *depth_image_data_m128i = (const __m128i *)depth_image_data; #if defined(__clang__) || defined(__GNUC__) @@ -1159,6 +1165,7 @@ static void transformation_depth_to_xyz_sse(k4a_transformation_xy_tables_t *xy_t *xyz_data_m128i++ = _mm_blend_epi16(_mm_blend_epi16(x, y, 0x49), z, 0x92); } } +#endif k4a_buffer_result_t transformation_depth_image_to_point_cloud_internal(k4a_transformation_xy_tables_t *xy_tables, @@ -1207,7 +1214,7 @@ transformation_depth_image_to_point_cloud_internal(k4a_transformation_xy_tables_ return K4A_BUFFER_RESULT_FAILED; } - transformation_depth_to_xyz_sse(xy_tables, (const void *)depth_image_data, (void *)xyz_image_data); + transformation_depth_to_xyz(xy_tables, (const void *)depth_image_data, (void *)xyz_image_data); return K4A_BUFFER_RESULT_SUCCEEDED; }