Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature precompiled header #23

Merged
merged 5 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,42 @@ set(CMAKE_CXX_STANDARD 17)
project(nuTens)
enable_testing()

## check build times
## have this optional as it's not supported on all CMake platforms
OPTION(BUILD_TIMING "output time to build each target" OFF)
IF(BUILD_TIMING)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CMAKE_COMMAND} -E time")
ENDIF()

find_package(Torch REQUIRED)
find_package(Protobuf REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")


## if user wants to use pch then we use the pch
## people, especially if developing, might want to use this as including tensor related things
## can be excruciatingly sloow when building
OPTION(USE_PCH "USE_PCH" OFF)
IF(USE_PCH)
message("Using precompiled header")

add_library(nuTens-pch nuTens-pch.hpp)

## the headers included in the PCH will (at some point) depend on which tensor library is being used
IF(TORCH_FOUND)
message( "Including PyTorch includes in the PCH")
message( "TORCH_LIBRARIES = ")
message( "${TORCH_LIBRARIES}")

target_compile_definitions(nuTens-pch PUBLIC USE_PYTORCH)
SET(PCH_LIBS "${TORCH_LIBRARIES}")
ENDIF()

target_link_libraries(nuTens-pch PUBLIC "${PCH_LIBS}")
target_precompile_headers(nuTens-pch PUBLIC nuTens-pch.hpp)
set_target_properties(nuTens-pch PROPERTIES LINKER_LANGUAGE CXX)

ENDIF() ## end USE_PCH block

add_subdirectory(nuTens)
add_subdirectory(tests)
13 changes: 13 additions & 0 deletions nuTens-pch.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <iostream>
#include <vector>
#include <math.h>
#include <map>
#include <any>
#include <variant>
#include <complex>

#if USE_PYTORCH
#include <torch/torch.h>
#endif
4 changes: 4 additions & 0 deletions nuTens/propagator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ add_library(
const-density-solver.hpp const-density-solver.cpp
)

IF(USE_PCH)
target_precompile_headers(propagator REUSE_FROM tensor)
ENDIF()

target_link_libraries(propagator PUBLIC tensor constants)

target_include_directories(propagator PUBLIC "${CMAKE_SOURCE_DIR}")
Expand Down
17 changes: 12 additions & 5 deletions nuTens/tensors/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@


IF(TORCH_FOUND)
message( "Found tensor library: PyTorch")

add_library(tensor STATIC tensor.hpp torch-tensor.cpp)
target_compile_definitions(tensor PUBLIC USE_PYTORCH)
target_link_libraries(tensor PUBLIC "${TORCH_LIBRARIES}")
ENDIF()

IF(USE_PCH)
target_link_libraries(tensor PUBLIC nuTens-pch)

ELSE()
message( FATAL_ERROR "No library found to deal with tensors. Currently only pytorch is available, please install this and try again." )
ENDIF()
IF(TORCH_FOUND)

target_link_libraries(tensor PUBLIC "${TORCH_LIBRARIES}")

ELSE()
message( FATAL_ERROR "No library found to deal with tensors. Currently only pytorch is available, please install this and try again." )
ENDIF()
ENDIF()

target_include_directories(tensor PUBLIC "${CMAKE_SOURCE_DIR}")
set_target_properties(tensor PROPERTIES LINKER_LANGUAGE CXX)
33 changes: 12 additions & 21 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,18 @@ add_library(test-utils test-utils.hpp barger-propagator.hpp)
target_link_libraries(test-utils PUBLIC constants)
set_target_properties(test-utils PROPERTIES LINKER_LANGUAGE CXX)

add_executable(tensor-basic tensor-basic.cpp)
target_link_libraries(tensor-basic PUBLIC tensor test-utils)
target_include_directories(tensor-basic PUBLIC "${CMAKE_SOURCE_DIR}")
foreach(TESTNAME
barger tensor-basic two-flavour-vacuum two-flavour-const-matter
)

add_test(NAME tensor-basic-test COMMAND tensor-basic)
add_executable("${TESTNAME}" "${TESTNAME}.cpp")

IF(USE_PCH)
target_precompile_headers("${TESTNAME}" REUSE_FROM tensor)
ENDIF()

target_link_libraries("${TESTNAME}" PUBLIC test-utils tensor propagator)
target_include_directories("${TESTNAME}" PUBLIC "${CMAKE_SOURCE_DIR}")
add_test(NAME "${TESTNAME}-test" COMMAND "${TESTNAME}")

add_executable(barger barger-test.cpp)
target_link_libraries(barger PUBLIC test-utils)
target_include_directories(barger PUBLIC "${CMAKE_SOURCE_DIR}")

add_test(NAME barger-test COMMAND barger)


add_executable(two-flavour-vacuum two-flavour-vacuum.cpp)
target_link_libraries(two-flavour-vacuum PUBLIC propagator test-utils)

add_test(NAME two-flavour-vacuum-test COMMAND two-flavour-vacuum)


add_executable(two-flavour-const-matter two-flavour-const-matter.cpp)
target_link_libraries(two-flavour-const-matter PUBLIC propagator test-utils)

add_test(NAME two-flavour-const-matter-test COMMAND two-flavour-const-matter)
endforeach()
File renamed without changes.