MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / final_boundary_reduce

Function final_boundary_reduce

src/backend/cuda/kernel/reduce_by_key.hpp:34–57  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32// Reduces keys across block boundaries
33template<typename Tk, typename To, af_op_t op>
34__global__ void final_boundary_reduce(int *reduced_block_sizes, Param<Tk> keys,
35 Param<To> vals, const int n) {
36 const int tid = blockIdx.x * blockDim.x + threadIdx.x;
37 common::Binary<compute_t<To>, op> reduce;
38
39 if (tid == ((blockIdx.x + 1) * blockDim.x) - 1 &&
40 blockIdx.x < gridDim.x - 1) {
41 Tk k0 = keys.ptr[tid];
42 Tk k1 = keys.ptr[tid + 1];
43 if (k0 == k1) {
44 compute_t<To> v0 = compute_t<To>(vals.ptr[tid]);
45 compute_t<To> v1 = compute_t<To>(vals.ptr[tid + 1]);
46 vals.ptr[tid + 1] = reduce(v0, v1);
47 reduced_block_sizes[blockIdx.x] = blockDim.x - 1;
48 } else {
49 reduced_block_sizes[blockIdx.x] = blockDim.x;
50 }
51 }
52
53 // if last block, set block size to difference between n and block boundary
54 if (threadIdx.x == 0 && blockIdx.x == gridDim.x - 1) {
55 reduced_block_sizes[blockIdx.x] = n - (blockIdx.x * blockDim.x);
56 }
57}
58
59// Tests if data needs further reduction, including across block boundaries
60template<typename Tk>

Callers

nothing calls this directly

Calls 1

reduceFunction · 0.70

Tested by

no test coverage detected