Skip to content

Record the work of applying the trace when learning it - #394

Merged
ederc merged 2 commits into
algebraic-solving:masterfrom
mohabsafey:f4-counters
Nov 9, 2026
Merged

ederc merged 2 commits into
algebraic-solving:masterfrom
mohabsafey:f4-counters

Conversation

@mohabsafey

@mohabsafey mohabsafey commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

The linear algebra no longer counts the F4 operations of the runs applying the trace (#390 removed the application counters from the kernels as unused, and the counts of a run were never added to the meta data of the caller anyway). As a result, the verbose output of msolve_trace_qq and of the lifting of Gröbner bases always reported 0 Gops/sec for the learning and the application phases, and 0 additions, multiplications and reductions at info level 3.

This PR records the work of an application of the trace in the trace itself, when it is learned. This work is the same for all primes, so it does not need to be counted at each run, and the kernels and their inner loops are not changed.

Changes

  • Three new fields of trace_t, summed over the rounds of the trace:
    • nmadd: the multiply-adds of the reductions of the rows by the known pivots. construct_trace adds, for each row kept in the trace, the lengths of the known pivots marked in its reducer bit array. This is exactly the work of these reductions when the trace is applied.
    • nterms: the terms of the rows of the matrices, that is the rows to be reduced (multiples of basis elements, whose lengths construct_trace now reads from the basis passed to it) and the reducers used.
    • nmadd_new: an estimate of the multiply-adds of the reductions of the new rows by each other, which nmadd does not include: the number of new elements of a round times their total length, added by add_lms_to_trace.
  • The rate of the application phase in the verbose output is computed from nmadd. It is printed only when a trace is learned, which is not the case with the probabilistic linear algebra (-l 42 or 44). The rate of the learning phase and the numbers of additions, multiplications and reductions printed at info level 3, which were always 0, are no longer printed.

These quantities do not depend on the prime nor on the number of threads, which makes them suitable for cost models choosing between strategies. They are meant for the cost model of the p-adic lifting of parametrizations (#391), which used the application counters removed by #390.

Testing

  • make check passes (73/73).
  • The outputs are identical to those of master on cyclic5, kat7, kat10, eco10 and random2_7_7, with -P 2 -t 2 and with -g 2.
  • On kat7, -P 2 and -g 2 run with each of the options -l 2, 42 and 44, at info levels 0, 2 and 3 (-l 1 crashes on master too, independently of this PR).
  • The learning run of F4 on kat12 is not slower (4.1 to 4.3 s against 4.6 to 4.8 s for master, 3 seeds).

Parts of this PR were written with the assistance of Claude Code (Claude Opus 5.5); all changes were reviewed and tested by the author.

🤖 Generated with Claude Code

mohabsafey and others added 2 commits November 7, 2026 18:21
The F4 operations of the runs applying the trace are no longer counted:
the linear algebra kernels do not increment the application counters,
and the counts of a run were never added to the meta data of the
caller, so the verbose output reported 0 Gops/sec for the learning and
the application phases. Counting in the kernels would add work to their
inner loops and needs care with several threads.

The work of an application of the trace is the same for all primes, so
it is now recorded in the trace when it is learned, outside the
kernels. For each round, construct_trace adds to nmadd the lengths of
the known pivots used by each row kept in the trace, that is the
multiply-adds of the reductions of the rows by the known pivots, and
to nterms the terms of the rows to be reduced and of the reducers used.
add_lms_to_trace adds to nmadd_new the number of new elements of the
round times their total length, an estimate of the multiply-adds of
the reductions of the new rows by each other, which nmadd does not
include. These quantities are meant for cost models choosing between
strategies, such as the p-adic lifting of the parametrizations.

In the verbose output of msolve_trace_qq and of the lifting of
Gröbner bases, the rate of the application phase is computed from
nmadd. The rate of the learning phase and the numbers of additions,
multiplications and reductions printed at info level 3, which were
always 0, are no longer printed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With probabilistic linear algebra (-l 42, 43 or 44), F4 learns no trace
and the meta data has no trace to read the multiply-adds from, so msolve
crashed when printing the rate of the application phase at info level
2. The rate is now printed only when a trace exists.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ederc
ederc merged commit d9e69d5 into algebraic-solving:master Nov 9, 2026
10 checks passed
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.

2 participants