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

Semaphore types bug fixes revised #1822

Merged

Conversation

joshqti
Copy link
Contributor

@joshqti joshqti commented Sep 28, 2023

This PR fixes a number of issues, all of which we need to fix to fully pass.

  • Detect semaphore handle types that are supported by both OpenCL and Vulkan implementations, using API queries. Test all of the detected handle types.

  • Update the clExternalSemaphore class to handle signaling/waiting for SYNC_FD semaphore handle type.

  • Delete obsolete semaphore test for double signal/wait. As per the current version of the spec, this behavior is undefined and cannot be tested.

  • Delete inapplicable clCreateImageWithProperties test cases not related to the semaphore or external memory extensions.

  • Fix error handling. The multi-import tests, and possibly others did not fail when the test result was incorrect

  • Delete dead code in the multi-import external memory tests related to "offset". clExternalMemory had an unused parameter called "offset", deleted all test code directly related to that parameter. Offset is no longer part of the spec.

Joshua Kelly, Qualcomm

Copy link
Contributor

@nikhiljnv nikhiljnv left a comment

Choose a reason for hiding this comment

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

Some early comments.

"Device %u does not support cl_khr_external_memory_opaque_fd, "
"which is required for this test. Skipping\n",
device_no);
continue;
Copy link
Contributor

Choose a reason for hiding this comment

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

What if cl_khr_external_memory_opaque_fd is not present, but some other handle type extension is present (e.g. cl_khr_external_memory_win32)? Consider either removing the check or adding checks for other handle types too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

"Device %u does not support cl_khr_external_memory_opaque_fd, "
"which is required for this test. Skipping\n",
device_no);
continue;
Copy link
Contributor

Choose a reason for hiding this comment

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

What if cl_khr_external_memory_opaque_fd is not present, but some other handle type extension is present (e.g. cl_khr_external_memory_win32)? Consider either removing the check or adding checks for other handle types too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

@nikhiljnv nikhiljnv left a comment

Choose a reason for hiding this comment

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

Some more comments.

all_known_handle_types.push_back(
{ "VK_KHR_external_semaphore_win32",
VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR,
VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_NT });
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any reason why we push opaque_fd, sync_fd and win32 KMT unconditionally, but need to push win32 NT conditionally? If we are anyway going to check against supported handle types later and this is merely a reference for all known handle types, don't see a need to check for Windows version condition here.

Copy link
Contributor Author

@joshqti joshqti Nov 16, 2023

Choose a reason for hiding this comment

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

The original structure of the code used conditional compilation, I tried to maintain the original structure, as I do not understand or have the ability to test windows handles. For example, we still have this code in the test from the original PR:

`
const std::vector
getSupportedVulkanExternalMemoryHandleTypeList()
{
std::vector externalMemoryHandleTypeList;

#if _WIN32
if (IsWindows8OrGreater())
{
externalMemoryHandleTypeList.push_back(
VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_NT);
}
externalMemoryHandleTypeList.push_back(
VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT);
#else
externalMemoryHandleTypeList.push_back(
VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD);
#endif

return externalMemoryHandleTypeList;

}
`

I was unclear on how to query Vulkan for the appropriate handle type. For example, the NT enum is a bitwise or of Vulkan flags:

VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_NT_KMT = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR | VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT_KHR

I am not sure how to interpret this, in the context of querying support from Vulkan for semaphore or memory handles.

Can you advise?

Copy link
Contributor

Choose a reason for hiding this comment

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

Since the test was iterating over all handle types pushed here, it made sense to push them conditionally here earlier so that we don't accidentally test for unsupported handle type based on OS version. Now that we anyway cross check this against supported handle types and use this just as reference of all known handle types, I think we can clean this up and push the types unconditionally.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I enable OPAQUE_WIN32_KMT when either VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR | VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT_KHR are supported? That enum is a bit hard to understand, as it is defined as a bitwise or of two Vulkan types

@@ -1299,38 +1313,29 @@ int test_image_common(cl_device_id device_, cl_context context_,
cl_kernel kernel_unsigned[num_kernels] = { NULL, NULL, NULL, NULL };
Copy link
Contributor

Choose a reason for hiding this comment

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

Since you are at it, can you also initialize program array above to NULL for the sake of consistency and completeness?

// value
SEMAPHORE_PARAM_TEST(CL_SEMAPHORE_REFERENCE_COUNT_KHR, cl_uint, 1);
SEMAPHORE_PARAM_TEST(
CL_SEMAPHORE_EXPORT_HANDLE_TYPES_KHR, cl_uint,
Copy link
Contributor

Choose a reason for hiding this comment

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

A couple of things -

  1. If we are creating semaphore by importing it from Vulkan, export handle types list can be NULL/absent. So, this place doesn't seem about right for me to check for exportable handle types query.
  2. The return type for CL_SEMAPHORE_EXPORT_HANDLE_TYPES_KHR query is cl_external_semaphore_handle_type_khr[], not cl_uint.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. This isn't new code for my change. Lets raise an issue to ensure we properly test this query, I would rather not add a new subtest in this change.

@joshqti
Copy link
Contributor Author

joshqti commented Nov 21, 2023

Pushed patch to address comments

Deleted test cases that are no longer testable
according to the spec.
-Delete obsolete code relating to offsets
-Propagate dedicated memory change
Some subtests did not fail on incorrect result.
Changes to macros to fail, so this does not occur
again.
Test cases are not related to this extension.
Add support for any handle type supported by
the platform.

Change-Id: I6765fde5e7929988f49bfbf2df2f41d5263b6abc
@joshqti joshqti force-pushed the semaphore_types_bug_fixes_revised branch from aa2d3b4 to affaad6 Compare November 28, 2023 00:39
…YPE_OPAQUE_WIN32_NT_KMT as it appears to be redundant.
@joshqti joshqti force-pushed the semaphore_types_bug_fixes_revised branch from affaad6 to 2f83bca Compare November 28, 2023 01:31
Copy link
Contributor

@nikhiljnv nikhiljnv left a comment

Choose a reason for hiding this comment

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

LGTM.

@nikhiljnv
Copy link
Contributor

Merging as agreed in Memory subgroup call on November 28th, 2023.

@nikhiljnv nikhiljnv merged commit f5bd92b into KhronosGroup:main Nov 29, 2023
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants