* Copyright (c) 2025 Huawei Technologies Co., Ltd.
* This program is free software, you can redistribute it and/or modify it under the terms and conditions of
* CANN Open Software License Agreement Version 2.0 (the "License").
* Please refer to the License for details. You may not use this file except in compliance with the License.
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
* See LICENSE in the root of the software repository for the full text of the License.
*/
#ifndef CATLASS_MATRIX_COORD_HPP
#define CATLASS_MATRIX_COORD_HPP
#include "catlass/coord.hpp"
namespace Catlass {
template <uint32_t ROW_ = 1, uint32_t COLUMN_ = 1>
struct MatrixShape {
static constexpr uint32_t ROW = ROW_;
static constexpr uint32_t COLUMN = COLUMN_;
static constexpr int64_t COUNT = ROW * COLUMN;
CATLASS_HOST_DEVICE
static Coord<2> ToCoord()
{
return MakeCoord(ROW, COLUMN);
}
};
struct MatrixCoord : public Coord<2, uint32_t> {
using Index = uint32_t;
using Base = Coord<2, Index>;
using LongIndex = typename Base::LongIndex;
static constexpr uint32_t ROW_INDEX = 0;
static constexpr uint32_t COLUMN_INDEX = 1;
CATLASS_HOST_DEVICE
MatrixCoord()
{}
CATLASS_HOST_DEVICE
MatrixCoord(Coord<2, Index> const& coord) : Base(coord)
{}
CATLASS_HOST_DEVICE
MatrixCoord(Index row, Index column) : Base(MakeCoord(row, column))
{}
CATLASS_HOST_DEVICE
MatrixCoord(LongIndex row, LongIndex column) : Base(MakeCoord(Index(row), Index(column)))
{}
CATLASS_HOST_DEVICE
Index const& row() const
{
return this->At(ROW_INDEX);
}
CATLASS_HOST_DEVICE
Index& row()
{
return this->At(ROW_INDEX);
}
CATLASS_HOST_DEVICE
Index const& column() const
{
return this->At(COLUMN_INDEX);
}
CATLASS_HOST_DEVICE
Index& column()
{
return this->At(COLUMN_INDEX);
}
CATLASS_HOST_DEVICE
MatrixCoord operator+(Base const& b) const
{
return MatrixCoord(Base::operator+(b));
}
CATLASS_HOST_DEVICE
MatrixCoord& operator+=(Base const& b)
{
Base::operator+=(b);
return *this;
}
};
}
#endif