| 126 | |
| 127 | template<typename Tk_, typename Tv_> |
| 128 | void sortByKeyBatched(Param pKey, Param pVal, const int dim, bool isAscending) { |
| 129 | typedef type_t<Tk_> Tk; |
| 130 | typedef type_t<Tv_> Tv; |
| 131 | |
| 132 | af::dim4 inDims; |
| 133 | for (int i = 0; i < 4; i++) inDims[i] = pKey.info.dims[i]; |
| 134 | |
| 135 | // Sort dimension |
| 136 | // tileDims * seqDims = inDims |
| 137 | af::dim4 tileDims(1); |
| 138 | af::dim4 seqDims = inDims; |
| 139 | tileDims[dim] = inDims[dim]; |
| 140 | seqDims[dim] = 1; |
| 141 | |
| 142 | // Create/call iota |
| 143 | Array<unsigned> pSeq = iota<unsigned>(seqDims, tileDims); |
| 144 | |
| 145 | int elements = inDims.elements(); |
| 146 | |
| 147 | // Flat - Not required since inplace and both are continuous |
| 148 | // val.modDims(inDims.elements()); |
| 149 | // key.modDims(inDims.elements()); |
| 150 | |
| 151 | // Sort indices |
| 152 | // sort_by_key<T, Tv, isAscending>(*resVal, *resKey, val, key, 0); |
| 153 | // kernel::sort0_by_key<T, Tv, isAscending>(pVal, pKey); |
| 154 | compute::command_queue c_queue(getQueue()()); |
| 155 | compute::context c_context(getContext()()); |
| 156 | |
| 157 | // Create buffer iterators for seq |
| 158 | compute::buffer pSeq_buf((*pSeq.get())()); |
| 159 | compute::buffer_iterator<unsigned> seq0 = |
| 160 | compute::make_buffer_iterator<unsigned>(pSeq_buf, 0); |
| 161 | compute::buffer_iterator<unsigned> seqN = |
| 162 | compute::make_buffer_iterator<unsigned>(pSeq_buf, elements); |
| 163 | // Create buffer iterators for key and val |
| 164 | compute::buffer pKey_buf((*pKey.data)()); |
| 165 | compute::buffer pVal_buf((*pVal.data)()); |
| 166 | compute::buffer_iterator<Tk> key0 = |
| 167 | compute::make_buffer_iterator<Tk>(pKey_buf, 0); |
| 168 | compute::buffer_iterator<Tk> keyN = |
| 169 | compute::make_buffer_iterator<Tk>(pKey_buf, elements); |
| 170 | compute::buffer_iterator<Tv> val0 = |
| 171 | compute::make_buffer_iterator<Tv>(pVal_buf, 0); |
| 172 | compute::buffer_iterator<Tv> valN = |
| 173 | compute::make_buffer_iterator<Tv>(pVal_buf, elements); |
| 174 | |
| 175 | // Sort By Key for descending is stable in the reverse |
| 176 | // (greater) order. Sorting in ascending with negated values |
| 177 | // will give the right result |
| 178 | if (!isAscending) |
| 179 | compute::transform(key0, keyN, key0, flipFunction<Tk>(), c_queue); |
| 180 | |
| 181 | // Create a copy of the pKey buffer |
| 182 | cl::Buffer* cKey = bufferAlloc(elements * sizeof(Tk)); |
| 183 | compute::buffer cKey_buf((*cKey)()); |
| 184 | compute::buffer_iterator<Tk> cKey0 = |
| 185 | compute::make_buffer_iterator<Tk>(cKey_buf, 0); |
nothing calls this directly
no test coverage detected