10#include <pscf/backend/cuda/ThreadArray.h>
11#include <pscf/backend/cuda/HostSendArray.h>
12#include <pscf/backend/cuda/cudaErrorCheck.h>
37 int nThreads = blockDim.x * gridDim.x;
38 int startID = blockIdx.x * blockDim.x + threadIdx.x;
39 for (
int i = startID; i < n; i +=
nThreads) {
40 a[i] = (b1[i] * c1) + (b2[i] * c2);
59 int nThreads = blockDim.x * gridDim.x;
60 int startID = blockIdx.x * blockDim.x + threadIdx.x;
61 for (
int i = startID; i < n; i +=
nThreads) {
79 int nThreads = blockDim.x * gridDim.x;
80 int startID = blockIdx.x * blockDim.x + threadIdx.x;
81 for (
int i = startID; i < n; i +=
nThreads) {
105 int nThreads = blockDim.x * gridDim.x;
106 int startID = blockIdx.x * blockDim.x + threadIdx.x;
107 for (
int i = startID; i < n; i +=
nThreads) {
108 a[i] = (b1[i] * c1) + (b2[i] * c2) + (b3[i] * c3);
129 int nThreads = blockDim.x * gridDim.x;
130 int startID = blockIdx.x * blockDim.x + threadIdx.x;
131 for (
int i = startID; i < n; i +=
nThreads) {
132 a[i] = (b1[i] * c1) + (b2[i] * c2) + s;
155 int nThreads = blockDim.x * gridDim.x;
156 int startID = blockIdx.x * blockDim.x + threadIdx.x;
157 for (
int i = startID; i < n; i +=
nThreads) {
158 a[i] = b[i] - c[i] - d;
177 int nThreads = blockDim.x * gridDim.x;
178 int startID = blockIdx.x * blockDim.x + threadIdx.x;
179 for (
int i = startID; i < n; i +=
nThreads) {
180 a[i].x /= (b[i] * c);
181 a[i].y /= (b[i] * c);
199 int nThreads = blockDim.x * gridDim.x;
200 int startID = blockIdx.x * blockDim.x + threadIdx.x;
201 for (
int i = startID; i < n; i +=
nThreads) {
202 a[i] = exp(b[i] * c);
220 int nThreads = blockDim.x * gridDim.x;
221 int startID = blockIdx.x * blockDim.x + threadIdx.x;
223 for (
int i = startID; i < n; i +=
nThreads) {
245 int nThreads = blockDim.x * gridDim.x;
246 int startID = blockIdx.x * blockDim.x + threadIdx.x;
248 for (
int i = startID; i < n; i +=
nThreads) {
250 a1[i] = b1[i] * input;
251 a2[i] = b2[i] * input;
267 int nThreads = blockDim.x * gridDim.x;
268 int startID = blockIdx.x * blockDim.x + threadIdx.x;
270 for (
int i = startID; i < n; i +=
nThreads) {
294 const int nVecs,
const int n)
296 int nThreads = blockDim.x * gridDim.x;
297 int startID = blockIdx.x * blockDim.x + threadIdx.x;
298 for (
int i = startID; i < n; i +=
nThreads) {
300 for (
int j = 1; j < nVecs; j++) {
324 const int nVecs,
const int n)
326 int nThreads = blockDim.x * gridDim.x;
327 int startID = blockIdx.x * blockDim.x + threadIdx.x;
328 for (
int i = startID; i < n; i +=
nThreads) {
330 for (
int j = 1; j < nVecs; j++) {
347 int nThreads = blockDim.x * gridDim.x;
348 int startID = blockIdx.x * blockDim.x + threadIdx.x;
350 for (
int i = startID; i < n; i +=
nThreads) {
351 tmp = (b[i].x * b[i].x) + (b[i].y * b[i].y);
367 const int n = a.capacity();
372 int nBlocks, nThreads;
376 _addVcVc<<<nBlocks, nThreads>>>(a.cArray(),
379 cudaErrorCheck( cudaGetLastError() );
389 const int n = a.capacity();
393 int nBlocks, nThreads;
397 _addVcS<<<nBlocks, nThreads>>>(a.cArray(), b.cArray(), c, s, n);
398 cudaErrorCheck( cudaGetLastError() );
409 const int n = a.capacity();
415 int nBlocks, nThreads;
419 _addVcVcVc<<<nBlocks, nThreads>>>(a.cArray(),
423 cudaErrorCheck( cudaGetLastError() );
434 const int n = a.capacity();
439 int nBlocks, nThreads;
443 _addVcVcS<<<nBlocks, nThreads>>>(a.cArray(),
447 cudaErrorCheck( cudaGetLastError() );
459 const int n = a.capacity();
463 int nBlocks, nThreads;
467 _addEqVc<<<nBlocks, nThreads>>>(a.cArray(), b.cArray(), c, n);
468 cudaErrorCheck( cudaGetLastError() );
477 const int n = a.capacity();
481 int nBlocks, nThreads;
485 _divEqVc<<<nBlocks, nThreads>>>(a.cArray(), b.cArray(), c, n);
486 cudaErrorCheck( cudaGetLastError() );
495 const int n = a.capacity();
499 int nBlocks, nThreads;
503 _expVc<<<nBlocks, nThreads>>>(a.cArray(), b.cArray(), c, n);
504 cudaErrorCheck( cudaGetLastError() );
514 const int n = a1.capacity();
519 int nBlocks, nThreads;
523 _eqVPair<<<nBlocks, nThreads>>>(a1.cArray(), a2.cArray(),
525 cudaErrorCheck( cudaGetLastError() );
537 const int n = a1.capacity();
544 int nBlocks, nThreads;
548 _mulVVPair<<<nBlocks, nThreads>>>(a1.cArray(), a2.cArray(),
549 b1.cArray(), b2.cArray(),
551 cudaErrorCheck( cudaGetLastError() );
560 const int n = a1.capacity();
565 int nBlocks, nThreads;
569 _mulEqVPair<<<nBlocks, nThreads>>>(a1.cArray(), a2.cArray(),
571 cudaErrorCheck( cudaGetLastError() );
580 int nVecs = vecs.capacity();
582 int n = vecs[0].capacity();
585 addVV(a, vecs[0], vecs[1]);
591 for (
int i = 0; i < nVecs; i++) {
592 vecs_h[i] = vecs[i].cArray();
598 int nBlocks, nThreads;
602 _addVMany<<<nBlocks, nThreads>>>(a.cArray(),
603 vecs_d.cArray(), nVecs, n);
604 cudaErrorCheck( cudaGetLastError() );
613 int nVecs = vecs.capacity();
615 int n = vecs[0]->capacity();
618 addVV(a, *vecs[0], *vecs[1]);
624 for (
int i = 0; i < nVecs; i++) {
625 vecs_h[i] = vecs[i]->cArray();
631 int nBlocks, nThreads;
635 _addVMany<<<nBlocks, nThreads>>>(a.cArray(),
636 vecs_d.cArray(), nVecs, n);
637 cudaErrorCheck( cudaGetLastError() );
646 int nVecs = vecs.capacity();
648 int n = vecs[0].capacity();
651 mulVV(a, vecs[0], vecs[1]);
657 for (
int i = 0; i < nVecs; i++) {
658 vecs_h[i] = vecs[i].cArray();
664 int nBlocks, nThreads;
668 _mulVMany<<<nBlocks, nThreads>>>(a.cArray(), vecs_d.cArray(),
670 cudaErrorCheck( cudaGetLastError() );
679 int nVecs = vecs.capacity();
681 int n = vecs[0]->capacity();
684 mulVV(a, *vecs[0], *vecs[1]);
690 for (
int i = 0; i < nVecs; i++) {
691 vecs_h[i] = vecs[i]->cArray();
697 int nBlocks, nThreads;
701 _mulVMany<<<nBlocks, nThreads>>>(a.cArray(),
702 vecs_d.cArray(), nVecs, n);
703 cudaErrorCheck( cudaGetLastError() );
712 const int n = a.capacity();
716 int nBlocks, nThreads;
720 _sqSqAbsV<<<nBlocks, nThreads>>>(a.cArray(), b.cArray(), n);
721 cudaErrorCheck( cudaGetLastError() );
Dynamically allocatable contiguous array template.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
void setThreadsLogical(int nThreadsLogical)
Given total number of threads, set 1D execution configuration.
int nThreads()
Get the number of threads per block for execution.
double sum(Array< double > const &in)
Compute sum of array elements (real).
void mulVVPair(Array< double > &a1, Array< double > &a2, Array< double > const &b1, Array< double > const &b2, Array< double > const &c)
Vector multiplication in pairs, ax[i] = bx[i] * s[i], x=1,2.
void eqVPair(Array< double > &a1, Array< double > &a2, Array< double > const &b)
Vector assignment in pairs, ax[i] = b[i], x = 1, 2.
void sqSqAbsV(Array< double > &a, Array< fftw_complex > const &b)
Fourth power of absolute magnitude, a[i] = |b[i]|^4 (complex).
void expVc(Array< double > &a, Array< double > const &b, const double c)
Exponentiation a scaled vector, a[i] = exp(b[i]*c) (real).
void mulVV(Array< double > &a, Array< double > const &b, Array< double > const &c)
Vector-vector multiplication, a[i] = b[i] * c[i] (real).
void mulEqVPair(Array< double > &a1, Array< double > &a2, Array< double > const &b)
In-place vector multiplication in pairs, ax[i] *= b[i], x=1,2.
void addVV(Array< double > &a, Array< double > const &b, Array< double > const &c)
Vector-vector addition, a[i] = b[i] + c[i] (real).
void divEqVc(Array< fftw_complex > &a, Array< double > const &b, double c)
Vector division in-place w/ coeff., a[i] /= (b[i] * c).
void addEqVc(Array< double > &a, Array< double > const &b, const double c)
Add scaled vector in-place, a[i] += b[i]*c (real).
void mulVMany(BackendArray< cudaReal, CUT > &a, DArray< BackendArray< cudaReal, CUT > > const &vecs)
Multiply an undefined number of vectors pointwise (real).
void addVMany(BackendArray< cudaReal, CUT > &a, DArray< BackendArray< cudaReal, CUT > > const &vecs)
Add an arbitrary number of vectors pointwise (real).
Elementwise vector operations.
void addVcVcS(Array< double > &a, Array< double > const &b1, const double c1, Array< double > const &b2, const double c2, const double s)
Add scaled vectors + scalar, a[i] = b1[i]*c1 + b2[2]*c2 + s (real).
void addVcS(Array< double > &a, Array< double > const &b, const double c, const double s)
Add a scaled vector and a scalar, a[i] = b[i]*c + s (real).
void addVcVc(Array< double > &a, Array< double > const &b1, const double c1, Array< double > const &b2, const double c2)
Add two scaled vectors, a[i] = b1[i]*c1 + b2[2]*c2 (real).
void addVcVcVc(Array< double > &a, Array< double > const &b1, const double c1, Array< double > const &b2, const double c2, Array< double > const &b3, const double c3)
Add scaled vectors, a[i] = b1[i]*c1 + b2[i]*c2 + b3[i]*c3 (real).
PSCF package top-level namespace.
cufftDoubleComplex cudaComplex
Complex number type used in CPU code that uses FFTW.
cufftDoubleReal cudaReal
Real number type used in CPU code that uses FFTW.