kali20gakki/msAgent / skills/operator/msdebug-basic-usage
msdebug-basic-usage
Verified昇腾AscendC算子调试工具(msDebug)技能,含两大流程:①上板调试——算子加 -g -O0 编译后由 msdebug 拉起,支持断点、单步、变量/内存打印、核切换、寄存器读取;②coredump解析——用户指定 core 文件路径后,msdebug 加载解析挂掉代码行/异常调用栈/现场变量。触发关键词:msdebug、算子调试、上板调试、断点、单步调试、打印变量、读内存、核切换、寄存器、coredump、core文件、调用栈、崩溃解析
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 12.3 KB |
| evals/evals.json | config | 11.8 KB |
| references/official_workflow.md | markdown | 11.6 KB |
| references/sample_coredump/CMakeLists.txt | markdown | 1.3 KB |
| references/sample_coredump/README.md | markdown | 8.5 KB |
| references/sample_coredump/add.asc | other | 6.8 KB |
| references/sample_coredump/data_utils.h | other | 2.7 KB |
| references/sample_coredump/scripts/gen_data.py | script | 2.1 KB |
| references/sample_coredump/scripts/verify_result.py | script | 3.8 KB |
| references/sample_debug/CMakeLists.txt | markdown | 1.2 KB |
| references/sample_debug/README.md | markdown | 11.3 KB |
| references/sample_debug/debug.asc | other | 4.4 KB |
references/sample_coredump/add.asc
View on GitHub/**
* Copyright (c) 2026 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.
*/
/* !
* \file add.asc
* \brief 双缓冲向量加法算子 coredump 调试样例,演示 msdebug 对 AI Core 崩溃的定位
*/
#include <cstdint>
#include <iostream>
#include <vector>
#include "acl/acl.h"
#include "kernel_operator.h"
#include "data_utils.h"
#define CHECK_ACL(call, msg) do { \
aclError _err = (call); \
if (_err != ACL_SUCCESS) { \
std::cerr << "[ERROR] " << msg << " failed, ret=" << _err << std::endl; \
ret = 1; \
goto cleanup; \
} \
} while(0)
struct TilingParam {
uint32_t coreLen;
};
namespace {
constexpr uint32_t tileSize = 4096;
}
class DoubleBufAdd {
public:
__aicore__ inline DoubleBufAdd() = default;
__aicore__ inline void Init(GM_ADDR a, GM_ADDR b, GM_ADDR c, uint32_t coreLen)
{
gmA.SetGlobalBuffer((__gm__ float *)a + AscendC::GetBlockIdx() * coreLen, coreLen);
gmB.SetGlobalBuffer((__gm__ float *)b + AscendC::GetBlockIdx() * coreLen, coreLen);
gmC.SetGlobalBuffer((__gm__ float *)c + AscendC::GetBlockIdx() * coreLen, coreLen);
numTiles = coreLen / tileSize;
}
__aicore__ inline void Process()
{
AscendC::LocalMemAllocator<AscendC::Hardware::UB> ubAlloc;
// ping buffer
AscendC::LocalTensor<float> bufA0 = ubAlloc.Alloc<float, tileSize>();
AscendC::LocalTensor<float> bufB0 = ubAlloc.Alloc<float, tileSize>();
AscendC::LocalTensor<float> bufC0 = ubAlloc.Alloc<float, tileSize>();
// pong buffer
AscendC::LocalTensor<float> bufA1 = ubAlloc.Alloc<float, tileSize>();
AscendC::LocalTensor<float> bufB1 = ubAlloc.Alloc<float, tileSize>();
AscendC::LocalTensor<float> bufC1 = ubAlloc.Alloc<float, tileSize>();
// double buffer pipeline
AscendC::SetFlag<AscendC::HardEvent::MTE3_MTE2>(EVENT_ID0);
AscendC::SetFlag<AscendC::HardEvent::MTE3_MTE2>(EVENT_ID1);
for (uint32_t i = 0; i < numTiles; i++) {
int32_t eventID = (i % 2 == 0 ? EVENT_ID0 : EVENT_ID1);
AscendC::LocalTensor<float> &bufA = (i % 2 == 0 ? bufA0 : bufA1);
AscendC::LocalTensor<float> &bufB = (i % 2 == 0 ? bufB0 : bufB1);
AscendC::LocalTensor<float> &bufC = (i % 2 == 0 ? bufC0 : bufC1);
AscendC::WaitFlag<AscendC::HardEvent::MTE3_MTE2>(eventID);
AscendC::DataCopy(bufA, gmA[i * tileSize], tileSize);
AscendC::DataCopy(bufB, gmB[i * tileSize], tileSize);
AscendC::SetFlag<AscendC::HardEvent::MTE2_V>(eventID);
AscendC::WaitFlag<AscendC::HardEvent::MTE2_V>(eventID);
AscendC::Add(bufC, bufA, bufB, tileSize);
AscendC::SetFlag<AscendC::HardEvent::V_MTE3>(eventID);
AscendC::WaitFlag<AscendC::HardEvent::V_MTE3>(eventID);
// 注入异常:+100000000 偏移导致越界写入,触发 MTE_ERROR
AscendC::DataCopy(gmC[i * tileSize + 100000000], bufC, tileSize);
AscendC::SetFlag<AscendC::HardEvent::MTE3_MTE2>(eventID);
}
AscendC::WaitFlag<AscendC::HardEvent::MTE3_MTE2>(EVENT_ID0);
AscendC::WaitFlag<AscendC::HardEvent::MTE3_MTE2>(EVENT_ID1);
}
private:
AscendC::GlobalTensor<float> gmA;
AscendC::GlobalTensor<float> gmB;
AscendC::GlobalTensor<float> gmC;
uint32_t numTiles;
};
__global__ __vector__ void add_demo(GM_ADDR a, GM_ADDR b, GM_ADDR c, GM_ADDR tiling)
{
AscendC::InitSocState();
DoubleBufAdd op;
op.Init(a, b, c, ((__gm__ TilingParam *)tiling)->coreLen);
op.Process();
}
int32_t main(int32_t argc, char *argv[])
{
uint32_t numBlocks = 8;
uint32_t dataLen = 4096 * 9 * numBlocks;
size_t inputBytes = dataLen * sizeof(float);
size_t outputBytes = dataLen * sizeof(float);
TilingParam tiling;
tiling.coreLen = dataLen / numBlocks;
int32_t ret = 0;
uint8_t *tilingDev = nullptr;
uint8_t *hostA = nullptr, *hostB = nullptr, *hostC = nullptr;
uint8_t *devA = nullptr, *devB = nullptr, *devC = nullptr;
aclrtStream stream = nullptr;
aclInit(nullptr);
int32_t deviceId = 0;
CHECK_ACL(aclrtSetDevice(deviceId), "aclrtSetDevice");
CHECK_ACL(aclrtCreateStream(&stream), "aclrtCreateStream");
// tiling
CHECK_ACL(aclrtMalloc((void **)(&tilingDev), sizeof(TilingParam), ACL_MEM_MALLOC_HUGE_FIRST), "aclrtMalloc tilingDev");
CHECK_ACL(aclrtMemcpy(tilingDev, sizeof(TilingParam), &tiling, sizeof(TilingParam), ACL_MEMCPY_HOST_TO_DEVICE),
"aclrtMemcpy H2D tiling");
// inputs
CHECK_ACL(aclrtMallocHost((void **)(&hostA), inputBytes), "aclrtMallocHost hostA");
CHECK_ACL(aclrtMallocHost((void **)(&hostB), inputBytes), "aclrtMallocHost hostB");
CHECK_ACL(aclrtMalloc((void **)(&devA), inputBytes, ACL_MEM_MALLOC_HUGE_FIRST), "aclrtMalloc devA");
CHECK_ACL(aclrtMalloc((void **)(&devB), inputBytes, ACL_MEM_MALLOC_HUGE_FIRST), "aclrtMalloc devB");
size_t fileSize;
if (!ReadFile("./input/input_x.bin", fileSize, hostA, inputBytes)) {
std::cerr << "[ERROR] ReadFile input_x.bin failed" << std::endl;
ret = 1;
goto cleanup;
}
if (!ReadFile("./input/input_y.bin", fileSize, hostB, inputBytes)) {
std::cerr << "[ERROR] ReadFile input_y.bin failed" << std::endl;
ret = 1;
goto cleanup;
}
CHECK_ACL(aclrtMemcpy(devA, inputBytes, hostA, inputBytes, ACL_MEMCPY_HOST_TO_DEVICE), "aclrtMemcpy H2D devA");
CHECK_ACL(aclrtMemcpy(devB, inputBytes, hostB, inputBytes, ACL_MEMCPY_HOST_TO_DEVICE), "aclrtMemcpy H2D devB");
// output
CHECK_ACL(aclrtMallocHost((void **)(&hostC), outputBytes), "aclrtMallocHost hostC");
CHECK_ACL(aclrtMalloc((void **)(&devC), outputBytes, ACL_MEM_MALLOC_HUGE_FIRST), "aclrtMalloc devC");
add_demo<<<numBlocks, nullptr, stream>>>(devA, devB, devC, tilingDev);
CHECK_ACL(aclrtSynchronizeStream(stream), "aclrtSynchronizeStream");
CHECK_ACL(aclrtMemcpy(hostC, outputBytes, devC, outputBytes, ACL_MEMCPY_DEVICE_TO_HOST), "aclrtMemcpy D2H");
WriteFile("./output/output.bin", hostC, outputBytes);
cleanup:
aclrtFree(tilingDev);
aclrtFree(devA); aclrtFree(devB); aclrtFree(devC);
aclrtFreeHost(hostA); aclrtFreeHost(hostB); aclrtFreeHost(hostC);
if (stream != nullptr) aclrtDestroyStream(stream);
aclrtResetDevice(deviceId);
aclFinalize();
return ret;
}
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 192k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 192k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 192k | Updated | Claude CodeCodex | Verified | Install |