CANN/GE UT测试用例开发指南

发布时间:2026/9/10 21:04:20

CANN/GE UT测试用例开发指南 UT Case Development Guide【免费下载链接】geGEGraph Engine是面向昇腾的图编译器和执行器提供了计算图优化、多流并行、内存复用和模型下沉等技术手段加速模型执行效率减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/geReturn to DT Test Case Development GuideUTs testing scope is a file. Theoretically, a UT should test the interfaces exposed by a file and validate behaviors belonging to the tested file. During testing, UT cases should assumeother files behaviors are correct and only validate the tested files behavior.UT Case DesignWhen designing test points for an interface, pay attention to the following points. These points form a checklist. If not applicable or considered unnecessary to validate, you can skip designing corresponding cases:Error value validation, for exampleInput parameter null pointerOut of specification rangeBoundary value validation, for exampleIf input involves Tensor, consider empty Tensor scenariosIf the tested module involves container concepts (e.g., can add or manage multiple elements), then need to additionally consider the following factorsInsertion occurs at the beginning, middle, or end of the containerDeletion occurs at the beginning, middle, or end of the containerHow to ValidateDo Complete ValidationUT cases should perform complete validation of the called functions return values and output parameters according to design. If the called function produces side effects, then complete validation of side effects should be done. Complete validation means all observable change points from the outside should be validated.A typical mistake is only validating the tested functions return value. Such cases have extremely limited value and should be avoided.Avoid Repeated ValidationCases should avoid repeated validation, which means the same type of validation should not appear in multiple different cases. The main problem with repeated validation is that it increases case maintenance difficulty. When modifying a modules behavior, it causes multiple cases to fail.Graph Class UT Validation PointsGraph modification and graph construction class UTs need to pay attention to graph changes, for example:New node checkDeleted node checkChanged edge checkChanged attribute checkTaking CEMs basic UT as an example, CEM (Constant Expression Motion) acts on execution graphs, moving invariant expressions in each computation in the Main graph to the Init graph to accelerate Main graph execution speed. In the following case, a Main Graph is constructed as shown in the comments, and its expected that through a Pass, two Consts and one Foo1 in the Main graph will be moved to the Init graph:/* * main graph: * * NetOutput * | * Foo2 * / \ * Foo1 data * / \ * const const */ TEST_F(ConstantExpressionsMotionUT, MoveToInit_Success_CeOnMain) { auto c1 ValueHolder::CreateConst(Hello, 5, true); auto c2 ValueHolder::CreateConst(World, 5, true); auto data ValueHolder::CreateFeed(0); auto foo1 ValueHolder::CreateSingleDataOutput(Foo, {c1, c2}); auto foo2 ValueHolder::CreateSingleDataOutput(Foo, {foo1, data}); auto main_frame ValueHolder::PopGraphFrame({foo2}, {}, NetOutput); auto root_frame ValueHolder::PopGraphFrame(); ASSERT_NE(root_frame, nullptr); ASSERT_NE(main_frame, nullptr); bool changed false; LoweringGlobalData global_data; ASSERT_EQ(ConstantExpressionMotion(global_data).Run(root_frame-GetExecuteGraph().get(), changed), ge::GRAPH_SUCCESS); ASSERT_TRUE(changed); EXPECT_EQ(ExeGraphSummaryChecker(main_frame-GetExecuteGraph().get()) .StrictDirectNodeTypes( std::mapstd::string, size_t{{Data, 1}, {Foo, 1}, {InnerData, 1}, {NetOutput, 1}}), success); EXPECT_EQ(ExeGraphSummaryChecker(init_frame_-GetExecuteGraph().get()) .StrictDirectNodeTypes(std::mapstd::string, size_t{{Const, 2}, {Foo, 1}, {InnerNetOutput, 1}}), success); EXPECT_EQ(de_init_frame_-GetExecuteGraph()-GetDirectNodesSize(), 0); ConnectFromInitToMain(foo1-GetFastNode(), 0, foo2-GetFastNode(), 0); changed false; ASSERT_EQ(ConstantExpressionMotion(global_data).Run(root_frame-GetExecuteGraph().get(), changed), ge::GRAPH_SUCCESS); ASSERT_FALSE(changed); }rt2 Kernel Class UT Validation PointsKernel Function ScopeKernel in RT2 refers to a collection of runtime functions registered for execution nodes, currently including:Kernel execution functions registered through .RunFunc, i.e., the computation logic of execution nodesExecution node output creation and initialization functions registered through .OutputsCreatorFuncNote: The .OutputsInitializer and .OutputsCreator registration interfaces in early versions have been deprecated.Node custom execution information assembly interfaces registered through .TracePrinterThis interface is called after node execution ends, returning context information the node type cares about, for framework node execution trace information printing.Kernel functions only serve execution nodes. Their function signatures are not readable and should typically be set as anonymous functions.Kernel Function UT Testing StrategyUT testing of Kernel is testing of runtime-related functions of a certain execution node, which should start from the execution node, not directly calling Kernel functions.Some cases export unreadable kernel function signatures for calling in UT, which puts the cart before the horse.The framework guarantees that when calling Kernel-related functions, input/output any value memory has been correctly allocated. When coding Kernel functions, you can perform ASSERT defensive validation on input/output any values, but its not recommended to do separate UT tests on them: dont test Kernel behavior when a certain input any value is empty.Such cases in current code are usually named input exception with expected execution failure. But they dont stand up to scrutiny, like why only test one exception input scenario and not test returns under different exception combinations? The famous saying partial proof equals zero illustrates the meaninglessness of such validation.Kernel Function Test Point DescriptionYou may need to pay attention to the related description of TracePrinter function in test point 4Test Point 1: Can correctly query registered Kernel series functions according to execution node typeauto funcs registry.FindKernelFuncs(YourTestingOpType); ASSERT_NE(funcs, nullptr); ASSERT_NE(funcs-outputs_creator, nullptr); // Validate based on whether registered ASSERT_EQ(funcs-outputs_creator(nullptr, context), ge::GRAPH_SUCCESS); // Validate based on whether registered ASSERT_NE(context-GetOutputPointerShape(0), nullptr); // Validate based on whether registeredTest Point 2: Test execution nodes OutputsCreatorFunc functionIf the execution node registered OutputsCreatorFunc, then UT test the OutputsCreatorFunc function. Usually only need to test that OutputsCreatorFuncs return value is correct.ASSERT_NE(funcs-outputs_creator, nullptr); ASSERT_EQ(funcs-outputs_creator(nullptr, context), ge::GRAPH_SUCCESS);We suggest only writing one case to validate OutputsCreatorFunc normal execution based on the following considerations:Correct interface return means all creation and initialization actions are complete, validation of created content is redundantValidation of created content is insufficient and untrustworthy, because type cannot be validated from pointers stored in any value objectsTest Point 3: Test execution nodes Kernel execution functionThis part needs to design reasonable test cases according to Kernel execution function implementation. But need to clarify case boundaries: Before calling Kernel execution function, need to ensure KernelContext input/output any value memory has been correctly created and OutputsCreatorFunc registration function called (if any). These two parts are test preconditions.TEST_F(BuildTensorUT, SplitTensor_Host) { auto tensor_holder TensorFaker().Shape({10, 20}).Format(ge::FORMAT_ND).Placement(kOnHost).Build(); auto context_holder KernelRunContextFaker() .KernelIONum(2, static_castsize_t(kernel::SplitTensorOutputs::kNum)) .NodeIoNum(1, 1) .Inputs({tensor_holder.GetTensor(), gert_allocator}) .Build(); auto run_context context_holder.GetContextKernelContext(); auto funcs registry.FindKernelFuncs(kernel::kSplitDataTensor); ASSERT_NE(funcs, nullptr); ASSERT_EQ(funcs-outputs_creator(FastNodeFaker().Build(), run_context), ge::GRAPH_SUCCESS); ASSERT_EQ(funcs-run_func(run_context), ge::GRAPH_SUCCESS); // Call execution function // check tensor data auto tensor_data_chain run_context-GetOutput(static_castsize_t(kernel::SplitTensorOutputs::kTensorData)); // Get output and validate result ASSERT_NE(tensor_data_chain, nullptr); EXPECT_TRUE(tensor_data_chain-HasDeleter()); auto tensor_data tensor_data_chain-GetPointerGertTensorData(); ASSERT_NE(tensor_data, nullptr); EXPECT_EQ(tensor_data-GetAddr(), tensor_holder.GetTensor()-GetAddr()); // check shape auto shape run_context-GetOutputPointerStorageShape(static_castsize_t(kernel::SplitTensorOutputs::kShape)); ASSERT_NE(shape, nullptr); EXPECT_EQ(*shape, tensor_holder.GetTensor()-GetShape()); context_holder.FreeAll(); }Note: If youre writing a case expecting Kernel execution function to fail, please be cautious: Is this a real runtime input scenario? If not, its easy to fall into the partial proof quagmire -- why not test all exception input combinations. Even if you list all exception combinations, youll fall into another quagmire of case count explosion.We can do some BUG scenario ASSERT defensive validation inside Kernel execution function, but shouldnt do separate UT tests on it.Test Point 4: Test TracePrinter functionTracePrinter functions functionality is to collect required execution information from context. In call sequence, it occurs after Kernel execution function call.Special note: Under current execution logic, even if Kernel execution function returns error, this function will still be called. Therefore, function implementation needs extra care for Kernel output processing, must strictly match Kernel execution function. Under current call timing not modified and unable to know execution result, developers need to carefully implement TracePrinter function to ensure no runtime errors occur when Kernel execution function exits abnormally, even though this is hard to implement. In the future, this functions call timing will likely be modified, or execution result information will be passed when calling.Based on current call timing, we only suggest two parts of testing for TracePrinter:Test case 1: Test return information after Kernel execution function executes normallyregistry.FindKernelFuncs(LaunchKernelWithFlag)-run_func(context.WithFlag()) auto ret registry.FindKernelFuncs(LaunchKernelWithFlag)-trace_printer(context.WithFlag()); EXPECT_FALSE(ret.empty());Note: This test is insufficient, assuming that when handling execution function errors, no modifications are made to output, which is usually not true.Test case 2: Simulate and test return information when Kernel execution function is abnormal (TBD)Construct -run_func() failure scenario, then call -trace_printer method【免费下载链接】geGEGraph Engine是面向昇腾的图编译器和执行器提供了计算图优化、多流并行、内存复用和模型下沉等技术手段加速模型执行效率减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/ge创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
延伸阅读

