-
Notifications
You must be signed in to change notification settings - Fork 770
[SYCL] Add support for compressed BF16 device lib images in runtime #18108
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 all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
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
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
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,60 @@ | ||
#include <sycl/detail/core.hpp> | ||
#include <sycl/ext/oneapi/bfloat16.hpp> | ||
|
||
using namespace sycl; | ||
|
||
constexpr access::mode sycl_read = access::mode::read; | ||
constexpr access::mode sycl_write = access::mode::write; | ||
|
||
using BFP = sycl::ext::oneapi::bfloat16; | ||
|
||
#ifdef BUILD_LIB | ||
void foo(queue &deviceQueue) { | ||
BFP bf16_v; | ||
float fp32_v = 16.5f; | ||
{ | ||
buffer<float, 1> fp32_buffer{&fp32_v, 1}; | ||
buffer<BFP, 1> bf16_buffer{&bf16_v, 1}; | ||
deviceQueue | ||
.submit([&](handler &cgh) { | ||
auto fp32_acc = fp32_buffer.template get_access<sycl_read>(cgh); | ||
auto bf16_acc = bf16_buffer.template get_access<sycl_write>(cgh); | ||
cgh.single_task([=]() { bf16_acc[0] = BFP{fp32_acc[0]}; }); | ||
}) | ||
.wait(); | ||
} | ||
std::cout << "In foo: " << bf16_v << std::endl; | ||
} | ||
#endif | ||
|
||
#ifdef BUILD_EXE | ||
void foo(queue &deviceQueue); | ||
#endif | ||
|
||
int main() { | ||
BFP bf16_array[3]; | ||
float fp32_array[3] = {7.0f, 8.5f, 0.5f}; | ||
|
||
sycl::queue deviceQueue; | ||
{ | ||
buffer<float, 1> fp32_buffer{fp32_array, 3}; | ||
buffer<BFP, 1> bf16_buffer{bf16_array, 3}; | ||
deviceQueue | ||
.submit([&](handler &cgh) { | ||
auto fp32_acc = fp32_buffer.template get_access<sycl_read>(cgh); | ||
auto bf16_acc = bf16_buffer.template get_access<sycl_write>(cgh); | ||
cgh.single_task([=]() { | ||
bf16_acc[0] = BFP{fp32_acc[0]}; | ||
bf16_acc[1] = BFP{fp32_acc[1]}; | ||
bf16_acc[2] = BFP{fp32_acc[2]}; | ||
}); | ||
}) | ||
.wait(); | ||
} | ||
std::cout << bf16_array[0] << " " << bf16_array[1] << " " << bf16_array[2] | ||
<< std::endl; | ||
#ifdef BUILD_EXE | ||
foo(deviceQueue); | ||
#endif | ||
return 0; | ||
} |
19 changes: 19 additions & 0 deletions
19
sycl/test-e2e/DeviceLib/bfloat16_conversion_test_compress.cpp
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,19 @@ | ||
//==-------------- bf1oat16 devicelib test for SYCL JIT --------------------==// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// Check bfloat16 devicelib device image compression. | ||
|
||
// REQUIRES: linux, zstd | ||
// RUN: %{build} --offload-compress -DBUILD_LIB -fPIC -shared -o %T/lib%basename_t_compress.so | ||
// RUN: %{build} --offload-compress -DBUILD_EXE -L%T -o %t1.out -l%basename_t_compress -Wl,-rpath=%T | ||
// RUN: %{run} %t1.out | ||
|
||
// UNSUPPORTED: target-nvidia || target-amd | ||
// UNSUPPORTED-INTENDED: bfloat16 device library is not used on AMD and Nvidia. | ||
|
||
#include "bfloat16_conversion_test.hpp" |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @jinge90 ,
I'm wondering why do we need to use dynamic RT device image and not a static one (RTDeviceBinaryImage)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, @uditagarwal97
The reason is RTDeviceBinaryImage does not own the sycl_device_binary_struct, which itself does not own the raw binary data (e.g. SPIRV) at sycl_device_binary_struct::BinaryStart. The previous discussion is in: #17461 (comment)
Suppose following scenario, if main program dlopen 2 sycl dynamic library lib1 and lib2, both of them depend on bfloat16 devicelib. SYCL RT calls addImages for lib1 and keeps the required bfloat16 devicelib RTDeviceBinaryImages in program manager's m_Bfloat16DeviceLibImages for further dynamic symbol resolve. Then, SYCL RT loads lib2 and resolves dependent bfloat16 symbols with m_Bfloat16DeviceLibImages. The RTDeviceBinaryImage stored in m_Bfloat16DeviceLibImages is from lib1 and SYCL RT may dlclose lib1 when lib2 device code is still alive. To avoid this, we need to make sure bfloat16 devicelib image is alive during the lifetime of the sycl programs, so we use dynamic device binary image.
I know little about 'CompressedDeviceImage', I think we need to do same thing if the compressed device image may be removed by SYCL RT.
Adding @jopperm for some suggestion.
Thanks very much.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, makes sense then.
CompressedDeviceImage
is same asDynRTDeviceImage
, i.e., it also allocates data on heap but, the former can also handle compressed images.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, @uditagarwal97
Just double confirm, do you mean the CompressedDeviceImage holds the compressed device image which is located on head and it be alive during the whole lifetime of current sycl program? If so, the patch is OK to be merged.
Thanks very much.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After a quick look, my understanding is that
CompressedRTDeviceBinaryImage
owns a copy of the original image'ssycl_device_binary
struct, and it owns the decompressed bytes, so that would be fine 👍There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, just like
DynRTDeviceImage
,CompressedRTDeviceBinaryImage
also owns the device image bytes.