This repository was archived by the owner on Mar 28, 2023. It is now read-only.
forked from llvm/llvm-test-suite
-
Notifications
You must be signed in to change notification settings - Fork 130
[SYCL] Add bfloat16 'hello world' host test. #1189
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3650f3b
[SYCL] Add bfloat16 'hello world' host test.
kbobrovs a27450b
Add missing return to function.
kbobrovs 92c8e96
clang-format
kbobrovs b3e3072
Update SYCL/BFloat16/bfloat_hw.cpp
kbobrovs b606499
Update SYCL/BFloat16/bfloat_hw.cpp
kbobrovs d0b7357
address review comments
kbobrovs ff4502e
Update SYCL/BFloat16/bfloat_hw.cpp
kbobrovs 4db1c0b
Apply suggestions from code review
kbobrovs f5751bd
Update SYCL/BFloat16/bfloat_hw.cpp
kbobrovs 7fa1850
Merge remote-tracking branch 'intel/intel' into bfloat16_fix
kbobrovs 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// RUN: %clangxx -fsycl %s -o %t.out | ||
// RUN: %t.out | ||
|
||
// "Hello world" bfloat16 test which checks conversion algorithms on host. | ||
|
||
#include <sycl/sycl.hpp> | ||
|
||
#include <cstdint> | ||
#include <type_traits> | ||
|
||
template <size_t Size> | ||
using get_uint_type_of_size = typename std::conditional_t< | ||
Size == 1, uint8_t, | ||
std::conditional_t< | ||
Size == 2, uint16_t, | ||
std::conditional_t<Size == 4, uint32_t, | ||
std::conditional_t<Size == 8, uint64_t, void>>>>; | ||
|
||
using bfloat16 = sycl::ext::oneapi::experimental::bfloat16; | ||
using Bfloat16StorageT = get_uint_type_of_size<sizeof(bfloat16)>; | ||
|
||
bool test(float Val, Bfloat16StorageT Bits) { | ||
std::cout << "Value: " << Val << " Bits: " << std::hex << "0x" << Bits | ||
<< std::dec << "...\n"; | ||
bool Passed = true; | ||
{ | ||
std::cout << " float -> bfloat16 conversion ..."; | ||
Bfloat16StorageT RawVal = sycl::bit_cast<Bfloat16StorageT>(bfloat16(Val)); | ||
bool Res = (RawVal == Bits); | ||
Passed &= Res; | ||
|
||
if (Res) { | ||
std::cout << "passed\n"; | ||
} else { | ||
std::cout << "failed. " << std::hex << "0x" << RawVal << " != " | ||
<< "0x" << Bits << "(gold)\n" | ||
<< std::dec; | ||
} | ||
} | ||
{ | ||
std::cout << " bfloat16 -> float conversion ..."; | ||
float NewVal = static_cast<float>(sycl::bit_cast<bfloat16>(Bits)); | ||
bool Res = (NewVal == Val); | ||
Passed &= Res; | ||
|
||
if (Res) { | ||
kbobrovs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
std::cout << "passed\n"; | ||
} else { | ||
std::cout << "failed. " << Val << "(Gold) != " << NewVal << "\n"; | ||
} | ||
} | ||
return Passed; | ||
} | ||
|
||
int main() { | ||
bool passed = true; | ||
passed &= test(3.140625f, 0x4049); | ||
std::cout << (passed ? "Test Passed\n" : "Test FAILED\n"); | ||
return (passed ? 0 : 1); | ||
} |
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.
I'm not sure if that is what we're supposed to do, but I honestly don't know.
Maybe someone else from @intel/llvm-reviewers-runtime know.
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.
Seems fine to me.