CUTLASS
CUDA Templates for Linear Algebra Subroutines and Solvers
matrix_coord.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  **************************************************************************************************/
28 #pragma once
29 
30 #include "cutlass/cutlass.h"
31 #include "cutlass/coord.h"
32 
33 namespace cutlass {
34 
36 
39 struct MatrixCoord : public Coord<2, int> {
40 
41 public:
42 
44  using Index = int;
45 
48 
49 private:
50 
52  static int const kRow = 0;
53 
55  static int const kColumn = 1;
56 
57 public:
58 
59  //
60  // Methods
61  //
62 
66 
69  MatrixCoord(Coord<2, Index> const &coord): Base(coord) { }
70 
74 
77  Index const & row() const { return this->at(kRow); }
78 
81  Index & row() { return this->at(kRow); }
82 
85  Index const & column() const { return this->at(kColumn); }
86 
89  Index & column() { return this->at(kColumn); }
90 
91  //
92  // Coord operators
93  //
94 
97  MatrixCoord operator+(Base const& b) const {
98  return MatrixCoord(Base::operator+(b));
99  }
100 
103  MatrixCoord operator-(Base const& b) const {
104  return MatrixCoord(Base::operator-(b));
105  }
106 
109  MatrixCoord operator*(Base const& b) const {
110  return MatrixCoord(Base::operator*(b));
111  }
112 
115  MatrixCoord operator/(Base const& b) const {
116  return MatrixCoord(Base::operator/(b));
117  }
118 
122  Base::operator+=(b);
123  return *this;
124  }
125 
129  Base::operator-=(b);
130  return *this;
131  }
132 
136  Base::operator*=(b);
137  return *this;
138  }
139 
143  Base::operator/=(b);
144  return *this;
145  }
146 
147 };
148 
150 
151 } // namespace cutlass
CUTLASS_HOST_DEVICE Index const & column() const
Returns the column of the coordinate.
Definition: matrix_coord.h:85
Definition: aligned_buffer.h:35
CUTLASS_HOST_DEVICE MatrixCoord operator-(Base const &b) const
Element-wise subtraction.
Definition: matrix_coord.h:103
CUTLASS_HOST_DEVICE Coord & operator*=(Coord const &b)
In-place multiplication.
Definition: coord.h:222
CUTLASS_HOST_DEVICE MatrixCoord operator*(Base const &b) const
Element-wise multiplication.
Definition: matrix_coord.h:109
A Coord is a coordinate of arbitrary rank into a tensor or matrix.
CUTLASS_HOST_DEVICE Coord< 1 > make_Coord(int _0)
Helper to make a 2-element coordinate.
Definition: coord.h:387
CUTLASS_HOST_DEVICE MatrixCoord & operator/=(Base const &b)
In-place division.
Definition: matrix_coord.h:142
CUTLASS_HOST_DEVICE Index const & row() const
Returns the row of the coordinate.
Definition: matrix_coord.h:77
CUTLASS_HOST_DEVICE Coord & operator-=(Coord const &b)
In-place subtraction.
Definition: coord.h:213
CUTLASS_HOST_DEVICE MatrixCoord operator+(Base const &b) const
Element-wise addition.
Definition: matrix_coord.h:97
CUTLASS_HOST_DEVICE MatrixCoord(Index row, Index column)
Helper to construct from a row and column.
Definition: matrix_coord.h:73
#define CUTLASS_HOST_DEVICE
Definition: cutlass.h:89
CUTLASS_HOST_DEVICE Coord & operator/=(Coord const &b)
In-place division.
Definition: coord.h:231
CUTLASS_HOST_DEVICE MatrixCoord(Coord< 2, Index > const &coord)
Constructs from Coord<2>
Definition: matrix_coord.h:69
Statically-sized array specifying Coords within a tensor.
Definition: coord.h:43
int Index
Integer-valued index.
Definition: matrix_coord.h:44
CUTLASS_HOST_DEVICE MatrixCoord & operator-=(Base const &b)
In-place subtraction.
Definition: matrix_coord.h:128
CUTLASS_HOST_DEVICE Index & row()
Returns the row of the coordinate.
Definition: matrix_coord.h:81
CUTLASS_HOST_DEVICE Coord & operator+=(Coord const &b)
In-place addition.
Definition: coord.h:204
CUTLASS_HOST_DEVICE MatrixCoord operator/(Base const &b) const
Element-wise division.
Definition: matrix_coord.h:115
CUTLASS_HOST_DEVICE Index & at()
Gets the index of a given Coord element.
Definition: coord.h:255
CUTLASS_HOST_DEVICE Index & column()
Returns the column of the coordinate.
Definition: matrix_coord.h:89
CUTLASS_HOST_DEVICE MatrixCoord & operator*=(Base const &b)
In-place multiplication.
Definition: matrix_coord.h:135
CUTLASS_HOST_DEVICE MatrixCoord & operator+=(Base const &b)
In-place addition.
Definition: matrix_coord.h:121
Basic include for CUTLASS.
Definition: matrix_coord.h:39
CUTLASS_HOST_DEVICE MatrixCoord()
Default ctor.
Definition: matrix_coord.h:65