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

Function csr2coo

src/backend/opencl/kernel/sparse.hpp:166–202  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

164
165template<typename T>
166void csr2coo(Param ovalues, Param orowIdx, Param ocolIdx, const Param ivalues,
167 const Param irowIdx, const Param icolIdx, Param index) {
168 std::vector<TemplateArg> tmpltArgs = {
169 TemplateTypename<T>(),
170 };
171 std::vector<std::string> compileOpts = {
172 DefineKeyValue(T, dtype_traits<T>::getName()),
173 };
174 compileOpts.emplace_back(getTypeBuildDefinition<T>());
175
176 auto csr2coo = common::getKernel("csr2Coo", {{csr2coo_cl_src}}, tmpltArgs,
177 compileOpts);
178
179 const int MAX_GROUPS = 4096;
180 int M = irowIdx.info.dims[0] - 1;
181 // FIXME: This needs to be based non nonzeros per row
182 int threads = 64;
183
184 cl::Buffer *scratch = bufferAlloc(orowIdx.info.dims[0] * sizeof(int));
185
186 cl::NDRange local(threads, 1);
187 int groups_x = std::min((int)(divup(M, local[0])), MAX_GROUPS);
188 cl::NDRange global(local[0] * groups_x, 1);
189
190 csr2coo(cl::EnqueueArgs(getQueue(), global, local), *scratch, *ocolIdx.data,
191 *irowIdx.data, *icolIdx.data, M);
192
193 // Now we need to sort this into column major
194 kernel::sort0ByKeyIterative<int, int>(ocolIdx, index, true);
195
196 // Now use index to sort values and rows
197 kernel::swapIndex<T>(ovalues, orowIdx, ivalues, scratch, index);
198
199 CL_DEBUG_FINISH(getQueue());
200
201 bufferFree(scratch);
202}
203
204template<typename T>
205void coo2csr(Param ovalues, Param orowIdx, Param ocolIdx, const Param ivalues,

Callers

nothing calls this directly

Calls 7

getNameFunction · 0.85
bufferAllocFunction · 0.85
EnqueueArgsClass · 0.85
bufferFreeFunction · 0.85
getKernelFunction · 0.50
minFunction · 0.50
getQueueFunction · 0.50

Tested by

no test coverage detected