QUDA  v1.1.0
A library for QCD on GPUs
copy_color_spinor_offset.cu
Go to the documentation of this file.
1 #include <color_spinor_field.h>
2 #include <color_spinor_field_order.h>
3 
4 #include <kernels/copy_field_offset.cuh>
5 
6 #include <instantiate.h>
7 
8 namespace quda
9 {
10 
11  template <class Field, class Element, class F>
12  void copy_color_spinor_offset(Field &out, const Field &in, CommKey offset, QudaPCType pc_type)
13  {
14  F out_accessor(out);
15  F in_accessor(in);
16  if (pc_type == QUDA_4D_PC) {
17  CopyFieldOffsetArg<Field, Element, F, QUDA_4D_PC> arg(out_accessor, out, in_accessor, in, offset);
18  CopyFieldOffset<decltype(arg)> copier(arg, in);
19  } else if (pc_type == QUDA_5D_PC) {
20  CopyFieldOffsetArg<Field, Element, F, QUDA_5D_PC> arg(out_accessor, out, in_accessor, in, offset);
21  CopyFieldOffset<decltype(arg)> copier(arg, in);
22  } else {
23  errorQuda("pc_type should either be QUDA_4D_PC or QUDA_5D_PC.\n");
24  }
25  }
26 
27  template <class Float, int nColor, int nSpin>
28  void copy_color_spinor_offset(ColorSpinorField &out, const ColorSpinorField &in, CommKey offset, QudaPCType pc_type)
29  {
30  using Field = ColorSpinorField;
31  using real = typename mapper<Float>::type;
32  using Element = ColorSpinor<real, nColor, nSpin>;
33 
34  if (in.Location() == QUDA_CPU_FIELD_LOCATION) {
35  if (in.FieldOrder() == QUDA_SPACE_COLOR_SPIN_FIELD_ORDER) {
36  using F = typename colorspinor_order_mapper<Float, QUDA_SPACE_COLOR_SPIN_FIELD_ORDER, nSpin, nColor>::type;
37  copy_color_spinor_offset<Field, Element, F>(out, in, offset, pc_type);
38  } else if (in.FieldOrder() == QUDA_SPACE_SPIN_COLOR_FIELD_ORDER) {
39  using F = typename colorspinor_order_mapper<Float, QUDA_SPACE_SPIN_COLOR_FIELD_ORDER, nSpin, nColor>::type;
40  copy_color_spinor_offset<Field, Element, F>(out, in, offset, pc_type);
41  } else {
42  errorQuda("Unsupported field order = %d.", in.FieldOrder());
43  }
44  } else {
45  if (!in.isNative() || !out.isNative()) { errorQuda("CUDA field has be in native order."); }
46 
47  using F = typename colorspinor_mapper<Float, nSpin, nColor>::type;
48  copy_color_spinor_offset<Field, Element, F>(out, in, offset, pc_type);
49  }
50  }
51 
52  template <class Float, int nColor> struct CopyColorSpinorOffset {
53  CopyColorSpinorOffset(ColorSpinorField &out, const ColorSpinorField &in, CommKey offset, QudaPCType pc_type)
54  {
55  if (in.Nspin() == 4) {
56  copy_color_spinor_offset<Float, nColor, 4>(out, in, offset, pc_type);
57  } else if (in.Nspin() == 1) {
58  copy_color_spinor_offset<Float, nColor, 1>(out, in, offset, pc_type);
59  } else {
60  errorQuda("Unsupported spin = %d.\n", in.Nspin());
61  }
62  }
63  };
64 
65  void copyFieldOffset(ColorSpinorField &out, const ColorSpinorField &in, CommKey offset, QudaPCType pc_type)
66  {
67  checkPrecision(out, in);
68  checkLocation(out, in); // check all locations match
69  instantiate<CopyColorSpinorOffset>(out, in, offset, pc_type);
70  }
71 
72 } // namespace quda