Skip to content
Open
Show file tree
Hide file tree
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
21 changes: 20 additions & 1 deletion packaging/build_cmake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ fi

# Compile and run the CPP example
popd
cd examples/cpp/hello_world
pushd examples/cpp/hello_world

mkdir build
cd build
Expand All @@ -99,3 +99,22 @@ fi

# Run CPP example
./hello-world


# Compile and run the CPP ops test
popd
pushd test/cpp-ops
mkdir build
cd build
cmake .. -DTorch_DIR=$TORCH_PATH/share/cmake/Torch
cmake --build .

# Disable exit on non 0
set +e
./vision-ops-test
# Ensure that there are 9 registered ops.
if [ "$?" != "9" ]; then
exit 1
fi
# Enable exit on non 0
set -e
9 changes: 9 additions & 0 deletions test/cpp-ops/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.8)
project(vision-ops-test)

set(CMAKE_CXX_STANDARD 14)

find_package(TorchVision REQUIRED)

add_executable(vision-ops-test main.cpp)
target_link_libraries(vision-ops-test TorchVision::TorchVision)
14 changes: 14 additions & 0 deletions test/cpp-ops/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <torchvision/vision.h>
#include <torch/csrc/jit/runtime/operator.h>

int main() {
auto ops = torch::jit::getAllOperators();
int vision_ops_count = 0;
for (const auto &op : ops) {
const auto &schema = op->schema();
const auto &ns = schema.getNamespace();
if (ns.has_value() && ns.value() == "torchvision")
++vision_ops_count;
}
return vision_ops_count;
}