Skip to content

Commit

Permalink
RPP Test Suite Upgrade 4 - CSV to BIN conversions for file size reduc…
Browse files Browse the repository at this point in the history
…tion (#293)

* change golden outputs from .csv files to .bin files

* Changed comparision funtions to use .bin files

* Address review comments

* minor change

* Address review comments

* minor change

---------

Co-authored-by: HazarathKumarM <hazarathkumar@multicorewareinc.com>
  • Loading branch information
2 people authored and kiritigowda committed Jan 31, 2024
1 parent 2d7adde commit 7fca025
Show file tree
Hide file tree
Showing 132 changed files with 154 additions and 219 deletions.
Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.
Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

133 changes: 64 additions & 69 deletions utilities/test_suite/rpp_test_suite_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,24 @@ inline void read_image_batch_turbojpeg(Rpp8u *input, RpptDescPtr descPtr, vector
tjDestroy(m_jpegDecompressor);
}

template <typename T>
inline void read_bin_file(string refFile, T *binaryContent)
{
FILE *fp;
fp = fopen(refFile.c_str(), "rb");
if(!fp)
std::cerr << "\n unable to open file : "<<refFile;

fseek(fp, 0, SEEK_END);
long fsize = ftell(fp);
if (fsize == 0)
std::cerr << "File is empty";

fseek(fp, 0, SEEK_SET);
fread(binaryContent, fsize, 1, fp);
fclose(fp);
}

// Write a batch of images using the OpenCV library
inline void write_image_batch_opencv(string outputFolder, Rpp8u *output, RpptDescPtr dstDescPtr, vector<string>::const_iterator imagesNamesStart, RpptImagePatch *dstImgSizes, int maxImageDump)
{
Expand Down Expand Up @@ -909,8 +927,8 @@ inline void write_image_batch_opencv(string outputFolder, Rpp8u *output, RpptDes
}
}

// compares the output of PKD3-PKD3 variants
void compare_outputs_pkd(Rpp8u* output, Rpp8u* refOutput, RpptDescPtr dstDescPtr, RpptImagePatch *dstImgSizes, int refOutputHeight, int refOutputWidth, int refOutputSize, int &fileMatch)
// compares the output of PKD3-PKD3 and PLN1-PLN1 variants
void compare_outputs_pkd_and_pln1(Rpp8u* output, Rpp8u* refOutput, RpptDescPtr dstDescPtr, RpptImagePatch *dstImgSizes, int refOutputHeight, int refOutputWidth, int refOutputSize, int &fileMatch)
{
Rpp8u *rowTemp, *rowTempRef, *outVal, *outRefVal, *outputTemp, *outputTempRef;
for(int imageCnt = 0; imageCnt < dstDescPtr->n; imageCnt++)
Expand All @@ -919,7 +937,7 @@ void compare_outputs_pkd(Rpp8u* output, Rpp8u* refOutput, RpptDescPtr dstDescPtr
outputTempRef = refOutput + imageCnt * refOutputSize;
int height = dstImgSizes[imageCnt].height;
int width = dstImgSizes[imageCnt].width * dstDescPtr->c;
int matched_idx = 0;
int matchedIdx = 0;
int refOutputHstride = refOutputWidth * dstDescPtr->c;

for(int i = 0; i < height; i++)
Expand All @@ -932,16 +950,16 @@ void compare_outputs_pkd(Rpp8u* output, Rpp8u* refOutput, RpptDescPtr dstDescPtr
outRefVal = rowTempRef + j;
int diff = abs(*outVal - *outRefVal);
if(diff <= CUTOFF)
matched_idx++;
matchedIdx++;
}
}
if(matched_idx == (height * width) && matched_idx !=0)
if(matchedIdx == (height * width) && matchedIdx !=0)
fileMatch++;
}
}

