Skip to content

Commit

Permalink
Added printf test for double type cases (KhronosGroup#2022)
Browse files Browse the repository at this point in the history
according to work plan for issue
KhronosGroup#1058
  • Loading branch information
shajder authored Aug 27, 2024
1 parent 6cbe8ca commit 0a00a1f
Show file tree
Hide file tree
Showing 5 changed files with 309 additions and 58 deletions.
29 changes: 13 additions & 16 deletions test_common/harness/kernelHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1511,30 +1511,27 @@ size_t get_min_alignment(cl_context context)
return align_size;
}

cl_device_fp_config get_default_rounding_mode(cl_device_id device,
const cl_uint &param)
cl_device_fp_config get_default_rounding_mode(const cl_device_id device,
const cl_uint param)
{
if (param == CL_DEVICE_DOUBLE_FP_CONFIG)
test_error_ret(
-1,
"FAILURE: CL_DEVICE_DOUBLE_FP_CONFIG not supported by this routine",
0);

char profileStr[128] = "";
cl_device_fp_config single = 0;
int error = clGetDeviceInfo(device, param, sizeof(single), &single, NULL);
cl_device_fp_config config = 0;
int error = clGetDeviceInfo(device, param, sizeof(config), &config, NULL);
if (error)
{
std::string message = std::string("Unable to get device ")
+ std::string(param == CL_DEVICE_HALF_FP_CONFIG
? "CL_DEVICE_HALF_FP_CONFIG"
: "CL_DEVICE_SINGLE_FP_CONFIG");
std::string config_name = "CL_DEVICE_SINGLE_FP_CONFIG";
if (param == CL_DEVICE_HALF_FP_CONFIG)
config_name = "CL_DEVICE_HALF_FP_CONFIG";
else if (param == CL_DEVICE_DOUBLE_FP_CONFIG)
config_name = "CL_DEVICE_DOUBLE_FP_CONFIG";
std::string message =
std::string("Unable to get device ") + config_name;
test_error_ret(error, message.c_str(), 0);
}

if (single & CL_FP_ROUND_TO_NEAREST) return CL_FP_ROUND_TO_NEAREST;
if (config & CL_FP_ROUND_TO_NEAREST) return CL_FP_ROUND_TO_NEAREST;

if (0 == (single & CL_FP_ROUND_TO_ZERO))
if (0 == (config & CL_FP_ROUND_TO_ZERO))
test_error_ret(-1,
"FAILURE: device must support either "
"CL_FP_ROUND_TO_ZERO or CL_FP_ROUND_TO_NEAREST",
Expand Down
4 changes: 2 additions & 2 deletions test_common/harness/kernelHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ size_t get_min_alignment(cl_context context);
/* Helper to obtain the default rounding mode for single precision computation.
* (Double is always CL_FP_ROUND_TO_NEAREST.) Returns 0 on error. */
cl_device_fp_config
get_default_rounding_mode(cl_device_id device,
const cl_uint &param = CL_DEVICE_SINGLE_FP_CONFIG);
get_default_rounding_mode(const cl_device_id device,
const cl_uint param = CL_DEVICE_SINGLE_FP_CONFIG);

#define PASSIVE_REQUIRE_IMAGE_SUPPORT(device) \
if (checkForImageSupport(device)) \
Expand Down
52 changes: 41 additions & 11 deletions test_conformance/printf/test_printf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,15 @@ int doTest(cl_command_queue queue, cl_context context,
return TEST_SKIPPED_ITSELF;
}

if ((allTestCase[testId]->_type == TYPE_DOUBLE
|| allTestCase[testId]->_type == TYPE_DOUBLE_LIMITS)
&& !is_extension_available(device, "cl_khr_fp64"))
{
log_info("Skipping double because cl_khr_fp64 extension is not "
"supported.\n");
return TEST_SKIPPED_ITSELF;
}

auto& genParams = allTestCase[testId]->_genParameters;

auto fail_count = s_test_fail;
Expand All @@ -708,18 +717,25 @@ int doTest(cl_command_queue queue, cl_context context,
{
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");
auto is_vector_type_supported = [&](const char* type_name,
const char* ext_name) {
if ((strcmp(genParams[testNum].dataType, type_name) == 0)
&& !is_extension_available(device, ext_name))
{
log_info("Skipping %s because %s extension "
"is not supported.\n",
type_name, ext_name);

s_test_skip++;
s_test_cnt++;
continue;
}
s_test_skip++;
s_test_cnt++;
return false;
}
return true;
};

if (!is_vector_type_supported("half", "cl_khr_fp16")) continue;

if (!is_vector_type_supported("double", "cl_khr_fp64")) continue;

// Long support for varible type
if (!strcmp(allTestCase[testId]->_genParameters[testNum].dataType,
Expand Down Expand Up @@ -935,6 +951,18 @@ int test_float_limits(cl_device_id deviceID, cl_context context,
return doTest(gQueue, gContext, TYPE_FLOAT_LIMITS, deviceID);
}

int test_double(cl_device_id deviceID, cl_context context,
cl_command_queue queue, int num_elements)
{
return doTest(gQueue, gContext, TYPE_DOUBLE, deviceID);
}

int test_double_limits(cl_device_id deviceID, cl_context context,
cl_command_queue queue, int num_elements)
{
return doTest(gQueue, gContext, TYPE_DOUBLE_LIMITS, deviceID);
}

int test_octal(cl_device_id deviceID, cl_context context,
cl_command_queue queue, int num_elements)
{
Expand Down Expand Up @@ -1020,6 +1048,8 @@ test_definition test_list[] = {
ADD_TEST(half_limits),
ADD_TEST(float),
ADD_TEST(float_limits),
ADD_TEST(double),
ADD_TEST(double_limits),
ADD_TEST(octal),
ADD_TEST(unsigned),
ADD_TEST(hexadecimal),
Expand Down
3 changes: 3 additions & 0 deletions test_conformance/printf/test_printf.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ enum PrintfTestType
TYPE_HALF_LIMITS,
TYPE_FLOAT,
TYPE_FLOAT_LIMITS,
TYPE_DOUBLE,
TYPE_DOUBLE_LIMITS,
TYPE_OCTAL,
TYPE_UNSIGNED,
TYPE_HEXADEC,
Expand Down Expand Up @@ -80,6 +82,7 @@ struct printDataGenParameters
static std::vector<std::string> correctBufferInt;
static std::vector<std::string> correctBufferHalf;
static std::vector<std::string> correctBufferFloat;
static std::vector<std::string> correctBufferDouble;
static std::vector<std::string> correctBufferOctal;
static std::vector<std::string> correctBufferUnsigned;
static std::vector<std::string> correctBufferHexadecimal;
Expand Down
Loading

0 comments on commit 0a00a1f

Please sign in to comment.