Skip to main content
. 2024 Feb 21;24(5):1399. doi: 10.3390/s24051399
Code 1 Sequential Addressing Reduction
Input: tid, e, b  → indexes of the threads and blocks
ncl → number of classes
1: int tid=threadIdx.x;
2: __shared__ float S[512];
3: int e=blockIdx.x  blockDim.x+threadIdx.x;
4: int b=blockIdx.y;
5: if (tid < n_estimators)
6:  S[tid]=Z[e  ncl+b];
7: __syncthreads();
8: for (s=blockDim.x/2;s>0;s=1){
9:    if (tid < s)
10:  S[tid]+=S[tid+s];
11:  __syncthreads();
12:}
Output: S