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

Minimal implementation of in-memory Geant4->VecGeom conversion with G4VG #289

Open
wants to merge 18 commits into
base: master
Choose a base branch
from

Conversation

drbenmorgan
Copy link
Member

This implements the minimal code/link to use G4VG for converting a Geant4 G4VPhysicalVolume to vecgeom::VPlacedVolume in-memory without an intermediary GDML file. Because of the link to CUDA-enabled VecGeom, the link structure originally trialled in #279 is also implemented, and now works properly thanks to the work done removing the old circular dependency described in that PR. Note that it's certain we'll need the --no-as-needed trick for linkers that use as-needed by default, but first things first. The major changes are thus:

  1. Import the CudaRdcUtils and FindVecGeom modules from Celeritas to support coherent linking/device linking of VecGeom into Cuda clients.
  2. Use and export the functions to compile and link the AdePT libraries/tests
  3. Move import of G4VG to top level and bump to latest upstream commit which better supports use and install
  4. Implement AdePTGeant4Integration::CreateVecGeomWorld(const G4VPhysicalVolume *physvol) to take the input Geant4 volume and convert to VecGeom using G4VG's interface.

Because of the linking issues seen before I haven't gone further yet in migrating the code to use CreateVecGeomWorld. I'd like to get a round of CI in first just to be sure there's no other issue. We then should confirm/decide how to solve the as-needed issue. Whilst it's a bit of a blunt instrument, we probably just link AdePT_G4_integration with -Wl,--no-as-needed, and perhaps enforce downstream clients to use that as well.

Supersedes #279 and #285.

@phsft-bot
Copy link

Can one of the admins verify this patch?

@drbenmorgan
Copy link
Member Author

Following discussion this morning, I've submitted celeritas-project/g4vg#7 which fixes the install issue (G4VG cannot be re-found). Once that's merged I'll up this PR to use the new commit.

@drbenmorgan
Copy link
Member Author

Latest commits update the G4VG commit to that providing full install support, so

find_package(AdePT)

in client code will now work without errors.

@andresailer
Copy link
Contributor

I updated one of the GPU machines to alma9 (in view of centos7 going EOL), which caused your jenkins build to fail. I will submit a PR for the CI to use the new OS tomorrow I hope.

@JuanGonzalezCaminero
Copy link
Contributor

Hi Ben, I get the same DSO Missing from command line link error we were seeing in your last PR, related to building in Debian.
target_link_options(example1 PRIVATE "-Wl,--no-as-needed") solves it for me

@JuanGonzalezCaminero
Copy link
Contributor

I haven't been able to link to AdePT from an external project because of find_dependency(G4VG REQUIRED) in AdePTConfig.cmake. Can this line actually work with the current way of pulling g4vg into adept?

@drbenmorgan
Copy link
Member Author

Latest commit should fix the as-needed issue!

I haven't been able to link to AdePT from an external project because of find_dependency(G4VG REQUIRED) in AdePTConfig.cmake. Can this line actually work with the current way of pulling g4vg into adept?

The latest commit which this MR includes for G4VG should install a G4VGConfig.cmake file that addresses this. How are you installing and then pointing the project to the AdePT install?

@JuanGonzalezCaminero
Copy link
Contributor

I see, I can't find G4VGConfig.cmake in the installation directory, I have:

AdePTConfig.cmake
AdePTTargets.cmake
AdePTTargets-release.cmake
CudaRdcUtils.cmake
FindVecGeom.cmake

@JuanGonzalezCaminero
Copy link
Contributor

JuanGonzalezCaminero commented May 3, 2024

G4VGConfig.cmake is generated in the build directory, in _deps/g4vg-build, but apparently not installed with the rest of AdePT

@drbenmorgan
Copy link
Member Author

It's installed parallel, so the structure is something like:

<CMAKE_INSTALL_PREFIX>
├── include
│   ├── ...headers
└── lib64
    ├── cmake
    │   ├── AdePT
    │   │   ├── AdePTConfig.cmake
    │   │   ├── AdePTTargets-relwithdebinfo.cmake
    │   │   ├── AdePTTargets.cmake
    │   │   ├── CudaRdcUtils.cmake
    │   │   └── FindVecGeom.cmake
    │   └── G4VG
    │       ├── G4VGConfig.cmake
    │       ├── G4VGConfigVersion.cmake
    │       ├── G4VGTargets-relwithdebinfo.cmake
    │       └── G4VGTargets.cmake
    ├── libAdePT_G4_integration.so
    ├── libAdePT_G4_integration_final.so
    ├── libAdePT_G4_integration_static.a
    └── libg4vg.so

