-
Notifications
You must be signed in to change notification settings - Fork 787
[Joint Matrix] Enable different accumulator and output types in spirv. Add tests to cover bfloat16 and half floating-point sizes. #17502
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
Open
ggojska
wants to merge
18
commits into
intel:sycl
Choose a base branch
from
ggojska:commonhpp_reference_calculation_change
base: sycl
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
4897c7d
DRAFT - Add different output and accumulator support in spirv. Add ca…
ggojska dfbd1fa
clang-format
ggojska 548a71f
Change called BF to F conversion function
ggojska c3d45e5
add Unsupported check for SG32 bfloat test
ggojska 920cc4b
remove unneccesary comment
ggojska 4a0de92
resolve review comments
ggojska 9252909
Format patch
ggojska e7bbc00
Add unsupported mark in no-unsupported-without-info.cpp
ggojska 324c38d
test fix
ggojska 55c63bc
remove unneccesary new lines
ggojska 088932b
Added comment for half casting. Removed redundant code
ggojska abfbc4b
fix typo and space at end of comment
ggojska 4f1ebab
Fix errors with Matrix Operands
ggojska 6053d94
Update sycl/test-e2e/Matrix/SG32/joint_matrix_half_accumulator.cpp
ggojska 607f1d5
Update joint_matrix_bfloat16_accumulator.cpp
ggojska a1cb181
Update joint_matrix_half_accumulator.cpp
ggojska 5278dc4
Update no-unsupported-without-info.cpp
ggojska 729973e
Merge branch 'sycl' into commonhpp_reference_calculation_change
ggojska 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
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
138 changes: 138 additions & 0 deletions
138
sycl/test-e2e/Matrix/Inputs/joint_matrix_16bit_impl.hpp
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,138 @@ | ||
//===---joint_matrix_16bit_impl.hpp - DPC++ joint_matrix----------------===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
template <typename Tab, typename TAcc, typename TResult, size_t TM, size_t TN, | ||
size_t TK, layout B_layout> | ||
class imatrix; | ||
|
||
template <typename Tab, typename TAcc, typename TResult, size_t M, size_t N, | ||
size_t K, size_t TM, size_t TN, size_t TK, layout B_layout, size_t VF> | ||
void matrix_multiply(big_matrix<TResult, M, N> &D, big_matrix<TAcc, M, N> &C, | ||
big_matrix<Tab, M, K> &A, | ||
big_matrix<Tab, K / VF, N * VF> &B) { | ||
size_t NDRangeM = M / TM; | ||
size_t NDRangeN = N / TN; | ||
buffer<Tab, 2> bufA(A.get_data(), range<2>(M, K)); | ||
buffer<Tab, 2> bufB(B.get_data(), range<2>(K, N)); | ||
buffer<TAcc, 2> bufC((TAcc *)C.get_data(), range<2>(M, N)); | ||
buffer<TResult, 2> bufD((TResult *)D.get_data(), range<2>(M, N)); | ||
queue q; | ||
size_t sg_size = | ||
get_sg_size<imatrix<Tab, TAcc, TResult, TM, TN, TK, B_layout>>(q); | ||
|
||
q.submit([&](handler &cgh) { | ||
accessor accA{bufA, cgh}; | ||
accessor accB{bufB, cgh}; | ||
accessor accC{bufC, cgh}; | ||
accessor accD{bufD, cgh}; | ||
|
||
cgh.parallel_for<imatrix<Tab, TAcc, TResult, TM, TN, TK, B_layout>>( | ||
nd_range<2>({NDRangeM, NDRangeN * sg_size}, {1, 1 * sg_size}), | ||
[=](nd_item<2> spmd_item) | ||
#ifdef SG_SZ | ||
[[sycl::reqd_sub_group_size(SG_SZ)]] | ||
#endif | ||
{ | ||
// The submatrix API has to be accessed by all the workitems in a | ||
// subgroup these functions will be called once by the subgroup no | ||
// code divergence between the workitems | ||
const auto global_idx = spmd_item.get_global_id(0); | ||
const auto global_idy = spmd_item.get_global_id(1); | ||
const auto sg_startx = global_idx - spmd_item.get_local_id(0); | ||
const auto sg_starty = global_idy - spmd_item.get_local_id(1); | ||
|
||
sub_group sg = spmd_item.get_sub_group(); | ||
joint_matrix<sub_group, Tab, use::a, TM, TK, layout::row_major> | ||
sub_a; | ||
joint_matrix<sub_group, Tab, use::b, TK, TN, B_layout> sub_b; | ||
joint_matrix<sub_group, TAcc, use::accumulator, TM, TN> sub_c; | ||
joint_matrix<sub_group, TResult, use::accumulator, TM, TN> sub_d; | ||
|
||
joint_matrix_load( | ||
sg, sub_c, | ||
accC.template get_multi_ptr<access::decorated::no>() + | ||
(sg_startx * TM) * N + sg_starty / sg_size * TN, | ||
N, layout::row_major); | ||
|
||
for (int k = 0; k < K / TK; k += 1) { | ||
joint_matrix_load( | ||
sg, sub_a, | ||
accA.template get_multi_ptr<access::decorated::no>() + | ||
(sg_startx * TM) * K + k * TK, | ||
K); | ||
joint_matrix_load( | ||
sg, sub_b, | ||
accB.template get_multi_ptr<access::decorated::no>() + | ||
(k * TK / VF) * (N * VF) + sg_starty / sg_size * TN * VF, | ||
N * VF); | ||
|
||
joint_matrix_mad(sg, sub_d, sub_a, sub_b, sub_c); | ||
joint_matrix_copy(sg, sub_d, sub_c); | ||
} | ||
|
||
joint_matrix_store( | ||
sg, sub_d, | ||
accD.template get_multi_ptr<access::decorated::no>() + | ||
(sg_startx * TM) * N + sg_starty / sg_size * TN, | ||
N, layout::row_major); | ||
}); // parallel for | ||
}).wait(); | ||
} | ||
|
||
template <typename Tab, typename TAcc, typename TResult, size_t TM, size_t TN, | ||
size_t TK, layout B_layout, size_t VF> | ||
void test() { | ||
std::cout << "Testing: " << TM << " x " << TN << " x " << TK | ||
<< " [TM x TN x TK]" << std::endl; | ||
|
||
static constexpr size_t MATRIX_M = TM * 2; | ||
static constexpr size_t MATRIX_N = TN * 2; | ||
static constexpr size_t MATRIX_K = TK * 2; | ||
Tab A[MATRIX_M][MATRIX_K]; | ||
Tab B[MATRIX_K / VF][MATRIX_N * VF]; | ||
TAcc C[MATRIX_M][MATRIX_N]; | ||
TResult D[MATRIX_M][MATRIX_N]; | ||
TResult DRef[MATRIX_M][MATRIX_N]; | ||
|
||
matrix_rand<Tab>(MATRIX_M, MATRIX_K, (Tab *)A, Tab(1)); | ||
matrix_rand<Tab>(MATRIX_K / VF, MATRIX_N * VF, (Tab *)B, Tab(1)); | ||
|
||
matrix_fill(MATRIX_M, MATRIX_N, (TAcc *)C, TAcc(1)); | ||
matrix_fill(MATRIX_M, MATRIX_N, (TResult *)D, TResult(1)); | ||
matrix_fill(MATRIX_M, MATRIX_N, (TResult *)DRef, TResult(1)); | ||
|
||
big_matrix<TAcc, MATRIX_M, MATRIX_N> MC((TAcc *)&C); | ||
big_matrix<TResult, MATRIX_M, MATRIX_N> MD((TResult *)&D); | ||
big_matrix<Tab, MATRIX_M, MATRIX_K> MA((Tab *)&A); | ||
big_matrix<Tab, MATRIX_K / VF, MATRIX_N * VF> MB((Tab *)&B); | ||
|
||
matrix_multiply<Tab, TAcc, TResult, MATRIX_M, MATRIX_N, MATRIX_K, TM, TN, TK, | ||
B_layout, VF>(MD, MC, MA, MB); | ||
matrix_multiply_ref<Tab, Tab, TResult, VF>( | ||
(Tab *)A, (Tab *)B, (TResult *)DRef, MATRIX_M, MATRIX_N, MATRIX_K / VF); | ||
assert(matrix_compare(MATRIX_M, MATRIX_N, (TResult *)D, (TResult *)DRef)); | ||
} | ||
|
||
template <typename TLow, typename THigh, size_t TM, size_t TN, size_t TK, | ||
layout B_layout, size_t VF> | ||
void test_combo() { | ||
test<TLow, TLow, THigh, TM, TN, TK, B_layout, VF>(); | ||
test<TLow, THigh, TLow, TM, TN, TK, B_layout, VF>(); | ||
test<TLow, TLow, TLow, TM, TN, TK, B_layout, VF>(); | ||
test<TLow, THigh, THigh, TM, TN, TK, B_layout, VF>(); | ||
} | ||
|
||
template <typename TLow, typename THigh, layout B_layout, size_t VF> | ||
void test_all() { | ||
test_combo<TLow, THigh, /*TM*/ 8, /*TN*/ 16, /*TK*/ 16, B_layout, VF>(); | ||
test_combo<TLow, THigh, /*TM*/ 16, /*TN*/ 16, /*TK*/ 16, B_layout, VF>(); | ||
test_combo<TLow, THigh, /*TM*/ 1, /*TN*/ 64, /*TK*/ 16, B_layout, VF>(); | ||
test_combo<TLow, THigh, /*TM*/ 1, /*TN*/ 64, /*TK*/ 32, B_layout, VF>(); | ||
test_combo<TLow, THigh, /*TM*/ 32, /*TN*/ 64, /*TK*/ 16, B_layout, VF>(); | ||
test_combo<TLow, THigh, /*TM*/ 32, /*TN*/ 64, /*TK*/ 32, B_layout, VF>(); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
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.