fix(opencl) prevent sign extension in CL.createPlatformCapabilities#1087
Closed
PeterPan94 wants to merge 1 commit intoLWJGL:masterfrom
Closed
fix(opencl) prevent sign extension in CL.createPlatformCapabilities#1087PeterPan94 wants to merge 1 commit intoLWJGL:masterfrom
PeterPan94 wants to merge 1 commit intoLWJGL:masterfrom
Conversation
CL_DEVICE_TYPE_ALL is defined as the integer 0xFFFF_FFFF = -1. When directly passed to nclGetDeviceIDs, the sign is extended to 0xFFFF_FFFF_FFFF_FFFFl = -1l. As the specification only requires the implementation to accept 0xFFFF_FFFFl, this may lead to nclGetDeviceIDs failing and returning CL_INVALID_DEVICE_TYPE.
Member
|
Hey @PeterPan94, I have changed the constants themselves to I have a plan to avoid such issues in the future, but it requires a refactoring of the generator type system. It's also a prerequisite for LWJGL 4, to migrate constants to value types. Thanks! |
Author
|
Thank you very much for your quick response! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The specification for clGetDeviceIDs allows the implementation to error on any value not explicitly listed.
CL_DEVICE_TYPE_ALLis defined as the integer0xFFFF_FFFF = -1. When directly passed tonclGetDeviceIDs, the sign is extended to0xFFFF_FFFF_FFFF_FFFFl = -1l. As the specification only requires the implementation to accept0xFFFF_FFFFl, this may lead tonclGetDeviceIDsfailing and returningCL_INVALID_DEVICE_TYPE.I encountered this bug using the opencl-mesa drivers on arch linux. This fix only enables
createPlatformCapabilitiesto return successfully. The problem still occurs anytimeCL_DEVICE_TYPE_ALLis passed to(n)clGetDeviceIDs. This can be prevented by the user using the same method as this fix to prevent sign extension. As this isn't ideal, the types ofCL_DEVICE_TYPE_*should probably be changed to long in a release where breaking backwards compatibility is acceptable if possible.An other option would be to trim the upper 32 bits of the long passed to
(n)clGetDeviceIDsto undo the sign extension retroactively, to fix this problem without breaking compatibility. I briefly tried implementing this approach, but was unsure how to approach it, as the java code blocks won't apply tonclGetDeviceIDswhilenativeBeforeCallcreates JNI code and needs to load a library.