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

Function sort0ByKeyIterative

src/backend/oneapi/kernel/sort_by_key_impl.hpp:41–84  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39
40template<typename Tk, typename Tv>
41void sort0ByKeyIterative(Param<Tk> pKey, Param<Tv> pVal, bool isAscending) {
42 auto dpl_policy = ::oneapi::dpl::execution::make_device_policy(getQueue());
43
44 for (int w = 0; w < pKey.info.dims[3]; w++) {
45 int pKeyW = w * pKey.info.strides[3];
46 int pValW = w * pVal.info.strides[3];
47 for (int z = 0; z < pKey.info.dims[2]; z++) {
48 int pKeyWZ = pKeyW + z * pKey.info.strides[2];
49 int pValWZ = pValW + z * pVal.info.strides[2];
50 for (int y = 0; y < pKey.info.dims[1]; y++) {
51 int pKeyOffset = pKeyWZ + y * pKey.info.strides[1];
52 int pValOffset = pValWZ + y * pVal.info.strides[1];
53
54 auto key_begin =
55 ::oneapi::dpl::begin(
56 pKey.data->template reinterpret<compute_t<Tk>>()) +
57 pKeyOffset;
58 auto key_end = key_begin + pKey.info.dims[0];
59 auto val_begin = ::oneapi::dpl::begin(*pVal.data) + pValOffset;
60 auto val_end = val_begin + pVal.info.dims[0];
61
62 auto zipped_begin =
63 ::oneapi::dpl::make_zip_iterator(key_begin, val_begin);
64 auto zipped_end =
65 ::oneapi::dpl::make_zip_iterator(key_end, val_end);
66
67 // sort by key
68 if (isAscending) {
69 std::sort(dpl_policy, zipped_begin, zipped_end,
70 [](auto lhs, auto rhs) {
71 return std::get<0>(lhs) < std::get<0>(rhs);
72 });
73 } else {
74 std::sort(dpl_policy, zipped_begin, zipped_end,
75 [](auto lhs, auto rhs) {
76 return std::get<0>(lhs) > std::get<0>(rhs);
77 });
78 }
79 }
80 }
81 }
82
83 ONEAPI_DEBUG_FINISH(getQueue());
84}
85
86template<typename Tk, typename Tv>
87void sortByKeyBatched(Param<Tk> pKey, Param<Tv> pVal, const int dim,

Callers

nothing calls this directly

Calls 3

beginFunction · 0.85
getQueueFunction · 0.50
sortFunction · 0.50

Tested by

no test coverage detected