Backend separation - #76
Open
stloufra wants to merge 25 commits into
Open
Conversation
depending on backend and pre-stored in separate folders template files need to be prunned and make it compiled
delete Bridge. Resolving the not nested #ifdefs. next the .inc in template_files
ProcessData.h ColorMatrixData.h process specic data
Relocate sigmaKin, calculate_jamps, computeDependentCouplings, getGoodHel/
setGoodHel, and color_sum_cpu/color_sum_gpu out of the per-process
CPPProcess.cc into backend-owned SigmaKin.{h,cc} and color_sum.cc under
backend/{cpu,simd,gpu}/.
The storage they operate on (cHel/cFlavors/cIPD/
cIPC/cIPF_*/bsmIndepParam/good-helicity cache) moves with them as generic,
backend-owned declarations sized via nIPD/nIPC/ncomb/etc. - constexpr
constants pulled from each process's own ProcessData.h/ProcessTables.h at
compile time, the same pattern already used by color_sum.cc (ncolor from
ColorMatrixData.h).
CPPProcess's constructor/initProc populates this
storage through new setters (setHelicitiesAndFlavors, setIndependentParams,
etc.) instead of writing it directly.
+ more resolution of #ifdefs paths to anhilatethem
Include right backend and copy right files.
cleaning of the EvaluateDiagrams.inc
only in standalone_mg7 copy needed files - e.g. check_sa.cc delete them from /backend and delete the death code files
more prune for standalone_mg7 output
delete the Gpu* files from cpu and simd. More prune of death code and #ifdefs
fpeEnable(), getCompiler() move in constexpr_math.h and mgOnGpuConfig.h tHel/tFlavors/flavorPDGs in ProcessData getCompiler had zero calls -> dropped mass/tIPD/tIPC setup (non-hardcoded branch) is now a generated pointer-to-member table read by generic gatherFptype/ gatherCxtype helpers in Parameters.h, instead of one assignment per parameter. The MGONGPU_HARDCODE_PARAM branch same TODO
unified namespace madgraph instead of mg5amcGpu/mg5amcCpu. Fix for some functions depending on vector lane size
to get rid off more ifdefs by having noop instance for cpu and simd
Conditionaly included for the simd Needed stuff for the cpu/gpu in mgOnGpuCxtypes
when making ccpnone -> cppsse4 -> cppnone rule for check_sa checked that cppnone buildir content is older than the check_sa and did not relink, silently reusing the sse4 lib. now small prerequisity storing last compiled backend solution
stloufra
requested review from
Qubitol,
oliviermattelaer,
roiser and
theoheimel
August 19, 2026 13:31
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Physically separates backend-owned driver code (cpu / simd / gpu) out of the madmatrix generator's shared and per-process-generated files into
backend/{cpu,simd,gpu}/, so a given backend's code lives in its own directory instead of being selected at compile time via#ifdef MGONGPUCPP_GPUIMPL/MGONGPU_CPPSIMD.What changed
SigmaKin,color_sum,CrossSectionKernels,MatrixElementKernels,EventStatistics,umami, the 14MemoryAccess*.hfiles, andmgOnGpuConfig/Cxtypes/Fptypes/Vectors.hnow live underbackend/{cpu,simd,gpu}/, sourced by the Makefile via-I/vpathinstead of being copied per process.ColorData.h(merges colour channel information + the color matrix),ProcessData.h(merges contexpr process data e.g.nwf, extended with the helicity/flavor tables that used to be inline inCPPProcess.cc),ProcessTables.h(flavor-coupling / broken-symmetry tables) — single source of truth read by bothCPPProcessand backend-owned code.CPPProcess.cc: all funcs related toSigmaKincomputation moved to/backend/SigmakinfpeEnable()/getCompiler()moved to backend files; per-parameter imperative literal-assignment code replaced by a generated pointer-to-member table plus one genericgatherFptype/gatherCxtypeloop written once inParameters.h.Bridge.h,BridgeKernels.*,fbridge.*,fsampler.cc(zero remaining references);GpuAbstraction.h/GpuRuntime.hmade gpu-only.mg5amcCpu/mg5amcGpu→ onemadmatrixnamespace (the split is now physical, not namespace-based)#ifdefat the point of use:createNormalizedColorMatrix(): no-op inline on cpu/simd, realgpuMemcpyToSymbolon gpu.ColorData.h's device→host copy ofchannel2iconfigremoved entirely (its only consumer,runTest.cc, isn't wired into any export path — kept a local#ifndef/#elsethere since it can't get per-process%-substituted literals the wayColorData.hcan for now).backend/{cpu,gpu}/mgOnGpuVectors.hentirely — neither backend has real C++ vector types; their scalar-only content (neppV,fpternary/cxternary/maskand, the_svtypedefs,cxabs2) merged intomgOnGpuCxtypes.h. The handful of shared, non-per-backend.incfiles that need this now pick the right header via__has_include. Stripped the remaining always-true#ifdef MGONGPU_CPPSIMDguards (and the dead code blocks they wrapped) frombackend/simd/mgOnGpuVectors.h.output standalone_mg7onlyUSEBUILDDIRdefaults to 1 for cleaner buildsramboused in standalone mode for both massive and massless version as well as the random number kernels live in./src/ramboand is sourced whenP1_*is compiledNet effect
MGONGPUCPP_GPUIMPLnow survives only for poping diagnostics while carryinghip/cudadiversification and in the standalone specific files (rambo/check_sa)MGONGPU_CPPSIMDnow survives only in the /backend/simd as carry for the sims lane size and in theHelAmps_sm.hpolarisation functions for masking paths of conditional codeTest
cppnone/cppsse4/cppavx2/cuda) × 3-process (gg_ttxgg,uu_huugg,epem_mupmum) bitwise match on our a100 machine (GCC + GPU) and Apple M4 Pro (Clang) checking 64MatrixElementandMeanMatrixElemValueagainst the pre-refactor baseline commit (1a4f00df67, the brach from commit onmain) usingcheck_sa -p -v 256 64 1Refs
backend_separation.pdf
check_backend_regression.py