Skip to content

Commit 8586d54

Browse files
driazatipfk-beta
authored andcommitted
[ci] Use available CPUs in builds (apache#10359)
* [ci] Use sccache in builds * trigger ci * update Co-authored-by: driazati <[email protected]>
1 parent a38b4f3 commit 8586d54

12 files changed

+155
-41
lines changed

Jenkinsfile

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@
4545
import org.jenkinsci.plugins.pipeline.modeldefinition.Utils
4646

4747
// NOTE: these lines are scanned by docker/dev_common.sh. Please update the regex as needed. -->
48-
ci_lint = "tlcpack/ci-lint:v0.68"
49-
ci_gpu = "tlcpack/ci-gpu:v0.81"
50-
ci_cpu = "tlcpack/ci-cpu:v0.81"
51-
ci_wasm = "tlcpack/ci-wasm:v0.71"
52-
ci_i386 = "tlcpack/ci-i386:v0.74"
53-
ci_qemu = "tlcpack/ci-qemu:v0.10"
54-
ci_arm = "tlcpack/ci-arm:v0.07"
55-
ci_hexagon = "tlcpack/ci-hexagon:v0.01"
48+
ci_lint = 'tlcpack/ci-lint:v0.68'
49+
ci_gpu = 'tlcpack/ci-gpu:v0.81'
50+
ci_cpu = 'tlcpack/ci-cpu:v0.81'
51+
ci_wasm = 'tlcpack/ci-wasm:v0.71'
52+
ci_i386 = 'tlcpack/ci-i386:v0.74'
53+
ci_qemu = 'tlcpack/ci-qemu:v0.10'
54+
ci_arm = 'tlcpack/ci-arm:v0.07'
55+
ci_hexagon = 'tlcpack/ci-hexagon:v0.01'
5656
// <--- End of regex-scanned config.
5757

5858
// Parameters to allow overriding (in Jenkins UI), the images
@@ -202,6 +202,7 @@ stage('Sanity Check') {
202202
}
203203
}
204204