更多相关文章

2026/9/10 20:59:20

Compute Exchange推出GPU库存管理工具简化AI基建采购

美国初创公司Compute Exchange Inc.专注于撮合图形处理器买卖双方交易,该公司近日推出一项GPU库存管理功能,旨在为企业买家提供跨100多家供应商的可用及即将上线AI计算能力的整合视图。这项新功能是对公司现有询价市场的扩展,让买家能够浏览当…

2026/9/10 20:59:20

Java Telegram Bot API支付系统集成教程:从发送发票到处理预结账

Java Telegram Bot API支付系统集成教程:从发送发票到处理预结账 Java Telegram Bot API是一款功能强大的工具,能帮助开发者轻松构建Telegram机器人并实现支付功能。本文将详细介绍如何使用该API集成支付系统,从发送发票到处理预结账&#x…

2026/9/10 21:54:30

基于改进灵敏度分析的有源配电网智能软开关优化配置

如果你做配电网优化,一定绕不开这个经典组合:有源配电网、智能软开关优化配置、IEEE33节点。这篇文章想把一条完整的技术路线理清楚——从基于改进灵敏度分析的选址定位,到Matlab代码实现,再到算例结果对照,把“为什么…

2026/9/10 21:54:29

1月22日内容创作指南:节气、盘点与营销策略

