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

Function cscmv

src/backend/opencl/kernel/cscmv.hpp:30–94  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28namespace kernel {
29template<typename T>
30void cscmv(Param out, const Param &values, const Param &colIdx,
31 const Param &rowIdx, const Param &rhs, const T alpha, const T beta,
32 bool is_conj) {
33 // TODO: rows_per_group limited by register pressure. Find better way to
34 // handle this.
35 constexpr int threads_per_g = 64;
36 constexpr int rows_per_group = 64;
37
38 const bool use_alpha = (alpha != scalar<T>(1.0));
39 const bool use_beta = (beta != scalar<T>(0.0));
40
41 cl::NDRange local(threads_per_g);
42
43 int K = colIdx.info.dims[0] - 1;
44 int M = out.info.dims[0];
45
46 std::array<TemplateArg, 5> targs = {
47 TemplateTypename<T>(), TemplateArg(use_alpha),
48 TemplateArg(is_conj), TemplateArg(rows_per_group),
49 TemplateArg(local[0]),
50 };
51 std::array<std::string, 9> options = {
52 DefineKeyValue(T, dtype_traits<T>::getName()),
53 DefineKeyValue(USE_ALPHA, use_alpha),
54 DefineKeyValue(IS_CONJ, is_conj),
55 DefineKeyValue(THREADS, local[0]),
56 DefineKeyValue(ROWS_PER_GROUP, rows_per_group),
57 DefineKeyValue(IS_CPLX, (iscplx<T>() ? 1 : 0)),
58 DefineKeyValue(IS_DBL, (isdbl<T>() ? 1 : 0)),
59 DefineKeyValue(IS_LONG, (islong<T>() ? 1 : 0)),
60 getTypeBuildDefinition<T>()};
61
62 if(use_beta) {
63 std::array<TemplateArg, 4> targs_beta = {
64 TemplateTypename<T>(), TemplateArg(is_conj),
65 TemplateArg(rows_per_group), TemplateArg(local[0])};
66 std::array<std::string, 8> options_beta = {
67 DefineKeyValue(T, dtype_traits<T>::getName()),
68 DefineKeyValue(IS_CONJ, is_conj),
69 DefineKeyValue(THREADS, local[0]),
70 DefineKeyValue(ROWS_PER_GROUP, rows_per_group),
71 DefineKeyValue(IS_CPLX, (iscplx<T>() ? 1 : 0)),
72 DefineKeyValue(IS_DBL, (isdbl<T>() ? 1 : 0)),
73 DefineKeyValue(IS_LONG, (islong<T>() ? 1 : 0)),
74 getTypeBuildDefinition<T>()};
75
76 int groups_x = divup(M, rows_per_group * threads_per_g);
77 cl::NDRange global(local[0] * groups_x, 1);
78 auto cscmvBeta = common::getKernel("cscmv_beta", {{cscmv_cl_src}}, targs_beta, options_beta);
79 cscmvBeta(cl::EnqueueArgs(getQueue(), global, local), *out.data, M, beta);
80
81 } else {
82 getQueue().enqueueFillBuffer(*out.data, 0, 0, M * sizeof(T));
83 }
84
85 int groups_x = divup(M, rows_per_group);
86 cl::NDRange global(local[0] * groups_x, 1);
87

Callers 1

matmulFunction · 0.85

Calls 5

TemplateArgClass · 0.85
getNameFunction · 0.85
EnqueueArgsClass · 0.85
getKernelFunction · 0.50
getQueueFunction · 0.50

Tested by

no test coverage detected