-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathCMakeLists.txt
62 lines (52 loc) · 2.05 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
# policy CMP0076 - target_sources source files are relative to file where
# target_sources is run
cmake_policy(SET CMP0076 NEW)
set(PROJECT_NAME SimpleNetExample)
project(${PROJECT_NAME} LANGUAGES Fortran)
# Build in Debug mode if not specified
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE
Debug
CACHE STRING "" FORCE)
endif()
find_package(FTorch)
message(STATUS "Building with Fortran PyTorch coupling")
# Fortran example
add_executable(simplenet_infer_fortran simplenet_infer_fortran.f90)
target_link_libraries(simplenet_infer_fortran PRIVATE FTorch::ftorch)
# Integration testing
if(CMAKE_BUILD_TESTS)
include(CTest)
# 1. Check the PyTorch model runs and its outputs meet expectations
add_test(NAME simplenet COMMAND ${PYTHON_EXECUTABLE}
${PROJECT_SOURCE_DIR}/simplenet.py)
# 1. Check the model is saved to file in the expected location with the
# pt2ts.py script
add_test(
NAME pt2ts
COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/pt2ts.py
${PROJECT_BINARY_DIR}
# Command line argument: filepath for saving the model
WORKING_DIRECTORY ${PROJECT_BINARY_DIR})
# 1. Check the model can be loaded from file and run in Python and that its
# outputs meet expectations
add_test(
NAME simplenet_infer_python
COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/simplenet_infer_python.py
${PROJECT_BINARY_DIR}
# Command line argument: filepath to find the model
WORKING_DIRECTORY ${PROJECT_BINARY_DIR})
# 1. Check the model can be loaded from file and run in Fortran and that its
# outputs meet expectations
add_test(
NAME simplenet_infer_fortran
COMMAND
simplenet_infer_fortran
${PROJECT_BINARY_DIR}/saved_simplenet_model_cpu.pt
# Command line argument: model file
WORKING_DIRECTORY ${PROJECT_BINARY_DIR})
set_tests_properties(
simplenet_infer_fortran PROPERTIES PASS_REGULAR_EXPRESSION
"SimpleNet example ran successfully")
endif()