CUTLASS
CUDA Templates for Linear Algebra Subroutines and Solvers
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 
84  pointer data() {
85  return reinterpret_cast<pointer>(storage);
86  }
87 
89  const_pointer data() const {
90  return reinterpret_cast<pointer>(storage);
91  }
92 
95  return storage;
96  }
97 
99  Storage const * raw_data() const {
100  return storage;
101  }
102 
103 
105  constexpr bool empty() const {
106  return !kCount;
107  }
108 
110  constexpr size_type size() const {
111  return kCount;
112  }
113 
115  constexpr size_type max_size() const {
116  return kCount;
117  }
118 };
119 
121 
122 } // namespace cutlass
123 
T value_type
Definition: aligned_buffer.h:71
value_type const * const_pointer
Definition: aligned_buffer.h:75
Definition: aligned_buffer.h:35
#define constexpr
Definition: platform.h:137
CUTLASS_HOST_DEVICE Storage const * raw_data() const
Definition: aligned_buffer.h:99
typename Array::const_reference const_reference
Definition: aligned_buffer.h:79
CUTLASS_HOST_DEVICE constexpr size_type max_size() const
Definition: aligned_buffer.h:115
uint8_t Storage
Internal storage type.
Definition: aligned_buffer.h:48
Statically sized array of elements that accommodates all CUTLASS-supported numeric types and is safe ...
Defines the size of an element in bits.
Definition: numeric_types.h:42
static int const kBytes
Number of storage elements.
Definition: aligned_buffer.h:57
#define CUTLASS_HOST_DEVICE
Definition: cutlass.h:89
Modifies semantics of cutlass::Array<> to provide guaranteed alignment.
Definition: aligned_buffer.h:45
CUTLASS_HOST_DEVICE pointer data()
Definition: aligned_buffer.h:84
static int const kCount
Number of logical elements held in buffer.
Definition: aligned_buffer.h:51
static int const kAlign
Alignment requirement in bytes.
Definition: aligned_buffer.h:54
CUTLASS_HOST_DEVICE Storage * raw_data()
Definition: aligned_buffer.h:94
typename Array::reference reference
Definition: aligned_buffer.h:78
Array< Element, N > Array
Definition: aligned_buffer.h:77
size_t size_type
Definition: aligned_buffer.h:72
ptrdiff_t difference_type
Definition: aligned_buffer.h:73
value_type * pointer
Definition: aligned_buffer.h:74
Basic include for CUTLASS.
CUTLASS_HOST_DEVICE constexpr bool empty() const
Definition: aligned_buffer.h:105
CUTLASS_HOST_DEVICE constexpr size_type size() const
Definition: aligned_buffer.h:110
CUTLASS_HOST_DEVICE const_pointer data() const
Definition: aligned_buffer.h:89