forked from microsoft/CNTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-test-common
executable file
·120 lines (102 loc) · 3.03 KB
/
run-test-common
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
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/bash
# Helper script containing common code used by run-test scripts of E2E tests
BinaryPath=$TEST_CNTK_BINARY
if [ "$TEST_DEVICE" == "cpu" ]; then
CNTKDeviceId=-1
elif [ "$TEST_DEVICE" == "gpu" ]; then
CNTKDeviceId=0
else
echo "Error: Unknown TEST_DEVICE specified!"
exit 3
fi
LogFileName=
ConfigDir=$TEST_DIR
RunDir=$TEST_RUN_DIR
DataDir=$TEST_DATA_DIR
OutputDir=$TEST_RUN_DIR
MPIMode=0
MPIArgs=
DeleteExistingModels=1
DeleteModelsAfterTest=0
# Helper function to print and run a command
run()
{
cmd=$1
shift
if [ "$DRY_RUN" == "1" ]; then
workingDir=$PWD
if [ "$OS" == "Windows_NT" ]; then
workingDir=$(cygpath -aw $workingDir)
if [[ $MPIMode == 0 ]]; then
cmd=$(cygpath -aw $cmd)
TEST_ROOT_DIR_ESCAPED=`echo -n $(cygpath -aw $TEST_ROOT_DIR) | sed 's/\\\\/\\\\\\\\/g'`
workingDir=`echo "$workingDir" | sed "s/$TEST_ROOT_DIR_ESCAPED/\\$\\(SolutionDir\\)\\\\\\\\Tests\\\\\\\\EndToEndTests/g"`
fi
fi
echo Working Directory: $workingDir
echo Full command: "$cmd" "$@"
if [ "$OS" == "Windows_NT" ]; then
if [[ $MPIMode == 0 ]]; then
echo VS debugging command args: "$@" | sed "s/$TEST_ROOT_DIR_ESCAPED/\\$\\(SolutionDir\\)\\\\Tests\\\\EndToEndTests/g"
fi
fi
return 1
else
echo === Running "$cmd" "$@"
"$cmd" "$@"
return $?
fi
}
# Function for launching the CNTK executable
# cntkrun <CNTK config file name> <additional CNTK args>
cntkrun()
{
configFileName=$1
additionalCNTKArgs=$2
if [ "$OS" == "Windows_NT" ]; then
# When running on cygwin translating /cygdrive/xxx paths to proper windows paths:
ConfigDir=$(cygpath -aw $ConfigDir)
RunDir=$(cygpath -aw $RunDir)
DataDir=$(cygpath -aw $DataDir)
OutputDir=$(cygpath -aw $OutputDir)
fi
CNTKArgs="configFile=$ConfigDir/$configFileName currentDirectory=$DataDir RunDir=$RunDir DataDir=$DataDir ConfigDir=$ConfigDir OutputDir=$OutputDir DeviceId=$CNTKDeviceId $additionalCNTKArgs"
if [ "$LogFileName" != "" ]; then
CNTKArgs="$CNTKArgs stderr=$RunDir/$LogFileName"
fi
modelsDir=$TEST_RUN_DIR/Models
if [[ $DeleteExistingModels == 1 ]]; then
[ -d $modelsDir ] && rm -rf $modelsDir
fi
mkdir -p $modelsDir || exit $?
if [[ $MPIMode == 0 ]]; then
run "$BinaryPath" $CNTKArgs
else
run "$MPI_BINARY" $MPIArgs $BinaryPath $CNTKArgs
fi
if [[ $DeleteModelsAfterTest == 1 ]]; then
[ -d $modelsDir ] && rm -rf $modelsDir
fi
return $?
}
# Given number of instances, return number of hardware threads we can use per
# instance
threadsPerInstance()
{
local threads=$((`nproc` / $1))
[[ $threads -eq 0 ]] && echo 1 || echo $threads
}
# Function for launching a parallel CNTK run with MPI
# cntkmpirun <MPI args> <CNTK config file name> <additional CNTK args>
cntkmpirun()
{
# Since we use the MS MPI program on Windows, the CNTK binary path argument
# passed to mpiexec must be in the windows format
if [ "$OS" == "Windows_NT" ]; then
BinaryPath=$(cygpath -aw $BinaryPath)
fi
MPIMode=1
MPIArgs=$1
cntkrun "$2" "$3"
return $?
}