Skip to content

Ascend/msagent / skills/operator/mssanitizer-basic-usage

mssanitizer-basic-usage

Unverified

昇腾AscendC算子异常检测工具(msSanitizer)。检测内存越界、内存泄漏、数据竞争、未初始化读取、同步异常等缺陷。触发关键词:mssanitizer、sanitizer、检测工具、内存检测、竞争检测、初始化检测、同步检测

references/sample_initcheck/initcheck.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 initcheck.asc
 * \brief 算子未初始化检测样例,演示 mssanitizer 对算子读取未初始化内存异常的检测和定位
 */
#include "acl/acl.h"
#include "kernel_operator.h"

class UninitReadDemo {
public:
    __aicore__ inline UninitReadDemo() = default;
    __aicore__ inline void Init(GM_ADDR buf)
    {
        srcGlobal.SetGlobalBuffer((__gm__ uint8_t*)buf, bufSize);
    }

    __aicore__ inline void Process()
    {
        AscendC::LocalMemAllocator<AscendC::Hardware::UB> ubAlloc;
        AscendC::LocalTensor<uint8_t> localBuf = ubAlloc.Alloc<uint8_t, bufSize>();

        // 从 Global Memory 读取数据,但 main() 中有意未初始化该内存
        AscendC::DataCopy(localBuf, srcGlobal, bufSize);
    }

private:
    constexpr static uint32_t bufSize = 256;
    AscendC::GlobalTensor<uint8_t> srcGlobal;
};

__global__ __vector__ void uninit_read_demo(GM_ADDR buf)
{
    AscendC::InitSocState();
    UninitReadDemo op;
    op.Init(buf);
    op.Process();
}

int32_t main(int32_t argc, char* argv[])
{
    constexpr uint32_t bufSize = 256;
    size_t bufBytes = bufSize * sizeof(uint8_t);

    aclInit(nullptr);

    int32_t deviceId = 0;
    aclrtSetDevice(deviceId);

    aclrtStream stream = nullptr;
    aclrtCreateStream(&stream);

    uint8_t* devBuf = nullptr;
    aclrtMalloc((void**)&devBuf, bufBytes, ACL_MEM_MALLOC_HUGE_FIRST);
    // 有意不对 devBuf 做初始化,算子内读取将触发未初始化告警

    uninit_read_demo<<<1, nullptr, stream>>>(devBuf);
    aclrtSynchronizeStream(stream);

    aclrtFree(devBuf);
    aclrtDestroyStream(stream);

    aclrtResetDevice(deviceId);
    aclFinalize();

    return 0;
}
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: 196kUpdated Claude CodeCodexVerifiedInstall
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: 192kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 192kUpdated Claude CodeCodexVerifiedInstall
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: 192kUpdated Claude CodeCodexVerifiedInstall