Skip to content

Commit

Permalink
Merge pull request #169 from cocoa-xu/cx-cuda
Browse files Browse the repository at this point in the history
CUDA support
  • Loading branch information
cocoa-xu authored Jan 16, 2023
2 parents 1d17ff4 + d4eb6c7 commit e697d97
Show file tree
Hide file tree
Showing 37 changed files with 2,115 additions and 274 deletions.
164 changes: 164 additions & 0 deletions .github/workflows/linux-cuda-gnu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
name: linux-cuda

on:
pull_request:
types: [ labeled, synchronize, opened, reopened ]
paths-ignore:
- '*.md'
- '**/*.md'
- 'LICENSE*'
- 'examples/**'
- 'nerves/**'
- 'Makefile.win'
- 'cc_toolchain/**'
- 'checksum.exs'
- '.github/FUNDING.yml'
- '.github/workflows/nerves-*'
- '.github/workflows/macos-*'
- '.github/workflows/windows-*'
- '.github/workflows/test-*.yml'
- '.github/workflows/linux-x86_64.yml'
- '.github/workflows/linux-arm64.yml'
- '.github/workflows/linux-armv7.yml'
- '.github/workflows/linux-ppc64le.yml'
- '.github/workflows/linux-s390x.yml'
- '.github/workflows/linux-precompile-*.yml'
push:
branches:
- main
paths-ignore:
- '*.md'
- '**/*.md'
- 'LICENSE*'
- 'examples/**'
- 'nerves/**'
- 'Makefile.win'
- 'cc_toolchain/**'
- 'checksum.exs'
- '.github/FUNDING.yml'
- '.github/workflows/nerves-*'
- '.github/workflows/macos-*'
- '.github/workflows/windows-*'
- '.github/workflows/test-*.yml'
- '.github/workflows/linux-x86_64.yml'
- '.github/workflows/linux-arm64.yml'
- '.github/workflows/linux-armv7.yml'
- '.github/workflows/linux-ppc64le.yml'
- '.github/workflows/linux-s390x.yml'
- '.github/workflows/linux-precompile-*.yml'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
x86_64-gnu-cuda:
if: contains(github.event.pull_request.labels.*.name, 'cuda')
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
include:
- container: nvidia/cuda:11.1.1-cudnn8-devel-ubuntu20.04
cuda_ver: "11.1.1"
cuda_id: "111"
- container: nvidia/cuda:11.4.3-cudnn8-devel-ubuntu20.04
cuda_ver: "11.4.3"
cuda_id: "114"
- container: nvidia/cuda:11.8.0-cudnn8-devel-ubuntu20.04
cuda_ver: "11.8.0"
cuda_id: "118"
container: ${{ matrix.container }}
env:
# container env vars
# ref link: https://github.com/elixir-nx/xla/blob/main/.github/workflows/release.yml
ImageOS: ubuntu20
LANG: en_US.UTF-8
LANGUAGE: en_US:en
LC_ALL: en_US.UTF-8
DEBIAN_FRONTEND: noninteractive
# evision related env vars
MIX_ENV: test
OPENCV_VER: "4.7.0"
OTP_VERSION: "25.2"
ELIXIR_VERSION: "1.14.3"
EVISION_PREFER_PRECOMPILED: "false"
EVISION_ENABLE_CUDA: "true"
PKG_CONFIG_PATH: "/usr/lib/x86_64-linux-gnu/pkgconfig"
steps:
- uses: actions/checkout@v3

- name: Install system dependencies
run: |
apt-get update
apt-get install -y build-essential automake autoconf pkg-config bc m4 unzip zip curl git libssl-dev gzip python3 ca-certificates \
libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libavresample-dev ffmpeg locales curl wget cmake
echo "${LANG} UTF-8" >> /etc/locale.gen
locale-gen
update-locale LANG=${LANG}
- uses: erlef/setup-beam@v1
with:
otp-version: ${{ env.OTP_VERSION }}
elixir-version: ${{ env.ELIXIR_VERSION }}

