From 9e984fe93b6bd3bb3c9b9b6277292d4ab8711b45 Mon Sep 17 00:00:00 2001 From: ArchieMeng Date: Tue, 4 May 2021 20:56:19 +0800 Subject: [PATCH] Add supports for Ubuntu 18.04 and other Linux Distro with GLIBC Version < 2.29 and cmake version < 3.15 Signed-off-by: ArchieMeng --- .github/workflows/CI.yml | 26 ++++++++++++ .github/workflows/release.yml | 75 ++++++++++++++++++++++++++++++----- README.md | 2 + src/CMakeLists.txt | 17 ++++++-- 4 files changed, 107 insertions(+), 13 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 06bc825..f6ae583 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -69,6 +69,32 @@ jobs: cmake ../src cmake --build . -j 2 + ubuntu-1804: # no needs to install swig for it is already there + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + with: + submodules: 'recursive' + - name: cache-vulkansdk + id: cache-vulkansdk + uses: actions/cache@v1 + with: + path: "1.2.162.0" + key: vulkansdk-linux-x86_64-1.2.162.0 + - name: vulkansdk + if: steps.cache-vulkansdk.outputs.cache-hit != 'true' + run: | + wget https://sdk.lunarg.com/sdk/download/1.2.162.0/linux/vulkansdk-linux-x86_64-1.2.162.0.tar.gz?Human=true -O vulkansdk-linux-x86_64-1.2.162.0.tar.gz + tar -xf vulkansdk-linux-x86_64-1.2.162.0.tar.gz + rm -rf 1.2.162.0/source 1.2.162.0/samples + find 1.2.162.0 -type f | grep -v -E 'vulkan|glslang' | xargs rm + - name: build + run: | + export VULKAN_SDK=`pwd`/1.2.162.0/x86_64 + mkdir build && cd build + cmake ../src + cmake --build . -j 2 + macos: runs-on: macos-latest steps: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index df439e1..6619f89 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,6 +7,7 @@ on: env: DEVELOPER_DIR: /Applications/Xcode_12.2.app/Contents/Developer APPLICATION_NAME: srmd-ncnn-vulkan-python + APPNAME_SHORT: srmd jobs: @@ -55,9 +56,9 @@ jobs: run: | mkdir -p ${{ env.PACKAGENAME }} cp README.md LICENSE ${{ env.PACKAGENAME }} - cp build/srmd_ncnn_vulkan.py ${{ env.PACKAGENAME }} - cp build/srmd_ncnn_vulkan_wrapper.py ${{ env.PACKAGENAME }} - cp build/_srmd_ncnn_vulkan_wrapper.so ${{ env.PACKAGENAME }} + cp build/${{ env.APPNAME_SHORT }}_ncnn_vulkan.py ${{ env.PACKAGENAME }} + cp build/${{ env.APPNAME_SHORT }}_ncnn_vulkan_wrapper.py ${{ env.PACKAGENAME }} + cp build/_${{ env.APPNAME_SHORT }}_ncnn_vulkan_wrapper.so ${{ env.PACKAGENAME }} cp -r models/ ${{ env.PACKAGENAME }} zip -9 -r ${{ env.PACKAGENAME }}.zip ${{ env.PACKAGENAME }} - name: upload @@ -66,6 +67,49 @@ jobs: name: ${{ env.PACKAGENAME }} path: ${{ env.PACKAGENAME }}.zip + ubuntu-1804: + needs: [setup] + runs-on: ubuntu-18.04 + env: + PACKAGENAME: ${{ needs.setup.outputs.APPNAME }}-${{ needs.setup.outputs.VERSION }}-ubuntu-1804 + steps: + - uses: actions/checkout@v2 + with: + submodules: 'recursive' + - name: cache-vulkansdk + id: cache-vulkansdk + uses: actions/cache@v1 + with: + path: "1.2.162.0" + key: vulkansdk-linux-x86_64-1.2.162.0 + - name: vulkansdk + if: steps.cache-vulkansdk.outputs.cache-hit != 'true' + run: | + wget https://sdk.lunarg.com/sdk/download/1.2.162.0/linux/vulkansdk-linux-x86_64-1.2.162.0.tar.gz?Human=true -O vulkansdk-linux-x86_64-1.2.162.0.tar.gz + tar -xf vulkansdk-linux-x86_64-1.2.162.0.tar.gz + rm -rf 1.2.162.0/source 1.2.162.0/samples + find 1.2.162.0 -type f | grep -v -E 'vulkan|glslang' | xargs rm + - name: build + run: | + export VULKAN_SDK=`pwd`/1.2.162.0/x86_64 + mkdir build && cd build + cmake ../src + cmake --build . -j 2 + - name: package + run: | + mkdir -p ${{ env.PACKAGENAME }} + cp README.md LICENSE ${{ env.PACKAGENAME }} + cp build/${{ env.APPNAME_SHORT }}_ncnn_vulkan.py ${{ env.PACKAGENAME }} + cp build/${{ env.APPNAME_SHORT }}_ncnn_vulkan_wrapper.py ${{ env.PACKAGENAME }} + cp build/_${{ env.APPNAME_SHORT }}_ncnn_vulkan_wrapper.so ${{ env.PACKAGENAME }} + cp -r models/ ${{ env.PACKAGENAME }} + zip -9 -r ${{ env.PACKAGENAME }}.zip ${{ env.PACKAGENAME }} + - name: upload + uses: actions/upload-artifact@v2 + with: + name: ${{ env.PACKAGENAME }} + path: ${{ env.PACKAGENAME }}.zip + openmp-macos: runs-on: macos-latest steps: @@ -182,9 +226,9 @@ jobs: run: | mkdir -p ${{ env.PACKAGENAME }} cp README.md LICENSE ${{ env.PACKAGENAME }} - cp build-x86_64/srmd_ncnn_vulkan.py ${{ env.PACKAGENAME }} - cp build-x86_64/srmd_ncnn_vulkan_wrapper.py ${{ env.PACKAGENAME }} - cp build-x86_64/_srmd_ncnn_vulkan_wrapper.so ${{ env.PACKAGENAME }} + cp build-x86_64/${{ env.APPNAME_SHORT }}_ncnn_vulkan.py ${{ env.PACKAGENAME }} + cp build-x86_64/${{ env.APPNAME_SHORT }}_ncnn_vulkan_wrapper.py ${{ env.PACKAGENAME }} + cp build-x86_64/_${{ env.APPNAME_SHORT }}_ncnn_vulkan_wrapper.so ${{ env.PACKAGENAME }} cp -r models/ ${{ env.PACKAGENAME }} zip -9 -r ${{ env.PACKAGENAME }}.zip ${{ env.PACKAGENAME }} - name: upload @@ -241,9 +285,9 @@ jobs: ls build Copy-Item -Verbose -Path "README.md" -Destination "${{ env.PACKAGENAME }}" Copy-Item -Verbose -Path "LICENSE" -Destination "${{ env.PACKAGENAME }}" - Copy-Item -Verbose -Path "src\srmd_ncnn_vulkan.py" -Destination "${{ env.PACKAGENAME }}" - Copy-Item -Verbose -Path "build\srmd_ncnn_vulkan_wrapper.py" -Destination "${{ env.PACKAGENAME }}" - Copy-Item -Verbose -Path "build\Release\_srmd_ncnn_vulkan_wrapper.pyd" -Destination "${{ env.PACKAGENAME }}" + Copy-Item -Verbose -Path "src\${{ env.APPNAME_SHORT }}_ncnn_vulkan.py" -Destination "${{ env.PACKAGENAME }}" + Copy-Item -Verbose -Path "build\${{ env.APPNAME_SHORT }}_ncnn_vulkan_wrapper.py" -Destination "${{ env.PACKAGENAME }}" + Copy-Item -Verbose -Path "build\Release\_${{ env.APPNAME_SHORT }}_ncnn_vulkan_wrapper.pyd" -Destination "${{ env.PACKAGENAME }}" Copy-Item -Verbose -Path "C:\windows\system32\vcomp140.dll" -Destination "${{ env.PACKAGENAME }}" Copy-Item -Verbose -Recurse -Path "models" -Destination "${{ env.PACKAGENAME }}" 7z a -r ${{ env.PACKAGENAME }}.zip ${{ env.PACKAGENAME }} @@ -254,7 +298,7 @@ jobs: path: ${{ env.PACKAGENAME }}.zip release: - needs: [setup, ubuntu, macos, windows] + needs: [setup, ubuntu, ubuntu-1804, macos, windows] runs-on: ubuntu-latest steps: - name: download @@ -284,6 +328,17 @@ jobs: asset_name: ${{ env.PACKAGENAME }}.zip asset_content_type: application/zip + - name: upload-ubuntu-1804 + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PACKAGENAME: ${{ needs.setup.outputs.APPNAME }}-${{ needs.setup.outputs.VERSION }}-ubuntu-1804 + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: artifacts/${{ env.PACKAGENAME }}/${{ env.PACKAGENAME }}.zip + asset_name: ${{ env.PACKAGENAME }}.zip + asset_content_type: application/zip + - name: upload-macos uses: actions/upload-release-asset@v1 env: diff --git a/README.md b/README.md index 927a507..ea9bb70 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,8 @@ linux x64, Windows x64 and MacOS x64 releases are available now. For other platf The reason why MacOS ARM64 build is not available is that it needs ARM Python Dev Libs which I have no ideas on how to get it on Github's MacOS x64 VM. Moreover, I don't have a Mac. +**However, for Linux (Like Ubuntu 18.04) with an older GLIBC (version < 2.29), you may try to use the ubuntu-1804 release or just compile it on your own.** + ## Build First, you have to install python, python development package (Python native development libs in Visual Studio), vulkan SDK and SWIG on your platform. And then: diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3730a55..268f54b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,12 +1,18 @@ -cmake_minimum_required(VERSION 3.15) +cmake_minimum_required(VERSION 3.9) cmake_policy(SET CMP0091 NEW) set(CMAKE_POLICY_DEFAULT_CMP0091 NEW) set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") project(srmd-ncnn-vulkan-python) +# Python +if (${CMAKE_VERSION} VERSION_LESS "3.15") + find_package(Python REQUIRED) +else() + find_package(Python REQUIRED COMPONENTS Development) +endif() + # SWIG -find_package(Python REQUIRED COMPONENTS Development) find_package(SWIG REQUIRED COMPONENTS python) if(SWIG_FOUND) message("SWIG found: ${SWIG_EXECUTABLE}") @@ -273,4 +279,9 @@ include_directories(.) swig_add_library(srmd_ncnn_vulkan_wrapper LANGUAGE python SOURCES srmd.i srmd.cpp srmd_wrapper.cpp) add_dependencies(srmd_ncnn_vulkan_wrapper generate-spirv) target_compile_options(srmd_ncnn_vulkan_wrapper PUBLIC -fexceptions) -target_link_libraries(srmd_ncnn_vulkan_wrapper ${SRMD_LINK_LIBRARIES} Python::Module) +if (${CMAKE_VERSION} VERSION_LESS "3.15") + include_directories(${PYTHON_INCLUDE_DIRS}) + target_link_libraries(srmd_ncnn_vulkan_wrapper ${SRMD_LINK_LIBRARIES} ${PYTHON_LIBRARIES}) +else() + target_link_libraries(srmd_ncnn_vulkan_wrapper ${SRMD_LINK_LIBRARIES} Python::Module) +endif()