mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-20 19:12:24 +00:00
Use cache for compilation in container (#13960)
### Description For compilation in container, ADO Cache task doesn't work directly. The workaround is to mount the cache directory to the container, and let CCache in container to read/write cache data. In short, we just leverage ADO API to download/upload cache data. The Post-jobs works in stack-mode, So the PostBuildCleanUp Tasks should be defined first. Thus, The PostBuildCleanUp would be executed lastly. Else, Cache Task would fail to upload cache because the Agent Directory is cleaned.
This commit is contained in:
parent
a061fedb5d
commit
7d20d889d1
3 changed files with 44 additions and 5 deletions
|
|
@ -675,6 +675,8 @@ def parse_arguments():
|
|||
|
||||
parser.add_argument("--use_xnnpack", action="store_true", help="Enable xnnpack EP.")
|
||||
|
||||
parser.add_argument("--use_cache", action="store_true", help="Use compiler cache in CI")
|
||||
|
||||
args = parser.parse_args()
|
||||
if args.android_sdk_path:
|
||||
args.android_sdk_path = os.path.normpath(args.android_sdk_path)
|
||||
|
|
@ -960,6 +962,9 @@ def generate_build_tree(
|
|||
"-Donnxruntime_USE_XNNPACK=" + ("ON" if args.use_xnnpack else "OFF"),
|
||||
"-Donnxruntime_USE_CANN=" + ("ON" if args.use_cann else "OFF"),
|
||||
]
|
||||
if args.use_cache:
|
||||
cmake_args.append("-DCMAKE_CXX_COMPILER_LAUNCHER=ccache")
|
||||
cmake_args.append("-DCMAKE_C_COMPILER_LAUNCHER=ccache")
|
||||
# By default cmake does not check TLS/SSL certificates. Here we turn it on.
|
||||
# But, in some cases you may also need to supply a CA file.
|
||||
add_default_definition(cmake_extra_defines, "CMAKE_TLS_VERIFY", "ON")
|
||||
|
|
|
|||
|
|
@ -13,8 +13,13 @@ jobs:
|
|||
clean: all
|
||||
variables:
|
||||
skipComponentGovernanceDetection: true
|
||||
CCACHE_DIR: $(Pipeline.Workspace)/ccache
|
||||
pool: Linux-CPU-2019
|
||||
steps:
|
||||
- task: mspremier.PostBuildCleanup.PostBuildCleanup-task.PostBuildCleanup@3
|
||||
displayName: 'Clean Agent Directories'
|
||||
condition: always()
|
||||
|
||||
- checkout: self
|
||||
clean: true
|
||||
submodules: none
|
||||
|
|
@ -35,6 +40,26 @@ jobs:
|
|||
DockerBuildArgs: "--build-arg BUILD_UID=$( id -u )"
|
||||
Repository: onnxruntimecpubuild
|
||||
|
||||
- script: |
|
||||
sudo apt-get install ccache -y
|
||||
echo "##vso[task.prependpath]/usr/lib/ccache"
|
||||
displayName: Install ccache and update PATH to use linked versions of gcc, cc, etc
|
||||
|
||||
- task: Cache@2
|
||||
inputs:
|
||||
key: '"ccache" | "$(Build.SourceBranch)" | "$(Build.SourceVersion)"'
|
||||
path: $(CCACHE_DIR)
|
||||
restoreKeys: |
|
||||
"ccache" | "$(Build.SourceBranch)"
|
||||
"ccache"
|
||||
cacheHitVar: CACHE_RESTORED
|
||||
displayName: Cach Task
|
||||
|
||||
- script: |
|
||||
sudo mkdir -p $(Pipeline.Workspace)/ccache
|
||||
condition: ne(variables.CACHE_RESTORED, 'true')
|
||||
displayName: Create Cache Dir
|
||||
|
||||
- task: CmdLine@2
|
||||
displayName: 'build'
|
||||
inputs:
|
||||
|
|
@ -45,10 +70,15 @@ jobs:
|
|||
--volume $(Build.SourcesDirectory):/onnxruntime_src \
|
||||
--volume $(Build.BinariesDirectory):/build \
|
||||
--volume $HOME/.onnx:/home/onnxruntimedev/.onnx \
|
||||
--volume $(Pipeline.Workspace)/ccache:/cache \
|
||||
-e ALLOW_RELEASED_ONNX_OPSET_ONLY=0 \
|
||||
-e NIGHTLY_BUILD \
|
||||
-e BUILD_BUILDNUMBER \
|
||||
-e CCACHE_DIR=/cache \
|
||||
onnxruntimecpubuild \
|
||||
/bin/bash -c "
|
||||
set -ex; \
|
||||
ccache -s; \
|
||||
/opt/python/cp38-cp38/bin/python3 /onnxruntime_src/tools/ci_build/build.py \
|
||||
--build_dir /build --cmake_generator Ninja \
|
||||
--config Debug Release \
|
||||
|
|
@ -58,7 +88,9 @@ jobs:
|
|||
--build_wheel \
|
||||
--enable_onnx_tests \
|
||||
--enable_transformers_tool_test \
|
||||
--build_java --build_nodejs --update --build --cmake_extra_defines onnxruntime_BUILD_BENCHMARKS=ON
|
||||
--use_cache \
|
||||
--build_java --build_nodejs --update --build --cmake_extra_defines onnxruntime_BUILD_BENCHMARKS=ON; \
|
||||
ccache -s"
|
||||
workingDirectory: $(Build.SourcesDirectory)
|
||||
|
||||
- task: CmdLine@2
|
||||
|
|
@ -144,7 +176,3 @@ jobs:
|
|||
searchFolder: '$(Build.BinariesDirectory)'
|
||||
testRunTitle: 'Unit Test Run'
|
||||
condition: succeededOrFailed()
|
||||
|
||||
- task: mspremier.PostBuildCleanup.PostBuildCleanup-task.PostBuildCleanup@3
|
||||
displayName: 'Clean Agent Directories'
|
||||
condition: always()
|
||||
|
|
|
|||
|
|
@ -83,6 +83,12 @@ echo "Installing Node.js"
|
|||
GetFile https://nodejs.org/dist/v16.14.2/node-v16.14.2-linux-x64.tar.gz /tmp/src/node-v16.14.2-linux-x64.tar.gz
|
||||
tar --strip 1 -xf /tmp/src/node-v16.14.2-linux-x64.tar.gz -C /usr
|
||||
|
||||
echo "Installing CCache"
|
||||
mkdir -p /tmp/ccache
|
||||
GetFile https://github.com/ccache/ccache/releases/download/v4.7.4/ccache-4.7.4-linux-x86_64.tar.xz /tmp/src/ccache-4.7.4-linux-x86_64.tar.xz
|
||||
tar --strip 1 -xf /tmp/src/ccache-4.7.4-linux-x86_64.tar.xz -C /tmp/ccache
|
||||
cp /tmp/ccache/ccache /usr/bin
|
||||
|
||||
cd /tmp/src
|
||||
GetFile https://downloads.gradle-dn.com/distributions/gradle-6.3-bin.zip /tmp/src/gradle-6.3-bin.zip
|
||||
unzip /tmp/src/gradle-6.3-bin.zip
|
||||
|
|
|
|||
Loading…
Reference in a new issue