Skip to content

Conversation

AlexeySachkov
Copy link
Contributor

Moved declaration of the built-in from compiler to header files, in
order to add a switch (through macro) between two versions of the
built-in: variadic and non-variadic one.

The problem with variadic version is that it follows C++ argument
promotion rules and replaces all floats with doubles, which doesn't look
good on HW, which doesn't support doubles.

Due to the fact, that we don't know the target HW in advance, we can't
selectively disable argument promotion for only some targets and doing
so will look like a hack anyway.

Therefore, a non-variadic version is introduced, which allows to avoid
argument promotion without any further changes to the compiler (and
thus, not affecting other variadic functions).

Encountering such printf call without argument promotion performed
should not be a surprise for a backend which consumes SPIR-V, because
SPIR-V instruction for printf is not variadic, all argument types are
statically known and it is legal to have both floats and doubles as
arguments at the same time. However, there is no certainty yet in proper
support of that instruction in backends: they were mostly designed for
OpenCL, where we either have argument promotion or don't have it, but
not encountering a mixed case.

Because of that, the new version is put under a macro for now, which
allows to experiment with it without disrupting existing applications
using printf.

Moved declaration of the built-in from compiler to header files, in
order to add a switch (through macro) between two versions of the
built-in: variadic and non-variadic one.

The problem with variadic version is that it follows C++ argument
promotion rules and replaces all floats with doubles, which doesn't look
good on HW, which doesn't support doubles.

Due to the fact, that we don't know the target HW in advance, we can't
selectively disable argument promotion for only some targets and doing
so will look like a hack anyway.

Therefore, a non-variadic version is introduced, which allows to avoid
argument promotion without any further changes to the compiler (and
thus, not affecting other variadic functions).

Encountering such `printf` call without argument promotion performed
should not be a surprise for a backend which consumes SPIR-V, because
SPIR-V instruction for `printf` is not variadic, all argument types are
statically known and it is legal to have both floats and doubles as
arguments at the same time. However, there is no certainty yet in proper
support of that instruction in backends: they were mostly designed for
OpenCL, where we either have argument promotion or don't have it, but
not encountering a mixed case.

Because of that, the new version is put under a macro for now, which
allows to experiment with it without disrupting existing applications
using `printf`.
@AlexeySachkov AlexeySachkov marked this pull request as ready for review October 20, 2021 09:41
Copy link
Contributor

@smanna12 smanna12 left a comment

Choose a reason for hiding this comment

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

FE change looks good to me.

Copy link
Contributor

@premanandrao premanandrao left a comment

Choose a reason for hiding this comment

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

FE changes look okay to me.

@AlexeySachkov
Copy link
Contributor Author

@intel/llvm-reviewers-runtime, could you please take a look?

@AlexeySachkov AlexeySachkov merged commit 24eb1ab into intel:sycl Oct 21, 2021
@AlexeySachkov AlexeySachkov deleted the private/asachkov/non-variadic-spriv-ocl-printf branch May 22, 2024 09:50
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.

4 participants