1. 项目背景解析"1月22日"这个看似简单的日期标题,实际上蕴含着丰富的创作可能性。作为内容创作者,我们需要挖掘这个特定日期背后的多维价值。从节气时令到历史事件,从文化习俗到商业节点,每个日期都是独特的时空坐标&a…

2026/9/10 21:49:29

Continue 如何在 VS Code 中配置 Next Edit 下一步编辑预测?

Continue 如何在 VS Code 中配置 Next Edit 下一步编辑预测? 【免费下载链接】continue open-source coding agent 项目地址: https://gitcode.com/GitHub_Trending/co/continue Next Edit 是 Continue 的一个实验性功能:它会分析你最近的编辑历史…

2026/9/10 16:39:38

超人会飞不算本事:系统稳定依赖清晰规则与边界设计

开头先不绕弯子。“#斯坦李吐槽dc 所以超人是无缘无故会飞的嘛哈哈哈哈哈哈哈锤哥真是技术人才啊!#雷神 #复联”这类调侃式短标题,第一波冲击力在于它把两个宇宙的角色塞进同一个吐槽箱里,但细想一下就能发现,它真正碰到的根本不是…

2026/9/10 11:16:38

超人VS蜘蛛侠:拆解超级IP的影响力与传播方法论

把“蜘蛛侠 vs 超人”放在 CSDN 上聊,可能很多人第一反应是走错片场了。但如果把这两个角色看成“两个持续运营了 80 多年的文化产品”,你会发现,这场比较本质上是两个不同 IP 策略的长期结果对比:超人赢在定义了整个超级英雄题材…