- name: Cache mix packages
id: cache-mix-deps
uses: actions/cache@v3
with:
key: deps-${{ hashFiles('mix.lock') }}-${{ env.OTP_VERSION }}-${{ env.ELIXIR_VERSION }}
path: |
./deps
- name: Get mix deps
if: steps.cache-mix-deps.outputs.cache-hit != 'true'
run: |
mix deps.get
- name: Cache OpenCV
id: cache-opencv
uses: actions/cache@v3
with:
key: opencv-with-contrib-${{ env.OPENCV_VER }}
path: |
./3rd_party
- name: Download OpenCV
if: steps.cache-opencv.outputs.cache-hit != 'true'
run: |
bash scripts/download_opencv.sh ${OPENCV_VER} 3rd_party/cache 3rd_party/opencv/
bash scripts/download_opencv_contrib.sh ${OPENCV_VER} 3rd_party/cache 3rd_party/opencv/
- name: Cache compiled OpenCV
id: cache-mix-compile_opencv
uses: actions/cache@v3
with:
key: compiled-opencv-${{ env.OPENCV_VER }}-cuda${{ matrix.cuda_ver }}-x86_64-linux-gnu-${{ hashFiles('Makefile') }}
path: |
./_build/${{ env.MIX_ENV }}/lib/evision
./c_src/headers.txt
./c_src/configuration.private.hpp
- name: Compile OpenCV
if: steps.cache-mix-compile_opencv.outputs.cache-hit != 'true'
run: |
mix compile_opencv
- name: Mix Compile
run: |
rm -f _build/${{ env.MIX_ENV }}/lib/evision/priv/evision.so
ls -la ./c_src
mix compile
ls -la ./lib/generated
- name: Cache testdata
id: cache-mix-testdata
uses: actions/cache@v3
with:
key: testdata-${{ hashFiles('test/downloading_list.txt') }}
path: |
./test/testdata
- name: Mix Test
run: |
mix test --include require_downloading --include require_ffmpeg
126 changes: 126 additions & 0 deletions .github/workflows/linux-precompile-cuda-gnu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
name: linux-precompile-cuda-gnu

on:
push:
tags:
- 'v*'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
mix_compile:
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
include:
- container: nvidia/cuda:11.1.1-cudnn8-devel-ubuntu20.04
cuda_ver: "11.1.1"
cuda_id: "111"
- container: nvidia/cuda:11.4.3-cudnn8-devel-ubuntu20.04
cuda_ver: "11.4.3"
cuda_id: "114"
- container: nvidia/cuda:11.8.0-cudnn8-devel-ubuntu20.04
cuda_ver: "11.8.0"
cuda_id: "118"
container: ${{ matrix.container }}
env:
# container env vars
# ref link: https://github.com/elixir-nx/xla/blob/main/.github/workflows/release.yml
ImageOS: ubuntu20
LANG: en_US.UTF-8
LANGUAGE: en_US:en
LC_ALL: en_US.UTF-8
DEBIAN_FRONTEND: noninteractive
# evision related env vars
MIX_ENV: test
OPENCV_VER: "4.7.0"
OTP_VERSION: "25.2"
ELIXIR_VERSION: "1.14.3"
EVISION_PREFER_PRECOMPILED: "false"
EVISION_ENABLE_CUDA: "true"
PKG_CONFIG_PATH: "/usr/lib/x86_64-linux-gnu/pkgconfig"
steps:
- uses: actions/checkout@v3

- name: Install system dependencies
run: |
apt-get update
apt-get install -y build-essential automake autoconf pkg-config bc m4 unzip zip curl git libssl-dev gzip python3 ca-certificates \
locales curl wget cmake
echo "${LANG} UTF-8" >> /etc/locale.gen
locale-gen
update-locale LANG=${LANG}
- uses: erlef/setup-beam@v1
with:
otp-version: ${{ env.OTP_VERSION }}
elixir-version: ${{ env.ELIXIR_VERSION }}

