Skip to content

Commit

Permalink
directml,cudaのダウンロードとデプロイを実装した (#1)
Browse files Browse the repository at this point in the history
* DirectMLのダウンロード処理を実装した

* checkout 追加

* cudaライセンス追加

* directml versionをmatrixにした

* DEFAULT_DIRECTML_VERSIONを追加した

* 全てmatrixで指定するようにした

* ASSET_NAMEに変更した

* defalut値を設定

* cuda ダウンロード実装

* CUDAのアップロード処理追加

* 注意点をコメントで書いた

* runnerの判定をちゃんと行うようにした

* Ubuntu->Linuxに変更

* Update .github/actions/download-cuda-libraries/action.yml

Co-authored-by: Hiroshiba <[email protected]>

* workflow_dispatchを有効にしてversionを受け取れるように変更した

* SKIP_UPLOADING_RELEASE_ASSET不要なので削除

#1 (comment)

* cuda,directmlのバージョンをmatrixで設定するように変更した

* matrixだったのをinputsに修正した

* 適切にjobが作成されなかったためinclude -> artifactに変更した

includeだとすでにあるパターンに対して適用するという形になるためcuda_versionに対して適用とするので一つしかjobがつくられないようです

* ライブラリのバージョンは個別に設定するようにしてシンプルに書けるようにした

Co-authored-by: Hiroshiba <[email protected]>
  • Loading branch information
qwerty2501 and Hiroshiba authored Aug 28, 2022
1 parent 6463d65 commit a33b5b7
Show file tree
Hide file tree
Showing 5 changed files with 1,947 additions and 0 deletions.
105 changes: 105 additions & 0 deletions .github/actions/download-cuda-libraries/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
name: download cuda libraries
description: cuda libraryをダウンロードする
inputs:
cudnn_download_url:
description: cudnnのダウンロードURL
required: true
asset_name:
description: assetの名前
required: true
cuda_version:
description: cudaのバージョン
required: true
extract_dir:
description: 出力先のディレクトリ
required: true
runs:
using: "composite"
steps:
- name: Prepare CUDA cache
uses: actions/cache@v2
id: cuda-library-cache
with:
key: v1-cuda-library-cache-${{ inputs.asset_name }}-${{ inputs.cuda_version }}
path: download/cuda
- name: Prepare cuDNN cache
uses: actions/cache@v2
id: cudnn-library-cache
with:
key: v1-cudnn-library-cache-${{ inputs.asset_name }}-${{ inputs.cudnn_download_url }}
path: download/cudnn
- name: Extract CUDNN Library
if: steps.cudnn-library-cache.outputs.cache-hit != 'true'
shell: bash
run: |
set -eux
mkdir -p download/cudnn_tmp
if [[ "${{ runner.os }}" = "Linux" ]]; then
curl -L "${{ inputs.cudnn_download_url }}" > download/cudnn.tar.xz
tar -Jxvf download/cudnn.tar.xz -C download/cudnn_tmp
mkdir -p download/cudnn_tmp/bin
# このディレクトリはcudnnのバージョンによって変わってしまうことがあるので注意すること
mv -v download/cudnn_tmp/**/lib/* download/cudnn_tmp/bin
elif [[ "${{ runner.os }}" = "Windows" ]];then
curl -L "${{ inputs.cudnn_download_url }}" > download/cudnn.zip
unzip download/cudnn.zip cudnn*/bin/*.dll -d download/cudnn_tmp
mkdir -p ./download/cudnn_tmp/bin
# このディレクトリはcudnnのバージョンによって変わってしまうことがあるので注意すること
mv -v ./download/cudnn_tmp/cudnn*/bin/* ./download/cudnn_tmp/bin
fi
mkdir -p download/cudnn/bin
mv download/cudnn_tmp/bin/*.{so*,dll} download/cudnn/bin/ || true
rm -rf download/cudnn_tmp
rm -f download/cudnn.*
mkdir -p ${{ inputs.extract_dir }}
cp -v docs/licenses/cuda/* "${{ inputs.extract_dir }}"
- uses: Jimver/[email protected]
id: cuda-toolkit
with:
method: network
cuda: ${{ inputs.cuda_version }}
- name: Extract CUDA Library
if: steps.cuda-library-cache.outputs.cache-hit != 'true'
shell: bash
run: |
set -eux
CUDA_ROOT=$( echo "${{ steps.cuda-toolkit.outputs.CUDA_PATH }}" | tr '\\' '/' )
mkdir -p download/cuda/bin
if [[ "${{ runner.os }}" = "Linux" ]]; then
cp -v "$CUDA_ROOT/lib64/"*.so* download/cuda/bin/
elif [[ "${{ runner.os }}" = "Windows" ]];then
cp -v "$CUDA_ROOT/bin/"*.dll download/cuda/bin/
fi
- name: Extract Libraries for Windows
shell: bash
if: ${{ runner.os == 'Windows' }}
run: |
# CUDA
ln -sf "$(pwd)/download/cuda/bin"/cublas64_*.dll "${{ inputs.extract_dir }}"
ln -sf "$(pwd)/download/cuda/bin"/cublasLt64_*.dll "${{ inputs.extract_dir }}"
ln -sf "$(pwd)/download/cuda/bin"/cudart64_*.dll "${{ inputs.extract_dir }}"
ln -sf "$(pwd)/download/cuda/bin"/cufft64_*.dll "${{ inputs.extract_dir }}"
ln -sf "$(pwd)/download/cuda/bin"/curand64_*.dll "${{ inputs.extract_dir }}"
# cuDNN
ln -sf "$(pwd)/download/cudnn/bin"/cudnn64_*.dll "${{ inputs.extract_dir }}"
ln -sf "$(pwd)/download/cudnn/bin"/cudnn_*_infer64*.dll "${{ inputs.extract_dir }}"
- name: Extract Libraries for Linux
shell: bash
if: ${{ runner.os == 'Linux' }}
run: |
# CUDA
ln -sf "$(pwd)/download/cuda/bin"/libcublas.so.* "${{ inputs.extract_dir }}"
rm -f "${{ inputs.extract_dir }}"/libcublas.so.*.*
ln -sf "$(pwd)/download/cuda/bin"/libcublasLt.so.* "${{ inputs.extract_dir }}"
rm -f "${{ inputs.extract_dir }}"/libcublasLt.so.*.*
ln -sf "$(pwd)/download/cuda/bin"/libcudart.so.* "${{ inputs.extract_dir }}"
rm -f "${{ inputs.extract_dir }}"/libcudart.so.*.*
ln -sf "$(pwd)/download/cuda/bin"/libcufft.so.* "${{ inputs.extract_dir }}"
rm -f "${{ inputs.extract_dir }}"/libcufft.so.*.*
ln -sf "$(pwd)/download/cuda/bin"/libcurand.so.* "${{ inputs.extract_dir }}"
rm -f "${{ inputs.extract_dir }}"/libcurand.so.*.*
# cuDNN
ln -sf "$(pwd)/download/cudnn/bin"/libcudnn.so.* "${{ inputs.extract_dir }}"
rm -f "${{ inputs.extract_dir }}"/libcudnn.so.*.*
ln -sf "$(pwd)/download/cudnn/bin"/libcudnn_*_infer.so.* "${{ inputs.extract_dir }}"
rm -f "${{ inputs.extract_dir }}"/libcudnn_*_infer.so.*.*
36 changes: 36 additions & 0 deletions .github/actions/upload-artifact/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: upload artifact
description: artifactをzipでアップロードする
inputs:
artifact_dir:
description: 作業ディレクトリ
required: true
asset_name:
description: artifactの名前
required: true
repo_token:
description: github token
required: true
version:
description: version
required: true
runs:
using: "composite"
steps:
- name: Archive artifact
if: ${{ runner.os != 'Windows' }}
shell: bash
run: |
cd "${{ inputs.artifact_dir }}"
zip -r "../${{ inputs.asset_name }}.zip" "${{ inputs.asset_name }}"
- name: Archive artifact (Windows)
if: ${{ runner.os == 'Windows' }}
shell: bash
run: |
powershell Compress-Archive -Path "${{ inputs.artifact_dir }}/${{ inputs.asset_name }}" -DestinationPath "${{ inputs.asset_name }}.zip"
- name: Upload to Release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ inputs.repo_token }}
prerelease: true
tag: ${{ inputs.version }}
file: ${{ inputs.asset_name }}.zip
90 changes: 90 additions & 0 deletions .github/workflows/download_and_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: download and deploy
on:
push:
pull_request:
release:
types:
- published
workflow_dispatch:
inputs:
version:
description: "バージョン情報(A.BB.C / A.BB.C-preview.D)"
required: true
env:
# releaseタグ名か、workflow_dispatchでのバージョン名か、DEBUGが入る
VERSION: ${{ github.event.release.tag_name || github.event.inputs.version || 'DEBUG' }}

jobs:
download_and_deploy_cuda:
strategy:
matrix:
include:
- os: windows-latest
artifact_name: windows-x64
cudnn_download_url: https://developer.download.nvidia.com/compute/redist/cudnn/v8.4.1/local_installers/11.6/cudnn-windows-x86_64-8.4.1.50_cuda11.6-archive.zip
cuda_version: 11.6.0
- os: ubuntu-latest
artifact_name: linux-x64
cudnn_download_url: https://developer.download.nvidia.com/compute/redist/cudnn/v8.4.1/local_installers/11.6/cudnn-linux-x86_64-8.4.1.50_cuda11.6-archive.tar.xz
cuda_version: 11.6.0
env:
ASSET_NAME: CUDA-${{ matrix.artifact_name }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Prepare directory
shell: bash
run: |
mkdir -p artifact/${{ env.ASSET_NAME }}
- name: Organize cuda lib artifact
uses: ./.github/actions/download-cuda-libraries
with:
cudnn_download_url: ${{ matrix.cudnn_download_url }}
asset_name: ${{ env.ASSET_NAME }}
cuda_version: ${{ matrix.cuda_version }}
extract_dir: artifact/${{ env.ASSET_NAME }}
- name: Upload CUDA
if: ${{ env.VERSION != 'DEBUG' && env.SKIP_UPLOADING_RELEASE_ASSET == '0' }}
uses: ./.github/actions/upload-artifact
with:
artifact_dir: artifact
asset_name: ${{ env.ASSET_NAME }}
repo_token: ${{ secrets.GITHUB_TOKEN }}
version: ${{ env.VERSION }}

download_and_deploy_directml:
strategy:
matrix:
include:
- platform: x64-win
artifact_name: windows-x64
directml_version: 1.9.0
env:
ASSET_NAME: DirectML-${{ matrix.artifact_name }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Prepare directory
shell: bash
run: |
mkdir -p artifact/${{ env.ASSET_NAME }}
- name: Download DirectML
shell: bash
run: |
directml_link="https://api.nuget.org/v3-flatcontainer/microsoft.ai.directml/${{ matrix.directml_version }}/microsoft.ai.directml.${{ matrix.directml_version }}.nupkg"
curl -sSLO $directml_link
- name: Extract DirectML
shell: bash
run: |
unzip -d ext_directml microsoft.ai.directml.${{ matrix.directml_version }}.nupkg
cp -v "ext_directml/bin/${{ matrix.platform }}/DirectML.dll" "artifact/${{ env.ASSET_NAME }}"
cp -v "ext_directml/LICENSE.txt" "artifact/${{ env.ASSET_NAME }}/DirectML_LICENSE.txt"
- name: Upload DirectML
if: ${{ env.VERSION != 'DEBUG' && env.SKIP_UPLOADING_RELEASE_ASSET == '0' }}
uses: ./.github/actions/upload-artifact
with:
artifact_dir: artifact
asset_name: ${{ env.ASSET_NAME }}
repo_token: ${{ secrets.GITHUB_TOKEN }}
version: ${{ env.VERSION }}
Loading

0 comments on commit a33b5b7

Please sign in to comment.