forked from Cambridge-ICCS/FTorch-benchmarks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
149 lines (128 loc) · 5.52 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
cmake_minimum_required(VERSION 3.14)
project(FTorch-benchmark Fortran)
# Set a custom build type called Profile that is based on RelWithDebInfo
# and populate it with flags to use instrumented profiling (gprof).
# Also check that build type is set, is one of the permitted types,
# and set it to Debug if it's not set.
# Oh CMake. Somehow these never-before-seen variables are getting set to
# an empty string so this set(...CACHE) doesn't do anything.
if(NOT CMAKE_Fortran_FLAGS_PROFILE)
set(CMAKE_Fortran_FLAGS_PROFILE
"${CMAKE_Fortran_FLAGS_RELWITHDEBINFO} -pg -fno-omit-frame-pointer"
CACHE STRING "" FORCE
)
endif()
if(NOT CMAKE_EXE_LINKER_FLAGS_PROFILE)
set(CMAKE_EXE_LINKER_FLAGS_PROFILE
"${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} -pg"
CACHE STRING "" FORCE
)
endif()
if(NOT CMAKE_SHARED_LINKER_FLAGS_PROFILE)
set(CMAKE_SHARED_LINKER_FLAGS_PROFILE
"${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO} -pg"
CACHE STRING "" FORCE
)
endif()
if(NOT CMAKE_STATIC_LINKER_FLAGS_PROFILE)
set(CMAKE_STATIC_LINKER_FLAGS_PROFILE
"${CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO}"
CACHE STRING "" FORCE
)
endif()
if(NOT CMAKE_MODULE_LINKER_FLAGS_PROFILE)
set(CMAKE_MODULE_LINKER_FLAGS_PROFILE
"${CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO} -pg"
CACHE STRING "" FORCE
)
endif()
get_property(isMultiConfig GLOBAL
PROPERTY GENERATOR_IS_MULTI_CONFIG
)
if(isMultiConfig)
if(NOT "Profile" IN_LIST CMAKE_CONFIGURATION_TYPES)
list(APPEND CMAKE_CONFIGURATION_TYPES Profile)
endif()
else()
set(allowedBuildTypes Debug Release RelWithDebInfo Profile)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY
STRINGS "${allowedBuildTypes}"
)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug CACHE STRING "" FORCE)
elseif(NOT CMAKE_BUILD_TYPE IN_LIST allowedBuildTypes)
message(FATAL_ERROR "Unknown build type: ${CMAKE_BUILD_TYPE}")
endif()
endif()
# Benchmarking Torch
find_package(FTorch)
message(STATUS "Building with the Fortran PyTorch coupling")
if (CMAKE_Fortran_COMPILER_ID STREQUAL "NVHPC")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -Mcpp -Mfreeform -Wall")
elseif (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -cpp -fopenmp -ffree-line-length-none -Wall")
elseif (CMAKE_Fortran_COMPILER_ID STREQUAL "Intel")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fpp -qopenmp -warn all")
endif()
# Set utils sources
set(UTIL_SRC utils/benchmarker_utils_mod.f90 utils/precision_mod.f90)
add_executable(benchmarker_torch benchmark_mima/benchmarker_torch.f90)
target_link_libraries(benchmarker_torch PRIVATE FTorch::ftorch )
target_sources(benchmarker_torch PRIVATE benchmark_mima/cg_drag_torch_mod.f90 ${UTIL_SRC})
# Large stride test
add_executable(benchmarker_large_stride_torch benchmark_large_stride/benchmarker_large_stride_torch.f90)
target_link_libraries(benchmarker_large_stride_torch PRIVATE FTorch::ftorch )
target_sources(benchmarker_large_stride_torch PRIVATE ${UTIL_SRC})
# ResNet test
add_executable(benchmarker_resnet_torch benchmark_resnet/benchmarker_resnet_torch.f90)
target_link_libraries(benchmarker_resnet_torch PRIVATE FTorch::ftorch )
target_sources(benchmarker_resnet_torch PRIVATE ${UTIL_SRC})
# cgdrag test
add_executable(benchmarker_cgdrag_torch benchmark_cgdrag/benchmarker_cgdrag_torch.f90)
target_link_libraries(benchmarker_cgdrag_torch PRIVATE FTorch::ftorch )
target_sources(benchmarker_cgdrag_torch PRIVATE ${UTIL_SRC})
# Make sure python present
# Search until Python version satisfying constraints is located
set(Python_FIND_STRATEGY LOCATION)
# Load interpreter and matching directories/libraries
find_package(Python REQUIRED COMPONENTS Interpreter Development)
# Benchmarking Forpy
# Get forpy module from github
include(FetchContent)
FetchContent_Declare(
forpy
GIT_REPOSITORY https://github.com/ylikx/forpy.git
GIT_TAG b4fc550c7282ed0751d6559c4d867a60af3718a7
# SOURCE_DIR ${FETCHCONTENT_BASE_DIR}/
GIT_PROGRESS ON
# UPDATE_DISCONNECTED ON
)
FetchContent_MakeAvailable(forpy)
message(STATUS "Building with the Fortran Forpy coupling")
add_executable(benchmarker_forpy benchmark_mima/benchmarker_forpy.f90)
target_sources(benchmarker_forpy PRIVATE ${forpy_SOURCE_DIR}/forpy_mod.F90 benchmark_mima/cg_drag_forpy_mod.f90 ${UTIL_SRC})
target_link_libraries(benchmarker_forpy PRIVATE Python::Python)
# Large stride test
option(USETS "Use torchscript format for forpy test" OFF)
add_executable(benchmarker_large_stride_forpy benchmark_large_stride/benchmarker_large_stride_forpy.f90)
target_sources(benchmarker_large_stride_forpy PRIVATE ${forpy_SOURCE_DIR}/forpy_mod.F90 ${UTIL_SRC})
target_link_libraries(benchmarker_large_stride_forpy PRIVATE Python::Python)
if (USETS)
target_compile_definitions(benchmarker_large_stride_forpy PUBLIC USETS)
endif()
# resnet test
option(USETS "Use torchscript format for forpy test" OFF)
add_executable(benchmarker_resnet_forpy benchmark_resnet/benchmarker_resnet_forpy.f90)
target_sources(benchmarker_resnet_forpy PRIVATE ${forpy_SOURCE_DIR}/forpy_mod.F90 ${UTIL_SRC})
target_link_libraries(benchmarker_resnet_forpy PRIVATE Python::Python)
if (USETS)
target_compile_definitions(benchmarker_resnet_forpy PUBLIC USETS)
endif()
# cgdrag test
option(USETS "Use torchscript format for forpy test" OFF)
add_executable(benchmarker_cgdrag_forpy benchmark_cgdrag/benchmarker_cgdrag_forpy.f90)
target_sources(benchmarker_cgdrag_forpy PRIVATE ${forpy_SOURCE_DIR}/forpy_mod.F90 ${UTIL_SRC})
target_link_libraries(benchmarker_cgdrag_forpy PRIVATE Python::Python)
if (USETS)
target_compile_definitions(benchmarker_cgdrag_forpy PUBLIC USETS)
endif()