group_blas_fill.hh
Go to the documentation of this file.
1#pragma once
2
4
5namespace batchlas::device {
6
7/// @addtogroup api_device_blas
8/// @{
9
10/// @brief Sets every element of `x` to `value`, cooperatively across `group`.
11/// @tparam Group `sycl::group`, `sycl::sub_group` or an `nd_item`; every work-item must call
12/// @param group executor whose work-items share the elements
13/// @param x single vector (`batch_size() == 1`), written in place
14/// @param value fill value
15template <typename Group, typename T>
16inline constexpr void fill(const Group& group,
17 const VectorView<T>& x,
18 const T& value) {
20 const int local_id = detail::group_local_linear_id(group);
21 const int local_size = detail::group_local_linear_range(group);
22
23 for (int index = local_id; index < x.size(); index += local_size) {
24 x(index) = value;
25 }
26}
27
28/// @brief Sets every element of the dense matrix `a` to `value`; the padding rows between `a.rows()` and `a.ld()` are not touched.
29/// @param group executor whose work-items share the elements
30/// @param a single matrix, written in place
31/// @param value fill value
32template <typename Group, typename T>
33inline constexpr void fill(const Group& group,
35 const T& value) {
37 const int local_id = detail::group_local_linear_id(group);
38 const int local_size = detail::group_local_linear_range(group);
39 const int extent = a.rows() * a.cols();
40
41 for (int linear_index = local_id; linear_index < extent; linear_index += local_size) {
42 const int row = linear_index % a.rows();
43 const int col = linear_index / a.rows();
44 a(row, col) = value;
45 }
46}
47
48/// @}
49
50} // namespace batchlas::device
Non-owning view of a batch of strided vectors: the vector argument type of the entry points.
Definition matrix.hh:1754
int size() const
Entries per item.
Definition matrix.hh:1837
constexpr void fill(const Group &group, const VectorView< T > &x, const T &value)
Sets every element of x to value, cooperatively across group.
@ NoTrans
op(A) = A.
Definition enums.hh:172
constexpr void validate_single_problem(const KernelMatrixView< T, MatrixFormat::Dense > &a, Transpose trans)
constexpr int group_local_linear_id(const Group &group)
constexpr int group_local_linear_range(const Group &group)
constexpr void validate_vector_operand(const VectorView< T > &x, const char *op_name)
Trivially copyable view of a MatrixView for use inside a SYCL kernel.
Definition matrix.hh:145
auto rows() const
Row count (the capacity on a heterogeneous batch).
Definition matrix.hh:219
auto cols() const
Column count (the capacity on a heterogeneous batch).
Definition matrix.hh:223