// compares the output of PLN3-PLN3 and PLN1-PLN1 variants
void compare_outputs_pln(Rpp8u* output, Rpp8u* refOutput, RpptDescPtr dstDescPtr, RpptImagePatch *dstImgSizes, int refOutputHeight, int refOutputWidth, int refOutputSize, int &fileMatch)
// compares the output of PLN3-PLN3 variants.This function compares the output buffer of pln3 format with its reference output in pkd3 format.
void compare_outputs_pln3(Rpp8u* output, Rpp8u* refOutput, RpptDescPtr dstDescPtr, RpptImagePatch *dstImgSizes, int refOutputHeight, int refOutputWidth, int refOutputSize, int &fileMatch)
{
Rpp8u *rowTemp, *rowTempRef, *outVal, *outRefVal, *outputTemp, *outputTempRef, *outputTempChn, *outputTempRefChn;
for(int imageCnt = 0; imageCnt < dstDescPtr->n; imageCnt++)
Expand All @@ -950,29 +968,28 @@ void compare_outputs_pln(Rpp8u* output, Rpp8u* refOutput, RpptDescPtr dstDescPtr
outputTempRef = refOutput + imageCnt * refOutputSize;
int height = dstImgSizes[imageCnt].height;
int width = dstImgSizes[imageCnt].width;
int matched_idx = 0;
int refOutputHstride = refOutputWidth;
int refOutputCstride = refOutputHeight * refOutputWidth;
int matchedIdx = 0;
int refOutputHstride = refOutputWidth * dstDescPtr->c;

for(int c = 0; c < dstDescPtr->c; c++)
{
outputTempChn = outputTemp + c * dstDescPtr->strides.cStride;
outputTempRefChn = outputTempRef + c * refOutputCstride;
outputTempRefChn = outputTempRef + c;
for(int i = 0; i < height; i++)
{
rowTemp = outputTempChn + i * dstDescPtr->strides.hStride;
rowTempRef = outputTempRefChn + i * refOutputHstride;
for(int j = 0; j < width; j++)
{
outVal = rowTemp + j;
outRefVal = rowTempRef + j ;
outRefVal = rowTempRef + j * 3;
int diff = abs(*outVal - *outRefVal);
if(diff <= CUTOFF)
matched_idx++;
matchedIdx++;
}
}
}
if(matched_idx == (height * width * dstDescPtr->c) && matched_idx !=0)
if(matchedIdx == (height * width * dstDescPtr->c) && matchedIdx !=0)
fileMatch++;
}
}
Expand All @@ -985,6 +1002,8 @@ inline void compare_output(T* output, string funcName, RpptDescPtr srcDescPtr, R
int refOutputWidth = ((GOLDEN_OUTPUT_MAX_WIDTH / 8) * 8) + 8; // obtain next multiple of 8 after GOLDEN_OUTPUT_MAX_WIDTH
int refOutputHeight = GOLDEN_OUTPUT_MAX_HEIGHT;
int refOutputSize = refOutputHeight * refOutputWidth * dstDescPtr->c;
Rpp64u binOutputSize = refOutputHeight * refOutputWidth * dstDescPtr->n * 4;
int pln1RefStride = dstDescPtr->strides.nStride * dstDescPtr->n * 3;

string dataType[4] = {"_u8_", "_f16_", "_f32_", "_i8_"};

Expand All @@ -997,6 +1016,7 @@ inline void compare_output(T* output, string funcName, RpptDescPtr srcDescPtr, R
func += dataType[dstDescPtr->dataType];
}

std::string binFile = func + "Tensor";
if(dstDescPtr->layout == RpptLayout::NHWC)
func += "Tensor_PKD3";
else
Expand All @@ -1011,47 +1031,36 @@ inline void compare_output(T* output, string funcName, RpptDescPtr srcDescPtr, R
func += "Tensor_PKD3";
else
func += "Tensor_PLN3";
pln1RefStride = 0;
}
else
func += "Tensor_PLN1";
}
}
if(testCase == 21 ||testCase == 23 || testCase == 24)
{
func += "_interpolationType" + interpolationTypeName;
binFile += "_interpolationType" + interpolationTypeName;
}
else if(testCase == 8)
{
func += "_noiseType" + noiseTypeName;
refFile = scriptPath + "/../REFERENCE_OUTPUT/" + funcName + "/"+ func + ".csv";

ifstream file(refFile);
Rpp8u *refOutput;
refOutput = (Rpp8u *)malloc(dstDescPtr->n * refOutputSize * sizeof(Rpp8u));
binFile += "_noiseType" + noiseTypeName;
}
refFile = scriptPath + "/../REFERENCE_OUTPUT/" + funcName + "/"+ binFile + ".bin";
string line,word;
int index = 0;
int fileMatch = 0;

// Load the refennce output values from files and store in vector
if(file.is_open())
{
while(getline(file, line))
{
stringstream str(line);
while(getline(str, word, ','))
{
refOutput[index] = stoi(word);
index++;
}
}
}
else
{
cout<<"Could not open the reference output. Please check the path specified\n";
return;
}
Rpp8u *binaryContent = (Rpp8u *)malloc(binOutputSize * sizeof(Rpp8u));
read_bin_file(refFile, binaryContent);

