Skip to content

[tmva][sofie] Emit self-contained inference code from SOFIE#22920

Open
guitargeek wants to merge 1 commit into
root-project:masterfrom
guitargeek:standalone_tmva
Open

[tmva][sofie] Emit self-contained inference code from SOFIE#22920
guitargeek wants to merge 1 commit into
root-project:masterfrom
guitargeek:standalone_tmva

Conversation

@guitargeek

Copy link
Copy Markdown
Contributor

The C++ that TMVA SOFIE generates used to call helper functions defined in TMVA/SOFIE_common.hxx, so the generated header was not truly standalone: it required the ROOT/TMVA headers to compile. This makes the generated inference code self-contained.

  • New src/SOFIE_common_helpers.cxx provides GenerateHelperFunctionsCode(), which returns standalone copies of only the helpers a given model needs (Gemm_Call, Copy, Fill, Relu, Im2col/Im2col_3d/col2im, the broadcast helpers, ReadTensorFromStream, the input-dim and dynamic-memory helpers). RModel records the needed helpers via RModel_Base::AddNeededHelperFunction() and dumps them into the generated model namespace; the generated header no longer includes TMVA/SOFIE_common.hxx.

  • Clad autodiff: the custom-derivative pullbacks (Gemm_Call/Copy/Fill/Relu) are moved out of Math/CladDerivator.h and emitted alongside the generated helpers, into clad::custom_derivatives:: where Clad looks them up. The generated code can therefore be differentiated with Clad without depending on SOFIE_common.hxx or CladDerivator.h.

  • Remove the now generated-code-only helpers from SOFIE_common.hxx/.cxx and the SOFIE custom-derivative block from CladDerivator.h. Helpers still used at generation time (ConvertShapeTo*, the broadcast helpers, GNN_Data, ...) are kept.

  • TestGemmDerivative now exercises the emitted helper + pullback via GenerateHelperFunctionsCode instead of the library helper + CladDerivator.h.

  • GNN / GraphIndependent keep the shared TMVA::Experimental::SOFIE::GNN_Data as the inference boundary type (emit a using-alias, not a per-model struct) so the type stays compatible with the callers that build and chain it.

  • Avoid declaring the BLAS sgemm_ routine twice in generated headers (the fNeededBlasRoutines block and the Gemm_Call helper no longer both emit it).

  • Fix a latent double-broadcast in the buffer-filling UnidirectionalBroadcast overload (missing return after the shape-prepend branch).

🤖 Done with the help of AI.

The C++ that TMVA SOFIE generates used to call helper functions defined in
TMVA/SOFIE_common.hxx, so the generated header was not truly standalone: it
required the ROOT/TMVA headers to compile. This makes the generated inference
code self-contained.

- New src/SOFIE_common_helpers.cxx provides GenerateHelperFunctionsCode(), which
  returns standalone copies of only the helpers a given model needs (Gemm_Call,
  Copy, Fill, Relu, Im2col/Im2col_3d/col2im, the broadcast helpers,
  ReadTensorFromStream, the input-dim and dynamic-memory helpers). RModel records
  the needed helpers via RModel_Base::AddNeededHelperFunction() and dumps them
  into the generated model namespace; the generated header no longer includes
  TMVA/SOFIE_common.hxx.

- Clad autodiff: the custom-derivative pullbacks (Gemm_Call/Copy/Fill/Relu) are
  moved out of Math/CladDerivator.h and emitted alongside the generated helpers,
  into clad::custom_derivatives::<model namespace> where Clad looks them up. The
  generated code can therefore be differentiated with Clad without depending on
  SOFIE_common.hxx or CladDerivator.h.

- Remove the now generated-code-only helpers from SOFIE_common.hxx/.cxx and the
  SOFIE custom-derivative block from CladDerivator.h. Helpers still used at
  generation time (ConvertShapeTo*, the broadcast helpers, GNN_Data, ...) are
  kept.

- TestGemmDerivative now exercises the emitted helper + pullback via
  GenerateHelperFunctionsCode instead of the library helper + CladDerivator.h.

- GNN / GraphIndependent keep the shared TMVA::Experimental::SOFIE::GNN_Data as
  the inference boundary type (emit a using-alias, not a per-model struct) so
  the type stays compatible with the callers that build and chain it.

- Avoid declaring the BLAS sgemm_ routine twice in generated headers (the
  fNeededBlasRoutines block and the Gemm_Call helper no longer both emit it).

- Fix a latent double-broadcast in the buffer-filling UnidirectionalBroadcast
  overload (missing return after the shape-prepend branch).

🤖 Done with the help of AI.
@github-actions

github-actions Bot commented Jul 26, 2026

Copy link
Copy Markdown

Test Results

    23 files      23 suites   3d 18h 22m 49s ⏱️
 3 876 tests  3 875 ✅ 0 💤 1 ❌
79 842 runs  79 833 ✅ 8 💤 1 ❌

For more details on these failures, see this check.

Results for commit 4551adf.

♻️ This comment has been updated with latest results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant