mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-19 06:09:01 +00:00
Added cl_half support for test_printf (#1622)
* Added support to test half floats with printf calls (issue #142, printf) * Added corrections related to rounding and casting halfs (issue #142, printf) * Reusing similar function (issue #142, printf) * Corrected path without cl_khr_fp16 support (issue #142, printf) * Cosmetic fix for order of vector tests (issue #142, printf) * Added correction related to vendor test review (issue #142, printf)
This commit is contained in:
@@ -13,7 +13,6 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#include "harness/compat.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
@@ -40,7 +39,6 @@
|
||||
#include "harness/testHarness.h"
|
||||
#include "harness/errorHelpers.h"
|
||||
#include "harness/kernelHelpers.h"
|
||||
#include "harness/mt19937.h"
|
||||
#include "harness/parseParameters.h"
|
||||
|
||||
#include <CL/cl_ext.h>
|
||||
@@ -237,10 +235,13 @@ static cl_program makePrintfProgram(cl_kernel *kernel_ptr, const cl_context cont
|
||||
char testname[256] = {0};
|
||||
char addrSpaceArgument[256] = {0};
|
||||
char addrSpacePAddArgument[256] = {0};
|
||||
char extension[128] = { 0 };
|
||||
|
||||
//Program Source code for int,float,octal,hexadecimal,char,string
|
||||
const char *sourceGen[] = {
|
||||
"__kernel void ", testname,
|
||||
const char* sourceGen[] = {
|
||||
extension,
|
||||
"__kernel void ",
|
||||
testname,
|
||||
"(void)\n",
|
||||
"{\n"
|
||||
" printf(\"",
|
||||
@@ -251,8 +252,10 @@ static cl_program makePrintfProgram(cl_kernel *kernel_ptr, const cl_context cont
|
||||
"}\n"
|
||||
};
|
||||
//Program Source code for vector
|
||||
const char *sourceVec[] = {
|
||||
"__kernel void ", testname,
|
||||
const char* sourceVec[] = {
|
||||
extension,
|
||||
"__kernel void ",
|
||||
testname,
|
||||
"(void)\n",
|
||||
"{\n",
|
||||
allTestCase[testId]->_genParameters[testNum].dataType,
|
||||
@@ -289,6 +292,11 @@ static cl_program makePrintfProgram(cl_kernel *kernel_ptr, const cl_context cont
|
||||
//Update testname
|
||||
sprintf(testname,"%s%d","test",testId);
|
||||
|
||||
if (allTestCase[testId]->_type == TYPE_HALF
|
||||
|| allTestCase[testId]->_type == TYPE_HALF_LIMITS)
|
||||
strcpy(extension, "#pragma OPENCL EXTENSION cl_khr_fp16 : enable\n");
|
||||
|
||||
|
||||
//Update addrSpaceArgument and addrSpacePAddArgument types, based on FULL_PROFILE/EMBEDDED_PROFILE
|
||||
if(allTestCase[testId]->_type == TYPE_ADDRESS_SPACE)
|
||||
{
|
||||
@@ -304,6 +312,12 @@ static cl_program makePrintfProgram(cl_kernel *kernel_ptr, const cl_context cont
|
||||
|
||||
if(allTestCase[testId]->_type == TYPE_VECTOR)
|
||||
{
|
||||
if (strcmp(allTestCase[testId]->_genParameters[testNum].dataType,
|
||||
"half")
|
||||
== 0)
|
||||
strcpy(extension,
|
||||
"#pragma OPENCL EXTENSION cl_khr_fp16 : enable\n");
|
||||
|
||||
err = create_single_kernel_helper(
|
||||
context, &program, kernel_ptr,
|
||||
sizeof(sourceVec) / sizeof(sourceVec[0]), sourceVec, testname);
|
||||
@@ -404,8 +418,27 @@ static bool is64bAddressSpace(cl_device_id device_id)
|
||||
//-----------------------------------------
|
||||
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"))
|
||||
{
|
||||
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)
|
||||
&& !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);
|
||||
}
|
||||
@@ -614,6 +647,75 @@ int test_int_8(cl_device_id deviceID, cl_context context, cl_command_queue queue
|
||||
}
|
||||
|
||||
|
||||
int test_half_0(cl_device_id deviceID, cl_context context,
|
||||
cl_command_queue queue, int num_elements)
|
||||
{
|
||||
return doTest(gQueue, gContext, TYPE_HALF, 0, deviceID);
|
||||
}
|
||||
int test_half_1(cl_device_id deviceID, cl_context context,
|
||||
cl_command_queue queue, int num_elements)
|
||||
{
|
||||
return doTest(gQueue, gContext, TYPE_HALF, 1, deviceID);
|
||||
}
|
||||
int test_half_2(cl_device_id deviceID, cl_context context,
|
||||
cl_command_queue queue, int num_elements)
|
||||
{
|
||||
return doTest(gQueue, gContext, TYPE_HALF, 2, deviceID);
|
||||
}
|
||||
int test_half_3(cl_device_id deviceID, cl_context context,
|
||||
cl_command_queue queue, int num_elements)
|
||||
{
|
||||
return doTest(gQueue, gContext, TYPE_HALF, 3, deviceID);
|
||||
}
|
||||
int test_half_4(cl_device_id deviceID, cl_context context,
|
||||
cl_command_queue queue, int num_elements)
|
||||
{
|
||||
return doTest(gQueue, gContext, TYPE_HALF, 4, deviceID);
|
||||
}
|
||||
int test_half_5(cl_device_id deviceID, cl_context context,
|
||||
cl_command_queue queue, int num_elements)
|
||||
{
|
||||
return doTest(gQueue, gContext, TYPE_HALF, 5, deviceID);
|
||||
}
|
||||
int test_half_6(cl_device_id deviceID, cl_context context,
|
||||
cl_command_queue queue, int num_elements)
|
||||
{
|
||||
return doTest(gQueue, gContext, TYPE_HALF, 6, deviceID);
|
||||
}
|
||||
int test_half_7(cl_device_id deviceID, cl_context context,
|
||||
cl_command_queue queue, int num_elements)
|
||||
{
|
||||
return doTest(gQueue, gContext, TYPE_HALF, 7, deviceID);
|
||||
}
|
||||
int test_half_8(cl_device_id deviceID, cl_context context,
|
||||
cl_command_queue queue, int num_elements)
|
||||
{
|
||||
return doTest(gQueue, gContext, TYPE_HALF, 8, deviceID);
|
||||
}
|
||||
int test_half_9(cl_device_id deviceID, cl_context context,
|
||||
cl_command_queue queue, int num_elements)
|
||||
{
|
||||
return doTest(gQueue, gContext, TYPE_HALF, 9, deviceID);
|
||||
}
|
||||
|
||||
|
||||
int test_half_limits_0(cl_device_id deviceID, cl_context context,
|
||||
cl_command_queue queue, int num_elements)
|
||||
{
|
||||
return doTest(gQueue, gContext, TYPE_HALF_LIMITS, 0, deviceID);
|
||||
}
|
||||
int test_half_limits_1(cl_device_id deviceID, cl_context context,
|
||||
cl_command_queue queue, int num_elements)
|
||||
{
|
||||
return doTest(gQueue, gContext, TYPE_HALF_LIMITS, 1, deviceID);
|
||||
}
|
||||
int test_half_limits_2(cl_device_id deviceID, cl_context context,
|
||||
cl_command_queue queue, int num_elements)
|
||||
{
|
||||
return doTest(gQueue, gContext, TYPE_HALF_LIMITS, 2, deviceID);
|
||||
}
|
||||
|
||||
|
||||
int test_float_0(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements)
|
||||
{
|
||||
return doTest(gQueue, gContext, TYPE_FLOAT, 0, deviceID);
|
||||
@@ -800,6 +902,11 @@ int test_vector_4(cl_device_id deviceID, cl_context context, cl_command_queue qu
|
||||
{
|
||||
return doTest(gQueue, gContext, TYPE_VECTOR, 4, deviceID);
|
||||
}
|
||||
int test_vector_5(cl_device_id deviceID, cl_context context,
|
||||
cl_command_queue queue, int num_elements)
|
||||
{
|
||||
return doTest(gQueue, gContext, TYPE_VECTOR, 5, deviceID);
|
||||
}
|
||||
|
||||
|
||||
int test_address_space_0(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements)
|
||||
@@ -855,6 +962,15 @@ test_definition test_list[] = {
|
||||
ADD_TEST(int_6), ADD_TEST(int_7),
|
||||
ADD_TEST(int_8),
|
||||
|
||||
ADD_TEST(half_0), ADD_TEST(half_1),
|
||||
ADD_TEST(half_2), ADD_TEST(half_3),
|
||||
ADD_TEST(half_4), ADD_TEST(half_5),
|
||||
ADD_TEST(half_6), ADD_TEST(half_7),
|
||||
ADD_TEST(half_8), ADD_TEST(half_9),
|
||||
|
||||
ADD_TEST(half_limits_0), ADD_TEST(half_limits_1),
|
||||
ADD_TEST(half_limits_2),
|
||||
|
||||
ADD_TEST(float_0), ADD_TEST(float_1),
|
||||
ADD_TEST(float_2), ADD_TEST(float_3),
|
||||
ADD_TEST(float_4), ADD_TEST(float_5),
|
||||
@@ -885,7 +1001,7 @@ test_definition test_list[] = {
|
||||
|
||||
ADD_TEST(vector_0), ADD_TEST(vector_1),
|
||||
ADD_TEST(vector_2), ADD_TEST(vector_3),
|
||||
ADD_TEST(vector_4),
|
||||
ADD_TEST(vector_4), ADD_TEST(vector_5),
|
||||
|
||||
ADD_TEST(address_space_0), ADD_TEST(address_space_1),
|
||||
ADD_TEST(address_space_2), ADD_TEST(address_space_3),
|
||||
@@ -1056,6 +1172,24 @@ test_status InitCL( cl_device_id device )
|
||||
|
||||
releaseOutputStream(gFd);
|
||||
|
||||
if (is_extension_available(device, "cl_khr_fp16"))
|
||||
{
|
||||
const cl_device_fp_config fpConfigHalf =
|
||||
get_default_rounding_mode(device, CL_DEVICE_HALF_FP_CONFIG);
|
||||
if (fpConfigHalf == CL_FP_ROUND_TO_NEAREST)
|
||||
{
|
||||
half_rounding_mode = CL_HALF_RTE;
|
||||
}
|
||||
else if (fpConfigHalf == CL_FP_ROUND_TO_ZERO)
|
||||
{
|
||||
half_rounding_mode = CL_HALF_RTZ;
|
||||
}
|
||||
else
|
||||
{
|
||||
log_error("Error while acquiring half rounding mode");
|
||||
}
|
||||
}
|
||||
|
||||
// Generate reference results
|
||||
generateRef(device);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user