Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added fp16 and fp64 api consistency tests #2058

Merged
merged 5 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions test_conformance/api/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ test_definition test_list[] = {
ADD_TEST_VERSION(consistency_subgroups, Version(3, 0)),
ADD_TEST_VERSION(consistency_prog_ctor_dtor, Version(3, 0)),
ADD_TEST_VERSION(consistency_3d_image_writes, Version(3, 0)),
ADD_TEST(consistency_requirements_fp64),
ADD_TEST(consistency_requirements_fp16),

ADD_TEST(min_image_formats),
ADD_TEST(set_command_queue_property),
Expand Down
8 changes: 8 additions & 0 deletions test_conformance/api/procs.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,14 @@ extern int test_consistency_3d_image_writes(cl_device_id deviceID,
cl_context context,
cl_command_queue queue,
int num_elements);
extern int test_consistency_requirements_fp64(cl_device_id deviceID,
cl_context context,
cl_command_queue queue,
int num_elements);
extern int test_consistency_requirements_fp16(cl_device_id deviceID,
cl_context context,
cl_command_queue queue,
int num_elements);

extern int test_min_image_formats(cl_device_id deviceID, cl_context context,
cl_command_queue queue, int num_elements);
Expand Down
145 changes: 145 additions & 0 deletions test_conformance/api/test_api_consistency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1151,3 +1151,148 @@ int test_consistency_3d_image_writes(cl_device_id deviceID, cl_context context,

return TEST_PASS;
}

int test_consistency_requirements_fp64(cl_device_id deviceID,
cl_context context,
cl_command_queue queue, int num_elements)
{
cl_int error = CL_SUCCESS;
cl_device_fp_config value = 0;

if (is_extension_available(deviceID, "cl_khr_fp64"))
{
const Version version = get_device_cl_version(deviceID);

error = clGetDeviceInfo(deviceID, CL_DEVICE_DOUBLE_FP_CONFIG,
sizeof(value), &value, nullptr);
test_error(error, "Unable to get device CL_DEVICE_DOUBLE_FP_CONFIG");
test_assert_error(
value > 0, "CL_DEVICE_DOUBLE_FP_CONFIG must return nonzero value");
svenvh marked this conversation as resolved.
Show resolved Hide resolved
if (version < Version(2, 0))
{
test_assert_error(
value
& (CL_FP_FMA | CL_FP_ROUND_TO_NEAREST | CL_FP_ROUND_TO_ZERO
| CL_FP_ROUND_TO_INF | CL_FP_INF_NAN | CL_FP_DENORM),
"Reported double fp config doesn't meet minimum set "
"for OpenCL 1.0, OpenCL 1.1, OpenCL 1.2 devices");
}
else
{
test_assert_error(
value
& (CL_FP_FMA | CL_FP_ROUND_TO_NEAREST | CL_FP_INF_NAN
| CL_FP_DENORM),
"Reported double fp config doesn't meet minimum set "
"for OpenCL 2.0 or newer devices");
}

error =
clGetDeviceInfo(deviceID, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE,
sizeof(value), &value, nullptr);
test_error(
error,
"Unable to get device CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE");
test_assert_error(value > 0,
"CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE must return "
"nonzero value");

error = clGetDeviceInfo(deviceID, CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE,
sizeof(value), &value, nullptr);
test_error(error,
"Unable to get device CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE");
test_assert_error(
value > 0,
"CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE must return nonzero value");
Comment on lines +1200 to +1206
Copy link
Contributor

@bashbaug bashbaug Sep 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we go in with eyes open: this change requires CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE to be non-zero when fp64 is supported. This is true even if there is no "native" double precision support, say when CL_DEVICE_DOUBLE_FP_CONFIG includes CL_FP_SOFT_FLOAT.

No action required, but if we did want to "fix" this, some options might be:

  1. Remove the check entirely - the spec doesn't have any requirements for a value for CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE when fp64 is supported. Note, there is a requirement when fp64 is NOT supported, so this check should not change.
  2. Have the check only when CL_DEVICE_DOUBLE_FP_CONFIG does not include CL_FP_SOFT_FLOAT, since there should be some "native" support in this case.

Same comments also apply to fp16.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed in the October 1st teleconference. We are going to leave this as-is for now. We will revisit in the future, if needed, if a vendor wants to return zero for CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE and still support fp64 for some reason.

}
else
{
error = clGetDeviceInfo(deviceID, CL_DEVICE_DOUBLE_FP_CONFIG,
sizeof(value), &value, nullptr);
test_error(error, "Unable to get device CL_DEVICE_DOUBLE_FP_CONFIG");
test_assert_error(value == 0,
"CL_DEVICE_DOUBLE_FP_CONFIG must return 0");

error =
clGetDeviceInfo(deviceID, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE,
sizeof(value), &value, nullptr);
test_error(
error,
"Unable to get device CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE");
test_assert_error(
value == 0,
"CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE must return 0");

error = clGetDeviceInfo(deviceID, CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE,
sizeof(value), &value, nullptr);
test_error(error,
"Unable to get device CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE");
test_assert_error(value == 0,
"CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE must return 0");
}

return TEST_PASS;
}

int test_consistency_requirements_fp16(cl_device_id deviceID,
cl_context context,
cl_command_queue queue, int num_elements)
{
cl_int error = CL_SUCCESS;
cl_device_fp_config value = 0;

if (is_extension_available(deviceID, "cl_khr_fp16"))
{
error = clGetDeviceInfo(deviceID, CL_DEVICE_HALF_FP_CONFIG,
sizeof(value), &value, nullptr);
test_error(error, "Unable to get device CL_DEVICE_HALF_FP_CONFIG");
test_assert_error(value > 0,
"CL_DEVICE_HALF_FP_CONFIG must return nonzero value");

test_assert_error((value & (CL_FP_ROUND_TO_NEAREST | CL_FP_INF_NAN))
|| (value & CL_FP_ROUND_TO_ZERO),
"Reported half fp config doesn't meet minimum set");

error = clGetDeviceInfo(deviceID, CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF,
sizeof(value), &value, nullptr);
test_error(
error,
"Unable to get device CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF");
test_assert_error(value > 0,
"CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF must return "
"nonzero value");

error = clGetDeviceInfo(deviceID, CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF,
sizeof(value), &value, nullptr);
test_error(error,
"Unable to get device CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF");
test_assert_error(
value > 0,
"CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF must return nonzero value");
}
else
{
error = clGetDeviceInfo(deviceID, CL_DEVICE_HALF_FP_CONFIG,
sizeof(value), &value, nullptr);
test_error(error, "Unable to get device CL_DEVICE_HALF_FP_CONFIG");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This requires implementations without the cl_khr_fp16 extension to recognise CL_DEVICE_HALF_FP_CONFIG, but support for CL_DEVICE_HALF_FP_CONFIG is only required if that extension is available, is it not? https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_API.html#CL_DEVICE_HALF_FP_CONFIG says "provided by the cl_khr_fp16 extension". Our implementation, when FP16 support is disabled, returns CL_INVALID_VALUE here rather than setting value to 0, and I think that is correct, since the spec also says it returns:

CL_INVALID_VALUE if param_name is not one of the supported values or if size in bytes specified by param_value_size is < size of return type as specified in the Device Queries table and param_value is not a NULL value or if param_name is a value that is available as an extension and the corresponding extension is not supported by the device.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hvdijk I agree with your analysis. CL_DEVICE_HALF_FP_CONFIG is provided by the cl_khr_fp16 extension, so if that extension is not supported the query should return CL_INVALID_VALUE indeed.

(the half query seems different from CL_DEVICE_DOUBLE_FP_CONFIG, which does not have a "provided by" clause)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, created #2108 to change that.

test_assert_error(value == 0, "CL_DEVICE_HALF_FP_CONFIG must return 0");

error = clGetDeviceInfo(deviceID, CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF,
sizeof(value), &value, nullptr);
test_error(
error,
"Unable to get device CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF");
test_assert_error(value == 0,
"CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF must return "
"0");

error = clGetDeviceInfo(deviceID, CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF,
sizeof(value), &value, nullptr);
test_error(error,
"Unable to get device CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF");
test_assert_error(value == 0,
"CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF must return 0");
}

return TEST_PASS;
}
Loading