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

Function scanFirst

src/backend/opencl/kernel/scan_first.hpp:110–152  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

108
109template<typename Ti, typename To, af_op_t op>
110static void scanFirst(Param &out, const Param &in,
111 const bool inclusiveScan = true) {
112 uint threads_x = nextpow2(std::max(32u, (uint)out.info.dims[0]));
113 threads_x = std::min(threads_x, THREADS_PER_GROUP);
114 uint threads_y = THREADS_PER_GROUP / threads_x;
115
116 uint groups_x = divup(out.info.dims[0], threads_x * REPEAT);
117 uint groups_y = divup(out.info.dims[1], threads_y);
118
119 if (groups_x == 1) {
120 scanFirstLauncher<Ti, To, op>(out, out, in, true, groups_x, groups_y,
121 threads_x, inclusiveScan);
122
123 } else {
124 Param tmp = out;
125 tmp.info.dims[0] = groups_x;
126 tmp.info.strides[0] = 1;
127 for (int k = 1; k < 4; k++) {
128 tmp.info.strides[k] =
129 tmp.info.strides[k - 1] * tmp.info.dims[k - 1];
130 }
131
132 int tmp_elements = tmp.info.strides[3] * tmp.info.dims[3];
133
134 tmp.data = bufferAlloc(tmp_elements * sizeof(To));
135
136 scanFirstLauncher<Ti, To, op>(out, tmp, in, false, groups_x, groups_y,
137 threads_x, inclusiveScan);
138
139 if (op == af_notzero_t) {
140 scanFirstLauncher<To, To, af_add_t>(tmp, tmp, tmp, true, 1,
141 groups_y, threads_x, true);
142 } else {
143 scanFirstLauncher<To, To, op>(tmp, tmp, tmp, true, 1, groups_y,
144 threads_x, true);
145 }
146
147 bcastFirstLauncher<To, To, op>(out, tmp, true, groups_x, groups_y,
148 threads_x, inclusiveScan);
149
150 bufferFree(tmp.data);
151 }
152}
153
154} // namespace kernel
155} // namespace opencl

Callers

nothing calls this directly

Calls 5

nextpow2Function · 0.85
bufferAllocFunction · 0.85
bufferFreeFunction · 0.85
maxFunction · 0.50
minFunction · 0.50

Tested by

no test coverage detected