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_utils_ceil_oom_que.h
13 : * \brief
14 : */
15 : #ifndef ASCENDC_MODULE_UTILS_CEIL_OOM_QUE_H
16 : #define ASCENDC_MODULE_UTILS_CEIL_OOM_QUE_H
17 :
18 : #define USE_ISA_INS 1
19 : #define GM_ADDR __gm__ uint8_t*
20 : #if defined(__NPU_ARCH__) && ((__NPU_ARCH__ == 3510) || (__NPU_ARCH__ == 5102))
21 : #define UB_ADDR __ubuf__ uint8_t*
22 : #define SSBUF_ADDR __ssbuf__ uint32_t*
23 : #endif
24 :
25 : #ifndef likely
26 : #define likely(x) __builtin_expect(!!(x), 1)
27 : #endif
28 : #ifndef unlikely
29 : #define unlikely(x) __builtin_expect(!!(x), 0)
30 : #endif
31 :
32 : #include "kernel_macros.h"
33 : #include "kernel_log.h"
34 : #include "kernel_event.h"
35 : #if defined(ASCENDC_CPU_DEBUG) && ASCENDC_CPU_DEBUG == 1
36 : #include <set>
37 : #include <map>
38 : #include <sstream>
39 : #include <thread>
40 : #include <iomanip>
41 : #include "stub_def.h"
42 : #include "stub_fun.h"
43 : #endif // ASCENDC_CPU_DEBUG
44 :
45 : #if defined(__NPU_ARCH__) && ((__NPU_ARCH__ == 5102) || (__NPU_ARCH__ == 2103) || (__NPU_ARCH__ == 3003) || \
46 : (__NPU_ARCH__ == 3103) || (__NPU_ARCH__ == 3113) || (__NPU_ARCH__ == 3510))
47 :
48 : #if !defined(ASCENDC_CPU_DEBUG)
49 : using fp4x2_e2m1_t = float4_e2m1x2_t;
50 : using fp4x2_e1m2_t = float4_e1m2x2_t;
51 : using fp8_e5m2_t = float8_e5m2_t;
52 : using fp8_e4m3fn_t = float8_e4m3_t;
53 : using fp8_e8m0_t = float8_e8m0_t;
54 : #endif
55 : #endif
56 :
57 : #include <cstdint>
58 : #ifndef TILING_KEY_VAR
59 : #if defined(ASCENDC_CPU_DEBUG)
60 : extern uint64_t g_tilingKey;
61 : #else
62 : #if __NPU_ARCH__ == 2002
63 : [[block_local]] uint64_t g_tilingKey;
64 : #else
65 : [[workgroup_local]] __gm__ uint64_t g_tilingKey;
66 : #endif
67 : #endif
68 : #define TILING_KEY_VAR g_tilingKey
69 : #endif
70 :
71 : namespace AscendC {
72 :
73 240 : __aicore__ constexpr inline uint32_t DivCeil(uint32_t a, uint32_t b) { return (a + b - 1) / b; }
74 :
75 : __aicore__ constexpr inline uint32_t AlignUp(uint32_t a, uint32_t b) { return DivCeil(a, b) * b; }
76 :
77 : template <bool b>
78 : struct BoolInst {
79 : using Type = BoolInst<b>;
80 : static constexpr bool value = b;
81 : };
82 :
83 : using TrueType = BoolInst<true>;
84 : using FalseType = BoolInst<false>;
85 :
86 : template <typename T, typename U>
87 : struct IsSameType : public FalseType {};
88 :
89 : template <typename T>
90 : struct IsSameType<T, T> : public TrueType {};
91 :
92 : template <typename... Arg>
93 : struct Tuple {};
94 :
95 : template <typename T, typename U, typename... Args>
96 : __aicore__ constexpr bool SupportType()
97 : {
98 : if constexpr (sizeof...(Args) > 0) {
99 : return IsSameType<T, U>::value || SupportType<T, Args...>();
100 : }
101 : return IsSameType<T, U>::value;
102 : }
103 :
104 : } // namespace AscendC
105 :
106 : #endif // ASCENDC_MODULE_UTILS_CEIL_OOM_QUE_H
|