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

Function csrmv

src/backend/opencl/kernel/csrmv.hpp:31–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29namespace kernel {
30template<typename T>
31void csrmv(Param out, const Param &values, const Param &rowIdx,
32 const Param &colIdx, const Param &rhs, const T alpha, const T beta) {
33 constexpr int MAX_CSRMV_GROUPS = 4096;
34 // Using greedy indexing is causing performance issues on many platforms
35 // FIXME: Figure out why
36 constexpr bool use_greedy = false;
37
38 // TODO: Figure out the proper way to choose either csrmv_thread or
39 // csrmv_block
40 bool is_csrmv_block = true;
41
42 const bool use_alpha = (alpha != scalar<T>(1.0));
43 const bool use_beta = (beta != scalar<T>(0.0));
44
45 cl::NDRange local(THREADS_PER_GROUP);
46
47 std::array<TemplateArg, 5> targs = {
48 TemplateTypename<T>(), TemplateArg(use_alpha), TemplateArg(use_beta),
49 TemplateArg(use_greedy), TemplateArg(local[0]),
50 };
51 std::array<std::string, 7> options = {
52 DefineKeyValue(T, dtype_traits<T>::getName()),
53 DefineKeyValue(USE_ALPHA, use_alpha),
54 DefineKeyValue(USE_BETA, use_beta),
55 DefineKeyValue(USE_GREEDY, use_greedy),
56 DefineKeyValue(THREADS, local[0]),
57 DefineKeyValue(IS_CPLX, (iscplx<T>() ? 1 : 0)),
58 getTypeBuildDefinition<T>()};
59
60 auto csrmv =
61 (is_csrmv_block ? common::getKernel("csrmv_thread", {{csrmv_cl_src}},
62 targs, options)
63 : common::getKernel("csrmv_block", {{csrmv_cl_src}},
64 targs, options));
65
66 int M = rowIdx.info.dims[0] - 1;
67
68 int groups_x =
69 is_csrmv_block ? divup(M, REPEAT) : divup(M, REPEAT * local[0]);
70 groups_x = std::min(groups_x, MAX_CSRMV_GROUPS);
71 cl::NDRange global(local[0] * groups_x, 1);
72
73 if (use_greedy) {
74 cl::Buffer *counter = bufferAlloc(sizeof(int));
75 getQueue().enqueueFillBuffer(*counter, 0, 0, sizeof(int));
76 csrmv(cl::EnqueueArgs(getQueue(), global, local), *out.data,
77 *values.data, *rowIdx.data, *colIdx.data, M, *rhs.data, rhs.info,
78 alpha, beta, *counter);
79 CL_DEBUG_FINISH(getQueue());
80 bufferFree(counter);
81 } else {
82 csrmv(cl::EnqueueArgs(getQueue(), global, local), *out.data,
83 *values.data, *rowIdx.data, *colIdx.data, M, *rhs.data, rhs.info,
84 alpha, beta);
85 CL_DEBUG_FINISH(getQueue());
86 }
87}
88} // namespace kernel

Callers 1

matmulFunction · 0.85

Calls 8

TemplateArgClass · 0.85
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