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 : #include <atomic>
11 : #include "acl_dump.h"
12 : #include "adump_pub.h"
13 : #include "adump_api.h"
14 : #include "dump_manager.h"
15 : #include "dump_printf.h"
16 : #include "adump_error_manager.h"
17 : #include "str_utils.h"
18 :
19 : namespace Adx {
20 : uint64_t g_chunk[RING_CHUNK_SIZE + MAX_TENSOR_NUM] = {0};
21 : bool g_setAssert = false;
22 : static std::mutex g_setAssertMtx;
23 : namespace {
24 : uint32_t g_atomicIndex = 0x2000;
25 : std::atomic<uint64_t> g_writeIdx{0};
26 : } // namespace
27 :
28 45022 : void *AdumpGetSizeInfoAddr(uint32_t space, uint32_t &atomicIndex)
29 : {
30 45022 : if (!g_setAssert) {
31 3 : const std::lock_guard<std::mutex> lock(g_setAssertMtx);
32 3 : if (!g_setAssert) {
33 3 : (void)rtSetTaskFailCallback(AdxAssertCallBack);
34 3 : g_setAssert = true;
35 : }
36 3 : }
37 45022 : if (space > MAX_TENSOR_NUM) {
38 3 : return nullptr;
39 : }
40 :
41 45019 : atomicIndex = g_atomicIndex++;
42 45019 : auto nextWriteCursor = g_writeIdx.fetch_add(space);
43 45019 : return g_chunk + (nextWriteCursor % RING_CHUNK_SIZE);
44 : }
45 :
46 18 : int32_t AdumpRegisterCallback(uint32_t moduleId, AdumpCallback enableFunc, AdumpCallback disableFunc)
47 : {
48 18 : return DumpManager::Instance().RegisterCallback(moduleId, enableFunc, disableFunc);
49 : }
50 :
51 24 : int32_t AdumpSaveToFile(const char *data, size_t dataLen, const char *filename, SaveType type)
52 : {
53 24 : return DumpManager::Instance().SaveFile(data, dataLen, filename, type);
54 : }
55 : } // namespace Adx
56 :
57 : /**
58 : * @ingroup AscendCL
59 : * @brief Enable the dump function of the corresponding dump type.
60 : *
61 : * @param dumpType [IN] type of dump
62 : * @param path [IN] dump path
63 : *
64 : * @retval ACL_SUCCESS The function is successfully executed.
65 : * @retval OtherValues Failure
66 : */
67 30 : aclError aclopStartDumpArgs(uint32_t dumpType, const char *path)
68 : {
69 30 : if (path == nullptr) {
70 54 : REPORT_EP0007_NULL_POINTER(
71 : Adx::FUNC_NAME_ACL_OP_START_DUMP_ARGS, Adx::FUNC_ACL_OP_START_DUMP_ARGS_PARAM_PATH);
72 3 : return ACL_ERROR_FAILURE;
73 : }
74 :
75 27 : if ((dumpType & ACL_OP_DUMP_OP_AICORE_ARGS) != ACL_OP_DUMP_OP_AICORE_ARGS) {
76 6 : std::string dumpTypeStr = std::to_string(dumpType);
77 6 : std::string expTypeStr = std::to_string(ACL_OP_DUMP_OP_AICORE_ARGS);
78 : std::string reason = Adx::StrUtils::Format(
79 6 : Adx::ADUMP_REASON_RESERVED_PARAM_MUST_EQUAL, expTypeStr.c_str());
80 138 : REPORT_EP0006_INVALID_ARGUMENT(
81 : Adx::FUNC_NAME_ACL_OP_START_DUMP_ARGS, dumpTypeStr,
82 : Adx::FUNC_ACL_OP_START_DUMP_ARGS_PARAM_DUMPTYPE, reason);
83 6 : return ACL_ERROR_FAILURE;
84 6 : }
85 :
86 21 : std::string dumpPath(path);
87 21 : int32_t ret = Adx::DumpManager::Instance().StartDumpArgs(dumpPath);
88 21 : if (ret != 0) {
89 15 : return ACL_ERROR_FAILURE;
90 : }
91 :
92 6 : return ACL_SUCCESS;
93 33 : }
94 :
95 : /**
96 : * @ingroup AscendCL
97 : * @brief Disable the dump function of the corresponding dump type.
98 : *
99 : * @param dumpType [IN] type of dump
100 : *
101 : * @retval ACL_SUCCESS The function is successfully executed.
102 : * @retval OtherValues Failure
103 : */
104 15 : aclError aclopStopDumpArgs(uint32_t dumpType)
105 : {
106 15 : if ((dumpType & ACL_OP_DUMP_OP_AICORE_ARGS) == ACL_OP_DUMP_OP_AICORE_ARGS) {
107 15 : if (Adx::DumpManager::Instance().StopDumpArgs() != 0) {
108 3 : return ACL_ERROR_FAILURE;
109 : }
110 : }
111 12 : return ACL_SUCCESS;
112 : }
113 :
114 : /**
115 : * @ingroup AscendCL
116 : * @brief Get Exception Dump path.
117 : *
118 : * @retval path for success
119 : * @retval NULL for failed
120 : */
121 12 : const char* acldumpGetPath(acldumpType dumpType)
122 : {
123 12 : switch (dumpType) {
124 6 : case acldumpType::AIC_ERR_BRIEF_DUMP:
125 : case acldumpType::AIC_ERR_NORM_DUMP:
126 : case acldumpType::AIC_ERR_DETAIL_DUMP:
127 6 : return Adx::DumpManager::Instance().GetExceptionDumpPath();
128 3 : case acldumpType::DATA_DUMP:
129 : case acldumpType::OVERFLOW_DUMP:
130 3 : return Adx::DumpManager::Instance().GetDataDumpPath();
131 3 : default:
132 3 : return nullptr;
133 : }
134 : }
|