| 30 | */ |
| 31 | template<size_t _dim, class _Float = float> |
| 32 | class Vector { |
| 33 | static_assert(std::is_floating_point<_Float>::value, "Vector can only be instantiated with floating point types"); |
| 34 | // static_assert(_dim % gpu::kWarpSize == 0, "`dim` should be divided by 32"); |
| 35 | public: |
| 36 | static const size_t dim = _dim; |
| 37 | typedef size_t Index; |
| 38 | typedef _Float Float; |
| 39 | Float data[dim]; |
| 40 | |
| 41 | /** Default constructor */ |
| 42 | Vector() = default; |
| 43 | |
| 44 | /** Construct a vector of repeat scalar */ |
| 45 | Vector(Float f) { |
| 46 | #pragma unroll |
| 47 | for (Index i = 0; i < dim; i++) |
| 48 | data[i] = f; |
| 49 | } |
| 50 | |
| 51 | __host__ __device__ Float &operator[](Index index) { |
| 52 | return data[index]; |
| 53 | } |
| 54 | |
| 55 | __host__ __device__ Float operator[](Index index) const { |
| 56 | return data[index]; |
| 57 | } |
| 58 | |
| 59 | __host__ __device__ Vector &operator=(const Vector &v) { |
| 60 | #if __CUDA_ARCH__ |
| 61 | using namespace gpu; |
| 62 | const int lane_id = threadIdx.x % kWarpSize; |
| 63 | for (Index i = lane_id; i < dim; i += kWarpSize) |
| 64 | #else |
| 65 | for (Index i = 0; i < dim; i++) |
| 66 | #endif |
| 67 | data[i] = v[i]; |
| 68 | return *this; |
| 69 | } |
| 70 | |
| 71 | Vector &operator =(Float f) { |
| 72 | #pragma unroll |
| 73 | for (Index i = 0; i < dim; i++) |
| 74 | data[i] = f; |
| 75 | return *this; |
| 76 | } |
| 77 | |
| 78 | Vector &operator +=(const Vector &v) { |
| 79 | #pragma unroll |
| 80 | for (Index i = 0; i < dim; i++) |
| 81 | data[i] += v[i]; |
| 82 | return *this; |
| 83 | } |
| 84 | |
| 85 | |
| 86 | Vector &operator -=(const Vector &v) { |
| 87 | #pragma unroll |
| 88 | for (Index i = 0; i < dim; i++) |
| 89 | data[i] -= v[i]; |
nothing calls this directly
no outgoing calls
no test coverage detected