Skip to content

ToT: strided arena kernels for complex inner cells; complex ToT scaling - #573

Open
kshitij-05 wants to merge 1 commit into
masterfrom
kshitij/feature/strided-tot-kernels-complex
Open

ToT: strided arena kernels for complex inner cells; complex ToT scaling#573
kshitij-05 wants to merge 1 commit into
masterfrom
kshitij/feature/strided-tot-kernels-complex

Conversation

@kshitij-05

@kshitij-05 kshitij-05 commented Aug 30, 2026

Copy link
Copy Markdown
Member

Problem

ToT×ToT contractions with std::complex<double> inner cells never use the strided arena kernels. arena_strided_dgemm_ce_e / _ce_ce_right / _ce_ce_left and their install gates in ContEngine are hard-coded to double, so a complex contraction falls back to the generic per-cell path: one tiny inner op per result cell and contracted index, instead of one strided BLAS gemm per cell. The kernels themselves are only layout/stride logic on top of blas::gemm, which already has the complex overloads.

Separately, scaling a complex ToT by an integral factor (2 * A("i;j")) does not compile: the ToT fill lambdas in Tensor::scale/add/subt/mult and ArenaTensor::scale_to use the raw elem * factor and miss the mixed complex×scalar operator* in detail that the non-nested scale branch already uses.

Changes

  • The three strided kernels are templated on the inner numeric type; detail::is_strided_dgemm_numeric_v<T> admits float, double, complex<float>, complex<double>. All three operands must share the type.
  • ContEngine install gates and the hc+e reuse gate use the trait; the diagnostic helpers' cell pointers are made type-generic.
  • ToT scale/add/subt/mult fill lambdas and ArenaTensor::scale_to pick up detail's mixed operators.
  • Tests: complex cases for the three kernels; a complex<double> row in the ToT fixture, so tot_expressions / tot_dist_array now cover complex ToTs.

Testing

arena_strided_dgemm, einsum*, tot_expressions, tot_dist_array_part{1,2}: 807 cases, no errors. With the change a complex ToT×ToT contraction reports strided ce+e installs where before it reported none.

Not addressed

  • conj() on a ToT contraction does not compile (ComplexConjugate<void> has no conversion to the element type; ContractReduce<…, ComplexConjugate<void>> needs a value-returning gemm).
  • The ToT × plain-tensor scale GEMM path requires identical element types; a complex ToT scaled by a real plain tensor uses per-cell AXPY.

…complex ToT scale/add/subt/mult

The arena strided-DGEMM ToT x ToT kernels (arena_strided_dgemm_ce_e,
_ce_ce_right, _ce_ce_left) and their ContEngine install gates were
numeric_type == double only, so every ToT contraction with
std::complex<double> inner storage silently took the generic per-cell path.

- kernels templated on the inner numeric type T, admitted through
  detail::is_strided_dgemm_numeric_v<T> (float, double, complex<float>,
  complex<double>); factor/beta typed T, cell pointers T*; all three operands
  must share T (mixed real x complex ToT products keep the per-cell path)
- diagnostic helpers classify_run / classify_operand / gather_rescuable /
  measure_segments: cell pointers made generic
- cont_engine.h ce+e / ce+ce install gates and the hc+e reuse gate: view
  cells + same numeric type + the trait; static_cast<numeric_type>(factor)
- Tensor<ToT> scale/add/subt/mult fill lambdas and ArenaTensor scale_to pick
  up detail's mixed complex x scalar operator* (as the non-nested scale branch
  already does), so e.g. 2 * A("i;j") compiles for complex ToTs
- tests: complex<double> cases for the three kernels; a complex<double> row
  in the ToT fixture type list (runs tot_expressions / tot_dist_array for
  complex ToTs); typedefs case compares scalar_type against scalar_t<elem>

Measured on MPQC Kramers PNS-CCD (complex ToTs, HSeOH/cc-pVDZ): 0 -> 531
strided ce+e installs, first CC iteration 52.0 -> 20.5 s, energy unchanged.
@kshitij-05 kshitij-05 changed the title ToT: strided arena kernels for complex<double>/float inner storage; complex ToT scale/add/subt/mult ToT: strided arena kernels for complex inner cells; complex ToT scaling Aug 30, 2026
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.

1 participant