[INFO] Initializing environment for https://gitcode.com/pre-commit-clang/mirrors-clang-format. [INFO] Installing environment for https://gitcode.com/pre-commit-clang/mirrors-clang-format. [INFO] Once installed this environment will be reused. [INFO] This may take a few minutes... clang-format.............................................................Failed - hook id: clang-format - files were modified by this hook Check....................................................................Passed All changes made by hooks: diff --git a/agent/skills/repo-test-develop/references/test/{op}/arch35/op_npu_wrapper.h b/agent/skills/repo-test-develop/references/test/{op}/arch35/op_npu_wrapper.h index d5712a3..9baa73f 100644 --- a/agent/skills/repo-test-develop/references/test/{op}/arch35/op_npu_wrapper.h +++ b/agent/skills/repo-test-develop/references/test/{op}/arch35/op_npu_wrapper.h @@ -16,15 +16,20 @@ // - wrapper 内部不得调用业务算子日志接口(如 OP_LOGE),只返回结构化错误码 // - 入参 nullptr 表示该 buffer 不参与,跳过对应 device 内存操作 -#ifndef {{OP}}_NPU_H -#define {{OP}}_NPU_H +#ifndef{{OP } } _NPU_H +#define{{OP } } _NPU_H #include #include "acl/acl.h" #include "cann_ops_blas.h" -inline aclblasStatus_t aclblas{{Op}}_npu( - aclblasHandle_t handle /* TEMPLATE: + API 参数:维度 + const 指针 + 非常量指针 */) +inline aclblasStatus_t aclblas +{ + { + Op + } +} +_npu(aclblasHandle_t handle /* TEMPLATE: + API 参数:维度 + const 指针 + 非常量指针 */) { // 1. 快速路径:handle == nullptr 或规模 <= 0 -> 直接透传(由算子内部处理) if (handle == nullptr /* || n <= 0 */) { @@ -32,8 +37,8 @@ inline aclblasStatus_t aclblas{{Op}}_npu( } // 2. 计算 host 端需要搬运的字节数(考虑 stride / lda / 多维) - const size_t xBytes = 0; // TEMPLATE - const size_t yBytes = 0; // TEMPLATE + const size_t xBytes = 0; // TEMPLATE + const size_t yBytes = 0; // TEMPLATE // 3. 分配 device 内存 + H2D(每个 malloc / H2D 必须校验返回值) void* dX = nullptr; @@ -42,7 +47,8 @@ inline aclblasStatus_t aclblas{{Op}}_npu( if (x != nullptr) { aclRet = aclrtMalloc(&dX, xBytes, ACL_MEM_MALLOC_HUGE_FIRST); - if (aclRet != ACL_SUCCESS) return ACLBLAS_STATUS_ALLOC_FAILED; + if (aclRet != ACL_SUCCESS) + return ACLBLAS_STATUS_ALLOC_FAILED; aclRet = aclrtMemcpy(dX, xBytes, x, xBytes, ACL_MEMCPY_HOST_TO_DEVICE); if (aclRet != ACL_SUCCESS) { aclrtFree(dX); @@ -53,12 +59,14 @@ inline aclblasStatus_t aclblas{{Op}}_npu( if (y != nullptr) { aclRet = aclrtMalloc(&dY, yBytes, ACL_MEM_MALLOC_HUGE_FIRST); if (aclRet != ACL_SUCCESS) { - if (dX) aclrtFree(dX); + if (dX) + aclrtFree(dX); return ACLBLAS_STATUS_ALLOC_FAILED; } aclRet = aclrtMemcpy(dY, yBytes, y, yBytes, ACL_MEMCPY_HOST_TO_DEVICE); if (aclRet != ACL_SUCCESS) { - if (dX) aclrtFree(dX); + if (dX) + aclrtFree(dX); aclrtFree(dY); return ACLBLAS_STATUS_INTERNAL_ERROR; } @@ -67,16 +75,20 @@ inline aclblasStatus_t aclblas{{Op}}_npu( // 4. 调用算子(必须校验返回状态) aclblasStatus_t ret = aclblas{{Op}}(handle /* , 参数转换为 device 指针 */); if (ret != ACLBLAS_STATUS_SUCCESS) { - if (dX) aclrtFree(dX); - if (dY) aclrtFree(dY); + if (dX) + aclrtFree(dX); + if (dY) + aclrtFree(dY); return ret; } // 5. 同步设备(必须校验返回值;异步算子改用 aclrtSynchronizeStream(h->stream)) aclRet = aclrtSynchronizeDevice(); if (aclRet != ACL_SUCCESS) { - if (dX) aclrtFree(dX); - if (dY) aclrtFree(dY); + if (dX) + aclrtFree(dX); + if (dY) + aclrtFree(dY); return ACLBLAS_STATUS_EXECUTION_FAILED; } @@ -84,15 +96,18 @@ inline aclblasStatus_t aclblas{{Op}}_npu( if (y != nullptr && dY != nullptr) { aclRet = aclrtMemcpy(y, yBytes, dY, yBytes, ACL_MEMCPY_DEVICE_TO_HOST); if (aclRet != ACL_SUCCESS) { - if (dX) aclrtFree(dX); + if (dX) + aclrtFree(dX); aclrtFree(dY); return ACLBLAS_STATUS_INTERNAL_ERROR; } } - if (dX) aclrtFree(dX); - if (dY) aclrtFree(dY); + if (dX) + aclrtFree(dX); + if (dY) + aclrtFree(dY); return ret; } -#endif // {{OP}}_NPU_H +#endif // {{OP}}_NPU_H diff --git a/agent/skills/repo-test-develop/references/test/{op}/arch35/op_test.cpp b/agent/skills/repo-test-develop/references/test/{op}/arch35/op_test.cpp index e37bb6b..1feddbc 100644 --- a/agent/skills/repo-test-develop/references/test/{op}/arch35/op_test.cpp +++ b/agent/skills/repo-test-develop/references/test/{op}/arch35/op_test.cpp @@ -23,37 +23,105 @@ #include "{{op}}_golden.h" #include "{{op}}_npu_wrapper.h" -class {{Op}}Arch35Test : public BlasTest<{{Op}}Param> { }; +class { + { + Op + } +} Arch35Test : public BlasTest < +{ + { + Op + } +} +Param > {}; -TEST_F({{Op}}Arch35Test, NullHandle) { +TEST_F( + { + { + Op + } + } Arch35Test, + NullHandle) +{ // TEMPLATE: 按 API 传占位实参,期望返回空 handle 错误码 - aclblasStatus_t ret = aclblas{{Op}}_npu(nullptr, ACLBLAS_LOWER, 5, nullptr, nullptr, 5); + aclblasStatus_t ret = aclblas + { + { + Op + } + } + _npu(nullptr, ACLBLAS_LOWER, 5, nullptr, nullptr, 5); EXPECT_EQ(ret, ACLBLAS_STATUS_NOT_INITIALIZED); } INSTANTIATE_TEST_SUITE_P( - {{Op}}, {{Op}}Arch35Test, - ::testing::ValuesIn(GetCasesFromCsv<{{Op}}Param>(ReplaceFileExtension2Csv(__FILE__))), - PrintCaseInfoString<{{Op}}Param>); + {{Op}}, + { + { + Op + } + } Arch35Test, + ::testing::ValuesIn(GetCasesFromCsv<{ + { + Op + } + } Param>(ReplaceFileExtension2Csv(__FILE__))), + PrintCaseInfoString<{ + { + Op + } + } Param>); -TEST_P({{Op}}Arch35Test, CsvDriven) { +TEST_P( + { + { + Op + } + } Arch35Test, + CsvDriven) +{ const auto& p = GetParam(); // 1. 生成 host 数据(按各数组参数的 BlasFillMode + randomSeed) std::vector apHost = makeBlasTriangular(p.n, p.uplo == ACLBLAS_UPPER, p.ap, p.randomSeed); - std::vector aHost = makeBlasArray(static_cast(p.lda) * p.n, p.a, p.randomSeed); + std::vector aHost = makeBlasArray(static_cast(p.lda) * p.n, p.a, p.randomSeed); const float* apPtr = apHost.empty() ? nullptr : apHost.data(); - float* aPtr = aHost.empty() ? nullptr : aHost.data(); + float* aPtr = aHost.empty() ? nullptr : aHost.data(); // 2. _npu 执行;3. 失败先比对错误码 - aclblasStatus_t ret = aclblas{{Op}}_npu({{Op}}Arch35Test::handle_, p.uplo, p.n, apPtr, aPtr, p.lda); + aclblasStatus_t ret = aclblas + { + { + Op + } + } + _npu( + { + { + Op + } + } Arch35Test::handle_, + p.uplo, p.n, apPtr, aPtr, p.lda); EXPECT_EQ(static_cast(ret), static_cast(p.expectResult)); - if (p.expectResult != ACLBLAS_STATUS_SUCCESS) return; + if (p.expectResult != ACLBLAS_STATUS_SUCCESS) + return; // 4. _cpu 算 golden std::vector golden(aHost.size()); - aclblas{{Op}}_cpu({{Op}}Arch35Test::handle_, p.uplo, p.n, apHost.data(), golden.data(), p.lda); + aclblas + { + { + Op + } + } + _cpu( + { + { + Op + } + } Arch35Test::handle_, + p.uplo, p.n, apHost.data(), golden.data(), p.lda); // 5. Verifier 比对(EXACT 为格式转换类示例;浮点计算类改 ABS / MERE_MARE) VerifyConfig cfg; diff --git a/agent/skills/repo-test-develop/references/test/{op}/op_golden.h b/agent/skills/repo-test-develop/references/test/{op}/op_golden.h index 762b0c6..1513537 100644 --- a/agent/skills/repo-test-develop/references/test/{op}/op_golden.h +++ b/agent/skills/repo-test-develop/references/test/{op}/op_golden.h @@ -23,18 +23,28 @@ #include "cblas_compat.h" // ---- 变体 A:CBLAS 算子(Level-1/2/3),以 gemv 为例 ---- -inline aclblasStatus_t aclblas{{Op}}_cpu( - aclblasHandle_t handle, aclblasOperation_t trans, int m, int n, - const float* alpha, const float* a, int lda, +inline aclblasStatus_t aclblas +{ + { + Op + } +} +_cpu( + aclblasHandle_t handle, aclblasOperation_t trans, int m, int n, const float* alpha, const float* a, int lda, const float* x, int incx, const float* beta, float* y, int incy) { - if (handle == nullptr) return ACLBLAS_STATUS_NOT_INITIALIZED; + if (handle == nullptr) + return ACLBLAS_STATUS_NOT_INITIALIZED; if (trans != ACLBLAS_OP_N && trans != ACLBLAS_OP_T && trans != ACLBLAS_OP_C) return ACLBLAS_STATUS_INVALID_VALUE; - if (m < 0 || n < 0 || lda < std::max(1, m)) return ACLBLAS_STATUS_INVALID_VALUE; - if (incx == 0 || incy == 0) return ACLBLAS_STATUS_INVALID_VALUE; - if (alpha == nullptr || beta == nullptr) return ACLBLAS_STATUS_INVALID_VALUE; - if (m == 0 || n == 0) return ACLBLAS_STATUS_SUCCESS; + if (m < 0 || n < 0 || lda < std::max(1, m)) + return ACLBLAS_STATUS_INVALID_VALUE; + if (incx == 0 || incy == 0) + return ACLBLAS_STATUS_INVALID_VALUE; + if (alpha == nullptr || beta == nullptr) + return ACLBLAS_STATUS_INVALID_VALUE; + if (m == 0 || n == 0) + return ACLBLAS_STATUS_SUCCESS; cblas_sgemv(CblasColMajor, ToCblasOp(trans), m, n, *alpha, a, lda, x, incx, *beta, y, incy); return ACLBLAS_STATUS_SUCCESS; diff --git a/agent/skills/repo-test-develop/references/test/{op}/op_param.h b/agent/skills/repo-test-develop/references/test/{op}/op_param.h index f60664b..ced0713 100644 --- a/agent/skills/repo-test-develop/references/test/{op}/op_param.h +++ b/agent/skills/repo-test-develop/references/test/{op}/op_param.h @@ -13,30 +13,41 @@ // - 数组参数类型为 BlasFillMode(填充方式见 SKILL 的 BlasFillMode 命名规则) // - 若按用例控制精度,额外加 mereThreshold / mareMultiplier 字段并从 CSV 读取 -#ifndef {{OP}}_PARAM_H -#define {{OP}}_PARAM_H +#ifndef{{OP } } _PARAM_H +#define{{OP } } _PARAM_H #include #include "acl/acl.h" #include "cann_ops_blas.h" #include "csv_loader.h" -struct {{Op}}Param : public BlasTestParamBase { +struct { + { + Op + } +} Param : public BlasTestParamBase +{ // TEMPLATE: 按 API 参数顺序声明字段。以下为 tpttr 形态示例,按算子替换: aclblasFillMode_t uplo = ACLBLAS_LOWER; int n = 0; - BlasFillMode ap = BlasFillMode("INDEX"); // 顺序正整数 1, 2, 3, ... - BlasFillMode a = BlasFillMode("VALUE_NORM_N999"); // 哨兵值 -999 + BlasFillMode ap = BlasFillMode("INDEX"); // 顺序正整数 1, 2, 3, ... + BlasFillMode a = BlasFillMode("VALUE_NORM_N999"); // 哨兵值 -999 int lda = 0; - {{Op}}Param(const csv_map& m) : BlasTestParamBase(m) { + { + { + Op + } + } + Param(const csv_map& m) : BlasTestParamBase(m) + { // TEMPLATE: 每个字段从 CSV 读取,键名 = CSV 列名,第三参为缺省值 uplo = parseFillMode(ReadMap(m, "uplo", "LOWER")); - n = parseInt(ReadMap(m, "n", "0")); - ap = BlasFillMode(ReadMap(m, "ap", "INDEX")); - a = BlasFillMode(ReadMap(m, "a", "VALUE_NORM_N999")); - lda = parseInt(ReadMap(m, "lda", std::to_string(std::max(1, n)))); + n = parseInt(ReadMap(m, "n", "0")); + ap = BlasFillMode(ReadMap(m, "ap", "INDEX")); + a = BlasFillMode(ReadMap(m, "a", "VALUE_NORM_N999")); + lda = parseInt(ReadMap(m, "lda", std::to_string(std::max(1, n)))); } }; -#endif // {{OP}}_PARAM_H +#endif // {{OP}}_PARAM_H