From aab3c15585c87fbf3830c2595865b693fc68d261 Mon Sep 17 00:00:00 2001 From: Yi Zhang Date: Thu, 30 Mar 2023 23:18:52 +0800 Subject: [PATCH] Add Compliation Cache in CoreML pipeline (#15259) ### Description 1. move the cache task definition into template 2. In debug mode, the compiler mtime is different in different machine. So, change the CCACHE_COMPILERCHECK to content. ### Motivation and Context 1. Accelerate the CoreML pipeline. Test run: https://dev.azure.com/onnxruntime/onnxruntime/_build/results?buildId=938040&view=logs&j=1ac7588f-a5bd-5ff7-4a8a-a34869d50220 With Cache, the run can be finished in 12 minutes. Without cache, it takes about 1 hour. 3. Make the cache function easy to use and maintain. --------- Co-authored-by: Edward Chen <18449977+edgchen1@users.noreply.github.com> --- .../mac-coreml-ci-pipeline.yml | 33 ++++++++++----- .../templates/mac-build-step-with-cache.yml | 42 +++++++++++++++++++ 2 files changed, 65 insertions(+), 10 deletions(-) create mode 100644 tools/ci_build/github/azure-pipelines/templates/mac-build-step-with-cache.yml diff --git a/tools/ci_build/github/azure-pipelines/mac-coreml-ci-pipeline.yml b/tools/ci_build/github/azure-pipelines/mac-coreml-ci-pipeline.yml index e2d9d03561..dd1793921c 100644 --- a/tools/ci_build/github/azure-pipelines/mac-coreml-ci-pipeline.yml +++ b/tools/ci_build/github/azure-pipelines/mac-coreml-ci-pipeline.yml @@ -1,21 +1,34 @@ jobs: - job: CoreML_CI + workspace: + clean: all pool: vmImage: 'macOS-12' variables: MACOSX_DEPLOYMENT_TARGET: '10.14' + TODAY: $[format('{0:dd}{0:MM}{0:yyyy}', pipeline.startTime)] + CCACHE_DIR: '$(Pipeline.Workspace)/ccache' timeoutInMinutes: 120 steps: - script: brew install coreutils ninja displayName: Install coreutils and ninja - - script: | - python3 tools/ci_build/build.py \ - --build_dir build \ - --skip_submodule_sync \ - --cmake_generator=Ninja \ - --parallel \ - --build_shared_lib \ - --config Debug \ - --use_coreml - displayName: CoreML EP, Build and Test on macOS \ No newline at end of file + - template: templates/mac-build-step-with-cache.yml + parameters: + TODAY: $(TODAY) + AdditionalKey: coreml + CACHE_DIR: $(CCACHE_DIR) + BuildStep: + - script: | + python3 tools/ci_build/build.py \ + --build_dir build \ + --skip_submodule_sync \ + --cmake_generator=Ninja \ + --parallel \ + --build_shared_lib \ + --config Debug \ + --use_cache \ + --use_coreml + displayName: CoreML EP, Build and Test on macOS + env: + CCACHE_COMPILERCHECK: content diff --git a/tools/ci_build/github/azure-pipelines/templates/mac-build-step-with-cache.yml b/tools/ci_build/github/azure-pipelines/templates/mac-build-step-with-cache.yml new file mode 100644 index 0000000000..68fe83a52d --- /dev/null +++ b/tools/ci_build/github/azure-pipelines/templates/mac-build-step-with-cache.yml @@ -0,0 +1,42 @@ +# It's used for compilation with cache in Mac Host. + +parameters: +- name: TODAY + type: string + +- name: BuildStep + type: stepList + +- name: AdditionalKey + type: string + +- name: CACHE_DIR + type: string + +steps: + - script: | + brew install ccache + echo "##vso[task.prependpath]/usr/local/opt/ccache/libexec" + mkdir -p "${{ parameters.CACHE_DIR }}" + displayName: Install ccache and update PATH to use linked versions of gcc, cc, etc + + - task: Cache@2 + inputs: + key: ' "${{parameters.TODAY}}" | ${{parameters.AdditionalKey}} | "$(Build.SourceVersion)" ' + path: ${{ parameters.CACHE_DIR }} + restoreKeys: | + "${{parameters.TODAY}}" | ${{parameters.AdditionalKey}} + displayName: ccache task + + - ${{ parameters.BuildStep }} + + - script: | + set -ex + ccache -s + ccache -z + ls -l "${{ parameters.CACHE_DIR }}" + du -sh "${{ parameters.CACHE_DIR }}" + displayName: Show Cache stats and Clear stats. + env: + CCACHE_DIR: ${{parameters.CACHE_DIR}} + condition: always()