#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 <ctime>
#include <sys/wait.h>
#include <dlfcn.h>
#include <cstdio>
#include <string>
#include <vector>
#include <iomanip>
#include <string.h>
#include <list>
#include <algorithm>
#include <stdarg.h>
#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_avgpool2d_backward.h"
using namespace std;
static const int CONSISTENT_MAX_RUN_TIMES = 64;
static int CONSISTENT_RUN_TIMES = 2;
static const char* ConsistentDtypeStr(aclDataType t) {
switch (t) {
case ACL_FLOAT: return "FLOAT"; case ACL_FLOAT16: return "FLOAT16";
case ACL_BF16: return "BFLOAT16"; case ACL_DOUBLE: return "DOUBLE";
case ACL_INT8: return "INT8"; case ACL_INT16: return "INT16";
case ACL_INT32: return "INT32"; case ACL_INT64: return "INT64";
case ACL_UINT8: return "UINT8"; case ACL_UINT16: return "UINT16";
case ACL_UINT32: return "UINT32"; case ACL_UINT64: return "UINT64";
case ACL_BOOL: return "BOOL"; case ACL_COMPLEX64: return "COMPLEX64";
case ACL_COMPLEX128: return "COMPLEX128";
default: return "UNKNOWN";
}
}
static const char* ConsistentFormatStr(aclFormat f) {
switch (f) {
case ACL_FORMAT_NCHW: return "NCHW"; case ACL_FORMAT_NHWC: return "NHWC";
case ACL_FORMAT_ND: return "ND"; case ACL_FORMAT_NC1HWC0: return "NC1HWC0";
case ACL_FORMAT_FRACTAL_Z: return "FRACTAL_Z"; case ACL_FORMAT_HWCN: return "HWCN";
case ACL_FORMAT_NDHWC: return "NDHWC"; case ACL_FORMAT_FRACTAL_NZ: return "FRACTAL_NZ";
case ACL_FORMAT_NCDHW: return "NCDHW"; case ACL_FORMAT_NC: return "NC";
case ACL_FORMAT_NCL: return "NCL";
default: return "OTHER";
}
}
static size_t ConsistentSizeOfDtype(aclDataType dataType) {
switch (dataType) {
case ACL_FLOAT: return 4; case ACL_FLOAT16: return 2;
case ACL_INT8: return 1; case ACL_INT32: return 4;
case ACL_UINT8: return 1; case ACL_INT16: return 2;
case ACL_UINT16: return 2; case ACL_UINT32: return 4;
case ACL_INT64: return 8; case ACL_UINT64: return 8;
case ACL_DOUBLE: return 8; case ACL_BOOL: return 1;
case ACL_BF16: return 2; case ACL_COMPLEX64: return 8;
case ACL_COMPLEX128: return 16;
case ACL_INT4: return 1;
case ACL_HIFLOAT8: return 1;
case ACL_FLOAT8_E5M2: return 1;
case ACL_FLOAT8_E4M3FN: return 1;
case ACL_FLOAT8_E8M0: return 1;
case ACL_FLOAT4_E2M1: return 1;
case ACL_FLOAT4_E1M2: return 1;
default: return 0;
}
}
static void ConsistentPrintShape(const std::vector<int64_t>& shape) {
printf("[");
for (size_t k = 0; k < shape.size(); k++) {
printf("%lld%s", (long long)shape[k], (k + 1 < shape.size()) ? "," : "");
}
printf("]");
}
static uint64_t ConsistentHashBuffer(const void* data, size_t len) {
const uint8_t* p = (const uint8_t*)data;
uint64_t hash = 1469598103934665603ULL;
for (size_t k = 0; k < len; k++) {
hash ^= (uint64_t)p[k];
hash *= 1099511628211ULL;
}
return hash;
}
static uint64_t ConsistentHashDeviceTensor(void* deviceAddr, size_t bytes) {
if (deviceAddr == nullptr || bytes == 0) return 0;
void* hostBuf = malloc(bytes);
if (hostBuf == nullptr) return 0;
if (aclrtMemcpy(hostBuf, bytes, deviceAddr, bytes, ACL_MEMCPY_DEVICE_TO_HOST) != ACL_SUCCESS) {
free(hostBuf);
return 0;
}
uint64_t h = ConsistentHashBuffer(hostBuf, bytes);
free(hostBuf);
return h;
}
static int kDtypeEnum[] = {0, 1, 27};
static int kDtypeNum = sizeof(kDtypeEnum) / sizeof(kDtypeEnum[0]);
int aclnnAvgPool2dBackward_consistent(int fuzz_num)
{
const long long kSingleInputSizeMax = 1073741824LL;
auto ret = Init(deviceId, &context, &stream);
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Init acl failed. ERROR: %d\n", ret); return ret);
ret = aclrtCtxSetSysParamOpt(aclSysParamOpt::ACL_OPT_DETERMINISTIC, 1);
printf("[FUZZ_DETERMINISTIC] api=aclnnAvgPool2dBackward, enable_deterministic=1, ret=%d\n", (int)ret);
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtCtxSetSysParamOpt failed. ERROR: %d\n", ret); return ret);
WriteDTLog("aclnnAvgPool2dBackward", "aclnnAvgPool2dBackward consistent op fuzz start \n");
aclrtSetOpExecuteTimeOut(1091);
DT_Set_TimeOut_Second(3000);
DT_FUZZ_START(0, fuzz_num, (char*)__func__, 0)
{
int i = 0;
void* gradOutputDeviceAddr = nullptr;
aclTensor* gradOutput = nullptr;
void* selfDeviceAddr = nullptr;
aclTensor* self = nullptr;
void* gradInputDeviceAddr = nullptr;
aclTensor* gradInput = nullptr;
aclIntArray* kernelSize = nullptr;
aclIntArray* stride = nullptr;
aclIntArray* padding = nullptr;
uint64_t workspaceSize = 0;
aclOpExecutor* executor;
void* workspaceAddr = nullptr;
char curTilingKey[64];
snprintf(curTilingKey, sizeof(curTilingKey), "N/A");
int cstRunCount = 0;
bool cstAllOk = true;
bool cstResultPrinted = false;
uint64_t cstGradOutputShapeSz = 0;
int cstGradOutputDtype = 0;
size_t cstGradOutputBytes = 0;
void* cstGradOutputSaveBuf = nullptr;
uint64_t cstGradOutputHashArr[CONSISTENT_MAX_RUN_TIMES];
memset(cstGradOutputHashArr, 0, sizeof(cstGradOutputHashArr));
uint64_t cstSelfShapeSz = 0;
int cstSelfDtype = 0;
size_t cstSelfBytes = 0;
void* cstSelfSaveBuf = nullptr;
uint64_t cstSelfHashArr[CONSISTENT_MAX_RUN_TIMES];
memset(cstSelfHashArr, 0, sizeof(cstSelfHashArr));
uint64_t cstGradInputShapeSz = 0;
int cstGradInputDtype = 0;
size_t cstGradInputBytes = 0;
void* cstGradInputSaveBuf = nullptr;
uint64_t cstGradInputHashArr[CONSISTENT_MAX_RUN_TIMES];
memset(cstGradInputHashArr, 0, sizeof(cstGradInputHashArr));
printf("[FUZZ_LOG] plog_file: aclnnAvgPool2dBackward_consistent_plog_case_%d\n", fuzzi);
LOG_PRINT("aclnnAvgPool2dBackward_consistent %d\n", fuzzi);
try
{
int sizeBucket = *(int *)DTSetGetNumberRange(&g_Element[i++], 1, 0, 1, "i");
long long totalSizeMin = 0, totalSizeMax = 0;
switch (sizeBucket) {
case 0: totalSizeMin = 1; totalSizeMax = 1000; break;
case 1: totalSizeMin = 1001; totalSizeMax = 67108864LL; break;
case 2: totalSizeMin = 1073741825LL; totalSizeMax = 2147483648LL; break;
case 3: totalSizeMin = 2147483649LL; totalSizeMax = 4294967296LL; break;
}
int N = *(int*)DTSetGetNumberRange(&g_Element[i++], 2, 1, 4, "i");
int C = *(int*)DTSetGetNumberRange(&g_Element[i++], 2, 1, 4, "i");
int H = *(int*)DTSetGetNumberRange(&g_Element[i++], 10, 4, 16, "i");
int W = *(int*)DTSetGetNumberRange(&g_Element[i++], 10, 4, 16, "i");
auto selfDtype = (aclDataType)*(int*)DT_SetGetNumberEnumV3(i++, aclDataType::ACL_FLOAT, kDtypeEnum, kDtypeNum);
if (N < 1) N = 1; if (N > 4) N = 4;
if (C < 1) C = 1; if (C > 4) C = 4;
if (H < 4) H = 4; if (H > 16) H = 16;
if (W < 4) W = 4; if (W > 16) W = 16;
int64_t oH = (int64_t)H - 1;
int64_t oW = (int64_t)W - 1;
if (oH < 1) oH = 1;
if (oW < 1) oW = 1;
std::vector<int64_t> gradOutputShape = {(int64_t)N, (int64_t)C, oH, oW};
std::vector<int64_t> selfShape = {(int64_t)N, (int64_t)C, (int64_t)H, (int64_t)W};
std::vector<int64_t> gradInputShape = selfShape;
int64_t ksArr[] = {2, 2};
kernelSize = aclCreateIntArray(ksArr, 2);
CHECK_RET(kernelSize != nullptr, LOG_PRINT("aclCreateIntArray kernelSize failed.\n"); goto ERROR);
int64_t strideArr[] = {1, 1};
stride = aclCreateIntArray(strideArr, 2);
CHECK_RET(stride != nullptr, LOG_PRINT("aclCreateIntArray stride failed.\n"); goto ERROR);
int64_t padArr[] = {0, 0};
padding = aclCreateIntArray(padArr, 2);
CHECK_RET(padding != nullptr, LOG_PRINT("aclCreateIntArray padding failed.\n"); goto ERROR);
bool ceilMode = false;
bool countIncludePad = true;
int64_t divisorOverride = 0;
int8_t cubeMathType = 0;
long long gradOutputSize = GetShapeSize(gradOutputShape);
long long selfSize = GetShapeSize(selfShape);
long long gradInputSize = GetShapeSize(gradInputShape);
if (gradOutputSize > kSingleInputSizeMax || selfSize > kSingleInputSizeMax || gradInputSize > kSingleInputSizeMax) { printf("shape_size too big\n"); goto ERROR; }
printf("selfDtype=%d, N=%d, C=%d, H=%d, W=%d, oH=%lld, oW=%lld\n", (int)selfDtype, N, C, H, W, (long long)oH, (long long)oW);
aclFormat fmt = aclFormat::ACL_FORMAT_NCHW;
if (selfDtype == aclDataType::ACL_FLOAT) {
std::vector<float> hostData(gradOutputSize, 1);
long long totalSize = gradOutputSize + selfSize + gradInputSize;
if (totalSize < totalSizeMin || totalSize > totalSizeMax) { goto ERROR; }
ret = CreateAclTensor_New(hostData, gradOutputShape, &gradOutputDeviceAddr, selfDtype, fmt, &gradOutput);
cstGradOutputShapeSz = (uint64_t)GetShapeSize(gradOutputShape);
cstGradOutputDtype = (int)(selfDtype);
} else if (selfDtype == aclDataType::ACL_FLOAT16) {
std::vector<int16_t> hostData(gradOutputSize, 1);
ret = CreateAclTensor_New(hostData, gradOutputShape, &gradOutputDeviceAddr, selfDtype, fmt, &gradOutput);
cstGradOutputShapeSz = (uint64_t)GetShapeSize(gradOutputShape);
cstGradOutputDtype = (int)(selfDtype);
} else if (selfDtype == aclDataType::ACL_BF16) {
std::vector<int16_t> hostData(gradOutputSize, 1);
ret = CreateAclTensor_New(hostData, gradOutputShape, &gradOutputDeviceAddr, selfDtype, fmt, &gradOutput);
cstGradOutputShapeSz = (uint64_t)GetShapeSize(gradOutputShape);
cstGradOutputDtype = (int)(selfDtype);
}
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
if (selfDtype == aclDataType::ACL_FLOAT) {
std::vector<float> hostData(selfSize, 1);
ret = CreateAclTensor_New(hostData, selfShape, &selfDeviceAddr, selfDtype, fmt, &self);
cstSelfShapeSz = (uint64_t)GetShapeSize(selfShape);
cstSelfDtype = (int)(selfDtype);
} else if (selfDtype == aclDataType::ACL_FLOAT16) {
std::vector<int16_t> hostData(selfSize, 1);
ret = CreateAclTensor_New(hostData, selfShape, &selfDeviceAddr, selfDtype, fmt, &self);
cstSelfShapeSz = (uint64_t)GetShapeSize(selfShape);
cstSelfDtype = (int)(selfDtype);
} else if (selfDtype == aclDataType::ACL_BF16) {
std::vector<int16_t> hostData(selfSize, 1);
ret = CreateAclTensor_New(hostData, selfShape, &selfDeviceAddr, selfDtype, fmt, &self);
cstSelfShapeSz = (uint64_t)GetShapeSize(selfShape);
cstSelfDtype = (int)(selfDtype);
}
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
if (selfDtype == aclDataType::ACL_FLOAT) {
std::vector<float> hostData(gradInputSize, 0);
ret = CreateAclTensor_New(hostData, gradInputShape, &gradInputDeviceAddr, selfDtype, fmt, &gradInput);
cstGradInputShapeSz = (uint64_t)GetShapeSize(gradInputShape);
cstGradInputDtype = (int)(selfDtype);
} else if (selfDtype == aclDataType::ACL_FLOAT16) {
std::vector<int16_t> hostData(gradInputSize, 0);
ret = CreateAclTensor_New(hostData, gradInputShape, &gradInputDeviceAddr, selfDtype, fmt, &gradInput);
cstGradInputShapeSz = (uint64_t)GetShapeSize(gradInputShape);
cstGradInputDtype = (int)(selfDtype);
} else if (selfDtype == aclDataType::ACL_BF16) {
std::vector<int16_t> hostData(gradInputSize, 0);
ret = CreateAclTensor_New(hostData, gradInputShape, &gradInputDeviceAddr, selfDtype, fmt, &gradInput);
cstGradInputShapeSz = (uint64_t)GetShapeSize(gradInputShape);
cstGradInputDtype = (int)(selfDtype);
}
CHECK_RET(ret == ACL_SUCCESS, goto ERROR);
cstGradOutputBytes = (gradOutputDeviceAddr != nullptr) ? (size_t)cstGradOutputShapeSz * (size_t)ConsistentSizeOfDtype((aclDataType)cstGradOutputDtype) : 0;
printf("[FUZZ_CONSISTENT_BYTES] case_%d: tensor=gradOutput, dtype=%d(%s), shapeSize=%llu, cstBytes=%zu, ConsistentSizeOfDtype=%zu\n", fuzzi, (int)cstGradOutputDtype, ConsistentDtypeStr((aclDataType)cstGradOutputDtype), (unsigned long long)cstGradOutputShapeSz, cstGradOutputBytes, ConsistentSizeOfDtype((aclDataType)cstGradOutputDtype));
if (cstGradOutputBytes == 0 && gradOutputDeviceAddr != nullptr) {
printf("[FUZZ_CONSISTENT_BYTES] case_%d: WARN tensor=gradOutput addr!=nullptr but cstBytes=0, dtype may be uncovered by ConsistentSizeOfDtype\n", fuzzi);
}
cstGradOutputSaveBuf = (cstGradOutputBytes > 0) ? malloc(cstGradOutputBytes) : nullptr;
if (cstGradOutputSaveBuf != nullptr && gradOutputDeviceAddr != nullptr) {
aclrtMemcpy(cstGradOutputSaveBuf, cstGradOutputBytes, gradOutputDeviceAddr, cstGradOutputBytes, ACL_MEMCPY_DEVICE_TO_HOST);
}
cstSelfBytes = (selfDeviceAddr != nullptr) ? (size_t)cstSelfShapeSz * (size_t)ConsistentSizeOfDtype((aclDataType)cstSelfDtype) : 0;
printf("[FUZZ_CONSISTENT_BYTES] case_%d: tensor=self, dtype=%d(%s), shapeSize=%llu, cstBytes=%zu, ConsistentSizeOfDtype=%zu\n", fuzzi, (int)cstSelfDtype, ConsistentDtypeStr((aclDataType)cstSelfDtype), (unsigned long long)cstSelfShapeSz, cstSelfBytes, ConsistentSizeOfDtype((aclDataType)cstSelfDtype));
if (cstSelfBytes == 0 && selfDeviceAddr != nullptr) {
printf("[FUZZ_CONSISTENT_BYTES] case_%d: WARN tensor=self addr!=nullptr but cstBytes=0, dtype may be uncovered by ConsistentSizeOfDtype\n", fuzzi);
}
cstSelfSaveBuf = (cstSelfBytes > 0) ? malloc(cstSelfBytes) : nullptr;
if (cstSelfSaveBuf != nullptr && selfDeviceAddr != nullptr) {
aclrtMemcpy(cstSelfSaveBuf, cstSelfBytes, selfDeviceAddr, cstSelfBytes, ACL_MEMCPY_DEVICE_TO_HOST);
}
cstGradInputBytes = (gradInputDeviceAddr != nullptr) ? (size_t)cstGradInputShapeSz * (size_t)ConsistentSizeOfDtype((aclDataType)cstGradInputDtype) : 0;
printf("[FUZZ_CONSISTENT_BYTES] case_%d: tensor=gradInput, dtype=%d(%s), shapeSize=%llu, cstBytes=%zu, ConsistentSizeOfDtype=%zu\n", fuzzi, (int)cstGradInputDtype, ConsistentDtypeStr((aclDataType)cstGradInputDtype), (unsigned long long)cstGradInputShapeSz, cstGradInputBytes, ConsistentSizeOfDtype((aclDataType)cstGradInputDtype));
if (cstGradInputBytes == 0 && gradInputDeviceAddr != nullptr) {
printf("[FUZZ_CONSISTENT_BYTES] case_%d: WARN tensor=gradInput addr!=nullptr but cstBytes=0, dtype may be uncovered by ConsistentSizeOfDtype\n", fuzzi);
}
cstGradInputSaveBuf = (cstGradInputBytes > 0) ? malloc(cstGradInputBytes) : nullptr;
if (cstGradInputSaveBuf != nullptr && gradInputDeviceAddr != nullptr) {
aclrtMemcpy(cstGradInputSaveBuf, cstGradInputBytes, gradInputDeviceAddr, cstGradInputBytes, ACL_MEMCPY_DEVICE_TO_HOST);
}
cstRunCount = 0;
cstAllOk = true;
for (int cstRun = 0; cstRun < CONSISTENT_RUN_TIMES; cstRun++) {
if (cstGradOutputSaveBuf != nullptr && gradOutputDeviceAddr != nullptr) {
aclrtMemcpy(gradOutputDeviceAddr, cstGradOutputBytes, cstGradOutputSaveBuf, cstGradOutputBytes, ACL_MEMCPY_HOST_TO_DEVICE);
}
if (cstSelfSaveBuf != nullptr && selfDeviceAddr != nullptr) {
aclrtMemcpy(selfDeviceAddr, cstSelfBytes, cstSelfSaveBuf, cstSelfBytes, ACL_MEMCPY_HOST_TO_DEVICE);
}
if (cstGradInputSaveBuf != nullptr && gradInputDeviceAddr != nullptr) {
aclrtMemcpy(gradInputDeviceAddr, cstGradInputBytes, cstGradInputSaveBuf, cstGradInputBytes, ACL_MEMCPY_HOST_TO_DEVICE);
}
ret = aclnnAvgPool2dBackwardGetWorkspaceSize(gradOutput, self, kernelSize, stride, padding, ceilMode, countIncludePad, divisorOverride, cubeMathType, gradInput, &workspaceSize, &executor);
if (ret != ACL_SUCCESS) {
printf("aclnnAvgPool2dBackward execute failed :%d\n", (int)ret);
printf("[FUZZ_CONSISTENT] case_%d: faild, type=execute_error, stage=GetWorkspaceSize, run=%d/%d, ret=%d\n", fuzzi, cstRun + 1, CONSISTENT_RUN_TIMES, (int)ret);
cstAllOk = false;
break;
}
if (workspaceSize > 0) {
if (workspaceAddr != nullptr) { aclrtFree(workspaceAddr); workspaceAddr = nullptr; }
ret = aclrtMalloc(&workspaceAddr, workspaceSize, ACL_MEM_MALLOC_HUGE_FIRST);
if (ret != ACL_SUCCESS) {
printf("[FUZZ_CONSISTENT] case_%d: faild, type=execute_error, stage=workspace_malloc, run=%d/%d, ret=%d\n", fuzzi, cstRun + 1, CONSISTENT_RUN_TIMES, (int)ret);
cstAllOk = false;
break;
}
}
ret = aclnnAvgPool2dBackward(workspaceAddr, workspaceSize, executor, stream);
if (ret != ACL_SUCCESS) {
printf("aclnnAvgPool2dBackward execute failed :%d\n", (int)ret);
printf("[FUZZ_CONSISTENT] case_%d: faild, type=execute_error, stage=execute, run=%d/%d, ret=%d\n", fuzzi, cstRun + 1, CONSISTENT_RUN_TIMES, (int)ret);
cstAllOk = false;
break;
}
ret = aclrtSynchronizeStream(stream);
if (ret != ACL_SUCCESS) {
printf("[FUZZ_CONSISTENT] case_%d: faild, type=execute_error, stage=sync, run=%d/%d, ret=%d\n", fuzzi, cstRun + 1, CONSISTENT_RUN_TIMES, (int)ret);
cstAllOk = false;
break;
}
if (gradOutputDeviceAddr != nullptr && cstGradOutputBytes > 0) {
cstGradOutputHashArr[cstRun] = ConsistentHashDeviceTensor(gradOutputDeviceAddr, cstGradOutputBytes);
}
if (selfDeviceAddr != nullptr && cstSelfBytes > 0) {
cstSelfHashArr[cstRun] = ConsistentHashDeviceTensor(selfDeviceAddr, cstSelfBytes);
}
if (gradInputDeviceAddr != nullptr && cstGradInputBytes > 0) {
cstGradInputHashArr[cstRun] = ConsistentHashDeviceTensor(gradInputDeviceAddr, cstGradInputBytes);
}
cstRunCount++;
printf("aclnnAvgPool2dBackward execute success :%d\n", (int)ret);
}
if (cstAllOk && cstRunCount == CONSISTENT_RUN_TIMES) {
bool cstGradOutputSame = true;
for (int cstR = 1; cstR < CONSISTENT_RUN_TIMES; cstR++) {
if (cstGradOutputHashArr[cstR] != cstGradOutputHashArr[0]) { cstGradOutputSame = false; break; }
}
bool cstSelfSame = true;
for (int cstR = 1; cstR < CONSISTENT_RUN_TIMES; cstR++) {
if (cstSelfHashArr[cstR] != cstSelfHashArr[0]) { cstSelfSame = false; break; }
}
bool cstGradInputSame = true;
for (int cstR = 1; cstR < CONSISTENT_RUN_TIMES; cstR++) {
if (cstGradInputHashArr[cstR] != cstGradInputHashArr[0]) { cstGradInputSame = false; break; }
}
bool cstAllSame = cstGradOutputSame && cstSelfSame && cstGradInputSame;
if (cstAllSame) {
printf("[FUZZ_CONSISTENT] case_%d: success, type=consistent, runs=%d, hash_consistent=all\n", fuzzi, CONSISTENT_RUN_TIMES);
printf("[FUZZ_RESULT] case_%d: success, ret=%d\n", fuzzi, (int)ret);
cstResultPrinted = true;
} else {
printf("[FUZZ_CONSISTENT] case_%d: faild, type=hash_mismatch, runs=%d, inconsistent=", fuzzi, CONSISTENT_RUN_TIMES);
if (!cstGradOutputSame) printf("gradOutput ");
if (!cstSelfSame) printf("self ");
if (!cstGradInputSame) printf("gradInput ");
printf("\n");
printf("[FUZZ_CONSISTENT_DETAIL] case_%d: gradOutput hash:", fuzzi);
for (int cstR = 0; cstR < CONSISTENT_RUN_TIMES; cstR++) printf(" run%d=%llu", cstR, (unsigned long long)cstGradOutputHashArr[cstR]);
printf("\n");
printf("[FUZZ_CONSISTENT_DETAIL] case_%d: self hash:", fuzzi);
for (int cstR = 0; cstR < CONSISTENT_RUN_TIMES; cstR++) printf(" run%d=%llu", cstR, (unsigned long long)cstSelfHashArr[cstR]);
printf("\n");
printf("[FUZZ_CONSISTENT_DETAIL] case_%d: gradInput hash:", fuzzi);
for (int cstR = 0; cstR < CONSISTENT_RUN_TIMES; cstR++) printf(" run%d=%llu", cstR, (unsigned long long)cstGradInputHashArr[cstR]);
printf("\n");
printf("[FUZZ_PARAM] ");
printf("gradOutput: dtype=%s, format=%s, ", ConsistentDtypeStr((aclDataType)cstGradOutputDtype), ConsistentFormatStr(fmt)); printf("shapeSize=%llu", (unsigned long long)cstGradOutputShapeSz); printf("; ");
printf("self: dtype=%s, format=%s, ", ConsistentDtypeStr((aclDataType)cstSelfDtype), ConsistentFormatStr(fmt)); printf("shapeSize=%llu", (unsigned long long)cstSelfShapeSz); printf("; ");
printf("gradInput: dtype=%s, format=%s, ", ConsistentDtypeStr((aclDataType)cstGradInputDtype), ConsistentFormatStr(fmt)); printf("shapeSize=%llu", (unsigned long long)cstGradInputShapeSz); printf("; ");
printf("kernelSize: len=%zu; ", (size_t)((size_t)2));
printf("stride: len=%zu; ", (size_t)((size_t)2));
printf("padding: len=%zu; ", (size_t)((size_t)2));
printf("ceilMode=%d; ", (int)((ceilMode) ? 1 : 0));
printf("countIncludePad=%d; ", (int)((countIncludePad) ? 1 : 0));
printf("divisorOverride=%lld; ", (long long)divisorOverride);
printf("cubeMathType=%d; ", (int)cubeMathType);
printf("tiling_key=%s\n", curTilingKey);
printf("[FUZZ_RESULT] case_%d: faild, ret=%d\n", fuzzi, -2);
cstResultPrinted = true;
}
} else if (!cstAllOk) {
printf("[FUZZ_PARAM] ");
printf("gradOutput: dtype=%s, format=%s, ", ConsistentDtypeStr((aclDataType)cstGradOutputDtype), ConsistentFormatStr(fmt)); printf("shapeSize=%llu", (unsigned long long)cstGradOutputShapeSz); printf("; ");
printf("self: dtype=%s, format=%s, ", ConsistentDtypeStr((aclDataType)cstSelfDtype), ConsistentFormatStr(fmt)); printf("shapeSize=%llu", (unsigned long long)cstSelfShapeSz); printf("; ");
printf("gradInput: dtype=%s, format=%s, ", ConsistentDtypeStr((aclDataType)cstGradInputDtype), ConsistentFormatStr(fmt)); printf("shapeSize=%llu", (unsigned long long)cstGradInputShapeSz); printf("; ");
printf("kernelSize: len=%zu; ", (size_t)((size_t)2));
printf("stride: len=%zu; ", (size_t)((size_t)2));
printf("padding: len=%zu; ", (size_t)((size_t)2));
printf("ceilMode=%d; ", (int)((ceilMode) ? 1 : 0));
printf("countIncludePad=%d; ", (int)((countIncludePad) ? 1 : 0));
printf("divisorOverride=%lld; ", (long long)divisorOverride);
printf("cubeMathType=%d; ", (int)cubeMathType);
printf("tiling_key=%s\n", curTilingKey);
printf("[FUZZ_RESULT] case_%d: faild, ret=%d\n", fuzzi, (int)ret);
cstResultPrinted = true;
}
}
catch (std::exception& e)
{
printf("catch exception %s\n", e.what());
printf("[FUZZ_CONSISTENT] case_%d: faild, type=exception, ret=%d\n", fuzzi, (int)ret);
printf("[FUZZ_RESULT] case_%d: faild, ret=%d\n", fuzzi, (int)ret);
cstResultPrinted = true;
}
ERROR:
printf("end \n");
CheckAndLog(ret);
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 (kernelSize) { aclDestroyIntArray(kernelSize); }
if (stride) { aclDestroyIntArray(stride); }
if (padding) { aclDestroyIntArray(padding); }
if (cstGradOutputSaveBuf != nullptr) { free(cstGradOutputSaveBuf); cstGradOutputSaveBuf = nullptr; }
if (cstSelfSaveBuf != nullptr) { free(cstSelfSaveBuf); cstSelfSaveBuf = nullptr; }
if (cstGradInputSaveBuf != nullptr) { free(cstGradInputSaveBuf); cstGradInputSaveBuf = nullptr; }
aclDestroyTensor(gradOutput);
aclDestroyTensor(self);
aclDestroyTensor(gradInput);
aclrtFree(gradOutputDeviceAddr);
aclrtFree(selfDeviceAddr);
aclrtFree(gradInputDeviceAddr);
if (workspaceSize > 0 && workspaceAddr) { aclrtFree(workspaceAddr); }
}
DT_FUZZ_END()
WriteDTLog("aclnnAvgPool2dBackward", "aclnnAvgPool2dBackward consistent 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("aclnnAvgPool2dBackward", "aclnnAvgPool2dBackward consistent op fuzz end \n");
aclrtDestroyStream(stream);
aclrtDestroyContext(context);
aclrtResetDevice(deviceId);
aclFinalize();
return 0;
}
extern "C" int aclnnAvgPool2dBackward_consistent_fuzz(int argc, char *argv[]);
int aclnnAvgPool2dBackward_consistent_fuzz(int argc, char *argv[])
{
const char* cstRunEnv = getenv("CONSISTENT_RUN_TIMES");
if (cstRunEnv != nullptr) {
int cstRunV = atoi(cstRunEnv);
if (cstRunV > 0 && cstRunV <= CONSISTENT_MAX_RUN_TIMES) { CONSISTENT_RUN_TIMES = cstRunV; }
}
printf("[FUZZ_CONSISTENT_RUNTIMES] run_times=%d\n", CONSISTENT_RUN_TIMES);
int fuzz_num = MAXFUZZNUMBER;
if (argc < 1) {
cout << "[ERROR] input arg num must be bigger than 1 \n" << endl;
return -1;
}
else if (argc > 1) {
fuzz_num = atoi(argv[2]);
}
if (argc == 4) { deviceId = atoi(argv[3]); }
printf("fuzz_num %d \n", fuzz_num);
printf("aclnnAvgPool2dBackward_consistent :%d \n", aclnnAvgPool2dBackward_consistent(fuzz_num));
return 0;
}