#include <iostream>
#include <vector>
#include <getopt.h>
#include <unistd.h>
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/wait.h>
#include <dlfcn.h>
#include <cstdio>
#include <string>
#include <iomanip>
#include <string.h>
#include <list>
#include <algorithm>
#include <stdarg.h>
#include <fstream>
#include <sstream>
#include "acl/acl.h"
#include "aclnn/aclnn_base.h"
#include "acl/acl_base.h"
#include "acl/acl_rt.h"
#include "sec_common.h"
#include "utils.h"
#include "../fuzzlib/secodeFuzz.h"
#include "aclnnop/aclnn_chamfer_distance_backward.h"

using namespace std;

static const char* GetDtypeName(aclDataType dt) {
    switch (dt) {
        case ACL_FLOAT: return "FLOAT";
        case ACL_FLOAT16: return "FLOAT16";
        case ACL_INT8: return "INT8";
        case ACL_INT32: return "INT32";
        case ACL_UINT8: return "UINT8";
        case ACL_INT16: return "INT16";
        case ACL_UINT16: return "UINT16";
        case ACL_UINT32: return "UINT32";
        case ACL_INT64: return "INT64";
        case ACL_UINT64: return "UINT64";
        case ACL_DOUBLE: return "DOUBLE";
        case ACL_BOOL: return "BOOL";
        case ACL_BF16: return "BFLOAT16";
        case ACL_COMPLEX64: return "COMPLEX64";
        case ACL_COMPLEX128: return "COMPLEX128";
        default: return "UNKNOWN";
    }
}

static std::string ShapeToStr(const std::vector<int64_t>& s) {
    std::string r = "[";
    for (size_t k = 0; k < s.size(); k++) {
        if (k) r += ",";
        r += std::to_string(s[k]);
    }
    return r + "]";
}

static std::string IntArrayToStr(const std::vector<int64_t>& s) {
    std::string r = "[";
    for (size_t k = 0; k < s.size(); k++) {
        if (k) r += ",";
        r += std::to_string(s[k]);
    }
    return r + "]";
}

static std::string FloatArrayToStr(const std::vector<float>& s) {
    std::string r = "[";
    for (size_t k = 0; k < s.size(); k++) {
        if (k) r += ",";
        r += std::to_string(s[k]);
    }
    return r + "]";
}

struct ScenarioResult {
    int scenarioId;
    int retCode;
    std::string desc;
    std::string violation;
    std::string category;
    std::string errorType;
    std::string aclErrMsg;
};
static std::vector<ScenarioResult> g_allResults;
static int g_stdoutFd = -1;

void RedirectStdoutToScenarioFile(int scenarioId) {
    const std::string baseDir = "./opfuzz/scenario_logs";
    mkdir(baseDir.c_str(), 0755);
    std::string logFile = baseDir + "/scenario_" + std::to_string(scenarioId) + ".log";
    fflush(stdout);
    g_stdoutFd = dup(fileno(stdout));
    freopen(logFile.c_str(), "w", stdout);
    setvbuf(stdout, NULL, _IONBF, 0);
}

void RestoreStdout() {
    if (g_stdoutFd < 0) return;
    fflush(stdout);
    dup2(g_stdoutFd, fileno(stdout));
    close(g_stdoutFd);
    g_stdoutFd = -1;
    clearerr(stdout);
}

void GenerateFinalSummary() {
    const std::string baseDir = "./opfuzz/scenario_logs";
    std::string summaryFile = baseDir + "/summary.txt";
    std::ofstream sf(summaryFile);

    int paramErr = 0, innerErr = 0, runtimeErr = 0, otherErr = 0, unexpectedOk = 0, ezPass = 0;
    for (const auto& r : g_allResults) {
        if (r.errorType == "UNEXPECTED_SUCCESS") unexpectedOk++;
        else if (r.errorType == "PARAM_ERROR") paramErr++;
        else if (r.errorType == "INNER_ERROR") innerErr++;
        else if (r.errorType == "RUNTIME_ERROR") runtimeErr++;
        else otherErr++;
        if (r.aclErrMsg.find("should") != std::string::npos ||
            r.aclErrMsg.find("must") != std::string::npos ||
            r.aclErrMsg.find("expected") != std::string::npos ||
            r.aclErrMsg.find("supported") != std::string::npos) {
            ezPass++;
        }
    }
    int total = (int)g_allResults.size();
    int detected = paramErr + innerErr + runtimeErr + otherErr;
    int rate = (total > 0) ? detected * 100 / total : 0;
    int ezRate = (total > 0) ? ezPass * 100 / total : 0;

    sf << "==============================================" << std::endl;
    sf << "  ERROR SCENARIO TEST SUMMARY: aclnnChamferDistanceBackward" << std::endl;
    sf << "==============================================" << std::endl;
    sf << "  Total Scenarios:      " << total << std::endl;
    sf << "  Error Detected:       " << detected << " / " << total << " (" << rate << "%)" << std::endl;
    sf << "    PARAM_ERROR:        " << paramErr << std::endl;
    sf << "    INNER_ERROR:        " << innerErr << std::endl;
    sf << "    RUNTIME_ERROR:      " << runtimeErr << std::endl;
    sf << "    OTHER_ERROR:        " << otherErr << std::endl;
    sf << "  Unexpected Success:   " << unexpectedOk << std::endl;
    sf << "  EZ Compliance:        " << ezPass << " / " << total << " (" << ezRate << "% have corrective hints)" << std::endl;
    sf << "==============================================" << std::endl;
    sf << std::endl;

    sf << std::string(120, '-') << std::endl;
    sf << "  Id | RetCode   | Type          | EZ  | desc" << std::endl;
    sf << std::string(120, '-') << std::endl;
    for (const auto& r : g_allResults) {
        bool ez = (r.aclErrMsg.find("should") != std::string::npos ||
                   r.aclErrMsg.find("must") != std::string::npos ||
                   r.aclErrMsg.find("expected") != std::string::npos);
        sf << "  " << std::setw(2) << r.scenarioId
           << " | " << std::setw(9) << r.retCode
           << " | " << std::setw(13) << r.errorType
           << " | " << (ez ? "OK " : "NO ")
           << " | " << r.desc << std::endl;
    }
    sf << std::string(120, '-') << std::endl;
    sf << std::endl;

    for (const auto& r : g_allResults) {
        std::string logPath = baseDir + "/scenario_" + std::to_string(r.scenarioId) + ".log";
        sf << std::endl << "===== Scenario " << r.scenarioId << " (" << r.errorType << ") ====" << std::endl;
        std::ifstream lf(logPath);
        if (lf.is_open()) {
            std::string line;
            while (std::getline(lf, line)) sf << line << std::endl;
            lf.close();
        } else {
            sf << "  (log file not found)" << std::endl;
        }
    }
    sf.close();

    printf("\n====== FINAL SUMMARY ======\n");
    {
        std::string catCmd = "cat " + summaryFile + " 2>/dev/null";
        system(catCmd.c_str());
    }
    printf("====== END SUMMARY ======\n\n");

    WriteDTLog("aclnnChamferDistanceBackward", "FINAL: total=%d detected=%d param=%d inner=%d runtime=%d unexpected=%d rate=%d%%\n",
               total, detected, paramErr, innerErr, runtimeErr, unexpectedOk, rate);
}

