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

Function sortBatched

src/backend/opencl/kernel/sort.hpp:66–119  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

64
65template<typename T>
66void sortBatched(Param pVal, int dim, bool isAscending) {
67 af::dim4 inDims;
68 for (int i = 0; i < 4; i++) inDims[i] = pVal.info.dims[i];
69
70 // Sort dimension
71 // tileDims * seqDims = inDims
72 af::dim4 tileDims(1);
73 af::dim4 seqDims = inDims;
74 tileDims[dim] = inDims[dim];
75 seqDims[dim] = 1;
76
77 // Create/call iota
78 // Array<uint> pKey = createEmptyArray<uint>(inDims);
79 Array<uint> pKey = iota<uint>(seqDims, tileDims);
80
81 pKey.setDataDims(inDims.elements());
82
83 // Flat
84 pVal.info.dims[0] = inDims.elements();
85 pVal.info.strides[0] = 1;
86 for (int i = 1; i < 4; i++) {
87 pVal.info.dims[i] = 1;
88 pVal.info.strides[i] = pVal.info.strides[i - 1] * pVal.info.dims[i - 1];
89 }
90
91 // Sort indices
92 // sort_by_key<T, uint, isAscending>(*resVal, *resKey, val, key, 0);
93 // kernel::sort0_by_key<T, uint, isAscending>(pVal, pKey);
94 compute::command_queue c_queue(getQueue()());
95
96 compute::buffer pKey_buf((*pKey.get())());
97 compute::buffer pVal_buf((*pVal.data)());
98
99 compute::buffer_iterator<type_t<T>> val0 =
100 compute::make_buffer_iterator<type_t<T>>(pVal_buf, 0);
101 compute::buffer_iterator<type_t<T>> valN =
102 compute::make_buffer_iterator<type_t<T>>(pVal_buf, +pVal.info.dims[0]);
103 compute::buffer_iterator<uint> key0 =
104 compute::make_buffer_iterator<uint>(pKey_buf, 0);
105 compute::buffer_iterator<uint> keyN =
106 compute::make_buffer_iterator<uint>(pKey_buf, pKey.dims()[0]);
107 if (isAscending) {
108 compute::sort_by_key(val0, valN, key0, c_queue);
109 } else {
110 compute::sort_by_key(val0, valN, key0, compute::greater<type_t<T>>(),
111 c_queue);
112 }
113
114 // Needs to be ascending (true) in order to maintain the indices properly
115 // kernel::sort0_by_key<uint, T, true>(pKey, pVal);
116 compute::sort_by_key(key0, keyN, val0, c_queue);
117
118 CL_DEBUG_FINISH(getQueue());
119}
120
121template<typename T>
122void sort0(Param val, bool isAscending) {

Callers

nothing calls this directly

Calls 6

getQueueFunction · 0.50
sort_by_keyFunction · 0.50
setDataDimsMethod · 0.45
elementsMethod · 0.45
getMethod · 0.45
dimsMethod · 0.45

Tested by

no test coverage detected