mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-19 06:09:01 +00:00
Corrections for printf test with floating point limits arguments (#1940)
According to work plan from issue #1058
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
#include "harness/os_helpers.h"
|
||||
#include "harness/typeWrappers.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
@@ -78,10 +79,16 @@ static int isKernelPFormat(testCase* pTestCase,size_t testId);
|
||||
// Static functions declarations
|
||||
//-----------------------------------------
|
||||
// Make a program that uses printf for the given type/format,
|
||||
static cl_program makePrintfProgram(cl_kernel *kernel_ptr, const cl_context context,const unsigned int testId,const unsigned int testNum,bool isLongSupport = true,bool is64bAddrSpace = false);
|
||||
static cl_program
|
||||
makePrintfProgram(cl_kernel* kernel_ptr, const cl_context context,
|
||||
const unsigned int testId, const unsigned int testNum,
|
||||
const unsigned int formatNum, bool isLongSupport = true,
|
||||
bool is64bAddrSpace = false);
|
||||
|
||||
// Creates and execute the printf test for the given device, context, type/format
|
||||
static int doTest(cl_command_queue queue, cl_context context, const unsigned int testId, const unsigned int testNum, cl_device_id device);
|
||||
static int doTest(cl_command_queue queue, cl_context context,
|
||||
const unsigned int testId, const unsigned int testNum,
|
||||
cl_device_id device);
|
||||
|
||||
// Check if device supports long
|
||||
static bool isLongSupported(cl_device_id device_id);
|
||||
@@ -206,7 +213,12 @@ int waitForEvent(cl_event* event)
|
||||
//-----------------------------------------
|
||||
// makePrintfProgram
|
||||
//-----------------------------------------
|
||||
static cl_program makePrintfProgram(cl_kernel *kernel_ptr, const cl_context context,const unsigned int testId,const unsigned int testNum,bool isLongSupport,bool is64bAddrSpace)
|
||||
static cl_program makePrintfProgram(cl_kernel* kernel_ptr,
|
||||
const cl_context context,
|
||||
const unsigned int testId,
|
||||
const unsigned int testNum,
|
||||
const unsigned int formatNum,
|
||||
bool isLongSupport, bool is64bAddrSpace)
|
||||
{
|
||||
int err;
|
||||
cl_program program;
|
||||
@@ -223,7 +235,10 @@ static cl_program makePrintfProgram(cl_kernel *kernel_ptr, const cl_context cont
|
||||
"(void)\n",
|
||||
"{\n"
|
||||
" printf(\"",
|
||||
allTestCase[testId]->_genParameters[testNum].genericFormat,
|
||||
allTestCase[testId]
|
||||
->_genParameters[testNum]
|
||||
.genericFormats[formatNum]
|
||||
.c_str(),
|
||||
"\\n\",",
|
||||
allTestCase[testId]->_genParameters[testNum].dataRepresentation,
|
||||
");",
|
||||
@@ -254,12 +269,20 @@ static cl_program makePrintfProgram(cl_kernel *kernel_ptr, const cl_context cont
|
||||
"}\n"
|
||||
};
|
||||
//Program Source code for address space
|
||||
const char *sourceAddrSpace[] = {
|
||||
"__kernel void ", testname,"(",addrSpaceArgument,
|
||||
const char* sourceAddrSpace[] = {
|
||||
"__kernel void ",
|
||||
testname,
|
||||
"(",
|
||||
addrSpaceArgument,
|
||||
")\n{\n",
|
||||
allTestCase[testId]->_genParameters[testNum].addrSpaceVariableTypeQualifier,
|
||||
allTestCase[testId]
|
||||
->_genParameters[testNum]
|
||||
.addrSpaceVariableTypeQualifier,
|
||||
"printf(",
|
||||
allTestCase[testId]->_genParameters[testNum].genericFormat,
|
||||
allTestCase[testId]
|
||||
->_genParameters[testNum]
|
||||
.genericFormats[formatNum]
|
||||
.c_str(),
|
||||
",",
|
||||
allTestCase[testId]->_genParameters[testNum].addrSpaceParameter,
|
||||
"); ",
|
||||
@@ -399,22 +422,17 @@ static bool is64bAddressSpace(cl_device_id device_id)
|
||||
//-----------------------------------------
|
||||
// doTest
|
||||
//-----------------------------------------
|
||||
static int doTest(cl_command_queue queue, cl_context context, const unsigned int testId, const unsigned int testNum, cl_device_id device)
|
||||
static int doTest(cl_command_queue queue, cl_context context,
|
||||
const unsigned int testId, const unsigned int testNum,
|
||||
cl_device_id device)
|
||||
{
|
||||
if ((allTestCase[testId]->_type == TYPE_HALF
|
||||
|| allTestCase[testId]->_type == TYPE_HALF_LIMITS)
|
||||
&& !is_extension_available(device, "cl_khr_fp16"))
|
||||
int err = TEST_FAIL;
|
||||
for (unsigned formatNum = 0; formatNum
|
||||
< allTestCase[testId]->_genParameters[testNum].genericFormats.size();
|
||||
formatNum++)
|
||||
{
|
||||
log_info(
|
||||
"Skipping half because cl_khr_fp16 extension is not supported.\n");
|
||||
return TEST_SKIPPED_ITSELF;
|
||||
}
|
||||
|
||||
if(allTestCase[testId]->_type == TYPE_VECTOR)
|
||||
{
|
||||
if ((strcmp(allTestCase[testId]->_genParameters[testNum].dataType,
|
||||
"half")
|
||||
== 0)
|
||||
if ((allTestCase[testId]->_type == TYPE_HALF
|
||||
|| allTestCase[testId]->_type == TYPE_HALF_LIMITS)
|
||||
&& !is_extension_available(device, "cl_khr_fp16"))
|
||||
{
|
||||
log_info("Skipping half because cl_khr_fp16 extension is not "
|
||||
@@ -422,171 +440,231 @@ static int doTest(cl_command_queue queue, cl_context context, const unsigned int
|
||||
return TEST_SKIPPED_ITSELF;
|
||||
}
|
||||
|
||||
log_info("%d)testing printf(\"%sv%s%s\",%s)\n",testNum,allTestCase[testId]->_genParameters[testNum].vectorFormatFlag,allTestCase[testId]->_genParameters[testNum].vectorSize,
|
||||
allTestCase[testId]->_genParameters[testNum].vectorFormatSpecifier,allTestCase[testId]->_genParameters[testNum].dataRepresentation);
|
||||
}
|
||||
else if(allTestCase[testId]->_type == TYPE_ADDRESS_SPACE)
|
||||
{
|
||||
if(isKernelArgument(allTestCase[testId], testNum))
|
||||
if (allTestCase[testId]->_type == TYPE_VECTOR)
|
||||
{
|
||||
log_info("%d)testing kernel //argument %s \n printf(%s,%s)\n",testNum,allTestCase[testId]->_genParameters[testNum].addrSpaceArgumentTypeQualifier,
|
||||
allTestCase[testId]->_genParameters[testNum].genericFormat,allTestCase[testId]->_genParameters[testNum].addrSpaceParameter);
|
||||
if ((strcmp(allTestCase[testId]->_genParameters[testNum].dataType,
|
||||
"half")
|
||||
== 0)
|
||||
&& !is_extension_available(device, "cl_khr_fp16"))
|
||||
{
|
||||
log_info("Skipping half because cl_khr_fp16 extension is not "
|
||||
"supported.\n");
|
||||
return TEST_SKIPPED_ITSELF;
|
||||
}
|
||||
|
||||
log_info(
|
||||
"%d)testing printf(\"%sv%s%s\",%s)\n", testNum,
|
||||
allTestCase[testId]->_genParameters[testNum].vectorFormatFlag,
|
||||
allTestCase[testId]->_genParameters[testNum].vectorSize,
|
||||
allTestCase[testId]
|
||||
->_genParameters[testNum]
|
||||
.vectorFormatSpecifier,
|
||||
allTestCase[testId]
|
||||
->_genParameters[testNum]
|
||||
.dataRepresentation);
|
||||
}
|
||||
else if (allTestCase[testId]->_type == TYPE_ADDRESS_SPACE)
|
||||
{
|
||||
if (isKernelArgument(allTestCase[testId], testNum))
|
||||
{
|
||||
log_info("%d)testing kernel //argument %s \n printf(%s,%s)\n",
|
||||
testNum,
|
||||
allTestCase[testId]
|
||||
->_genParameters[testNum]
|
||||
.addrSpaceArgumentTypeQualifier,
|
||||
allTestCase[testId]
|
||||
->_genParameters[testNum]
|
||||
.genericFormats[formatNum]
|
||||
.c_str(),
|
||||
allTestCase[testId]
|
||||
->_genParameters[testNum]
|
||||
.addrSpaceParameter);
|
||||
}
|
||||
else
|
||||
{
|
||||
log_info("%d)testing kernel //variable %s \n printf(%s,%s)\n",
|
||||
testNum,
|
||||
allTestCase[testId]
|
||||
->_genParameters[testNum]
|
||||
.addrSpaceVariableTypeQualifier,
|
||||
allTestCase[testId]
|
||||
->_genParameters[testNum]
|
||||
.genericFormats[formatNum]
|
||||
.c_str(),
|
||||
allTestCase[testId]
|
||||
->_genParameters[testNum]
|
||||
.addrSpaceParameter);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
log_info("%d)testing kernel //variable %s \n printf(%s,%s)\n",testNum,allTestCase[testId]->_genParameters[testNum].addrSpaceVariableTypeQualifier,
|
||||
allTestCase[testId]->_genParameters[testNum].genericFormat,allTestCase[testId]->_genParameters[testNum].addrSpaceParameter);
|
||||
log_info("%d)testing printf(\"%s\",%s)\n", testNum,
|
||||
allTestCase[testId]
|
||||
->_genParameters[testNum]
|
||||
.genericFormats[formatNum]
|
||||
.c_str(),
|
||||
allTestCase[testId]
|
||||
->_genParameters[testNum]
|
||||
.dataRepresentation);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
log_info("%d)testing printf(\"%s\",%s)\n",testNum,allTestCase[testId]->_genParameters[testNum].genericFormat,allTestCase[testId]->_genParameters[testNum].dataRepresentation);
|
||||
}
|
||||
|
||||
// Long support for varible type
|
||||
if(allTestCase[testId]->_type == TYPE_VECTOR && !strcmp(allTestCase[testId]->_genParameters[testNum].dataType,"long") && !isLongSupported(device))
|
||||
{
|
||||
log_info( "Long is not supported, test not run.\n" );
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Long support for address in FULL_PROFILE/EMBEDDED_PROFILE
|
||||
bool isLongSupport = true;
|
||||
if(allTestCase[testId]->_type == TYPE_ADDRESS_SPACE && isKernelPFormat(allTestCase[testId],testNum) && !isLongSupported(device))
|
||||
{
|
||||
isLongSupport = false;
|
||||
}
|
||||
|
||||
int err;
|
||||
cl_program program;
|
||||
cl_kernel kernel;
|
||||
cl_mem d_out = NULL;
|
||||
cl_mem d_a = NULL;
|
||||
char _analysisBuffer[ANALYSIS_BUFFER_SIZE];
|
||||
cl_uint out32 = 0;
|
||||
cl_ulong out64 = 0;
|
||||
int fd = -1;
|
||||
|
||||
// Define an index space (global work size) of threads for execution.
|
||||
size_t globalWorkSize[1];
|
||||
|
||||
program = makePrintfProgram(&kernel, context,testId,testNum,isLongSupport,is64bAddressSpace(device));
|
||||
if (!program || !kernel) {
|
||||
++s_test_fail;
|
||||
++s_test_cnt;
|
||||
return -1;
|
||||
}
|
||||
|
||||
//For address space test if there is kernel argument - set it
|
||||
if(allTestCase[testId]->_type == TYPE_ADDRESS_SPACE )
|
||||
{
|
||||
if(isKernelArgument(allTestCase[testId],testNum))
|
||||
// Long support for varible type
|
||||
if (allTestCase[testId]->_type == TYPE_VECTOR
|
||||
&& !strcmp(allTestCase[testId]->_genParameters[testNum].dataType,
|
||||
"long")
|
||||
&& !isLongSupported(device))
|
||||
{
|
||||
int a = 2;
|
||||
d_a = clCreateBuffer(context, CL_MEM_READ_ONLY|CL_MEM_COPY_HOST_PTR,
|
||||
sizeof(int), &a, &err);
|
||||
if(err!= CL_SUCCESS || d_a == NULL) {
|
||||
log_error("clCreateBuffer failed\n");
|
||||
goto exit;
|
||||
}
|
||||
err = clSetKernelArg(kernel, 0, sizeof(cl_mem), &d_a);
|
||||
if(err!= CL_SUCCESS) {
|
||||
log_error("clSetKernelArg failed\n");
|
||||
goto exit;
|
||||
}
|
||||
log_info("Long is not supported, test not run.\n");
|
||||
return 0;
|
||||
}
|
||||
//For address space test if %p is tested
|
||||
if(isKernelPFormat(allTestCase[testId],testNum))
|
||||
{
|
||||
d_out = clCreateBuffer(context, CL_MEM_READ_WRITE,
|
||||
sizeof(cl_ulong), NULL, &err);
|
||||
if(err!= CL_SUCCESS || d_out == NULL) {
|
||||
log_error("clCreateBuffer failed\n");
|
||||
goto exit;
|
||||
}
|
||||
err = clSetKernelArg(kernel, 1, sizeof(cl_mem), &d_out);
|
||||
if(err!= CL_SUCCESS) {
|
||||
log_error("clSetKernelArg failed\n");
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fd = acquireOutputStream(&err);
|
||||
if (err != 0)
|
||||
{
|
||||
log_error("Error while redirection stdout to file");
|
||||
goto exit;
|
||||
}
|
||||
globalWorkSize[0] = 1;
|
||||
cl_event ndrEvt;
|
||||
err = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, globalWorkSize, NULL, 0, NULL,&ndrEvt);
|
||||
if (err != CL_SUCCESS) {
|
||||
// Long support for address in FULL_PROFILE/EMBEDDED_PROFILE
|
||||
bool isLongSupport = true;
|
||||
if (allTestCase[testId]->_type == TYPE_ADDRESS_SPACE
|
||||
&& isKernelPFormat(allTestCase[testId], testNum)
|
||||
&& !isLongSupported(device))
|
||||
{
|
||||
isLongSupport = false;
|
||||
}
|
||||
|
||||
clProgramWrapper program;
|
||||
clKernelWrapper kernel;
|
||||
clMemWrapper d_out;
|
||||
clMemWrapper d_a;
|
||||
char _analysisBuffer[ANALYSIS_BUFFER_SIZE];
|
||||
cl_uint out32 = 0;
|
||||
cl_ulong out64 = 0;
|
||||
int fd = -1;
|
||||
|
||||
// Define an index space (global work size) of threads for execution.
|
||||
size_t globalWorkSize[1];
|
||||
|
||||
program =
|
||||
makePrintfProgram(&kernel, context, testId, testNum, formatNum,
|
||||
isLongSupport, is64bAddressSpace(device));
|
||||
if (!program || !kernel)
|
||||
{
|
||||
++s_test_fail;
|
||||
++s_test_cnt;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// For address space test if there is kernel argument - set it
|
||||
if (allTestCase[testId]->_type == TYPE_ADDRESS_SPACE)
|
||||
{
|
||||
if (isKernelArgument(allTestCase[testId], testNum))
|
||||
{
|
||||
int a = 2;
|
||||
d_a = clCreateBuffer(context,
|
||||
CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
|
||||
sizeof(int), &a, &err);
|
||||
if (err != CL_SUCCESS || d_a == NULL)
|
||||
{
|
||||
log_error("clCreateBuffer failed\n");
|
||||
continue;
|
||||
}
|
||||
err = clSetKernelArg(kernel, 0, sizeof(cl_mem), &d_a);
|
||||
if (err != CL_SUCCESS)
|
||||
{
|
||||
log_error("clSetKernelArg failed\n");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// For address space test if %p is tested
|
||||
if (isKernelPFormat(allTestCase[testId], testNum))
|
||||
{
|
||||
d_out = clCreateBuffer(context, CL_MEM_READ_WRITE,
|
||||
sizeof(cl_ulong), NULL, &err);
|
||||
if (err != CL_SUCCESS || d_out == NULL)
|
||||
{
|
||||
log_error("clCreateBuffer failed\n");
|
||||
continue;
|
||||
}
|
||||
err = clSetKernelArg(kernel, 1, sizeof(cl_mem), &d_out);
|
||||
if (err != CL_SUCCESS)
|
||||
{
|
||||
log_error("clSetKernelArg failed\n");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fd = acquireOutputStream(&err);
|
||||
if (err != 0)
|
||||
{
|
||||
log_error("Error while redirection stdout to file");
|
||||
continue;
|
||||
}
|
||||
globalWorkSize[0] = 1;
|
||||
cl_event ndrEvt;
|
||||
err = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, globalWorkSize,
|
||||
NULL, 0, NULL, &ndrEvt);
|
||||
if (err != CL_SUCCESS)
|
||||
{
|
||||
releaseOutputStream(fd);
|
||||
log_error("\n clEnqueueNDRangeKernel failed errcode:%d\n", err);
|
||||
++s_test_fail;
|
||||
continue;
|
||||
}
|
||||
|
||||
fflush(stdout);
|
||||
err = clFlush(queue);
|
||||
if (err != CL_SUCCESS)
|
||||
{
|
||||
releaseOutputStream(fd);
|
||||
log_error("clFlush failed\n");
|
||||
continue;
|
||||
}
|
||||
// Wait until kernel finishes its execution and (thus) the output
|
||||
// printed from the kernel is immediately printed
|
||||
err = waitForEvent(&ndrEvt);
|
||||
|
||||
releaseOutputStream(fd);
|
||||
log_error("\n clEnqueueNDRangeKernel failed errcode:%d\n", err);
|
||||
++s_test_fail;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
fflush(stdout);
|
||||
err = clFlush(queue);
|
||||
if(err != CL_SUCCESS)
|
||||
{
|
||||
releaseOutputStream(fd);
|
||||
log_error("clFlush failed\n");
|
||||
goto exit;
|
||||
}
|
||||
//Wait until kernel finishes its execution and (thus) the output printed from the kernel
|
||||
//is immediately printed
|
||||
err = waitForEvent(&ndrEvt);
|
||||
|
||||
releaseOutputStream(fd);
|
||||
|
||||
if(err != CL_SUCCESS)
|
||||
{
|
||||
log_error("waitforEvent failed\n");
|
||||
goto exit;
|
||||
}
|
||||
fflush(stdout);
|
||||
|
||||
if(allTestCase[testId]->_type == TYPE_ADDRESS_SPACE && isKernelPFormat(allTestCase[testId],testNum))
|
||||
{
|
||||
// Read the OpenCL output buffer (d_out) to the host output array (out)
|
||||
if(!is64bAddressSpace(device))//32-bit address space
|
||||
if (err != CL_SUCCESS)
|
||||
{
|
||||
clEnqueueReadBuffer(queue, d_out, CL_TRUE, 0, sizeof(cl_int),&out32,
|
||||
0, NULL, NULL);
|
||||
log_error("waitforEvent failed\n");
|
||||
continue;
|
||||
}
|
||||
fflush(stdout);
|
||||
|
||||
if (allTestCase[testId]->_type == TYPE_ADDRESS_SPACE
|
||||
&& isKernelPFormat(allTestCase[testId], testNum))
|
||||
{
|
||||
// Read the OpenCL output buffer (d_out) to the host output array
|
||||
// (out)
|
||||
if (!is64bAddressSpace(device)) // 32-bit address space
|
||||
{
|
||||
clEnqueueReadBuffer(queue, d_out, CL_TRUE, 0, sizeof(cl_int),
|
||||
&out32, 0, NULL, NULL);
|
||||
}
|
||||
else // 64-bit address space
|
||||
{
|
||||
clEnqueueReadBuffer(queue, d_out, CL_TRUE, 0, sizeof(cl_ulong),
|
||||
&out64, 0, NULL, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Get the output printed from the kernel to _analysisBuffer
|
||||
// and verify its correctness
|
||||
getAnalysisBuffer(_analysisBuffer);
|
||||
if (!is64bAddressSpace(device)) // 32-bit address space
|
||||
{
|
||||
if (0
|
||||
!= verifyOutputBuffer(_analysisBuffer, allTestCase[testId],
|
||||
testNum, (cl_ulong)out32))
|
||||
err = ++s_test_fail;
|
||||
}
|
||||
else //64-bit address space
|
||||
{
|
||||
clEnqueueReadBuffer(queue, d_out, CL_TRUE, 0, sizeof(cl_ulong),&out64,
|
||||
0, NULL, NULL);
|
||||
if (0
|
||||
!= verifyOutputBuffer(_analysisBuffer, allTestCase[testId],
|
||||
testNum, out64))
|
||||
err = ++s_test_fail;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
//Get the output printed from the kernel to _analysisBuffer
|
||||
//and verify its correctness
|
||||
getAnalysisBuffer(_analysisBuffer);
|
||||
if(!is64bAddressSpace(device)) //32-bit address space
|
||||
{
|
||||
if(0 != verifyOutputBuffer(_analysisBuffer,allTestCase[testId],testNum,(cl_ulong) out32))
|
||||
err = ++s_test_fail;
|
||||
}
|
||||
else //64-bit address space
|
||||
{
|
||||
if(0 != verifyOutputBuffer(_analysisBuffer,allTestCase[testId],testNum,out64))
|
||||
err = ++s_test_fail;
|
||||
}
|
||||
exit:
|
||||
if(clReleaseKernel(kernel) != CL_SUCCESS)
|
||||
log_error("clReleaseKernel failed\n");
|
||||
if(clReleaseProgram(program) != CL_SUCCESS)
|
||||
log_error("clReleaseProgram failed\n");
|
||||
if(d_out)
|
||||
clReleaseMemObject(d_out);
|
||||
if(d_a)
|
||||
clReleaseMemObject(d_a);
|
||||
++s_test_cnt;
|
||||
return err;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user