PeriDyno 1.0.0
Loading...
Searching...
No Matches
CalculateNorm.cu
Go to the documentation of this file.
1#include "CalculateNorm.h"
2
3namespace dyno
4{
5 IMPLEMENT_TCLASS(CalculateNorm, TDataType)
6
7 template <typename Real, typename Coord>
8 __global__ void CN_CalculateNorm(
9 DArray<Real> norm,
10 DArray<Coord> vec)
11 {
12 int tId = threadIdx.x + (blockIdx.x * blockDim.x);
13 if (tId >= vec.size()) return;
14
15 norm[tId] = vec[tId].norm();
16 }
17
18 template<typename TDataType>
19 void CalculateNorm<TDataType>::compute()
20 {
21 auto& inData = this->inVec()->getData();
22
23 int num = inData.size();
24
25 if (this->outNorm()->isEmpty())
26 {
27 this->outNorm()->allocate();
28 }
29
30 auto& outData = this->outNorm()->getData();
31 if (outData.size() != num)
32 {
33 outData.resize(num);
34 }
35
36 cuExecute(num,
37 CN_CalculateNorm,
38 outData,
39 inData);
40 }
41
42 DEFINE_CLASS(CalculateNorm);
43}