qcdcode / quda

QUDA is a library for performing calculations in lattice QCD on GPUs.
http://lattice.github.com/quda
Other
2 stars 0 forks source link

wire up NdegTwistedCloverPreconditioned and get it to compile #7

Closed kostrzewa closed 3 years ago

kostrzewa commented 3 years ago

@urbach didn't want to step on your toes so I did this in a separate branch tonight, just wanted to see if I could get the logic compiled to get NdegTwistedCloverPreconditioned under test coverage.

Note that part of the non-deg twisted clover dslash already passes the tmc_ndeg_dslash test, since the daggered symmetric operator is not fused and implemented via the Wilson Dslash and TwistCloverInv, the latter of which I generalised to two flavours yesterday.

See lib/dirac_twisted_clover.cpp:

  // apply hopping term, then inverse twist: (A_ee^-1 D_eo) or (A_oo^-1 D_oe),
  // and likewise for dagger: (D^dagger_eo D_ee^-1) or (D^dagger_oe A_oo^-1)
  void DiracTwistedCloverPC::Dslash(ColorSpinorField &out, const ColorSpinorField &in, const QudaParity parity) const
  {
    checkParitySpinor(in, out);
    checkSpinorAlias(in, out);

    if (in.TwistFlavor() != out.TwistFlavor())
      errorQuda("Twist flavors %d %d don't match", in.TwistFlavor(), out.TwistFlavor());
    if (in.TwistFlavor() == QUDA_TWIST_NO || in.TwistFlavor() == QUDA_TWIST_INVALID)
      errorQuda("Twist flavor not set %d", in.TwistFlavor());

    bool symmetric = (matpcType == QUDA_MATPC_EVEN_EVEN || matpcType == QUDA_MATPC_ODD_ODD) ? true : false;
    if (dagger && symmetric && !reverse) {
      bool reset = newTmp(&tmp2, in);
      TwistCloverInv(*tmp2, in, 1 - parity);
      DiracWilson::Dslash(out, *tmp2, parity);
      deleteTmp(&tmp2, reset);
    } else {
      if (in.TwistFlavor() == QUDA_TWIST_SINGLET){
        ApplyTwistedCloverPreconditioned(out, in, *gauge, *clover, 1.0, -2.0 * kappa * mu, false, in, parity, dagger,
                                         commDim, profile);
        flops += (1320ll + 552ll) * in.Volume();
      } else {
        ApplyNdegTwistedCloverPreconditioned(out, in, *gauge, *clover, 1.0, -2.0 * kappa * mu, 2.0 * kappa * epsilon,
                                             false, in, parity, dagger, !symmetric, commDim, profile);
        // FIXME check flops
        flops += (1320ll + 96ll + 48ll + 552ll) * in.Volume();
      } 
    }
  }

The logic for this split is also further spelled out in the Doxygen for ApplyNdegTwistedCloverPreconditioned (include/dslash_quda.h)

494   /**
495      @brief Driver for applying the non-degenerate preconditioned twisted-clover stencil
496 
497      out = a * (C + i*b*gamma_5*tau_3 - c*tau_1)^{-1} * D * in + x
498          = a * (C - i*b*gamma_5*tau_3 + c*tau_1)/(C^2 + b^2 - c^2) * D * in + x
499          = A^{-1} * D * in + x
500 
501      where D is the gauged Wilson linear operator and C is the clover
502      field.  This operator can (at present) be applied to only single
503      parity (checker-boarded) fields.  When the dagger operator is
504      requested, we do not transpose the order of operations, e.g.
505 
506      out = A^{-\dagger} D^\dagger  (no xpay term)
507 
508      Although not a conjugate transpose of the regular operator, this
509      variant is used to enable kernel fusion between the application
510      of D and the subsequent application of A, e.g., in the symmetric
511      dagger operator we need to apply
512 
513      M = (1 - kappa^2 D^{\dagger} A^{-\dagger} D{^\dagger} A^{-\dagger} )
514 
515      and since cannot fuse D{^\dagger} A^{-\dagger}, we instead fused
516      A^{-\dagger} D{^\dagger}.
517 
518      @param[out] out The output result field
519      @param[in] in The input field
520      @param[in] U The gauge field used for the operator
521      @param[in] C The clover field used for the operator
522      @param[in] a Scale factor applied to Wilson term ( typically 1.0)
523      @param[in] b chiral twist factor applied (typically -2*kappa*mu)
524      @param[in] c flavor twist factor applied (typically 2*kappa*epsilon)
525      @param[in] xpay Whether to do xpay or not
526      @param[in] x Vector field we accumulate onto to when xpay is true
527      @param[in] parity Destination parity
528      @param[in] dagger Whether this is for the dagger operator
529      @param[in] asymmetric Whether this is for the asymmetric preconditioned daggered operator
530       out = a * (C - i*b*gamma_5*tau_3 + c*tau_1)^{-1} * D^\dagger * in
531      @param[in] comm_override Override for which dimensions are partitioned
532      @param[in] profile The TimeProfile used for profiling the dslash
533   */
534   void ApplyNdegTwistedCloverPreconditioned(ColorSpinorField &out, const ColorSpinorField &in, const GaugeField &U,
535       const CloverField &C, double a, double b, double c, bool xpay, const ColorSpinorField &x, int parity, bool dagger,
536       bool asymmetric, const int *comm_override, TimeProfile &profile);
urbach commented 3 years ago

Very good, I'll look at it. You have fortunately much more time than I do!

On 18 March 2021 20:49:03 CET, Bartosz Kostrzewa @.> wrote: @. commented on this pull request.

@@ -8,11 +8,11 @@ namespace quda {

  • template <typename Float, int nColor, int nDim, QudaReconstructType reconstruct_, bool dynamicclover, bool asymmetric_>
  • template <typename Float, int nColor, int nDim, QudaReconstructType reconstruct, bool asymmetric>

note that I've removed the dynamic_clover template argument since it's not required

-- CU Mobil, www.carsten-urbach.eu

urbach commented 3 years ago

apart from these question I'm happy to merge this in.

urbach commented 3 years ago

okay, that's true. so one needs to make sure that never both cuh files are included...

@kostrzewa commented on this pull request.

@@ -15,15 +15,12 @@ namespace quda { // trait to ensure we don't instantiate asymmetric & xpay

  • // defined dslash_ndeg_twisted_mass_preconditioned.cu
  • template constexpr bool xpay_();
  • template <> constexpr bool xpay_();
  • template constexpr bool xpay_() { return true; }
  • template <> constexpr bool xpay_() { return false; }

image

-- You are receiving this because you modified the open/close state. Reply to this email directly or view it on GitHub: https://github.com/qcdcode/quda/pull/7#discussion_r597567877

-- Carsten Urbach e-mail: @. @. Fon : +49 (0)228 73 2379 skype : carsten.urbach URL: http://www.carsten-urbach.eu

kostrzewa commented 3 years ago

Very good, I'll look at it. You have fortunately much more time than I do!

That will change next week I'm afraid, so I wanted to do as much ground-work as possible to be in a position from next week onwards to work in small chunks.