Skip to content

Commit

Permalink
amend
Browse files Browse the repository at this point in the history
  • Loading branch information
lancerts committed Jan 23, 2024
1 parent 42b3bda commit e125dc4
Showing 1 changed file with 52 additions and 4 deletions.
56 changes: 52 additions & 4 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 error_run() {
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
error_run "autograd"
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
error_run "custom-dataset"
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
error_run "mnist"
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
error_run "regression"
else
error "Failed to build $EXAMPLE"
exit 1
Expand All @@ -93,8 +139,10 @@ function clean() {
}

function run_all() {
autograd
custom-dataset
# autograd
# custom-dataset
mnist
# regression
}

# by default, run all examples
Expand Down

0 comments on commit e125dc4

Please sign in to comment.