Cutlass
CUDA Templates for Linear Algebra Subroutines and Solvers
tile_allocation.h
Go to the documentation of this file.
1 /***************************************************************************************************
2  * Copyright (c) 2017-2018, 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  **************************************************************************************************/
28 #pragma once
29 
30 #include "cutlass/shape.h"
31 #include "cutlass/fragment.h"
32 #include "cutlass/tensor_ref.h"
33 #include "cutlass/zip_tensor_ref.h"
34 
35 namespace cutlass {
36 
38 
40 template <typename Scalar_, typename Shape_>
42  //
43  // Type definitions
44  //
45 
47  typedef Scalar_ Scalar;
48 
51 
53  typedef Shape_ Shape;
54 
57 
60 
63 
64  //
65  // Data members
66  //
67 
70 
71  //
72  // Methods
73  //
74 
76  CUTLASS_DEVICE
77  Scalar *data() { return reinterpret_cast<Scalar *>(&storage[0][0][0][0]); }
78 
80  CUTLASS_DEVICE
81  Scalar const *data() const { return reinterpret_cast<Scalar const *>(&storage[0][0][0][0]); }
82 
84  CUTLASS_DEVICE
86  return TensorRef(data(), make_Coord(Strides::kD, Strides::kH, Strides::kW, Strides::kC));
87  }
88 
90  CUTLASS_DEVICE
92  return ConstTensorRef(data(), make_Coord(Strides::kD, Strides::kH, Strides::kW, Strides::kC));
93  }
94 };
95 
97 
99 template <typename First_, typename Second_>
101  //
102  // Type definitions
103  //
104 
106  typedef First_ First;
107 
109  typedef Second_ Second;
110 
113 
117 
118  //
119  // Data members
120  //
121 
124 
127 
128  //
129  // Methods
130  //
131 
133  CUTLASS_DEVICE
134  TensorRef reference() { return TensorRef(first.reference(), second.reference()); }
135 
137  CUTLASS_DEVICE
138  ConstTensorRef reference() const { return ConstTensorRef(first.reference(), second.reference()); }
139 };
140 
142 
143 } // namespace cutlass
Definition: convert.h:33
CUTLASS_DEVICE TensorRef reference()
Returns a TensorRef object pointing to the data.
Definition: tile_allocation.h:134
ZipTensorRef< typename First::ConstTensorRef, typename Second::ConstTensorRef > ConstTensorRef
Defines the tensor reference for this allocation.
Definition: tile_allocation.h:116
Shape< Shape_::kH *Shape_::kW *Shape_::kC, Shape_::kW *Shape_::kC, Shape_::kC, elementsPerAccess > Shape
Definition: shape.h:170
Defines a structure containing strides, bounds, and a pointer to tensor data.
Definition: zip_tensor_ref.h:38
TensorRef< Scalar, 4 > TensorRef
Defines the tensor reference for this allocation.
Definition: tile_allocation.h:62
CUTLASS_DEVICE Scalar const * data() const
Returns a const pointer to the raw data.
Definition: tile_allocation.h:81
CUTLASS_HOST_DEVICE Coord< 1 > make_Coord(int _0)
Helper to make a 2-element coordinate.
Definition: coord.h:318
CUTLASS_DEVICE TensorRef reference()
Returns a TensorRef object pointing to the data.
Definition: tile_allocation.h:85
Second_ Second
Second tensor allocation.
Definition: tile_allocation.h:109
Storage storage[Shape::kD][Shape::kH][Shape::kW][Shape::kC]
Storage.
Definition: tile_allocation.h:69
ZipTensorRef< typename First::TensorRef, typename Second::TensorRef > TensorRef
Defines the tensor reference for this allocation.
Definition: tile_allocation.h:112
ShapeStrides< Shape, 1 >::Shape Strides
Strides.
Definition: tile_allocation.h:56
static int const kH
The height of the cube.
Definition: shape.h:68
Second second
Second tensor allocation.
Definition: tile_allocation.h:126
Definition: fragment.h:76
static int const kC
The number of scalars per element.
Definition: shape.h:72
TensorRef< Scalar const, 4 > ConstTensorRef
Defines the tensor reference for this allocation.
Definition: tile_allocation.h:59
First first
First tensor allocation.
Definition: tile_allocation.h:123
CUTLASS_DEVICE ConstTensorRef reference() const
Returns a TensorRef object pointing to the data.
Definition: tile_allocation.h:91
Defines a structure containing a pair of TensorRef-like objects.
Scalar_ Scalar
Scalar element.
Definition: tile_allocation.h:47
Manages a pair of tile allocations as if they are one allocation.
Definition: tile_allocation.h:100
Shape_ Shape
Size of the allocation in units of scalars.
Definition: tile_allocation.h:53
Class for storing a tile in memory and accessing it through a tensor ref.
Definition: tile_allocation.h:41
CUTLASS_DEVICE Scalar * data()
Returns a pointer to the raw data.
Definition: tile_allocation.h:77
CUTLASS_DEVICE ConstTensorRef reference() const
Returns a TensorRef object pointing to the data.
Definition: tile_allocation.h:138
static int const kW
The width of the cube.
Definition: shape.h:70
static int const kD
The depth of the cube.
Definition: shape.h:66
Defines Shape implementing the Layout concept for representing a 4D hypercube of objects.
StorageType< sizeof(Scalar)>::Type Storage
The actual storage (may differ from the scalar type)
Definition: tile_allocation.h:50
Defines Fragment, a statically-sized array for storing parts of matrices within a thread&#39;s registers...
First_ First
First tensor allocation.
Definition: tile_allocation.h:106