* 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.
*/
* \file tile_shape.h
* \brief
*/
#pragma once
#include "tilefwk/tile_shape.h"
#include "interface/inner/hash_buffer.h"
namespace npu::tile_fwk {
inline HashBuffer& SerializeTo(const VecTile& vecTile, HashBuffer& hashBuffer)
{
hashBuffer.assign(vecTile.tile.begin(), vecTile.tile.end());
return hashBuffer;
}
inline HashBuffer& SerializeTo(const CubeTile& cubeTile, HashBuffer& hashBuffer)
{
hashBuffer.Append(cubeTile.m);
hashBuffer.Append(cubeTile.k);
hashBuffer.Append(cubeTile.n);
return hashBuffer;
}
inline HashBuffer& SerializeTo(const DistTile& distTile, HashBuffer& hashBuffer)
{
hashBuffer.Append(distTile.row);
hashBuffer.Append(distTile.col);
hashBuffer.Append(distTile.rank);
hashBuffer.Append(distTile.rankId);
return hashBuffer;
}
inline void DeserializeFrom(HashBuffer& hashBuffer, VecTile& vecTile)
{
vecTile.tile.assign(hashBuffer.begin(), hashBuffer.end());
}
inline void DeserializeFrom(HashBuffer& hashBuffer, CubeTile& cubeTile)
{
cubeTile.m[0] = hashBuffer.Get<int64_t>(0);
cubeTile.m[1] = hashBuffer.Get<int64_t>(2);
cubeTile.k[0] = hashBuffer.Get<int64_t>(4);
cubeTile.k[1] = hashBuffer.Get<int64_t>(6);
cubeTile.k[2] = hashBuffer.Get<int64_t>(8);
cubeTile.n[0] = hashBuffer.Get<int64_t>(10);
cubeTile.n[1] = hashBuffer.Get<int64_t>(12);
}
inline void DeserializeFrom(HashBuffer& hashBuffer, DistTile& distTile)
{
distTile.row[0] = hashBuffer[0];
distTile.row[1] = hashBuffer[1];
distTile.row[2] = hashBuffer[2];
distTile.col[0] = hashBuffer[3];
distTile.col[1] = hashBuffer[4];
distTile.col[2] = hashBuffer[5];
distTile.rank[0] = hashBuffer[6];
distTile.rank[1] = hashBuffer[7];
distTile.rank[2] = hashBuffer[8];
distTile.rankId = hashBuffer[9];
}
};