Skip to content

ToT: conj() on nested-tile contractions; real-plain x complex-ToT products via one real gemm - #574

Draft
kshitij-05 wants to merge 1 commit into
kshitij/feature/strided-tot-kernels-complexfrom
kshitij/feature/tot-conj-mixed-scale
Draft

ToT: conj() on nested-tile contractions; real-plain x complex-ToT products via one real gemm#574
kshitij-05 wants to merge 1 commit into
kshitij/feature/strided-tot-kernels-complexfrom
kshitij/feature/tot-conj-mixed-scale

Conversation

@kshitij-05

Copy link
Copy Markdown
Member

Builds on #573 (branch kshitij/feature/strided-tot-kernels-complex); to be retargeted to master once #573 is merged.

Problem

  1. conj() on a ToT contraction does not compile. conj(A * B) carries a ComplexConjugate<void> contraction factor; the ToT per-cell multiply-add ops in ContEngine static_cast that factor to the element type, Tensor::gemm forwards it as the BLAS alpha, and the ContractReduce<…, ComplexConjugate<…>> specializations name their result type through a value-returning gemm that nested tiles do not have.
  2. A complex ToT contracted with a real plain tensor (A("i,j;a") * t("j,k"), Tensor<Tensor<complex<double>>> × Tensor<double>) skips the ToT × plain-tensor GEMM fast path, which requires identical element types, and runs the per-cell AXPY loop.

Changes

  • detail::elem_factor<Numeric>(factor): the per-element multiplier for a contraction factor — the factor for numeric factors, 1 for ComplexConjugate<…> (conjugation and scale are applied to the finished result by ContractReduce's finalization, as for non-nested tiles). Used by the ToT per-cell ops in ContEngine and by Tensor::gemm's alpha.
  • ContractReduce<…, ComplexConjugate<void>> / <…, ComplexConjugate<Scalar>>: result_type is Result, as in the primary template, and the nested-tile accumulate (which was an abort(); // not yet implemented stub) and the partial-result reduce are shared with the primary template through ContractReduceBase::accumulate_nested / reduce_results.
  • ToT × real-plain products: when the plain element type is the real part of the inner element type, the complex slabs are viewed as real matrices with the inner extent doubled (re/im interleaved) and the existing strided GEMM runs in real arithmetic with alpha = beta = 1; results are identical to the complex product.
  • Tests (tot_conj suite in tests/tot_expressions.cpp, real and complex rows): conj(a), permuted conj(a), conj(a) * b, a * conj(b), conj(a * b) (outer contraction with inner outer product), conj(a) * b with an inner contraction, and the mixed-type ToT × real-plain product, all against explicit references.

Testing

arena_strided_dgemm, einsum*, tot_expressions (incl. tot_conj), tot_dist_array_part{1,2}: 821 cases, no errors.

Not addressed

  • Mixed real-ToT × complex-ToT products (the strided kernels require one element type for all three operands).

…ducts via one real gemm

conj(A * B) on tensor-of-tensor operands did not compile: ContEngine's per-cell
multiply-add ops static_cast the ComplexConjugate<void> contraction factor to the
element type, Tensor::gemm forwarded it as the BLAS alpha, the
ContractReduce<..., ComplexConjugate<...>> specializations named their result
type through a value-returning gemm nested tiles do not have, and their
nested-tile accumulate was an abort() stub.

- detail::elem_factor<Numeric>(factor): the per-element multiplier for a
  contraction factor -- the factor for numeric factors, 1 for
  ComplexConjugate<...> (conjugation and scale are applied to the finished
  result by ContractReduce's finalization, as for non-nested tiles); used by
  the ToT per-cell ops in ContEngine and by Tensor::gemm's alpha
- ContractReduce ComplexConjugate specializations: result_type is Result; the
  nested-tile accumulate and the arena-aware partial-result reduce are shared
  with the primary template (ContractReduceBase::accumulate_nested /
  reduce_results)
- ToT x real plain-tensor products: when the plain element type is the real
  part of the inner element type, the complex slabs are viewed as real matrices
  with the inner extent doubled (re,im interleaved) and the strided GEMM fast
  path runs in real arithmetic with alpha = beta = 1
- tests: tot_conj suite in tot_expressions.cpp -- conj(a), permuted conj(a),
  conj(a)*b, a*conj(b), conj(a*b), conj(a)*b with an inner contraction, and the
  mixed-type ToT x real-plain product, against explicit references
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