Adding support for a few built in functions#8
Conversation
|
Thanks for the PR. If any of the half precision functions are detected, you need to forcibly add the cl_khr_fp16 extension to the top of the generated kernel file. (Ideally, any of the half precision functions that weren't introduced until later OpenCL versions would also be ifdefd on the corresponding CL_VERSION__ macro.) https://www.khronos.org/registry/OpenCL/specs/2.2/html/OpenCL_Ext.html#cl_khr_fp16 Atomic functions also need to check the type of the operands and use the atom_ 64bit versions if either is a long or ulong, and forcibly add the corresponding cl_khr_int64_base/extended_atomics extension. IIRC the "DevPreamble" variable can be used to inject these, but it's been a while since I looked that closely at kernel file generation. |
|
Thanks for the quick reply. |
psath
left a comment
There was a problem hiding this comment.
As written this will add a pragma line each time a half-precision function is encountered (even if it is the same function used in multiple places). This will not (and should not) be handled by the deduplication code since the entire DevPreamble is being added as a single monolithic Replacement.
A direct fix is to maintain a flag for each kernel TranslationUnit, defaulting to false, so that the pragma can only be added IFF a half-precision function is encountered while the flag is false. (Then immediately set it to true after emitting the pragma the first time.)
Built functions added: atomic functions, half math functions, half comparison functions and integer intrinsics. Also handled translation of cudaDeviceSynchronize