| 108 | |
| 109 | template<typename Ti, typename To, af_op_t op> |
| 110 | static void scanDim(Param out, const Param in, const int dim, |
| 111 | const bool inclusiveScan = true) { |
| 112 | uint threads_y = std::min(THREADS_Y, nextpow2(out.info.dims[dim])); |
| 113 | uint threads_x = THREADS_X; |
| 114 | |
| 115 | uint groups_all[] = {divup((uint)out.info.dims[0], threads_x), |
| 116 | (uint)out.info.dims[1], (uint)out.info.dims[2], |
| 117 | (uint)out.info.dims[3]}; |
| 118 | |
| 119 | groups_all[dim] = divup(out.info.dims[dim], threads_y * REPEAT); |
| 120 | |
| 121 | if (groups_all[dim] == 1) { |
| 122 | scanDimLauncher<Ti, To, op>(out, out, in, dim, true, threads_y, |
| 123 | groups_all, inclusiveScan); |
| 124 | } else { |
| 125 | Param tmp = out; |
| 126 | |
| 127 | tmp.info.dims[dim] = groups_all[dim]; |
| 128 | tmp.info.strides[0] = 1; |
| 129 | for (int k = 1; k < 4; k++) { |
| 130 | tmp.info.strides[k] = |
| 131 | tmp.info.strides[k - 1] * tmp.info.dims[k - 1]; |
| 132 | } |
| 133 | |
| 134 | int tmp_elements = tmp.info.strides[3] * tmp.info.dims[3]; |
| 135 | // FIXME: Do I need to free this ? |
| 136 | tmp.data = bufferAlloc(tmp_elements * sizeof(To)); |
| 137 | |
| 138 | scanDimLauncher<Ti, To, op>(out, tmp, in, dim, false, threads_y, |
| 139 | groups_all, inclusiveScan); |
| 140 | |
| 141 | int gdim = groups_all[dim]; |
| 142 | groups_all[dim] = 1; |
| 143 | |
| 144 | if (op == af_notzero_t) { |
| 145 | scanDimLauncher<To, To, af_add_t>(tmp, tmp, tmp, dim, true, |
| 146 | threads_y, groups_all, true); |
| 147 | } else { |
| 148 | scanDimLauncher<To, To, op>(tmp, tmp, tmp, dim, true, threads_y, |
| 149 | groups_all, true); |
| 150 | } |
| 151 | |
| 152 | groups_all[dim] = gdim; |
| 153 | bcastDimLauncher<To, To, op>(out, tmp, dim, true, threads_y, groups_all, |
| 154 | inclusiveScan); |
| 155 | bufferFree(tmp.data); |
| 156 | } |
| 157 | } |
| 158 | } // namespace kernel |
| 159 | } // namespace opencl |
| 160 | } // namespace arrayfire |
nothing calls this directly
no test coverage detected