forked from kata-containers/kata-containers
-
Notifications
You must be signed in to change notification settings - Fork 3
/
onednn.sh
executable file
·107 lines (83 loc) · 2.89 KB
/
onednn.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/bash
#
# Copyright (c) 2024 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
# Description of the test:
# This test runs the 'onednn benchmark'
# https://openbenchmarking.org/test/pts/onednn
set -o pipefail
# General env
SCRIPT_PATH=$(dirname "$(readlink -f "$0")")
source "${SCRIPT_PATH}/../lib/common.bash"
# TEST_NAME is required to collect results and name the workload container.
TEST_NAME="onednn-bench"
WORKLOAD="phoronix-test-suite batch-run onednn"
PAYLOAD_ARGS="${PAYLOAD_ARGS:-tail -f /dev/null}"
IMAGE="docker.io/library/pts-onednn:latest"
DOCKERFILE="${SCRIPT_PATH}/onednn-dockerfile/Dockerfile"
TMP_DIR=$(mktemp --tmpdir -d onednn.XXXXXXXXXX)
KATA_PERF_CONFIG="${TMP_DIR}/onednn_config.toml"
TEST_RESULTS_FNAME="${TMP_DIR}/onednn-results.json"
# Variable used to store the initial configuration file name.
# This file is again pointed to by kata once the script finishes.
KATA_INITIAL_CONFIG_FNAME=""
function restore_kata_config() {
rm -rf "${TMP_DIR}"
set_kata_config_file "${KATA_INITIAL_CONFIG_FNAME}"
}
trap restore_kata_config EXIT
# Show help about this script
function help(){
cat << EOF
Usage: $0
Description:
Runs onednn benchmark using the maximum number of cpus and memory available.
EOF
}
function save_config() {
metrics_json_start_array
local json="$(cat << EOF
{
"image": "${IMAGE}",
"units": "ms",
"mode": "Lower Is Better",
}
EOF
)"
metrics_json_add_array_element "${json}"
metrics_json_end_array "Config"
}
function main() {
local cmds=("docker")
local RES_DIR="/var/lib/phoronix-test-suite/test-results"
# Check tools/commands dependencies
init_env
check_cmds "${cmds[@]}"
check_ctr_images "$IMAGE" "$DOCKERFILE"
clean_cache
# Configure Kata to use the maximum number of available CPUs
# and to use the available free memory.
get_current_kata_config_file KATA_INITIAL_CONFIG_FNAME
set_kata_configuration_performance "${KATA_PERF_CONFIG}"
# Launch container.
sudo -E "${CTR_EXE}" run -d --runtime "${CTR_RUNTIME}" "${IMAGE}" "${TEST_NAME}" sh -c "${PAYLOAD_ARGS}"
# Run the test.
sudo -E "${CTR_EXE}" t exec -t --exec-id "$(random_name)" "${TEST_NAME}" sh -c "${WORKLOAD}"
results_fname=$(sudo -E "${CTR_EXE}" t exec --exec-id $(random_name) ${TEST_NAME} sh -c "ls ${RES_DIR}")
SAVE_RESULTS_CMD="phoronix-test-suite result-file-to-json ${results_fname}"
# Save results.
sudo -E "${CTR_EXE}" t exec --exec-id "$(random_name)" "${TEST_NAME}" sh -c "${SAVE_RESULTS_CMD}"
# Extract results.
sudo -E "${CTR_EXE}" t exec --exec-id "${RANDOM}" "${TEST_NAME}" sh -c "cat /root/${results_fname}.json" > "${TEST_RESULTS_FNAME}"
cat <<< $(jq 'del(.systems[].data)' "${TEST_RESULTS_FNAME}") > "${TEST_RESULTS_FNAME}"
local results="$(cat ${TEST_RESULTS_FNAME})"
metrics_json_init
save_config
metrics_json_start_array
metrics_json_add_array_element "${results}"
metrics_json_end_array "Results"
metrics_json_save
clean_env_ctr
}
main "$@"