Unverified Commit c36dc43b authored by Edgar Andrés Margffoy Tuay's avatar Edgar Andrés Margffoy Tuay Committed by GitHub
Browse files

PR: Run C++ torchvision example as part of cmake tests (#2678)

* Run C++ torchvision example as part of cmake tests

* Enable C++14 support

* Minor error correction

* Add GPU forward on example

* Use arrow operator
parent ca26022c
...@@ -11,4 +11,6 @@ add_executable(hello-world main.cpp) ...@@ -11,4 +11,6 @@ add_executable(hello-world main.cpp)
# We now need to link the TorchVision library to our executable. # We now need to link the TorchVision library to our executable.
# We can do that by using the TorchVision::TorchVision target, # We can do that by using the TorchVision::TorchVision target,
# which also adds all the necessary torch dependencies. # which also adds all the necessary torch dependencies.
target_compile_features(hello-world PUBLIC cxx_range_for)
target_link_libraries(hello-world TorchVision::TorchVision) target_link_libraries(hello-world TorchVision::TorchVision)
set_property(TARGET hello-world PROPERTY CXX_STANDARD 14)
#include <iostream> #include <iostream>
#include <torchvision/models/resnet.h> #include <torchvision/models/resnet.h>
int main() int main()
...@@ -11,5 +10,14 @@ int main() ...@@ -11,5 +10,14 @@ int main()
auto in = torch::rand({1, 3, 10, 10}); auto in = torch::rand({1, 3, 10, 10});
auto out = model->forward(in); auto out = model->forward(in);
std::cout << out; std::cout << out.sizes();
if (torch::cuda::is_available()) {
// Move model and inputs to GPU
model->to(torch::kCUDA);
auto gpu_in = in.to(torch::kCUDA);
auto gpu_out = model->forward(gpu_in);
std::cout << gpu_out.sizes();
}
} }
...@@ -61,7 +61,7 @@ popd ...@@ -61,7 +61,7 @@ popd
python setup.py develop python setup.py develop
# Trace, compile and run project that uses Faster-RCNN # Trace, compile and run project that uses Faster-RCNN
cd test/tracing/frcnn pushd test/tracing/frcnn
mkdir build mkdir build
# Trace model # Trace model
...@@ -81,3 +81,21 @@ fi ...@@ -81,3 +81,21 @@ fi
# Run traced program # Run traced program
./test_frcnn_tracing ./test_frcnn_tracing
# Compile and run the CPP example
popd
cd examples/cpp/hello_world
mkdir build
cd build
cmake .. -DTorch_DIR=$TORCH_PATH/share/cmake/Torch
if [[ "$OSTYPE" == "msys" ]]; then
"$script_dir/windows/internal/vc_env_helper.bat" "$script_dir/windows/internal/build_cpp_example.bat"
cd Release
else
make
fi
# Run CPP example
./hello-world
@echo on
set CL=/I"C:\Program Files (x86)\torchvision\include"
msbuild "-p:Configuration=Release" hello-world.vcxproj
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment