matrix_coord.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/coord.h"
namespace cutlass {
struct MatrixCoord : public Coord<2, int> {
public:
using Index = int;
using Base = Coord<2, Index>;
private:
static int const kRow = 0;
static int const kColumn = 1;
public:
//
// Methods
//
CUTLASS_HOST_DEVICE
MatrixCoord() { }
CUTLASS_HOST_DEVICE
MatrixCoord(Coord<2, Index> const &coord): Base(coord) { }
CUTLASS_HOST_DEVICE
MatrixCoord(Index row, Index column): Base(make_Coord(row, column)) { }
CUTLASS_HOST_DEVICE
Index const & row() const { return this->at(kRow); }
CUTLASS_HOST_DEVICE
Index & row() { return this->at(kRow); }
CUTLASS_HOST_DEVICE
Index const & column() const { return this->at(kColumn); }
CUTLASS_HOST_DEVICE
Index & column() { return this->at(kColumn); }
//
// Coord operators
//
CUTLASS_HOST_DEVICE
MatrixCoord operator+(Base const& b) const {
return MatrixCoord(Base::operator+(b));
}
CUTLASS_HOST_DEVICE
MatrixCoord operator-(Base const& b) const {
return MatrixCoord(Base::operator-(b));
}
CUTLASS_HOST_DEVICE
MatrixCoord operator*(Base const& b) const {
return MatrixCoord(Base::operator*(b));
}
CUTLASS_HOST_DEVICE
MatrixCoord operator/(Base const& b) const {
return MatrixCoord(Base::operator/(b));
}
CUTLASS_HOST_DEVICE
MatrixCoord& operator+=(Base const& b) {
Base::operator+=(b);
return *this;
}
CUTLASS_HOST_DEVICE
MatrixCoord& operator-=(Base const& b) {
Base::operator-=(b);
return *this;
}
CUTLASS_HOST_DEVICE
MatrixCoord& operator*=(Base const& b) {
Base::operator*=(b);
return *this;
}
CUTLASS_HOST_DEVICE
MatrixCoord& operator/=(Base const& b) {
Base::operator/=(b);
return *this;
}
};
} // namespace cutlass
cutlass::MatrixCoord::column
CUTLASS_HOST_DEVICE Index const & column() const
Returns the column of the coordinate.
Definition: matrix_coord.h:85
cutlass
Definition: aligned_buffer.h:35
cutlass::MatrixCoord::operator-
CUTLASS_HOST_DEVICE MatrixCoord operator-(Base const &b) const
Element-wise subtraction.
Definition: matrix_coord.h:103
cutlass::Coord::operator*=
CUTLASS_HOST_DEVICE Coord & operator*=(Coord const &b)
In-place multiplication.
Definition: coord.h:222
cutlass::MatrixCoord::operator*
CUTLASS_HOST_DEVICE MatrixCoord operator*(Base const &b) const
Element-wise multiplication.
Definition: matrix_coord.h:109
coord.h
A Coord is a coordinate of arbitrary rank into a tensor or matrix.
cutlass::make_Coord
CUTLASS_HOST_DEVICE Coord< 1 > make_Coord(int _0)
Helper to make a 2-element coordinate.
Definition: coord.h:387
cutlass::MatrixCoord::operator/=
CUTLASS_HOST_DEVICE MatrixCoord & operator/=(Base const &b)
In-place division.
Definition: matrix_coord.h:142
cutlass::MatrixCoord::row
CUTLASS_HOST_DEVICE Index const & row() const
Returns the row of the coordinate.
Definition: matrix_coord.h:77
cutlass::Coord::operator-=
CUTLASS_HOST_DEVICE Coord & operator-=(Coord const &b)
In-place subtraction.
Definition: coord.h:213
cutlass::MatrixCoord::operator+
CUTLASS_HOST_DEVICE MatrixCoord operator+(Base const &b) const
Element-wise addition.
Definition: matrix_coord.h:97
cutlass::MatrixCoord::MatrixCoord
CUTLASS_HOST_DEVICE MatrixCoord(Index row, Index column)
Helper to construct from a row and column.
Definition: matrix_coord.h:73
CUTLASS_HOST_DEVICE
#define CUTLASS_HOST_DEVICE
Definition: cutlass.h:89
cutlass::Coord::operator/=
CUTLASS_HOST_DEVICE Coord & operator/=(Coord const &b)
In-place division.
Definition: coord.h:231
cutlass::MatrixCoord::MatrixCoord
CUTLASS_HOST_DEVICE MatrixCoord(Coord< 2, Index > const &coord)
Constructs from Coord<2>
Definition: matrix_coord.h:69
cutlass::Coord
Statically-sized array specifying Coords within a tensor.
Definition: coord.h:43
cutlass::MatrixCoord::Index
int Index
Integer-valued index.
Definition: matrix_coord.h:44
cutlass::MatrixCoord::operator-=
CUTLASS_HOST_DEVICE MatrixCoord & operator-=(Base const &b)
In-place subtraction.
Definition: matrix_coord.h:128
cutlass::MatrixCoord::row
CUTLASS_HOST_DEVICE Index & row()
Returns the row of the coordinate.
Definition: matrix_coord.h:81
cutlass::Coord::operator+=
CUTLASS_HOST_DEVICE Coord & operator+=(Coord const &b)
In-place addition.
Definition: coord.h:204
cutlass::MatrixCoord::operator/
CUTLASS_HOST_DEVICE MatrixCoord operator/(Base const &b) const
Element-wise division.
Definition: matrix_coord.h:115
cutlass::Coord< 2, int >::at
CUTLASS_HOST_DEVICE Index & at()
Gets the index of a given Coord element.
Definition: coord.h:255
cutlass::MatrixCoord::column
CUTLASS_HOST_DEVICE Index & column()
Returns the column of the coordinate.
Definition: matrix_coord.h:89
cutlass::MatrixCoord::operator*=
CUTLASS_HOST_DEVICE MatrixCoord & operator*=(Base const &b)
In-place multiplication.
Definition: matrix_coord.h:135
cutlass::MatrixCoord::operator+=
CUTLASS_HOST_DEVICE MatrixCoord & operator+=(Base const &b)
In-place addition.
Definition: matrix_coord.h:121
cutlass.h
Basic include for CUTLASS.
cutlass::MatrixCoord
Definition: matrix_coord.h:39
cutlass::MatrixCoord::MatrixCoord
CUTLASS_HOST_DEVICE MatrixCoord()
Default ctor.
Definition: matrix_coord.h:65