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

Adding support for a few built in functions #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

GMKB
Copy link

@GMKB GMKB commented Jul 8, 2020

Built functions added: atomic functions, half math functions, half comparison functions and integer intrinsics. Also handled translation of cudaDeviceSynchronize

@psath
Copy link
Contributor

psath commented Jul 8, 2020

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.
https://www.khronos.org/registry/OpenCL/specs/2.2/html/OpenCL_Ext.html#cl_khr_int64_atomics

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.

@GMKB
Copy link
Author

GMKB commented Jul 12, 2020

Thanks for the quick reply.
I have used DevExtensions variable to forcibly add the respective extensions.

Copy link
Contributor

@psath psath left a comment

Choose a reason for hiding this comment

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

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.)

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.

2 participants