Skip to content

Commit 058aead

Browse files
committed
update
1 parent b2765d7 commit 058aead

File tree

4 files changed

+139
-58
lines changed

4 files changed

+139
-58
lines changed

Jenkinsfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ def fsim_test(image) {
261261

262262
def cmake_build(image, path, make_flag) {
263263
sh (
264-
script: "${docker_run} ${image} ./tests/scripts/task_build.sh ${path} ${make_flag} tvm-sccache-prod",
264+
script: "${docker_run} ${image} ./tests/scripts/task_build.py --num-executors ${CI_NUM_EXECUTORS} --sccache-bucket tvm-sccache-prod",
265265
label: 'Run cmake build',
266266
)
267267
}

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 & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)