vec4.hh
Go to the documentation of this file.
1#pragma once
2
3// The 4-wide register value of the reg: and small gemm tiles: a clang ext_vector, or under
4// BATCHLAS_DEVICE_NO_VECTOR_TYPES (Metal: its emitter has no vector types) a 16-byte struct
5// with the members the kernels use (.x-.w, [i], scalar * Vec4).
6
7#include <batchlas/backend_config.h>
8
9namespace batchlas::sycl_gemm {
10
11#if BATCHLAS_DEVICE_NO_VECTOR_TYPES
12
13// Element-wise copies on purpose: LLVM folds a trivial global->private->local copy pair into
14// a byte-loop memmove (AdaptiveCpp's emitter needs patch 0005 to compile it at all).
15template <typename T>
16struct alignas(4 * sizeof(T)) Vec4 {
17 T x, y, z, w;
18 Vec4() = default;
19 Vec4(T a, T b, T c, T d) : x(a), y(b), z(c), w(d) {}
20 Vec4(const Vec4& o) : x(o.x), y(o.y), z(o.z), w(o.w) {}
21 Vec4& operator=(const Vec4& o) {
22 x = o.x, y = o.y, z = o.z, w = o.w;
23 return *this;
24 }
25 T& operator[](int i) { return i == 0 ? x : i == 1 ? y : i == 2 ? z : w; }
26 T operator[](int i) const { return i == 0 ? x : i == 1 ? y : i == 2 ? z : w; }
27 friend Vec4 operator*(T a, const Vec4& v) { return {a * v.x, a * v.y, a * v.z, a * v.w}; }
28};
29
30#else
31
32template <typename T>
33using Vec4 = T __attribute__((ext_vector_type(4)));
34
35#endif
36
37} // namespace batchlas::sycl_gemm
T __attribute__((ext_vector_type(4))) Vec4
Definition vec4.hh:33