Check that you have those, if not, try a from-scratch build just in case it's retained the older G4VG. The only other thing is to check that you're configuring the external project with CMAKE_PREFIX_PATH set to the prefix under which you installed AdePT (AdePT_DIR won't work in this case).

@JuanGonzalezCaminero
Copy link
Contributor

I see, I did try a build from scratch several times but the G4VG directory is not there, building from the latest commit ef45fed.

I'm configuring the project with: cmake -S. -B./build -DCMAKE_PREFIX_PATH="..." -DCMAKE_INSTALL_PREFIX="../adept_install" -DCMAKE_CUDA_ARCHITECTURES=... -DCMAKE_BUILD_TYPE=Release , in case I'm missing an option

@drbenmorgan
Copy link
Member Author

Those options look fine, what gets printed when you do make install for AdePT? This should list all the files that get installed. Locally, with that same ef45fed commit, I get (with ninja, but make should print the same)

$ ninja install
[0/1] Install the project...
-- Install configuration: "RelWithDebInfo"
-- Installing: /.../lib64/libg4vg.so
-- Set runtime path of "/.../lib64/libg4vg.so" to ""
-- Installing: /.../include
-- Installing: /.../include/G4VG.hh
-- Installing: /.../lib64/cmake/G4VG/G4VGConfigVersion.cmake
-- Installing: /.../lib64/cmake/G4VG/G4VGConfig.cmake
-- Installing: /.../lib64/cmake/G4VG/G4VGTargets.cmake
-- Installing: /.../lib64/cmake/G4VG/G4VGTargets-relwithdebinfo.cmake
-- Installing: /.../lib64/libAdePT_G4_integration_final.so
-- Set runtime path of "/.../lib64/libAdePT_G4_integration_final.so" to ""
-- Installing: /.../lib64/libAdePT_G4_integration_static.a
-- Installing: /.../lib64/libAdePT_G4_integration.so
-- Set runtime path of "/.../lib64/libAdePT_G4_integration.so" to ""
-- Installing: /.../include/AdePT
-- Installing: /.../include/AdePT/base
-- Installing: /.../include/AdePT/base/ArgParser.h
-- Installing: /.../include/AdePT/base/Atomic.h
-- Installing: /.../include/AdePT/base/BlockData.h
-- Installing: /.../include/AdePT/base/MParray.h
-- Installing: /.../include/AdePT/base/MParrayT.h
-- Installing: /.../include/AdePT/base/TrackManager.cuh
-- Installing: /.../include/AdePT/base/Utils.h
-- Installing: /.../include/AdePT/base/mpmc_bounded_queue.h
-- Installing: /.../include/AdePT/benchmarking
-- Installing: /.../include/AdePT/benchmarking/NVTX.h
-- Installing: /.../include/AdePT/benchmarking/TestManager.h
-- Installing: /.../include/AdePT/benchmarking/TestManagerStore.h
-- Installing: /.../include/AdePT/copcore
-- Installing: /.../include/AdePT/copcore/Allocator.h
-- Installing: /.../include/AdePT/copcore/CopCore.h
-- Installing: /.../include/AdePT/copcore/Global.h
-- Installing: /.../include/AdePT/copcore/Macros.h
-- Installing: /.../include/AdePT/copcore/PhysicalConstants.h
-- Installing: /.../include/AdePT/copcore/Ranluxpp.h
-- Installing: /.../include/AdePT/copcore/SystemOfUnits.h
-- Installing: /.../include/AdePT/copcore/VariableSizeObj.h
-- Installing: /.../include/AdePT/copcore/VariableSizeObjAllocator.h
-- Installing: /.../include/AdePT/copcore/ranluxpp
-- Installing: /.../include/AdePT/copcore/ranluxpp/helpers.h
-- Installing: /.../include/AdePT/copcore/ranluxpp/mulmod.h
-- Installing: /.../include/AdePT/copcore/ranluxpp/ranlux_lcg.h
-- Installing: /.../include/AdePT/core
-- Installing: /.../include/AdePT/core/AdePTConfiguration.hh
-- Installing: /.../include/AdePT/core/AdePTScoringTemplate.cuh
-- Installing: /.../include/AdePT/core/AdePTTransport.cuh
-- Installing: /.../include/AdePT/core/AdePTTransport.h
-- Installing: /.../include/AdePT/core/AdePTTransport.icc
-- Installing: /.../include/AdePT/core/AdePTTransportStruct.cuh
-- Installing: /.../include/AdePT/core/CommonStruct.h
-- Installing: /.../include/AdePT/core/HostScoringImpl.cuh
-- Installing: /.../include/AdePT/core/HostScoringStruct.cuh
-- Installing: /.../include/AdePT/core/Track.cuh
-- Installing: /.../include/AdePT/core/TrackData.h
-- Installing: /.../include/AdePT/integration
-- Installing: /.../include/AdePT/integration/AdePTConfigurationMessenger.hh
-- Installing: /.../include/AdePT/integration/AdePTPhysics.hh
-- Installing: /.../include/AdePT/integration/AdePTTrackingManager.hh
-- Installing: /.../include/AdePT/integration/HepEMPhysics.hh
-- Installing: /.../include/AdePT/integration/AdePTGeant4Integration.hh
-- Installing: /.../include/AdePT/kernels
-- Installing: /.../include/AdePT/kernels/electrons.cuh
-- Installing: /.../include/AdePT/kernels/gammas.cuh
-- Installing: /.../include/AdePT/magneticfield
-- Installing: /.../include/AdePT/magneticfield/CompareResponses.h
-- Installing: /.../include/AdePT/magneticfield/ConstBzFieldStepper.h
-- Installing: /.../include/AdePT/magneticfield/ConstFieldHelixStepper.h
-- Installing: /.../include/AdePT/magneticfield/DormandPrinceRK45.h
-- Installing: /.../include/AdePT/magneticfield/ErrorEstimatorRK.h
-- Installing: /.../include/AdePT/magneticfield/MagneticFieldEquation.h
-- Installing: /.../include/AdePT/magneticfield/PrintFieldVectors.h
-- Installing: /.../include/AdePT/magneticfield/RkIntegrationDriver.h
-- Installing: /.../include/AdePT/magneticfield/UniformMagneticField.h
-- Installing: /.../include/AdePT/magneticfield/fieldConstants.h
-- Installing: /.../include/AdePT/magneticfield/fieldPropagatorConstBany.h
-- Installing: /.../include/AdePT/magneticfield/fieldPropagatorConstBz.h
-- Installing: /.../include/AdePT/magneticfield/fieldPropagatorRungeKutta.h
-- Installing: /.../include/AdePT/navigation
-- Installing: /.../include/AdePT/navigation/BVHNavigator.h
-- Installing: /.../include/AdePT/navigation/LoopNavigator.h
-- Installing: /.../include/AdePT/navigation/SurfNavigator.h
-- Installing: /.../lib64/cmake/AdePT/AdePTConfig.cmake
-- Installing: /.../lib64/cmake/AdePT/CudaRdcUtils.cmake
-- Installing: /.../lib64/cmake/AdePT/FindVecGeom.cmake
-- Installing: /.../lib64/cmake/AdePT/AdePTTargets.cmake
-- Installing: /.../lib64/cmake/AdePT/AdePTTargets-relwithdebinfo.cmake

@JuanGonzalezCaminero
Copy link
Contributor

In my case, I have everything except for the G4VG lines:

Install the project...
-- Install configuration: "RelWithDebInfo"
-- Installing: /.../lib/libAdePT_G4_integration_final.so
-- Set non-toolchain portion of runtime path of "/.../lib/libAdePT_G4_integration_final.so" to ""
-- Installing: /.../lib/libAdePT_G4_integration_static.a
-- Installing: /.../lib/libAdePT_G4_integration.so
-- Set non-toolchain portion of runtime path of "/.../lib/libAdePT_G4_integration.so" to ""
-- Installing: /.../include/AdePT
-- Installing: /.../include/AdePT/magneticfield
-- Installing: /.../include/AdePT/magneticfield/ErrorEstimatorRK.h
-- Installing: /.../include/AdePT/magneticfield/fieldConstants.h
-- Installing: /.../include/AdePT/magneticfield/fieldPropagatorConstBz.h
-- Installing: /.../include/AdePT/magneticfield/fieldPropagatorConstBany.h
-- Installing: /.../include/AdePT/magneticfield/RkIntegrationDriver.h
-- Installing: /.../include/AdePT/magneticfield/ConstFieldHelixStepper.h
-- Installing: /.../include/AdePT/magneticfield/DormandPrinceRK45.h
-- Installing: /.../include/AdePT/magneticfield/CompareResponses.h
-- Installing: /.../include/AdePT/magneticfield/PrintFieldVectors.h
-- Installing: /.../include/AdePT/magneticfield/fieldPropagatorRungeKutta.h
-- Installing: /.../include/AdePT/magneticfield/MagneticFieldEquation.h
-- Installing: /.../include/AdePT/magneticfield/UniformMagneticField.h
-- Installing: /.../include/AdePT/magneticfield/ConstBzFieldStepper.h
-- Installing: /.../include/AdePT/base
-- Installing: /.../include/AdePT/base/ArgParser.h
-- Installing: /.../include/AdePT/base/BlockData.h
-- Installing: /.../include/AdePT/base/TrackManager.cuh
-- Installing: /.../include/AdePT/base/mpmc_bounded_queue.h
-- Installing: /.../include/AdePT/base/Atomic.h
-- Installing: /.../include/AdePT/base/MParray.h
-- Installing: /.../include/AdePT/base/MParrayT.h
-- Installing: /.../include/AdePT/base/Utils.h
-- Installing: /.../include/AdePT/benchmarking
-- Installing: /.../include/AdePT/benchmarking/TestManagerStore.h
-- Installing: /.../include/AdePT/benchmarking/NVTX.h
-- Installing: /.../include/AdePT/benchmarking/TestManager.h
-- Installing: /.../include/AdePT/integration
-- Installing: /.../include/AdePT/integration/AdePTTrackingManager.hh
-- Installing: /.../include/AdePT/integration/HepEMPhysics.hh
-- Installing: /.../include/AdePT/integration/AdePTPhysics.hh
-- Installing: /.../include/AdePT/integration/AdePTConfigurationMessenger.hh
-- Installing: /.../include/AdePT/integration/AdePTGeant4Integration.hh
-- Installing: /.../include/AdePT/copcore
-- Installing: /.../include/AdePT/copcore/CopCore.h
-- Installing: /.../include/AdePT/copcore/PhysicalConstants.h
-- Installing: /.../include/AdePT/copcore/Global.h
-- Installing: /.../include/AdePT/copcore/VariableSizeObj.h
-- Installing: /.../include/AdePT/copcore/Macros.h
-- Installing: /.../include/AdePT/copcore/VariableSizeObjAllocator.h
-- Installing: /.../include/AdePT/copcore/SystemOfUnits.h
-- Installing: /.../include/AdePT/copcore/Ranluxpp.h
-- Installing: /.../include/AdePT/copcore/ranluxpp
-- Installing: /.../include/AdePT/copcore/ranluxpp/ranlux_lcg.h
-- Installing: /.../include/AdePT/copcore/ranluxpp/helpers.h
-- Installing: /.../include/AdePT/copcore/ranluxpp/mulmod.h
-- Installing: /.../include/AdePT/copcore/Allocator.h
-- Installing: /.../include/AdePT/navigation
-- Installing: /.../include/AdePT/navigation/BVHNavigator.h
-- Installing: /.../include/AdePT/navigation/SurfNavigator.h
-- Installing: /.../include/AdePT/navigation/LoopNavigator.h
-- Installing: /.../include/AdePT/kernels
-- Installing: /.../include/AdePT/kernels/electrons.cuh
-- Installing: /.../include/AdePT/kernels/gammas.cuh
-- Installing: /.../include/AdePT/core
-- Installing: /.../include/AdePT/core/TrackData.h
-- Installing: /.../include/AdePT/core/AdePTTransport.cuh
-- Installing: /.../include/AdePT/core/AdePTTransport.h
-- Installing: /.../include/AdePT/core/CommonStruct.h
-- Installing: /.../include/AdePT/core/HostScoringStruct.cuh
-- Installing: /.../include/AdePT/core/AdePTTransport.icc
-- Installing: /.../include/AdePT/core/AdePTTransportStruct.cuh
-- Installing: /.../include/AdePT/core/AdePTScoringTemplate.cuh
-- Installing: /.../include/AdePT/core/Track.cuh
-- Installing: /.../include/AdePT/core/AdePTConfiguration.hh
-- Installing: /.../include/AdePT/core/HostScoringImpl.cuh
-- Installing: /.../lib/cmake/AdePT/AdePTConfig.cmake
-- Installing: /.../lib/cmake/AdePT/CudaRdcUtils.cmake
-- Installing: /.../lib/cmake/AdePT/FindVecGeom.cmake
-- Installing: /.../lib/cmake/AdePT/AdePTTargets.cmake
-- Installing: /.../lib/cmake/AdePT/AdePTTargets-relwithdebinfo.cmake

git log -1
commit ef45fed89eb842a032cee0bc34b59b95644e0a0c (HEAD -> g4vg)
...

@WitekPokorski
Copy link
Contributor

I am getting the right directory structure (like Ben), however, it fails to link the tests:

[ 51%] Linking CXX executable ../BuildProducts/bin/test_g4vg_link
/usr/local/bin/ld: warning: libG4analysis.so, needed by /home/witoldp/Geant4/installation/lib64/libG4processes.so, not found (try using -rpath or -rpath-link)
/usr/local/bin/ld: warning: libG4zlib.so, needed by /home/witoldp/Geant4/installation/lib64/libG4processes.so, not found (try using -rpath or -rpath-link)
/usr/local/bin/ld: /home/witoldp/Geant4/installation/lib64/libG4processes.so: undefined reference to G4VAnalysisManager::CreateNtupleSColumn(int, G4String const&)' /usr/local/bin/ld: /home/witoldp/Geant4/installation/lib64/libG4processes.so: undefined reference to G4VAnalysisManager::CreateNtupleIColumn(int, G4String const&)'
/usr/local/bin/ld: /home/witoldp/Geant4/installation/lib64/libG4processes.so: undefined reference to G4VAnalysisManager::FinishNtuple(int)' /usr/local/bin/ld: /home/witoldp/Geant4/installation/lib64/libG4processes.so: undefined reference to G4BaseFileManager::GetFileType() const'
/usr/local/bin/ld: /home/witoldp/Geant4/installation/lib64/libG4processes.so: undefined reference to G4VAnalysisManager::OpenFile(G4String const&)' /usr/local/bin/ld: /home/witoldp/Geant4/installation/lib64/libG4processes.so: undefined reference to G4VAnalysisManager::CreateNtuple(G4String const&, G4String const&)'
/usr/local/bin/ld: /home/witoldp/Geant4/installation/lib64/libG4processes.so: undefined reference to `G4VAnalysisManager::CreateNtupleDColumn(int, G4String const&)'
collect2: error: ld returned 1 exit status
make[2]: *** [test/CMakeFiles/test_g4vg_link.dir/build.make:98: BuildProducts/bin/test_g4vg_link] Error 1

This is very strange, because libG4analysis.so is in the same directory as libG4processes.so, so I don't understand why it can't link.

@drbenmorgan
Copy link
Member Author

@JuanGonzalezCaminero though I know that you did a fresh build, all I can think of is that the old G4VG version is still present. Could you confirm that you fully deleted the build directory (i.e. not just a "make clean") and then re-cmaked from a completely empty directory? Which CMake version are you using?

@WitekPokorski that's very weird... Which Linux/gcc/CMake and Geant4 versions are you using?

@WitekPokorski
Copy link
Contributor

RHEL9, gcc (GCC) 12.3.0, cmake version 3.27.4, G4.11.1.2

@drbenmorgan
Copy link
Member Author

Thanks! I'll set up this locally (Rocky 9, but close enough) and see if I can reproduce.

@drbenmorgan
Copy link
Member Author

@WitekPokorski, I think there is an issue in G4VG, but to help track this down, could you do a fresh build of AdePT (just run make clean first) and post the output of the link steps for

$ make g4vg VERBOSE=1

and

$ make test_g4vg_link VERBOSE=1 

please? Also, when you've done those, what's the output of

$ ldd BuildProducts/lib64/libg4vg.so

and

$ readelf -d BuildProducts/lib64/libg4vg.so

please?

@WitekPokorski
Copy link
Contributor

make -f _deps/g4vg-build/src/CMakeFiles/g4vg.dir/build.make _deps/g4vg-build/src/CMakeFiles/g4vg.dir/depend make[3]: Entering directory '/home/witoldp/test_g4gv/AdePT/build' cd /home/witoldp/test_g4gv/AdePT/build && /usr/local/bin/cmake -E cmake_depends "Unix Makefiles" /home/witoldp/test_g4gv/AdePT /home/witoldp/test_g4gv/AdePT/build/_deps/g4vg-src/src /home/witoldp/test_g4gv/AdePT/build /home/witoldp/test_g4gv/AdePT/build/_deps/g4vg-build/src /home/witoldp/test_g4gv/AdePT/build/_deps/g4vg-build/src/CMakeFiles/g4vg.dir/DependInfo.cmake "--color=" make[3]: Leaving directory '/home/witoldp/test_g4gv/AdePT/build' make -f _deps/g4vg-build/src/CMakeFiles/g4vg.dir/build.make _deps/g4vg-build/src/CMakeFiles/g4vg.dir/build make[3]: Entering directory '/home/witoldp/test_g4gv/AdePT/build' [100%] Building CXX object _deps/g4vg-build/src/CMakeFiles/g4vg.dir/G4VG.cc.o cd /home/witoldp/test_g4gv/AdePT/build/_deps/g4vg-build/src && /usr/bin/c++ -DHEPMC3_FOUND -Dg4vg_EXPORTS -I/home/witoldp/test_g4gv/AdePT/build/_deps/g4vg-src/src -I/home/witoldp/test_g4gv/AdePT/build/_deps/celeritas-src/src -I/home/witoldp/test_g4gv/AdePT/build/_deps/celeritas-build/include -O2 -g -DNDEBUG -std=c++17 -fPIC -MD -MT _deps/g4vg-build/src/CMakeFiles/g4vg.dir/G4VG.cc.o -MF CMakeFiles/g4vg.dir/G4VG.cc.o.d -o CMakeFiles/g4vg.dir/G4VG.cc.o -c /home/witoldp/test_g4gv/AdePT/build/_deps/g4vg-src/src/G4VG.cc [100%] Linking CXX shared library ../../../BuildProducts/lib64/libg4vg.so cd /home/witoldp/test_g4gv/AdePT/build/_deps/g4vg-build/src && /usr/local/bin/cmake -E cmake_link_script CMakeFiles/g4vg.dir/link.txt --verbose=1 /usr/bin/c++ -fPIC -O2 -g -DNDEBUG -shared -Wl,-soname,libg4vg.so -o ../../../BuildProducts/lib64/libg4vg.so CMakeFiles/g4vg.dir/G4VG.cc.o -Wl,-rpath,/home/witoldp/Geant4/installation/lib64:/usr/local/lib64:/home/witoldp/VecGeom/installation/lib64: ../../celeritas-build/lib64/libgeocel.a /home/witoldp/Geant4/installation/lib64/libG4persistency.so /home/witoldp/Geant4/installation/lib64/libG4run.so /home/witoldp/Geant4/installation/lib64/libG4event.so /home/witoldp/Geant4/installation/lib64/libG4tracking.so /home/witoldp/Geant4/installation/lib64/libG4processes.so /home/witoldp/Geant4/installation/lib64/libG4digits_hits.so /home/witoldp/Geant4/installation/lib64/libG4track.so /home/witoldp/Geant4/installation/lib64/libG4geometry.so /home/witoldp/Geant4/installation/lib64/libG4graphics_reps.so /home/witoldp/Geant4/installation/lib64/libG4materials.so /home/witoldp/Geant4/installation/lib64/libG4particles.so /home/witoldp/Geant4/installation/lib64/libG4expat.so /home/witoldp/Geant4/installation/lib64/libG4intercoms.so /home/witoldp/Geant4/installation/lib64/libG4global.so /home/witoldp/Geant4/installation/lib64/libG4clhep.so /home/witoldp/Geant4/installation/lib64/libG4ptl.so.2.3.3 /home/witoldp/VecGeom/installation/lib64/libvgdml.a /usr/local/lib64/libxerces-c.so /home/witoldp/VecGeom/installation/lib64/libvecgeomcuda.so /home/witoldp/VecGeom/installation/lib64/libvecgeom.a -lrt -lpthread -ldl ../../celeritas-build/lib64/libcorecel.a -Wl,-rpath-link,/home/witoldp/Geant4/installation/lib64 make[3]: Leaving directory '/home/witoldp/test_g4gv/AdePT/build' [100%] Built target g4vg make[2]: Leaving directory '/home/witoldp/test_g4gv/AdePT/build' /usr/local/bin/cmake -E cmake_progress_start /home/witoldp/test_g4gv/AdePT/build/CMakeFiles 0 make[1]: Leaving directory '/home/witoldp/test_g4gv/AdePT/build'

@WitekPokorski
Copy link
Contributor

Consolidate compiler generated dependencies of target g4vg make[3]: Leaving directory '/home/witoldp/test_g4gv/AdePT/build' make -f _deps/g4vg-build/src/CMakeFiles/g4vg.dir/build.make _deps/g4vg-build/src/CMakeFiles/g4vg.dir/build make[3]: Entering directory '/home/witoldp/test_g4gv/AdePT/build' make[3]: Nothing to be done for '_deps/g4vg-build/src/CMakeFiles/g4vg.dir/build'. make[3]: Leaving directory '/home/witoldp/test_g4gv/AdePT/build' [ 93%] Built target g4vg make -f test/CMakeFiles/test_g4vg_link.dir/build.make test/CMakeFiles/test_g4vg_link.dir/depend make[3]: Entering directory '/home/witoldp/test_g4gv/AdePT/build' cd /home/witoldp/test_g4gv/AdePT/build && /usr/local/bin/cmake -E cmake_depends "Unix Makefiles" /home/witoldp/test_g4gv/AdePT /home/witoldp/test_g4gv/AdePT/test /home/witoldp/test_g4gv/AdePT/build /home/witoldp/test_g4gv/AdePT/build/test /home/witoldp/test_g4gv/AdePT/build/test/CMakeFiles/test_g4vg_link.dir/DependInfo.cmake "--color=" make[3]: Leaving directory '/home/witoldp/test_g4gv/AdePT/build' make -f test/CMakeFiles/test_g4vg_link.dir/build.make test/CMakeFiles/test_g4vg_link.dir/build make[3]: Entering directory '/home/witoldp/test_g4gv/AdePT/build' [100%] Building CXX object test/CMakeFiles/test_g4vg_link.dir/test_g4vg_link.cpp.o cd /home/witoldp/test_g4gv/AdePT/build/test && /usr/bin/c++ -DHEPMC3_FOUND -DVECCORE_ENABLE_CUDA -I/home/witoldp/test_g4gv/AdePT/build/_deps/g4vg-src/src -isystem /home/witoldp/VecGeom/installation/include -isystem /home/witoldp/VecCore/installation/include -isystem /usr/local/cuda-12.4/include -O2 -g -DNDEBUG -std=c++17 -faligned-new -msse2 -MD -MT test/CMakeFiles/test_g4vg_link.dir/test_g4vg_link.cpp.o -MF CMakeFiles/test_g4vg_link.dir/test_g4vg_link.cpp.o.d -o CMakeFiles/test_g4vg_link.dir/test_g4vg_link.cpp.o -c /home/witoldp/test_g4gv/AdePT/test/test_g4vg_link.cpp [100%] Linking CXX executable ../BuildProducts/bin/test_g4vg_link cd /home/witoldp/test_g4gv/AdePT/build/test && /usr/local/bin/cmake -E cmake_link_script CMakeFiles/test_g4vg_link.dir/link.txt --verbose=1 /usr/bin/c++ -O2 -g -DNDEBUG -Wl,--no-as-needed CMakeFiles/test_g4vg_link.dir/test_g4vg_link.cpp.o -o ../BuildProducts/bin/test_g4vg_link -Wl,-rpath,/home/witoldp/test_g4gv/AdePT/build/BuildProducts/lib64:/home/witoldp/VecGeom/installation/lib64 ../BuildProducts/lib64/libg4vg.so /home/witoldp/VecGeom/installation/lib64/libvecgeomcuda.so /home/witoldp/VecGeom/installation/lib64/libvecgeom.a -lrt -lpthread -ldl /usr/local/bin/ld: warning: libG4analysis.so, needed by /home/witoldp/Geant4/installation/lib64/libG4processes.so, not found (try using -rpath or -rpath-link) /usr/local/bin/ld: warning: libG4zlib.so, needed by /home/witoldp/Geant4/installation/lib64/libG4processes.so, not found (try using -rpath or -rpath-link) /usr/local/bin/ld: /home/witoldp/Geant4/installation/lib64/libG4processes.so: undefined reference to G4VAnalysisManager::CreateNtupleSColumn(int, G4String const&)'
/usr/local/bin/ld: /home/witoldp/Geant4/installation/lib64/libG4processes.so: undefined reference to G4VAnalysisManager::CreateNtupleIColumn(int, G4String const&)' /usr/local/bin/ld: /home/witoldp/Geant4/installation/lib64/libG4processes.so: undefined reference to G4VAnalysisManager::FinishNtuple(int)'
/usr/local/bin/ld: /home/witoldp/Geant4/installation/lib64/libG4processes.so: undefined reference to G4BaseFileManager::GetFileType() const' /usr/local/bin/ld: /home/witoldp/Geant4/installation/lib64/libG4processes.so: undefined reference to G4VAnalysisManager::OpenFile(G4String const&)'
/usr/local/bin/ld: /home/witoldp/Geant4/installation/lib64/libG4processes.so: undefined reference to G4VAnalysisManager::CreateNtuple(G4String const&, G4String const&)' /usr/local/bin/ld: /home/witoldp/Geant4/installation/lib64/libG4processes.so: undefined reference to G4VAnalysisManager::CreateNtupleDColumn(int, G4String const&)'
collect2: error: ld returned 1 exit status
make[3]: *** [test/CMakeFiles/test_g4vg_link.dir/build.make:98: BuildProducts/bin/test_g4vg_link] Error 1
make[3]: Leaving directory '/home/witoldp/test_g4gv/AdePT/build'
make[2]: *** [CMakeFiles/Makefile2:1712: test/CMakeFiles/test_g4vg_link.dir/all] Error 2
make[2]: Leaving directory '/home/witoldp/test_g4gv/AdePT/build'
make[1]: *** [CMakeFiles/Makefile2:1719: test/CMakeFiles/test_g4vg_link.dir/rule] Error 2
make[1]: Leaving directory '/home/witoldp/test_g4gv/AdePT/build'
make: *** [Makefile:790: test_g4vg_link] Error 2
`

@WitekPokorski
Copy link
Contributor

[witoldp@omenrtx ~/test_g4gv/AdePT/build]$ ldd BuildProducts/lib64/libg4vg.so linux-vdso.so.1 (0x00007ffcd1ae8000) libG4persistency.so => /home/witoldp/Geant4/installation/lib64/libG4persistency.so (0x00007fdc17d2b000) libG4run.so => /home/witoldp/Geant4/installation/lib64/libG4run.so (0x00007fdc17918000) libG4event.so => /home/witoldp/Geant4/installation/lib64/libG4event.so (0x00007fdc17896000) libG4tracking.so => /home/witoldp/Geant4/installation/lib64/libG4tracking.so (0x00007fdc17838000) libG4processes.so => /home/witoldp/Geant4/installation/lib64/libG4processes.so (0x00007fdc15c00000) libG4digits_hits.so => /home/witoldp/Geant4/installation/lib64/libG4digits_hits.so (0x00007fdc1775f000) libG4track.so => /home/witoldp/Geant4/installation/lib64/libG4track.so (0x00007fdc17d0c000) libG4geometry.so => /home/witoldp/Geant4/installation/lib64/libG4geometry.so (0x00007fdc15800000) libG4graphics_reps.so => /home/witoldp/Geant4/installation/lib64/libG4graphics_reps.so (0x00007fdc17709000) libG4materials.so => /home/witoldp/Geant4/installation/lib64/libG4materials.so (0x00007fdc15b0f000) libG4particles.so => /home/witoldp/Geant4/installation/lib64/libG4particles.so (0x00007fdc156c2000) libG4expat.so => /home/witoldp/Geant4/installation/lib64/libG4expat.so (0x00007fdc1568f000) libG4intercoms.so => /home/witoldp/Geant4/installation/lib64/libG4intercoms.so (0x00007fdc1561b000) libG4global.so => /home/witoldp/Geant4/installation/lib64/libG4global.so (0x00007fdc15594000) libG4clhep.so => /home/witoldp/Geant4/installation/lib64/libG4clhep.so (0x00007fdc154ed000) libG4ptl.so.2 => /home/witoldp/Geant4/installation/lib64/libG4ptl.so.2 (0x00007fdc17cdc000) libxerces-c-3.2.so => /usr/local/lib64/libxerces-c-3.2.so (0x00007fdc15000000) libvecgeomcuda.so => /home/witoldp/VecGeom/installation/lib64/libvecgeomcuda.so (0x00007fdc13400000) libstdc++.so.6 => /usr/local/lib64/libstdc++.so.6 (0x00007fdc13000000) libm.so.6 => /lib64/libm.so.6 (0x00007fdc14f25000) libgcc_s.so.1 => /usr/local/lib64/libgcc_s.so.1 (0x00007fdc154cc000) libc.so.6 => /lib64/libc.so.6 (0x00007fdc12c00000) /lib64/ld-linux-x86-64.so.2 (0x00007fdc17e8a000) libG4analysis.so => /home/witoldp/Geant4/installation/lib64/libG4analysis.so (0x00007fdc12600000) libG4zlib.so => /home/witoldp/Geant4/installation/lib64/libG4zlib.so (0x00007fdc154ae000) libcurl.so.4 => /lib64/libcurl.so.4 (0x00007fdc1335f000) libicuuc.so.67 => /lib64/libicuuc.so.67 (0x00007fdc12e15000) libicudata.so.67 => /lib64/libicudata.so.67 (0x00007fdc10a00000) libcudart.so.12 => /usr/local/cuda-12.4/lib64/libcudart.so.12 (0x00007fdc10600000) libnghttp2.so.14 => /lib64/libnghttp2.so.14 (0x00007fdc14efb000) libidn2.so.0 => /lib64/libidn2.so.0 (0x00007fdc1548d000) libssh.so.4 => /lib64/libssh.so.4 (0x00007fdc132ea000) libpsl.so.5 => /lib64/libpsl.so.5 (0x00007fdc14ee7000) libssl.so.3 => /lib64/libssl.so.3 (0x00007fdc13244000) libcrypto.so.3 => /lib64/libcrypto.so.3 (0x00007fdc10000000) libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x00007fdc125a9000) libkrb5.so.3 => /lib64/libkrb5.so.3 (0x00007fdc10925000) libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x00007fdc1322b000) libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007fdc12e0e000) libldap.so.2 => /lib64/libldap.so.2 (0x00007fdc12542000) liblber.so.2 => /lib64/liblber.so.2 (0x00007fdc12bee000) libbrotlidec.so.1 => /lib64/libbrotlidec.so.1 (0x00007fdc12be0000) libz.so.1 => /lib64/libz.so.1 (0x00007fdc12528000) libdl.so.2 => /lib64/libdl.so.2 (0x00007fdc15b0a000) libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fdc14ee2000) librt.so.1 => /lib64/librt.so.1 (0x00007fdc12e09000) libunistring.so.2 => /lib64/libunistring.so.2 (0x00007fdc1047b000) libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x00007fdc10914000) libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00007fdc12521000) libresolv.so.2 => /lib64/libresolv.so.2 (0x00007fdc10900000) libevent-2.1.so.7 => /lib64/libevent-2.1.so.7 (0x00007fdc0ffa7000) libsasl2.so.3 => /lib64/libsasl2.so.3 (0x00007fdc108e0000) libbrotlicommon.so.1 => /lib64/libbrotlicommon.so.1 (0x00007fdc108bd000) libselinux.so.1 => /lib64/libselinux.so.1 (0x00007fdc1044e000) libcrypt.so.2 => /lib64/libcrypt.so.2 (0x00007fdc0ff6d000) libpcre2-8.so.0 => /lib64/libpcre2-8.so.0 (0x00007fdc0fed1000)

