Skip to content

Added test to verify API consistency when linker or compiler unavailable#2630

Open
shajder wants to merge 2 commits intoKhronosGroup:mainfrom
shajder:api_consistency_missing_compiler_linker
Open

Added test to verify API consistency when linker or compiler unavailable#2630
shajder wants to merge 2 commits intoKhronosGroup:mainfrom
shajder:api_consistency_missing_compiler_linker

Conversation

@shajder
Copy link
Contributor

@shajder shajder commented Mar 5, 2026

Fixes #955

@kpet @bashbaug I've noticed procedure clBuildProgram does not return CL_LINKER_NOT_AVAILABLE, only CL_COMPILER_NOT_AVAILABLE. Is this intentional ? What if compiler is available but linker isn't ? Should it still return CL_COMPILER_NOT_AVAILABLE ? Thanks

Comment on lines +971 to +975
if (!compilerAvail)
{
cl_uint specConst = 42;
error = clSetProgramSpecializationConstant(
program, 0, sizeof(specConst), &specConst);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you describe what this case is testing in more detail?

If we get here there's something in the string returned by CL_DEVICE_IL_VERSION or the array returned by CL_DEVICE_ILS_WITH_VERSION, so it would be odd to return that a compiler is unavailable. If anything, it seems like we should test that a compiler is available in this case, otherwise how would you compile the programs created from a supported IL?

Regardless, we haven't created program for the call to clSetProgramSpecializationConstant, so I think we would need to accept CL_INVALID_PROGRAM or a bunch of other error conditions, not just CL_COMPILER_NOT_AVAILABLE.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, thanks for pointing that out. I tried to create a scenario where clSetProgramSpecializationConstant returns CL_COMPILER_NOT_AVAILABLE, which currently isn’t covered by the CTS. However, you’re right that the program should first be created with clCreateProgramWithIL.

I can’t find an appropriate test that covers the scenario (CL_COMPILER_NOT_AVAILABLE + clCreateProgramWithIL), so this will probably need to be handled as a separate issue/PR.


REGISTER_TEST(consistency_missing_compiler)
{
cl_bool compilerAvail = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick - same type of code occurs in a few other places, also:

Suggested change
cl_bool compilerAvail = true;
cl_bool compilerAvail = CL_TRUE;

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

Comment on lines +1047 to +1050
if (linkerAvail || !compilerAvail)
{
log_info("Can't perform linker consistency check\n");
return TEST_SKIPPED_ITSELF;
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be an error. Both the full profile and the embedded profile say for CL_DEVICE_LINKER_AVAILABLE:

This must be CL_TRUE if CL_DEVICE_COMPILER_AVAILABLE is CL_TRUE.

I think it would be fine to skip this test if CL_DEVICE_COMPILER_AVAILABLE is CL_FALSE, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed test for CL_DEVICE_COMPILER_AVAILABLE

Comment on lines +1009 to +1013
size_t line_length = strlen(sample_kernel);

/* New OpenCL API only has one entry point, so go ahead and just try it */
clProgramWrapper program = clCreateProgramWithSource(
context, 1, &sample_kernel, &line_length, &err);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpicks:

  1. This seems like a weird and confusing (and copy-pasted) comment. Can we just remove it?
  2. Since sample_kernel is NUL-terminated, we can just pass nullptr for lengths, vs. calling strlen explicitly.

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

@bashbaug
Copy link
Contributor

I've noticed procedure clBuildProgram does not return CL_LINKER_NOT_AVAILABLE, only CL_COMPILER_NOT_AVAILABLE. Is this intentional ? What if compiler is available but linker isn't ? Should it still return CL_COMPILER_NOT_AVAILABLE ?

This is historical.

clCompileProgram, clLinkProgram, and CL_DEVICE_LINKER_AVAILABLE were added in OpenCL 1.2. Prior to OpenCL 1.2, you could only call clBuildProgram, and you could query CL_DEVICE_COMPILER_AVAILABLE to determine if a compiler was available and hence you could compile your OpenCL programs.

This behavior was carried forward into OpenCL 1.2 and beyond, so clBuildProgram only cares whether CL_DEVICE_COMPILER_AVAILABLE is CL_TRUE or not, and if it is not, the error code that is returned is CL_COMPILER_NOT_AVAILABLE. Same goes for clCompileProgram. The only API that can return CL_LINKER_NOT_AVAILABLE is clLinkProgram, and only when CL_DEVICE_LINKER_AVAILABLE is CL_FALSE.

@shajder
Copy link
Contributor Author

shajder commented Mar 11, 2026

This is historical.
...

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing compiler optionality consistency tests

2 participants