| CUTLASS CUDA Templates for Linear Algebra Subroutines and Solvers

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

aligned_buffer.h
Go to the documentation of this file.
1 /***************************************************************************************************
2 * Copyright (c) 2017-2019, NVIDIA CORPORATION. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are permitted
5 * provided that the following conditions are met:
6 * * Redistributions of source code must retain the above copyright notice, this list of
7 * conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright notice, this list of
9 * conditions and the following disclaimer in the documentation and/or other materials
10 * provided with the distribution.
11 * * Neither the name of the NVIDIA CORPORATION nor the names of its contributors may be used
12 * to endorse or promote products derived from this software without specific prior written
13 * permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21 * STRICT LIABILITY, OR TOR (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 **************************************************************************************************/
30 #pragma once
31
32 #include "cutlass/cutlass.h"
33 #include "cutlass/array.h"
34
35 namespace cutlass {
36
38
40 template <
41 typename T,
42 int N,
43 int Align = 16
44 >
45 struct AlignedBuffer {
46
48 using Storage = uint8_t;
49
51 static int const kCount = N;
52
54 static int const kAlign = Align;
55
57 static int const kBytes =
58 (sizeof_bits<T>::value * N + 7) / 8;
59
60 private:
61
63 alignas(Align) Storage storage[kBytes];
64
65 public:
66
67 //
68 // C++ standard members
69 //
70
71 typedef T value_type;
72 typedef size_t size_type;
73 typedef ptrdiff_t difference_type;
74 typedef value_type *pointer;
75 typedef value_type const * const_pointer;
76
77 using Array = Array<T, N>;
78 using reference = typename Array::reference;
79 using const_reference = typename Array::const_reference;
80
81 public:
82
83 CUTLASS_HOST_DEVICE
84 pointer data() {
85 return reinterpret_cast<pointer>(storage);
86 }
87
88 CUTLASS_HOST_DEVICE
89 const_pointer data() const {
90 return reinterpret_cast<pointer>(storage);
91 }
92
93 CUTLASS_HOST_DEVICE
94 Storage * raw_data() {
95 return storage;
96 }
97
98 CUTLASS_HOST_DEVICE
99 Storage const * raw_data() const {
100 return storage;
101 }
102
103
104 CUTLASS_HOST_DEVICE
105 constexpr bool empty() const {
106 return !kCount;
107 }
108
109 CUTLASS_HOST_DEVICE
110 constexpr size_type size() const {
111 return kCount;
112 }
113
114 CUTLASS_HOST_DEVICE
115 constexpr size_type max_size() const {
116 return kCount;
117 }
118 };
119
121
122 } // namespace cutlass
123
cutlass::AlignedBuffer::value_type
T value_type
Definition: aligned_buffer.h:71
cutlass::AlignedBuffer::const_pointer
value_type const * const_pointer
Definition: aligned_buffer.h:75
cutlass
Definition: aligned_buffer.h:35
constexpr
#define constexpr
Definition: platform.h:137
cutlass::AlignedBuffer::raw_data
CUTLASS_HOST_DEVICE Storage const * raw_data() const
Definition: aligned_buffer.h:99
cutlass::AlignedBuffer< Element, cutlass::MatrixShape::kCount >::const_reference
typename Array::const_reference const_reference
Definition: aligned_buffer.h:79
cutlass::AlignedBuffer::max_size
CUTLASS_HOST_DEVICE constexpr size_type max_size() const
Definition: aligned_buffer.h:115
cutlass::AlignedBuffer< Element, cutlass::MatrixShape::kCount >::Storage
uint8_t Storage
Internal storage type.
Definition: aligned_buffer.h:48
array.h
Statically sized array of elements that accommodates all CUTLASS-supported numeric types and is safe ...
cutlass::sizeof_bits
Defines the size of an element in bits.
Definition: numeric_types.h:42
cutlass::AlignedBuffer::kBytes
static int const kBytes
Number of storage elements.
Definition: aligned_buffer.h:57
CUTLASS_HOST_DEVICE
#define CUTLASS_HOST_DEVICE
Definition: cutlass.h:89
cutlass::AlignedBuffer
Modifies semantics of cutlass::Array<> to provide guaranteed alignment.
Definition: aligned_buffer.h:45
cutlass::AlignedBuffer::data
CUTLASS_HOST_DEVICE pointer data()
Definition: aligned_buffer.h:84
cutlass::AlignedBuffer::kCount
static int const kCount
Number of logical elements held in buffer.
Definition: aligned_buffer.h:51
cutlass::AlignedBuffer::kAlign
static int const kAlign
Alignment requirement in bytes.
Definition: aligned_buffer.h:54
cutlass::AlignedBuffer::raw_data
CUTLASS_HOST_DEVICE Storage * raw_data()
Definition: aligned_buffer.h:94
cutlass::AlignedBuffer< Element, cutlass::MatrixShape::kCount >::reference
typename Array::reference reference
Definition: aligned_buffer.h:78
cutlass::AlignedBuffer< Element, cutlass::MatrixShape::kCount >::Array
Array< Element, N > Array
Definition: aligned_buffer.h:77
cutlass::AlignedBuffer::size_type
size_t size_type
Definition: aligned_buffer.h:72
cutlass::AlignedBuffer::difference_type
ptrdiff_t difference_type
Definition: aligned_buffer.h:73
cutlass::AlignedBuffer::pointer
value_type * pointer
Definition: aligned_buffer.h:74
cutlass.h
Basic include for CUTLASS.
cutlass::AlignedBuffer::empty
CUTLASS_HOST_DEVICE constexpr bool empty() const
Definition: aligned_buffer.h:105
cutlass::AlignedBuffer::size
CUTLASS_HOST_DEVICE constexpr size_type size() const
Definition: aligned_buffer.h:110
cutlass::AlignedBuffer::data
CUTLASS_HOST_DEVICE const_pointer data() const
Definition: aligned_buffer.h:89