Skip to content

Backend separation - #76

Open
stloufra wants to merge 25 commits into
mainfrom
backend_separation
Open

Backend separation#76
stloufra wants to merge 25 commits into
mainfrom
backend_separation

Conversation

@stloufra

@stloufra stloufra commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

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

  • New layout: SigmaKin, color_sum, CrossSectionKernels, MatrixElementKernels, EventStatistics, umami, the 14 MemoryAccess*.h files, and mgOnGpuConfig/Cxtypes/Fptypes/Vectors.h now live under backend/{cpu,simd,gpu}/, sourced by the Makefile via -I/vpath instead of being copied per process.
  • New per-process files: 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 in CPPProcess.cc), ProcessTables.h (flavor-coupling / broken-symmetry tables) — single source of truth read by both CPPProcess and backend-owned code.
  • Shrunk CPPProcess.cc: all funcs related to SigmaKin computation moved to /backend/Sigmakin fpeEnable()/getCompiler() moved to backend files; per-parameter imperative literal-assignment code replaced by a generated pointer-to-member table plus one generic gatherFptype/gatherCxtype loop written once in Parameters.h.
  • Deleted dead code: Bridge.h, BridgeKernels.*, fbridge.*, fsampler.cc (zero remaining references);
  • **GpuAbstraction.h/GpuRuntime.h made gpu-only.
  • Namespace unification: mg5amcCpu/mg5amcGpu → one madmatrix namespace (the split is now physical, not namespace-based)
  • Backend call sites, no more #ifdef at the point of use:
    • createNormalizedColorMatrix(): no-op inline on cpu/simd, real gpuMemcpyToSymbol on gpu.
    • ColorData.h's device→host copy of channel2iconfig removed entirely (its only consumer, runTest.cc, isn't wired into any export path — kept a local #ifndef/#else there since it can't get per-process %-substituted literals the way ColorData.h can for now).
  • Removed backend/{cpu,gpu}/mgOnGpuVectors.h entirely — neither backend has real C++ vector types; their scalar-only content (neppV, fpternary/cxternary/maskand, the _sv typedefs, cxabs2) merged into mgOnGpuCxtypes.h. The handful of shared, non-per-backend .inc files that need this now pick the right header via __has_include. Stripped the remaining always-true #ifdef MGONGPU_CPPSIMD guards (and the dead code blocks they wrapped) from backend/simd/mgOnGpuVectors.h.
  • Standalone files are guarded for output standalone_mg7 only
  • USEBUILDDIR defaults to 1 for cleaner builds
  • rambo used in standalone mode for both massive and massless version as well as the random number kernels live in ./src/rambo and is sourced when P1_* is compiled

Net effect

  • defined MGONGPUCPP_GPUIMPL now survives only for poping diagnostics while carrying hip/cuda diversification and in the standalone specific files (rambo/check_sa)
  • defined MGONGPU_CPPSIMD now survives only in the /backend/simd as carry for the sims lane size and in the HelAmps_sm.h polarisation functions for masking paths of conditional code

Test

  • Full 4-backend (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 64 MatrixElement and MeanMatrixElemValue against the pre-refactor baseline commit (1a4f00df67, the brach from commit on main) using check_sa -p -v 256 64 1

Refs

stloufra added 24 commits August 5, 2026 11:00
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
not committed ProcessData and ProcessTables due to .gitignore
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 stloufra added the enhancement New feature or request label Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants