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

Draft: Factor build/link/use of VecGeom/CUDA using libraries for simplicity #279

Closed
wants to merge 8 commits into from
Closed
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
44 changes: 21 additions & 23 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
include(CMakeSettings)
include(CTest)
include(CheckCXXSourceCompiles)
include(CudaRdcUtils)

# - Core/C++/CUDA build and dependency settings
# For single-mode generators, default to Optimized with Debug if nothing is specified
Expand Down Expand Up @@ -146,20 +147,28 @@ set(ADEPT_G4_INTEGRATION_SRCS
src/AdePTConfigurationMessenger.cc
)

add_library(CopCore INTERFACE)
target_include_directories(CopCore
# - Build RDC/Non-RDC libraries
# NB: The ALIAS call after the main library MUST be here to make
# RDC-enabled libraries to work when installed with a NAMESPACE.

# - CopCore
cuda_rdc_add_library(CopCore INTERFACE)
cuda_rdc_add_library(AdePT::CopCore ALIAS CopCore)
cuda_rdc_target_include_directories(CopCore
INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/AdePT/copcore/>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}>
)

add_library(AdePT_G4_integration SHARED ${ADEPT_G4_INTEGRATION_SRCS})
target_include_directories(AdePT_G4_integration
# - AdePT_G4_integration
cuda_rdc_add_library(AdePT_G4_integration SHARED ${ADEPT_G4_INTEGRATION_SRCS})
cuda_rdc_add_library(AdePT::AdePT_G4_integration ALIAS AdePT_G4_integration)
cuda_rdc_target_include_directories(AdePT_G4_integration
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_link_libraries(AdePT_G4_integration
cuda_rdc_target_link_libraries(AdePT_G4_integration
PUBLIC
CopCore
VecGeom::vecgeom
Expand All @@ -168,14 +177,6 @@ target_link_libraries(AdePT_G4_integration
${Geant4_LIBRARIES}
G4HepEm::g4HepEm
G4HepEm::g4HepEmData
G4HepEm::g4HepEmInit
G4HepEm::g4HepEmRun
)

set_target_properties(AdePT_G4_integration
PROPERTIES
CUDA_SEPARABLE_COMPILATION ON
CUDA_RESOLVE_DEVICE_SYMBOLS ON
)

# Optional library to activate NVTX annotations for profiling:
Expand Down Expand Up @@ -203,7 +204,7 @@ configure_package_config_file(cmake/${PROJECT_NAME}Config.cmake.in
)

#Install the libraries
install(TARGETS CopCore AdePT_G4_integration
cuda_rdc_install(TARGETS CopCore AdePT_G4_integration
EXPORT ${PROJECT_NAME}Targets
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
Expand All @@ -215,18 +216,15 @@ install(DIRECTORY include/AdePT
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

#Install the configuration file
install(FILES "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/AdePTConfig.cmake"
#Install the configuration files and needed modules for downstream
install(FILES "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/AdePTConfig.cmake"
"${PROJECT_SOURCE_DIR}/cmake/CudaRdcUtils.cmake"
"${PROJECT_SOURCE_DIR}/cmake/FindVecGeom.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)

#Export the targets file
export(TARGETS CopCore AdePT_G4_integration
FILE "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${PROJECT_NAME}Targets.cmake"
)

#Install the targets file
install(EXPORT ${PROJECT_NAME}Targets
NAMESPACE ${PROJECT_NAME}::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)
)
7 changes: 7 additions & 0 deletions LICENSES/MIT.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright <YEAR> <COPYRIGHT HOLDER>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 changes: 19 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,22 +109,33 @@ $ CUDA_VISIBLE_DEVICES=0 BuildProducts/bin/<executable> ### use the device num

In order to include AdePT in a separate project we need to run:

```
```cmake
find_package(AdePT)
```

Which has the same dependencies as before (VecGeom, VecCore and G4HepEM).

Then, for the targets using AdePT:
Due to the design of the CUDA interface in the VecGeom dependency, linking to
AdePT whether or not your project uses CUDA code requires use of CMake wrapper
functions to ensure the correct device linking. For an executable target:

```cmake
include(CudaRdcUtils)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be done transparently in AdePTConfig.cmake.in?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to enforce an explicit include for now for clarity in downstream use It also matches the Celeritas pattern of use. We can of course review (in both) in future.


add_executable(MyExe MyExe.cc)
cuda_rdc_target_link_libraries(MyExe AdePT::AdePT_G4_integration)
```
target_include_directories(example_target <SCOPE>
<TARGET INCLUDE DIRECTORIES>
${AdePT_INCLUDE_DIRS})

target_link_libraries(example_target <SCOPE>
<TARGET LINK LIBRARIES>
${AdePT_LIBRARIES})
and for a library plus executable:

```cmake
include(CudaRdcUtils)

cuda_rdc_add_library(MyLib ...)
cuda_rdc_target_link_libraries(MyLib AdePT::AdePT_G4_integration)

add_executable(MyExe MyExe.cc)
cuda_rdc_target_link_libraries(MyExe MyLib)
```

## Copyright
Expand Down
13 changes: 10 additions & 3 deletions cmake/AdePTConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
set(AdePT_INCLUDE_DIRS "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@")
set_and_check(AdePT_CMAKE_DIR "${CMAKE_CURRENT_LIST_DIR}")

# So that we find VecGeom and set appropriate RDC flags, we need
# to use our own wrapper module, but only here.
list(PREPEND CMAKE_MODULE_PATH "${AdePT_CMAKE_DIR}")

set(AdePT_LIBRARIES
AdePT::CopCore
AdePT::AdePT_G4_integration)

# Find required dependencies

SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--disable-new-dtags")
set(CMAKE_EXE_LINKER_FLAGS "-Wl,--disable-new-dtags")

include(CMakeFindDependencyMacro)

Expand All @@ -33,4 +36,8 @@ if(G4HepEm_FOUND)
endif()

# Include the targets file
include("${AdePT_CMAKE_DIR}/AdePTTargets.cmake")
include("${AdePT_CMAKE_DIR}/AdePTTargets.cmake")

# Restore CMAKE_MODULE_PATH, with ours at the back
list(REMOVE_ITEM CMAKE_MODULE_PATH "${AdePT_CMAKE_DIR}")
list(APPEND CMAKE_MODULE_PATH "${AdePT_CMAKE_DIR}")
Loading
Loading