int aclnnChamferDistanceBackward_Normal(int fuzz_num)
{
    auto ret = Init(deviceId, &context, &stream);
    CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Init acl failed. ERROR: %d\n", ret); return ret);
    WriteDTLog("aclnnChamferDistanceBackward", "aclnnChamferDistanceBackward error scenario test start\n");
    aclrtSetOpExecuteTimeOut(1091);
    DT_Set_TimeOut_Second(3000);
    DT_FUZZ_START(0, fuzz_num, "aclnnChamferDistanceBackward", 0)
    {
        int i = 0;
        void* xyz1DeviceAddr = nullptr;
        aclTensor* xyz1 = nullptr;
        void* xyz2DeviceAddr = nullptr;
        aclTensor* xyz2 = nullptr;
        void* idx1DeviceAddr = nullptr;
        aclTensor* idx1 = nullptr;
        void* idx2DeviceAddr = nullptr;
        aclTensor* idx2 = nullptr;
        void* gradDist1DeviceAddr = nullptr;
        aclTensor* gradDist1 = nullptr;
        void* gradDist2DeviceAddr = nullptr;
        aclTensor* gradDist2 = nullptr;
        void* gradXyz1DeviceAddr = nullptr;
        aclTensor* gradXyz1 = nullptr;
        void* gradXyz2DeviceAddr = nullptr;
        aclTensor* gradXyz2 = nullptr;
        uint64_t workspaceSize = 0;
        aclOpExecutor* executor;
        void* workspaceAddr = nullptr;
        int scenario = 0;
        int caseRet = -1;
        std::string scenarioDesc, violationDetail, errorCategory, savedErrMsg;
        int expectedErrorCode = 0;
        std::string expectedErrorName, errorTypeStr, errorTargetStr, verifyRequirement;

        LOG_PRINT("aclnnChamferDistanceBackward error test %d\n", fuzzi);

        RedirectStdoutToScenarioFile(fuzzi);

        try
        {
            scenario = *(int *)DTSetGetNumberRange(&g_Element[i++], 0, 0, 52, "i");

            // === Base config ===
            std::vector<int64_t> xyz1Shape = {2, 4, 16};
            std::vector<int64_t> xyz2Shape = {2, 4, 16};
            std::vector<int64_t> idx1Shape = {2, 4};
            std::vector<int64_t> idx2Shape = {2, 4};
            std::vector<int64_t> gradDist1Shape = {2, 4};
            std::vector<int64_t> gradDist2Shape = {2, 4};
            std::vector<int64_t> gradXyz1Shape = {2, 4, 16};
            std::vector<int64_t> gradXyz2Shape = {2, 4, 16};

            aclDataType xyz1Dtype = ACL_FLOAT;
            aclDataType xyz2Dtype = ACL_FLOAT;
            aclDataType idx1Dtype = ACL_INT32;
            aclDataType idx2Dtype = ACL_INT32;
            aclDataType gradDist1Dtype = ACL_FLOAT;
            aclDataType gradDist2Dtype = ACL_FLOAT;
            aclDataType gradXyz1Dtype = ACL_FLOAT;
            aclDataType gradXyz2Dtype = ACL_FLOAT;
            aclFormat tensorFormat = ACL_FORMAT_ND;
            bool nullXyz1 = false, nullXyz2 = false, nullIdx1 = false, nullIdx2 = false, nullGradDist1 = false, nullGradDist2 = false, nullGradXyz1 = false, nullGradXyz2 = false;

            // === Error scenario injection ===
            if (scenario == 0) {
                // [BASE_CHECK] base config sanity check: no violation injected, expect success
                scenarioDesc = "base config sanity check: no violation injected, expect success";
                violationDetail = "base config sanity check: no violation injected, expect success";
                errorCategory = "BASE";
                expectedErrorCode = 0;
                expectedErrorName = "ACL_SUCCESS";
                errorTypeStr = "BASE_CHECK";
                errorTargetStr = "";
                verifyRequirement = "基线自检:base配置应执行成功(ret==0);若失败则基线污染,所有异常场景报错不可信,需重构造base";
                LOG_PRINT("[BASE_CHECK] base config sanity check: no violation injected, expect success\n");
            }
            else if (scenario == 1) {
                // [A1_xyz1_ACL_INT8] xyz1 dtype=ACL_INT8 not in supported list [FLOAT,FLOAT16]
                scenarioDesc = "xyz1 dtype=ACL_INT8 not in supported list [FLOAT,FLOAT16]";
                violationDetail = "xyz1=ACL_INT8";
                errorCategory = "A1";
                expectedErrorCode = 161002;
                expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
                errorTypeStr = "DTYPE_UNSUPPORTED";
                errorTargetStr = "xyz1";
                verifyRequirement = "返回码应为161001或161002,错误信息应包含ACL_INT8不支持或invalid dtype相关提示";
                xyz1Dtype = ACL_INT8;  // override
                LOG_PRINT("[A1_xyz1_ACL_INT8] xyz1 dtype=ACL_INT8 not in supported list [FLOAT,FLOAT16]\n");
            }
            else if (scenario == 2) {
                // [A1_xyz1_ACL_INT32] xyz1 dtype=ACL_INT32 not in supported list [FLOAT,FLOAT16]
                scenarioDesc = "xyz1 dtype=ACL_INT32 not in supported list [FLOAT,FLOAT16]";
                violationDetail = "xyz1=ACL_INT32";
                errorCategory = "A1";
                expectedErrorCode = 161002;
                expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
                errorTypeStr = "DTYPE_UNSUPPORTED";
                errorTargetStr = "xyz1";
                verifyRequirement = "返回码应为161001或161002,错误信息应包含ACL_INT32不支持或invalid dtype相关提示";
                xyz1Dtype = ACL_INT32;  // override
                LOG_PRINT("[A1_xyz1_ACL_INT32] xyz1 dtype=ACL_INT32 not in supported list [FLOAT,FLOAT16]\n");
            }
            else if (scenario == 3) {
                // [B1_xyz1_dim_above_3] xyz1 dim=4D exceeds max=3D
                scenarioDesc = "xyz1 dim=4D exceeds max=3D";
                violationDetail = "xyz1 dim=4D exceeds max=3D";
                errorCategory = "B1";
                expectedErrorCode = 161002;
                expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
                errorTypeStr = "DIM_ILLEGAL";
                errorTargetStr = "xyz1";
                verifyRequirement = "返回码应为161001或161002,错误信息应提示维度数超限";
                xyz1Shape = {1, 1, 1, 1};  // override
                LOG_PRINT("[B1_xyz1_dim_above_3] xyz1 dim=4D exceeds max=3D\n");
            }
            else if (scenario == 4) {
                // [B1_xyz1_dim_below_3] xyz1 dim=2D below min=3D
                scenarioDesc = "xyz1 dim=2D below min=3D";
                violationDetail = "xyz1 dim=2D below min=3D";
                errorCategory = "B1";
                expectedErrorCode = 161002;
                expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
                errorTypeStr = "DIM_ILLEGAL";
                errorTargetStr = "xyz1";
                verifyRequirement = "返回码应为161001或161002,错误信息应提示维度数不足";
                xyz1Shape = {1, 1};  // override
                LOG_PRINT("[B1_xyz1_dim_below_3] xyz1 dim=2D below min=3D\n");
            }
            else if (scenario == 5) {
                // [B4_xyz1_zero_dim] xyz1 shape has zero dimension: [0, 4, 16]
                scenarioDesc = "xyz1 shape has zero dimension: [0, 4, 16]";
                violationDetail = "xyz1 shape has zero dimension: [0, 4, 16]";
                errorCategory = "B4";
                expectedErrorCode = 161002;
                expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
                errorTypeStr = "SHAPE_ILLEGAL";
                errorTargetStr = "xyz1";
                verifyRequirement = "空tensor可能合法也可能非法,需根据md文档确认;若非法应返回161001或161002";
                xyz1Shape = {0, 4, 16};  // override
                LOG_PRINT("[B4_xyz1_zero_dim] xyz1 shape has zero dimension: [0, 4, 16]\n");
            }
            else if (scenario == 6) {
                // [D3_xyz1_nullptr] xyz1 tensor is nullptr (input pointer is null)
                scenarioDesc = "xyz1 tensor is nullptr (input pointer is null)";
                violationDetail = "xyz1 tensor is nullptr (input pointer is null)";
                errorCategory = "D3";
                expectedErrorCode = 161001;
                expectedErrorName = "ACLNN_ERR_PARAM_NULLPTR";
                errorTypeStr = "NULLPTR_INPUT";
                errorTargetStr = "xyz1";
                verifyRequirement = "返回码应为161001,错误信息应包含null或nullptr相关提示";
                nullXyz1 = true;
                LOG_PRINT("[D3_xyz1_nullptr] xyz1 tensor is nullptr (input pointer is null)\n");
            }
            else if (scenario == 7) {
                // [A1_xyz2_ACL_INT8] xyz2 dtype=ACL_INT8 not in supported list [FLOAT,FLOAT16]
                scenarioDesc = "xyz2 dtype=ACL_INT8 not in supported list [FLOAT,FLOAT16]";
                violationDetail = "xyz2=ACL_INT8";
                errorCategory = "A1";
                expectedErrorCode = 161002;
                expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
                errorTypeStr = "DTYPE_UNSUPPORTED";
                errorTargetStr = "xyz2";
                verifyRequirement = "返回码应为161001或161002,错误信息应包含ACL_INT8不支持或invalid dtype相关提示";
                xyz2Dtype = ACL_INT8;  // override
                LOG_PRINT("[A1_xyz2_ACL_INT8] xyz2 dtype=ACL_INT8 not in supported list [FLOAT,FLOAT16]\n");
            }
            else if (scenario == 8) {
                // [A1_xyz2_ACL_INT32] xyz2 dtype=ACL_INT32 not in supported list [FLOAT,FLOAT16]
                scenarioDesc = "xyz2 dtype=ACL_INT32 not in supported list [FLOAT,FLOAT16]";
                violationDetail = "xyz2=ACL_INT32";
                errorCategory = "A1";
                expectedErrorCode = 161002;
                expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
                errorTypeStr = "DTYPE_UNSUPPORTED";
                errorTargetStr = "xyz2";
                verifyRequirement = "返回码应为161001或161002,错误信息应包含ACL_INT32不支持或invalid dtype相关提示";
                xyz2Dtype = ACL_INT32;  // override
                LOG_PRINT("[A1_xyz2_ACL_INT32] xyz2 dtype=ACL_INT32 not in supported list [FLOAT,FLOAT16]\n");
            }
            else if (scenario == 9) {
                // [B1_xyz2_dim_above_3] xyz2 dim=4D exceeds max=3D
                scenarioDesc = "xyz2 dim=4D exceeds max=3D";
                violationDetail = "xyz2 dim=4D exceeds max=3D";
                errorCategory = "B1";
                expectedErrorCode = 161002;
                expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
                errorTypeStr = "DIM_ILLEGAL";
                errorTargetStr = "xyz2";
                verifyRequirement = "返回码应为161001或161002,错误信息应提示维度数超限";
                xyz2Shape = {1, 1, 1, 1};  // override
                LOG_PRINT("[B1_xyz2_dim_above_3] xyz2 dim=4D exceeds max=3D\n");
            }
            else if (scenario == 10) {
                // [B1_xyz2_dim_below_3] xyz2 dim=2D below min=3D
                scenarioDesc = "xyz2 dim=2D below min=3D";
                violationDetail = "xyz2 dim=2D below min=3D";
                errorCategory = "B1";
                expectedErrorCode = 161002;
                expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
                errorTypeStr = "DIM_ILLEGAL";
                errorTargetStr = "xyz2";
                verifyRequirement = "返回码应为161001或161002,错误信息应提示维度数不足";
                xyz2Shape = {1, 1};  // override
                LOG_PRINT("[B1_xyz2_dim_below_3] xyz2 dim=2D below min=3D\n");
            }
            else if (scenario == 11) {
                // [B4_xyz2_zero_dim] xyz2 shape has zero dimension: [0, 4, 16]
                scenarioDesc = "xyz2 shape has zero dimension: [0, 4, 16]";
                violationDetail = "xyz2 shape has zero dimension: [0, 4, 16]";
                errorCategory = "B4";
                expectedErrorCode = 161002;
                expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
                errorTypeStr = "SHAPE_ILLEGAL";
                errorTargetStr = "xyz2";
                verifyRequirement = "空tensor可能合法也可能非法,需根据md文档确认;若非法应返回161001或161002";
                xyz2Shape = {0, 4, 16};  // override
                LOG_PRINT("[B4_xyz2_zero_dim] xyz2 shape has zero dimension: [0, 4, 16]\n");
            }
            else if (scenario == 12) {
                // [D3_xyz2_nullptr] xyz2 tensor is nullptr (input pointer is null)
                scenarioDesc = "xyz2 tensor is nullptr (input pointer is null)";
                violationDetail = "xyz2 tensor is nullptr (input pointer is null)";
                errorCategory = "D3";
                expectedErrorCode = 161001;
                expectedErrorName = "ACLNN_ERR_PARAM_NULLPTR";
                errorTypeStr = "NULLPTR_INPUT";
                errorTargetStr = "xyz2";
                verifyRequirement = "返回码应为161001,错误信息应包含null或nullptr相关提示";
                nullXyz2 = true;
                LOG_PRINT("[D3_xyz2_nullptr] xyz2 tensor is nullptr (input pointer is null)\n");
            }
            else if (scenario == 13) {
                // [A1_idx1_ACL_INT8] idx1 dtype=ACL_INT8 not in supported list [INT32]
                scenarioDesc = "idx1 dtype=ACL_INT8 not in supported list [INT32]";
                violationDetail = "idx1=ACL_INT8";
                errorCategory = "A1";
                expectedErrorCode = 161002;
                expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
                errorTypeStr = "DTYPE_UNSUPPORTED";
                errorTargetStr = "idx1";
                verifyRequirement = "返回码应为161001或161002,错误信息应包含ACL_INT8不支持或invalid dtype相关提示";
                idx1Dtype = ACL_INT8;  // override
                LOG_PRINT("[A1_idx1_ACL_INT8] idx1 dtype=ACL_INT8 not in supported list [INT32]\n");
            }
            else if (scenario == 14) {
                // [A1_idx1_ACL_INT64] idx1 dtype=ACL_INT64 not in supported list [INT32]
                scenarioDesc = "idx1 dtype=ACL_INT64 not in supported list [INT32]";
                violationDetail = "idx1=ACL_INT64";
                errorCategory = "A1";
                expectedErrorCode = 161002;
                expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
                errorTypeStr = "DTYPE_UNSUPPORTED";
                errorTargetStr = "idx1";
                verifyRequirement = "返回码应为161001或161002,错误信息应包含ACL_INT64不支持或invalid dtype相关提示";
                idx1Dtype = ACL_INT64;  // override
                LOG_PRINT("[A1_idx1_ACL_INT64] idx1 dtype=ACL_INT64 not in supported list [INT32]\n");
            }
            else if (scenario == 15) {
                // [A3_idx1_ACL_FLOAT16] idx1 must be ACL_INT32, set to ACL_FLOAT16
                scenarioDesc = "idx1 must be ACL_INT32, set to ACL_FLOAT16";
                violationDetail = "idx1=ACL_FLOAT16";
                errorCategory = "A3";
                expectedErrorCode = 161002;
                expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
                errorTypeStr = "DTYPE_UNSUPPORTED";
                errorTargetStr = "idx1";
                verifyRequirement = "返回码应为161001或161002,错误信息应提示ACL_FLOAT16不支持";
                idx1Dtype = ACL_FLOAT16;  // override
                LOG_PRINT("[A3_idx1_ACL_FLOAT16] idx1 must be ACL_INT32, set to ACL_FLOAT16\n");
            }
            else if (scenario == 16) {
                // [B1_idx1_dim_above_2] idx1 dim=3D exceeds max=2D
                scenarioDesc = "idx1 dim=3D exceeds max=2D";
                violationDetail = "idx1 dim=3D exceeds max=2D";
                errorCategory = "B1";
                expectedErrorCode = 161002;
                expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
                errorTypeStr = "DIM_ILLEGAL";
                errorTargetStr = "idx1";
                verifyRequirement = "返回码应为161001或161002,错误信息应提示维度数超限";
                idx1Shape = {1, 1, 1};  // override
                LOG_PRINT("[B1_idx1_dim_above_2] idx1 dim=3D exceeds max=2D\n");
            }
            else if (scenario == 17) {
                // [B1_idx1_dim_below_2] idx1 dim=1D below min=2D
                scenarioDesc = "idx1 dim=1D below min=2D";
                violationDetail = "idx1 dim=1D below min=2D";
                errorCategory = "B1";
                expectedErrorCode = 161002;
                expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
                errorTypeStr = "DIM_ILLEGAL";
                errorTargetStr = "idx1";
                verifyRequirement = "返回码应为161001或161002,错误信息应提示维度数不足";
                idx1Shape = {1};  // override
                LOG_PRINT("[B1_idx1_dim_below_2] idx1 dim=1D below min=2D\n");
            }
            else if (scenario == 18) {
                // [B4_idx1_zero_dim] idx1 shape has zero dimension: [0, 4]
                scenarioDesc = "idx1 shape has zero dimension: [0, 4]";
                violationDetail = "idx1 shape has zero dimension: [0, 4]";
                errorCategory = "B4";
                expectedErrorCode = 161002;
                expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
                errorTypeStr = "SHAPE_ILLEGAL";
                errorTargetStr = "idx1";
                verifyRequirement = "空tensor可能合法也可能非法,需根据md文档确认;若非法应返回161001或161002";
                idx1Shape = {0, 4};  // override
                LOG_PRINT("[B4_idx1_zero_dim] idx1 shape has zero dimension: [0, 4]\n");
            }
            else if (scenario == 19) {
                // [D3_idx1_nullptr] idx1 tensor is nullptr (input pointer is null)
                scenarioDesc = "idx1 tensor is nullptr (input pointer is null)";
                violationDetail = "idx1 tensor is nullptr (input pointer is null)";
                errorCategory = "D3";
                expectedErrorCode = 161001;
                expectedErrorName = "ACLNN_ERR_PARAM_NULLPTR";
                errorTypeStr = "NULLPTR_INPUT";
                errorTargetStr = "idx1";
                verifyRequirement = "返回码应为161001,错误信息应包含null或nullptr相关提示";
                nullIdx1 = true;
                LOG_PRINT("[D3_idx1_nullptr] idx1 tensor is nullptr (input pointer is null)\n");
            }
            else if (scenario == 20) {
                // [A1_idx2_ACL_INT8] idx2 dtype=ACL_INT8 not in supported list [INT32]
                scenarioDesc = "idx2 dtype=ACL_INT8 not in supported list [INT32]";
                violationDetail = "idx2=ACL_INT8";
                errorCategory = "A1";
                expectedErrorCode = 161002;
                expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
                errorTypeStr = "DTYPE_UNSUPPORTED";
                errorTargetStr = "idx2";
                verifyRequirement = "返回码应为161001或161002,错误信息应包含ACL_INT8不支持或invalid dtype相关提示";
                idx2Dtype = ACL_INT8;  // override
                LOG_PRINT("[A1_idx2_ACL_INT8] idx2 dtype=ACL_INT8 not in supported list [INT32]\n");
            }
            else if (scenario == 21) {
                // [A1_idx2_ACL_INT64] idx2 dtype=ACL_INT64 not in supported list [INT32]
                scenarioDesc = "idx2 dtype=ACL_INT64 not in supported list [INT32]";
                violationDetail = "idx2=ACL_INT64";
                errorCategory = "A1";
                expectedErrorCode = 161002;
                expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
                errorTypeStr = "DTYPE_UNSUPPORTED";
                errorTargetStr = "idx2";
                verifyRequirement = "返回码应为161001或161002,错误信息应包含ACL_INT64不支持或invalid dtype相关提示";
                idx2Dtype = ACL_INT64;  // override
                LOG_PRINT("[A1_idx2_ACL_INT64] idx2 dtype=ACL_INT64 not in supported list [INT32]\n");
            }
            else if (scenario == 22) {
                // [A3_idx2_ACL_FLOAT16] idx2 must be ACL_INT32, set to ACL_FLOAT16
                scenarioDesc = "idx2 must be ACL_INT32, set to ACL_FLOAT16";
                violationDetail = "idx2=ACL_FLOAT16";
                errorCategory = "A3";
                expectedErrorCode = 161002;
                expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
                errorTypeStr = "DTYPE_UNSUPPORTED";
                errorTargetStr = "idx2";
                verifyRequirement = "返回码应为161001或161002,错误信息应提示ACL_FLOAT16不支持";
                idx2Dtype = ACL_FLOAT16;  // override
                LOG_PRINT("[A3_idx2_ACL_FLOAT16] idx2 must be ACL_INT32, set to ACL_FLOAT16\n");
            }
            else if (scenario == 23) {
                // [B1_idx2_dim_above_2] idx2 dim=3D exceeds max=2D
                scenarioDesc = "idx2 dim=3D exceeds max=2D";
                violationDetail = "idx2 dim=3D exceeds max=2D";
                errorCategory = "B1";
                expectedErrorCode = 161002;
                expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
                errorTypeStr = "DIM_ILLEGAL";
                errorTargetStr = "idx2";
                verifyRequirement = "返回码应为161001或161002,错误信息应提示维度数超限";
                idx2Shape = {1, 1, 1};  // override
                LOG_PRINT("[B1_idx2_dim_above_2] idx2 dim=3D exceeds max=2D\n");
            }
            else if (scenario == 24) {
                // [B1_idx2_dim_below_2] idx2 dim=1D below min=2D
                scenarioDesc = "idx2 dim=1D below min=2D";
                violationDetail = "idx2 dim=1D below min=2D";
                errorCategory = "B1";
                expectedErrorCode = 161002;
                expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
                errorTypeStr = "DIM_ILLEGAL";
                errorTargetStr = "idx2";
                verifyRequirement = "返回码应为161001或161002,错误信息应提示维度数不足";
                idx2Shape = {1};  // override
                LOG_PRINT("[B1_idx2_dim_below_2] idx2 dim=1D below min=2D\n");
            }
            else if (scenario == 25) {
                // [B4_idx2_zero_dim] idx2 shape has zero dimension: [0, 4]
                scenarioDesc = "idx2 shape has zero dimension: [0, 4]";
                violationDetail = "idx2 shape has zero dimension: [0, 4]";
                errorCategory = "B4";
                expectedErrorCode = 161002;
                expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
                errorTypeStr = "SHAPE_ILLEGAL";
                errorTargetStr = "idx2";
                verifyRequirement = "空tensor可能合法也可能非法,需根据md文档确认;若非法应返回161001或161002";
                idx2Shape = {0, 4};  // override
                LOG_PRINT("[B4_idx2_zero_dim] idx2 shape has zero dimension: [0, 4]\n");
            }
            else if (scenario == 26) {
                // [D3_idx2_nullptr] idx2 tensor is nullptr (input pointer is null)
                scenarioDesc = "idx2 tensor is nullptr (input pointer is null)";
                violationDetail = "idx2 tensor is nullptr (input pointer is null)";
                errorCategory = "D3";
                expectedErrorCode = 161001;
                expectedErrorName = "ACLNN_ERR_PARAM_NULLPTR";
                errorTypeStr = "NULLPTR_INPUT";
                errorTargetStr = "idx2";
                verifyRequirement = "返回码应为161001,错误信息应包含null或nullptr相关提示";
                nullIdx2 = true;
                LOG_PRINT("[D3_idx2_nullptr] idx2 tensor is nullptr (input pointer is null)\n");
            }
            else if (scenario == 27) {
                // [A1_gradDist1_ACL_INT8] gradDist1 dtype=ACL_INT8 not in supported list [FLOAT,FLOAT16]
                scenarioDesc = "gradDist1 dtype=ACL_INT8 not in supported list [FLOAT,FLOAT16]";
                violationDetail = "gradDist1=ACL_INT8";
                errorCategory = "A1";
                expectedErrorCode = 161002;
                expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
                errorTypeStr = "DTYPE_UNSUPPORTED";
                errorTargetStr = "gradDist1";
                verifyRequirement = "返回码应为161001或161002,错误信息应包含ACL_INT8不支持或invalid dtype相关提示";
                gradDist1Dtype = ACL_INT8;  // override
                LOG_PRINT("[A1_gradDist1_ACL_INT8] gradDist1 dtype=ACL_INT8 not in supported list [FLOAT,FLOAT16]\n");
            }
            else if (scenario == 28) {
                // [A1_gradDist1_ACL_INT32] gradDist1 dtype=ACL_INT32 not in supported list [FLOAT,FLOAT16]
                scenarioDesc = "gradDist1 dtype=ACL_INT32 not in supported list [FLOAT,FLOAT16]";
                violationDetail = "gradDist1=ACL_INT32";
                errorCategory = "A1";
                expectedErrorCode = 161002;
                expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
                errorTypeStr = "DTYPE_UNSUPPORTED";
                errorTargetStr = "gradDist1";
                verifyRequirement = "返回码应为161001或161002,错误信息应包含ACL_INT32不支持或invalid dtype相关提示";
                gradDist1Dtype = ACL_INT32;  // override
                LOG_PRINT("[A1_gradDist1_ACL_INT32] gradDist1 dtype=ACL_INT32 not in supported list [FLOAT,FLOAT16]\n");
            }
            else if (scenario == 29) {
                // [B1_gradDist1_dim_above_2] gradDist1 dim=3D exceeds max=2D
                scenarioDesc = "gradDist1 dim=3D exceeds max=2D";
                violationDetail = "gradDist1 dim=3D exceeds max=2D";
                errorCategory = "B1";
                expectedErrorCode = 161002;
                expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
                errorTypeStr = "DIM_ILLEGAL";
                errorTargetStr = "gradDist1";
                verifyRequirement = "返回码应为161001或161002,错误信息应提示维度数超限";
                gradDist1Shape = {1, 1, 1};  // override
                LOG_PRINT("[B1_gradDist1_dim_above_2] gradDist1 dim=3D exceeds max=2D\n");
            }
            else if (scenario == 30) {
                // [B1_gradDist1_dim_below_2] gradDist1 dim=1D below min=2D
                scenarioDesc = "gradDist1 dim=1D below min=2D";
                violationDetail = "gradDist1 dim=1D below min=2D";
                errorCategory = "B1";
                expectedErrorCode = 161002;
                expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
                errorTypeStr = "DIM_ILLEGAL";
                errorTargetStr = "gradDist1";
                verifyRequirement = "返回码应为161001或161002,错误信息应提示维度数不足";
                gradDist1Shape = {1};  // override
                LOG_PRINT("[B1_gradDist1_dim_below_2] gradDist1 dim=1D below min=2D\n");
            }
            else if (scenario == 31) {
                // [B4_gradDist1_zero_dim] gradDist1 shape has zero dimension: [0, 4]
                scenarioDesc = "gradDist1 shape has zero dimension: [0, 4]";
                violationDetail = "gradDist1 shape has zero dimension: [0, 4]";
                errorCategory = "B4";
                expectedErrorCode = 161002;
                expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
                errorTypeStr = "SHAPE_ILLEGAL";
                errorTargetStr = "gradDist1";
                verifyRequirement = "空tensor可能合法也可能非法,需根据md文档确认;若非法应返回161001或161002";
                gradDist1Shape = {0, 4};  // override
                LOG_PRINT("[B4_gradDist1_zero_dim] gradDist1 shape has zero dimension: [0, 4]\n");
            }
            else if (scenario == 32) {
                // [D3_gradDist1_nullptr] gradDist1 tensor is nullptr (input pointer is null)
                scenarioDesc = "gradDist1 tensor is nullptr (input pointer is null)";
                violationDetail = "gradDist1 tensor is nullptr (input pointer is null)";
                errorCategory = "D3";
                expectedErrorCode = 161001;
                expectedErrorName = "ACLNN_ERR_PARAM_NULLPTR";
                errorTypeStr = "NULLPTR_INPUT";
                errorTargetStr = "gradDist1";
                verifyRequirement = "返回码应为161001,错误信息应包含null或nullptr相关提示";
                nullGradDist1 = true;
                LOG_PRINT("[D3_gradDist1_nullptr] gradDist1 tensor is nullptr (input pointer is null)\n");
            }
            else if (scenario == 33) {
                // [A1_gradDist2_ACL_INT8] gradDist2 dtype=ACL_INT8 not in supported list [FLOAT,FLOAT16]
                scenarioDesc = "gradDist2 dtype=ACL_INT8 not in supported list [FLOAT,FLOAT16]";
                violationDetail = "gradDist2=ACL_INT8";
                errorCategory = "A1";
                expectedErrorCode = 161002;
                expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
                errorTypeStr = "DTYPE_UNSUPPORTED";
                errorTargetStr = "gradDist2";
                verifyRequirement = "返回码应为161001或161002,错误信息应包含ACL_INT8不支持或invalid dtype相关提示";
                gradDist2Dtype = ACL_INT8;  // override
                LOG_PRINT("[A1_gradDist2_ACL_INT8] gradDist2 dtype=ACL_INT8 not in supported list [FLOAT,FLOAT16]\n");
            }
            else if (scenario == 34) {
                // [A1_gradDist2_ACL_INT32] gradDist2 dtype=ACL_INT32 not in supported list [FLOAT,FLOAT16]
                scenarioDesc = "gradDist2 dtype=ACL_INT32 not in supported list [FLOAT,FLOAT16]";
                violationDetail = "gradDist2=ACL_INT32";
                errorCategory = "A1";
                expectedErrorCode = 161002;
                expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
                errorTypeStr = "DTYPE_UNSUPPORTED";
                errorTargetStr = "gradDist2";
                verifyRequirement = "返回码应为161001或161002,错误信息应包含ACL_INT32不支持或invalid dtype相关提示";
                gradDist2Dtype = ACL_INT32;  // override
                LOG_PRINT("[A1_gradDist2_ACL_INT32] gradDist2 dtype=ACL_INT32 not in supported list [FLOAT,FLOAT16]\n");
            }
            else if (scenario == 35) {
                // [B1_gradDist2_dim_above_2] gradDist2 dim=3D exceeds max=2D
                scenarioDesc = "gradDist2 dim=3D exceeds max=2D";
                violationDetail = "gradDist2 dim=3D exceeds max=2D";
                errorCategory = "B1";
                expectedErrorCode = 161002;
                expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
                errorTypeStr = "DIM_ILLEGAL";
                errorTargetStr = "gradDist2";
                verifyRequirement = "返回码应为161001或161002,错误信息应提示维度数超限";
                gradDist2Shape = {1, 1, 1};  // override
                LOG_PRINT("[B1_gradDist2_dim_above_2] gradDist2 dim=3D exceeds max=2D\n");
            }
            else if (scenario == 36) {
                // [B1_gradDist2_dim_below_2] gradDist2 dim=1D below min=2D
                scenarioDesc = "gradDist2 dim=1D below min=2D";
                violationDetail = "gradDist2 dim=1D below min=2D";
                errorCategory = "B1";
                expectedErrorCode = 161002;
                expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
                errorTypeStr = "DIM_ILLEGAL";
                errorTargetStr = "gradDist2";
                verifyRequirement = "返回码应为161001或161002,错误信息应提示维度数不足";
                gradDist2Shape = {1};  // override
                LOG_PRINT("[B1_gradDist2_dim_below_2] gradDist2 dim=1D below min=2D\n");
            }
            else if (scenario == 37) {
                // [B4_gradDist2_zero_dim] gradDist2 shape has zero dimension: [0, 4]
                scenarioDesc = "gradDist2 shape has zero dimension: [0, 4]";
                violationDetail = "gradDist2 shape has zero dimension: [0, 4]";
                errorCategory = "B4";
                expectedErrorCode = 161002;
                expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
                errorTypeStr = "SHAPE_ILLEGAL";
                errorTargetStr = "gradDist2";
                verifyRequirement = "空tensor可能合法也可能非法,需根据md文档确认;若非法应返回161001或161002";
                gradDist2Shape = {0, 4};  // override
                LOG_PRINT("[B4_gradDist2_zero_dim] gradDist2 shape has zero dimension: [0, 4]\n");
            }
            else if (scenario == 38) {
                // [D3_gradDist2_nullptr] gradDist2 tensor is nullptr (input pointer is null)
                scenarioDesc = "gradDist2 tensor is nullptr (input pointer is null)";
                violationDetail = "gradDist2 tensor is nullptr (input pointer is null)";
                errorCategory = "D3";
                expectedErrorCode = 161001;
                expectedErrorName = "ACLNN_ERR_PARAM_NULLPTR";
                errorTypeStr = "NULLPTR_INPUT";
                errorTargetStr = "gradDist2";
                verifyRequirement = "返回码应为161001,错误信息应包含null或nullptr相关提示";
                nullGradDist2 = true;
                LOG_PRINT("[D3_gradDist2_nullptr] gradDist2 tensor is nullptr (input pointer is null)\n");
            }
            else if (scenario == 39) {
                // [A1_gradXyz1_ACL_INT8] gradXyz1 dtype=ACL_INT8 not in supported list [FLOAT,FLOAT16]
                scenarioDesc = "gradXyz1 dtype=ACL_INT8 not in supported list [FLOAT,FLOAT16]";
                violationDetail = "gradXyz1=ACL_INT8";
                errorCategory = "A1";
                expectedErrorCode = 161002;
                expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
                errorTypeStr = "DTYPE_UNSUPPORTED";
                errorTargetStr = "gradXyz1";
                verifyRequirement = "返回码应为161001或161002,错误信息应包含ACL_INT8不支持或invalid dtype相关提示";
                gradXyz1Dtype = ACL_INT8;  // override
                LOG_PRINT("[A1_gradXyz1_ACL_INT8] gradXyz1 dtype=ACL_INT8 not in supported list [FLOAT,FLOAT16]\n");
            }
            else if (scenario == 40) {
                // [A1_gradXyz1_ACL_INT32] gradXyz1 dtype=ACL_INT32 not in supported list [FLOAT,FLOAT16]
                scenarioDesc = "gradXyz1 dtype=ACL_INT32 not in supported list [FLOAT,FLOAT16]";
                violationDetail = "gradXyz1=ACL_INT32";
                errorCategory = "A1";
                expectedErrorCode = 161002;
                expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
                errorTypeStr = "DTYPE_UNSUPPORTED";
                errorTargetStr = "gradXyz1";
                verifyRequirement = "返回码应为161001或161002,错误信息应包含ACL_INT32不支持或invalid dtype相关提示";
                gradXyz1Dtype = ACL_INT32;  // override
                LOG_PRINT("[A1_gradXyz1_ACL_INT32] gradXyz1 dtype=ACL_INT32 not in supported list [FLOAT,FLOAT16]\n");
            }
            else if (scenario == 41) {
                // [B1_gradXyz1_dim_above_3] gradXyz1 dim=4D exceeds max=3D
                scenarioDesc = "gradXyz1 dim=4D exceeds max=3D";
                violationDetail = "gradXyz1 dim=4D exceeds max=3D";
                errorCategory = "B1";
                expectedErrorCode = 161002;
                expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
                errorTypeStr = "DIM_ILLEGAL";
                errorTargetStr = "gradXyz1";
                verifyRequirement = "返回码应为161001或161002,错误信息应提示维度数超限";
                gradXyz1Shape = {1, 1, 1, 1};  // override
                LOG_PRINT("[B1_gradXyz1_dim_above_3] gradXyz1 dim=4D exceeds max=3D\n");
            }
            else if (scenario == 42) {
                // [B1_gradXyz1_dim_below_3] gradXyz1 dim=2D below min=3D
                scenarioDesc = "gradXyz1 dim=2D below min=3D";
                violationDetail = "gradXyz1 dim=2D below min=3D";
                errorCategory = "B1";
                expectedErrorCode = 161002;
                expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
                errorTypeStr = "DIM_ILLEGAL";
                errorTargetStr = "gradXyz1";
                verifyRequirement = "返回码应为161001或161002,错误信息应提示维度数不足";
                gradXyz1Shape = {1, 1};  // override
                LOG_PRINT("[B1_gradXyz1_dim_below_3] gradXyz1 dim=2D below min=3D\n");
            }
            else if (scenario == 43) {
                // [B4_gradXyz1_zero_dim] gradXyz1 shape has zero dimension: [0, 4, 16]
                scenarioDesc = "gradXyz1 shape has zero dimension: [0, 4, 16]";
                violationDetail = "gradXyz1 shape has zero dimension: [0, 4, 16]";
                errorCategory = "B4";
                expectedErrorCode = 161002;
                expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
                errorTypeStr = "SHAPE_ILLEGAL";
                errorTargetStr = "gradXyz1";
                verifyRequirement = "空tensor可能合法也可能非法,需根据md文档确认;若非法应返回161001或161002";
                gradXyz1Shape = {0, 4, 16};  // override
                LOG_PRINT("[B4_gradXyz1_zero_dim] gradXyz1 shape has zero dimension: [0, 4, 16]\n");
            }
            else if (scenario == 44) {
                // [D3_gradXyz1_nullptr] gradXyz1 tensor is nullptr (output pointer is null)
                scenarioDesc = "gradXyz1 tensor is nullptr (output pointer is null)";
                violationDetail = "gradXyz1 tensor is nullptr (output pointer is null)";
                errorCategory = "D3";
                expectedErrorCode = 161001;
                expectedErrorName = "ACLNN_ERR_PARAM_NULLPTR";
                errorTypeStr = "NULLPTR_OUTPUT";
                errorTargetStr = "gradXyz1";
                verifyRequirement = "返回码应为161001,错误信息应包含null或nullptr相关提示";
                nullGradXyz1 = true;
                LOG_PRINT("[D3_gradXyz1_nullptr] gradXyz1 tensor is nullptr (output pointer is null)\n");
            }
            else if (scenario == 45) {
                // [A1_gradXyz2_ACL_INT8] gradXyz2 dtype=ACL_INT8 not in supported list [FLOAT,FLOAT16]
                scenarioDesc = "gradXyz2 dtype=ACL_INT8 not in supported list [FLOAT,FLOAT16]";
                violationDetail = "gradXyz2=ACL_INT8";
                errorCategory = "A1";
                expectedErrorCode = 161002;
                expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
                errorTypeStr = "DTYPE_UNSUPPORTED";
                errorTargetStr = "gradXyz2";
                verifyRequirement = "返回码应为161001或161002,错误信息应包含ACL_INT8不支持或invalid dtype相关提示";
                gradXyz2Dtype = ACL_INT8;  // override
                LOG_PRINT("[A1_gradXyz2_ACL_INT8] gradXyz2 dtype=ACL_INT8 not in supported list [FLOAT,FLOAT16]\n");
            }
            else if (scenario == 46) {
                // [A1_gradXyz2_ACL_INT32] gradXyz2 dtype=ACL_INT32 not in supported list [FLOAT,FLOAT16]
                scenarioDesc = "gradXyz2 dtype=ACL_INT32 not in supported list [FLOAT,FLOAT16]";
                violationDetail = "gradXyz2=ACL_INT32";
                errorCategory = "A1";
                expectedErrorCode = 161002;
                expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
                errorTypeStr = "DTYPE_UNSUPPORTED";
                errorTargetStr = "gradXyz2";
                verifyRequirement = "返回码应为161001或161002,错误信息应包含ACL_INT32不支持或invalid dtype相关提示";
                gradXyz2Dtype = ACL_INT32;  // override
                LOG_PRINT("[A1_gradXyz2_ACL_INT32] gradXyz2 dtype=ACL_INT32 not in supported list [FLOAT,FLOAT16]\n");
            }
            else if (scenario == 47) {
                // [B1_gradXyz2_dim_above_3] gradXyz2 dim=4D exceeds max=3D
                scenarioDesc = "gradXyz2 dim=4D exceeds max=3D";
                violationDetail = "gradXyz2 dim=4D exceeds max=3D";
                errorCategory = "B1";
                expectedErrorCode = 161002;
                expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
                errorTypeStr = "DIM_ILLEGAL";
                errorTargetStr = "gradXyz2";
                verifyRequirement = "返回码应为161001或161002,错误信息应提示维度数超限";
                gradXyz2Shape = {1, 1, 1, 1};  // override
                LOG_PRINT("[B1_gradXyz2_dim_above_3] gradXyz2 dim=4D exceeds max=3D\n");
            }
            else if (scenario == 48) {
                // [B1_gradXyz2_dim_below_3] gradXyz2 dim=2D below min=3D
                scenarioDesc = "gradXyz2 dim=2D below min=3D";
                violationDetail = "gradXyz2 dim=2D below min=3D";
                errorCategory = "B1";
                expectedErrorCode = 161002;
                expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
                errorTypeStr = "DIM_ILLEGAL";
                errorTargetStr = "gradXyz2";
                verifyRequirement = "返回码应为161001或161002,错误信息应提示维度数不足";
                gradXyz2Shape = {1, 1};  // override
                LOG_PRINT("[B1_gradXyz2_dim_below_3] gradXyz2 dim=2D below min=3D\n");
            }
            else if (scenario == 49) {
                // [B4_gradXyz2_zero_dim] gradXyz2 shape has zero dimension: [0, 4, 16]
                scenarioDesc = "gradXyz2 shape has zero dimension: [0, 4, 16]";
                violationDetail = "gradXyz2 shape has zero dimension: [0, 4, 16]";
                errorCategory = "B4";
                expectedErrorCode = 161002;
                expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
                errorTypeStr = "SHAPE_ILLEGAL";
                errorTargetStr = "gradXyz2";
                verifyRequirement = "空tensor可能合法也可能非法,需根据md文档确认;若非法应返回161001或161002";
                gradXyz2Shape = {0, 4, 16};  // override
                LOG_PRINT("[B4_gradXyz2_zero_dim] gradXyz2 shape has zero dimension: [0, 4, 16]\n");
            }
            else if (scenario == 50) {
                // [D3_gradXyz2_nullptr] gradXyz2 tensor is nullptr (output pointer is null)
                scenarioDesc = "gradXyz2 tensor is nullptr (output pointer is null)";
                violationDetail = "gradXyz2 tensor is nullptr (output pointer is null)";
                errorCategory = "D3";
                expectedErrorCode = 161001;
                expectedErrorName = "ACLNN_ERR_PARAM_NULLPTR";
                errorTypeStr = "NULLPTR_OUTPUT";
                errorTargetStr = "gradXyz2";
                verifyRequirement = "返回码应为161001,错误信息应包含null或nullptr相关提示";
                nullGradXyz2 = true;
                LOG_PRINT("[D3_gradXyz2_nullptr] gradXyz2 tensor is nullptr (output pointer is null)\n");
            }
            else if (scenario == 51) {
                // [A2_xyz2_vs_xyz1_dtype_mismatch] xyz1=ACL_FLOAT but xyz2=ACL_INT8 (pair requires same)
                scenarioDesc = "xyz1=ACL_FLOAT but xyz2=ACL_INT8 (pair requires same)";
                violationDetail = "xyz2=ACL_INT8";
                errorCategory = "A2";
                expectedErrorCode = 161002;
                expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
                errorTypeStr = "DTYPE_MISMATCH";
                errorTargetStr = "xyz2+xyz1";
                verifyRequirement = "返回码应为161001或161002,错误信息应提示dtype不匹配";
                xyz2Dtype = ACL_INT8;  // override
                LOG_PRINT("[A2_xyz2_vs_xyz1_dtype_mismatch] xyz1=ACL_FLOAT but xyz2=ACL_INT8 (pair requires same)\n");
            }
            else if (scenario == 52) {
                // [B2_xyz2_vs_xyz1_mismatch] xyz2.shape=[2, 4, 33] mismatch with xyz1.shape=[2, 4, 16]
                scenarioDesc = "xyz2.shape=[2, 4, 33] mismatch with xyz1.shape=[2, 4, 16]";
                violationDetail = "xyz2.shape=[2, 4, 33] mismatch with xyz1.shape=[2, 4, 16]";
                errorCategory = "B2";
                expectedErrorCode = 561002;
                expectedErrorName = "ACLNN_ERR_INNER_SHAPE_MISMATCH";
                errorTypeStr = "SHAPE_MISMATCH";
                errorTargetStr = "xyz2+xyz1";
                verifyRequirement = "返回码可能为561001或561002,错误信息应提示shape不匹配";
                xyz2Shape = {2, 4, 33};  // override
                LOG_PRINT("[B2_xyz2_vs_xyz1_mismatch] xyz2.shape=[2, 4, 33] mismatch with xyz1.shape=[2, 4, 16]\n");
            }
            else {
                scenarioDesc = "OUT_OF_RANGE";
                violationDetail = "scenario index exceeds total";
                errorCategory = "SKIP";
                LOG_PRINT("Scenario %d out of range (0-52), skipping\n", scenario);
            }

            // === Create tensors ===
            if (!nullXyz1) {
                long long xyz1_sz = GetShapeSize(xyz1Shape);
                if (xyz1_sz > 0 && xyz1_sz <= 1073741824) {
                    if (xyz1Dtype == ACL_FLOAT) {
                        std::vector<float> xyz1_host(xyz1_sz, 1);
                        ret = CreateAclTensor(xyz1_host, xyz1Shape, &xyz1DeviceAddr, xyz1Dtype, &xyz1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (xyz1Dtype == ACL_FLOAT16) {
                        std::vector<int16_t> xyz1_host(xyz1_sz, 1);
                        ret = CreateAclTensor(xyz1_host, xyz1Shape, &xyz1DeviceAddr, xyz1Dtype, &xyz1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (xyz1Dtype == ACL_INT8) {
                        std::vector<int8_t> xyz1_host(xyz1_sz, 1);
                        ret = CreateAclTensor(xyz1_host, xyz1Shape, &xyz1DeviceAddr, xyz1Dtype, &xyz1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (xyz1Dtype == ACL_INT32) {
                        std::vector<int32_t> xyz1_host(xyz1_sz, 1);
                        ret = CreateAclTensor(xyz1_host, xyz1Shape, &xyz1DeviceAddr, xyz1Dtype, &xyz1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (xyz1Dtype == ACL_UINT8) {
                        std::vector<uint8_t> xyz1_host(xyz1_sz, 1);
                        ret = CreateAclTensor(xyz1_host, xyz1Shape, &xyz1DeviceAddr, xyz1Dtype, &xyz1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (xyz1Dtype == ACL_INT16) {
                        std::vector<int16_t> xyz1_host(xyz1_sz, 1);
                        ret = CreateAclTensor(xyz1_host, xyz1Shape, &xyz1DeviceAddr, xyz1Dtype, &xyz1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (xyz1Dtype == ACL_UINT16) {
                        std::vector<uint16_t> xyz1_host(xyz1_sz, 1);
                        ret = CreateAclTensor(xyz1_host, xyz1Shape, &xyz1DeviceAddr, xyz1Dtype, &xyz1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (xyz1Dtype == ACL_UINT32) {
                        std::vector<uint32_t> xyz1_host(xyz1_sz, 1);
                        ret = CreateAclTensor(xyz1_host, xyz1Shape, &xyz1DeviceAddr, xyz1Dtype, &xyz1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (xyz1Dtype == ACL_INT64) {
                        std::vector<int64_t> xyz1_host(xyz1_sz, 1);
                        ret = CreateAclTensor(xyz1_host, xyz1Shape, &xyz1DeviceAddr, xyz1Dtype, &xyz1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (xyz1Dtype == ACL_UINT64) {
                        std::vector<uint64_t> xyz1_host(xyz1_sz, 1);
                        ret = CreateAclTensor(xyz1_host, xyz1Shape, &xyz1DeviceAddr, xyz1Dtype, &xyz1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (xyz1Dtype == ACL_DOUBLE) {
                        std::vector<double> xyz1_host(xyz1_sz, 1);
                        ret = CreateAclTensor(xyz1_host, xyz1Shape, &xyz1DeviceAddr, xyz1Dtype, &xyz1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (xyz1Dtype == ACL_BOOL) {
                        std::vector<int8_t> xyz1_host(xyz1_sz, 1);
                        ret = CreateAclTensor(xyz1_host, xyz1Shape, &xyz1DeviceAddr, xyz1Dtype, &xyz1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (xyz1Dtype == ACL_BF16) {
                        std::vector<int16_t> xyz1_host(xyz1_sz, 1);
                        ret = CreateAclTensor(xyz1_host, xyz1Shape, &xyz1DeviceAddr, xyz1Dtype, &xyz1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (xyz1Dtype == ACL_COMPLEX64) {
                        std::vector<float> xyz1_host((xyz1_sz * 2), 1);
                        ret = CreateAclTensor(xyz1_host, xyz1Shape, &xyz1DeviceAddr, xyz1Dtype, &xyz1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (xyz1Dtype == ACL_COMPLEX128) {
                        std::vector<double> xyz1_host((xyz1_sz * 2), 1);
                        ret = CreateAclTensor(xyz1_host, xyz1Shape, &xyz1DeviceAddr, xyz1Dtype, &xyz1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else {
                        std::vector<float> xyz1_host(xyz1_sz, 1);
                        ret = CreateAclTensor(xyz1_host, xyz1Shape, &xyz1DeviceAddr, xyz1Dtype, &xyz1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    }
                }
            } else {
                xyz1 = nullptr;
            }

            if (!nullXyz2) {
                long long xyz2_sz = GetShapeSize(xyz2Shape);
                if (xyz2_sz > 0 && xyz2_sz <= 1073741824) {
                    if (xyz2Dtype == ACL_FLOAT) {
                        std::vector<float> xyz2_host(xyz2_sz, 1);
                        ret = CreateAclTensor(xyz2_host, xyz2Shape, &xyz2DeviceAddr, xyz2Dtype, &xyz2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (xyz2Dtype == ACL_FLOAT16) {
                        std::vector<int16_t> xyz2_host(xyz2_sz, 1);
                        ret = CreateAclTensor(xyz2_host, xyz2Shape, &xyz2DeviceAddr, xyz2Dtype, &xyz2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (xyz2Dtype == ACL_INT8) {
                        std::vector<int8_t> xyz2_host(xyz2_sz, 1);
                        ret = CreateAclTensor(xyz2_host, xyz2Shape, &xyz2DeviceAddr, xyz2Dtype, &xyz2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (xyz2Dtype == ACL_INT32) {
                        std::vector<int32_t> xyz2_host(xyz2_sz, 1);
                        ret = CreateAclTensor(xyz2_host, xyz2Shape, &xyz2DeviceAddr, xyz2Dtype, &xyz2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (xyz2Dtype == ACL_UINT8) {
                        std::vector<uint8_t> xyz2_host(xyz2_sz, 1);
                        ret = CreateAclTensor(xyz2_host, xyz2Shape, &xyz2DeviceAddr, xyz2Dtype, &xyz2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (xyz2Dtype == ACL_INT16) {
                        std::vector<int16_t> xyz2_host(xyz2_sz, 1);
                        ret = CreateAclTensor(xyz2_host, xyz2Shape, &xyz2DeviceAddr, xyz2Dtype, &xyz2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (xyz2Dtype == ACL_UINT16) {
                        std::vector<uint16_t> xyz2_host(xyz2_sz, 1);
                        ret = CreateAclTensor(xyz2_host, xyz2Shape, &xyz2DeviceAddr, xyz2Dtype, &xyz2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (xyz2Dtype == ACL_UINT32) {
                        std::vector<uint32_t> xyz2_host(xyz2_sz, 1);
                        ret = CreateAclTensor(xyz2_host, xyz2Shape, &xyz2DeviceAddr, xyz2Dtype, &xyz2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (xyz2Dtype == ACL_INT64) {
                        std::vector<int64_t> xyz2_host(xyz2_sz, 1);
                        ret = CreateAclTensor(xyz2_host, xyz2Shape, &xyz2DeviceAddr, xyz2Dtype, &xyz2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (xyz2Dtype == ACL_UINT64) {
                        std::vector<uint64_t> xyz2_host(xyz2_sz, 1);
                        ret = CreateAclTensor(xyz2_host, xyz2Shape, &xyz2DeviceAddr, xyz2Dtype, &xyz2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (xyz2Dtype == ACL_DOUBLE) {
                        std::vector<double> xyz2_host(xyz2_sz, 1);
                        ret = CreateAclTensor(xyz2_host, xyz2Shape, &xyz2DeviceAddr, xyz2Dtype, &xyz2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (xyz2Dtype == ACL_BOOL) {
                        std::vector<int8_t> xyz2_host(xyz2_sz, 1);
                        ret = CreateAclTensor(xyz2_host, xyz2Shape, &xyz2DeviceAddr, xyz2Dtype, &xyz2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (xyz2Dtype == ACL_BF16) {
                        std::vector<int16_t> xyz2_host(xyz2_sz, 1);
                        ret = CreateAclTensor(xyz2_host, xyz2Shape, &xyz2DeviceAddr, xyz2Dtype, &xyz2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (xyz2Dtype == ACL_COMPLEX64) {
                        std::vector<float> xyz2_host((xyz2_sz * 2), 1);
                        ret = CreateAclTensor(xyz2_host, xyz2Shape, &xyz2DeviceAddr, xyz2Dtype, &xyz2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (xyz2Dtype == ACL_COMPLEX128) {
                        std::vector<double> xyz2_host((xyz2_sz * 2), 1);
                        ret = CreateAclTensor(xyz2_host, xyz2Shape, &xyz2DeviceAddr, xyz2Dtype, &xyz2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else {
                        std::vector<float> xyz2_host(xyz2_sz, 1);
                        ret = CreateAclTensor(xyz2_host, xyz2Shape, &xyz2DeviceAddr, xyz2Dtype, &xyz2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    }
                }
            } else {
                xyz2 = nullptr;
            }

            if (!nullIdx1) {
                long long idx1_sz = GetShapeSize(idx1Shape);
                if (idx1_sz > 0 && idx1_sz <= 1073741824) {
                    if (idx1Dtype == ACL_FLOAT) {
                        std::vector<float> iH(idx1_sz, 0);
                                            for (size_t idx = 0; idx < iH.size(); idx++) {
                                                iH[idx] = (float)(idx % (xyz2Shape.size() > 1 && xyz2Shape[1] > 0 ? (size_t)xyz2Shape[1] : 1));
                                            }
                        ret = CreateAclTensor(iH, idx1Shape, &idx1DeviceAddr, idx1Dtype, &idx1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (idx1Dtype == ACL_FLOAT16) {
                        std::vector<int16_t> iH(idx1_sz, 0);
                                            for (size_t idx = 0; idx < iH.size(); idx++) {
                                                iH[idx] = (int16_t)(idx % (xyz2Shape.size() > 1 && xyz2Shape[1] > 0 ? (size_t)xyz2Shape[1] : 1));
                                            }
                        ret = CreateAclTensor(iH, idx1Shape, &idx1DeviceAddr, idx1Dtype, &idx1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (idx1Dtype == ACL_INT8) {
                        std::vector<int8_t> iH(idx1_sz, 0);
                                            for (size_t idx = 0; idx < iH.size(); idx++) {
                                                iH[idx] = (int8_t)(idx % (xyz2Shape.size() > 1 && xyz2Shape[1] > 0 ? (size_t)xyz2Shape[1] : 1));
                                            }
                        ret = CreateAclTensor(iH, idx1Shape, &idx1DeviceAddr, idx1Dtype, &idx1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (idx1Dtype == ACL_INT32) {
                        std::vector<int32_t> iH(idx1_sz, 0);
                                            for (size_t idx = 0; idx < iH.size(); idx++) {
                                                iH[idx] = (int32_t)(idx % (xyz2Shape.size() > 1 && xyz2Shape[1] > 0 ? (size_t)xyz2Shape[1] : 1));
                                            }
                        ret = CreateAclTensor(iH, idx1Shape, &idx1DeviceAddr, idx1Dtype, &idx1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (idx1Dtype == ACL_UINT8) {
                        std::vector<uint8_t> iH(idx1_sz, 0);
                                            for (size_t idx = 0; idx < iH.size(); idx++) {
                                                iH[idx] = (uint8_t)(idx % (xyz2Shape.size() > 1 && xyz2Shape[1] > 0 ? (size_t)xyz2Shape[1] : 1));
                                            }
                        ret = CreateAclTensor(iH, idx1Shape, &idx1DeviceAddr, idx1Dtype, &idx1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (idx1Dtype == ACL_INT16) {
                        std::vector<int16_t> iH(idx1_sz, 0);
                                            for (size_t idx = 0; idx < iH.size(); idx++) {
                                                iH[idx] = (int16_t)(idx % (xyz2Shape.size() > 1 && xyz2Shape[1] > 0 ? (size_t)xyz2Shape[1] : 1));
                                            }
                        ret = CreateAclTensor(iH, idx1Shape, &idx1DeviceAddr, idx1Dtype, &idx1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (idx1Dtype == ACL_UINT16) {
                        std::vector<uint16_t> iH(idx1_sz, 0);
                                            for (size_t idx = 0; idx < iH.size(); idx++) {
                                                iH[idx] = (uint16_t)(idx % (xyz2Shape.size() > 1 && xyz2Shape[1] > 0 ? (size_t)xyz2Shape[1] : 1));
                                            }
                        ret = CreateAclTensor(iH, idx1Shape, &idx1DeviceAddr, idx1Dtype, &idx1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (idx1Dtype == ACL_UINT32) {
                        std::vector<uint32_t> iH(idx1_sz, 0);
                                            for (size_t idx = 0; idx < iH.size(); idx++) {
                                                iH[idx] = (uint32_t)(idx % (xyz2Shape.size() > 1 && xyz2Shape[1] > 0 ? (size_t)xyz2Shape[1] : 1));
                                            }
                        ret = CreateAclTensor(iH, idx1Shape, &idx1DeviceAddr, idx1Dtype, &idx1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (idx1Dtype == ACL_INT64) {
                        std::vector<int64_t> iH(idx1_sz, 0);
                                            for (size_t idx = 0; idx < iH.size(); idx++) {
                                                iH[idx] = (int64_t)(idx % (xyz2Shape.size() > 1 && xyz2Shape[1] > 0 ? (size_t)xyz2Shape[1] : 1));
                                            }
                        ret = CreateAclTensor(iH, idx1Shape, &idx1DeviceAddr, idx1Dtype, &idx1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (idx1Dtype == ACL_UINT64) {
                        std::vector<uint64_t> iH(idx1_sz, 0);
                                            for (size_t idx = 0; idx < iH.size(); idx++) {
                                                iH[idx] = (uint64_t)(idx % (xyz2Shape.size() > 1 && xyz2Shape[1] > 0 ? (size_t)xyz2Shape[1] : 1));
                                            }
                        ret = CreateAclTensor(iH, idx1Shape, &idx1DeviceAddr, idx1Dtype, &idx1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (idx1Dtype == ACL_DOUBLE) {
                        std::vector<double> iH(idx1_sz, 0);
                                            for (size_t idx = 0; idx < iH.size(); idx++) {
                                                iH[idx] = (double)(idx % (xyz2Shape.size() > 1 && xyz2Shape[1] > 0 ? (size_t)xyz2Shape[1] : 1));
                                            }
                        ret = CreateAclTensor(iH, idx1Shape, &idx1DeviceAddr, idx1Dtype, &idx1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (idx1Dtype == ACL_BOOL) {
                        std::vector<int8_t> iH(idx1_sz, 0);
                                            for (size_t idx = 0; idx < iH.size(); idx++) {
                                                iH[idx] = (int8_t)(idx % (xyz2Shape.size() > 1 && xyz2Shape[1] > 0 ? (size_t)xyz2Shape[1] : 1));
                                            }
                        ret = CreateAclTensor(iH, idx1Shape, &idx1DeviceAddr, idx1Dtype, &idx1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (idx1Dtype == ACL_BF16) {
                        std::vector<int16_t> iH(idx1_sz, 0);
                                            for (size_t idx = 0; idx < iH.size(); idx++) {
                                                iH[idx] = (int16_t)(idx % (xyz2Shape.size() > 1 && xyz2Shape[1] > 0 ? (size_t)xyz2Shape[1] : 1));
                                            }
                        ret = CreateAclTensor(iH, idx1Shape, &idx1DeviceAddr, idx1Dtype, &idx1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (idx1Dtype == ACL_COMPLEX64) {
                        std::vector<float> iH(idx1_sz, 0);
                                            for (size_t idx = 0; idx < iH.size(); idx++) {
                                                iH[idx] = (float)(idx % (xyz2Shape.size() > 1 && xyz2Shape[1] > 0 ? (size_t)xyz2Shape[1] : 1));
                                            }
                        ret = CreateAclTensor(iH, idx1Shape, &idx1DeviceAddr, idx1Dtype, &idx1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (idx1Dtype == ACL_COMPLEX128) {
                        std::vector<double> iH(idx1_sz, 0);
                                            for (size_t idx = 0; idx < iH.size(); idx++) {
                                                iH[idx] = (double)(idx % (xyz2Shape.size() > 1 && xyz2Shape[1] > 0 ? (size_t)xyz2Shape[1] : 1));
                                            }
                        ret = CreateAclTensor(iH, idx1Shape, &idx1DeviceAddr, idx1Dtype, &idx1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else {
                        std::vector<float> iH(idx1_sz, 0);
                                            for (size_t idx = 0; idx < iH.size(); idx++) {
                                                iH[idx] = (float)(idx % (xyz2Shape.size() > 1 && xyz2Shape[1] > 0 ? (size_t)xyz2Shape[1] : 1));
                                            }
                        ret = CreateAclTensor(iH, idx1Shape, &idx1DeviceAddr, idx1Dtype, &idx1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    }
                }
            } else {
                idx1 = nullptr;
            }

            if (!nullIdx2) {
                long long idx2_sz = GetShapeSize(idx2Shape);
                if (idx2_sz > 0 && idx2_sz <= 1073741824) {
                    if (idx2Dtype == ACL_FLOAT) {
                        std::vector<float> iH(idx2_sz, 0);
                                            for (size_t idx = 0; idx < iH.size(); idx++) {
                                                iH[idx] = (float)(idx % (xyz1Shape.size() > 1 && xyz1Shape[1] > 0 ? (size_t)xyz1Shape[1] : 1));
                                            }
                        ret = CreateAclTensor(iH, idx2Shape, &idx2DeviceAddr, idx2Dtype, &idx2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (idx2Dtype == ACL_FLOAT16) {
                        std::vector<int16_t> iH(idx2_sz, 0);
                                            for (size_t idx = 0; idx < iH.size(); idx++) {
                                                iH[idx] = (int16_t)(idx % (xyz1Shape.size() > 1 && xyz1Shape[1] > 0 ? (size_t)xyz1Shape[1] : 1));
                                            }
                        ret = CreateAclTensor(iH, idx2Shape, &idx2DeviceAddr, idx2Dtype, &idx2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (idx2Dtype == ACL_INT8) {
                        std::vector<int8_t> iH(idx2_sz, 0);
                                            for (size_t idx = 0; idx < iH.size(); idx++) {
                                                iH[idx] = (int8_t)(idx % (xyz1Shape.size() > 1 && xyz1Shape[1] > 0 ? (size_t)xyz1Shape[1] : 1));
                                            }
                        ret = CreateAclTensor(iH, idx2Shape, &idx2DeviceAddr, idx2Dtype, &idx2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (idx2Dtype == ACL_INT32) {
                        std::vector<int32_t> iH(idx2_sz, 0);
                                            for (size_t idx = 0; idx < iH.size(); idx++) {
                                                iH[idx] = (int32_t)(idx % (xyz1Shape.size() > 1 && xyz1Shape[1] > 0 ? (size_t)xyz1Shape[1] : 1));
                                            }
                        ret = CreateAclTensor(iH, idx2Shape, &idx2DeviceAddr, idx2Dtype, &idx2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (idx2Dtype == ACL_UINT8) {
                        std::vector<uint8_t> iH(idx2_sz, 0);
                                            for (size_t idx = 0; idx < iH.size(); idx++) {
                                                iH[idx] = (uint8_t)(idx % (xyz1Shape.size() > 1 && xyz1Shape[1] > 0 ? (size_t)xyz1Shape[1] : 1));
                                            }
                        ret = CreateAclTensor(iH, idx2Shape, &idx2DeviceAddr, idx2Dtype, &idx2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (idx2Dtype == ACL_INT16) {
                        std::vector<int16_t> iH(idx2_sz, 0);
                                            for (size_t idx = 0; idx < iH.size(); idx++) {
                                                iH[idx] = (int16_t)(idx % (xyz1Shape.size() > 1 && xyz1Shape[1] > 0 ? (size_t)xyz1Shape[1] : 1));
                                            }
                        ret = CreateAclTensor(iH, idx2Shape, &idx2DeviceAddr, idx2Dtype, &idx2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (idx2Dtype == ACL_UINT16) {
                        std::vector<uint16_t> iH(idx2_sz, 0);
                                            for (size_t idx = 0; idx < iH.size(); idx++) {
                                                iH[idx] = (uint16_t)(idx % (xyz1Shape.size() > 1 && xyz1Shape[1] > 0 ? (size_t)xyz1Shape[1] : 1));
                                            }
                        ret = CreateAclTensor(iH, idx2Shape, &idx2DeviceAddr, idx2Dtype, &idx2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (idx2Dtype == ACL_UINT32) {
                        std::vector<uint32_t> iH(idx2_sz, 0);
                                            for (size_t idx = 0; idx < iH.size(); idx++) {
                                                iH[idx] = (uint32_t)(idx % (xyz1Shape.size() > 1 && xyz1Shape[1] > 0 ? (size_t)xyz1Shape[1] : 1));
                                            }
                        ret = CreateAclTensor(iH, idx2Shape, &idx2DeviceAddr, idx2Dtype, &idx2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (idx2Dtype == ACL_INT64) {
                        std::vector<int64_t> iH(idx2_sz, 0);
                                            for (size_t idx = 0; idx < iH.size(); idx++) {
                                                iH[idx] = (int64_t)(idx % (xyz1Shape.size() > 1 && xyz1Shape[1] > 0 ? (size_t)xyz1Shape[1] : 1));
                                            }
                        ret = CreateAclTensor(iH, idx2Shape, &idx2DeviceAddr, idx2Dtype, &idx2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (idx2Dtype == ACL_UINT64) {
                        std::vector<uint64_t> iH(idx2_sz, 0);
                                            for (size_t idx = 0; idx < iH.size(); idx++) {
                                                iH[idx] = (uint64_t)(idx % (xyz1Shape.size() > 1 && xyz1Shape[1] > 0 ? (size_t)xyz1Shape[1] : 1));
                                            }
                        ret = CreateAclTensor(iH, idx2Shape, &idx2DeviceAddr, idx2Dtype, &idx2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (idx2Dtype == ACL_DOUBLE) {
                        std::vector<double> iH(idx2_sz, 0);
                                            for (size_t idx = 0; idx < iH.size(); idx++) {
                                                iH[idx] = (double)(idx % (xyz1Shape.size() > 1 && xyz1Shape[1] > 0 ? (size_t)xyz1Shape[1] : 1));
                                            }
                        ret = CreateAclTensor(iH, idx2Shape, &idx2DeviceAddr, idx2Dtype, &idx2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (idx2Dtype == ACL_BOOL) {
                        std::vector<int8_t> iH(idx2_sz, 0);
                                            for (size_t idx = 0; idx < iH.size(); idx++) {
                                                iH[idx] = (int8_t)(idx % (xyz1Shape.size() > 1 && xyz1Shape[1] > 0 ? (size_t)xyz1Shape[1] : 1));
                                            }
                        ret = CreateAclTensor(iH, idx2Shape, &idx2DeviceAddr, idx2Dtype, &idx2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (idx2Dtype == ACL_BF16) {
                        std::vector<int16_t> iH(idx2_sz, 0);
                                            for (size_t idx = 0; idx < iH.size(); idx++) {
                                                iH[idx] = (int16_t)(idx % (xyz1Shape.size() > 1 && xyz1Shape[1] > 0 ? (size_t)xyz1Shape[1] : 1));
                                            }
                        ret = CreateAclTensor(iH, idx2Shape, &idx2DeviceAddr, idx2Dtype, &idx2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (idx2Dtype == ACL_COMPLEX64) {
                        std::vector<float> iH(idx2_sz, 0);
                                            for (size_t idx = 0; idx < iH.size(); idx++) {
                                                iH[idx] = (float)(idx % (xyz1Shape.size() > 1 && xyz1Shape[1] > 0 ? (size_t)xyz1Shape[1] : 1));
                                            }
                        ret = CreateAclTensor(iH, idx2Shape, &idx2DeviceAddr, idx2Dtype, &idx2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (idx2Dtype == ACL_COMPLEX128) {
                        std::vector<double> iH(idx2_sz, 0);
                                            for (size_t idx = 0; idx < iH.size(); idx++) {
                                                iH[idx] = (double)(idx % (xyz1Shape.size() > 1 && xyz1Shape[1] > 0 ? (size_t)xyz1Shape[1] : 1));
                                            }
                        ret = CreateAclTensor(iH, idx2Shape, &idx2DeviceAddr, idx2Dtype, &idx2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else {
                        std::vector<float> iH(idx2_sz, 0);
                                            for (size_t idx = 0; idx < iH.size(); idx++) {
                                                iH[idx] = (float)(idx % (xyz1Shape.size() > 1 && xyz1Shape[1] > 0 ? (size_t)xyz1Shape[1] : 1));
                                            }
                        ret = CreateAclTensor(iH, idx2Shape, &idx2DeviceAddr, idx2Dtype, &idx2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    }
                }
            } else {
                idx2 = nullptr;
            }

            if (!nullGradDist1) {
                long long gradDist1_sz = GetShapeSize(gradDist1Shape);
                if (gradDist1_sz > 0 && gradDist1_sz <= 1073741824) {
                    if (gradDist1Dtype == ACL_FLOAT) {
                        std::vector<float> gradDist1_host(gradDist1_sz, 1);
                        ret = CreateAclTensor(gradDist1_host, gradDist1Shape, &gradDist1DeviceAddr, gradDist1Dtype, &gradDist1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradDist1Dtype == ACL_FLOAT16) {
                        std::vector<int16_t> gradDist1_host(gradDist1_sz, 1);
                        ret = CreateAclTensor(gradDist1_host, gradDist1Shape, &gradDist1DeviceAddr, gradDist1Dtype, &gradDist1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradDist1Dtype == ACL_INT8) {
                        std::vector<int8_t> gradDist1_host(gradDist1_sz, 1);
                        ret = CreateAclTensor(gradDist1_host, gradDist1Shape, &gradDist1DeviceAddr, gradDist1Dtype, &gradDist1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradDist1Dtype == ACL_INT32) {
                        std::vector<int32_t> gradDist1_host(gradDist1_sz, 1);
                        ret = CreateAclTensor(gradDist1_host, gradDist1Shape, &gradDist1DeviceAddr, gradDist1Dtype, &gradDist1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradDist1Dtype == ACL_UINT8) {
                        std::vector<uint8_t> gradDist1_host(gradDist1_sz, 1);
                        ret = CreateAclTensor(gradDist1_host, gradDist1Shape, &gradDist1DeviceAddr, gradDist1Dtype, &gradDist1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradDist1Dtype == ACL_INT16) {
                        std::vector<int16_t> gradDist1_host(gradDist1_sz, 1);
                        ret = CreateAclTensor(gradDist1_host, gradDist1Shape, &gradDist1DeviceAddr, gradDist1Dtype, &gradDist1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradDist1Dtype == ACL_UINT16) {
                        std::vector<uint16_t> gradDist1_host(gradDist1_sz, 1);
                        ret = CreateAclTensor(gradDist1_host, gradDist1Shape, &gradDist1DeviceAddr, gradDist1Dtype, &gradDist1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradDist1Dtype == ACL_UINT32) {
                        std::vector<uint32_t> gradDist1_host(gradDist1_sz, 1);
                        ret = CreateAclTensor(gradDist1_host, gradDist1Shape, &gradDist1DeviceAddr, gradDist1Dtype, &gradDist1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradDist1Dtype == ACL_INT64) {
                        std::vector<int64_t> gradDist1_host(gradDist1_sz, 1);
                        ret = CreateAclTensor(gradDist1_host, gradDist1Shape, &gradDist1DeviceAddr, gradDist1Dtype, &gradDist1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradDist1Dtype == ACL_UINT64) {
                        std::vector<uint64_t> gradDist1_host(gradDist1_sz, 1);
                        ret = CreateAclTensor(gradDist1_host, gradDist1Shape, &gradDist1DeviceAddr, gradDist1Dtype, &gradDist1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradDist1Dtype == ACL_DOUBLE) {
                        std::vector<double> gradDist1_host(gradDist1_sz, 1);
                        ret = CreateAclTensor(gradDist1_host, gradDist1Shape, &gradDist1DeviceAddr, gradDist1Dtype, &gradDist1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradDist1Dtype == ACL_BOOL) {
                        std::vector<int8_t> gradDist1_host(gradDist1_sz, 1);
                        ret = CreateAclTensor(gradDist1_host, gradDist1Shape, &gradDist1DeviceAddr, gradDist1Dtype, &gradDist1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradDist1Dtype == ACL_BF16) {
                        std::vector<int16_t> gradDist1_host(gradDist1_sz, 1);
                        ret = CreateAclTensor(gradDist1_host, gradDist1Shape, &gradDist1DeviceAddr, gradDist1Dtype, &gradDist1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradDist1Dtype == ACL_COMPLEX64) {
                        std::vector<float> gradDist1_host((gradDist1_sz * 2), 1);
                        ret = CreateAclTensor(gradDist1_host, gradDist1Shape, &gradDist1DeviceAddr, gradDist1Dtype, &gradDist1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradDist1Dtype == ACL_COMPLEX128) {
                        std::vector<double> gradDist1_host((gradDist1_sz * 2), 1);
                        ret = CreateAclTensor(gradDist1_host, gradDist1Shape, &gradDist1DeviceAddr, gradDist1Dtype, &gradDist1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else {
                        std::vector<float> gradDist1_host(gradDist1_sz, 1);
                        ret = CreateAclTensor(gradDist1_host, gradDist1Shape, &gradDist1DeviceAddr, gradDist1Dtype, &gradDist1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    }
                }
            } else {
                gradDist1 = nullptr;
            }

            if (!nullGradDist2) {
                long long gradDist2_sz = GetShapeSize(gradDist2Shape);
                if (gradDist2_sz > 0 && gradDist2_sz <= 1073741824) {
                    if (gradDist2Dtype == ACL_FLOAT) {
                        std::vector<float> gradDist2_host(gradDist2_sz, 1);
                        ret = CreateAclTensor(gradDist2_host, gradDist2Shape, &gradDist2DeviceAddr, gradDist2Dtype, &gradDist2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradDist2Dtype == ACL_FLOAT16) {
                        std::vector<int16_t> gradDist2_host(gradDist2_sz, 1);
                        ret = CreateAclTensor(gradDist2_host, gradDist2Shape, &gradDist2DeviceAddr, gradDist2Dtype, &gradDist2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradDist2Dtype == ACL_INT8) {
                        std::vector<int8_t> gradDist2_host(gradDist2_sz, 1);
                        ret = CreateAclTensor(gradDist2_host, gradDist2Shape, &gradDist2DeviceAddr, gradDist2Dtype, &gradDist2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradDist2Dtype == ACL_INT32) {
                        std::vector<int32_t> gradDist2_host(gradDist2_sz, 1);
                        ret = CreateAclTensor(gradDist2_host, gradDist2Shape, &gradDist2DeviceAddr, gradDist2Dtype, &gradDist2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradDist2Dtype == ACL_UINT8) {
                        std::vector<uint8_t> gradDist2_host(gradDist2_sz, 1);
                        ret = CreateAclTensor(gradDist2_host, gradDist2Shape, &gradDist2DeviceAddr, gradDist2Dtype, &gradDist2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradDist2Dtype == ACL_INT16) {
                        std::vector<int16_t> gradDist2_host(gradDist2_sz, 1);
                        ret = CreateAclTensor(gradDist2_host, gradDist2Shape, &gradDist2DeviceAddr, gradDist2Dtype, &gradDist2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradDist2Dtype == ACL_UINT16) {
                        std::vector<uint16_t> gradDist2_host(gradDist2_sz, 1);
                        ret = CreateAclTensor(gradDist2_host, gradDist2Shape, &gradDist2DeviceAddr, gradDist2Dtype, &gradDist2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradDist2Dtype == ACL_UINT32) {
                        std::vector<uint32_t> gradDist2_host(gradDist2_sz, 1);
                        ret = CreateAclTensor(gradDist2_host, gradDist2Shape, &gradDist2DeviceAddr, gradDist2Dtype, &gradDist2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradDist2Dtype == ACL_INT64) {
                        std::vector<int64_t> gradDist2_host(gradDist2_sz, 1);
                        ret = CreateAclTensor(gradDist2_host, gradDist2Shape, &gradDist2DeviceAddr, gradDist2Dtype, &gradDist2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradDist2Dtype == ACL_UINT64) {
                        std::vector<uint64_t> gradDist2_host(gradDist2_sz, 1);
                        ret = CreateAclTensor(gradDist2_host, gradDist2Shape, &gradDist2DeviceAddr, gradDist2Dtype, &gradDist2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradDist2Dtype == ACL_DOUBLE) {
                        std::vector<double> gradDist2_host(gradDist2_sz, 1);
                        ret = CreateAclTensor(gradDist2_host, gradDist2Shape, &gradDist2DeviceAddr, gradDist2Dtype, &gradDist2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradDist2Dtype == ACL_BOOL) {
                        std::vector<int8_t> gradDist2_host(gradDist2_sz, 1);
                        ret = CreateAclTensor(gradDist2_host, gradDist2Shape, &gradDist2DeviceAddr, gradDist2Dtype, &gradDist2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradDist2Dtype == ACL_BF16) {
                        std::vector<int16_t> gradDist2_host(gradDist2_sz, 1);
                        ret = CreateAclTensor(gradDist2_host, gradDist2Shape, &gradDist2DeviceAddr, gradDist2Dtype, &gradDist2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradDist2Dtype == ACL_COMPLEX64) {
                        std::vector<float> gradDist2_host((gradDist2_sz * 2), 1);
                        ret = CreateAclTensor(gradDist2_host, gradDist2Shape, &gradDist2DeviceAddr, gradDist2Dtype, &gradDist2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradDist2Dtype == ACL_COMPLEX128) {
                        std::vector<double> gradDist2_host((gradDist2_sz * 2), 1);
                        ret = CreateAclTensor(gradDist2_host, gradDist2Shape, &gradDist2DeviceAddr, gradDist2Dtype, &gradDist2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else {
                        std::vector<float> gradDist2_host(gradDist2_sz, 1);
                        ret = CreateAclTensor(gradDist2_host, gradDist2Shape, &gradDist2DeviceAddr, gradDist2Dtype, &gradDist2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    }
                }
            } else {
                gradDist2 = nullptr;
            }

            if (!nullGradXyz1) {
                long long gradXyz1_sz = GetShapeSize(gradXyz1Shape);
                if (gradXyz1_sz > 0 && gradXyz1_sz <= 1073741824) {
                    if (gradXyz1Dtype == ACL_FLOAT) {
                        std::vector<float> gradXyz1_host(gradXyz1_sz, 1);
                        ret = CreateAclTensor(gradXyz1_host, gradXyz1Shape, &gradXyz1DeviceAddr, gradXyz1Dtype, &gradXyz1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradXyz1Dtype == ACL_FLOAT16) {
                        std::vector<int16_t> gradXyz1_host(gradXyz1_sz, 1);
                        ret = CreateAclTensor(gradXyz1_host, gradXyz1Shape, &gradXyz1DeviceAddr, gradXyz1Dtype, &gradXyz1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradXyz1Dtype == ACL_INT8) {
                        std::vector<int8_t> gradXyz1_host(gradXyz1_sz, 1);
                        ret = CreateAclTensor(gradXyz1_host, gradXyz1Shape, &gradXyz1DeviceAddr, gradXyz1Dtype, &gradXyz1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradXyz1Dtype == ACL_INT32) {
                        std::vector<int32_t> gradXyz1_host(gradXyz1_sz, 1);
                        ret = CreateAclTensor(gradXyz1_host, gradXyz1Shape, &gradXyz1DeviceAddr, gradXyz1Dtype, &gradXyz1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradXyz1Dtype == ACL_UINT8) {
                        std::vector<uint8_t> gradXyz1_host(gradXyz1_sz, 1);
                        ret = CreateAclTensor(gradXyz1_host, gradXyz1Shape, &gradXyz1DeviceAddr, gradXyz1Dtype, &gradXyz1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradXyz1Dtype == ACL_INT16) {
                        std::vector<int16_t> gradXyz1_host(gradXyz1_sz, 1);
                        ret = CreateAclTensor(gradXyz1_host, gradXyz1Shape, &gradXyz1DeviceAddr, gradXyz1Dtype, &gradXyz1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradXyz1Dtype == ACL_UINT16) {
                        std::vector<uint16_t> gradXyz1_host(gradXyz1_sz, 1);
                        ret = CreateAclTensor(gradXyz1_host, gradXyz1Shape, &gradXyz1DeviceAddr, gradXyz1Dtype, &gradXyz1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradXyz1Dtype == ACL_UINT32) {
                        std::vector<uint32_t> gradXyz1_host(gradXyz1_sz, 1);
                        ret = CreateAclTensor(gradXyz1_host, gradXyz1Shape, &gradXyz1DeviceAddr, gradXyz1Dtype, &gradXyz1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradXyz1Dtype == ACL_INT64) {
                        std::vector<int64_t> gradXyz1_host(gradXyz1_sz, 1);
                        ret = CreateAclTensor(gradXyz1_host, gradXyz1Shape, &gradXyz1DeviceAddr, gradXyz1Dtype, &gradXyz1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradXyz1Dtype == ACL_UINT64) {
                        std::vector<uint64_t> gradXyz1_host(gradXyz1_sz, 1);
                        ret = CreateAclTensor(gradXyz1_host, gradXyz1Shape, &gradXyz1DeviceAddr, gradXyz1Dtype, &gradXyz1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradXyz1Dtype == ACL_DOUBLE) {
                        std::vector<double> gradXyz1_host(gradXyz1_sz, 1);
                        ret = CreateAclTensor(gradXyz1_host, gradXyz1Shape, &gradXyz1DeviceAddr, gradXyz1Dtype, &gradXyz1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradXyz1Dtype == ACL_BOOL) {
                        std::vector<int8_t> gradXyz1_host(gradXyz1_sz, 1);
                        ret = CreateAclTensor(gradXyz1_host, gradXyz1Shape, &gradXyz1DeviceAddr, gradXyz1Dtype, &gradXyz1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradXyz1Dtype == ACL_BF16) {
                        std::vector<int16_t> gradXyz1_host(gradXyz1_sz, 1);
                        ret = CreateAclTensor(gradXyz1_host, gradXyz1Shape, &gradXyz1DeviceAddr, gradXyz1Dtype, &gradXyz1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradXyz1Dtype == ACL_COMPLEX64) {
                        std::vector<float> gradXyz1_host((gradXyz1_sz * 2), 1);
                        ret = CreateAclTensor(gradXyz1_host, gradXyz1Shape, &gradXyz1DeviceAddr, gradXyz1Dtype, &gradXyz1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradXyz1Dtype == ACL_COMPLEX128) {
                        std::vector<double> gradXyz1_host((gradXyz1_sz * 2), 1);
                        ret = CreateAclTensor(gradXyz1_host, gradXyz1Shape, &gradXyz1DeviceAddr, gradXyz1Dtype, &gradXyz1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else {
                        std::vector<float> gradXyz1_host(gradXyz1_sz, 1);
                        ret = CreateAclTensor(gradXyz1_host, gradXyz1Shape, &gradXyz1DeviceAddr, gradXyz1Dtype, &gradXyz1);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    }
                }
            } else {
                gradXyz1 = nullptr;
            }

            if (!nullGradXyz2) {
                long long gradXyz2_sz = GetShapeSize(gradXyz2Shape);
                if (gradXyz2_sz > 0 && gradXyz2_sz <= 1073741824) {
                    if (gradXyz2Dtype == ACL_FLOAT) {
                        std::vector<float> gradXyz2_host(gradXyz2_sz, 1);
                        ret = CreateAclTensor(gradXyz2_host, gradXyz2Shape, &gradXyz2DeviceAddr, gradXyz2Dtype, &gradXyz2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradXyz2Dtype == ACL_FLOAT16) {
                        std::vector<int16_t> gradXyz2_host(gradXyz2_sz, 1);
                        ret = CreateAclTensor(gradXyz2_host, gradXyz2Shape, &gradXyz2DeviceAddr, gradXyz2Dtype, &gradXyz2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradXyz2Dtype == ACL_INT8) {
                        std::vector<int8_t> gradXyz2_host(gradXyz2_sz, 1);
                        ret = CreateAclTensor(gradXyz2_host, gradXyz2Shape, &gradXyz2DeviceAddr, gradXyz2Dtype, &gradXyz2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradXyz2Dtype == ACL_INT32) {
                        std::vector<int32_t> gradXyz2_host(gradXyz2_sz, 1);
                        ret = CreateAclTensor(gradXyz2_host, gradXyz2Shape, &gradXyz2DeviceAddr, gradXyz2Dtype, &gradXyz2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradXyz2Dtype == ACL_UINT8) {
                        std::vector<uint8_t> gradXyz2_host(gradXyz2_sz, 1);
                        ret = CreateAclTensor(gradXyz2_host, gradXyz2Shape, &gradXyz2DeviceAddr, gradXyz2Dtype, &gradXyz2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradXyz2Dtype == ACL_INT16) {
                        std::vector<int16_t> gradXyz2_host(gradXyz2_sz, 1);
                        ret = CreateAclTensor(gradXyz2_host, gradXyz2Shape, &gradXyz2DeviceAddr, gradXyz2Dtype, &gradXyz2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradXyz2Dtype == ACL_UINT16) {
                        std::vector<uint16_t> gradXyz2_host(gradXyz2_sz, 1);
                        ret = CreateAclTensor(gradXyz2_host, gradXyz2Shape, &gradXyz2DeviceAddr, gradXyz2Dtype, &gradXyz2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradXyz2Dtype == ACL_UINT32) {
                        std::vector<uint32_t> gradXyz2_host(gradXyz2_sz, 1);
                        ret = CreateAclTensor(gradXyz2_host, gradXyz2Shape, &gradXyz2DeviceAddr, gradXyz2Dtype, &gradXyz2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradXyz2Dtype == ACL_INT64) {
                        std::vector<int64_t> gradXyz2_host(gradXyz2_sz, 1);
                        ret = CreateAclTensor(gradXyz2_host, gradXyz2Shape, &gradXyz2DeviceAddr, gradXyz2Dtype, &gradXyz2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradXyz2Dtype == ACL_UINT64) {
                        std::vector<uint64_t> gradXyz2_host(gradXyz2_sz, 1);
                        ret = CreateAclTensor(gradXyz2_host, gradXyz2Shape, &gradXyz2DeviceAddr, gradXyz2Dtype, &gradXyz2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradXyz2Dtype == ACL_DOUBLE) {
                        std::vector<double> gradXyz2_host(gradXyz2_sz, 1);
                        ret = CreateAclTensor(gradXyz2_host, gradXyz2Shape, &gradXyz2DeviceAddr, gradXyz2Dtype, &gradXyz2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradXyz2Dtype == ACL_BOOL) {
                        std::vector<int8_t> gradXyz2_host(gradXyz2_sz, 1);
                        ret = CreateAclTensor(gradXyz2_host, gradXyz2Shape, &gradXyz2DeviceAddr, gradXyz2Dtype, &gradXyz2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradXyz2Dtype == ACL_BF16) {
                        std::vector<int16_t> gradXyz2_host(gradXyz2_sz, 1);
                        ret = CreateAclTensor(gradXyz2_host, gradXyz2Shape, &gradXyz2DeviceAddr, gradXyz2Dtype, &gradXyz2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradXyz2Dtype == ACL_COMPLEX64) {
                        std::vector<float> gradXyz2_host((gradXyz2_sz * 2), 1);
                        ret = CreateAclTensor(gradXyz2_host, gradXyz2Shape, &gradXyz2DeviceAddr, gradXyz2Dtype, &gradXyz2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else if (gradXyz2Dtype == ACL_COMPLEX128) {
                        std::vector<double> gradXyz2_host((gradXyz2_sz * 2), 1);
                        ret = CreateAclTensor(gradXyz2_host, gradXyz2Shape, &gradXyz2DeviceAddr, gradXyz2Dtype, &gradXyz2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    } else {
                        std::vector<float> gradXyz2_host(gradXyz2_sz, 1);
                        ret = CreateAclTensor(gradXyz2_host, gradXyz2Shape, &gradXyz2DeviceAddr, gradXyz2Dtype, &gradXyz2);
                        CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
                    }
                }
            } else {
                gradXyz2 = nullptr;
            }

            printf("[FUZZ_LOG] plog_file: aclnnChamferDistanceBackward_error_plog_case_%d.log\n", scenario);

            printf("[FUZZ_PARAM] xyz1=%s, xyz1Shape=%s, xyz2=%s, xyz2Shape=%s, idx1=%s, idx1Shape=%s, idx2=%s, idx2Shape=%s, gradDist1=%s, gradDist1Shape=%s, gradDist2=%s, gradDist2Shape=%s, gradXyz1=%s, gradXyz1Shape=%s, gradXyz2=%s, gradXyz2Shape=%s, format=ND\n", GetDtypeName(xyz1Dtype), ShapeToStr(xyz1Shape).c_str(), GetDtypeName(xyz2Dtype), ShapeToStr(xyz2Shape).c_str(), GetDtypeName(idx1Dtype), ShapeToStr(idx1Shape).c_str(), GetDtypeName(idx2Dtype), ShapeToStr(idx2Shape).c_str(), GetDtypeName(gradDist1Dtype), ShapeToStr(gradDist1Shape).c_str(), GetDtypeName(gradDist2Dtype), ShapeToStr(gradDist2Shape).c_str(), GetDtypeName(gradXyz1Dtype), ShapeToStr(gradXyz1Shape).c_str(), GetDtypeName(gradXyz2Dtype), ShapeToStr(gradXyz2Shape).c_str());

            printf("[FUZZ_ERROR_POINT] case_%d: errorType=%s, errorTarget=%s, description=%s\n", scenario, errorTypeStr.c_str(), errorTargetStr.c_str(), scenarioDesc.c_str());

            // === Call GetWorkspaceSize ===
            ret = aclnnChamferDistanceBackwardGetWorkspaceSize(xyz1, xyz2, idx1, idx2, gradDist1, gradDist2, gradXyz1, gradXyz2, &workspaceSize, &executor);
            caseRet = (int)ret;
            LOG_PRINT("aclnnChamferDistanceBackwardGetWorkspaceSize ret=%d, scenario=%d\n", ret, scenario);
            const char* rawErrMsg = aclGetRecentErrMsg();
            savedErrMsg = (rawErrMsg && rawErrMsg[0] != '\0') ? std::string(rawErrMsg) : "";
            LOG_PRINT("aclGetRecentErrMsg: %s\n", savedErrMsg.c_str());

            // === Error code verification (维测要求) ===
            printf("[FUZZ_VERIFY] case_%d: expected_code=%d, actual_code=%d, expected_name=%s, match=%s\n",
                       scenario, expectedErrorCode, caseRet, expectedErrorName.c_str(),
                       (caseRet == expectedErrorCode || (expectedErrorCode == 161001 && caseRet == 161002) || (expectedErrorCode == 161002 && caseRet == 161001)) ? "YES" : "NO");
            printf("[FUZZ_VERIFY] verify_requirement: %s\n", verifyRequirement.c_str());

            if (ret == 0) {
                if (workspaceSize > 8589934592ULL) {
                    LOG_PRINT("workspaceSize %llu exceeds 8G cap, skip phase-2 execution\n", (unsigned long long)workspaceSize);
                } else {
                if (workspaceSize > 0) {
                    ret = aclrtMalloc(&workspaceAddr, workspaceSize, ACL_MEM_MALLOC_HUGE_FIRST);
                    if (ret != ACL_SUCCESS) { caseRet = (int)ret; LOG_PRINT("aclrtMalloc failed. ERROR: %d\n", ret); goto ERROR; }
                }
                ret = aclnnChamferDistanceBackward(workspaceAddr, workspaceSize, executor, stream);
                    if (ret != ACL_SUCCESS) { caseRet = (int)ret; LOG_PRINT("aclnnChamferDistanceBackward execute failed : %d\n", ret); goto ERROR; }
                caseRet = (int)ret;
                LOG_PRINT("aclnnChamferDistanceBackward execute success : %d\n", ret);
                ret = aclrtSynchronizeStream(stream);
                    if (ret != ACL_SUCCESS) { caseRet = (int)ret; LOG_PRINT("aclrtSynchronizeStream failed. ERROR: %d\n", ret); goto ERROR; }
                }
            }

        }
        catch (std::exception& e)
        {
            printf("catch exception %s\n", e.what());
        }

    ERROR:
        ret = aclrtSynchronizeStream(stream);
        printf("end \n");
        CheckAndLog(ret);

        fflush(stdout);
        RestoreStdout();

        {
            std::string fromPath = "./opfuzz/scenario_logs/scenario_" + std::to_string(fuzzi) + ".log";
            std::string toPath = "./opfuzz/scenario_logs/scenario_" + std::to_string(scenario) + ".log";
            rename(fromPath.c_str(), toPath.c_str());
        }

        std::string aclErrMsg = savedErrMsg.empty() ? "(no aclnn error msg)" : savedErrMsg;
        std::string errType;
        if (caseRet == -1) errType = "SETUP_ERROR";
        else if (expectedErrorCode == 0) errType = (caseRet == 0) ? "BASE_CHECK_OK" : "BASE_INVALID";
        else if (caseRet == 0) errType = "UNEXPECTED_SUCCESS";
        else if (caseRet == 161001 || caseRet == 161002) errType = "PARAM_ERROR";
        else if (caseRet > 561001 && caseRet < 561119) errType = "INNER_ERROR";
        else if (caseRet > 507000 && caseRet < 507901) errType = "RUNTIME_ERROR";
        else errType = "OTHER_ERROR";

        bool hasHint = (aclErrMsg.find("should") != std::string::npos ||
                        aclErrMsg.find("must") != std::string::npos ||
                        aclErrMsg.find("expected") != std::string::npos ||
                        aclErrMsg.find("supported") != std::string::npos ||
                        aclErrMsg.find("range") != std::string::npos ||
                        aclErrMsg.find("invalid") != std::string::npos ||
                        aclErrMsg.find("mismatch") != std::string::npos);
        std::string ezVerdict = hasHint ? "PASS" : "FAIL";

        printf("== Scenario %3d | ret=%-8d | %-16s | EZ:%-4s | %s ==\n", scenario, caseRet, errType.c_str(), ezVerdict.c_str(), scenarioDesc.c_str());
        printf("   aclnn error msg: %s\n", aclErrMsg.c_str());

        ScenarioResult sr;
        sr.scenarioId = scenario;
        sr.retCode = caseRet;
        sr.desc = scenarioDesc;
        sr.violation = violationDetail;
        sr.category = errorCategory;
        sr.errorType = errType;
        sr.aclErrMsg = aclErrMsg;
        g_allResults.push_back(sr);

        pid_t pid = getpid();
        std::string cmd = "grep -rinE 'ai(vec|core) error' /root/ascend/log/debug/plog/ ";
        printf("system return value %d\n", CheckResult(pid));

        if (xyz1 != nullptr) { aclDestroyTensor(xyz1); xyz1 = nullptr; }
        if (xyz2 != nullptr) { aclDestroyTensor(xyz2); xyz2 = nullptr; }
        if (idx1 != nullptr) { aclDestroyTensor(idx1); idx1 = nullptr; }
        if (idx2 != nullptr) { aclDestroyTensor(idx2); idx2 = nullptr; }
        if (gradDist1 != nullptr) { aclDestroyTensor(gradDist1); gradDist1 = nullptr; }
        if (gradDist2 != nullptr) { aclDestroyTensor(gradDist2); gradDist2 = nullptr; }
        if (gradXyz1 != nullptr) { aclDestroyTensor(gradXyz1); gradXyz1 = nullptr; }
        if (gradXyz2 != nullptr) { aclDestroyTensor(gradXyz2); gradXyz2 = nullptr; }
        if (xyz1DeviceAddr != nullptr) { aclrtFree(xyz1DeviceAddr); xyz1DeviceAddr = nullptr; }
        if (xyz2DeviceAddr != nullptr) { aclrtFree(xyz2DeviceAddr); xyz2DeviceAddr = nullptr; }
        if (idx1DeviceAddr != nullptr) { aclrtFree(idx1DeviceAddr); idx1DeviceAddr = nullptr; }
        if (idx2DeviceAddr != nullptr) { aclrtFree(idx2DeviceAddr); idx2DeviceAddr = nullptr; }
        if (gradDist1DeviceAddr != nullptr) { aclrtFree(gradDist1DeviceAddr); gradDist1DeviceAddr = nullptr; }
        if (gradDist2DeviceAddr != nullptr) { aclrtFree(gradDist2DeviceAddr); gradDist2DeviceAddr = nullptr; }
        if (gradXyz1DeviceAddr != nullptr) { aclrtFree(gradXyz1DeviceAddr); gradXyz1DeviceAddr = nullptr; }
        if (gradXyz2DeviceAddr != nullptr) { aclrtFree(gradXyz2DeviceAddr); gradXyz2DeviceAddr = nullptr; }
        if (workspaceSize > 0) { aclrtFree(workspaceAddr); }
    }
    DT_FUZZ_END()

    GenerateFinalSummary();

    WriteDTLog("aclnnChamferDistanceBackward", "aclnnChamferDistanceBackward op fuzz total number:%u, para error number %u, execute error number %u \n",
               fuzz_num, aclnn_INVALID_Para, aclnn_Inner_Error + Runtime_Error);
    WriteDTLog("aclnnChamferDistanceBackward", "aclnnChamferDistanceBackward op fuzz end\n");
    aclrtDestroyStream(stream);
    aclrtDestroyContext(context);
    aclrtResetDevice(deviceId);
    aclFinalize();
    return 0;
}

extern "C" int aclnnChamferDistanceBackward_error_fuzz(int argc, char *argv[]);
int aclnnChamferDistanceBackward_error_fuzz(int argc, char *argv[])
{
    int fuzz_num = MAXFUZZNUMBER;
    if (argc < 2) {
        cout << "[ERROR] usage: " << argv[0] << " " << argv[1] << " [fuzz_num] [deviceId]" << endl;
        return -1;
    } else if (argc > 2 && argv[2] != nullptr) {
        fuzz_num = atoi(argv[2]);
    }
    if (argc == 4) { deviceId = atoi(argv[3]); }
    printf("fuzz_num %d \n", fuzz_num);
    printf("aclnnChamferDistanceBackward_Normal :%d \n", aclnnChamferDistanceBackward_Normal(fuzz_num));
    return 0;
}