205+
205206
// Run make. First try to do an incremental make from a previous workspace in hope to
206207
// accelerate the compilation. If something is wrong, clean the workspace and then
207208
// build from scratch.
@@ -262,13 +263,13 @@ def python_unittest(image) {
262263
def fsim_test(image) {
263264
sh (
264265
script: "${docker_run} ${image} ./tests/scripts/task_python_vta_fsim.sh",
265-
label: 'Run VTA tests in FSIM ',
266+
label: 'Run VTA tests in FSIM',
266267
)
267268
}
268269

269270
def cmake_build(image, path, make_flag) {
270271
sh (
271-
script: "${docker_run} ${image} ./tests/scripts/task_build.sh ${path} ${make_flag}",
272+
script: "${docker_run} ${image} ./tests/scripts/task_build.py --num-executors ${CI_NUM_EXECUTORS} --sccache-bucket tvm-sccache-prod",
272273
label: 'Run cmake build',
273274
)
274275
}

docker/dev_common.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function filter_jenkinsfile() {
4545
function lookup_image_spec() {
4646
img_line=$(cat "${GIT_TOPLEVEL}/Jenkinsfile" | filter_jenkinsfile | grep -E "^${1} = ")
4747
if [ -n "${img_line}" ]; then
48-
img_spec=$(echo "${img_line}" | sed -E "s/${1} = \"([^\"]*)\"/\1/")
48+
img_spec=$(echo "${img_line}" | sed -E "s/${1} = '([^\"]*)'/\1/")
4949
has_similar_docker_image=1
5050
docker inspect "${1}" &>/dev/null || has_similar_docker_image=0
5151
if [ ${has_similar_docker_image} -ne 0 ]; then

tests/scripts/cmd_utils.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
import subprocess
19+
import os
20+
import logging
21+
import sys
22+
from pathlib import Path
23+
24+
25+
REPO_ROOT = Path(__file__).resolve().parent.parent.parent
26+
27+
28+
class RelativePathFilter(logging.Filter):
29+
def filter(self, record):
30+
path = Path(record.pathname).resolve()
31+
record.relativepath = str(path.relative_to(REPO_ROOT))
32+
return True
33+
34+
35+
def init_log():
36+
logging.basicConfig(
37+
format="[%(relativepath)s:%(lineno)d %(levelname)-1s] %(message)s", level=logging.INFO
38+
)
39+
40+
# Flush on every log call (logging and then calling subprocess.run can make
41+
# the output look confusing)
42+
logging.root.handlers[0].addFilter(RelativePathFilter())
43+
logging.root.handlers[0].flush = sys.stderr.flush
44+
45+
46+
class Sh:
47+
def __init__(self, env=None):
48+
self.env = os.environ.copy()
49+
if env is not None:
50+
self.env.update(env)
51+
52+
def run(self, cmd: str, **kwargs):
53+
logging.info(f"+ {cmd}")
54+
if "check" not in kwargs:
55+
kwargs["check"] = True
56+
if "shell" not in kwargs:
57+
kwargs["shell"] = True
58+
if "env" not in kwargs:
59+
kwargs["env"] = self.env
60+
61+
subprocess.run(cmd, **kwargs)

tests/scripts/task_build.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/usr/bin/env python3
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
import argparse
19+
import shutil
20+
import os
21+
import logging
22+
import multiprocessing
23+
24+
from pathlib import Path
25+
from cmd_utils import Sh, init_log, REPO_ROOT
26+
27+
28+
if __name__ == "__main__":
29+
init_log()
30+
31+
parser = argparse.ArgumentParser(description="List pytest nodeids for a folder")
32+
parser.add_argument("--sccache-bucket", required=False, help="sccache bucket name")
33+
parser.add_argument("--num-executors", required=True, help="number of Jenkins executors")
34+
parser.add_argument("--build-dir", default="build", help="build folder")
35+
args = parser.parse_args()
36+
37+
env = {"VTA_HW_PATH": str(Path(os.getcwd()) / "3rdparty" / "vta-hw")}
38+
sccache_exe = shutil.which("sccache")
39+
40+
use_sccache = sccache_exe is not None and args.sccache_bucket is not None
41+
build_dir = Path(os.getcwd()) / args.build_dir
42+
build_dir = build_dir.relative_to(REPO_ROOT)
43+
44+
if use_sccache:
45+
env["SCCACHE_BUCKET"] = args.sccache_bucket
46+
env["CXX"] = "/opt/sccache/c++"
47+
env["CC"] = "/opt/sccache/cc"
48+
49+
logging.info(f"Using sccache bucket: {args.sccache_bucket}")
50+
else:
51+
if sccache_exe is None:
52+
reason = "'sccache' executable not found"
53+
elif args.sccache_bucket is None:
54+
reason = "'sccache' executable not found"
55+
else:
56+
reason = "<unknown>"
57+
logging.info(f"Not using sccache, reason: {reason}")
58+
59+
sh = Sh(env)
60+
61+
if use_sccache:
62+
sh.run("sccache --start-server", check=False)
63+
logging.info("===== sccache stats =====")
64+
sh.run("sccache --show-stats")
65+
66+
executors = int(args.num_executors)
67+
nproc = multiprocessing.cpu_count()
68+
69+
available_cpus = nproc // executors
70+
num_cpus = max(available_cpus, 1)
71+
72+
sh.run("cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo ..", cwd=build_dir)
73+
sh.run(f"cmake --build . -- VERBOSE=1 -j{num_cpus}", cwd=build_dir)
74+
75+
if use_sccache:
76+
logging.info("===== sccache stats =====")
77+
sh.run("sccache --show-stats")

tests/scripts/task_build.sh

Lines changed: 0 additions & 19 deletions
This file was deleted.

tests/scripts/task_config_build_arm.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ echo set\(USE_MICRO ON\) >> config.cmake
2929
echo set\(USE_MICRO_STANDALONE_RUNTIME ON\) >> config.cmake
3030
echo set\(USE_PROFILER ON\) >> config.cmake
3131
echo set\(USE_LLVM llvm-config-8\) >> config.cmake
32-
echo set\(CMAKE_CXX_COMPILER g++\) >> config.cmake
3332
echo set\(CMAKE_CXX_FLAGS -Werror\) >> config.cmake
3433
echo set\(USE_VTA_FSIM ON\) >> config.cmake
3534
echo set\(USE_ARM_COMPUTE_LIB ON\) >> config.cmake

tests/scripts/task_config_build_cpu.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ echo set\(USE_LLVM llvm-config-11\) >> config.cmake
3333
echo set\(USE_NNPACK ON\) >> config.cmake
3434
echo set\(NNPACK_PATH /NNPACK/build/\) >> config.cmake
3535
echo set\(USE_ANTLR ON\) >> config.cmake
36-
echo set\(CMAKE_CXX_COMPILER g++\) >> config.cmake
3736
echo set\(CMAKE_CXX_FLAGS -Werror\) >> config.cmake
3837
echo set\(HIDE_PRIVATE_SYMBOLS ON\) >> config.cmake
3938
echo set\(USE_VTA_TSIM ON\) >> config.cmake

tests/scripts/task_config_build_gpu.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ echo set\(USE_PROFILER ON\) >> config.cmake
4141
echo set\(USE_ANTLR ON\) >> config.cmake
4242
echo set\(USE_VTA_FSIM ON\) >> config.cmake
4343
echo set\(USE_BLAS openblas\) >> config.cmake
44-
echo set\(CMAKE_CXX_COMPILER g++\) >> config.cmake
4544
echo set\(CMAKE_CXX_FLAGS -Werror\) >> config.cmake
4645
echo set\(USE_TENSORRT_CODEGEN ON\) >> config.cmake
4746
echo set\(USE_LIBBACKTRACE AUTO\) >> config.cmake

tests/scripts/task_config_build_i386.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ echo set\(USE_MICRO ON\) >> config.cmake
2929
echo set\(USE_MICRO_STANDALONE_RUNTIME ON\) >> config.cmake
3030
echo set\(USE_PROFILER ON\) >> config.cmake
3131
echo set\(USE_LLVM llvm-config-4.0\) >> config.cmake
32-
echo set\(CMAKE_CXX_COMPILER g++\) >> config.cmake
3332
echo set\(CMAKE_CXX_FLAGS -Werror\) >> config.cmake
3433
echo set\(USE_VTA_FSIM ON\) >> config.cmake
3534
echo set\(USE_VTA_TSIM ON\) >> config.cmake

tests/scripts/task_config_build_qemu.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ echo set\(USE_MICRO ON\) >> config.cmake
2828
echo set\(USE_CMSISNN ON\) >> config.cmake
2929
echo set\(USE_ETHOSU ON\) >> config.cmake
3030
echo set\(USE_LLVM llvm-config-10\) >> config.cmake
31-
echo set\(CMAKE_CXX_COMPILER g++\) >> config.cmake
3231
echo set\(CMAKE_CXX_FLAGS -Werror\) >> config.cmake
3332
echo set\(HIDE_PRIVATE_SYMBOLS ON\) >> config.cmake
3433
echo set\(USE_CCACHE OFF\) >> config.cmake

0 commit comments

Comments
 (0)