Printf fixes for reference results #673 #675 (#680)

* Moved float tests that expect limits into their own sub-test.

These are harder to test generically on the CPU so have them be their own test which will retain hard-coded reference results.

* Remove unused variable.

* Switched reference result type from (char**) to (vector::const char*)

* printf: generate reference results where possible #673 #675

The reference results had two issues:
- They did not take into account the rounding mode of the device.
- Scientific notation results did not have trailing zero's, meaning that the exponent could be a single digit, despite the requirement being at least two digits.

This change introduces runtime generated reference results for types with numerical representations (float, int, hex, etc) where a direct mapping to standard C99 (sn)printf is possible to execute on the CPU.

* Trim leading zeroes from the exponent when verifying result #675.

There is no limit on how many leading zeros may be in the exponent, so strip them all.

* Switched to using get_default_rounding_mode.
This commit is contained in:
Jeremy Kemp
2020-04-15 14:30:29 +01:00
committed by GitHub
parent 349da6e6fb
commit ce39ffdda7
3 changed files with 247 additions and 200 deletions

View File

@@ -17,9 +17,12 @@
#define TESTPRINTF_INCLUDED_H
#include "harness/compat.h"
#include "harness/testHarness.h"
#include "harness/rounding_mode.h"
#include <stdio.h>
#include <string.h>
#include <vector>
#ifdef __APPLE__
#include <OpenCL/opencl.h>
@@ -38,10 +41,11 @@
//-----------------------------------------
// Types
//-----------------------------------------
enum Type
enum PrintfTestType
{
TYPE_INT,
TYPE_FLOAT,
TYPE_FLOAT_LIMITS,
TYPE_OCTAL,
TYPE_UNSIGNED,
TYPE_HEXADEC,
@@ -66,22 +70,39 @@ struct printDataGenParameters
const char* addrSpacePAdd;
};
// Reference results - filled out at run-time
static std::vector<std::string> correctBufferInt;
static std::vector<std::string> correctBufferFloat;
static std::vector<std::string> correctBufferOctal;
static std::vector<std::string> correctBufferUnsigned;
static std::vector<std::string> correctBufferHexadecimal;
// Reference results - Compile-time known
extern std::vector<std::string> correctBufferChar;
extern std::vector<std::string> correctBufferString;
extern std::vector<std::string> correctBufferFloatLimits;
extern std::vector<std::string> correctBufferVector;
extern std::vector<std::string> correctAddrSpace;
// Helper for generating reference results
void generateRef(const cl_device_id device);
//-----------------------------------------
//Test Case
//-----------------------------------------
struct testCase
{
unsigned int _testNum; //test number
enum Type _type; //(data)type for test
//const char** _strPrint; //auxiliary data to build the code for kernel source
const char** _correctBuffer; //look-up table for correct results for printf
struct printDataGenParameters* _genParameters; //auxiliary data to build the code for kernel source
enum PrintfTestType _type; //(data)type for test
std::vector<std::string>& _correctBuffer; //look-up table for correct results for printf
std::vector<printDataGenParameters>& _genParameters; //auxiliary data to build the code for kernel source
void (*printFN)(printDataGenParameters&,
char*,
const size_t); //function pointer for generating reference results
Type dataType; //the data type that will be printed during reference result generation (used for setting rounding mode)
};
extern const char* strType[];
extern testCase* allTestCase[];
extern std::vector<testCase*> allTestCase;
size_t verifyOutputBuffer(char *analysisBuffer,testCase* pTestCase,size_t testId,cl_ulong pAddr = 0);