@WitekPokorski
Copy link
Contributor

`[witoldp@omenrtx ~/test_g4gv/AdePT/build]$ readelf -d BuildProducts/lib64/libg4vg.so

Dynamic section at offset 0x2d3088 contains 48 entries:
Tag Type Name/Value
0x0000000000000001 (NEEDED) Shared library: [libG4persistency.so]
0x0000000000000001 (NEEDED) Shared library: [libG4run.so]
0x0000000000000001 (NEEDED) Shared library: [libG4event.so]
0x0000000000000001 (NEEDED) Shared library: [libG4tracking.so]
0x0000000000000001 (NEEDED) Shared library: [libG4processes.so]
0x0000000000000001 (NEEDED) Shared library: [libG4digits_hits.so]
0x0000000000000001 (NEEDED) Shared library: [libG4track.so]
0x0000000000000001 (NEEDED) Shared library: [libG4geometry.so]
0x0000000000000001 (NEEDED) Shared library: [libG4graphics_reps.so]
0x0000000000000001 (NEEDED) Shared library: [libG4materials.so]
0x0000000000000001 (NEEDED) Shared library: [libG4particles.so]
0x0000000000000001 (NEEDED) Shared library: [libG4expat.so]
0x0000000000000001 (NEEDED) Shared library: [libG4intercoms.so]
0x0000000000000001 (NEEDED) Shared library: [libG4global.so]
0x0000000000000001 (NEEDED) Shared library: [libG4clhep.so]
0x0000000000000001 (NEEDED) Shared library: [libG4ptl.so.2]
0x0000000000000001 (NEEDED) Shared library: [libxerces-c-3.2.so]
0x0000000000000001 (NEEDED) Shared library: [libvecgeomcuda.so]
0x0000000000000001 (NEEDED) Shared library: [libstdc++.so.6]
0x0000000000000001 (NEEDED) Shared library: [libm.so.6]
0x0000000000000001 (NEEDED) Shared library: [libgcc_s.so.1]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
0x0000000000000001 (NEEDED) Shared library: [ld-linux-x86-64.so.2]
0x000000000000000e (SONAME) Library soname: [libg4vg.so]
0x000000000000000f (RPATH) Library rpath: [/home/witoldp/Geant4/installation/lib64:/usr/local/lib64:/home/witoldp/VecGeom/installation/lib64:]
0x000000000000000c (INIT) 0x77000
0x000000000000000d (FINI) 0x29f464
0x0000000000000019 (INIT_ARRAY) 0x2cb6d0
0x000000000000001b (INIT_ARRAYSZ) 680 (bytes)
0x000000000000001a (FINI_ARRAY) 0x2cb978
0x000000000000001c (FINI_ARRAYSZ) 8 (bytes)
0x000000006ffffef5 (GNU_HASH) 0x298
0x0000000000000005 (STRTAB) 0x18270
0x0000000000000006 (SYMTAB) 0x5688
0x000000000000000a (STRSZ) 268775 (bytes)
0x000000000000000b (SYMENT) 24 (bytes)
0x0000000000000003 (PLTGOT) 0x2d3fe8
0x0000000000000002 (PLTRELSZ) 17472 (bytes)
0x0000000000000014 (PLTREL) RELA
0x0000000000000017 (JMPREL) 0x72860
0x0000000000000007 (RELA) 0x5b718
0x0000000000000008 (RELASZ) 94536 (bytes)
0x0000000000000009 (RELAENT) 24 (bytes)
0x000000006ffffffe (VERNEED) 0x5b558
0x000000006fffffff (VERNEEDNUM) 5
0x000000006ffffff0 (VERSYM) 0x59c58
0x000000006ffffff9 (RELACOUNT) 109
0x0000000000000000 (NULL) 0x0
`

