Back to home page

EIC code displayed by LXR

 
 

    


Warning, /geant4/examples/extended/parameterisations/Par04/CMakeLists.txt is written in an unsupported language. File is not indexed.

0001 #----------------------------------------------------------------------------
0002 # Setup the project
0003 cmake_minimum_required(VERSION 3.16...3.27)
0004 
0005 # must be set before project(...) call; version module is needed before
0006 list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
0007 
0008 project(Par04)
0009 
0010 #----------------------------------------------------------------------------
0011 # Find Geant4 package, activating all available UI and Vis drivers by default
0012 # You can set WITH_GEANT4_UIVIS to OFF via the command line or ccmake/cmake-gui
0013 # to build a batch mode only executable
0014 #
0015 SET(GEANT4_MIN_VERSION "11.0")
0016 option(WITH_GEANT4_UIVIS "Build example with Geant4 UI and Vis drivers" ON)
0017 if(WITH_GEANT4_UIVIS)
0018   find_package(Geant4 ${GEANT4_MIN_VERSION} REQUIRED ui_all vis_all)
0019 else()
0020   find_package(Geant4 ${GEANT4_MIN_VERSION} REQUIRED)
0021 endif()
0022 
0023 #----------------------------------------------------------------------------
0024 # Setup Geant4 include directories and compile definitions
0025 #
0026 include(${Geant4_USE_FILE})
0027 
0028 #----------------------------------------------------------------------------
0029 # Setup ML-infernce (LCG)
0030 #
0031 option(INFERENCE_LIB "The inference library: currently implemented LWTNN and ONNX" ON)
0032 
0033 # LWTNN
0034 if(INFERENCE_LIB)
0035    find_package(lwtnn QUIET)
0036    if(lwtnn_FOUND)
0037            message("LWTNN inference library found.")
0038            add_definitions(-DUSE_INFERENCE)
0039            add_definitions(-DUSE_INFERENCE_LWTNN)
0040    else()
0041      message("LWTNN not found!")
0042    endif()
0043 endif()
0044 
0045 # ONNX
0046 if(INFERENCE_LIB)
0047   find_package(OnnxRuntime QUIET)
0048   find_package(CUDAToolkit QUIET)
0049    if(OnnxRuntime_FOUND)
0050        message("ONNX Runtime inference library found.")
0051            add_definitions(-DUSE_INFERENCE)
0052            add_definitions(-DUSE_INFERENCE_ONNX)
0053       if(CUDAToolkit_FOUND)
0054         message("Cuda found.")
0055         add_definitions(-DUSE_CUDA)
0056       else()
0057         message("Cuda not found!")
0058       endif()
0059    else()
0060       message("ONNX Runtime not found!")
0061    endif()
0062 endif()
0063 
0064 # TORCH
0065 if(INFERENCE_LIB)
0066   find_package(Torch QUIET)
0067    if(Torch_FOUND)
0068        message("Torch inference library found.")
0069           add_definitions(-DUSE_INFERENCE)
0070              add_definitions(-DUSE_INFERENCE_TORCH)
0071    else()
0072       message("Torch not found!")
0073    endif()
0074 endif()
0075 
0076 #----------------------------------------------------------------------------
0077 # Locate sources and headers for this project
0078 #
0079 include_directories(${PROJECT_SOURCE_DIR}/include
0080                     ${Geant4_INCLUDE_DIR})
0081 file(GLOB sources ${PROJECT_SOURCE_DIR}/src/*.cc)
0082 file(GLOB headers ${PROJECT_SOURCE_DIR}/include/*.hh)
0083 
0084 #----------------------------------------------------------------------------
0085 # Add the executable, and link it to the Geant4 libraries
0086 #
0087 add_executable(examplePar04 examplePar04.cc ${sources} ${headers})
0088 target_link_libraries(examplePar04 ${Geant4_LIBRARIES} )
0089 
0090 if(lwtnn_FOUND)
0091   target_include_directories(examplePar04 PUBLIC ${lwtnn_INCLUDE_DIRS})
0092   target_link_libraries(examplePar04 ${lwtnn_LIBRARIES} )
0093   # Depend on data for runtime
0094   add_dependencies(examplePar04 examplePar04lwtnndata)
0095 endif()
0096 
0097 if(OnnxRuntime_FOUND)
0098    target_include_directories(examplePar04 PUBLIC ${OnnxRuntime_INCLUDE_DIR})
0099    target_link_libraries(examplePar04 ${OnnxRuntime_LIBRARY})
0100     # Cuda_FOUND
0101     if(CUDAToolkit_FOUND)
0102       target_link_libraries(examplePar04 CUDA::cudart)     
0103     endif()
0104    # Depend on data for runtime
0105    add_dependencies(examplePar04 examplePar04onnxVAEdata)
0106    add_dependencies(examplePar04 examplePar04onnxCaloDiTdata)
0107 endif()
0108 
0109 if(Torch_FOUND)
0110    target_include_directories(examplePar04 PUBLIC ${TORCH_INCLUDE_DIRS})
0111    target_link_libraries(examplePar04 ${TORCH_LIBRARIES})
0112    message(STATUS "${TORCH_LIBRARIES}")
0113    # Depend on data for runtime
0114    add_dependencies(examplePar04 examplePar04torchVAEdata)
0115    add_dependencies(examplePar04 examplePar04torchCaloDiTdata)
0116 endif()
0117 
0118 #----------------------------------------------------------------------------
0119 # Copy all scripts to the build directory, i.e. the directory in which we
0120 # build Par04. This is so that we can run the executable directly because it
0121 # relies on these scripts being in the current working directory.
0122 #
0123 set(Par04_SCRIPTS
0124     examplePar04.mac vis.mac common_settings_lowgran.mac common_settings_highgran.mac common_settings_vis.mac common_settings_postInit.mac
0125   )
0126 if(lwtnn_FOUND)
0127   set(Par04_SCRIPTS ${Par04_SCRIPTS} examplePar04_lwtnn_vae.mac vis_lwtnn_vae.mac)
0128 endif()
0129 if(OnnxRuntime_FOUND)
0130   set(Par04_SCRIPTS ${Par04_SCRIPTS} examplePar04_onnx_calodit.mac examplePar04_onnx_vae.mac vis_onnx_calodit.mac vis_onnx_vae.mac)
0131 endif()
0132 if(Torch_FOUND)
0133   set(Par04_SCRIPTS ${Par04_SCRIPTS} examplePar04_torch_calodit.mac examplePar04_torch_vae.mac vis_torch_calodit.mac vis_torch_vae.mac)
0134 endif()
0135 
0136 foreach(_script ${Par04_SCRIPTS})
0137   configure_file(
0138     ${PROJECT_SOURCE_DIR}/${_script}
0139     ${PROJECT_BINARY_DIR}/${_script}
0140     COPYONLY
0141     )
0142 endforeach()
0143 
0144 #----------------------------------------------------------------------------
0145 # Use external data. They are stored outside of the code because of their size.
0146 # THey can be downloaded on demand when this example is built (with inference enabled)
0147 #
0148 include(ExternalProject)
0149 if(lwtnn_FOUND)
0150   ExternalProject_Add(examplePar04lwtnndata
0151     DOWNLOAD_DIR ${PROJECT_BINARY_DIR}/MLModels
0152     URL https://cern.ch/geant4-data/datasets/examples/extended/parameterisations/Par04/Generator.json
0153     URL_MD5 af94b1130347428e2e6030930c1ac2cc
0154     CONFIGURE_COMMAND ""
0155     BUILD_COMMAND ""
0156     INSTALL_COMMAND ""
0157     DOWNLOAD_NO_EXTRACT true
0158     )
0159 endif()
0160 if(OnnxRuntime_FOUND)
0161   ExternalProject_Add(examplePar04onnxVAEdata
0162     DOWNLOAD_DIR ${PROJECT_BINARY_DIR}/MLModels
0163     URL https://cern.ch/geant4-data/datasets/examples/extended/parameterisations/Par04/Generator.onnx
0164     URL_MD5 cacd07c24b704decca28de990850287e
0165     CONFIGURE_COMMAND ""
0166     BUILD_COMMAND ""
0167     INSTALL_COMMAND ""
0168     DOWNLOAD_NO_EXTRACT true
0169     )
0170   ExternalProject_Add(examplePar04onnxCaloDiTdata
0171     DOWNLOAD_DIR ${PROJECT_BINARY_DIR}/MLModels
0172     URL https://cern.ch/geant4-data/datasets/examples/extended/parameterisations/Par04/cd.onnx
0173     URL_MD5 eb0fa86fc53d9baf72414410a4a9e3c9
0174     CONFIGURE_COMMAND ""
0175     BUILD_COMMAND ""
0176     INSTALL_COMMAND ""
0177     DOWNLOAD_NO_EXTRACT true
0178     )
0179 endif()
0180 if(Torch_FOUND)
0181   ExternalProject_Add(examplePar04torchVAEdata
0182     DOWNLOAD_DIR ${PROJECT_BINARY_DIR}/MLModels
0183     URL https://cern.ch/geant4-data/datasets/examples/extended/parameterisations/Par04/Generator.pt
0184     URL_MD5 a43337f7f976e976f1127015f2ba61db
0185     CONFIGURE_COMMAND ""
0186     BUILD_COMMAND ""
0187     INSTALL_COMMAND ""
0188     DOWNLOAD_NO_EXTRACT true
0189     )
0190   ExternalProject_Add(examplePar04torchCaloDiTdata
0191     DOWNLOAD_DIR ${PROJECT_BINARY_DIR}/MLModels
0192     URL https://cern.ch/geant4-data/datasets/examples/extended/parameterisations/Par04/cd_cpu.pt
0193     URL_MD5 c812651390bfc2a4f4a88b3c7f945c56
0194     CONFIGURE_COMMAND ""
0195     BUILD_COMMAND ""
0196     INSTALL_COMMAND ""
0197     DOWNLOAD_NO_EXTRACT true
0198     )
0199 endif()
0200 
0201 #----------------------------------------------------------------------------
0202 # Add program to the project targets
0203 # (this avoids the need of typing the program name after make)
0204 #
0205 add_custom_target(Par04 DEPENDS examplePar04)
0206 
0207 #----------------------------------------------------------------------------
0208 # Install the executable to 'bin' directory under CMAKE_INSTALL_PREFIX
0209 #
0210 install(TARGETS examplePar04 DESTINATION bin)
0211