Skip to content

Commit 4e44a9e

Browse files
illsilinLisa Delaney
andauthored
Enable sccache in the default docker and CI. (ROCm#1009)
* replace ccache with sccache, pin package versions * put ccache back temporarily to avoid breaking other CI jobs * add sccashe_wrapper.sh script * fix the package version syntax * fix the pymysql package issue * run sccache_wrapper before build if ccache server found * set the paths before calling the sccache_wrapper * use /tmp instead of /usr/local for cache * try using sccache --start-server instead of wrapper * try using redis server with sccache * define SCCACHE_REDIS * add redis and ping packages, and redis port * use the new sccache redis server * do not use sccache with staging compiler * fix the condition syntax * add stunnel to redis * add tunnel verification * separate caches for different architectures * fix syntax for the cache tag * quse double brackets for conditions * add bash line to the script * add a switch for sccache and only use it in build stage * run check_host function when enabling sccache * fix the invocation tags for sccache * fix groovy syntax * set the invocation tag in groovy * disable sccache in clang-format stage * try another syntax for invocation tags * use local sccache server if can't connect to redis * fix script syntax * update README * refresh readme * readme updates * remove the timing and verification caveat from readme --------- Co-authored-by: Lisa Delaney <lisa.delaney@amd.com>
1 parent f46a6ff commit 4e44a9e

File tree

6 files changed

+265
-142
lines changed

6 files changed

+265
-142
lines changed

CMakeLists.txt

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,10 @@ include_directories(BEFORE
373373

374374
SET(BUILD_DEV ON CACHE BOOL "BUILD_DEV")
375375
if(BUILD_DEV)
376-
add_compile_options(-Werror)
377-
add_compile_options(-Weverything)
376+
add_compile_options(-Werror -Weverything)
378377
endif()
378+
#add flags to reduce the size of binaries
379+
add_compile_options(-Oz -flto=thin)
379380
message("CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
380381

381382
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C ${CMAKE_CFG_INTDIR})
@@ -390,35 +391,27 @@ IF(IS_DIRECTORY "${PROJECT_SOURCE_DIR}/library/src/tensor_operation_instance/gpu
390391
file(READ "${PROJECT_SOURCE_DIR}/library/src/tensor_operation_instance/gpu/${subdir_path}/CMakeLists.txt" cmake_instance)
391392
set(add_inst 0)
392393
if(("${cmake_instance}" MATCHES "fp8" OR "${cmake_instance}" MATCHES "_f8") AND DTYPES MATCHES "fp8")
393-
#message("fp8 instance found!")
394394
set(add_inst 1)
395395
endif()
396396
if(("${cmake_instance}" MATCHES "bf8" OR "${cmake_instance}" MATCHES "_b8") AND DTYPES MATCHES "bf8")
397-
#message("bf8 instance found!")
398397
set(add_inst 1)
399398
endif()
400399
if(("${cmake_instance}" MATCHES "fp16" OR "${cmake_instance}" MATCHES "_f16") AND DTYPES MATCHES "fp16")
401-
#message("fp16 instance found!")
402400
set(add_inst 1)
403401
endif()
404402
if(("${cmake_instance}" MATCHES "fp32" OR "${cmake_instance}" MATCHES "_f32") AND DTYPES MATCHES "fp32")
405-
#message("fp32 instance found!")
406403
set(add_inst 1)
407404
endif()
408405
if(("${cmake_instance}" MATCHES "fp64" OR "${cmake_instance}" MATCHES "_f64") AND DTYPES MATCHES "fp64")
409-
#message("fp64 instance found!")
410406
set(add_inst 1)
411407
endif()
412408
if(("${cmake_instance}" MATCHES "bf16" OR "${cmake_instance}" MATCHES "_b16") AND DTYPES MATCHES "bf16")
413-
#message("bf16 instance found!")
414409
set(add_inst 1)
415410
endif()
416411
if(("${cmake_instance}" MATCHES "int8" OR "${cmake_instance}" MATCHES "_i8") AND DTYPES MATCHES "int8")
417-
#message("int8 instance found!")
418412
set(add_inst 1)
419413
endif()
420414
if(NOT "${cmake_instance}" MATCHES "DTYPES")
421-
#message("instance should be built for all types!")
422415
set(add_inst 1)
423416
endif()
424417
if(add_inst EQUAL 1 OR NOT DEFINED DTYPES)

Dockerfile

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,37 @@ RUN wget -qO - http://repo.radeon.com/rocm/rocm.gpg.key | apt-key add - && \
2626
RUN sh -c "echo deb http://mirrors.kernel.org/ubuntu focal main universe | tee -a /etc/apt/sources.list"
2727
RUN amdgpu-install -y --usecase=rocm --no-dkms
2828

29+
## Sccache binary built from source for ROCm
30+
ARG SCCACHE_REPO_URL=http://compute-artifactory.amd.com/artifactory/rocm-generic-experimental/rocm-sccache
31+
ENV SCCACHE_INSTALL_LOCATION=/usr/local/.cargo/bin
32+
RUN mkdir -p ${SCCACHE_INSTALL_LOCATION} && \
33+
curl ${SCCACHE_REPO_URL}/portable/0.2.16/sccache-0.2.16-alpha.1-rocm --output ${SCCACHE_INSTALL_LOCATION}/sccache && \
34+
chmod +x ${SCCACHE_INSTALL_LOCATION}/sccache
35+
ENV PATH=$PATH:${SCCACHE_INSTALL_LOCATION}
36+
2937
# Install dependencies
3038
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --allow-unauthenticated \
3139
build-essential \
32-
ccache \
3340
cmake \
41+
ccache \
3442
git \
3543
hip-rocclr \
44+
iputils-ping \
3645
jq \
3746
libelf-dev \
3847
libncurses5-dev \
3948
libnuma-dev \
4049
libpthread-stubs0-dev \
4150
llvm-amdgpu \
51+
net-tools \
4252
pkg-config \
4353
python \
4454
python3 \
4555
python3-dev \
4656
python3-pip \
57+
redis \
4758
sshpass \
59+
stunnel \
4860
software-properties-common \
4961
vim \
5062
nano \
@@ -62,7 +74,7 @@ RUN gunzip /usr/local/bin/ninja.gz
6274
RUN chmod a+x /usr/local/bin/ninja
6375
RUN git clone https://github.com/nico/ninjatracing.git
6476
# Update the cmake to the latest version
65-
RUN pip install --upgrade cmake
77+
RUN pip install --upgrade cmake==3.27.5
6678

6779
# Setup ubsan environment to printstacktrace
6880
RUN ln -s /usr/bin/llvm-symbolizer-3.8 /usr/local/bin/llvm-symbolizer
@@ -77,9 +89,9 @@ ARG PREFIX=/opt/rocm
7789
RUN pip3 install --upgrade pip
7890
RUN pip3 install sqlalchemy==1.4.46
7991
RUN pip3 install pymysql
80-
RUN pip3 install pandas
92+
RUN pip3 install pandas==2.0.3
8193
RUN pip3 install setuptools-rust
82-
RUN pip3 install sshtunnel
94+
RUN pip3 install sshtunnel==0.4.0
8395
# Setup ubsan environment to printstacktrace
8496
ENV UBSAN_OPTIONS=print_stacktrace=1
8597

@@ -115,6 +127,8 @@ RUN if [ "$compiler_version" = "amd-stg-open" ] && [ "$compiler_commit" != "" ];
115127
else echo "using the release compiler"; \
116128
fi
117129

130+
#clean-up the deb package
131+
RUN sh -c "rm -rf amdgpu-install*"
118132

119133
#ENV HIP_CLANG_PATH='/llvm-project/build/bin'
120134
#RUN sh -c "echo HIP_CLANG_PATH = '$HIP_CLANG_PATH'"

Jenkinsfile

Lines changed: 52 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ def getDockerImageName(){
6565
}
6666

6767
def check_host() {
68-
if ("${env.CK_CCACHE}" != "null"){
69-
def CCACHE_SERVER="${env.CK_CCACHE.split(':')[0]}"
70-
echo "ccache server: ${CCACHE_SERVER}"
71-
sh '''ping -c 1 -p 6379 "${CCACHE_SERVER}" | echo $? > tmp.txt'''
68+
if ("${env.CK_SCCACHE}" != "null"){
69+
def SCCACHE_SERVER="${env.CK_SCCACHE.split(':')[0]}"
70+
echo "sccache server: ${SCCACHE_SERVER}"
71+
sh '''ping -c 1 -p 6379 "${SCCACHE_SERVER}" | echo $? > tmp.txt'''
7272
def output = readFile(file: "tmp.txt")
7373
echo "tmp.txt contents: \$output"
7474
return (output != "0")
@@ -96,24 +96,9 @@ def build_compiler(){
9696

9797
def getDockerImage(Map conf=[:]){
9898
env.DOCKER_BUILDKIT=1
99-
def prefixpath = conf.get("prefixpath", "/opt/rocm") // prefix:/opt/rocm
99+
def prefixpath = conf.get("prefixpath", "/opt/rocm")
100100
def no_cache = conf.get("no_cache", false)
101101
def dockerArgs = "--build-arg BUILDKIT_INLINE_CACHE=1 --build-arg PREFIX=${prefixpath} --build-arg compiler_version='${params.COMPILER_VERSION}' --build-arg compiler_commit='${params.COMPILER_COMMIT}' --build-arg ROCMVERSION='${params.ROCMVERSION}' "
102-
echo "ccache server: ${env.CK_CCACHE}"
103-
if(env.CK_CCACHE)
104-
{
105-
if(check_host())
106-
{
107-
echo "FOUND CCACHE SERVER: ${env.CK_CCACHE}"
108-
}
109-
else
110-
{
111-
echo "CCACHE SERVER: ${env.CK_CCACHE} NOT FOUND, got ${check_host} response"
112-
}
113-
dockerArgs = dockerArgs + " --build-arg CCACHE_SECONDARY_STORAGE='redis://${env.CK_CCACHE}' --build-arg COMPILER_LAUNCHER='ccache' "
114-
env.CCACHE_DIR = """/tmp/ccache_store"""
115-
env.CCACHE_SECONDARY_STORAGE="""redis://${env.CK_CCACHE}"""
116-
}
117102
if(no_cache)
118103
{
119104
dockerArgs = dockerArgs + " --no-cache "
@@ -142,21 +127,6 @@ def buildDocker(install_prefix){
142127
def image_name = getDockerImageName()
143128
echo "Building Docker for ${image_name}"
144129
def dockerArgs = "--build-arg BUILDKIT_INLINE_CACHE=1 --build-arg PREFIX=${install_prefix} --build-arg compiler_version='${params.COMPILER_VERSION}' --build-arg compiler_commit='${params.COMPILER_COMMIT}' --build-arg ROCMVERSION='${params.ROCMVERSION}' "
145-
echo "ccache server: ${env.CK_CCACHE}"
146-
if(env.CK_CCACHE)
147-
{
148-
if(check_host())
149-
{
150-
echo "FOUND CCACHE SERVER: ${env.CK_CCACHE}"
151-
}
152-
else
153-
{
154-
echo "CCACHE SERVER: ${env.CK_CCACHE} NOT FOUND, got ${check_host} response"
155-
}
156-
dockerArgs = dockerArgs + " --build-arg CCACHE_SECONDARY_STORAGE='redis://${env.CK_CCACHE}' --build-arg COMPILER_LAUNCHER='ccache' "
157-
env.CCACHE_DIR = """/tmp/ccache_store"""
158-
env.CCACHE_SECONDARY_STORAGE="""redis://${env.CK_CCACHE}"""
159-
}
160130

161131
echo "Build Args: ${dockerArgs}"
162132
try{
@@ -219,13 +189,9 @@ def cmake_build(Map conf=[:]){
219189
}else{
220190
setup_args = " -DCMAKE_BUILD_TYPE=release" + setup_args
221191
}
222-
if(env.CK_CCACHE)
223-
{
224-
setup_args = " -DCMAKE_CXX_COMPILER_LAUNCHER='ccache' -DCMAKE_C_COMPILER_LAUNCHER='ccache' " + setup_args
225-
}
226-
echo "ccache server: ${env.CK_CCACHE}"
227192

228193
def pre_setup_cmd = """
194+
#!/bin/bash
229195
echo \$HSA_ENABLE_SDMA
230196
ulimit -c unlimited
231197
rm -rf build
@@ -234,6 +200,46 @@ def cmake_build(Map conf=[:]){
234200
mkdir install
235201
cd build
236202
"""
203+
def invocation_tag=""
204+
if (setup_args.contains("gfx11")){
205+
invocation_tag="gfx11"
206+
}
207+
if (setup_args.contains("gfx10")){
208+
invocation_tag="gfx10"
209+
}
210+
if (setup_args.contains("gfx90")){
211+
invocation_tag="gfx90"
212+
}
213+
if (setup_args.contains("gfx94")){
214+
invocation_tag="gfx94"
215+
}
216+
if(check_host() && params.USE_SCCACHE && "${env.CK_SCCACHE}" != "null" && "${invocation_tag}" != "") {
217+
pre_setup_cmd = pre_setup_cmd + """
218+
#!/bin/bash
219+
export ROCM_PATH=/opt/rocm
220+
export SCCACHE_ENABLED=true
221+
export SCCACHE_LOG_LEVEL=debug
222+
export SCCACHE_IDLE_TIMEOUT=14400
223+
export COMPILERS_HASH_DIR=/tmp/.sccache
224+
export SCCACHE_BIN=/usr/local/.cargo/bin/sccache
225+
export SCCACHE_EXTRAFILES=/tmp/.sccache/rocm_compilers_hash_file
226+
export SCCACHE_REDIS="redis://${env.CK_SCCACHE}"
227+
echo "connect = ${env.CK_SCCACHE}" >> ../script/redis-cli.conf
228+
export SCCACHE_C_CUSTOM_CACHE_BUSTER="${invocation_tag}"
229+
echo \$SCCACHE_C_CUSTOM_CACHE_BUSTER
230+
stunnel ../script/redis-cli.conf
231+
(
232+
set -e
233+
../script/sccache_wrapper.sh --enforce_redis
234+
)
235+
error_code=\$?
236+
if [ \$error_code -ne 0 ]; then
237+
echo "could not connect to the redis server. using sccache locally."
238+
../script/sccache_wrapper.sh
239+
fi
240+
"""
241+
setup_args = " -DCMAKE_CXX_COMPILER_LAUNCHER=sccache -DCMAKE_C_COMPILER_LAUNCHER=sccache " + setup_args
242+
}
237243
def setup_cmd = conf.get("setup_cmd", "${cmake_envs} cmake ${setup_args} .. ")
238244
// reduce parallelism when compiling, clang uses too much memory
239245
def nt = nthreads()
@@ -251,7 +257,7 @@ def cmake_build(Map conf=[:]){
251257
sh cmd
252258

253259
// Only archive from master or develop
254-
if (package_build == true && (env.BRANCH_NAME == "develop" || env.BRANCH_NAME == "master")) {
260+
if (package_build == true && (env.BRANCH_NAME == "develop" || env.BRANCH_NAME == "amd-master")) {
255261
archiveArtifacts artifacts: "build/*.deb", allowEmptyArchive: true, fingerprint: true
256262
}
257263
}
@@ -635,7 +641,7 @@ def process_results(Map conf=[:]){
635641
//launch develop branch daily at 23:00 UT in FULL_QA mode and at 19:00 UT with latest staging compiler version
636642
CRON_SETTINGS = BRANCH_NAME == "develop" ? '''0 23 * * * % RUN_FULL_QA=true;ROCMVERSION=5.7;COMPILER_VERSION=
637643
0 21 * * * % ROCMVERSION=5.7;COMPILER_VERSION=;COMPILER_COMMIT=
638-
0 19 * * * % BUILD_DOCKER=true;DL_KERNELS=true;COMPILER_VERSION=amd-stg-open;COMPILER_COMMIT=''' : ""
644+
0 19 * * * % BUILD_DOCKER=true;DL_KERNELS=true;COMPILER_VERSION=amd-stg-open;COMPILER_COMMIT=;USE_SCCACHE=false''' : ""
639645

640646
pipeline {
641647
agent none
@@ -682,7 +688,10 @@ pipeline {
682688
name: 'hipTensor_branch',
683689
defaultValue: 'mainline',
684690
description: 'Specify which branch of hipTensor to use (default: mainline)')
685-
691+
booleanParam(
692+
name: "USE_SCCACHE",
693+
defaultValue: true,
694+
description: "Use the sccache for building CK (default: ON)")
686695
}
687696
environment{
688697
dbuser = "${dbuser}"

0 commit comments

Comments
 (0)