drbenmorgan added a commit to drbenmorgan/g4vg that referenced this pull request May 7, 2024
Discovered in testing of integration of G4VG in apt-sim/AdePT#289,
targets linking to installed G4VG may fail to link due to linker
not having needed information on location of deps-of-deps of G4VG.
This happens in build environments where

1. The installed dependencies (here, Geant4, VecGeom) do not have
   their rpath set correctly.
2. They are otherwise in a location the linker is not aware of,
   e.g. via ldconfig of LD_LIBRARY_PATH etc.

The link error warns about this and suggests adding the path through,
e.g. `-rpath-link`. CMake will always add this flag/path correctly,
but only if it knows about the dependencies (even if private).

The G4VG library only depends on the static Celeritas::geocel target,
which does not forward its dependencies to Geant4/Vecgeom and so
it does not set `-rpath-link` for these.

Workaround this issue by explicitly making used Geant4 targets
PRIVATE deps of the g4vg target. Refind Geant4/VecGeom dependencies
when finding G4VG so these are resolved and available if the linker
requires it.

Add smoke test for linking that simply tries to link only the G4VG
target. Confirmed to reproduce problem observed in AdePT, with
the fixes above resolving it.
@drbenmorgan
Copy link
Member Author

Thanks @WitekPokorski! This looks like it may be a GCC 12/binutils issue with increased strictness around link paths/resolving libraries through rpath/etc (I couldn't reproduce in a GCC 11 environment). I'll submit a workaround to upstream in G4VG, but in the meantime could you check if adding /home/witoldp/Geant4/installation/lib64 to LD_LIBRARY_PATH resolves things for you please? You may need to do a fresh build to fully pick that change up after doing it.

sethrj pushed a commit to celeritas-project/g4vg that referenced this pull request May 7, 2024
Discovered in testing of integration of G4VG in apt-sim/AdePT#289,
targets linking to installed G4VG may fail to link due to linker
not having needed information on location of deps-of-deps of G4VG.
This happens in build environments where

1. The installed dependencies (here, Geant4, VecGeom) do not have
   their rpath set correctly.
2. They are otherwise in a location the linker is not aware of,
   e.g. via ldconfig of LD_LIBRARY_PATH etc.

The link error warns about this and suggests adding the path through,
e.g. `-rpath-link`. CMake will always add this flag/path correctly,
but only if it knows about the dependencies (even if private).

The G4VG library only depends on the static Celeritas::geocel target,
which does not forward its dependencies to Geant4/Vecgeom and so
it does not set `-rpath-link` for these.

Workaround this issue by explicitly making used Geant4 targets
PRIVATE deps of the g4vg target. Refind Geant4/VecGeom dependencies
when finding G4VG so these are resolved and available if the linker
requires it.

Add smoke test for linking that simply tries to link only the G4VG
target. Confirmed to reproduce problem observed in AdePT, with
the fixes above resolving it.
@JuanGonzalezCaminero
Copy link
Contributor

Yes, on one side there is the crash in the HGCALTB application, which I didn't have time to check more in detail yet. Then, regarding the AdePT examples, I noticed that the results are not numerically identical to master (With relatively large differences in some cases I remember). This is not necessarily wrong, but we should understand where they come from since this PR shouldn't have an effect there.

- Taken as of commit fb03216c0cd701c6aff0eb901370dad19e178503
- celeritas-project/celeritas@fb03216
Update README to explain and document use of "cuda_rdc_..." for
linking to AdePT.
Provides full support for install and reuse by clients.
Some platforms, Ubuntu being the canonical case, have their linker
configured to use the "as-needed" option by default. Due to the
current structure of RDC split device/host code libraries, link time
errors can result due to the linker ignoring one of these libraries.

Explicitly add `--no-as-needed` to AdePT's host linking stage to
workaround this issue. Document use in downstream projects.
- Update to latest upstream commit with fix for typo in G4VGConfig.cmake
- Do not use EXCLUDE_FROM_ALL so that CMake 3.28 and newer will install
  G4VG and support files

Expect second point to be temporary until true common G4VG as external
dependency shared between Celeritas and AdePT can be established.
If explicit ALIAS targets with the final install namespace (e.g.
"NS::Target" for "Target") are not created for an RDC library,
the installed targets have the wrong names set for the CUDA_RDC
properties. This results in both compile and (unseen) link errors
because the bare target names are interpreted as raw libraries,
not CMake targets. Dependencies are then not transmitted correctly,
resulting in compile/link issues for missing include paths etc.

Explicitly create ALIAS targets for CopCore and AdePT RDC libraries
to ensure they are installed with the correct install-time target
names for their `CUDA_RDC_...` properties.
@drbenmorgan
Copy link
Member Author

@andresailer, @JuanGonzalezCaminero, @agheata, could someone take a look at why the CI is failing please? The output suggests something on the Jenkins side rather than this PR, but I'm not 100% sure.

@agheata
Copy link
Contributor

agheata commented Jun 11, 2024

@drbenmorgan the CI was migrated from centos to alma, can you try to rebase this branch on the master?

@drbenmorgan
Copy link
Member Author

The latest build was triggered by me rebasing this onto the current master (as of 92851f7) and pushing, so the latest changes are here.

@andresailer
Copy link
Contributor

Can you push another change?
Jenkins pipelines somehow always need two runs when configurations change, because the first run only has the previous configuration.

@andresailer
Copy link
Contributor

Thanks! Now the jenkins build runs.

@drbenmorgan
Copy link
Member Author

Phew, that's good to know! Things all seem to pass both on CI and locally, so could people try out in the current integration projects, or point me to the current state/repos for them please? It would be good to get this progressed/merged asap.

@agheata
Copy link
Contributor

agheata commented Jun 11, 2024

@drbenmorgan the status is that linking a simple example using the RDC from this branch works indeed, but then we get a CUDA stack corruption, which we have not managed to debug yet. The corruption does not happen if linking against the master. This did not go away by increasing the stack size per thread in CUDA. @JuanGonzalezCaminero can provide a simple reproducer if you want to look.

@JuanGonzalezCaminero
Copy link
Contributor

Hi Ben,

Yes, for now the only reproducer we have is still the HGCALTB application. I described how to adapt it in my previous comment #289 (comment)

@drbenmorgan
Copy link
Member Author

Thanks @JuanGonzalezCaminero I'll revisit that and see if I can reproduce.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants