Skip to content

Commit 814f047

Browse files
authored
Include the CI for cpp/autograd (#1217)
Include a CI job for cpp/autograd. Split the cpp and python CI jobs.
1 parent 97adea1 commit 814f047

File tree

3 files changed

+123
-0
lines changed

3 files changed

+123
-0
lines changed

.github/workflows/main_cpp.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Run Examples
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
schedule:
9+
# Every day at 3:00am
10+
- cron: '0 3 * * *'
11+
12+
13+
jobs:
14+
test:
15+
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- uses: actions/checkout@v2
20+
- name: Set up Python 3.11
21+
uses: actions/setup-python@v2
22+
with:
23+
python-version: 3.11
24+
25+
- name: Install Cmake, Make, g++, MKL
26+
run: |
27+
sudo apt update && sudo apt upgrade
28+
sudo apt install cmake g++ make
29+
sudo apt-get -y install intel-mkl
30+
- name: Run Cpp Tests
31+
run: |
32+
chmod +x ./run_cpp_examples.sh
33+
./run_cpp_examples.sh "get_libtorch,run_all,clean"
File renamed without changes.

run_cpp_examples.sh

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env bash
2+
# This script runs through the code in each of the cpp examples.
3+
# The purpose is just as an integration test, not to actually train models in any meaningful way.
4+
5+
# Optionally specify a comma separated list of examples to run.
6+
# can be run as:
7+
# ./run_cpp_examples.sh "get_libtorch,run_all,clean"
8+
# To get libtorch, run all examples, and remove temporary/changed data files.
9+
10+
BASE_DIR=`pwd`"/"`dirname $0`
11+
echo "BASE_DIR: $BASE_DIR"
12+
EXAMPLES=`echo $1 | sed -e 's/ //g'`
13+
HOME_DIR=$HOME
14+
ERRORS=""
15+
16+
function error() {
17+
ERR=$1
18+
ERRORS="$ERRORS\n$ERR"
19+
echo $ERR
20+
}
21+
22+
function get_libtorch() {
23+
echo "Getting libtorch"
24+
cd $HOME_DIR
25+
wget https://download.pytorch.org/libtorch/nightly/cpu/libtorch-shared-with-deps-latest.zip
26+
unzip libtorch-shared-with-deps-latest.zip
27+
28+
if [ $? -eq 0 ]; then
29+
echo "Successfully downloaded and extracted libtorch"
30+
LIBTORCH_PATH="$HOME_DIR/libtorch" # Store the LibTorch path in a variable.
31+
echo "LibTorch path: $LIBTORCH_PATH" # Print the LibTorch path
32+
else
33+
error "Failed to download or extract LibTorch"
34+
fi
35+
}
36+
37+
function start() {
38+
EXAMPLE=${FUNCNAME[1]}
39+
cd $BASE_DIR/cpp/$EXAMPLE
40+
echo "Running example: $EXAMPLE"
41+
}
42+
43+
function autograd() {
44+
start
45+
mkdir build
46+
cd build
47+
cmake -DCMAKE_PREFIX_PATH=$LIBTORCH_PATH ..
48+
make
49+
if [ $? -eq 0 ]; then
50+
echo "Successfully built $EXAMPLE"
51+
./$EXAMPLE # Run the executable
52+
else
53+
error "Failed to build $EXAMPLE"
54+
exit 1
55+
fi
56+
}
57+
58+
function clean() {
59+
cd $BASE_DIR
60+
echo "Running clean to remove cruft"
61+
# Remove the build directories
62+
find . -type d -name 'build' -exec rm -rf {} +
63+
# Remove the libtorch directory
64+
rm -rf $HOME_DIR/libtorch
65+
echo "Clean completed"
66+
}
67+
68+
function run_all() {
69+
autograd
70+
}
71+
72+
# by default, run all examples
73+
if [ "" == "$EXAMPLES" ]; then
74+
run_all
75+
else
76+
for i in $(echo $EXAMPLES | sed "s/,/ /g")
77+
do
78+
echo "Starting $i"
79+
$i
80+
echo "Finished $i, status $?"
81+
done
82+
fi
83+
84+
if [ "" == "$ERRORS" ]; then
85+
echo "Completed successfully with status $?"
86+
else
87+
echo "Some examples failed:"
88+
printf "$ERRORS"
89+
exit 1
90+
fi

0 commit comments

Comments
 (0)