Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 50 additions & 2 deletions run_cpp_examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ function error() {
function get_libtorch() {
echo "Getting libtorch"
cd $HOME_DIR
wget https://download.pytorch.org/libtorch/nightly/cpu/libtorch-cxx11-abi-shared-with-deps-latest.zip
unzip libtorch-cxx11-abi-shared-with-deps-latest.zip
if [ ! -d "libtorch" ]; then
wget https://download.pytorch.org/libtorch/nightly/cpu/libtorch-cxx11-abi-shared-with-deps-latest.zip
unzip libtorch-cxx11-abi-shared-with-deps-latest.zip
fi

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

function check_run_success() {
if [ $? -eq 0 ]; then
echo "Successfully ran $1"
else
echo "Failed to run $1"
error "Failed to run $1"
exit 1
fi
}

function autograd() {
start
mkdir build
Expand All @@ -49,6 +61,7 @@ function autograd() {
if [ $? -eq 0 ]; then
echo "Successfully built $EXAMPLE"
./$EXAMPLE # Run the executable
check_run_success $EXAMPLE
else
error "Failed to build $EXAMPLE"
exit 1
Expand All @@ -75,6 +88,39 @@ function custom-dataset() {
echo "Successfully built $EXAMPLE"
cd $BASE_DIR/cpp/$EXAMPLE
./build/$EXAMPLE # Run the executable
check_run_success $EXAMPLE
else
error "Failed to build $EXAMPLE"
exit 1
fi
}

function mnist() {
start
mkdir build
cd build
cmake -DCMAKE_PREFIX_PATH=$LIBTORCH_PATH ..
make
if [ $? -eq 0 ]; then
echo "Successfully built $EXAMPLE"
./$EXAMPLE # Run the executable
check_run_success $EXAMPLE
else
error "Failed to build $EXAMPLE"
exit 1
fi
}

function regression() {
start
mkdir build
cd build
cmake -DCMAKE_PREFIX_PATH=$LIBTORCH_PATH ..
make
if [ $? -eq 0 ]; then
echo "Successfully built $EXAMPLE"
./$EXAMPLE # Run the executable
check_run_success $EXAMPLE
else
error "Failed to build $EXAMPLE"
exit 1
Expand All @@ -95,6 +141,8 @@ function clean() {
function run_all() {
autograd
custom-dataset
mnist
regression
}

# by default, run all examples
Expand Down