SIRIUS 7.5.0
Electronic structure library and applications
mul_veff_with_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 mul_veff_with_phase_factors.cu
21 *
22 * \brief CUDA kernel to multiply effective potential by the phase factors.
23 */
24
27
28using namespace sirius;
29using namespace sirius::acc;
30
31__global__ void mul_veff_with_phase_factors_gpu_kernel(int num_gvec_loc__,
32 acc_complex_double_t const* veff__,
33 int const* gvx__,
34 int const* gvy__,
35 int const* gvz__,
36 int num_atoms__,
37 double const* atom_pos__,
38 acc_complex_double_t* veff_a__,
39 int ld__)
40{
41 int ia = blockIdx.y;
42 double ax = atom_pos__[array2D_offset(ia, 0, num_atoms__)];
43 double ay = atom_pos__[array2D_offset(ia, 1, num_atoms__)];
44 double az = atom_pos__[array2D_offset(ia, 2, num_atoms__)];
45
46 int igloc = blockDim.x * blockIdx.x + threadIdx.x;
47 if (igloc < num_gvec_loc__) {
48 int gvx = gvx__[igloc];
49 int gvy = gvy__[igloc];
50 int gvz = gvz__[igloc];
51
52 double p = twopi * (ax * gvx + ay * gvy + az * gvz);
53
54 veff_a__[array2D_offset(igloc, ia, ld__)] = accCmul(veff__[igloc], make_accDoubleComplex(cos(p), sin(p)));
55 }
56}
57
58extern "C" void mul_veff_with_phase_factors_gpu(int num_atoms__,
59 int num_gvec_loc__,
60 acc_complex_double_t const* veff__,
61 int const* gvx__,
62 int const* gvy__,
63 int const* gvz__,
64 double const* atom_pos__,
65 double* veff_a__,
66 int ld__,
67 int stream_id__)
68{
69 dim3 grid_t(64);
70 dim3 grid_b(num_blocks(num_gvec_loc__, grid_t.x), num_atoms__);
71
72 acc_stream_t stream = (acc_stream_t)acc::stream(stream_id(stream_id__));
73
74 accLaunchKernel((mul_veff_with_phase_factors_gpu_kernel), dim3(grid_b), dim3(grid_t), 0, stream,
75 num_gvec_loc__,
76 veff__,
77 gvx__,
78 gvy__,
79 gvz__,
80 num_atoms__,
81 atom_pos__,
82 (acc_complex_double_t*)veff_a__,
83 ld__
84 );
85}
Common device functions used by GPU kernels.
Uniform interface to the runtime API of CUDA and ROCm.
Helper class to wrap stream id (integer number).
Definition: acc.hpp:132
Namespace for accelerator-related functions.
Definition: acc.cpp:30
acc_stream_t stream(stream_id sid__)
Return a single device stream.
Definition: acc.hpp:202
Namespace of the SIRIUS library.
Definition: sirius.f90:5