-
Notifications
You must be signed in to change notification settings - Fork 76
[XeTLA] Add xetla splitk gemm #2520
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
2 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 @@ | ||
| target_include_directories(xetla_kernel PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) |
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,113 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2023-2024 Intel Corporation | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| *******************************************************************************/ | ||
| #ifndef TRITONBENCHMARK_SPLIT_K_GEMM_H | ||
| #define TRITONBENCHMARK_SPLIT_K_GEMM_H | ||
|
|
||
| #include "xetla.hpp" | ||
| #include <sycl.hpp> | ||
|
|
||
| enum class kslicing_impl_t : uint8_t { none = 0, global = 1, local = 2 }; | ||
|
|
||
| template <int m, int k, int n, | ||
| kslicing_impl_t kslicing_type = kslicing_impl_t::none> | ||
| sycl::event split_k_gemm_run(void *_A, void *_B, void *_C, void *_Acc, | ||
| void *_Cnt, sycl::queue &queue) { | ||
|
|
||
| // GEMM_UNIVERSAL input size | ||
| size_t matrix_m = m; | ||
| size_t matrix_n = n; | ||
| size_t matrix_k = k; | ||
|
|
||
| size_t size_a = matrix_m * matrix_k; | ||
| size_t size_b = matrix_k * matrix_n; | ||
| size_t size_c = matrix_m * matrix_n; | ||
|
|
||
| using data_type_a = sycl::ext::oneapi::bfloat16; | ||
| using data_type_b = sycl::ext::oneapi::bfloat16; | ||
| using data_type_c = float; | ||
| using data_type_acc = float; | ||
|
|
||
| data_type_a *A = static_cast<data_type_a *>(_A); | ||
| data_type_b *B = static_cast<data_type_b *>(_B); | ||
| data_type_c *C = static_cast<data_type_c *>(_C); | ||
|
|
||
| // Define the shape of workgroup | ||
| // It's tunable parameters based on different input shape and hardware for | ||
| // better performance | ||
| constexpr uint32_t wg_tile_m = | ||
| (kslicing_type != kslicing_impl_t::local) ? 256 : 64; | ||
| constexpr uint32_t wg_tile_n = | ||
| (kslicing_type != kslicing_impl_t::local) ? 256 : 128; | ||
|
|
||
| // specify the range k_w/k_s by setting the corresponding ratio | ||
| // splitk using global memory | ||
| constexpr uint32_t num_global_splitk = | ||
| (kslicing_type == kslicing_impl_t::global) ? 2 : 1; | ||
| // splitk using local memory | ||
| constexpr uint32_t num_local_splitk = | ||
| (kslicing_type == kslicing_impl_t::local) ? 2 : 1; | ||
|
|
||
| // Mirco-kernel configuration | ||
| using tune_option = | ||
| dict_t<elem_v_t<tune_key::param_optimizer_type, | ||
| tune_key_value::param_optimizer_decision_tree>, | ||
| elem_t_t<tune_key::data_type_acc, data_type_acc>, | ||
| elem_v_t<tune_key::dispatch_policy, | ||
| tune_key_value::dispatch_policy_kslicing>, | ||
| elem_v_t<tune_key::global_kslicing_ratio, num_global_splitk>, | ||
| elem_v_t<tune_key::local_kslicing_ratio, num_local_splitk>, | ||
| elem_t_t<tune_key::wg_tile_shape, shape<wg_tile_n, wg_tile_m>>>; | ||
| using gemm_op_t = gpu::xetla::kernel::default_gemm_t< | ||
| data_type_a, // input datatype for A | ||
| mem_layout::row_major, // memory layout for A | ||
| 8, // leading dimension alignment for A, in unit of element | ||
| data_type_b, // input datatype for B | ||
| mem_layout::row_major, // memory layout for B | ||
| 8, // leading dimension alignment for B, in unit of element | ||
| data_type_c, // output datatype for C | ||
| mem_layout::row_major, // memory layout for C | ||
| 8, // leading dimension alignment for C, in unit of element | ||
| data_type_acc, // accumulator data type for intermediate resutls | ||
| gpu_arch::Xe, // GPU arch | ||
| tune_option>; | ||
|
|
||
| // allocate temp buffers for global split | ||
| size_t size_acc = gemm_op_t::get_acc_buf_size(matrix_m, matrix_n); | ||
| size_t size_cnt = gemm_op_t::get_cnt_buf_size(matrix_m, matrix_n); | ||
|
|
||
| data_type_acc *Acc = static_cast<data_type_acc *>(_Acc); | ||
| uint32_t *Cnt = static_cast<uint32_t *>(_Cnt); | ||
|
|
||
| // set up gemm_universal arguments | ||
| typename gemm_op_t::arguments_t gemm_arg(matrix_m, matrix_k, matrix_n, A, | ||
| matrix_k, B, matrix_n, C, matrix_n, | ||
| Acc, Cnt); | ||
|
|
||
| cl::sycl::nd_range<3> nd_range = gemm_op_t::get_nd_range(gemm_arg); | ||
|
|
||
| auto gpu_event = queue.submit([&](sycl::handler &cgh) { | ||
| // GPU kernel | ||
| cgh.parallel_for(nd_range, [=](sycl::nd_item<3> item) KERNEL_MAIN { | ||
| // allocate slm and nbarrier resource | ||
| slm_barrier_init<gemm_op_t>(); | ||
| gemm_op_t gemm_op; | ||
| gemm_op(item, gemm_arg); | ||
| }); | ||
| }); | ||
| return gpu_event; | ||
| } | ||
|
|
||
| #endif // TRITONBENCHMARK_SPLIT_K_GEMM_H |
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 |
|---|---|---|
| @@ -1 +1 @@ | ||
| ae46a690bac364a93437e248418636c2a8423134 | ||
| b9e489ca6a776694a898044a3f2ae023a98db03d |
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.