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

Function where

src/backend/opencl/kernel/where.hpp:65–133  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63
64template<typename T>
65static void where(Param &out, Param &in) {
66 uint threads_x = nextpow2(std::max(32u, (uint)in.info.dims[0]));
67 threads_x = std::min(threads_x, THREADS_PER_GROUP);
68 uint threads_y = THREADS_PER_GROUP / threads_x;
69
70 uint groups_x = divup(in.info.dims[0], threads_x * REPEAT);
71 uint groups_y = divup(in.info.dims[1], threads_y);
72
73 Param rtmp;
74 Param otmp;
75
76 rtmp.info.dims[0] = groups_x;
77 otmp.info.dims[0] = in.info.dims[0];
78
79 rtmp.info.strides[0] = 1;
80 otmp.info.strides[0] = 1;
81
82 rtmp.info.offset = 0;
83 otmp.info.offset = 0;
84
85 for (int k = 1; k < 4; k++) {
86 rtmp.info.dims[k] = in.info.dims[k];
87 rtmp.info.strides[k] = rtmp.info.strides[k - 1] * rtmp.info.dims[k - 1];
88
89 otmp.info.dims[k] = in.info.dims[k];
90 otmp.info.strides[k] = otmp.info.strides[k - 1] * otmp.info.dims[k - 1];
91 }
92
93 int rtmp_elements = rtmp.info.strides[3] * rtmp.info.dims[3];
94 rtmp.data = bufferAlloc(rtmp_elements * sizeof(uint));
95
96 int otmp_elements = otmp.info.strides[3] * otmp.info.dims[3];
97 otmp.data = bufferAlloc(otmp_elements * sizeof(uint));
98
99 scanFirstLauncher<T, uint, af_notzero_t>(otmp, rtmp, in, false, groups_x,
100 groups_y, threads_x);
101
102 // Linearize the dimensions and perform scan
103 Param ltmp = rtmp;
104 ltmp.info.offset = 0;
105 ltmp.info.dims[0] = rtmp_elements;
106 for (int k = 1; k < 4; k++) {
107 ltmp.info.dims[k] = 1;
108 ltmp.info.strides[k] = rtmp_elements;
109 }
110
111 scanFirst<uint, uint, af_add_t>(ltmp, ltmp);
112
113 // Get output size and allocate output
114 uint total;
115 getQueue().enqueueReadBuffer(*rtmp.data, CL_TRUE,
116 sizeof(uint) * (rtmp_elements - 1),
117 sizeof(uint), &total);
118
119 out.data = bufferAlloc(total * sizeof(uint));
120
121 out.info.dims[0] = total;
122 out.info.strides[0] = 1;

Callers

nothing calls this directly

Calls 6

nextpow2Function · 0.85
bufferAllocFunction · 0.85
bufferFreeFunction · 0.85
maxFunction · 0.50
minFunction · 0.50
getQueueFunction · 0.50

Tested by

no test coverage detected