Skip to content

Commit d78cff0

Browse files
authored
Add CI jobs for cpp/mnist and cpp/regression (#1220)
1 parent b2832cc commit d78cff0

File tree

1 file changed

+50
-2
lines changed

1 file changed

+50
-2
lines changed

run_cpp_examples.sh

+50-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ function error() {
2222
function get_libtorch() {
2323
echo "Getting libtorch"
2424
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
2729

2830
if [ $? -eq 0 ]; then
2931
echo "Successfully downloaded and extracted libtorch"
@@ -40,6 +42,16 @@ function start() {
4042
echo "Running example: $EXAMPLE"
4143
}
4244

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+
4355
function autograd() {
4456
start
4557
mkdir build
@@ -49,6 +61,7 @@ function autograd() {
4961
if [ $? -eq 0 ]; then
5062
echo "Successfully built $EXAMPLE"
5163
./$EXAMPLE # Run the executable
64+
check_run_success $EXAMPLE
5265
else
5366
error "Failed to build $EXAMPLE"
5467
exit 1
@@ -75,6 +88,39 @@ function custom-dataset() {
7588
echo "Successfully built $EXAMPLE"
7689
cd $BASE_DIR/cpp/$EXAMPLE
7790
./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
78124
else
79125
error "Failed to build $EXAMPLE"
80126
exit 1
@@ -95,6 +141,8 @@ function clean() {
95141
function run_all() {
96142
autograd
97143
custom-dataset
144+
mnist
145+
regression
98146
}
99147

100148
# by default, run all examples

0 commit comments

Comments
 (0)