Line data Source code
1 : /**
2 : * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 :
11 : /*!
12 : * \file kernel_vec_scatter_check.cpp
13 : * \brief
14 : */
15 :
16 : #include "kernel_check_params.h"
17 : #include "kernel_vec_scatter_check.h"
18 :
19 : namespace AscendC {
20 : namespace check {
21 :
22 0 : bool TikcppVecScatterCheck::CheckTensorSize(std::vector<uint64_t> maskArray)
23 : {
24 : // max element calculated in a repeat
25 0 : uint64_t maskVal = (maskArray.size() == 1) ? maskArray[0] : GetMaskLength(maskArray, param_.dstDtypeBytes);
26 :
27 : // dstLocal:
28 0 : uint64_t blockLen = ONE_BLK_SIZE / param_.dstDtypeBytes; // ele num in one block
29 0 : uint64_t blkNumLastRep = DivCeil(maskVal, blockLen); // last repeat needs x blocks for maskLen elements
30 0 : uint64_t eleNumLastBlk = ((maskVal % blockLen) != 0) ? (maskVal % blockLen) : blockLen;
31 0 : uint64_t maxOffset =
32 0 : ((param_.repeatTimes - 1) * DEFAULT_REPEAT_STRIDE + (blkNumLastRep - 1) * DEFAULT_BLK_STRIDE) * blockLen +
33 : eleNumLastBlk;
34 0 : maxOffset = maxOffset * param_.dstDtypeBytes + param_.dstBaseAddr;
35 0 : ASCENDC_CHECK(CheckTensorSizeOverflow(maxOffset, param_.dstSize, "dstLocal", "Scatter"));
36 0 : return true;
37 : }
38 :
39 0 : bool TikcppVecScatterCheck::CommonCheck()
40 : {
41 0 : const std::string supportPos = "VECIN/VECOUT/VECCALC";
42 0 : ASCENDC_CHECK(CheckTensorScope(param_.dstLogicPos, static_cast<uint8_t>(HardWareIndex::UB), "dst", supportPos));
43 0 : ASCENDC_CHECK(CheckTensorScope(param_.srcLogicPos, static_cast<uint8_t>(HardWareIndex::UB), "src", supportPos));
44 0 : ASCENDC_CHECK(
45 : CheckTensorScope(param_.dstOffsetLogicPos, static_cast<uint8_t>(HardWareIndex::UB), "dstOffset", supportPos));
46 :
47 0 : ASCENDC_CHECK(CheckAddrAlign());
48 0 : ASCENDC_CHECK(CheckBufferSizeOverFlow(
49 : param_.dstSize, GlobalParams::Instance().bufferSizeMap.at(param_.dstPos),
50 : "check dst tensor buffersize failed"));
51 0 : ASCENDC_CHECK(CheckBufferSizeOverFlow(
52 : param_.srcSize, GlobalParams::Instance().bufferSizeMap.at(param_.srcPos),
53 : "check src tensor buffersize failed"));
54 0 : ASCENDC_CHECK(CheckBufferSizeOverFlow(
55 : param_.dstOffsetSize, GlobalParams::Instance().bufferSizeMap.at(param_.dstOffsetPos),
56 : "check dstOffset tensor buffersize failed"));
57 0 : return true;
58 0 : }
59 :
60 0 : bool TikcppVecScatterCheck::CheckAllLowLevel(std::vector<uint64_t> maskArray)
61 : {
62 0 : uint32_t maxByteLen = param_.dstDtypeBytes;
63 0 : ASCENDC_CHECK(UpdateMaskArrayAndCheck(maskArray, maxByteLen));
64 0 : ASCENDC_CHECK(CommonCheck());
65 0 : ASCENDC_CHECK(CheckTensorSize(maskArray));
66 : TensorOverflowParams params = {
67 0 : param_.srcSize,
68 0 : param_.srcDtypeBytes,
69 0 : static_cast<uint64_t>(param_.repeatTimes),
70 : static_cast<uint64_t>(DEFAULT_BLK_STRIDE),
71 0 : static_cast<uint64_t>(param_.srcRepStride),
72 0 : false};
73 0 : ASCENDC_CHECK(CheckTensorOverflowLow(maskArray, params, "srcLocal"));
74 0 : return true;
75 : }
76 0 : bool TikcppVecScatterCheck::CheckAddrAlign()
77 : {
78 0 : bool dstRes = CheckTensorAddrAlign(param_.dstAddr, param_.dstPos, ONE_BLK_SIZE, "dst");
79 0 : bool srcRes = CheckTensorAddrAlign(param_.srcAddr, param_.srcPos, ONE_BLK_SIZE, "src");
80 0 : bool dstOffsetRes = CheckTensorAddrAlign(param_.dstOffsetAddr, param_.dstOffsetPos, ONE_BLK_SIZE, "dstOffset");
81 0 : return dstRes && srcRes && dstOffsetRes;
82 : }
83 :
84 0 : bool TikcppVecScatterCheck::CheckAllHighLevel()
85 : {
86 0 : ASCENDC_CHECK(CommonCheck());
87 0 : ASCENDC_CHECK(CheckTensorOverflowHigh(param_.dstDtypeBytes, param_.dstSize, param_.count, "dstLocal"));
88 0 : ASCENDC_CHECK(CheckTensorOverflowHigh(param_.srcDtypeBytes, param_.srcSize, param_.count, "srcLocal"));
89 0 : ASCENDC_CHECK(
90 : CheckTensorOverflowHigh(param_.dstOffsetDtypeBytes, param_.dstOffsetSize, param_.count, "dstOffsetLocal"));
91 0 : return true;
92 : }
93 : } // namespace check
94 : } // namespace AscendC
|