milupHPC documentation
  • src
  • processing
kernels.cu
Go to the documentation of this file.
1#include "../../include/processing/kernels.cuh"
2#include "../../include/cuda_utils/cuda_launcher.cuh"
3
4namespace Processing {
5
6 namespace Kernel {
7
8 __global__ void particlesWithinRadii(Particles *particles, int *particlesWithin, real deltaRadial, int n) {
9
10 int bodyIndex = threadIdx.x + blockIdx.x * blockDim.x;
11 int stride = blockDim.x * gridDim.x;
12 int offset = 0;
13
14 real r;
15 int index;
16
17 while ((bodyIndex + offset) < n) {
18
19#if DIM == 1
20 r = cuda::math::sqrt(particles->x[bodyIndex + offset] * particles->x[bodyIndex + offset]);
21#elif DIM == 2
22 r = cuda::math::sqrt(particles->x[bodyIndex + offset] * particles->x[bodyIndex + offset] +
23 particles->y[bodyIndex + offset] * particles->y[bodyIndex + offset]);
24#else
25 r = cuda::math::sqrt(particles->x[bodyIndex + offset] * particles->x[bodyIndex + offset] +
26 particles->y[bodyIndex + offset] * particles->y[bodyIndex + offset] +
27 particles->z[bodyIndex + offset] * particles->z[bodyIndex + offset]);
28#endif
29
30 index = (int) (r / deltaRadial);
31 atomicAdd(&particlesWithin[index], 1);
32
33 offset += stride;
34 }
35
36 }
37
38 template<typename T>
39 __global__ void
40 cartesianToRadial(Particles *particles, int *particlesWithin, T *input, T *output, real deltaRadial, int n) {
41
42 int bodyIndex = threadIdx.x + blockIdx.x * blockDim.x;
43 int stride = blockDim.x * gridDim.x;
44 int offset = 0;
45
46 real r;
47 int index;
48
49 while ((bodyIndex + offset) < n) {
50
51#if DIM == 1
52 r = cuda::math::sqrt(particles->x[bodyIndex + offset] * particles->x[bodyIndex + offset]);
53#elif DIM == 2
54 r = cuda::math::sqrt(particles->x[bodyIndex + offset] * particles->x[bodyIndex + offset] +
55 particles->y[bodyIndex + offset] * particles->y[bodyIndex + offset]);
56#else
57 r = cuda::math::sqrt(particles->x[bodyIndex + offset] * particles->x[bodyIndex + offset] +
58 particles->y[bodyIndex + offset] * particles->y[bodyIndex + offset] +
59 particles->z[bodyIndex + offset] * particles->z[bodyIndex + offset]);
60#endif
61
62 index = (int) (r / deltaRadial);
63
64 if (particlesWithin[index] > 0) {
65 output[index] += input[bodyIndex + offset] / particlesWithin[index];
66 }
67
68 offset += stride;
69 }
70
71 }
72
73
74 namespace Launch {
75 void particlesWithinRadii(Particles *particles, int *particlesWithin, real deltaRadial, int n) {
76 ExecutionPolicy executionPolicy;
77 cuda::launch(false, executionPolicy, ::Processing::Kernel::particlesWithinRadii, particles, particlesWithin, deltaRadial, n);
78 }
79
80 template<typename T>
81 void cartesianToRadial(Particles *particles, int *particlesWithin, T *input, T *output, real deltaRadial, int n) {
82 ExecutionPolicy executionPolicy;
83 cuda::launch(false, executionPolicy, ::Processing::Kernel::cartesianToRadial<T>, particles, particlesWithin, input, output, deltaRadial, n);
84 }
85 template void cartesianToRadial<real>(Particles *particles, int *particlesWithin, real *input, real *output, real deltaRadial, int n);
86 }
87
88 }
89}
ExecutionPolicy
Execution policy/instruction for CUDA kernel execution.
Definition: cuda_launcher.cuh:33
Particles
Particle(s) class based on SoA (Structur of Arrays).
Definition: particles.cuh:50
Particles::x
real * x
(pointer to) x position (array)
Definition: particles.cuh:62
Particles::y
real * y
(pointer to) y position (array)
Definition: particles.cuh:70
Particles::z
real * z
(pointer to) z position (array)
Definition: particles.cuh:78
Kernel
Definition: device_rhs.cuh:7
Processing::Kernel::Launch::cartesianToRadial
void cartesianToRadial(Particles *particles, int *particlesWithin, T *input, T *output, real deltaRadial, int n)
Wrapper for Processing::Kernel::cartesianToRadial().
Definition: kernels.cu:81
Processing::Kernel::Launch::cartesianToRadial< real >
template void cartesianToRadial< real >(Particles *particles, int *particlesWithin, real *input, real *output, real deltaRadial, int n)
Processing::Kernel::Launch::particlesWithinRadii
void particlesWithinRadii(Particles *particles, int *particlesWithin, real deltaRadial, int n)
Wrapper for Processing::Kernel::particlesWithinRadii().
Definition: kernels.cu:75
Processing::Kernel::cartesianToRadial
__global__ void cartesianToRadial(Particles *particles, int *particlesWithin, T *input, T *output, real deltaRadial, int n)
Convert cartesian to radial.
Definition: kernels.cu:40
Processing::Kernel::particlesWithinRadii
__global__ void particlesWithinRadii(Particles *particles, int *particlesWithin, real deltaRadial, int n)
Particles within radius/radii.
Definition: kernels.cu:8
Processing
Definition: kernels.cuh:19
cuda::math::sqrt
__device__ real sqrt(real a)
Square root of a floating point value.
Definition: cuda_utilities.cu:456
cuda::launch
real launch(bool timeKernel, const ExecutionPolicy &policy, void(*f)(Arguments...), Arguments... args)
CUDA execution wrapper function.
Definition: cuda_launcher.cuh:114
real
double real
Definition: parameter.h:15

milupHPC - src/processing/kernels.cu Source File
Generated on Wed Aug 31 2022 12:16:53 by Doxygen 1.9.3