9#include <rmm/cuda_stream_pool.hpp>
10#include <rmm/device_uvector.hpp>
11#include <rmm/mr/device/pool_memory_resource.hpp>
12#include <thrust/reduce.h>
20 template <
typename ctype,
typename NT,
typename KERNEL,
typename... T>
22 const ctype *y_quadrature_p,
const ctype *y_quadrature_w,
23 const ctype *z_quadrature_p,
const ctype *z_quadrature_w,
const ctype qx_min,
24 const ctype qy_min,
const ctype qz_min,
const ctype qx_extent,
25 const ctype qy_extent,
const ctype qz_extent,
const ctype k, T... t)
27 uint len_x = gridDim.x * blockDim.x;
28 uint len_y = gridDim.y * blockDim.y;
29 uint idx_x = (blockIdx.x * blockDim.x) + threadIdx.x;
30 uint idx_y = (blockIdx.y * blockDim.y) + threadIdx.y;
31 uint idx_z = (blockIdx.z * blockDim.z) + threadIdx.z;
32 uint idx = idx_z * len_x * len_y + idx_y * len_x + idx_x;
35 constexpr ctype int_element =
powr<-d>(2 * (ctype)M_PI);
37 const ctype qx = qx_min + qx_extent * x_quadrature_p[idx_x];
38 const ctype qy = qy_min + qy_extent * y_quadrature_p[idx_y];
39 const ctype qz = qz_min + qz_extent * z_quadrature_p[idx_z];
41 qz_extent * z_quadrature_w[idx_z] * qy_extent * y_quadrature_w[idx_y] * qx_extent * x_quadrature_w[idx_x];
43 NT res = KERNEL::kernel(qx, qy, qz, k, t...);
45 dest[idx] = int_element * res * weight;
59 json.get_uint(
"/integration/cudathreadsperblock"),
60 json.get_double(
"/discretization/integration/qx_min", -M_PI),
61 json.get_double(
"/discretization/integration/qy_min", -M_PI),
62 json.get_double(
"/discretization/integration/qz_min", -M_PI),
63 json.get_double(
"/discretization/integration/qx_max", M_PI),
64 json.get_double(
"/discretization/integration/qy_max", M_PI),
65 json.get_double(
"/discretization/integration/qz_max", M_PI))
72 const ctype qy_max = M_PI,
const ctype qz_max = M_PI)
83 block_sizes = {max_block_size, max_block_size, max_block_size};
86 uint optimize_dim = 2;
92 optimize_dim = (optimize_dim + 2) % 3;
174 template <
typename... T> NT
get(
const ctype k,
const T &...t)
const
182 return KERNEL::constant(k, t...) + thrust::reduce(thrust::cuda::par.on(cuda_stream.value()), device_data.begin(),
183 device_data.end(), NT(0.), thrust::plus<NT>());
196 template <
typename... T> std::future<NT>
request(
const ctype k,
const T &...t)
const
199 std::shared_ptr<rmm::device_uvector<NT>> device_data =
205 const NT constant = KERNEL::constant(k, t...);
207 return std::async(std::launch::deferred, [=,
this]() {
208 return constant + thrust::reduce(thrust::cuda::par.on(cuda_stream.value()), (*device_data).begin(),
209 (*device_data).end(), NT(0.), thrust::plus<NT>());
236 using PoolMR = rmm::mr::pool_memory_resource<rmm::mr::device_memory_resource>;
252 template <
typename NT,
typename KERNEL>
class Integrator3DCartesianGPU :
public Integrator3DCartesianTBB<NT, KERNEL>
260 const ctype qy_max = M_PI,
const ctype qz_max = M_PI)
261 : Integrator3DCartesianTBB<NT, KERNEL>(quadrature_provider,
grid_sizes, x_extent, max_block_size,
qx_min,
267 const ctype x_extent,
const JSONValue &json)
268 : Integrator3DCartesianTBB<NT, KERNEL>(quadrature_provider,
grid_sizes, x_extent, json)
Definition integrator_3D_cartesian_gpu.hh:49
const ctype * ptr_z_quadrature_p
Definition integrator_3D_cartesian_gpu.hh:223
ctype qx_extent
Definition integrator_3D_cartesian_gpu.hh:228
void set_qz_min(const ctype qz_min)
Set the minimum value of the qz integration range.
Definition integrator_3D_cartesian_gpu.hh:153
const ctype * ptr_y_quadrature_w
Definition integrator_3D_cartesian_gpu.hh:222
const ctype * ptr_z_quadrature_w
Definition integrator_3D_cartesian_gpu.hh:224
ctype qx_min
Definition integrator_3D_cartesian_gpu.hh:226
void set_qx_min(const ctype qx_min)
Set the minimum value of the qx integration range.
Definition integrator_3D_cartesian_gpu.hh:135
Integrator3DCartesianGPU(QuadratureProvider &quadrature_provider, const std::array< uint, 3 > grid_sizes, const ctype x_extent, const JSONValue &json)
Definition integrator_3D_cartesian_gpu.hh:56
typename get_type::ctype< NT > ctype
Numerical type to be used for integration tasks e.g. the argument or possible jacobians.
Definition integrator_3D_cartesian_gpu.hh:54
Integrator3DCartesianGPU(QuadratureProvider &quadrature_provider, std::array< uint, 3 > grid_sizes, const ctype x_extent, const uint max_block_size=256, const ctype qx_min=-M_PI, const ctype qy_min=-M_PI, const ctype qz_min=-M_PI, const ctype qx_max=M_PI, const ctype qy_max=M_PI, const ctype qz_max=M_PI)
Definition integrator_3D_cartesian_gpu.hh:69
dim3 threads_per_block
Definition integrator_3D_cartesian_gpu.hh:234
NT get(const ctype k, const T &...t) const
Definition integrator_3D_cartesian_gpu.hh:174
void set_qy_min(const ctype qy_min)
Set the minimum value of the qy integration range.
Definition integrator_3D_cartesian_gpu.hh:144
const ctype * ptr_x_quadrature_w
Definition integrator_3D_cartesian_gpu.hh:220
ctype qz_min
Definition integrator_3D_cartesian_gpu.hh:230
void set_qx_max(const ctype qx_max)
Set the maximum value of the qx integration range.
Definition integrator_3D_cartesian_gpu.hh:162
const uint device_data_size
Definition integrator_3D_cartesian_gpu.hh:217
ctype qy_min
Definition integrator_3D_cartesian_gpu.hh:227
PoolMR pool
Definition integrator_3D_cartesian_gpu.hh:237
void set_qz_max(const ctype qz_max)
Set the maximum value of the qz integration range.
Definition integrator_3D_cartesian_gpu.hh:172
rmm::mr::pool_memory_resource< rmm::mr::device_memory_resource > PoolMR
Definition integrator_3D_cartesian_gpu.hh:236
const rmm::cuda_stream_pool cuda_stream_pool
Definition integrator_3D_cartesian_gpu.hh:238
const ctype * ptr_x_quadrature_p
Definition integrator_3D_cartesian_gpu.hh:219
ctype qz_extent
Definition integrator_3D_cartesian_gpu.hh:231
void set_qy_max(const ctype qy_max)
Set the maximum value of the qy integration range.
Definition integrator_3D_cartesian_gpu.hh:167
const std::array< uint, 3 > grid_sizes
Definition integrator_3D_cartesian_gpu.hh:214
std::future< NT > request(const ctype k, const T &...t) const
Request a future for the integral of the kernel.
Definition integrator_3D_cartesian_gpu.hh:196
const ctype * ptr_y_quadrature_p
Definition integrator_3D_cartesian_gpu.hh:221
Integrator3DCartesianGPU(const Integrator3DCartesianGPU &other)
Definition integrator_3D_cartesian_gpu.hh:113
std::array< uint, 3 > block_sizes
Definition integrator_3D_cartesian_gpu.hh:215
ctype qy_extent
Definition integrator_3D_cartesian_gpu.hh:229
dim3 num_blocks
Definition integrator_3D_cartesian_gpu.hh:233
A wrapper around the boost json value class.
Definition json.hh:19
A class that provides quadrature points and weights, in host and device memory. The quadrature points...
Definition quadrature_provider.hh:139
const NT * get_device_weights(const size_t order, const int device=0, const QuadratureType type=QuadratureType::legendre)
Get the device-side quadrature weights for a quadrature of size quadrature_size.
Definition quadrature_provider.hh:211
const NT * get_device_points(const size_t order, const int device=0, const QuadratureType type=QuadratureType::legendre)
Get the device-side quadrature points for a quadrature of size quadrature_size.
Definition quadrature_provider.hh:198
typename internal::_ctype< CT >::value ctype
Definition types.hh:106
Definition complex_math.hh:14
constexpr __forceinline__ __host__ __device__ NumberType powr(const NumberType x)
A compile-time evaluatable power function for whole number exponents.
Definition math.hh:45
__global__ void gridreduce_3d_cartesian(NT *dest, const ctype *x_quadrature_p, const ctype *x_quadrature_w, const ctype *y_quadrature_p, const ctype *y_quadrature_w, const ctype *z_quadrature_p, const ctype *z_quadrature_w, const ctype qx_min, const ctype qy_min, const ctype qz_min, const ctype qx_extent, const ctype qy_extent, const ctype qz_extent, const ctype k, T... t)
Definition integrator_3D_cartesian_gpu.hh:21
void check_cuda(std::string prefix="")
Check if a CUDA error occurred and print an error message if it did.
unsigned int uint
Definition utils.hh:22