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 comparability verification for GL associated devices query #2231

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

shajder
Copy link
Contributor

@shajder shajder commented Jan 17, 2025

Fixes #1485 according to work plan from issue description.

@shajder shajder marked this pull request as ready for review January 20, 2025 10:25
@shajder
Copy link
Contributor Author

shajder commented Jan 20, 2025

I've tested this PR with linux and windows, currently I am not able to launch the test on MacOS - I will appreciate confirmation from this platform.

GLES version does not work for me, neither on ubuntu nor on windows. Is this sample operational ?

Comment on lines 90 to 93
cl_context_properties properties[] = {
CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE,
(cl_context_properties)mShareGroup, 0
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we instead call GetContextProps here?

As-written, if any of the context properties change, we need to make a code change in two places, whereas if we call GetContextProps instead we only need to change one place.

Same goes for win32 and x11 also.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

GetContextProps removed due to the discussion below. List extended with CL_CONTEXT_PLATFORM.

There is still one small confusion worth mentioning I think. Please note that code to setup interoperability context uses first platform on the list of clGetPlatformIDs. I think we could get platform from harness, right?

cl_int init()
{
cl_uint num_platforms = 0;
cl_int error = clGetPlatformIDs(16, nullptr, &num_platforms);
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's just pass zero for num_entries here if platforms is nullptr (I'm surprised this isn't an error):

Suggested change
cl_int error = clGetPlatformIDs(16, nullptr, &num_platforms);
cl_int error = clGetPlatformIDs(0, nullptr, &num_platforms);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Corrected, it was borrowed from other test. I will create separate PR

return CL_SUCCESS;
}

cl_int find(const cl_device_id &id)
Copy link
Contributor

Choose a reason for hiding this comment

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

There's no need to pass the device ID by reference. Additionally, can we return true/false here, vs. assigning some meaning to an "int"?

Suggested change
cl_int find(const cl_device_id &id)
bool find(const cl_device_id id)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Corrected.

num_devices, devices.data(), nullptr);
test_error(error, "clGetDeviceIDs failed");

// try to find invalid device
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment is confusing - I think this is trying to find the passed-in device, not necessarily an "invalid device"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment removed.


// get GL context info function pointer
size_t dev_size = 0;
clGetGLContextInfoKHR_fn GetGLContextInfo =
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's use the name of the function as the function pointer name to avoid confusion.

Suggested change
clGetGLContextInfoKHR_fn GetGLContextInfo =
clGetGLContextInfoKHR_fn clGetGLContextInfoKHR =

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Corrected.

Comment on lines 97 to 102
if (GetGLContextInfo == NULL)
{
log_error("ERROR: clGetGLContextInfoKHR failed! (%s:%d)\n", __FILE__,
__LINE__);
return TEST_FAIL;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We should be able to use test_assert_error here, which already prints the right __FILE__ and __LINE__ information.

Note, the error message should also say something about being unable to get the function pointer for clGetGLContextInfoKHR, not that clGetGLContextInfoKHR failed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Corrected.

Comment on lines 78 to 84
// Create the environment for the test.
GLEnvironment *glEnv = GLEnvironment::Instance();

// get GL environment props
std::vector<cl_context_properties> props;
props.push_back(CL_CONTEXT_PLATFORM);
props.push_back((cl_context_properties)platform);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we query the context properties from the passed-in context from the harness (clGetContextInfo(CL_CONTEXT_PROPERTIES)) vs. trying to re-create the test environment here? This seems a lot simpler, and then we wouldn't need any changes to the setup code, but I'm not sure if that would hurt the test for some reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correction applied as suggested.

}

// comparability test for CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR
test_assert_error(device == devices[0],
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't have easy access to a setup to test this, but if I'm reading the code right, there's no guarantee that device will be equal to the queried devices[0] for a multi-device context, particularly in the X11 case. This is because the context contains all of the devices that support cl_khr_gl_sharing in the platform in the X11 case. The Win32 case is probably OK, but only because the context only contains the "current device for GL context" rather than all devices.

Should the X11 case follow the same logic as the Win32 case, in which case this check would probably be OK?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is because the context contains all of the devices that support cl_khr_gl_sharing in the platform in the X11 case. The Win32 case is probably OK, but only because the context only contains the "current device for GL context" rather than all devices.

Please note that final comparability test is performed agains CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR query result, only one (currently associated with context) device ID should be returned, right ?

@shajder
Copy link
Contributor Author

shajder commented Feb 20, 2025

@bashbaug thanks for your feedback. The confusion around cl_context_properties comes from the differencies in creating context between platforms. Please note that for OSX and X11 existing setup does not use CL_CONTEXT_PLATFORM property to create context. Then, if I will use clGetContextInfo(CL_CONTEXT_PROPERTIES) to collect properties to be used later with clGetGLContextInfoKHR the test fails at my machine. I am aware this is inconsistency either in spec or driver implementation (most probably clGetGLContextInfoKHR implementation in my nvidia driver). Spec for clGetGLContextInfoKHR says:

properties points to an property list whose format and valid contents are identical to the properties argument of clCreateContext

which means your suggestion should work. Now if I extend list of properties for creation of a context with CL_CONTEXT_PLATFORM my X11 setup passes the test so we could try unifying properties list among platforms but I have no OSX device to verify that (thus I separated clCreateContext and clGetGLContextInfoKHR props). Can you do OSX test so I could extend props list with CL_CONTEXT_PLATFORM ?

@bashbaug
Copy link
Contributor

I think this question is in reference to #2231 (comment) - is that correct? If so, note that replying to review comments tends to thread better, and then we can resolve the discussion once it's closed.

This seems like a problem:

Please note that for OSX and X11 existing setup does not use CL_CONTEXT_PLATFORM property to create context.

When CL_CONTEXT_PLATFORM is not specified in the properties, the default platform is "implementation-defined", so if this is working currently then we are getting lucky. It sounds like if we fix this and pass a CL_CONTEXT_PLATFORM then we can use the CL_CONTEXT_PROPERTIES query to make the new test more self-contained, so this definitely gets my vote.

I don't have an OSX system setup to test with. If no other working group members do either, I think we should just do our best, which probably means including the CL_CONTEXT_PLATFORM for OSX as well.

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.

add test for object comparability
3 participants