Skip to content

Commit b2861fd

Browse files
committed
update pass by value example
1 parent ed51c95 commit b2861fd

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

pass_by_value/pass_by_value.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,23 @@ __global__ void k(A<T, N> a, T* b, const int iter) {
3535
template __global__ void k(A<int, num_elements>, int*, const int);
3636

3737

38+
template<typename T, int N>
39+
__attribute((noinline))
40+
__device__ void k_const_aggregate_callee(const A<T, N> a, T* b, const int iter) {
41+
b[0] = static_cast<T>(0);
42+
int idx = blockIdx.x % N;
43+
for (int i = 0; i < iter; ++i) {
44+
b[0] += a.a[idx];
45+
idx = (idx == N-1) ? 0 : idx + 1;
46+
}
47+
}
48+
template<typename T, int N>
49+
__global__ void k_const_aggregate_caller(const A<T, N> a, T* b, const int iter) {
50+
k_const_aggregate_callee(a, b, iter);
51+
}
52+
template __global__ void k_const_aggregate_caller(const A<int, num_elements>, int*, const int);
53+
54+
3855
#endif
3956

4057
template<typename T, int N>
@@ -48,3 +65,15 @@ void host_k_const_aggregate(const A<T, N> a, T* b, const int blockidx, const int
4865
}
4966
template void host_k_const_aggregate(const A<int, num_elements>, int*, const int, const int);
5067

68+
69+
template<typename T, int N>
70+
void host_k(A<T, N> a, T* b, const int blockidx, const int iter) {
71+
b[0] = static_cast<T>(0);
72+
int idx = blockidx;
73+
for (int i = 0; i < iter; ++i) {
74+
b[0] += a.a[idx];
75+
idx = (idx == N-1) ? 0 : idx + 1;
76+
}
77+
}
78+
template void host_k(A<int, num_elements>, int*, const int, const int);
79+

0 commit comments

Comments
 (0)