* 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 HCCLV1_CHECK_UTILS_H
#define HCCLV1_CHECK_UTILS_H
#include <map>
#include <set>
#include <vector>
#include <memory>
#include "base.h"
#include "log.h"
#include "task_stub.h"
#include "task_def.h"
#include "checker_def.h"
namespace checker {
extern const std::string FOUR_INDENT_SPACE;
struct SrcBufDes {
RankId rankId;
BufferType bufType;
mutable u64 srcAddr;
SrcBufDes(RankId id, BufferType type, u64 addr) : rankId(id), bufType(type), srcAddr(addr)
{
}
inline bool operator<(const SrcBufDes &another) const
{
return rankId < another.rankId;
}
std::string Describe() const
{
std::stringstream ret;
ret << "rankId is " << rankId << ", ";
ret << "bufType is " << bufType << ", ";
ret << "srcAddr is " << srcAddr << std::endl;
return ret.str();
}
};
struct BufferSemantic {
u64 startAddr;
mutable u64 size;
mutable bool isReduce;
mutable CheckerReduceOp reduceType;
mutable std::set<SrcBufDes> srcBufs;
std::vector<u32> affectedGlobalSteps;
BufferSemantic(u64 startAddr, u64 size, bool isReduce = false,
CheckerReduceOp reduceType = CheckerReduceOp::REDUCE_RESERVED)
: startAddr(startAddr), size(size), isReduce(isReduce), reduceType(reduceType)
{
}
BufferSemantic(u64 startAddr, u64 size, bool isReduce, CheckerReduceOp reduceType, std::set<SrcBufDes> srcBufs)
: startAddr(startAddr), size(size), isReduce(isReduce), reduceType(reduceType), srcBufs(srcBufs)
{
}
inline bool operator<(const BufferSemantic &another) const
{
return startAddr < another.startAddr;
}
std::string Describe() const
{
std::stringstream ret;
ret << "startAddr is " << startAddr << ", ";
ret << "size is " << size << ", ";
if (isReduce) {
ret << "HcclReduceOp is " << reduceType << "." << std::endl;
} else {
ret << "no reduce" << std::endl;
}
for (auto &ele : srcBufs) {
ret << FOUR_INDENT_SPACE << FOUR_INDENT_SPACE << FOUR_INDENT_SPACE << ele.Describe();
}
return ret.str();
}
};
using RankMemorySemantics = std::map<BufferType, std::set<BufferSemantic>>;
TaskTypeStub GetNodeType(const TaskNode *node);
void CalcInputOutputSize(const CheckerOpParam &opParam, u32 ranksize, u64 &inputSize, u64 &outputSize, RankId myRank);
void CalcDataSize(const CheckerOpParam &opParam, u64 &dataSize);
bool IsAllToAllSeries(CheckerOpType opType);
}
#endif