#include "acl/acl.h"
#include "acl/acl_base.h"
#include "acl/acl_rt.h"
#include "aclnn/aclnn_base.h"
#include "sec_common.h"
#include "utils.h"
#include <algorithm>
#include <cstdio>
#include <ctime>
#include <dirent.h>
#include <dlfcn.h>
#include <getopt.h>
#include <iomanip>
#include <iostream>
#include <list>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
#include <vector>
#include "../fuzzlib/secodeFuzz.h"
#include "aclnnop/aclnn_addr.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;
}
int aclnnAddr_consistent(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);
printf("[FUZZ_DETERMINISTIC] api=aclnnAddr, enable_deterministic=0, reason=md文档标注:aclnnAddr&aclnnInplaceAddr默认确定性实现。\n");
WriteDTLog("aclnnAddr", "aclnnAddr op fuzz alpha \n");
printf("log path %s\n", seedPath);
int aiDtypeAll[] = {0, 1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 16, 17, 27, 29, 30, 33};
int aiDtypeAllNum = sizeof(aiDtypeAll) / sizeof(aiDtypeAll[0]);
int aiDtypeNormal[] = {0, 1, 2, 3, 4, 6, 9, 11, 12, 27};
int aiDtypeNum = sizeof(aiDtypeNormal) / sizeof(aiDtypeNormal[0]);
aclrtSetOpExecuteTimeOut(1091);
DT_Set_TimeOut_Second(3000);
DT_FUZZ_START(0, fuzz_num, seedPath, 0) {
int i = 0;
void *selfDeviceAddr = nullptr;
void *vec1DeviceAddr = nullptr;
void *vec2DeviceAddr = nullptr;
void *outDeviceAddr = nullptr;
aclTensor *self = nullptr;
aclTensor *vec1 = nullptr;
aclTensor *vec2 = nullptr;
aclTensor *out = nullptr;
aclScalar* beta = nullptr;
aclScalar* alpha = 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 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 cstVec1ShapeSz = 0;
int cstVec1Dtype = 0;
size_t cstVec1Bytes = 0;
void* cstVec1SaveBuf = nullptr;
uint64_t cstVec1HashArr[CONSISTENT_MAX_RUN_TIMES];
memset(cstVec1HashArr, 0, sizeof(cstVec1HashArr));
uint64_t cstVec2ShapeSz = 0;
int cstVec2Dtype = 0;
size_t cstVec2Bytes = 0;
void* cstVec2SaveBuf = nullptr;
uint64_t cstVec2HashArr[CONSISTENT_MAX_RUN_TIMES];
memset(cstVec2HashArr, 0, sizeof(cstVec2HashArr));
uint64_t cstOutShapeSz = 0;
int cstOutDtype = 0;
size_t cstOutBytes = 0;
void* cstOutSaveBuf = nullptr;
uint64_t cstOutHashArr[CONSISTENT_MAX_RUN_TIMES];
memset(cstOutHashArr, 0, sizeof(cstOutHashArr));
double cstBetaVal = 0;
double cstAlphaVal = 0;
printf("[FUZZ_LOG] plog_file: aclnnAddr_consistent_plog_case_%d\n", fuzzi);
LOG_PRINT("aclnnAddr_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 shape11 = *(int *)DTSetGetNumberRange(&g_Element[i++], 3, 1, MAX_SHAPE_SIZE, "i");
int shape12 = *(int *)DTSetGetNumberRange(&g_Element[i++], 2, 1, MAX_SHAPE_SIZE, "i");
int shape21 = *(int *)DTSetGetNumberRange(&g_Element[i++], 3, 1, MAX_SHAPE_SIZE, "i");
int shape31 = *(int *)DTSetGetNumberRange(&g_Element[i++], 2, 1, MAX_SHAPE_SIZE, "i");
int shape41 = *(int *)DTSetGetNumberRange(&g_Element[i++], 3, 1, MAX_SHAPE_SIZE, "i");
int shape42 = *(int *)DTSetGetNumberRange(&g_Element[i++], 2, 1, MAX_SHAPE_SIZE, "i");
auto selfDtype = (aclDataType) * (int *)DT_SetGetNumberEnumV3(i++, aclDataType::ACL_FLOAT, aiDtypeNormal, aiDtypeNum);
auto vec1Dtype = (aclDataType) * (int *)DT_SetGetNumberEnumV3(i++, aclDataType::ACL_FLOAT, aiDtypeNormal, aiDtypeNum);
auto vec2Dtype = (aclDataType) * (int *)DT_SetGetNumberEnumV3(i++, aclDataType::ACL_FLOAT, aiDtypeNormal, aiDtypeNum);
auto outDtype = (aclDataType) * (int *)DT_SetGetNumberEnumV3(i++, aclDataType::ACL_FLOAT, aiDtypeNormal, aiDtypeNum);
auto betaDtype = (aclDataType) * (int *)DT_SetGetNumberEnumV3(i++, aclDataType::ACL_FLOAT, aiDtypeNormal, aiDtypeNum);
auto alphaDtype = betaDtype;
if (alphaDtype == aclDataType::ACL_BOOL){
selfDtype = alphaDtype;
vec1Dtype = alphaDtype;
vec2Dtype = alphaDtype;
}
if (betaDtype == aclDataType::ACL_FLOAT) {
float betaValue = *(float *)DTSetGetNumberRangeFloat(&g_Element[i++], 1.17, -100.001, MAX_SHAPE_SIZE,"i");
float alphaValue = *(float *)DTSetGetNumberRangeFloat(&g_Element[i++], 1.31, -100.001, MAX_SHAPE_SIZE,"i");
printf("alphaValue %f, betaValue %f.\n", alphaValue, betaValue);
beta = aclCreateScalar(&betaValue, betaDtype);
cstBetaVal = (double)(betaValue);
CHECK_RET(beta != nullptr, LOG_PRINT("Create Scalar failed. ERROR: 161001\n"); goto ERROR);
alpha = aclCreateScalar(&alphaValue, alphaDtype);
cstAlphaVal = (double)(alphaValue);
CHECK_RET(alpha != nullptr, LOG_PRINT("Create Scalar failed. ERROR: 161001\n"); goto ERROR);
} else if (betaDtype == aclDataType::ACL_FLOAT16) {
} else if (betaDtype == aclDataType::ACL_INT8) {
int8_t betaValue = *(int8_t *)DTSetGetNumberRange(&g_Element[i++], 1, -100, MAX_SHAPE_SIZE,"i");
int8_t alphaValue = *(int8_t *)DTSetGetNumberRange(&g_Element[i++], 1, -100, MAX_SHAPE_SIZE,"i");
printf("alphaValue %d, betaValue %d.\n", alphaValue, betaValue);
beta = aclCreateScalar(&betaValue, betaDtype);
cstBetaVal = (double)(betaValue);
CHECK_RET(beta != nullptr, LOG_PRINT("Create Scalar failed. ERROR: 161001\n"); goto ERROR);
alpha = aclCreateScalar(&alphaValue, alphaDtype);
cstAlphaVal = (double)(alphaValue);
CHECK_RET(alpha != nullptr, LOG_PRINT("Create Scalar failed. ERROR: 161001\n"); goto ERROR);
} else if (betaDtype == aclDataType::ACL_INT32) {
int32_t betaValue = *(int32_t *)DTSetGetNumberRange(&g_Element[i++], 1, -100, MAX_SHAPE_SIZE,"i");
int32_t alphaValue = *(int32_t *)DTSetGetNumberRange(&g_Element[i++], 1, -100, MAX_SHAPE_SIZE,"i");
printf("alphaValue %d, betaValue %d.\n", alphaValue, betaValue);
beta = aclCreateScalar(&betaValue, betaDtype);
cstBetaVal = (double)(betaValue);
CHECK_RET(beta != nullptr, LOG_PRINT("Create Scalar failed. ERROR: 161001\n"); goto ERROR);
alpha = aclCreateScalar(&alphaValue, alphaDtype);
cstAlphaVal = (double)(alphaValue);
} else if (betaDtype == aclDataType::ACL_UINT8) {
uint8_t betaValue = *(uint8_t *)DTSetGetNumberRange(&g_Element[i++], 1, 1, MAX_SHAPE_SIZE,"i");
uint8_t alphaValue = *(uint8_t *)DTSetGetNumberRange(&g_Element[i++], 1, 0, MAX_SHAPE_SIZE,"i");
printf("alphaValue %d, betaValue %d.\n", alphaValue, betaValue);
beta = aclCreateScalar(&betaValue, betaDtype);
cstBetaVal = (double)(betaValue);
CHECK_RET(beta != nullptr, LOG_PRINT("Create Scalar failed. ERROR: 161001\n"); goto ERROR);
alpha = aclCreateScalar(&alphaValue, alphaDtype);
cstAlphaVal = (double)(alphaValue);
CHECK_RET(alpha != nullptr, LOG_PRINT("Create Scalar failed. ERROR: 161001\n"); goto ERROR);
} else if (betaDtype == aclDataType::ACL_INT16) {
int16_t betaValue = *(int16_t *)DTSetGetNumberRange(&g_Element[i++], 1, -100, MAX_SHAPE_SIZE,"i");
int16_t alphaValue = *(int16_t *)DTSetGetNumberRange(&g_Element[i++], 1, -100, MAX_SHAPE_SIZE,"i");
printf("alphaValue %d, betaValue %d.\n", alphaValue, betaValue);
beta = aclCreateScalar(&betaValue, betaDtype);
cstBetaVal = (double)(betaValue);
CHECK_RET(beta != nullptr, LOG_PRINT("Create Scalar failed. ERROR: 161001\n"); goto ERROR);
alpha = aclCreateScalar(&alphaValue, alphaDtype);
cstAlphaVal = (double)(alphaValue);
CHECK_RET(alpha != nullptr, LOG_PRINT("Create Scalar failed. ERROR: 161001\n"); goto ERROR);
} else if (betaDtype == aclDataType::ACL_INT64) {
int64_t betaValue = *(int64_t *)DTSetGetNumberRangeS64(&g_Element[i++], 1, -100, MAX_SHAPE_SIZE,"i");
int64_t alphaValue = *(int64_t *)DTSetGetNumberRangeS64(&g_Element[i++], 1, -100, MAX_SHAPE_SIZE,"i");
printf("alphaValue %lld, betaValue %lld.\n", alphaValue, betaValue);
beta = aclCreateScalar(&betaValue, betaDtype);
cstBetaVal = (double)(betaValue);
CHECK_RET(beta != nullptr, LOG_PRINT("Create Scalar failed. ERROR: 161001\n"); goto ERROR);
alpha = aclCreateScalar(&alphaValue, alphaDtype);
cstAlphaVal = (double)(alphaValue);
CHECK_RET(alpha != nullptr, LOG_PRINT("Create Scalar failed. ERROR: 161001\n"); goto ERROR);
} else if (betaDtype == aclDataType::ACL_DOUBLE) {
double betaValue = *(double *)DTSetGetNumberRangeDouble(&g_Element[i++], 1.17, -100.001, MAX_SHAPE_SIZE,"i");
double alphaValue = *(double *)DTSetGetNumberRangeDouble(&g_Element[i++], 1.31, -100.001, MAX_SHAPE_SIZE,"i");
printf("alphaValue %f, betaValue %f.\n", alphaValue, betaValue);
beta = aclCreateScalar(&betaValue, betaDtype);
cstBetaVal = (double)(betaValue);
CHECK_RET(beta != nullptr, LOG_PRINT("Create Scalar failed. ERROR: 161001\n"); goto ERROR);
alpha = aclCreateScalar(&alphaValue, alphaDtype);
cstAlphaVal = (double)(alphaValue);
CHECK_RET(alpha != nullptr, LOG_PRINT("Create Scalar failed. ERROR: 161001\n"); goto ERROR);
} else if (betaDtype == aclDataType::ACL_BOOL) {
int8_t betaValue = *(int8_t *)DTSetGetNumberRange(&g_Element[i++], 1, -100, MAX_SHAPE_SIZE,"i");
int8_t alphaValue = *(int8_t *)DTSetGetNumberRange(&g_Element[i++], 1, -100, MAX_SHAPE_SIZE,"i");
printf("alphaValue %d, betaValue %d.\n", alphaValue, betaValue);
beta = aclCreateScalar(&betaValue, betaDtype);
cstBetaVal = (double)(betaValue);
CHECK_RET(beta != nullptr, LOG_PRINT("Create Scalar failed. ERROR: 161001\n"); goto ERROR);
alpha = aclCreateScalar(&alphaValue, alphaDtype);
cstAlphaVal = (double)(alphaValue);
CHECK_RET(alpha != nullptr, LOG_PRINT("Create Scalar failed. ERROR: 161001\n"); goto ERROR);
} else if (betaDtype == aclDataType::ACL_BF16) {
}else {
printf("betaDtype dtype=%d not support\n", betaDtype);
double betaValue = *(double *)DTSetGetNumberRangeDouble(&g_Element[i++], 1.17, -100.001, MAX_SHAPE_SIZE,"i");
double alphaValue = *(double *)DTSetGetNumberRangeDouble(&g_Element[i++], 1.31, -100.001, MAX_SHAPE_SIZE,"i");
printf("alphaValue %lf, betaValue %lf.\n", alphaValue, betaValue);
beta = aclCreateScalar(&betaValue, betaDtype);
cstBetaVal = (double)(betaValue);
CHECK_RET(beta != nullptr, LOG_PRINT("Create Scalar failed. ERROR: 161001\n"); goto ERROR);
alpha = aclCreateScalar(&alphaValue, alphaDtype);
cstAlphaVal = (double)(alphaValue);
CHECK_RET(alpha != nullptr, LOG_PRINT("Create Scalar failed. ERROR: 161001\n"); goto ERROR);
}
LOG_PRINT("Cnt:%d, param: selfDtype %d, alphaDtype %d, betaDtype %d\n", fuzzi, selfDtype, alphaDtype, betaDtype);
std::vector<int64_t> selfShape = {shape11, shape12};
printf("selfShape:{%d,%d}\n", shape11, shape12);
long long shape_size1 = GetShapeSize(selfShape);
if (shape_size1 > SHAPE_SIZE_CTL) {
goto ERROR;
}
printf("self shape size %lld\n", shape_size1);
if (selfDtype == aclDataType::ACL_FLOAT) {
std::vector<float> selfHostData(shape_size1, 0);
long long totalSize = shape_size1;
if (totalSize < totalSizeMin || totalSize > totalSizeMax) { goto ERROR; }
ret = CreateAclTensor_New(selfHostData, selfShape, &selfDeviceAddr, selfDtype, aclFormat::ACL_FORMAT_ND, &self);
cstSelfShapeSz = (uint64_t)GetShapeSize(selfShape);
cstSelfDtype = (int)(selfDtype);
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Create Tensor failed. ERROR: %d\n", ret); goto ERROR);
} else if (selfDtype == aclDataType::ACL_FLOAT16) {
std::vector<int16_t> selfHostData(shape_size1, 0);
ret = CreateAclTensor_New(selfHostData, selfShape, &selfDeviceAddr, selfDtype, aclFormat::ACL_FORMAT_ND, &self);
cstSelfShapeSz = (uint64_t)GetShapeSize(selfShape);
cstSelfDtype = (int)(selfDtype);
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Create Tensor failed. ERROR: %d\n", ret); goto ERROR);
} else if (selfDtype == aclDataType::ACL_INT32) {
std::vector<int32_t> selfHostData(shape_size1, 0);
ret = CreateAclTensor_New(selfHostData, selfShape, &selfDeviceAddr, selfDtype, aclFormat::ACL_FORMAT_ND, &self);
cstSelfShapeSz = (uint64_t)GetShapeSize(selfShape);
cstSelfDtype = (int)(selfDtype);
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Create Tensor failed. ERROR: %d\n", ret); goto ERROR);
} else if (selfDtype == aclDataType::ACL_INT64) {
std::vector<int64_t> selfHostData(shape_size1, 0);
ret = CreateAclTensor_New(selfHostData, selfShape, &selfDeviceAddr, selfDtype, aclFormat::ACL_FORMAT_ND, &self);
cstSelfShapeSz = (uint64_t)GetShapeSize(selfShape);
cstSelfDtype = (int)(selfDtype);
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Create Tensor failed. ERROR: %d\n", ret); goto ERROR);
} else if (selfDtype == aclDataType::ACL_DOUBLE) {
std::vector<double> selfHostData(shape_size1, 0);
ret = CreateAclTensor_New(selfHostData, selfShape, &selfDeviceAddr, selfDtype, aclFormat::ACL_FORMAT_ND, &self);
cstSelfShapeSz = (uint64_t)GetShapeSize(selfShape);
cstSelfDtype = (int)(selfDtype);
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Create Tensor failed. ERROR: %d\n", ret); goto ERROR);
} else if (selfDtype == aclDataType::ACL_BF16) {
std::vector<int16_t> selfHostData(shape_size1, 0);
ret = CreateAclTensor_New(selfHostData, selfShape, &selfDeviceAddr, selfDtype, aclFormat::ACL_FORMAT_ND, &self);
cstSelfShapeSz = (uint64_t)GetShapeSize(selfShape);
cstSelfDtype = (int)(selfDtype);
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Create Tensor failed. ERROR: %d\n", ret); goto ERROR);
} else {
printf("selfDtype dtype=%d not support\n", selfDtype);
std::vector<double> selfHostData(shape_size1, 0);
ret = CreateAclTensor_New(selfHostData, selfShape, &selfDeviceAddr, selfDtype, aclFormat::ACL_FORMAT_ND, &self);
cstSelfShapeSz = (uint64_t)GetShapeSize(selfShape);
cstSelfDtype = (int)(selfDtype);
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Create Tensor failed. ERROR: %d\n", ret); goto ERROR);
}
std::vector<int64_t> vec1Shape = {shape21};
printf("vec1Shape:{%d}\n", shape21);
long long shape_size2 = GetShapeSize(vec1Shape);
if (shape_size2 > SHAPE_SIZE_CTL) {
goto ERROR;
}
printf("vec1 shape size %lld\n", shape_size2);
if (vec1Dtype == aclDataType::ACL_FLOAT) {
std::vector<float> vec1HostData(shape_size2, 0);
ret = CreateAclTensor_New(vec1HostData, vec1Shape, &vec1DeviceAddr, vec1Dtype, aclFormat::ACL_FORMAT_ND, &vec1);
cstVec1ShapeSz = (uint64_t)GetShapeSize(vec1Shape);
cstVec1Dtype = (int)(vec1Dtype);
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Create Tensor failed. ERROR: %d\n", ret); goto ERROR);
} else if (vec1Dtype == aclDataType::ACL_FLOAT16) {
std::vector<int16_t> vec1HostData(shape_size2, 0);
ret = CreateAclTensor_New(vec1HostData, vec1Shape, &vec1DeviceAddr, vec1Dtype, aclFormat::ACL_FORMAT_ND, &vec1);
cstVec1ShapeSz = (uint64_t)GetShapeSize(vec1Shape);
cstVec1Dtype = (int)(vec1Dtype);
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Create Tensor failed. ERROR: %d\n", ret); goto ERROR);
} else if (vec1Dtype == aclDataType::ACL_INT32) {
std::vector<int32_t> vec1HostData(shape_size2, 0);
ret = CreateAclTensor_New(vec1HostData, vec1Shape, &vec1DeviceAddr, vec1Dtype, aclFormat::ACL_FORMAT_ND, &vec1);
cstVec1ShapeSz = (uint64_t)GetShapeSize(vec1Shape);
cstVec1Dtype = (int)(vec1Dtype);
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Create Tensor failed. ERROR: %d\n", ret); goto ERROR);
} else if (vec1Dtype == aclDataType::ACL_INT64) {
std::vector<int64_t> vec1HostData(shape_size2, 0);
ret = CreateAclTensor_New(vec1HostData, vec1Shape, &vec1DeviceAddr, vec1Dtype, aclFormat::ACL_FORMAT_ND, &vec1);
cstVec1ShapeSz = (uint64_t)GetShapeSize(vec1Shape);
cstVec1Dtype = (int)(vec1Dtype);
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Create Tensor failed. ERROR: %d\n", ret); goto ERROR);
} else if (vec1Dtype == aclDataType::ACL_DOUBLE) {
std::vector<double> vec1HostData(shape_size2, 0);
ret = CreateAclTensor_New(vec1HostData, vec1Shape, &vec1DeviceAddr, vec1Dtype, aclFormat::ACL_FORMAT_ND, &vec1);
cstVec1ShapeSz = (uint64_t)GetShapeSize(vec1Shape);
cstVec1Dtype = (int)(vec1Dtype);
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Create Tensor failed. ERROR: %d\n", ret); goto ERROR);
} else if (vec1Dtype == aclDataType::ACL_BF16) {
std::vector<int16_t> vec1HostData(shape_size2, 0);
ret = CreateAclTensor_New(vec1HostData, vec1Shape, &vec1DeviceAddr, vec1Dtype, aclFormat::ACL_FORMAT_ND, &vec1);
cstVec1ShapeSz = (uint64_t)GetShapeSize(vec1Shape);
cstVec1Dtype = (int)(vec1Dtype);
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Create Tensor failed. ERROR: %d\n", ret); goto ERROR);
} else {
printf("vec1Dtype dtype=%d not support\n", vec1Dtype);
std::vector<double> vec1HostData(shape_size2, 0);
ret = CreateAclTensor_New(vec1HostData, vec1Shape, &vec1DeviceAddr, vec1Dtype, aclFormat::ACL_FORMAT_ND, &vec1);
cstVec1ShapeSz = (uint64_t)GetShapeSize(vec1Shape);
cstVec1Dtype = (int)(vec1Dtype);
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Create Tensor failed. ERROR: %d\n", ret); goto ERROR);
}
std::vector<int64_t> vec2Shape = {shape31};
printf("vec2Shape:{%d}\n", shape31);
long long shape_size3 = GetShapeSize(vec2Shape);
if (shape_size3 > SHAPE_SIZE_CTL) {
goto ERROR;
}
printf("vec2 shape size %lld\n", shape_size3);
if (vec2Dtype == aclDataType::ACL_FLOAT) {
std::vector<float> vec2HostData(shape_size3, 0);
ret = CreateAclTensor_New(vec2HostData, vec2Shape, &vec2DeviceAddr, vec2Dtype, aclFormat::ACL_FORMAT_ND, &vec2);
cstVec2ShapeSz = (uint64_t)GetShapeSize(vec2Shape);
cstVec2Dtype = (int)(vec2Dtype);
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Create Tensor failed. ERROR: %d\n", ret); goto ERROR);
} else if (vec2Dtype == aclDataType::ACL_FLOAT16) {
std::vector<int16_t> vec2HostData(shape_size3, 0);
ret = CreateAclTensor_New(vec2HostData, vec2Shape, &vec2DeviceAddr, vec2Dtype, aclFormat::ACL_FORMAT_ND, &vec2);
cstVec2ShapeSz = (uint64_t)GetShapeSize(vec2Shape);
cstVec2Dtype = (int)(vec2Dtype);
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Create Tensor failed. ERROR: %d\n", ret); goto ERROR);
} else if (vec2Dtype == aclDataType::ACL_INT32) {
std::vector<int32_t> vec2HostData(shape_size3, 0);
ret = CreateAclTensor_New(vec2HostData, vec2Shape, &vec2DeviceAddr, vec2Dtype, aclFormat::ACL_FORMAT_ND, &vec2);
cstVec2ShapeSz = (uint64_t)GetShapeSize(vec2Shape);
cstVec2Dtype = (int)(vec2Dtype);
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Create Tensor failed. ERROR: %d\n", ret); goto ERROR);
} else if (vec2Dtype == aclDataType::ACL_INT64) {
std::vector<int64_t> vec2HostData(shape_size3, 0);
ret = CreateAclTensor_New(vec2HostData, vec2Shape, &vec2DeviceAddr, vec2Dtype, aclFormat::ACL_FORMAT_ND, &vec2);
cstVec2ShapeSz = (uint64_t)GetShapeSize(vec2Shape);
cstVec2Dtype = (int)(vec2Dtype);
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Create Tensor failed. ERROR: %d\n", ret); goto ERROR);
} else if (vec2Dtype == aclDataType::ACL_DOUBLE) {
std::vector<double> vec2HostData(shape_size3, 0);
ret = CreateAclTensor_New(vec2HostData, vec2Shape, &vec2DeviceAddr, vec2Dtype, aclFormat::ACL_FORMAT_ND, &vec2);
cstVec2ShapeSz = (uint64_t)GetShapeSize(vec2Shape);
cstVec2Dtype = (int)(vec2Dtype);
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Create Tensor failed. ERROR: %d\n", ret); goto ERROR);
} else if (vec2Dtype == aclDataType::ACL_BF16) {
std::vector<int16_t> vec2HostData(shape_size3, 0);
ret = CreateAclTensor_New(vec2HostData, vec2Shape, &vec2DeviceAddr, vec2Dtype, aclFormat::ACL_FORMAT_ND, &vec2);
cstVec2ShapeSz = (uint64_t)GetShapeSize(vec2Shape);
cstVec2Dtype = (int)(vec2Dtype);
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Create Tensor failed. ERROR: %d\n", ret); goto ERROR);
} else {
printf("vec2Dtype dtype=%d not support\n", vec2Dtype);
std::vector<double> vec2HostData(shape_size3, 0);
ret = CreateAclTensor_New(vec2HostData, vec2Shape, &vec2DeviceAddr, vec2Dtype, aclFormat::ACL_FORMAT_ND, &vec2);
cstVec2ShapeSz = (uint64_t)GetShapeSize(vec2Shape);
cstVec2Dtype = (int)(vec2Dtype);
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Create Tensor failed. ERROR: %d\n", ret); goto ERROR);
}
std::vector<int64_t> outShape = {shape41, shape42};
printf("outShape:{%d,%d}\n", shape41, shape42);
long long shape_size4 = GetShapeSize(outShape);
if (shape_size4 > SHAPE_SIZE_CTL) {
goto ERROR;
}
printf("out shape size %lld\n", shape_size4);
if (outDtype == aclDataType::ACL_FLOAT) {
std::vector<float> outHostData(shape_size4, 0);
ret = CreateAclTensor_New(outHostData, outShape, &outDeviceAddr, outDtype, aclFormat::ACL_FORMAT_ND, &out);
cstOutShapeSz = (uint64_t)GetShapeSize(outShape);
cstOutDtype = (int)(outDtype);
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Create Tensor failed. ERROR: %d\n", ret); goto ERROR);
} else if (outDtype == aclDataType::ACL_FLOAT16) {
std::vector<int16_t> outHostData(shape_size4, 0);
ret = CreateAclTensor_New(outHostData, outShape, &outDeviceAddr, outDtype, aclFormat::ACL_FORMAT_ND, &out);
cstOutShapeSz = (uint64_t)GetShapeSize(outShape);
cstOutDtype = (int)(outDtype);
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Create Tensor failed. ERROR: %d\n", ret); goto ERROR);
} else if (outDtype == aclDataType::ACL_INT32) {
std::vector<int32_t> outHostData(shape_size4, 0);
ret = CreateAclTensor_New(outHostData, outShape, &outDeviceAddr, outDtype, aclFormat::ACL_FORMAT_ND, &out);
cstOutShapeSz = (uint64_t)GetShapeSize(outShape);
cstOutDtype = (int)(outDtype);
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Create Tensor failed. ERROR: %d\n", ret); goto ERROR);
} else if (outDtype == aclDataType::ACL_INT64) {
std::vector<int64_t> outHostData(shape_size4, 0);
ret = CreateAclTensor_New(outHostData, outShape, &outDeviceAddr, outDtype, aclFormat::ACL_FORMAT_ND, &out);
cstOutShapeSz = (uint64_t)GetShapeSize(outShape);
cstOutDtype = (int)(outDtype);
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Create Tensor failed. ERROR: %d\n", ret); goto ERROR);
} else if (outDtype == aclDataType::ACL_DOUBLE) {
std::vector<double> outHostData(shape_size4, 0);
ret = CreateAclTensor_New(outHostData, outShape, &outDeviceAddr, outDtype, aclFormat::ACL_FORMAT_ND, &out);
cstOutShapeSz = (uint64_t)GetShapeSize(outShape);
cstOutDtype = (int)(outDtype);
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Create Tensor failed. ERROR: %d\n", ret); goto ERROR);
} else if (outDtype == aclDataType::ACL_BF16) {
std::vector<int16_t> outHostData(shape_size4, 0);
ret = CreateAclTensor_New(outHostData, outShape, &outDeviceAddr, outDtype, aclFormat::ACL_FORMAT_ND, &out);
cstOutShapeSz = (uint64_t)GetShapeSize(outShape);
cstOutDtype = (int)(outDtype);
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Create Tensor failed. ERROR: %d\n", ret); goto ERROR);
} else {
printf("outDtype dtype=%d not support\n", outDtype);
std::vector<double> outHostData(shape_size4, 0);
ret = CreateAclTensor_New(outHostData, outShape, &outDeviceAddr, outDtype, aclFormat::ACL_FORMAT_ND, &out);
cstOutShapeSz = (uint64_t)GetShapeSize(outShape);
cstOutDtype = (int)(outDtype);
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Create Tensor failed. ERROR: %d\n", ret); goto ERROR);
}
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);
}
cstVec1Bytes = (vec1DeviceAddr != nullptr) ? (size_t)cstVec1ShapeSz * (size_t)ConsistentSizeOfDtype((aclDataType)cstVec1Dtype) : 0;
printf("[FUZZ_CONSISTENT_BYTES] case_%d: tensor=vec1, dtype=%d(%s), shapeSize=%llu, cstBytes=%zu, ConsistentSizeOfDtype=%zu\n", fuzzi, (int)cstVec1Dtype, ConsistentDtypeStr((aclDataType)cstVec1Dtype), (unsigned long long)cstVec1ShapeSz, cstVec1Bytes, ConsistentSizeOfDtype((aclDataType)cstVec1Dtype));
if (cstVec1Bytes == 0 && vec1DeviceAddr != nullptr) {
printf("[FUZZ_CONSISTENT_BYTES] case_%d: WARN tensor=vec1 addr!=nullptr but cstBytes=0, dtype may be uncovered by ConsistentSizeOfDtype\n", fuzzi);
}
cstVec1SaveBuf = (cstVec1Bytes > 0) ? malloc(cstVec1Bytes) : nullptr;
if (cstVec1SaveBuf != nullptr && vec1DeviceAddr != nullptr) {
aclrtMemcpy(cstVec1SaveBuf, cstVec1Bytes, vec1DeviceAddr, cstVec1Bytes, ACL_MEMCPY_DEVICE_TO_HOST);
}
cstVec2Bytes = (vec2DeviceAddr != nullptr) ? (size_t)cstVec2ShapeSz * (size_t)ConsistentSizeOfDtype((aclDataType)cstVec2Dtype) : 0;
printf("[FUZZ_CONSISTENT_BYTES] case_%d: tensor=vec2, dtype=%d(%s), shapeSize=%llu, cstBytes=%zu, ConsistentSizeOfDtype=%zu\n", fuzzi, (int)cstVec2Dtype, ConsistentDtypeStr((aclDataType)cstVec2Dtype), (unsigned long long)cstVec2ShapeSz, cstVec2Bytes, ConsistentSizeOfDtype((aclDataType)cstVec2Dtype));
if (cstVec2Bytes == 0 && vec2DeviceAddr != nullptr) {
printf("[FUZZ_CONSISTENT_BYTES] case_%d: WARN tensor=vec2 addr!=nullptr but cstBytes=0, dtype may be uncovered by ConsistentSizeOfDtype\n", fuzzi);
}
cstVec2SaveBuf = (cstVec2Bytes > 0) ? malloc(cstVec2Bytes) : nullptr;
if (cstVec2SaveBuf != nullptr && vec2DeviceAddr != nullptr) {
aclrtMemcpy(cstVec2SaveBuf, cstVec2Bytes, vec2DeviceAddr, cstVec2Bytes, ACL_MEMCPY_DEVICE_TO_HOST);
}
cstOutBytes = (outDeviceAddr != nullptr) ? (size_t)cstOutShapeSz * (size_t)ConsistentSizeOfDtype((aclDataType)cstOutDtype) : 0;
printf("[FUZZ_CONSISTENT_BYTES] case_%d: tensor=out, dtype=%d(%s), shapeSize=%llu, cstBytes=%zu, ConsistentSizeOfDtype=%zu\n", fuzzi, (int)cstOutDtype, ConsistentDtypeStr((aclDataType)cstOutDtype), (unsigned long long)cstOutShapeSz, cstOutBytes, ConsistentSizeOfDtype((aclDataType)cstOutDtype));
if (cstOutBytes == 0 && outDeviceAddr != nullptr) {
printf("[FUZZ_CONSISTENT_BYTES] case_%d: WARN tensor=out addr!=nullptr but cstBytes=0, dtype may be uncovered by ConsistentSizeOfDtype\n", fuzzi);
}
cstOutSaveBuf = (cstOutBytes > 0) ? malloc(cstOutBytes) : nullptr;
if (cstOutSaveBuf != nullptr && outDeviceAddr != nullptr) {
aclrtMemcpy(cstOutSaveBuf, cstOutBytes, outDeviceAddr, cstOutBytes, ACL_MEMCPY_DEVICE_TO_HOST);
}
cstRunCount = 0;
cstAllOk = true;
for (int cstRun = 0; cstRun < CONSISTENT_RUN_TIMES; cstRun++) {
if (cstSelfSaveBuf != nullptr && selfDeviceAddr != nullptr) {
aclrtMemcpy(selfDeviceAddr, cstSelfBytes, cstSelfSaveBuf, cstSelfBytes, ACL_MEMCPY_HOST_TO_DEVICE);
}
if (cstVec1SaveBuf != nullptr && vec1DeviceAddr != nullptr) {
aclrtMemcpy(vec1DeviceAddr, cstVec1Bytes, cstVec1SaveBuf, cstVec1Bytes, ACL_MEMCPY_HOST_TO_DEVICE);
}
if (cstVec2SaveBuf != nullptr && vec2DeviceAddr != nullptr) {
aclrtMemcpy(vec2DeviceAddr, cstVec2Bytes, cstVec2SaveBuf, cstVec2Bytes, ACL_MEMCPY_HOST_TO_DEVICE);
}
if (cstOutSaveBuf != nullptr && outDeviceAddr != nullptr) {
aclrtMemcpy(outDeviceAddr, cstOutBytes, cstOutSaveBuf, cstOutBytes, ACL_MEMCPY_HOST_TO_DEVICE);
}
ret = aclnnAddrGetWorkspaceSize(self, vec1, vec2, beta, alpha, out, &workspaceSize, &executor);
if (ret != ACL_SUCCESS) {
printf("aclnnAddr 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 = aclnnAddr(workspaceAddr, workspaceSize, executor, stream);
if (ret != ACL_SUCCESS) {
printf("aclnnAddr 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 (selfDeviceAddr != nullptr && cstSelfBytes > 0) {
cstSelfHashArr[cstRun] = ConsistentHashDeviceTensor(selfDeviceAddr, cstSelfBytes);
}
if (vec1DeviceAddr != nullptr && cstVec1Bytes > 0) {
cstVec1HashArr[cstRun] = ConsistentHashDeviceTensor(vec1DeviceAddr, cstVec1Bytes);
}
if (vec2DeviceAddr != nullptr && cstVec2Bytes > 0) {
cstVec2HashArr[cstRun] = ConsistentHashDeviceTensor(vec2DeviceAddr, cstVec2Bytes);
}
if (outDeviceAddr != nullptr && cstOutBytes > 0) {
cstOutHashArr[cstRun] = ConsistentHashDeviceTensor(outDeviceAddr, cstOutBytes);
}
cstRunCount++;
printf("aclnnAddr execute success :%d\n", (int)ret);
}
if (cstAllOk && cstRunCount == CONSISTENT_RUN_TIMES) {
bool cstSelfSame = true;
for (int cstR = 1; cstR < CONSISTENT_RUN_TIMES; cstR++) {
if (cstSelfHashArr[cstR] != cstSelfHashArr[0]) { cstSelfSame = false; break; }
}
bool cstVec1Same = true;
for (int cstR = 1; cstR < CONSISTENT_RUN_TIMES; cstR++) {
if (cstVec1HashArr[cstR] != cstVec1HashArr[0]) { cstVec1Same = false; break; }
}
bool cstVec2Same = true;
for (int cstR = 1; cstR < CONSISTENT_RUN_TIMES; cstR++) {
if (cstVec2HashArr[cstR] != cstVec2HashArr[0]) { cstVec2Same = false; break; }
}
bool cstOutSame = true;
for (int cstR = 1; cstR < CONSISTENT_RUN_TIMES; cstR++) {
if (cstOutHashArr[cstR] != cstOutHashArr[0]) { cstOutSame = false; break; }
}
bool cstAllSame = cstSelfSame && cstVec1Same && cstVec2Same && cstOutSame;
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 (!cstSelfSame) printf("self ");
if (!cstVec1Same) printf("vec1 ");
if (!cstVec2Same) printf("vec2 ");
if (!cstOutSame) printf("out ");
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: vec1 hash:", fuzzi);
for (int cstR = 0; cstR < CONSISTENT_RUN_TIMES; cstR++) printf(" run%d=%llu", cstR, (unsigned long long)cstVec1HashArr[cstR]);
printf("\n");
printf("[FUZZ_CONSISTENT_DETAIL] case_%d: vec2 hash:", fuzzi);
for (int cstR = 0; cstR < CONSISTENT_RUN_TIMES; cstR++) printf(" run%d=%llu", cstR, (unsigned long long)cstVec2HashArr[cstR]);
printf("\n");
printf("[FUZZ_CONSISTENT_DETAIL] case_%d: out hash:", fuzzi);
for (int cstR = 0; cstR < CONSISTENT_RUN_TIMES; cstR++) printf(" run%d=%llu", cstR, (unsigned long long)cstOutHashArr[cstR]);
printf("\n");
printf("[FUZZ_PARAM] ");
printf("self: dtype=%s, format=%s, ", ConsistentDtypeStr((aclDataType)cstSelfDtype), ConsistentFormatStr(aclFormat::ACL_FORMAT_ND)); printf("shapeSize=%llu", (unsigned long long)cstSelfShapeSz); printf("; ");
printf("vec1: dtype=%s, format=%s, ", ConsistentDtypeStr((aclDataType)cstVec1Dtype), ConsistentFormatStr(aclFormat::ACL_FORMAT_ND)); printf("shapeSize=%llu", (unsigned long long)cstVec1ShapeSz); printf("; ");
printf("vec2: dtype=%s, format=%s, ", ConsistentDtypeStr((aclDataType)cstVec2Dtype), ConsistentFormatStr(aclFormat::ACL_FORMAT_ND)); printf("shapeSize=%llu", (unsigned long long)cstVec2ShapeSz); printf("; ");
printf("out: dtype=%s, format=%s, ", ConsistentDtypeStr((aclDataType)cstOutDtype), ConsistentFormatStr(aclFormat::ACL_FORMAT_ND)); printf("shapeSize=%llu", (unsigned long long)cstOutShapeSz); printf("; ");
printf("beta=%g; ", (double)cstBetaVal);
printf("alpha=%g; ", (double)cstAlphaVal);
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("self: dtype=%s, format=%s, ", ConsistentDtypeStr((aclDataType)cstSelfDtype), ConsistentFormatStr(aclFormat::ACL_FORMAT_ND)); printf("shapeSize=%llu", (unsigned long long)cstSelfShapeSz); printf("; ");
printf("vec1: dtype=%s, format=%s, ", ConsistentDtypeStr((aclDataType)cstVec1Dtype), ConsistentFormatStr(aclFormat::ACL_FORMAT_ND)); printf("shapeSize=%llu", (unsigned long long)cstVec1ShapeSz); printf("; ");
printf("vec2: dtype=%s, format=%s, ", ConsistentDtypeStr((aclDataType)cstVec2Dtype), ConsistentFormatStr(aclFormat::ACL_FORMAT_ND)); printf("shapeSize=%llu", (unsigned long long)cstVec2ShapeSz); printf("; ");
printf("out: dtype=%s, format=%s, ", ConsistentDtypeStr((aclDataType)cstOutDtype), ConsistentFormatStr(aclFormat::ACL_FORMAT_ND)); printf("shapeSize=%llu", (unsigned long long)cstOutShapeSz); printf("; ");
printf("beta=%g; ", (double)cstBetaVal);
printf("alpha=%g; ", (double)cstAlphaVal);
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));
aclDestroyScalar(alpha);
aclDestroyScalar(beta);
if (cstSelfSaveBuf != nullptr) { free(cstSelfSaveBuf); cstSelfSaveBuf = nullptr; }
if (cstVec1SaveBuf != nullptr) { free(cstVec1SaveBuf); cstVec1SaveBuf = nullptr; }
if (cstVec2SaveBuf != nullptr) { free(cstVec2SaveBuf); cstVec2SaveBuf = nullptr; }
if (cstOutSaveBuf != nullptr) { free(cstOutSaveBuf); cstOutSaveBuf = nullptr; }
aclDestroyTensor(self);
aclDestroyTensor(vec1);
aclDestroyTensor(vec2);
aclDestroyTensor(out);
aclrtFree(selfDeviceAddr);
aclrtFree(vec1DeviceAddr);
aclrtFree(vec2DeviceAddr);
aclrtFree(outDeviceAddr);
if (workspaceSize > 0) {
aclrtFree(workspaceAddr);
}
}
DT_FUZZ_END()
WriteDTLog("aclnnAddr", "aclnnAddr 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("aclnnAddr", "aclnnAddr consistent op fuzz end \n");
aclrtDestroyStream(stream);
aclrtDestroyContext(context);
aclrtResetDevice(deviceId);
aclFinalize();
return 0;
}
extern "C" int aclnnAddr_consistent_fuzz(int argc, char *argv[]);
int aclnnAddr_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;
strcpy(seedPath, strcat(logPath, __func__));
if (argc < 1) {
cout << "[ERROR] input arg num must be bigger than 1 \n" << endl;
cout << "The second arg stand for testcase num \n" << endl;
return -1;
} else if (argc > 1) {
fuzz_num = atoi(argv[2]);
}
if (argc == 4) {
deviceId = atoi(argv[3]);
}
printf("deviceId %d \n", deviceId);
printf("fuzz_num %d \n", fuzz_num);
printf("aclnnAddr_consistent :%d \n", aclnnAddr_consistent(fuzz_num));
return 0;
}