#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_adaptive_max_pool3d.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 const char* FormatName(aclFormat fmt) {
switch (fmt) {
case ACL_FORMAT_ND: return "ND";
case ACL_FORMAT_NCHW: return "NCHW";
case ACL_FORMAT_NHWC: return "NHWC";
case ACL_FORMAT_NDHWC: return "NDHWC";
case ACL_FORMAT_NCL: return "NCL";
case ACL_FORMAT_FRACTAL_NZ: return "FRACTAL_NZ";
default: return "FMT?";
}
}
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: aclnnAdaptiveMaxPool3d" << 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("aclnnAdaptiveMaxPool3d", "FINAL: total=%d detected=%d param=%d inner=%d runtime=%d unexpected=%d rate=%d%%\n",
total, detected, paramErr, innerErr, runtimeErr, unexpectedOk, rate);
}
int aclnnAdaptiveMaxPool3d_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("aclnnAdaptiveMaxPool3d", "aclnnAdaptiveMaxPool3d error scenario test start\n");
aclrtSetOpExecuteTimeOut(1091);
DT_Set_TimeOut_Second(3000);
DT_FUZZ_START(0, fuzz_num, "aclnnAdaptiveMaxPool3d", 0)
{
int i = 0;
void* selfDeviceAddr = nullptr;
aclTensor* self = nullptr;
aclIntArray* outputSize = nullptr;
void* outputOutDeviceAddr = nullptr;
aclTensor* outputOut = nullptr;
void* indicesOutDeviceAddr = nullptr;
aclTensor* indicesOut = 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("aclnnAdaptiveMaxPool3d error test %d\n", fuzzi);
RedirectStdoutToScenarioFile(fuzzi);
try
{
scenario = *(int *)DTSetGetNumberRange(&g_Element[i++], 0, 0, 20, "i");
std::vector<int64_t> selfShape = {2, 4, 16, 2};
std::vector<int64_t> outputOutShape = {2, 4, 16};
std::vector<int64_t> indicesOutShape = {2, 4, 16};
aclDataType selfDtype = ACL_BF16;
aclDataType outputOutDtype = ACL_BF16;
aclDataType indicesOutDtype = ACL_INT32;
std::vector<int64_t> outputSizeVec = {2, 2};
outputSizeVec.reserve(16);
aclFormat selfFormat = ACL_FORMAT_NCHW;
aclFormat outputOutFormat = ACL_FORMAT_NCHW;
aclFormat indicesOutFormat = ACL_FORMAT_NCHW;
bool nullSelf = false, nullOutputSize = false, nullOutputOut = false, nullIndicesOut = false;
if (scenario == 0) {
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) {
scenarioDesc = "self dtype=ACL_INT8 not in supported list [BF16,FLOAT16,FLOAT]";
violationDetail = "self=ACL_INT8";
errorCategory = "A1";
expectedErrorCode = 161002;
expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
errorTypeStr = "DTYPE_UNSUPPORTED";
errorTargetStr = "self";
verifyRequirement = "返回码应为161001或161002,错误信息应包含ACL_INT8不支持或invalid dtype相关提示";
selfDtype = ACL_INT8;
LOG_PRINT("[A1_self_ACL_INT8] self dtype=ACL_INT8 not in supported list [BF16,FLOAT16,FLOAT]\n");
}
else if (scenario == 2) {
scenarioDesc = "self dtype=ACL_INT32 not in supported list [BF16,FLOAT16,FLOAT]";
violationDetail = "self=ACL_INT32";
errorCategory = "A1";
expectedErrorCode = 161002;
expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
errorTypeStr = "DTYPE_UNSUPPORTED";
errorTargetStr = "self";
verifyRequirement = "返回码应为161001或161002,错误信息应包含ACL_INT32不支持或invalid dtype相关提示";
selfDtype = ACL_INT32;
LOG_PRINT("[A1_self_ACL_INT32] self dtype=ACL_INT32 not in supported list [BF16,FLOAT16,FLOAT]\n");
}
else if (scenario == 3) {
scenarioDesc = "self dim=9D exceeds max=8D";
violationDetail = "self dim=9D exceeds max=8D";
errorCategory = "B1";
expectedErrorCode = 161002;
expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
errorTypeStr = "DIM_ILLEGAL";
errorTargetStr = "self";
verifyRequirement = "返回码应为161001或161002,错误信息应提示维度数超限";
selfShape = {1, 1, 1, 1, 1, 1, 1, 1, 1};
LOG_PRINT("[B1_self_dim_above_8] self dim=9D exceeds max=8D\n");
}
else if (scenario == 4) {
scenarioDesc = "self shape has zero dimension: [0, 4, 16, 2]";
violationDetail = "self shape has zero dimension: [0, 4, 16, 2]";
errorCategory = "B4";
expectedErrorCode = 161002;
expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
errorTypeStr = "SHAPE_ILLEGAL";
errorTargetStr = "self";
verifyRequirement = "空tensor可能合法也可能非法,需根据md文档确认;若非法应返回161001或161002";
selfShape = {0, 4, 16, 2};
LOG_PRINT("[B4_self_zero_dim] self shape has zero dimension: [0, 4, 16, 2]\n");
}
else if (scenario == 5) {
scenarioDesc = "self format=ACL_FORMAT_NHWC (only NCHW supported)";
violationDetail = "self format=ACL_FORMAT_NHWC (only NCHW supported)";
errorCategory = "C1";
expectedErrorCode = 161002;
expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
errorTypeStr = "FORMAT_UNSUPPORTED";
errorTargetStr = "self";
verifyRequirement = "返回码应为161001或161002,错误信息应提示format不支持";
selfFormat = ACL_FORMAT_NHWC;
LOG_PRINT("[C1_self_NHWC] self format=ACL_FORMAT_NHWC (only NCHW supported)\n");
}
else if (scenario == 6) {
scenarioDesc = "self tensor is nullptr (input pointer is null)";
violationDetail = "self tensor is nullptr (input pointer is null)";
errorCategory = "D3";
expectedErrorCode = 161001;
expectedErrorName = "ACLNN_ERR_PARAM_NULLPTR";
errorTypeStr = "NULLPTR_INPUT";
errorTargetStr = "self";
verifyRequirement = "返回码应为161001,错误信息应包含null或nullptr相关提示";
nullSelf = true;
LOG_PRINT("[D3_self_nullptr] self tensor is nullptr (input pointer is null)\n");
}
else if (scenario == 7) {
scenarioDesc = "outputSize tensor is nullptr (input pointer is null)";
violationDetail = "outputSize tensor is nullptr (input pointer is null)";
errorCategory = "D3";
expectedErrorCode = 161001;
expectedErrorName = "ACLNN_ERR_PARAM_NULLPTR";
errorTypeStr = "NULLPTR_INPUT";
errorTargetStr = "outputSize";
verifyRequirement = "返回码应为161001,错误信息应包含null或nullptr相关提示";
nullOutputSize = true;
LOG_PRINT("[D3_outputSize_nullptr] outputSize tensor is nullptr (input pointer is null)\n");
}
else if (scenario == 8) {
scenarioDesc = "outputSize is empty array [] with no elements (length=0)";
violationDetail = "outputSize is empty array [] with no elements (length=0)";
errorCategory = "E0";
expectedErrorCode = 161002;
expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
errorTypeStr = "ATTR_ILLEGAL";
errorTargetStr = "outputSize";
verifyRequirement = "空数组[]场景:若算子要求非空数组应返回161001或161002;若接受空数组则记录为资料约束问题";
outputSizeVec.clear();
LOG_PRINT("[E0_outputSize_empty_array] outputSize is empty array [] with no elements (length=0)\n");
}
else if (scenario == 9) {
scenarioDesc = "outputOut dtype=ACL_INT8 not in supported list [BF16,FLOAT16,FLOAT]";
violationDetail = "outputOut=ACL_INT8";
errorCategory = "A1";
expectedErrorCode = 161002;
expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
errorTypeStr = "DTYPE_UNSUPPORTED";
errorTargetStr = "outputOut";
verifyRequirement = "返回码应为161001或161002,错误信息应包含ACL_INT8不支持或invalid dtype相关提示";
outputOutDtype = ACL_INT8;
LOG_PRINT("[A1_outputOut_ACL_INT8] outputOut dtype=ACL_INT8 not in supported list [BF16,FLOAT16,FLOAT]\n");
}
else if (scenario == 10) {
scenarioDesc = "outputOut dtype=ACL_INT32 not in supported list [BF16,FLOAT16,FLOAT]";
violationDetail = "outputOut=ACL_INT32";
errorCategory = "A1";
expectedErrorCode = 161002;
expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
errorTypeStr = "DTYPE_UNSUPPORTED";
errorTargetStr = "outputOut";
verifyRequirement = "返回码应为161001或161002,错误信息应包含ACL_INT32不支持或invalid dtype相关提示";
outputOutDtype = ACL_INT32;
LOG_PRINT("[A1_outputOut_ACL_INT32] outputOut dtype=ACL_INT32 not in supported list [BF16,FLOAT16,FLOAT]\n");
}
else if (scenario == 11) {
scenarioDesc = "outputOut dim=9D exceeds max=8D";
violationDetail = "outputOut dim=9D exceeds max=8D";
errorCategory = "B1";
expectedErrorCode = 161002;
expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
errorTypeStr = "DIM_ILLEGAL";
errorTargetStr = "outputOut";
verifyRequirement = "返回码应为161001或161002,错误信息应提示维度数超限";
outputOutShape = {1, 1, 1, 1, 1, 1, 1, 1, 1};
LOG_PRINT("[B1_outputOut_dim_above_8] outputOut dim=9D exceeds max=8D\n");
}
else if (scenario == 12) {
scenarioDesc = "outputOut shape has zero dimension: [0, 4, 16]";
violationDetail = "outputOut shape has zero dimension: [0, 4, 16]";
errorCategory = "B4";
expectedErrorCode = 161002;
expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
errorTypeStr = "SHAPE_ILLEGAL";
errorTargetStr = "outputOut";
verifyRequirement = "空tensor可能合法也可能非法,需根据md文档确认;若非法应返回161001或161002";
outputOutShape = {0, 4, 16};
LOG_PRINT("[B4_outputOut_zero_dim] outputOut shape has zero dimension: [0, 4, 16]\n");
}
else if (scenario == 13) {
scenarioDesc = "outputOut format=ACL_FORMAT_NHWC (only NCHW supported)";
violationDetail = "outputOut format=ACL_FORMAT_NHWC (only NCHW supported)";
errorCategory = "C1";
expectedErrorCode = 161002;
expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
errorTypeStr = "FORMAT_UNSUPPORTED";
errorTargetStr = "outputOut";
verifyRequirement = "返回码应为161001或161002,错误信息应提示format不支持";
outputOutFormat = ACL_FORMAT_NHWC;
LOG_PRINT("[C1_outputOut_NHWC] outputOut format=ACL_FORMAT_NHWC (only NCHW supported)\n");
}
else if (scenario == 14) {
scenarioDesc = "outputOut tensor is nullptr (output pointer is null)";
violationDetail = "outputOut tensor is nullptr (output pointer is null)";
errorCategory = "D3";
expectedErrorCode = 161001;
expectedErrorName = "ACLNN_ERR_PARAM_NULLPTR";
errorTypeStr = "NULLPTR_OUTPUT";
errorTargetStr = "outputOut";
verifyRequirement = "返回码应为161001,错误信息应包含null或nullptr相关提示";
nullOutputOut = true;
LOG_PRINT("[D3_outputOut_nullptr] outputOut tensor is nullptr (output pointer is null)\n");
}
else if (scenario == 15) {
scenarioDesc = "indicesOut dtype=ACL_INT8 not in supported list [INT32,INT64]";
violationDetail = "indicesOut=ACL_INT8";
errorCategory = "A1";
expectedErrorCode = 161002;
expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
errorTypeStr = "DTYPE_UNSUPPORTED";
errorTargetStr = "indicesOut";
verifyRequirement = "返回码应为161001或161002,错误信息应包含ACL_INT8不支持或invalid dtype相关提示";
indicesOutDtype = ACL_INT8;
LOG_PRINT("[A1_indicesOut_ACL_INT8] indicesOut dtype=ACL_INT8 not in supported list [INT32,INT64]\n");
}
else if (scenario == 16) {
scenarioDesc = "indicesOut dtype=ACL_BOOL not in supported list [INT32,INT64]";
violationDetail = "indicesOut=ACL_BOOL";
errorCategory = "A1";
expectedErrorCode = 161002;
expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
errorTypeStr = "DTYPE_UNSUPPORTED";
errorTargetStr = "indicesOut";
verifyRequirement = "返回码应为161001或161002,错误信息应包含ACL_BOOL不支持或invalid dtype相关提示";
indicesOutDtype = ACL_BOOL;
LOG_PRINT("[A1_indicesOut_ACL_BOOL] indicesOut dtype=ACL_BOOL not in supported list [INT32,INT64]\n");
}
else if (scenario == 17) {
scenarioDesc = "indicesOut dim=9D exceeds max=8D";
violationDetail = "indicesOut dim=9D exceeds max=8D";
errorCategory = "B1";
expectedErrorCode = 161002;
expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
errorTypeStr = "DIM_ILLEGAL";
errorTargetStr = "indicesOut";
verifyRequirement = "返回码应为161001或161002,错误信息应提示维度数超限";
indicesOutShape = {1, 1, 1, 1, 1, 1, 1, 1, 1};
LOG_PRINT("[B1_indicesOut_dim_above_8] indicesOut dim=9D exceeds max=8D\n");
}
else if (scenario == 18) {
scenarioDesc = "indicesOut shape has zero dimension: [0, 4, 16]";
violationDetail = "indicesOut shape has zero dimension: [0, 4, 16]";
errorCategory = "B4";
expectedErrorCode = 161002;
expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
errorTypeStr = "SHAPE_ILLEGAL";
errorTargetStr = "indicesOut";
verifyRequirement = "空tensor可能合法也可能非法,需根据md文档确认;若非法应返回161001或161002";
indicesOutShape = {0, 4, 16};
LOG_PRINT("[B4_indicesOut_zero_dim] indicesOut shape has zero dimension: [0, 4, 16]\n");
}
else if (scenario == 19) {
scenarioDesc = "indicesOut format=ACL_FORMAT_NHWC (only NCHW supported)";
violationDetail = "indicesOut format=ACL_FORMAT_NHWC (only NCHW supported)";
errorCategory = "C1";
expectedErrorCode = 161002;
expectedErrorName = "ACLNN_ERR_PARAM_INVALID";
errorTypeStr = "FORMAT_UNSUPPORTED";
errorTargetStr = "indicesOut";
verifyRequirement = "返回码应为161001或161002,错误信息应提示format不支持";
indicesOutFormat = ACL_FORMAT_NHWC;
LOG_PRINT("[C1_indicesOut_NHWC] indicesOut format=ACL_FORMAT_NHWC (only NCHW supported)\n");
}
else if (scenario == 20) {
scenarioDesc = "indicesOut tensor is nullptr (output pointer is null)";
violationDetail = "indicesOut tensor is nullptr (output pointer is null)";
errorCategory = "D3";
expectedErrorCode = 161001;
expectedErrorName = "ACLNN_ERR_PARAM_NULLPTR";
errorTypeStr = "NULLPTR_OUTPUT";
errorTargetStr = "indicesOut";
verifyRequirement = "返回码应为161001,错误信息应包含null或nullptr相关提示";
nullIndicesOut = true;
LOG_PRINT("[D3_indicesOut_nullptr] indicesOut tensor is nullptr (output pointer is null)\n");
}
else {
scenarioDesc = "OUT_OF_RANGE";
violationDetail = "scenario index exceeds total";
errorCategory = "SKIP";
LOG_PRINT("Scenario %d out of range (0-20), skipping\n", scenario);
}
if (!nullSelf) {
long long self_sz = GetShapeSize(selfShape);
if (self_sz > 0 && self_sz <= 1073741824) {
if (selfDtype == ACL_FLOAT) {
std::vector<float> self_host(self_sz, 1);
ret = CreateAclTensor_New(self_host, selfShape, &selfDeviceAddr, selfDtype, selfFormat, &self);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (selfDtype == ACL_FLOAT16) {
std::vector<int16_t> self_host(self_sz, 1);
ret = CreateAclTensor_New(self_host, selfShape, &selfDeviceAddr, selfDtype, selfFormat, &self);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (selfDtype == ACL_INT8) {
std::vector<int8_t> self_host(self_sz, 1);
ret = CreateAclTensor_New(self_host, selfShape, &selfDeviceAddr, selfDtype, selfFormat, &self);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (selfDtype == ACL_INT32) {
std::vector<int32_t> self_host(self_sz, 1);
ret = CreateAclTensor_New(self_host, selfShape, &selfDeviceAddr, selfDtype, selfFormat, &self);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (selfDtype == ACL_UINT8) {
std::vector<uint8_t> self_host(self_sz, 1);
ret = CreateAclTensor_New(self_host, selfShape, &selfDeviceAddr, selfDtype, selfFormat, &self);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (selfDtype == ACL_INT16) {
std::vector<int16_t> self_host(self_sz, 1);
ret = CreateAclTensor_New(self_host, selfShape, &selfDeviceAddr, selfDtype, selfFormat, &self);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (selfDtype == ACL_UINT16) {
std::vector<uint16_t> self_host(self_sz, 1);
ret = CreateAclTensor_New(self_host, selfShape, &selfDeviceAddr, selfDtype, selfFormat, &self);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (selfDtype == ACL_UINT32) {
std::vector<uint32_t> self_host(self_sz, 1);
ret = CreateAclTensor_New(self_host, selfShape, &selfDeviceAddr, selfDtype, selfFormat, &self);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (selfDtype == ACL_INT64) {
std::vector<int64_t> self_host(self_sz, 1);
ret = CreateAclTensor_New(self_host, selfShape, &selfDeviceAddr, selfDtype, selfFormat, &self);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (selfDtype == ACL_UINT64) {
std::vector<uint64_t> self_host(self_sz, 1);
ret = CreateAclTensor_New(self_host, selfShape, &selfDeviceAddr, selfDtype, selfFormat, &self);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (selfDtype == ACL_DOUBLE) {
std::vector<double> self_host(self_sz, 1);
ret = CreateAclTensor_New(self_host, selfShape, &selfDeviceAddr, selfDtype, selfFormat, &self);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (selfDtype == ACL_BOOL) {
std::vector<int8_t> self_host(self_sz, 1);
ret = CreateAclTensor_New(self_host, selfShape, &selfDeviceAddr, selfDtype, selfFormat, &self);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (selfDtype == ACL_COMPLEX64) {
std::vector<float> self_host((self_sz * 2), 1);
ret = CreateAclTensor_New(self_host, selfShape, &selfDeviceAddr, selfDtype, selfFormat, &self);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (selfDtype == ACL_COMPLEX128) {
std::vector<double> self_host((self_sz * 2), 1);
ret = CreateAclTensor_New(self_host, selfShape, &selfDeviceAddr, selfDtype, selfFormat, &self);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (selfDtype == ACL_BF16) {
std::vector<int16_t> self_host(self_sz, 1);
ret = CreateAclTensor_New(self_host, selfShape, &selfDeviceAddr, selfDtype, selfFormat, &self);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (selfDtype == ACL_INT4) {
std::vector<int8_t> self_host(self_sz, 1);
ret = CreateAclTensor_New(self_host, selfShape, &selfDeviceAddr, selfDtype, selfFormat, &self);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (selfDtype == ACL_UINT1) {
std::vector<int8_t> self_host(self_sz, 1);
ret = CreateAclTensor_New(self_host, selfShape, &selfDeviceAddr, selfDtype, selfFormat, &self);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (selfDtype == ACL_COMPLEX32) {
std::vector<float> self_host((self_sz * 2), 1);
ret = CreateAclTensor_New(self_host, selfShape, &selfDeviceAddr, selfDtype, selfFormat, &self);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (selfDtype == ACL_HIFLOAT8) {
std::vector<int8_t> self_host(self_sz, 1);
ret = CreateAclTensor_New(self_host, selfShape, &selfDeviceAddr, selfDtype, selfFormat, &self);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (selfDtype == ACL_FLOAT8_E5M2) {
std::vector<int8_t> self_host(self_sz, 1);
ret = CreateAclTensor_New(self_host, selfShape, &selfDeviceAddr, selfDtype, selfFormat, &self);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (selfDtype == ACL_FLOAT8_E4M3FN) {
std::vector<int8_t> self_host(self_sz, 1);
ret = CreateAclTensor_New(self_host, selfShape, &selfDeviceAddr, selfDtype, selfFormat, &self);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (selfDtype == ACL_FLOAT8_E8M0) {
std::vector<int8_t> self_host(self_sz, 1);
ret = CreateAclTensor_New(self_host, selfShape, &selfDeviceAddr, selfDtype, selfFormat, &self);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (selfDtype == ACL_FLOAT4_E2M1) {
std::vector<int8_t> self_host(self_sz, 1);
ret = CreateAclTensor_New(self_host, selfShape, &selfDeviceAddr, selfDtype, selfFormat, &self);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else {
std::vector<float> self_host(self_sz, 1);
ret = CreateAclTensor_New(self_host, selfShape, &selfDeviceAddr, selfDtype, selfFormat, &self);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
}
}
} else {
self = nullptr;
}
if (!nullOutputSize) {
outputSize = aclCreateIntArray(outputSizeVec.data(), outputSizeVec.size());
} else {
outputSize = nullptr;
}
if (!nullOutputOut) {
long long outputOut_sz = GetShapeSize(outputOutShape);
if (outputOut_sz > 0 && outputOut_sz <= 1073741824) {
if (outputOutDtype == ACL_FLOAT) {
std::vector<float> outputOut_host(outputOut_sz, 1);
ret = CreateAclTensor_New(outputOut_host, outputOutShape, &outputOutDeviceAddr, outputOutDtype, outputOutFormat, &outputOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (outputOutDtype == ACL_FLOAT16) {
std::vector<int16_t> outputOut_host(outputOut_sz, 1);
ret = CreateAclTensor_New(outputOut_host, outputOutShape, &outputOutDeviceAddr, outputOutDtype, outputOutFormat, &outputOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (outputOutDtype == ACL_INT8) {
std::vector<int8_t> outputOut_host(outputOut_sz, 1);
ret = CreateAclTensor_New(outputOut_host, outputOutShape, &outputOutDeviceAddr, outputOutDtype, outputOutFormat, &outputOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (outputOutDtype == ACL_INT32) {
std::vector<int32_t> outputOut_host(outputOut_sz, 1);
ret = CreateAclTensor_New(outputOut_host, outputOutShape, &outputOutDeviceAddr, outputOutDtype, outputOutFormat, &outputOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (outputOutDtype == ACL_UINT8) {
std::vector<uint8_t> outputOut_host(outputOut_sz, 1);
ret = CreateAclTensor_New(outputOut_host, outputOutShape, &outputOutDeviceAddr, outputOutDtype, outputOutFormat, &outputOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (outputOutDtype == ACL_INT16) {
std::vector<int16_t> outputOut_host(outputOut_sz, 1);
ret = CreateAclTensor_New(outputOut_host, outputOutShape, &outputOutDeviceAddr, outputOutDtype, outputOutFormat, &outputOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (outputOutDtype == ACL_UINT16) {
std::vector<uint16_t> outputOut_host(outputOut_sz, 1);
ret = CreateAclTensor_New(outputOut_host, outputOutShape, &outputOutDeviceAddr, outputOutDtype, outputOutFormat, &outputOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (outputOutDtype == ACL_UINT32) {
std::vector<uint32_t> outputOut_host(outputOut_sz, 1);
ret = CreateAclTensor_New(outputOut_host, outputOutShape, &outputOutDeviceAddr, outputOutDtype, outputOutFormat, &outputOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (outputOutDtype == ACL_INT64) {
std::vector<int64_t> outputOut_host(outputOut_sz, 1);
ret = CreateAclTensor_New(outputOut_host, outputOutShape, &outputOutDeviceAddr, outputOutDtype, outputOutFormat, &outputOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (outputOutDtype == ACL_UINT64) {
std::vector<uint64_t> outputOut_host(outputOut_sz, 1);
ret = CreateAclTensor_New(outputOut_host, outputOutShape, &outputOutDeviceAddr, outputOutDtype, outputOutFormat, &outputOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (outputOutDtype == ACL_DOUBLE) {
std::vector<double> outputOut_host(outputOut_sz, 1);
ret = CreateAclTensor_New(outputOut_host, outputOutShape, &outputOutDeviceAddr, outputOutDtype, outputOutFormat, &outputOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (outputOutDtype == ACL_BOOL) {
std::vector<int8_t> outputOut_host(outputOut_sz, 1);
ret = CreateAclTensor_New(outputOut_host, outputOutShape, &outputOutDeviceAddr, outputOutDtype, outputOutFormat, &outputOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (outputOutDtype == ACL_COMPLEX64) {
std::vector<float> outputOut_host((outputOut_sz * 2), 1);
ret = CreateAclTensor_New(outputOut_host, outputOutShape, &outputOutDeviceAddr, outputOutDtype, outputOutFormat, &outputOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (outputOutDtype == ACL_COMPLEX128) {
std::vector<double> outputOut_host((outputOut_sz * 2), 1);
ret = CreateAclTensor_New(outputOut_host, outputOutShape, &outputOutDeviceAddr, outputOutDtype, outputOutFormat, &outputOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (outputOutDtype == ACL_BF16) {
std::vector<int16_t> outputOut_host(outputOut_sz, 1);
ret = CreateAclTensor_New(outputOut_host, outputOutShape, &outputOutDeviceAddr, outputOutDtype, outputOutFormat, &outputOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (outputOutDtype == ACL_INT4) {
std::vector<int8_t> outputOut_host(outputOut_sz, 1);
ret = CreateAclTensor_New(outputOut_host, outputOutShape, &outputOutDeviceAddr, outputOutDtype, outputOutFormat, &outputOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (outputOutDtype == ACL_UINT1) {
std::vector<int8_t> outputOut_host(outputOut_sz, 1);
ret = CreateAclTensor_New(outputOut_host, outputOutShape, &outputOutDeviceAddr, outputOutDtype, outputOutFormat, &outputOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (outputOutDtype == ACL_COMPLEX32) {
std::vector<float> outputOut_host((outputOut_sz * 2), 1);
ret = CreateAclTensor_New(outputOut_host, outputOutShape, &outputOutDeviceAddr, outputOutDtype, outputOutFormat, &outputOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (outputOutDtype == ACL_HIFLOAT8) {
std::vector<int8_t> outputOut_host(outputOut_sz, 1);
ret = CreateAclTensor_New(outputOut_host, outputOutShape, &outputOutDeviceAddr, outputOutDtype, outputOutFormat, &outputOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (outputOutDtype == ACL_FLOAT8_E5M2) {
std::vector<int8_t> outputOut_host(outputOut_sz, 1);
ret = CreateAclTensor_New(outputOut_host, outputOutShape, &outputOutDeviceAddr, outputOutDtype, outputOutFormat, &outputOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (outputOutDtype == ACL_FLOAT8_E4M3FN) {
std::vector<int8_t> outputOut_host(outputOut_sz, 1);
ret = CreateAclTensor_New(outputOut_host, outputOutShape, &outputOutDeviceAddr, outputOutDtype, outputOutFormat, &outputOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (outputOutDtype == ACL_FLOAT8_E8M0) {
std::vector<int8_t> outputOut_host(outputOut_sz, 1);
ret = CreateAclTensor_New(outputOut_host, outputOutShape, &outputOutDeviceAddr, outputOutDtype, outputOutFormat, &outputOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (outputOutDtype == ACL_FLOAT4_E2M1) {
std::vector<int8_t> outputOut_host(outputOut_sz, 1);
ret = CreateAclTensor_New(outputOut_host, outputOutShape, &outputOutDeviceAddr, outputOutDtype, outputOutFormat, &outputOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else {
std::vector<float> outputOut_host(outputOut_sz, 1);
ret = CreateAclTensor_New(outputOut_host, outputOutShape, &outputOutDeviceAddr, outputOutDtype, outputOutFormat, &outputOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
}
}
} else {
outputOut = nullptr;
}
if (!nullIndicesOut) {
long long indicesOut_sz = GetShapeSize(indicesOutShape);
if (indicesOut_sz > 0 && indicesOut_sz <= 1073741824) {
if (indicesOutDtype == ACL_FLOAT) {
std::vector<float> indicesOut_host(indicesOut_sz, 1);
ret = CreateAclTensor_New(indicesOut_host, indicesOutShape, &indicesOutDeviceAddr, indicesOutDtype, indicesOutFormat, &indicesOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (indicesOutDtype == ACL_FLOAT16) {
std::vector<int16_t> indicesOut_host(indicesOut_sz, 1);
ret = CreateAclTensor_New(indicesOut_host, indicesOutShape, &indicesOutDeviceAddr, indicesOutDtype, indicesOutFormat, &indicesOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (indicesOutDtype == ACL_INT8) {
std::vector<int8_t> indicesOut_host(indicesOut_sz, 1);
ret = CreateAclTensor_New(indicesOut_host, indicesOutShape, &indicesOutDeviceAddr, indicesOutDtype, indicesOutFormat, &indicesOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (indicesOutDtype == ACL_INT32) {
std::vector<int32_t> indicesOut_host(indicesOut_sz, 1);
ret = CreateAclTensor_New(indicesOut_host, indicesOutShape, &indicesOutDeviceAddr, indicesOutDtype, indicesOutFormat, &indicesOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (indicesOutDtype == ACL_UINT8) {
std::vector<uint8_t> indicesOut_host(indicesOut_sz, 1);
ret = CreateAclTensor_New(indicesOut_host, indicesOutShape, &indicesOutDeviceAddr, indicesOutDtype, indicesOutFormat, &indicesOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (indicesOutDtype == ACL_INT16) {
std::vector<int16_t> indicesOut_host(indicesOut_sz, 1);
ret = CreateAclTensor_New(indicesOut_host, indicesOutShape, &indicesOutDeviceAddr, indicesOutDtype, indicesOutFormat, &indicesOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (indicesOutDtype == ACL_UINT16) {
std::vector<uint16_t> indicesOut_host(indicesOut_sz, 1);
ret = CreateAclTensor_New(indicesOut_host, indicesOutShape, &indicesOutDeviceAddr, indicesOutDtype, indicesOutFormat, &indicesOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (indicesOutDtype == ACL_UINT32) {
std::vector<uint32_t> indicesOut_host(indicesOut_sz, 1);
ret = CreateAclTensor_New(indicesOut_host, indicesOutShape, &indicesOutDeviceAddr, indicesOutDtype, indicesOutFormat, &indicesOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (indicesOutDtype == ACL_INT64) {
std::vector<int64_t> indicesOut_host(indicesOut_sz, 1);
ret = CreateAclTensor_New(indicesOut_host, indicesOutShape, &indicesOutDeviceAddr, indicesOutDtype, indicesOutFormat, &indicesOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (indicesOutDtype == ACL_UINT64) {
std::vector<uint64_t> indicesOut_host(indicesOut_sz, 1);
ret = CreateAclTensor_New(indicesOut_host, indicesOutShape, &indicesOutDeviceAddr, indicesOutDtype, indicesOutFormat, &indicesOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (indicesOutDtype == ACL_DOUBLE) {
std::vector<double> indicesOut_host(indicesOut_sz, 1);
ret = CreateAclTensor_New(indicesOut_host, indicesOutShape, &indicesOutDeviceAddr, indicesOutDtype, indicesOutFormat, &indicesOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (indicesOutDtype == ACL_BOOL) {
std::vector<int8_t> indicesOut_host(indicesOut_sz, 1);
ret = CreateAclTensor_New(indicesOut_host, indicesOutShape, &indicesOutDeviceAddr, indicesOutDtype, indicesOutFormat, &indicesOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (indicesOutDtype == ACL_COMPLEX64) {
std::vector<float> indicesOut_host((indicesOut_sz * 2), 1);
ret = CreateAclTensor_New(indicesOut_host, indicesOutShape, &indicesOutDeviceAddr, indicesOutDtype, indicesOutFormat, &indicesOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (indicesOutDtype == ACL_COMPLEX128) {
std::vector<double> indicesOut_host((indicesOut_sz * 2), 1);
ret = CreateAclTensor_New(indicesOut_host, indicesOutShape, &indicesOutDeviceAddr, indicesOutDtype, indicesOutFormat, &indicesOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (indicesOutDtype == ACL_BF16) {
std::vector<int16_t> indicesOut_host(indicesOut_sz, 1);
ret = CreateAclTensor_New(indicesOut_host, indicesOutShape, &indicesOutDeviceAddr, indicesOutDtype, indicesOutFormat, &indicesOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (indicesOutDtype == ACL_INT4) {
std::vector<int8_t> indicesOut_host(indicesOut_sz, 1);
ret = CreateAclTensor_New(indicesOut_host, indicesOutShape, &indicesOutDeviceAddr, indicesOutDtype, indicesOutFormat, &indicesOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (indicesOutDtype == ACL_UINT1) {
std::vector<int8_t> indicesOut_host(indicesOut_sz, 1);
ret = CreateAclTensor_New(indicesOut_host, indicesOutShape, &indicesOutDeviceAddr, indicesOutDtype, indicesOutFormat, &indicesOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (indicesOutDtype == ACL_COMPLEX32) {
std::vector<float> indicesOut_host((indicesOut_sz * 2), 1);
ret = CreateAclTensor_New(indicesOut_host, indicesOutShape, &indicesOutDeviceAddr, indicesOutDtype, indicesOutFormat, &indicesOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (indicesOutDtype == ACL_HIFLOAT8) {
std::vector<int8_t> indicesOut_host(indicesOut_sz, 1);
ret = CreateAclTensor_New(indicesOut_host, indicesOutShape, &indicesOutDeviceAddr, indicesOutDtype, indicesOutFormat, &indicesOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (indicesOutDtype == ACL_FLOAT8_E5M2) {
std::vector<int8_t> indicesOut_host(indicesOut_sz, 1);
ret = CreateAclTensor_New(indicesOut_host, indicesOutShape, &indicesOutDeviceAddr, indicesOutDtype, indicesOutFormat, &indicesOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (indicesOutDtype == ACL_FLOAT8_E4M3FN) {
std::vector<int8_t> indicesOut_host(indicesOut_sz, 1);
ret = CreateAclTensor_New(indicesOut_host, indicesOutShape, &indicesOutDeviceAddr, indicesOutDtype, indicesOutFormat, &indicesOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (indicesOutDtype == ACL_FLOAT8_E8M0) {
std::vector<int8_t> indicesOut_host(indicesOut_sz, 1);
ret = CreateAclTensor_New(indicesOut_host, indicesOutShape, &indicesOutDeviceAddr, indicesOutDtype, indicesOutFormat, &indicesOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else if (indicesOutDtype == ACL_FLOAT4_E2M1) {
std::vector<int8_t> indicesOut_host(indicesOut_sz, 1);
ret = CreateAclTensor_New(indicesOut_host, indicesOutShape, &indicesOutDeviceAddr, indicesOutDtype, indicesOutFormat, &indicesOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
} else {
std::vector<float> indicesOut_host(indicesOut_sz, 1);
ret = CreateAclTensor_New(indicesOut_host, indicesOutShape, &indicesOutDeviceAddr, indicesOutDtype, indicesOutFormat, &indicesOut);
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
}
}
} else {
indicesOut = nullptr;
}
printf("[FUZZ_LOG] plog_file: aclnnAdaptiveMaxPool3d_error_plog_case_%d.log\n", scenario);
printf("[FUZZ_PARAM] self=%s, selfShape=%s, outputSize=%s, outputOut=%s, outputOutShape=%s, indicesOut=%s, indicesOutShape=%s, selfFmt=%s, outputOutFmt=%s, indicesOutFmt=%s\n", GetDtypeName(selfDtype), ShapeToStr(selfShape).c_str(), IntArrayToStr(outputSizeVec).c_str(), GetDtypeName(outputOutDtype), ShapeToStr(outputOutShape).c_str(), GetDtypeName(indicesOutDtype), ShapeToStr(indicesOutShape).c_str(), FormatName(selfFormat), FormatName(outputOutFormat), FormatName(indicesOutFormat));
printf("[FUZZ_ERROR_POINT] case_%d: errorType=%s, errorTarget=%s, description=%s\n", scenario, errorTypeStr.c_str(), errorTargetStr.c_str(), scenarioDesc.c_str());
ret = aclnnAdaptiveMaxPool3dGetWorkspaceSize(self, outputSize, outputOut, indicesOut, &workspaceSize, &executor);
caseRet = (int)ret;
LOG_PRINT("aclnnAdaptiveMaxPool3dGetWorkspaceSize 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());
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 = aclnnAdaptiveMaxPool3d(workspaceAddr, workspaceSize, executor, stream);
if (ret != ACL_SUCCESS) { caseRet = (int)ret; LOG_PRINT("aclnnAdaptiveMaxPool3d execute failed : %d\n", ret); goto ERROR; }
caseRet = (int)ret;
LOG_PRINT("aclnnAdaptiveMaxPool3d 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 -rin 'aicore error' /root/ascend/log/debug/plog/ ";
printf("system return value %d\n", CheckResult(pid));
if (self != nullptr) { aclDestroyTensor(self); self = nullptr; }
if (outputSize != nullptr) { aclDestroyIntArray(outputSize); outputSize = nullptr; }
if (outputOut != nullptr) { aclDestroyTensor(outputOut); outputOut = nullptr; }
if (indicesOut != nullptr) { aclDestroyTensor(indicesOut); indicesOut = nullptr; }
if (selfDeviceAddr != nullptr) { aclrtFree(selfDeviceAddr); selfDeviceAddr = nullptr; }
if (outputOutDeviceAddr != nullptr) { aclrtFree(outputOutDeviceAddr); outputOutDeviceAddr = nullptr; }
if (indicesOutDeviceAddr != nullptr) { aclrtFree(indicesOutDeviceAddr); indicesOutDeviceAddr = nullptr; }
if (workspaceSize > 0) { aclrtFree(workspaceAddr); }
}
DT_FUZZ_END()
GenerateFinalSummary();
WriteDTLog("aclnnAdaptiveMaxPool3d", "aclnnAdaptiveMaxPool3d 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("aclnnAdaptiveMaxPool3d", "aclnnAdaptiveMaxPool3d op fuzz end\n");
aclrtDestroyStream(stream);
aclrtDestroyContext(context);
aclrtResetDevice(deviceId);
aclFinalize();
return 0;
}
extern "C" int aclnnAdaptiveMaxPool3d_error_fuzz(int argc, char *argv[]);
int aclnnAdaptiveMaxPool3d_error_fuzz(int argc, char *argv[])
{
int fuzz_num = MAXFUZZNUMBER;
if (argc < 2) {
cout << "[ERROR] input arg num must be bigger than 1 " << 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("aclnnAdaptiveMaxPool3d_Normal :%d \n", aclnnAdaptiveMaxPool3d_Normal(fuzz_num));
return 0;
}