Created
December 11, 2021 12:59
-
-
Save OlegJakushkin/f3bb5ecb91b23443dac0088b82122bac to your computer and use it in GitHub Desktop.
torchpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 3.15) | |
project(torchpp) | |
set(CMAKE_CXX_STANDARD 14) | |
find_package(Torch REQUIRED) | |
add_executable(torchpp main.cpp) | |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}") | |
target_link_libraries(torchpp "${TORCH_LIBRARIES}") | |
set_property(TARGET torchpp PROPERTY CXX_STANDARD 14) | |
if (MSVC) | |
file(GLOB TORCH_DLLS "${TORCH_INSTALL_PREFIX}/lib/*.dll") | |
add_custom_command(TARGET example-app | |
POST_BUILD | |
COMMAND ${CMAKE_COMMAND} -E copy_if_different | |
${TORCH_DLLS} | |
$<TARGET_FILE_DIR:example-app>) | |
endif (MSVC) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <torch/torch.h> | |
int main() { | |
torch::Tensor tensor = torch::rand({2, 3, 3, 3, 3}); | |
torch::Tensor tensor2 = torch::rand({3}); | |
std::cout << tensor << std::endl << tensor2 << std::endl; | |
std::cout << "Hello, World!" << std::endl; | |
std::cout << tensor * tensor2 << std::endl; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add cmake config argument
-DTorch_DIR=/home/user/Documents/torch/libtorch/share/cmake/Torch