int fileMatch = 0;
if(dstDescPtr->layout == RpptLayout::NHWC)
compare_outputs_pkd(output, refOutput, dstDescPtr, dstImgSizes, refOutputHeight, refOutputWidth, refOutputSize, fileMatch);
compare_outputs_pkd_and_pln1(output, binaryContent, dstDescPtr, dstImgSizes, refOutputHeight, refOutputWidth, refOutputSize, fileMatch);
else if(dstDescPtr->layout == RpptLayout::NCHW && dstDescPtr->c == 3)
compare_outputs_pln3(output, binaryContent, dstDescPtr, dstImgSizes, refOutputHeight, refOutputWidth, refOutputSize, fileMatch);
else
compare_outputs_pln(output, refOutput, dstDescPtr, dstImgSizes, refOutputHeight, refOutputWidth, refOutputSize, fileMatch);
compare_outputs_pkd_and_pln1(output, binaryContent + pln1RefStride, dstDescPtr, dstImgSizes, refOutputHeight, refOutputWidth, refOutputSize, fileMatch);

std::cout << std::endl << "Results for " << func << " :" << std::endl;
std::string status = func + ": ";
Expand All @@ -1074,16 +1083,20 @@ inline void compare_output(T* output, string funcName, RpptDescPtr srcDescPtr, R
qaResults << status << std::endl;
qaResults.close();
}
free(binaryContent);
}

inline void compare_reduction_output(Rpp64u* output, string funcName, RpptDescPtr srcDescPtr, int testCase, string dst, string scriptPath)
{
string func = funcName;
string refFile = "";
int pln1RefStride = srcDescPtr->n * 4;
Rpp64u binaryOutputSize = srcDescPtr->n * 5;

string dataType[4] = {"_u8_", "_f16_", "_f32_", "_i8_"};

func += dataType[srcDescPtr->dataType];
std::string binFile = func + "Tensor";

if(srcDescPtr->layout == RpptLayout::NHWC)
func += "Tensor_PKD3";
Expand All @@ -1095,40 +1108,21 @@ inline void compare_reduction_output(Rpp64u* output, string funcName, RpptDescPt
func += "Tensor_PLN1";
}

refFile = scriptPath + "/../REFERENCE_OUTPUT/" + funcName + "/"+ func + ".csv";
refFile = scriptPath + "/../REFERENCE_OUTPUT/" + funcName + "/"+ binFile + ".bin";

ifstream file(refFile);
Rpp64u *refOutput;
refOutput = (Rpp64u *)calloc(srcDescPtr->n * 4, sizeof(Rpp64u));
string line,word;
int index = 0;

// Load the refennce output values from files and store in vector
if(file.is_open())
{
while(getline(file, line))
{
stringstream str(line);
while(getline(str, word, ','))
{
refOutput[index] = stoi(word);
index++;
}
}
}
else
{
cout<<"Could not open the reference output. Please check the path specified\n";
return;
}

int fileMatch = 0;
int matched_values = 0;
Rpp64u *binaryContent = (Rpp64u *)malloc(binaryOutputSize * sizeof(Rpp64u));
read_bin_file(refFile, binaryContent);

if(srcDescPtr->c == 1)
{
binaryContent += pln1RefStride;
for(int i = 0; i < srcDescPtr->n; i++)
{
int diff = output[i] - refOutput[i];
int diff = output[i] - binaryContent[i];
if(diff <= CUTOFF)
fileMatch++;
}
Expand All @@ -1140,7 +1134,7 @@ inline void compare_reduction_output(Rpp64u* output, string funcName, RpptDescPt
matched_values = 0;
for(int j = 0; j < 4; j++)
{
int diff = output[(i * 4) + j] - refOutput[(i * 4) + j];
int diff = output[(i * 4) + j] - binaryContent[(i * 4) + j];
if(diff <= CUTOFF)
matched_values++;
}
Expand All @@ -1149,16 +1143,16 @@ inline void compare_reduction_output(Rpp64u* output, string funcName, RpptDescPt
}
}

std::cerr << std::endl << "Results for " << func << " :" << std::endl;
std::cout << std::endl << "Results for " << func << " :" << std::endl;
std::string status = func + ": ";
if(fileMatch == srcDescPtr->n)
{
std::cerr << "PASSED!" << std::endl;
std::cout << "PASSED!" << std::endl;
status += "PASSED";
}
else
{
std::cerr << "FAILED! " << fileMatch << "/" << srcDescPtr->n << " outputs are matching with reference outputs" << std::endl;
std::cout << "FAILED! " << fileMatch << "/" << srcDescPtr->n << " outputs are matching with reference outputs" << std::endl;
status += "FAILED";
}

Expand All @@ -1170,6 +1164,7 @@ inline void compare_reduction_output(Rpp64u* output, string funcName, RpptDescPt
qaResults << status << std::endl;
qaResults.close();
}
free(binaryContent);
}

// Used to randomly swap values present in array of size n
Expand Down
Loading

0 comments on commit 7fca025

Please sign in to comment.