aligned_buffer.h
Go to the documentation of this file.
/***************************************************************************************************
* Copyright (c) 2017-2019, NVIDIA CORPORATION. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
* * Neither the name of the NVIDIA CORPORATION nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TOR (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
**************************************************************************************************/
#pragma once
#include "cutlass/cutlass.h"
#include "cutlass/array.h"
namespace cutlass {
template <
typename T,
int N,
int Align = 16
>
struct AlignedBuffer {
using Storage = uint8_t;
static int const kCount = N;
static int const kAlign = Align;
static int const kBytes =
(sizeof_bits<T>::value * N + 7) / 8;
private:
alignas(Align) Storage storage[kBytes];
public:
//
// C++ standard members
//
typedef T value_type;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef value_type *pointer;
typedef value_type const * const_pointer;
using Array = Array<T, N>;
using reference = typename Array::reference;
using const_reference = typename Array::const_reference;
public:
CUTLASS_HOST_DEVICE
pointer data() {
return reinterpret_cast<pointer>(storage);
}
CUTLASS_HOST_DEVICE
const_pointer data() const {
return reinterpret_cast<pointer>(storage);
}
CUTLASS_HOST_DEVICE
Storage * raw_data() {
return storage;
}
CUTLASS_HOST_DEVICE
Storage const * raw_data() const {
return storage;
}
CUTLASS_HOST_DEVICE
constexpr bool empty() const {
return !kCount;
}
CUTLASS_HOST_DEVICE
constexpr size_type size() const {
return kCount;
}
CUTLASS_HOST_DEVICE
constexpr size_type max_size() const {
return kCount;
}
};
} // namespace cutlass
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