SIRIUS 7.5.0
Electronic structure library and applications
generate_phase_factors.cu
Go to the documentation of this file.
1// Copyright (c) 2013-2018 Anton Kozhevnikov, Thomas Schulthess
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without modification, are permitted provided that
5// the following conditions are met:
6//
7// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
8// following disclaimer.
9// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
10// and the following disclaimer in the documentation and/or other materials provided with the distribution.
11//
12// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
13// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
14// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
15// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
16// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
17// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
18// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
19
20/** \file generate_phase_factors.cu
21 *
22 * \brief CUDA kernel to generate plane-wave atomic phase factors.
23 */
24
27
28using namespace sirius;
29using namespace sirius::acc;
30
31__global__ void generate_phase_factors_gpu_kernel
32(
33 int num_gvec_loc,
34 int num_atoms,
35 double const* atom_pos,
36 int const* gvec,
37 acc_complex_double_t* phase_factors
38)
39{
40 int ia = blockIdx.y;
41 int igloc = blockIdx.x * blockDim.x + threadIdx.x;
42
43 if (igloc < num_gvec_loc) {
44 int gvx = gvec[array2D_offset(igloc, 0, num_gvec_loc)];
45 int gvy = gvec[array2D_offset(igloc, 1, num_gvec_loc)];
46 int gvz = gvec[array2D_offset(igloc, 2, num_gvec_loc)];
47
48 double ax = atom_pos[array2D_offset(ia, 0, num_atoms)];
49 double ay = atom_pos[array2D_offset(ia, 1, num_atoms)];
50 double az = atom_pos[array2D_offset(ia, 2, num_atoms)];
51
52 double p = twopi * (ax * gvx + ay * gvy + az * gvz);
53
54 double sinp = sin(p);
55 double cosp = cos(p);
56
57 phase_factors[array2D_offset(igloc, ia, num_gvec_loc)] = make_accDoubleComplex(cosp, sinp);
58 }
59}
60
61
62extern "C" void generate_phase_factors_gpu(int num_gvec_loc__,
63 int num_atoms__,
64 int const* gvec__,
65 double const* atom_pos__,
66 acc_complex_double_t* phase_factors__)
67
68{
69 dim3 grid_t(32);
70 dim3 grid_b(num_blocks(num_gvec_loc__, grid_t.x), num_atoms__);
71
72 accLaunchKernel((generate_phase_factors_gpu_kernel), dim3(grid_b), dim3(grid_t), 0, 0,
73 num_gvec_loc__,
74 num_atoms__,
75 atom_pos__,
76 gvec__,
77 phase_factors__
78 );
79}
Common device functions used by GPU kernels.
Uniform interface to the runtime API of CUDA and ROCm.
Namespace for accelerator-related functions.
Definition: acc.cpp:30
Namespace of the SIRIUS library.
Definition: sirius.f90:5