@@ -22,8 +22,10 @@ function error() {
22
22
function get_libtorch() {
23
23
echo " Getting libtorch"
24
24
cd $HOME_DIR
25
- wget https://download.pytorch.org/libtorch/nightly/cpu/libtorch-cxx11-abi-shared-with-deps-latest.zip
26
- unzip libtorch-cxx11-abi-shared-with-deps-latest.zip
25
+ if [ ! -d " libtorch" ]; then
26
+ wget https://download.pytorch.org/libtorch/nightly/cpu/libtorch-cxx11-abi-shared-with-deps-latest.zip
27
+ unzip libtorch-cxx11-abi-shared-with-deps-latest.zip
28
+ fi
27
29
28
30
if [ $? -eq 0 ]; then
29
31
echo " Successfully downloaded and extracted libtorch"
@@ -40,6 +42,16 @@ function start() {
40
42
echo " Running example: $EXAMPLE "
41
43
}
42
44
45
+ function check_run_success() {
46
+ if [ $? -eq 0 ]; then
47
+ echo " Successfully ran $1 "
48
+ else
49
+ echo " Failed to run $1 "
50
+ error " Failed to run $1 "
51
+ exit 1
52
+ fi
53
+ }
54
+
43
55
function autograd() {
44
56
start
45
57
mkdir build
@@ -49,6 +61,7 @@ function autograd() {
49
61
if [ $? -eq 0 ]; then
50
62
echo " Successfully built $EXAMPLE "
51
63
./$EXAMPLE # Run the executable
64
+ check_run_success $EXAMPLE
52
65
else
53
66
error " Failed to build $EXAMPLE "
54
67
exit 1
@@ -75,6 +88,39 @@ function custom-dataset() {
75
88
echo " Successfully built $EXAMPLE "
76
89
cd $BASE_DIR /cpp/$EXAMPLE
77
90
./build/$EXAMPLE # Run the executable
91
+ check_run_success $EXAMPLE
92
+ else
93
+ error " Failed to build $EXAMPLE "
94
+ exit 1
95
+ fi
96
+ }
97
+
98
+ function mnist() {
99
+ start
100
+ mkdir build
101
+ cd build
102
+ cmake -DCMAKE_PREFIX_PATH=$LIBTORCH_PATH ..
103
+ make
104
+ if [ $? -eq 0 ]; then
105
+ echo " Successfully built $EXAMPLE "
106
+ ./$EXAMPLE # Run the executable
107
+ check_run_success $EXAMPLE
108
+ else
109
+ error " Failed to build $EXAMPLE "
110
+ exit 1
111
+ fi
112
+ }
113
+
114
+ function regression() {
115
+ start
116
+ mkdir build
117
+ cd build
118
+ cmake -DCMAKE_PREFIX_PATH=$LIBTORCH_PATH ..
119
+ make
120
+ if [ $? -eq 0 ]; then
121
+ echo " Successfully built $EXAMPLE "
122
+ ./$EXAMPLE # Run the executable
123
+ check_run_success $EXAMPLE
78
124
else
79
125
error " Failed to build $EXAMPLE "
80
126
exit 1
@@ -95,6 +141,8 @@ function clean() {
95
141
function run_all() {
96
142
autograd
97
143
custom-dataset
144
+ mnist
145
+ regression
98
146
}
99
147
100
148
# by default, run all examples
0 commit comments