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

Function sortByKeyBatched

src/backend/cuda/kernel/sort_by_key.hpp:46–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44
45template<typename Tk, typename Tv>
46void sortByKeyBatched(Param<Tk> pKey, Param<Tv> pVal, const int dim,
47 bool isAscending) {
48 af::dim4 inDims;
49 for (int i = 0; i < 4; i++) inDims[i] = pKey.dims[i];
50
51 const dim_t elements = inDims.elements();
52
53 // Sort dimension
54 // tileDims * seqDims = inDims
55 af::dim4 tileDims(1);
56 af::dim4 seqDims = inDims;
57 tileDims[dim] = inDims[dim];
58 seqDims[dim] = 1;
59
60 // Create/call iota
61 Array<uint> Seq = iota<uint>(seqDims, tileDims);
62
63 Tk *Key = pKey.ptr;
64 auto cKey = memAlloc<Tk>(elements);
65 CUDA_CHECK(cudaMemcpyAsync(cKey.get(), Key, elements * sizeof(Tk),
66 cudaMemcpyDeviceToDevice, getActiveStream()));
67
68 Tv *Val = pVal.ptr;
69 thrustSortByKey(Key, Val, elements, isAscending);
70 thrustSortByKey(cKey.get(), Seq.get(), elements, isAscending);
71
72 auto cSeq = memAlloc<uint>(elements);
73 CUDA_CHECK(cudaMemcpyAsync(cSeq.get(), Seq.get(), elements * sizeof(uint),
74 cudaMemcpyDeviceToDevice, getActiveStream()));
75
76 // This always needs to be ascending
77 thrustSortByKey(Seq.get(), Val, elements, true);
78 thrustSortByKey(cSeq.get(), Key, elements, true);
79
80 // No need of doing moddims here because the original Array<T>
81 // dimensions have not been changed
82 // val.modDims(inDims);
83}
84
85template<typename Tk, typename Tv>
86void sort0ByKey(Param<Tk> okey, Param<Tv> oval, bool isAscending) {

Callers

nothing calls this directly

Calls 4

getActiveStreamFunction · 0.85
thrustSortByKeyFunction · 0.85
elementsMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected