-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script & case for benchmark utility (#272)
* Add new feature for benchmark utility;
- Loading branch information
Showing
7 changed files
with
150 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/bin/bash | ||
|
||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
|
||
declare THIS_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
declare MODELS=$THIS_SCRIPT_DIR/../../models | ||
|
||
create_cuda_container(){ | ||
docker kill $1 >/dev/null 2>&1 || true | ||
docker rm $1 >/dev/null 2>&1 || true | ||
docker run --gpus all --name $1 -t -d --net=host -e EXEC_BASH=1 -v $THIS_SCRIPT_DIR/../../:/nnfusion -v $THIS_SCRIPT_DIR/../../../frozenmodels:/frozenmodels -w /nnfusion $2 bash | ||
} | ||
|
||
# check if inside one docker container(for testing) | ||
if [ -f "/.dockerenv" ]; then | ||
$THIS_SCRIPT_DIR/build.sh | ||
python3 $THIS_SCRIPT_DIR/../../test/nnfusion/scripts/e2e_tests.py $THIS_SCRIPT_DIR/../../test/nnfusion/scripts/perf.json | ||
else | ||
|
||
if [ ! -d "$THIS_SCRIPT_DIR/../../models/frozenmodels/" ]; then | ||
# prepare models | ||
if [ ! -d "$THIS_SCRIPT_DIR/../../../frozenmodels/" ]; then | ||
$THIS_SCRIPT_DIR/download_models.sh | ||
fi | ||
fi | ||
|
||
# use nnfusion_base for build / test cpu | ||
create_cuda_container nnfusion_cuda_dev nnfusion/cuda:10.2-cudnn7-devel-ubuntu18.04 | ||
if [ $? -ne 0 ]; then | ||
echo "One or many Docker containers were not built. Run ./build_containers.sh ." | ||
exit 1 | ||
fi | ||
|
||
# build & install | ||
# docker exec -t nnfusion_cuda_dev /nnfusion/maint/script/build.sh | ||
|
||
failed=0 | ||
|
||
res=`lspci | grep -i nvidia` | ||
if [ ! -z "$res" ]; then | ||
echo "Launch Cuda container to benchmark:" | ||
docker exec -t nnfusion_cuda_dev /nnfusion/maint/script/benchmark.sh & | ||
fi | ||
|
||
for job in `jobs -p` | ||
do | ||
wait $job || let "failed+=1" | ||
done | ||
|
||
docker exec -t nnfusion_cuda_dev sh -c "rm -rf /nnfusion/build /nnfusion/nnfusion_rt" | ||
docker exec -t nnfusion_cuda_dev sh -c "find /nnfusion -type d -name '__pycache__' | xargs rm -rf" | ||
|
||
if [ ! "$failed" == "0" ]; then | ||
echo "Test execution failed." | ||
exit 1 | ||
fi | ||
|
||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"env": { | ||
"PYTHONDONTWRITEBYTECODE" : { | ||
"set" : 1 | ||
}, | ||
"HSA_USERPTR_FOR_PAGED_MEM": { | ||
"set": 0 | ||
}, | ||
"LD_LIBRARY_PATH": { | ||
"append": "/usr/local/lib" | ||
}, | ||
"HIP_VISIBLE_DEVICES" : { | ||
"set": 1 | ||
} | ||
}, | ||
"device_capability": ["CUDA"], | ||
"enabled_tags": { | ||
"CUDA" : ["perf"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,4 +51,4 @@ | |
"comment": "Naive json descriptor for test case." | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
|
||
import logging | ||
import os | ||
from testcases.testcase import * | ||
|
||
|
||
class PerfOutput(TestCase): | ||
def __init__(self, casename, filename, tags, flag): | ||
self.casename = casename | ||
self.filename = filename | ||
self.tags = tags | ||
self.flag = flag | ||
|
||
# Get data from output of main_test | ||
def allclose(self, raw_strdata): | ||
return True | ||
|
||
def latency(self, raw_strdata): | ||
real_time = float(raw_strdata[-1].strip("\n").split(" ")[-2][:-1]) | ||
return real_time | ||
#return raw_strdata[-1] | ||
|
||
|
||
def create_perf_case(base_folder, json_data): | ||
testcase = json_data["testcase"] | ||
tags = json_data["tag"] | ||
filename = os.path.join(base_folder, json_data["filename"]) | ||
flag = "" | ||
if "flag" in json_data: | ||
flag = json_data["flag"] | ||
|
||
return PerfOutput(testcase, filename, tags, flag) |