6 template <
typename SpinorX,
typename SpinorY,
typename SpinorZ,
7 typename SpinorW,
typename Functor>
16 : X(X), Y(Y), Z(Z), W(W), f(f), length(length) { ; }
22 template <
typename FloatN,
int M,
typename SpinorX,
typename SpinorY,
23 typename SpinorZ,
typename SpinorW,
typename Functor>
25 unsigned int i = blockIdx.x*(blockDim.x) + threadIdx.x;
26 unsigned int gridSize = gridDim.x*blockDim.x;
28 FloatN
x[M],
y[M], z[M], w[M];
35 for (
int j=0; j<M; j++) arg.
f(x[j], y[j], z[j], w[j]);
45 template <
typename FloatN,
int M,
typename SpinorX,
typename SpinorY,
46 typename SpinorZ,
typename SpinorW,
typename Functor>
54 char *X_h, *Y_h, *Z_h, *W_h;
55 char *Xnorm_h, *Ynorm_h, *Znorm_h, *Wnorm_h;
57 const size_t *norm_bytes_;
59 unsigned int sharedBytesPerThread()
const {
return 0; }
60 unsigned int sharedBytesPerBlock(
const TuneParam &
param)
const {
return 0; }
62 virtual bool advanceSharedBytes(TuneParam ¶m)
const
64 TuneParam next(param);
65 advanceBlockDim(next);
66 int nthreads = next.block.x * next.block.y * next.block.z;
67 param.shared_bytes = sharedBytesPerThread()*nthreads > sharedBytesPerBlock(param) ?
68 sharedBytesPerThread()*nthreads : sharedBytesPerBlock(param);
73 BlasCuda(SpinorX &
X, SpinorY &
Y, SpinorZ &
Z, SpinorW &W, Functor &f,
74 int length,
const size_t *
bytes,
const size_t *norm_bytes) :
75 arg(X, Y, Z, W, f, length), X_h(0), Y_h(0), Z_h(0), W_h(0),
76 Xnorm_h(0), Ynorm_h(0), Znorm_h(0), Wnorm_h(0),
77 bytes_(bytes), norm_bytes_(norm_bytes)
82 return TuneKey(blasStrings.vol_str,
typeid(arg.f).name(), blasStrings.aux_tmp);
87 blasKernel<FloatN,M> <<<tp.grid, tp.block, tp.shared_bytes, stream>>>(arg);
91 arg.X.save(&X_h, &Xnorm_h, bytes_[0], norm_bytes_[0]);
92 arg.Y.save(&Y_h, &Ynorm_h, bytes_[1], norm_bytes_[1]);
93 arg.Z.save(&Z_h, &Znorm_h, bytes_[2], norm_bytes_[2]);
94 arg.W.save(&W_h, &Wnorm_h, bytes_[3], norm_bytes_[3]);
98 arg.X.load(&X_h, &Xnorm_h, bytes_[0], norm_bytes_[0]);
99 arg.Y.load(&Y_h, &Ynorm_h, bytes_[1], norm_bytes_[1]);
100 arg.Z.load(&Z_h, &Znorm_h, bytes_[2], norm_bytes_[2]);
101 arg.W.load(&W_h, &Wnorm_h, bytes_[3], norm_bytes_[3]);
104 long long flops()
const {
return arg.f.flops()*(
sizeof(FloatN)/
sizeof(((FloatN*)0)->x))*arg.length*M; }
106 size_t bytes = arg.X.Precision()*(
sizeof(FloatN)/
sizeof(((FloatN*)0)->x))*M;
108 return arg.f.streams()*bytes*arg.length; }
115 template <
template <
typename Float,
typename FloatN>
class Functor,
116 int writeX,
int writeY,
int writeZ,
int writeW>
117 void blasCuda(
const double2 &a,
const double2 &b,
const double2 &c,
118 cudaColorSpinorField &
x, cudaColorSpinorField &
y,
119 cudaColorSpinorField &z, cudaColorSpinorField &w) {
125 warningQuda(
"Blas on non-native fields is not supported\n");
129 blasStrings.vol_str = x.VolString();
130 strcpy(blasStrings.aux_tmp, x.AuxString());
131 strcat(blasStrings.aux_tmp,
",");
132 strcat(blasStrings.aux_tmp, y.AuxString());
135 mixed::blasCuda<Functor,writeX,writeY,writeZ,writeW>
136 (a, b, c, x.Even(), y.Even(), z.Even(), w.Even());
137 mixed::blasCuda<Functor,writeX,writeY,writeZ,writeW>
138 (a, b, c, x.Odd(), y.Odd(), z.Odd(), w.Odd());
145 size_t bytes[] = {x.Bytes(), y.Bytes(), z.Bytes(), w.Bytes()};
146 size_t norm_bytes[] = {x.NormBytes(), y.NormBytes(), z.NormBytes(), w.NormBytes()};
149 if (x.Nspin() == 4) {
155 Functor<double2, double2> f(a, b, c);
157 Spinor<double2,double2,double2,M,writeY,1>,
Spinor<double2,double4,float4,M,writeZ,2>,
159 blas(X, Y, Z, W, f, y.Volume(), bytes, norm_bytes);
160 blas.apply(*blasStream);
161 }
else if (x.Nspin() == 1) {
167 Functor<double2, double2> f(a, b, c);
169 Spinor<double2,double2,float2,M,writeX,0>,
Spinor<double2,double2,double2,M,writeY,1>,
170 Spinor<double2,double2,float2,M,writeZ,2>,
Spinor<double2,double2,float2,M,writeW,3>,
171 Functor<double2, double2> > blas(X, Y, Z, W, f, y.Volume(), bytes, norm_bytes);
172 blas.apply(*blasStream);
175 if (x.Nspin() == 4) {
181 Functor<double2, double2> f(a, b, c);
183 Spinor<double2,double4,short4,M,writeX,0>,
Spinor<double2,double2,double2,M,writeY,1>,
184 Spinor<double2,double4,short4,M,writeZ,2>,
Spinor<double2,double4,short4,M,writeW,3>,
185 Functor<double2, double2> > blas(X, Y, Z, W, f, y.Volume(), bytes, norm_bytes);
186 blas.apply(*blasStream);
187 }
else if (x.Nspin() == 1) {
193 Functor<double2, double2> f(a, b, c);
195 Spinor<double2,double2,short2,M,writeX,0>,
Spinor<double2,double2,double2,M,writeY,1>,
196 Spinor<double2,double2,short2,M,writeZ,2>,
Spinor<double2,double2,short2,M,writeW,3>,
197 Functor<double2, double2> > blas(X, Y, Z, W, f, y.Volume(), bytes, norm_bytes);
198 blas.apply(*blasStream);
201 if (x.Nspin() == 4) {
207 Functor<float2, float4> f(make_float2(a.x, a.y), make_float2(b.x, b.y), make_float2(c.x, c.y));
209 Spinor<float4,float4,short4,M,writeX,0>,
Spinor<float4,float4,float4,M,writeY,1>,
210 Spinor<float4,float4,short4,M,writeZ,2>,
Spinor<float4,float4,short4,M,writeW,3>,
211 Functor<float2, float4> > blas(X, Y, Z, W, f, y.Volume(), bytes, norm_bytes);
212 blas.apply(*blasStream);
213 }
else if (x.Nspin() == 1) {
219 Functor<float2, float2> f(make_float2(a.x, a.y), make_float2(b.x, b.y), make_float2(c.x, c.y));
221 Spinor<float2,float2,short2,M,writeX,0>,
Spinor<float2,float2,float2,M,writeY,1>,
222 Spinor<float2,float2,short2,M,writeZ,2>,
Spinor<float2,float2,short2,M,writeW,3>,
223 Functor<float2, float2> > blas(X, Y, Z, W, f, y.Volume(), bytes, norm_bytes);
224 blas.apply(*blasStream);
227 errorQuda(
"Not implemented for this precision combination");
231 blas_flops += Functor<double2,double2>::flops()*(
unsigned long long)x.RealLength();
QudaVerbosity getVerbosity()
unsigned long long blas_bytes
BlasArg(SpinorX X, SpinorY Y, SpinorZ Z, SpinorW W, Functor f, int length)
__global__ void blasKernel(BlasArg< SpinorX, SpinorY, SpinorZ, SpinorW, Functor > arg)
void apply(const cudaStream_t &stream)
TuneParam & tuneLaunch(Tunable &tunable, QudaTune enabled, QudaVerbosity verbosity)
BlasCuda(SpinorX &X, SpinorY &Y, SpinorZ &Z, SpinorW &W, Functor &f, int length, const size_t *bytes, const size_t *norm_bytes)
#define checkLength(a, b)
unsigned long long blas_flops
__host__ __device__ ValueType arg(const complex< ValueType > &z)
Returns the phase angle of z.
void blasCuda(const double2 &a, const double2 &b, const double2 &c, cudaColorSpinorField &x, cudaColorSpinorField &y, cudaColorSpinorField &z, cudaColorSpinorField &w)
#define checkSpinor(a, b)