diff --git a/packaging/build_cmake.sh b/packaging/build_cmake.sh index ff384457e5e..4826ada47e8 100755 --- a/packaging/build_cmake.sh +++ b/packaging/build_cmake.sh @@ -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 @@ -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 diff --git a/test/cpp-ops/CMakeLists.txt b/test/cpp-ops/CMakeLists.txt new file mode 100644 index 00000000000..30173fdfd1b --- /dev/null +++ b/test/cpp-ops/CMakeLists.txt @@ -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) diff --git a/test/cpp-ops/main.cpp b/test/cpp-ops/main.cpp new file mode 100644 index 00000000000..227a2c67cad --- /dev/null +++ b/test/cpp-ops/main.cpp @@ -0,0 +1,14 @@ +#include +#include + +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; +}