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(CUDA 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(CUDA_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(CUDA_FOUND)
0102       target_include_directories(examplePar04 PUBLIC ${CUDA_INCLUDE_DIRS})
0103       include_directories(${CUDA_INCLUDE_DIRS})
0104       target_link_libraries(examplePar04 ${CUDA_LIBRARIES})     
0105     endif()
0106    # Depend on data for runtime
0107    add_dependencies(examplePar04 examplePar04onnxdata)
0108 endif()
0109 
0110 if(Torch_FOUND)
0111    target_include_directories(examplePar04 PUBLIC ${TORCH_INCLUDE_DIRS})
0112    target_link_libraries(examplePar04 ${TORCH_LIBRARIES})
0113    message(STATUS "${TORCH_LIBRARIES}")
0114    # Depend on data for runtime
0115    add_dependencies(examplePar04 examplePar04torchdata)
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.mac
0125   )
0126 if(lwtnn_FOUND)
0127   set(Par04_SCRIPTS ${Par04_SCRIPTS} examplePar04_lwtnn.mac vis_lwtnn.mac)
0128 endif()
0129 if(OnnxRuntime_FOUND)
0130   set(Par04_SCRIPTS ${Par04_SCRIPTS} examplePar04_onnx.mac vis_onnx.mac)
0131 endif()
0132 if(Torch_FOUND)
0133   set(Par04_SCRIPTS ${Par04_SCRIPTS} examplePar04_torch.mac vis_torch.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(examplePar04onnxdata
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 endif()
0171 if(Torch_FOUND)
0172   ExternalProject_Add(examplePar04torchdata
0173     DOWNLOAD_DIR ${PROJECT_BINARY_DIR}/MLModels
0174     URL https://cern.ch/geant4-data/datasets/examples/extended/parameterisations/Par04/Generator.pt
0175     URL_MD5 a43337f7f976e976f1127015f2ba61db
0176     CONFIGURE_COMMAND ""
0177     BUILD_COMMAND ""
0178     INSTALL_COMMAND ""
0179     DOWNLOAD_NO_EXTRACT true
0180     )
0181 endif()
0182 
0183 #----------------------------------------------------------------------------
0184 # Add program to the project targets
0185 # (this avoids the need of typing the program name after make)
0186 #
0187 add_custom_target(Par04 DEPENDS examplePar04)
0188 
0189 #----------------------------------------------------------------------------
0190 # Install the executable to 'bin' directory under CMAKE_INSTALL_PREFIX
0191 #
0192 install(TARGETS examplePar04 DESTINATION bin)
0193