- name: Cache mix packages
id: cache-mix-deps
uses: actions/cache@v3
with:
key: deps-${{ hashFiles('mix.lock') }}-${{ env.OTP_VERSION }}-${{ env.ELIXIR_VERSION }}
path: |
./deps
- name: Get mix deps
if: steps.cache-mix-deps.outputs.cache-hit != 'true'
run: |
mix deps.get
- name: Cache OpenCV
id: cache-opencv
uses: actions/cache@v3
with:
key: opencv-with-contrib-${{ env.OPENCV_VER }}
path: |
./3rd_party
- name: Download OpenCV
if: steps.cache-opencv.outputs.cache-hit != 'true'
run: |
bash scripts/download_opencv.sh ${OPENCV_VER} 3rd_party/cache 3rd_party/opencv/
bash scripts/download_opencv_contrib.sh ${OPENCV_VER} 3rd_party/cache 3rd_party/opencv/
- name: Cache compiled OpenCV
id: cache-mix-compile_opencv
uses: actions/cache@v3
with:
key: precompiled-opencv-${{ env.OPENCV_VER }}-cuda${{ matrix.cuda_ver }}-x86_64-linux-gnu-${{ hashFiles('Makefile') }}
path: |
./_build/${{ env.MIX_ENV }}/lib/evision
./c_src/headers.txt
./c_src/configuration.private.hpp
- name: Compile OpenCV
if: steps.cache-mix-compile_opencv.outputs.cache-hit != 'true'
run: |
mix compile_opencv
- name: Mix Compile
run: |
rm -f _build/${{ env.MIX_ENV }}/lib/evision/priv/evision.so
ls -la ./c_src
mix compile
ls -la ./lib/generated
- name: Create precompiled library
run: |
export PKG_NAME=evision-nif_${NIF_VERSION}-x86_64-linux-gnu-contrib-cuda${{ matrix.cuda_ver }}-${GITHUB_REF##*/v}
mkdir -p "${PKG_NAME}"
cp -a _build/${MIX_ENV}/lib/evision/priv "${PKG_NAME}"
cp -a lib/generated "${PKG_NAME}/elixir_generated"
cp -a src/generated "${PKG_NAME}/erlang_generated"
tar -czf "${PKG_NAME}.tar.gz" "${PKG_NAME}"
rm -rf "${PKG_NAME}"
ls -lah "${PKG_NAME}.tar.gz"
mkdir -p artifacts
mv "${PKG_NAME}.tar.gz" artifacts
- uses: softprops/action-gh-release@v1
with:
files: artifacts/*.tar.gz
4 changes: 2 additions & 2 deletions .github/workflows/linux-precompile-gnu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ jobs:
env:
OPENCV_VER: "4.7.0"
MIX_ENV: prod
OTP_VERSION: "25.1.2"
OTP_VERSION: "25.2"
NIF_VERSION: "2.16"
ELIXIR_VERSION: "1.14.2"
ELIXIR_VERSION: "1.14.3"
EVISION_PREFER_PRECOMPILED: "false"
EVISION_GENERATE_LANG: "erlang,elixir"
strategy:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/linux-precompile-musl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ jobs:
env:
MIX_ENV: prod
OPENCV_VER: "4.7.0"
OTP_VERSION: "25.1.2"
OTP_VERSION: "25.2"
NIF_VERSION: "2.16"
ELIXIR_VERSION: "1.14.2"
ELIXIR_VERSION: "1.14.3"
EVISION_PREFER_PRECOMPILED: "false"
EVISION_GENERATE_LANG: "erlang,elixir"
steps:
Expand Down Expand Up @@ -170,9 +170,9 @@ jobs:
env:
OPENCV_VER: "4.7.0"
MIX_ENV: prod
OTP_VERSION: "25.1.2"
OTP_VERSION: "25.2"
NIF_VERSION: "2.16"
ELIXIR_VERSION: "1.14.2"
ELIXIR_VERSION: "1.14.3"
ZIG_VERSION: "0.8.0"
EVISION_PREFER_PRECOMPILED: "false"
EVISION_GENERATE_LANG: "erlang,elixir"
Expand Down
20 changes: 11 additions & 9 deletions .github/workflows/linux-x86_64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ on:
- '.github/workflows/linux-armv7.yml'
- '.github/workflows/linux-ppc64le.yml'
- '.github/workflows/linux-s390x.yml'
- '.github/workflows/linux-cuda-*.yml'
- '.github/workflows/linux-precompile-*.yml'
push:
branches:
Expand All @@ -46,6 +47,7 @@ on:
- '.github/workflows/linux-armv7.yml'
- '.github/workflows/linux-ppc64le.yml'
- '.github/workflows/linux-s390x.yml'
- '.github/workflows/linux-cuda-*.yml'
- '.github/workflows/linux-precompile-*.yml'

concurrency:
Expand All @@ -59,8 +61,8 @@ jobs:
env:
MIX_ENV: test
OPENCV_VER: "4.7.0"
OTP_VERSION: "25.1.2"
ELIXIR_VERSION: "1.14.2"
OTP_VERSION: "25.2"
ELIXIR_VERSION: "1.14.3"
EVISION_PREFER_PRECOMPILED: "false"
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -153,13 +155,13 @@ jobs:
env:
MIX_ENV: test
OPENCV_VER: "4.7.0"
OTP_VERSION: "25.1.2"
ELIXIR_VERSION: "1.14.2"
OTP_VERSION: "25.2"
ELIXIR_VERSION: "1.14.3"
EVISION_PREFER_PRECOMPILED: "false"

PKG_CONFIG_PATH: "/usr/lib/x86_64-linux-gnu/pkgconfig"
steps:
- uses: actions/checkout@v3

- uses: erlef/setup-beam@v1
with:
otp-version: ${{ env.OTP_VERSION }}
Expand All @@ -168,8 +170,8 @@ jobs:
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential automake autoconf pkg-config bc m4 unzip zip curl git libssl-dev gzip libncurses5-dev erlang-inets erlang-os-mon erlang-runtime-tools erlang-ssl erlang-dev python3 ca-certificates
sudo apt-get install -y libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libavresample-dev ffmpeg
sudo apt-get install -y build-essential automake autoconf pkg-config bc m4 unzip zip curl git libssl-dev gzip python3 ca-certificates \
libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libavresample-dev ffmpeg
- name: Cache mix packages
id: cache-mix-deps
Expand Down Expand Up @@ -235,4 +237,4 @@ jobs:
- name: Mix Test
run: |
mix test --include require_downloading --include require_ffmpeg --exclude may_crash
mix test --include require_downloading --include require_ffmpeg
Loading

0 comments on commit e697d97

Please sign in to comment.