2026/9/9 16:31:09

基于CNN的调制信号识别:MATLAB实现时频图分类实战

简介:本资源是一套面向通信工程与信号处理方向学习者、研究者的深度学习实践方案,聚焦调制信号自动检测与识别这一典型无线通信任务,解决传统方法依赖人工特征、低信噪比下性能下降等痛点。压缩包共12个文件(10.73MB)&…

2026/9/10 0:00:55

目录对比去重实战:用哈希算法精准清理重复文件

我电脑里现在还有一块换了三次机的“数据墓地”硬盘,里面存着2016年以前所有旧笔记本的完整备份。平时不觉得有什么,直到前阵子想把它整理归档,发现同一个安装包、同一批照片、同一份论文草稿,在几个不同的备份目录里反复出现。更…

2026/9/10 0:00:55

Leaflet离线地图完整Demo合集:内网部署与坐标纠偏实战

简介:这是一份面向Web GIS开发者的LeafLet离线地图示例合集,帮助开发者快速掌握离线地图从搭建到交互的完整流程。压缩包共723个文件,大小14.06MB,以319个js脚本、175个html页面和29个css样式文件为主体,配合png/svg图…

2026/9/10 0:00:55

MATLAB读取Rinex 3.02观测文件:多系统GNSS数据解析实战

简介:基于MATLAB开发的Rinex3.02版观测文件(o文件)读取代码包,面向卫星定位导航方向的学习者与研究人员,用于解决新版观测文件的数据解析、历元提取与时间转换问题。压缩包共4个文件,包含两个m脚本、一个19…

2026/9/10 12:32:02

USB Type-C PCB布局分区设计:电源、高速信号与PD协议全攻略

做硬件这行,Type-C接口算是典型的“看着简单,做起来全坑”的东西。光引脚就24个,高低速信号、电源、控制线全部塞在一个小小的连接器里,如果PCB布局不做规划,打样回来基本就是“插上没反应”、“高速掉线”、“静电一打…

2026/9/10 15:19:50

系统编程学习原型如何补齐稳定性边界

系统编程学习原型如何补齐稳定性边界预算有限时&#xff0c;我先优化明显多余的复制&#xff0c;而不是猜测性地换容器。用借用传递只读数据通常就能减少分配&#xff1a; fn parse(line: &str) -> Result<Item, Error> { /* ... */ }用基准确认热点确实在分配&am…

2026/9/10 15:49:53

雨花区哪家财务公司代理记账比较好?

在雨花区&#xff0c;企业处理财税事务常常面临诸多挑战&#xff0c;选择一家靠谱的财务公司至关重要。湖南巨勤财务管理咨询有限公司就是本地正规实体财税服务机构&#xff0c;深耕本地工商财税行业多年&#xff0c;熟悉当地工商局、税务局最新政策与申报流程。主营公司注册、…

还想了解更多?直接咨询顾问

免费诊断 + 免费方案 + 透明报价。

全国咨询热线400-8866-253
免费获取方案
咨询二维码