-
Notifications
You must be signed in to change notification settings - Fork 802
SYCL_INTEL_bf16_conversion spec #4237
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
64c375f
SYCL_INTEL_bf16_conversion first draft
AlexeySotkin 6771315
Update SYCL_INTEL_bf16_conversion.asciidoc
AlexeySotkin 8d9066b
Applying review comments
AlexeySotkin a7354b4
Update SYCL_INTEL_bf16_conversion
AlexeySotkin 2134a30
Update SYCL_INTEL_bf16_conversion.asciidoc
AlexeySotkin b2e669d
Update SYCL_INTEL_bf16_conversion.asciidoc
AlexeySotkin 4156f75
Update SYCL_INTEL_bf16_conversion.asciidoc
AlexeySotkin cd6d55c
Update SYCL_INTEL_bf16_conversion.asciidoc
AlexeySotkin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
200 changes: 200 additions & 0 deletions
200
sycl/doc/extensions/Bf16Conversion/SYCL_INTEL_bf16_conversion.asciidoc
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,200 @@ | ||
| = SYCL_INTEL_bf16_conversion | ||
|
|
||
| :source-highlighter: coderay | ||
| :coderay-linenums-mode: table | ||
|
|
||
| // This section needs to be after the document title. | ||
| :doctype: book | ||
| :toc2: | ||
| :toc: left | ||
| :encoding: utf-8 | ||
| :lang: en | ||
|
|
||
| :blank: pass:[ +] | ||
|
|
||
| // Set the default source code type in this document to C++, | ||
| // for syntax highlighting purposes. This is needed because | ||
| // docbook uses c++ and html5 uses cpp. | ||
| :language: {basebackend@docbook:c++:cpp} | ||
|
|
||
| // This is necessary for asciidoc, but not for asciidoctor | ||
| :cpp: C++ | ||
|
|
||
| == Notice | ||
|
|
||
| IMPORTANT: This specification is a draft. | ||
|
|
||
| Copyright (c) 2021 Intel Corporation. All rights reserved. | ||
|
|
||
| NOTE: Khronos(R) is a registered trademark and SYCL(TM) and SPIR(TM) are | ||
| trademarks of The Khronos Group Inc. OpenCL(TM) is a trademark of Apple Inc. | ||
| used by permission by Khronos. | ||
|
|
||
| NOTE: This document is better viewed when rendered as html with asciidoctor. | ||
| GitHub does not render image icons. | ||
|
|
||
| == Dependencies | ||
|
|
||
| This extension is written against the SYCL 2020 specification, Revision 3. | ||
|
|
||
| == Status | ||
|
|
||
| Draft | ||
|
|
||
| This is a preview extension specification, intended to provide early access to | ||
| a feature for review and community feedback. When the feature matures, this | ||
| specification may be released as a formal extension. | ||
|
|
||
| Because the interfaces defined by this specification are not final and are | ||
| subject to change they are not intended to be used by shipping software | ||
| products. | ||
|
|
||
| == Version | ||
|
|
||
| Built On: {docdate} + | ||
AlexeySotkin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Revision: 1 | ||
|
|
||
| == Introduction | ||
|
|
||
| This extension adds functionality to convert value of single-precision | ||
| floating-point type(`float`) to `bfloat16` type and vice versa. The extension | ||
| doesn't add support for `bfloat16` type as such, instead it uses 16-bit integer | ||
| type(`uint16_t`) as a storage for `bfloat16` values. | ||
|
|
||
| The purpose of conversion from float to bfloat16 is to reduce ammount of memory | ||
| required to store floating-point numbers. Computations are expected to be done with | ||
| 32-bit floating-point values. | ||
|
|
||
|
|
||
| == Feature test macro | ||
|
|
||
| This extension provides a feature-test macro as described in the core SYCL | ||
| specification section 6.3.3 "Feature test macros". Therefore, an implementation | ||
| supporting this extension must predefine the macro | ||
| `SYCL_EXT_INTEL_BF16_CONVERSION` to one of the values defined in the table | ||
| below. Applications can test for the existence of this macro to determine if | ||
| the implementation supports this feature, or applications can test the macro’s | ||
| value to determine which of the extension’s APIs the implementation supports. | ||
|
|
||
| [%header,cols="1,5"] | ||
| |=== | ||
| |Value |Description | ||
| |1 |Initial extension version. Base features are supported. | ||
| |=== | ||
|
|
||
| == Extension to `enum class aspect` | ||
|
|
||
| [source] | ||
| ---- | ||
| namespace sycl { | ||
| enum class aspect { | ||
| ... | ||
| ext_intel_bf16_conversion | ||
| } | ||
| } | ||
| ---- | ||
|
|
||
| If a SYCL device has the `ext_intel_bf16_conversion` aspect, then it natively | ||
| supports conversion of values of `float` type to `bfloat16` and back. | ||
|
|
||
| If the device doesn't have the aspect, objects of `bfloat16` class ust not be | ||
AlexeySotkin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| used in the device code. | ||
|
|
||
| == New `bfloat16` class | ||
|
|
||
| The following class provides the conversion functionality: | ||
|
|
||
| [source] | ||
| ---- | ||
| namespace sycl { | ||
| namespace ext { | ||
| namespace intel { | ||
| namespace experimental { | ||
|
|
||
| class [[sycl_detail::uses_aspects(ext_intel_bf16_conversion)]] | ||
AlexeySotkin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| bfloat16 { | ||
AlexeySotkin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| using storage_t = uint16_t; | ||
| storage_t value; | ||
|
|
||
| public: | ||
| // Direct initialization | ||
AlexeySotkin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| bfloat16(const storage_t& a) | ||
|
|
||
| // Convert from float to bfloat16 | ||
| bfloat16(const float& a); | ||
|
|
||
| // Convert from bfloat16 to float | ||
| operator float() const; | ||
|
|
||
| // Get bfloat16 as uint16. | ||
| operator storage_t() const; | ||
| }; | ||
|
|
||
| } // namespace experimental | ||
| } // namespace intel | ||
| } // namespace ext | ||
| } // namespace sycl | ||
| ---- | ||
AlexeySotkin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| == Example | ||
|
|
||
| [source] | ||
| ---- | ||
| bfloat16 operator+(const bfloat16 &lhs, const bfloat16 &rhs) { | ||
| return static_cast<float>(lhs) + static_cast<float>(rhs); | ||
| } | ||
|
|
||
| float foo(float a, float b) { | ||
| // Convert from float to bfloat16. | ||
| bfloat16 A {a}; | ||
| bfloat16 B {b}; | ||
|
|
||
| // Convert A and B from bfloat16 to float, do addition on floating-pointer | ||
AlexeySotkin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // numbers, then convert the result to bfloat16 and store in C. | ||
| bfloat16 C = A + B; | ||
AlexeySotkin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Return the result converted from bfloat16 to float. | ||
| return C; | ||
| } | ||
|
|
||
| int main (int argc, char *argv[]) { | ||
| float data[3] = {7.0, 8.1, 0.0}; | ||
| sycl::device dev{sycl::default_selector{}}; | ||
AlexeySotkin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| sycl::queue deviceQueue{dev}; | ||
| sycl::buffer<float, 1> buf {data, cl::sycl::range<1> {3}}; | ||
AlexeySotkin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| if (dev.has(aspect::ext_intel_bf16_conversion)) { | ||
AlexeySotkin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| deviceQueue.submit ([&] (cl::sycl::handler& cgh) { | ||
AlexeySotkin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| auto numbers = buf.get_access<cl::sycl::access::mode::read_write> (cgh); | ||
AlexeySotkin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| cgh.single_task<class simple_kernel> ([=] () { | ||
| numbers[2] = foo(numbers[0], numbers[1]); | ||
| }); | ||
| }); | ||
| } | ||
| return 0; | ||
| } | ||
| ---- | ||
|
|
||
| == Issues | ||
|
|
||
| None. | ||
|
|
||
| == Revision History | ||
|
|
||
| [cols="5,15,15,70"] | ||
| [grid="rows"] | ||
| [options="header"] | ||
| |======================================== | ||
| |Rev|Date|Author|Changes | ||
| |1|2021-08-02|Alexey Sotkin |*Initial public working draft* | ||
| |======================================== | ||
|
|
||
| //************************************************************************ | ||
| //Other formatting suggestions: | ||
| // | ||
| //* Use *bold* text for host APIs, or [source] syntax highlighting. | ||
| //* Use +mono+ text for device APIs, or [source] syntax highlighting. | ||
| //* Use +mono+ text for extension names, types, or enum values. | ||
| //* Use _italics_ for parameters. | ||
| //************************************************************************ | ||
|
|
||
AlexeySotkin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.