已合并
test: add_example kernel UT 补输入初始化与输出校验(修复 #27) #91
test: add_example kernel UT 补输入初始化与输出校验(修复 #27) #91
已合并
不喜欢雨天ༀ创建于 29 天前
共 1 个文件变更+19-4
@@ -38,9 +38,10 @@ protected:
38 38 
39TEST_F(add_example_test, test_case_0)39TEST_F(add_example_test, test_case_0)
40{40{
41- size_t xByteSize = 32 * 4 * 4 * 4 * sizeof(float);41+ constexpr size_t totalLength = 32UL * 4UL * 4UL * 4UL;
42- size_t yByteSize = 32 * 4 * 4 * 4 * sizeof(float);42+ size_t xByteSize = totalLength * sizeof(float);
43- size_t zByteSize = 32 * 4 * 4 * 4 * sizeof(float);43+ size_t yByteSize = totalLength * sizeof(float);
44+ size_t zByteSize = totalLength * sizeof(float);
44 size_t tiling_data_size = sizeof(AddExampleTilingData);45 size_t tiling_data_size = sizeof(AddExampleTilingData);
45 uint32_t blockDim = 8;46 uint32_t blockDim = 8;
46 47 
@@ -56,9 +57,17 @@ TEST_F(add_example_test, test_case_0)
56 57 
57 AddExampleTilingData* tilingDatafromBin = reinterpret_cast<AddExampleTilingData*>(tiling);58 AddExampleTilingData* tilingDatafromBin = reinterpret_cast<AddExampleTilingData*>(tiling);
58 59 
59- tilingDatafromBin->totalLength = 32 * 4 * 4 * 4;60+ tilingDatafromBin->totalLength = totalLength;
60 tilingDatafromBin->tileNum = 8;61 tilingDatafromBin->tileNum = 8;
61 62 
63+ // 输入填入已知值,使 kernel 输出可校验(x=i, y=2i,期望 z=3i,float32 下位精确)
64+ float* xFloat = reinterpret_cast<float*>(x);
65+ float* yFloat = reinterpret_cast<float*>(y);
66+ for (size_t i = 0; i < totalLength; ++i) {
67+ xFloat[i] = static_cast<float>(i);
68+ yFloat[i] = 2.0f * static_cast<float>(i);
69+ }
70+ 
62 auto AddExampleKernel = [](GM_ADDR x, GM_ADDR y, GM_ADDR z, GM_ADDR workspace, GM_ADDR tiling) {71 auto AddExampleKernel = [](GM_ADDR x, GM_ADDR y, GM_ADDR z, GM_ADDR workspace, GM_ADDR tiling) {
63 ::add_example<0>(x, y, z, workspace, tiling);72 ::add_example<0>(x, y, z, workspace, tiling);
64 };73 };
@@ -73,6 +82,12 @@ TEST_F(add_example_test, test_case_0)
73 workspace,82 workspace,
74 (uint8_t *)(tilingDatafromBin));83 (uint8_t *)(tilingDatafromBin));
75 84 
85+ // 逐元素校验输出(float32 加法位精确,可位级比较)
86+ const float* zFloat = reinterpret_cast<const float*>(z);
87+ for (size_t i = 0; i < totalLength; ++i) {
88+ EXPECT_EQ(zFloat[i], xFloat[i] + yFloat[i]) << "add_example output mismatch at index " << i;
89+ }
90+ 
76 AscendC::GmFree(x);91 AscendC::GmFree(x);
77 AscendC::GmFree(y);92 AscendC::GmFree(y);
78 AscendC::GmFree(z);93 AscendC::GmFree(z);