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_bilinearinterpolation_check.cpp
13 : * \brief
14 : */
15 :
16 : #include "kernel_check_params.h"
17 : #include "kernel_vec_bilinearinterpolation_check.h"
18 :
19 : namespace AscendC {
20 : namespace check {
21 :
22 : const uint64_t ELE_PER_REPEAT = 8; // 1 repeat && repeatMode = 1 -> 8 src1 elements
23 :
24 0 : bool TikcppVecBilinearInterpolationCheck::CheckTensorSize(std::vector<uint64_t> maskArray)
25 : {
26 0 : uint8_t n = param_.hRepeat;
27 0 : uint8_t m = param_.vRepeat;
28 : // max element calculated in a repeat
29 0 : uint64_t maskVal = (maskArray.size() == 1) ? maskArray[0] : GetMaskLength(maskArray, param_.src0DtypeBytes);
30 :
31 : // src0OffsetLocal: total: m * n block, but last block is related to maskVal
32 0 : uint64_t eleNumPerOffset = ONE_BLK_SIZE / param_.src0DtypeBytes; // each offset element -> element in src0
33 : // example: maskVal = 17, dtype = half, thus offset needs at least 2 elements to pick blocks in src0
34 0 : uint64_t offsetNumPerRep = (maskVal + eleNumPerOffset - 1) / eleNumPerOffset;
35 0 : uint64_t expectedSize = (m * n - 1) * ONE_BLK_SIZE + offsetNumPerRep * param_.offsetDtypeBytes;
36 0 : ASCENDC_CHECK(CheckTensorSizeOverflow(expectedSize, param_.offsetSize, "src0OffsetLocal", "BilinearInterpolation"));
37 :
38 : // src0Local: needs to read values in src0OffsetLocal. Thus make optimistic check
39 : // example: maskVal = 7, only need 7 elements at most; maskVal = 16, probably src0Local all points to same block
40 0 : expectedSize = (maskVal <= eleNumPerOffset) ? maskVal * param_.src0DtypeBytes : ONE_BLK_SIZE;
41 0 : ASCENDC_CHECK(CheckTensorSizeOverflow(expectedSize, param_.src0Size, "src0Local", "BilinearInterpolation"));
42 :
43 : // src1Local: similar to src0Offset
44 0 : expectedSize = (param_.repeatMode) ? ELE_PER_REPEAT * (m * n - 1) + offsetNumPerRep : m * n; // in unit of elements
45 0 : ASCENDC_CHECK(CheckTensorSizeOverflow(
46 : expectedSize * param_.src1DtypeBytes, param_.src1Size, "src1Local", "BilinearInterpolation"));
47 :
48 : // dstLocal:
49 0 : uint64_t blockLen = ONE_BLK_SIZE / param_.dstDtypeBytes; // ele num in one block
50 0 : uint64_t blkNumLastRep = DivCeil(maskVal, blockLen); // last repeat needs x blocks for maskLen elements
51 0 : uint64_t eleNumLastBlk = ((maskVal % blockLen) != 0) ? (maskVal % blockLen) : blockLen;
52 0 : uint64_t dstLastRepStart = (m - 1) * param_.vROffset; // unit of elem
53 0 : uint64_t dstLastRepEleNum = (blkNumLastRep - 1) * param_.dstBlockStride * blockLen + eleNumLastBlk; // unit of elem
54 0 : expectedSize = (dstLastRepStart + dstLastRepEleNum) * param_.dstDtypeBytes;
55 0 : ASCENDC_CHECK(CheckTensorSizeOverflow(expectedSize, param_.dstSize, "dstLocal", "BilinearInterpolation"));
56 0 : return true;
57 : }
58 :
59 0 : bool TikcppVecBilinearInterpolationCheck::CheckAllLowLevel(std::vector<uint64_t> maskArray)
60 : {
61 0 : uint32_t maxByteLen = std::max(std::max(param_.dstDtypeBytes, param_.src0DtypeBytes), param_.src1DtypeBytes);
62 0 : ASCENDC_CHECK(UpdateMaskArrayAndCheck(maskArray, maxByteLen));
63 :
64 0 : const std::string supportPos = "VECIN/VECOUT/VECCALC";
65 0 : ASCENDC_CHECK(
66 : CheckTensorScope(param_.dstLogicPos, static_cast<uint8_t>(HardWareIndex::UB), "dstLocal", supportPos));
67 0 : ASCENDC_CHECK(
68 : CheckTensorScope(param_.src0LogicPos, static_cast<uint8_t>(HardWareIndex::UB), "src0Local", supportPos));
69 0 : ASCENDC_CHECK(CheckTensorScope(
70 : param_.offsetLogicPos, static_cast<uint8_t>(HardWareIndex::UB), "src0OffsetLocal", supportPos));
71 0 : ASCENDC_CHECK(
72 : CheckTensorScope(param_.src1LogicPos, static_cast<uint8_t>(HardWareIndex::UB), "src1Local", supportPos));
73 :
74 0 : ASCENDC_CHECK(CheckTensorAddrAlign(param_.dstAddr, param_.dstPos, ONE_BLK_SIZE, "dstLocal"));
75 0 : ASCENDC_CHECK(CheckTensorAddrAlign(param_.src0Addr, param_.src0Pos, ONE_BLK_SIZE, "src0Local"));
76 0 : ASCENDC_CHECK(CheckTensorAddrAlign(param_.offsetAddr, param_.offsetPos, ONE_BLK_SIZE, "src0OffsetLocal"));
77 0 : ASCENDC_CHECK(CheckTensorAddrAlign(param_.src1Addr, param_.src1Pos, ONE_BLK_SIZE, "src1Local"));
78 :
79 0 : ASCENDC_CHECK(CheckBufferSizeOverFlow(
80 : param_.src0Size, GlobalParams::Instance().bufferSizeMap.at(param_.src0Pos),
81 : "Failed to check src0Local tensor buffersize"));
82 0 : ASCENDC_CHECK(CheckBufferSizeOverFlow(
83 : param_.src1Size, GlobalParams::Instance().bufferSizeMap.at(param_.src1Pos),
84 : "Failed to check src1Local tensor buffersize"));
85 0 : ASCENDC_CHECK(CheckBufferSizeOverFlow(
86 : param_.offsetSize, GlobalParams::Instance().bufferSizeMap.at(param_.offsetPos),
87 : "Failed to check src0OffsetLocal tensor buffersize"));
88 0 : ASCENDC_CHECK(CheckBufferSizeOverFlow(
89 : param_.dstSize, GlobalParams::Instance().bufferSizeMap.at(param_.dstPos),
90 : "Failed to check dstLocal tensor buffersize"));
91 :
92 0 : ASCENDC_CHECK(CheckTensorSize(maskArray));
93 0 : return true;
94 0 : }
95 :
96 : } // namespace check
97 : } // namespace AscendC
|