Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

Enable XeTLA LSTM for GPU (#28932)

Vasily Yakovleve9f13c9c96ff
diff --git a/src/plugins/intel_gpu/src/graph/impls/cm/lstm_seq.cpp b/src/plugins/intel_gpu/src/graph/impls/cm/lstm_seq.cpp
new file mode 100644
index 00000000000..d5477cc62e4
--- /dev/null
+++ b/src/plugins/intel_gpu/src/graph/impls/cm/lstm_seq.cpp
@@ -0,0 +1,96 @@
+// Copyright (C) 2018-2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "impls/ocl/primitive_base.hpp"
+
+#include "lstm_seq.hpp"
+#include "lstm/cm/lstm_seq_cm_kernel_selector.h"
+#include "lstm/lstm_kernel_base.h"
+#include "openvino/op/lstm_sequence.hpp"
+#include "impls/registry/implementation_manager.hpp"
+
+namespace cldnn {
+namespace cm {
+
+struct lstm_seq_impl : ocl::typed_primitive_impl_ocl<lstm_seq> {
+ using parent = ocl::typed_primitive_impl_ocl<lstm_seq>;
+ using parent::parent;
+ using kernel_selector_t = kernel_selector::lstm_seq_cm_kernel_selector;
+ using kernel_params_t = kernel_selector::lstm_params;
+
+ DECLARE_OBJECT_TYPE_SERIALIZATION(cldnn::cm::lstm_seq_impl)
+
+ std::unique_ptr<primitive_impl> clone() const override {
+ return std::make_unique<lstm_seq_impl>(*this);
+ }
+
+protected:
+ kernel_arguments_data get_arguments(const typed_primitive_inst<lstm_seq>& instance) const override {
+ kernel_arguments_data args;
+ for (size_t i = 0; i < instance.inputs_memory_count(); i++) {
+ args.inputs.push_back(instance.input_memory_ptr(i));
+ }
+
+ for (size_t i = 0; i < instance.outputs_memory_count(); i++) {
+ args.outputs.push_back(instance.output_memory_ptr(i));
+ }
+ return args;
+ }
+
+public:
+ static kernel_params_t get_kernel_params(const kernel_impl_params& impl_param) {
+ const auto& primitive = impl_param.typed_desc<lstm_seq>();
+ auto params = get_default_params<kernel_selector::lstm_params>(impl_param);
+ for (size_t i = 1; i < impl_param.input_layouts.size(); ++i) {
+ params.inputs.push_back(convert_data_tensor(impl_param.get_input_layout(i)));
+ }
+
+ if (!primitive->activations.empty()) {
+ auto a_sz = primitive->activations.size();
+ auto param_sz = primitive->activation_params.size();
+ OPENVINO_ASSERT(param_sz == 0|| a_sz == param_sz, "[GPU] Unexpected activation params count in lstm_seq impl: ", param_sz);
+ for (size_t i = 0; i < a_sz; i++) {
+ params.activations.emplace_back(get_kernel_selector_activation_param(primitive->activations[i]),
+ param_sz ? primitive->activation_params[i].a : 0.0f,
+ param_sz ? primitive->activation_params[i].b : 0.0f);
+ }
+ }
+
+ if (primitive->clip > 0.0f) {
+ params.activations.emplace_back(get_kernel_selector_activation_param(activation_func::clamp), -primitive->clip, primitive->clip);
+ }
+
+ params.SetOffsetOrder(static_cast<int32_t>(primitive->offset_order));
+ params.clip = primitive->clip;
+ params.direction = primitive->direction;
+ //Legacy multi-output
+ params.outputs.push_back(convert_data_tensor(impl_param.input_layouts[1]));
+ if (!primitive->initial_cell_state.pid.empty()) {
+ params.outputs.push_back(convert_data_tensor(impl_param.input_layouts[1]));
+ }
+ return params;
+ }
+
+ static kernel_impl_params static_canonicalize_shapes(const kernel_impl_params& impl_params) {
+ if (impl_params.get_input_layout().get_partial_shape().size() != 3) {
+ return primitive_impl::static_canonicalize_shapes(impl_params);
+ }
+ auto updated_impl_params = canonicalize_fused_shapes(impl_params);
+ return updated_impl_params;
+ }
+
+ kernel_impl_params canonicalize_shapes(const kernel_impl_params& impl_params) const override {
+ return static_canonicalize_shapes(impl_params);
+ }
+};
+
+std::unique_ptr<primitive_impl> LSTMSeqImplementationManager::create_impl(const program_node& node, const kernel_impl_params& params) const {
+ OPENVINO_ASSERT(node.is_type<lstm_seq>());
+ return ocl::typed_primitive_impl_ocl<lstm_seq>::create<lstm_seq_impl>(static_cast<const lstm_seq_node&>(node), params);
+}
+
+} // namespace cm
+} // namespace cldnn
+
+BIND_BINARY_BUFFER_WITH_TYPE(cldnn::cm::lstm_seq_impl)
diff --git a/src/plugins/intel_gpu/src/graph/impls/cm/lstm_seq.hpp b/src/plugins/intel_gpu/src/graph/impls/cm/lstm_seq.hpp
new file mode 100644
index 00000000000..83ff241944a
--- /dev/null
+++ b/src/plugins/intel_gpu/src/graph/impls/cm/lstm_seq.hpp
@@ -0,0 +1,105 @@
+// Copyright (C) 2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include <memory>
+
+#include "impls/registry/implementation_manager.hpp"
+#include "intel_gpu/runtime/layout.hpp"
+#include "lstm_seq_inst.h"
+namespace cldnn {
+namespace cm {
+
+struct LSTMSeqImplementationManager : public ImplementationManager {
+ OV_GPU_PRIMITIVE_IMPL("cm::lstm_seq")
+ LSTMSeqImplementationManager(shape_types shape_type, ValidateFunc vf = nullptr)
+ : ImplementationManager(impl_types::cm, shape_type, vf) {}
+
+ in_out_fmts_t query_formats(const program_node& node) const override {
+ assert(node.is_type<lstm_seq>());
+ std::vector<format::type> in_fmts(node.get_dependencies().size(), format::any);
+ std::vector<format::type> out_fmts(node.get_outputs_count(), format::any);
+
+ for (size_t idx = 0; idx < node.get_dependencies().size(); idx++) {
+ in_fmts[idx] = format::bfyx;
+ }
+ out_fmts[0] = format::byfx;
+ for (size_t idx = 1; idx < node.get_outputs_count(); idx++) {
+ out_fmts[idx] = format::bfyx;
+ }
+
+ return {in_fmts, out_fmts};
+ }
+
+ std::unique_ptr<primitive_impl> create_impl(const program_node& node,
+ const kernel_impl_params& params) const override;
+
+ bool validate_impl(const program_node& node) const override {
+ assert(node.is_type<lstm_seq>());
+
+ auto &engine = node.get_program().get_engine();
+ auto &config = node.get_program().get_config();
+ const auto& info = engine.get_device_info();
+
+ // XeTLA LSTM optimized for Xe2 architectures
+ if (!check_cm_jit_support(engine, config) || info.arch != gpu_arch::xe2) {
+ return false;
+ }
+
+ const auto& lstm_node = node.as<lstm_seq>();
+ const auto& lstm_prim = lstm_node.get_primitive();
+ if (lstm_prim->clip > 0.0f) {
+ return false;
+ }
+
+ if (lstm_prim->activations.size() != 3 ||
+ lstm_prim->activations[0] != activation_func::logistic ||
+ lstm_prim->activations[1] != activation_func::hyperbolic_tan ||
+ lstm_prim->activations[2] != activation_func::hyperbolic_tan) {
+ return false;
+ }
+
+ auto in_layouts = node.get_input_layouts();
+ if (node.is_dynamic()) {
+ return false;
+ }
+ unsigned int expected_inputs = 7;
+ if (in_layouts.size() != expected_inputs) {
+ return false;
+ }
+ {
+ auto &seq_lengths = in_layouts[expected_inputs-1];
+ if (seq_lengths.format != format::bfyx || seq_lengths.data_type != data_types::i32) {
+ return false;
+ }
+ in_layouts.pop_back();
+ }
+
+
+ auto out_layouts = node.get_output_layouts();
+ for (auto &layout : in_layouts) {
+ if (layout.format != format::bfyx || layout.data_type != data_types::f16) {
+ return false;
+ }
+ }
+ for (auto &layout : out_layouts) {
+ if (layout.data_type != data_types::f16) {
+ return false;
+ }
+ }
+
+ auto num_gates = 4;
+ auto batch_size = in_layouts[0].get_shape()[0];
+ auto input_size = in_layouts[0].get_shape()[2];
+ auto hidden_size = in_layouts[3].get_shape()[1] / num_gates;
+ auto num_dir = in_layouts[3].get_shape()[0];
+ if (hidden_size != 128 || batch_size != 1 || num_dir != 2 || (input_size != 64 && input_size != 256)) {
+ return false;
+ }
+
+ return true;
+ }
+};
+
+} // namespace cm
+} // namespace cldnn
diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl/kernels_cache.hpp b/src/plugins/intel_gpu/src/graph/impls/ocl/kernels_cache.hpp
index 56459b93d24..79ccfd050f4 100644
--- a/src/plugins/intel_gpu/src/graph/impls/ocl/kernels_cache.hpp
+++ b/src/plugins/intel_gpu/src/graph/impls/ocl/kernels_cache.hpp
@@ -86,6 +86,7 @@ public:
}
}
} else {
+ source.push_back("#include <cm/cm.h>\n#include <cm/cmtl.h>\n");
for (const auto& kv : batch_headers)
source.push_back(kv.second);
}
diff --git a/src/plugins/intel_gpu/src/graph/impls/registry/lstm_seq_impls.cpp b/src/plugins/intel_gpu/src/graph/impls/registry/lstm_seq_impls.cpp
index 42114c892a4..5cd25b7f62a 100644
--- a/src/plugins/intel_gpu/src/graph/impls/registry/lstm_seq_impls.cpp
+++ b/src/plugins/intel_gpu/src/graph/impls/registry/lstm_seq_impls.cpp
@@ -10,6 +10,10 @@
#include "impls/ocl/rnn_seq.hpp"
#endif
+#if OV_GPU_WITH_CM
+ #include "impls/cm/lstm_seq.hpp"
+#endif
+
#if OV_GPU_WITH_ONEDNN
#include "impls/onednn/lstm_seq_onednn.hpp"
#endif
@@ -20,6 +24,7 @@ using namespace cldnn;
const std::vector<std::shared_ptr<cldnn::ImplementationManager>>& Registry<lstm_seq>::get_implementations() {
static const std::vector<std::shared_ptr<ImplementationManager>> impls = {
+ OV_GPU_CREATE_INSTANCE_CM(cm::LSTMSeqImplementationManager, shape_types::static_shape)
OV_GPU_CREATE_INSTANCE_ONEDNN(onednn::LSTMSeqImplementationManager, shape_types::static_shape)
OV_GPU_CREATE_INSTANCE_OCL(ocl::RNNSeqImplementationManager, shape_types::static_shape)
};
diff --git a/src/plugins/intel_gpu/src/graph/lstm_seq.cpp b/src/plugins/intel_gpu/src/graph/lstm_seq.cpp
index 55e25672300..c17a387ad27 100644
--- a/src/plugins/intel_gpu/src/graph/lstm_seq.cpp
+++ b/src/plugins/intel_gpu/src/graph/lstm_seq.cpp
@@ -20,7 +20,7 @@ layout lstm_seq_inst::calc_output_layout(lstm_seq_node const& node, kernel_impl_
const auto& lstm_hidden_size = input_pshape_hidden[2];
auto first_out_fmt = cldnn::format::bfyx;
- if (node.get_preferred_impl_type() == impl_types::onednn && node.get_preferred_output_fmt() != format::any) {
+ if (node.get_preferred_output_fmt() != format::any) {
first_out_fmt = node.get_preferred_output_fmt();
}
@@ -41,7 +41,7 @@ std::vector<layout> lstm_seq_inst::calc_output_layouts(lstm_seq_node const& node
auto first_out_fmt = cldnn::format::bfyx;
auto second_out_fmt = input_layout.format;
auto third_out_fmt = input_layout.format;
- if (node.get_preferred_impl_type() == impl_types::onednn && node.get_preferred_output_fmt() != format::any) {
+ if (node.get_preferred_output_fmt() != format::any) {
first_out_fmt = node.get_preferred_output_fmt();
second_out_fmt = node.get_preferred_output_fmt(1);
third_out_fmt = node.get_preferred_output_fmt(2);
diff --git a/src/plugins/intel_gpu/src/kernel_selector/CMakeLists.txt b/src/plugins/intel_gpu/src/kernel_selector/CMakeLists.txt
index 1e585714bf7..b12711ca42e 100644
--- a/src/plugins/intel_gpu/src/kernel_selector/CMakeLists.txt
+++ b/src/plugins/intel_gpu/src/kernel_selector/CMakeLists.txt
@@ -18,7 +18,9 @@ file(GLOB_RECURSE KERNELS
)
file(GLOB_RECURSE CM_KERNELS
- "${CMAKE_CURRENT_SOURCE_DIR}/cm_kernels/*"
+ "${CMAKE_CURRENT_SOURCE_DIR}/cm_kernels/*.h"
+ "${CMAKE_CURRENT_SOURCE_DIR}/cm_kernels/*.hpp"
+ "${CMAKE_CURRENT_SOURCE_DIR}/cm_kernels/*.cpp"
)
# Path which points to root directory where code generated elements are created
@@ -61,12 +63,31 @@ add_custom_command(OUTPUT "${CODEGEN_INCDIR}/${PRIM_DB}"
COMMENT "Updating file if the file changed (${PRIM_DB}) ..."
)
+set(XETLA_HEADER "cm_xetla.h")
+if(WIN32)
+ add_custom_command(OUTPUT "${CODEGEN_CACHE_DIR}/cm_kernels"
+ COMMAND "${CMAKE_COMMAND}" -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/cm_kernels/" "${CODEGEN_CACHE_DIR}/cm_kernels"
+ COMMAND "${CMAKE_CXX_COMPILER}" "${CODEGEN_CACHE_DIR}/cm_kernels/include/batch_headers/${XETLA_HEADER}" -I ${XETLA_INCLUDE_DIR} -D _WIN32 -EP > "${CODEGEN_CACHE_DIR}/${XETLA_HEADER}"
+ COMMAND "${CMAKE_COMMAND}" -E rename "${CODEGEN_CACHE_DIR}/${XETLA_HEADER}" "${CODEGEN_CACHE_DIR}/cm_kernels/include/batch_headers/${XETLA_HEADER}"
+ DEPENDS "${CM_KERNELS}" "${CODEGEN_INCDIR}/${PRIM_DB}"
+ COMMENT "Copying CM sources and preprocessing XeTLA headers ..."
+ )
+else()
+ add_custom_command(OUTPUT "${CODEGEN_CACHE_DIR}/cm_kernels"
+ COMMAND "${CMAKE_COMMAND}" -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/cm_kernels/" "${CODEGEN_CACHE_DIR}/cm_kernels"
+ COMMAND "${CMAKE_CXX_COMPILER}" "${CODEGEN_CACHE_DIR}/cm_kernels/include/batch_headers/${XETLA_HEADER}" -I ${XETLA_INCLUDE_DIR} -E -P > "${CODEGEN_CACHE_DIR}/${XETLA_HEADER}"
+ COMMAND "${CMAKE_COMMAND}" -E rename "${CODEGEN_CACHE_DIR}/${XETLA_HEADER}" "${CODEGEN_CACHE_DIR}/cm_kernels/include/batch_headers/${XETLA_HEADER}"
+ DEPENDS "${CM_KERNELS}" "${CODEGEN_INCDIR}/${PRIM_DB}"
+ COMMENT "Copying CM sources and preprocessing XeTLA headers ..."
+ )
+endif()
+
add_custom_command(OUTPUT "${CODEGEN_CACHE_DIR}/${CM_PRIM_DB}"
COMMAND "${Python3_EXECUTABLE}" "${CODEGEN_SCRIPT}" -out_path "${CODEGEN_CACHE_DIR}"
-out_file_name_prim_db "${CM_PRIM_DB}"
-out_file_name_batch_headers "${CM_PRIM_DB_BATCH_HEADERS}"
- -kernels "${CMAKE_CURRENT_SOURCE_DIR}/cm_kernels" -cm
- DEPENDS ${CM_KERNELS} "${CODEGEN_SCRIPT}" "${CODEGEN_INCDIR}/${PRIM_DB}"
+ -kernels "${CODEGEN_CACHE_DIR}/cm_kernels" -cm
+ DEPENDS ${CM_KERNELS} "${CODEGEN_SCRIPT}" "${CODEGEN_CACHE_DIR}/cm_kernels" "${CODEGEN_INCDIR}/${PRIM_DB}"
COMMENT "Generating ${CODEGEN_CACHE_DIR}/${CM_PRIM_DB} ..."
)
diff --git a/src/plugins/intel_gpu/src/kernel_selector/cm_kernels/include/batch_headers/cm_xetla.h b/src/plugins/intel_gpu/src/kernel_selector/cm_kernels/include/batch_headers/cm_xetla.h
new file mode 100644
index 00000000000..27a5a4f3da0
--- /dev/null
+++ b/src/plugins/intel_gpu/src/kernel_selector/cm_kernels/include/batch_headers/cm_xetla.h
@@ -0,0 +1,5 @@
+// This file is to be preprocessed by the cpp compiler before adding to batch headers db for cm
+
+#define XETLA_CODE_BASE __CM__
+#define XETLA_NO_CM_INCLUDE
+#include <xetla.hpp>
diff --git a/src/plugins/intel_gpu/src/kernel_selector/cm_kernels/include/xetla_lstm.h b/src/plugins/intel_gpu/src/kernel_selector/cm_kernels/include/xetla_lstm.h
new file mode 100644
index 00000000000..d208e924efa
--- /dev/null
+++ b/src/plugins/intel_gpu/src/kernel_selector/cm_kernels/include/xetla_lstm.h
@@ -0,0 +1,605 @@
+/*******************************************************************************
+* Copyright (c) 2022-2025 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.
+*******************************************************************************/
+
+using namespace gpu::xetla;
+using namespace gpu::xetla::group;
+using namespace gpu::xetla::kernel;
+using namespace gpu::xetla::subgroup;
+
+template <typename dtype_a, typename dtype_b, typename dtype_c,
+ typename dtype_acc, uint32_t wg_m, uint32_t wg_n, uint32_t sg_m,
+ uint32_t sg_n, uint32_t sg_k, mem_layout layout_a, mem_layout layout_b,
+ mem_layout layout_c, mem_space mem_space_a, mem_space mem_space_b,
+ mem_space mem_space_c, mma_engine engine, uint32_t local_kslicing,
+ gpu_arch arch_tag>
+struct gemm_universal {
+ using tile_shape = group::tile_shape_t<wg_n, wg_m, sg_n, sg_m>;
+ static constexpr uint32_t periodic_sync_interval = 0;
+ static constexpr uint32_t prefetch_distance = 2;
+
+ using gemm_t = typename group::gemm_selector_t<dtype_a, dtype_b, layout_a,
+ layout_b, mem_space_a, mem_space_b, 8, 8, dtype_acc, tile_shape,
+ sg_k, mma_engine::xmx, arch_tag, prefetch_distance,
+ periodic_sync_interval>::gemm;
+
+ using bias_op_t = subgroup::bias_add_op_t<dtype_b, arch_tag>;
+ using tile_op_t = subgroup::chained_tile_op_t<bias_op_t>;
+ using epilogue_t = epilogue_t<epilogue_policy_tile_op<tile_op_t, arch_tag>,
+ tile_shape, mem_desc_t<dtype_c, layout_c, mem_space_c>>;
+ using epilogue_args_t = typename epilogue_t::arguments_t;
+
+ using group_swizzle_t = kernel::group_swizzle_default<arch_tag>;
+
+ using gemm_op_t = kernel::gemm_universal_t<
+ kernel::dispatch_policy_kslicing<group_swizzle_t, 1,
+ local_kslicing>,
+ gemm_t, epilogue_t>;
+
+ using gemm_acc_t = typename gemm_t::matAcc_t;
+
+ static constexpr uint32_t barrier_count = gemm_op_t::get_barrier_count();
+ static constexpr uint32_t slm_size = gemm_op_t::get_slm_size();
+
+ inline void operator()(sycl::nd_item<3> &item, dtype_a *a,
+ dtype_b *b, dtype_b *bias,
+ typename epilogue_t::mem_desc_c_t::base_t c, uint32_t mat_m,
+ uint32_t mat_n, uint32_t mat_k, uint32_t lda, uint32_t ldb,
+ uint32_t ldc) {
+ gemm_op_t gemm_op;
+
+ typename bias_op_t::shape_t bias_add_shape(mat_n, 1, mat_n);
+ epilogue_args_t epilogue_args;
+
+ uint64_t matrix_size_a = mat_m * mat_k;
+ uint64_t matrix_size_b = mat_k * mat_n;
+ uint64_t matrix_size_c = mat_m * mat_n;
+
+ epilogue_args.init({{bias, bias_add_shape}});
+ typename gemm_op_t::arguments_t arg(mat_m, mat_k, mat_n, a,
+ layout_a == mem_layout::col_major ? mat_m : mat_k, b,
+ layout_b == mem_layout::col_major ? mat_k : mat_n, c.base,
+ mat_n, nullptr, nullptr, epilogue_args);
+ gemm_op(item, arg);
+ }
+};
+
+template <typename dtype_a, typename dtype_b, typename dtype_c,
+ typename dtype_acc, uint32_t wg_m, uint32_t wg_n, uint32_t sg_m,
+ uint32_t sg_n, uint32_t sg_k, mem_layout mem_layout_a,
+ mem_layout mem_layout_b, mem_layout mem_layout_c, mem_space mem_space_a,
+ mem_space mem_space_b, mem_space mem_space_c, mma_engine engine,
+ uint32_t k_size, gpu_arch arch_tag>
+struct gemm_persistent {
+ static_assert(engine == mma_engine::fpu);
+ static_assert(group::detail::check_2d_block_pitch_alignment<dtype_a,
+ dtype_b, 8, 8, arch_tag>::value);
+
+ static constexpr uint32_t periodic_sync_interval = 0;
+ static constexpr uint32_t prefetch_distance = 0;
+ static constexpr uint32_t barrier_count = 0;
+ static constexpr uint32_t slm_size = 0;
+
+ using tile_shape = group::tile_shape_t<wg_n, wg_m, sg_n, sg_m>;
+ using work_group_t = typename tile_shape::work_group_t;
+
+ using mem_desc_a_t = mem_desc_t<dtype_a, mem_layout_a, mem_space_a, 8>;
+ using mem_desc_b_t = mem_desc_t<dtype_b, mem_layout_b, mem_space_b, 8>;
+
+ using compute_attr_t
+ = group::compute_attr_t<dtype_acc, dtype_acc, dtype_acc>;
+ using perf_tuning_knob_t = group::perf_tuning_knob_t<sg_k,
+ prefetch_distance, periodic_sync_interval>;
+ using compute_policy_t = group::compute_policy_default_fpu<compute_attr_t,
+ perf_tuning_knob_t, arch_tag>;
+
+ using group_swizzle_t = kernel::group_swizzle_default<arch_tag>;
+
+ using dtype_mma_acc = typename compute_policy_t::dtype_mma_acc;
+ using dtype_mma_a = typename compute_policy_t::dtype_mma_a;
+ using dtype_mma_b = typename compute_policy_t::dtype_mma_b;
+
+ using check_dtype
+ = group::gemm<gpu_arch::Xe>::default_fpu::check_dtype_default<
+ dtype_a, dtype_b, dtype_mma_a, dtype_mma_b, dtype_mma_acc>;
+
+ using check_memory
+ = group::gemm<gpu_arch::Xe>::default_fpu::check_memory_default<
+ mem_layout_a, mem_layout_b, mem_space_a, mem_space_b>;
+
+ static constexpr uint32_t tile_size_x_a = compute_policy_t::k_stride;
+ static constexpr uint32_t tile_size_y_a = tile_shape::sg_tile_size_y;
+ static constexpr uint32_t tile_size_x_b = tile_shape::sg_tile_size_x;
+ static constexpr uint32_t tile_size_y_b = compute_policy_t::k_stride;
+ static constexpr uint32_t tile_size_x_c = tile_shape::sg_tile_size_x;
+ static constexpr uint32_t tile_size_y_c = tile_shape::sg_tile_size_y;
+
+ static constexpr uint32_t block_size_x_a
+ = (compute_policy_t::block_size_x_a > tile_size_x_a)
+ ? tile_size_x_a
+ : compute_policy_t::block_size_x_a;
+ static constexpr uint32_t block_size_y_a
+ = (compute_policy_t::block_size_y_a > tile_size_y_a)
+ ? tile_size_y_a
+ : compute_policy_t::block_size_y_a;
+ static constexpr uint32_t block_size_x_b
+ = (compute_policy_t::block_size_x_b > tile_size_x_b)
+ ? tile_size_x_b
+ : compute_policy_t::block_size_x_b;
+ static constexpr uint32_t block_size_y_b
+ = (compute_policy_t::block_size_y_b > tile_size_y_b)
+ ? tile_size_y_b
+ : compute_policy_t::block_size_y_b;
+
+ static constexpr reg_layout reg_layout_a = reg_layout::tiled;
+ using matA_tile_desc_t
+ = subgroup::tile_desc_t<k_size, 1, k_size, 1, reg_layout_a>;
+ using matA_t = subgroup::tile_t<dtype_a, matA_tile_desc_t>;
+ using matA_payload_t = subgroup::mem_payload_t<mem_desc_a_t,
+ matA_tile_desc_t,
+ subgroup::msg_type_v<matA_tile_desc_t, mem_space_a>, arch_tag>;
+ using matA_acc_t = subgroup::tile_t<dtype_mma_a, matA_tile_desc_t>;
+
+ static constexpr reg_layout reg_layout_b = reg_layout::tiled;
+ using matB_tile_desc_t = subgroup::tile_desc_t<tile_size_x_b, tile_size_y_b,
+ block_size_x_b, block_size_y_b, reg_layout_b>;
+ using matB_t = subgroup::tile_t<dtype_b, matB_tile_desc_t>;
+ using matB_payload_t = subgroup::mem_payload_t<mem_desc_b_t,
+ matB_tile_desc_t, msg_type::block_2d, arch_tag>;
+ using matB_acc_t = subgroup::tile_t<dtype_mma_b, matB_tile_desc_t>;
+
+ using matAcc_tile_desc_t = subgroup::tile_desc_t<tile_size_x_c,
+ tile_size_y_c, block_size_x_b, block_size_y_a, reg_layout::tiled>;
+ using matAcc_t = subgroup::tile_t<dtype_mma_acc, matAcc_tile_desc_t>;
+
+ using tile_mma = subgroup::tile_mma_t<matAcc_t, matAcc_t, matB_acc_t,
+ matA_acc_t, mma_engine::fpu, arch_tag>;
+
+ static constexpr bool is_col_major_a
+ = mem_layout_a == mem_layout::col_major;
+ static constexpr bool is_col_major_b
+ = mem_layout_b == mem_layout::col_major;
+
+ static constexpr tdesc_update_dir update_dir_a = is_col_major_a
+ ? tdesc_update_dir::y_dir
+ : tdesc_update_dir::x_dir;
+ static constexpr tdesc_update_dir update_dir_b = is_col_major_b
+ ? tdesc_update_dir::x_dir
+ : tdesc_update_dir::y_dir;
+
+ mem_desc_a_t mem_desc_a;
+ static_assert(k_size % compute_policy_t::k_stride == 0);
+ static constexpr uint32_t k_steps = k_size / compute_policy_t::k_stride;
+ matB_acc_t matB_acc[k_steps];
+
+ inline void init(sycl::nd_item<3> &item,
+ typename mem_desc_a_t::base_t a, dtype_b *b, uint32_t mat_m,
+ uint32_t mat_n, uint32_t mat_k, uint32_t lda, uint32_t ldb,
+ uint32_t ldc) {
+ work_group_t g(item.get_local_linear_id() % work_group_t::size);
+ uint32_t wg_id = item.get_local_linear_id() / work_group_t::size;
+
+ group_swizzle_t group_swizzle;
+ int start_m = group_swizzle.template get_tile_idx<1>(item)
+ * tile_shape::wg_tile_size_y;
+ int start_n = group_swizzle.template get_tile_idx<2>(item)
+ * tile_shape::wg_tile_size_x;
+ int start_k = 0;
+
+ uint32_t wg_tile_k = mat_k;
+ uint32_t boundary_n = (start_n + tile_shape::wg_tile_size_x)
+ > tile_shape::wg_tile_size_x
+ ? mat_n
+ : (start_n + tile_shape::wg_tile_size_x);
+ uint32_t boundary_m = (start_m + tile_shape::wg_tile_size_y)
+ > tile_shape::wg_tile_size_y
+ ? mat_m
+ : (start_m + tile_shape::wg_tile_size_y);
+ uint32_t boundary_k = wg_tile_k;
+
+ mem_desc_b_t mem_desc_b;
+
+ mem_desc_a.init(a, {boundary_k, boundary_m, lda}, {start_k, start_m});
+ mem_desc_b.init(b, {boundary_n, boundary_k, ldb}, {start_n, start_k});
+
+ int32_t sg_idx = g.get_id() % tile_shape::wg_size_x;
+ int32_t sg_idy = g.get_id() / tile_shape::wg_size_x;
+ int32_t tile_offset_n = sg_idx * tile_shape::sg_tile_size_x;
+ int32_t tile_offset_m = sg_idy * tile_shape::sg_tile_size_y;
+
+ mem_desc_a.update_coord_y(tile_offset_m);
+ mem_desc_b.update_coord_x(tile_offset_n);
+
+ matB_payload_t matB_payload(mem_desc_b);
+ matB_t matB[k_steps];
+
+#pragma unroll
+ for (int i = 0; i < k_steps; i++) {
+ subgroup::tile_load<cache_hint::uncached, cache_hint::uncached>(
+ matB[i], matB_payload);
+ matB_payload.template update_tdesc<update_dir_b>(
+ matB_t::tile_size_y);
+ subgroup::elemwise_cvt(matB_acc[i], matB[i]);
+ }
+
+#pragma unroll
+ for (int i = 0; i < k_steps; i++) {
+ subgroup::tile_store<cache_hint::uncached, cache_hint::uncached>(
+ matB_acc[i], matB_payload);
+ }
+ }
+
+ inline void run(matAcc_t &result) {
+
+ matAcc_t part_res[k_steps];
+ matA_t matA;
+ matA_acc_t matA_acc;
+ matA_payload_t matA_payload(mem_desc_a);
+
+ subgroup::tile_load<cache_hint::cached, cache_hint::cached>(
+ matA, matA_payload);
+ subgroup::elemwise_cvt(matA_acc, matA);
+
+ cm_fence(CM_SW_BARRIER);
+
+#pragma unroll
+ for (int i = 0; i < k_steps; i++) {
+ part_res[i].init(0);
+#pragma unroll
+ for (int j = 0; j < sg_k; j++) {
+ vector<float, k_size> tempA = matA_acc.reg;
+ float a = tempA[j + i * sg_k];
+ vector<float, sg_n *sg_k> tempB = matB_acc[i].reg;
+ vector<float, sg_n> tempB_simd
+ = tempB.select<sg_n, 1>(j * sg_n);
+ part_res[i].reg += a * tempB_simd;
+ }
+ }
+ cm_fence(CM_SW_BARRIER);
+ result.init(0);
+#pragma unroll
+ for (int i = 0; i < k_steps; i++) {
+ result.reg += part_res[i].reg;
+ }
+ }
+};
+
+template <typename dtype_a, typename dtype_b, typename dtype_c,
+ typename dtype_acc, uint32_t input_size, uint32_t hidden_size,
+ uint32_t directions, mem_layout mem_layout_x, mem_layout mem_layout_w,
+ mem_layout mem_layout_out, mem_space mem_space_x, mem_space mem_space_w,
+ mem_space mem_space_out, gpu_arch arch_tag>
+struct __xetla_kernel_lstm_gemm {
+ static_assert(directions == 1 || directions == 2);
+
+ static constexpr uint32_t wg_m = 40;
+ static constexpr uint32_t wg_n = 256;
+
+ static constexpr uint32_t sg_m = 24;
+ static constexpr uint32_t sg_n = 32;
+ static constexpr uint32_t sg_k = 32;
+ static constexpr uint32_t local_kslicing = 1;
+
+ using gemm_t = gemm_universal<dtype_a, dtype_b, dtype_c, dtype_acc, wg_m,
+ wg_n, sg_m, sg_n, sg_k, mem_layout_x, mem_layout_w, mem_layout_x,
+ mem_space_x, mem_space_w, mem_space_x, mma_engine::xmx,
+ local_kslicing, arch_tag>;
+
+ static inline void init() {
+ if constexpr (gemm_t::barrier_count != 0) {
+ xetla_nbarrier_init<gemm_t::barrier_count>();
+ }
+ if constexpr (gemm_t::slm_size != 0) {
+ xetla_local_init<gemm_t::slm_size>();
+ }
+ }
+
+ static inline void run(sycl::nd_item<3> &item, dtype_a *x, dtype_b *W,
+ dtype_b *B, int *sequence_lengths, dtype_acc *out) {
+ uint32_t seq_len = sequence_lengths[0];
+ uint32_t matrix_m = seq_len;
+ uint32_t matrix_k = input_size;
+ uint32_t matrix_n = hidden_size * 4;
+
+ size_t lda
+ = mem_layout_x == mem_layout::col_major ? matrix_m : matrix_k;
+ size_t ldb
+ = mem_layout_w == mem_layout::col_major ? matrix_k : matrix_n;
+ size_t ldc = matrix_n;
+
+ int dir_id = item.get_group(0);
+
+ dtype_b *w_dir = W + matrix_k * matrix_n * dir_id;
+ dtype_b *bias_dir = B + matrix_n * dir_id;
+ dtype_c *x_dir = out + matrix_m * matrix_n * dir_id;
+
+ gemm_t gemm = gemm_t();
+ gemm(item, x, w_dir, bias_dir, x_dir, matrix_m, matrix_n, matrix_k, lda,
+ ldb, ldc);
+ }
+};
+
+template <typename dtype_a, typename dtype_b, typename dtype_c,
+ typename dtype_acc, uint32_t input_size, uint32_t hidden_size,
+ uint32_t directions, mem_layout mem_layout_x, mem_layout mem_layout_w,
+ mem_layout mem_layout_out, mem_space mem_space_x, mem_space mem_space_w,
+ mem_space mem_space_out, gpu_arch arch_tag>
+struct __xetla_kernel_lstm_loop {
+ static_assert(directions == 1 || directions == 2);
+ static_assert(hidden_size == 128);
+ static_assert(hidden_size % 4 == 0);
+
+ static constexpr uint32_t SIMD = 16;
+ static constexpr uint32_t num_threads = 32;
+ static constexpr uint32_t gates = 4;
+
+ static constexpr uint32_t wg_m = 1;
+ static constexpr uint32_t wg_n = hidden_size * gates;
+
+ static constexpr uint32_t sg_m = 1;
+ static constexpr uint32_t sg_n = SIMD;
+ static constexpr uint32_t sg_k = hidden_size / 4;
+
+ static constexpr uint32_t matrix_m = 1;
+ static constexpr uint32_t matrix_k = hidden_size;
+ static constexpr uint32_t matrix_n = hidden_size * gates;
+
+ static constexpr size_t lda
+ = mem_layout_x == mem_layout::col_major ? matrix_m : matrix_k;
+ static constexpr size_t ldb
+ = mem_layout_w == mem_layout::col_major ? matrix_k : matrix_n;
+ static constexpr size_t ldc = matrix_n;
+
+ using gemm_t = gemm_persistent<dtype_a, dtype_b, dtype_acc, dtype_acc, wg_m,
+ wg_n, sg_m, sg_n, sg_k, mem_layout::row_major, mem_layout_w,
+ mem_layout::row_major, mem_space::local, mem_space_w,
+ mem_space::local, mma_engine::fpu, hidden_size, arch_tag>;
+
+ static constexpr uint32_t barrier_count = gemm_t::barrier_count + 1;
+ static constexpr uint32_t context_size_bytes
+ = hidden_size * sizeof(dtype_acc);
+ static constexpr uint32_t figo_size = gates * hidden_size;
+ static constexpr uint32_t figo_size_bytes = figo_size * sizeof(dtype_acc);
+ static constexpr uint32_t slm_size
+ = context_size_bytes * 2 + figo_size_bytes + gemm_t::slm_size;
+
+ static inline void init() {
+ if constexpr (barrier_count != 0) {
+ xetla_nbarrier_init<barrier_count>();
+ }
+ if constexpr (slm_size != 0) { xetla_local_init<slm_size>(); }
+ }
+
+ static inline void run(sycl::nd_item<3> &item, dtype_a *x,
+ dtype_b *initial_hidden_state, dtype_b *initial_cell_state,
+ dtype_b *R, int *sequence_lengths, dtype_c *hidden_history,
+ dtype_c *hidden_state, dtype_c *cell_state) {
+ xetla_nbarrier_t<num_threads, num_threads, arch_tag> nbarrier;
+ nbarrier.init_nbarrier(
+ barrier_count - 1, nbarrier_role::producer_consumer);
+
+ int dir_id = item.get_group(0);
+ uint32_t seq_len = sequence_lengths[0];
+
+ dtype_a *x_dir = x + seq_len * hidden_size * gates * dir_id;
+ dtype_b *r_dir = R + matrix_k * matrix_n * dir_id;
+ dtype_b *context_h_init = initial_hidden_state + hidden_size * dir_id;
+ dtype_b *context_c_init = initial_cell_state + hidden_size * dir_id;
+ dtype_c *context_h_out = hidden_state + hidden_size * dir_id;
+ dtype_c *context_c_out = cell_state + hidden_size * dir_id;
+
+ constexpr uint32_t slm_figo_offset = gemm_t::slm_size;
+ constexpr uint32_t slm_h_offset = slm_figo_offset + figo_size_bytes;
+ constexpr uint32_t slm_c_offset = slm_h_offset + context_size_bytes;
+
+ gemm_t gemm = gemm_t();
+ gemm.init(item, slm_h_offset, r_dir, matrix_m, matrix_n, matrix_k, lda,
+ ldb, ldc);
+
+ using tile_desc_t
+ = subgroup::tile_desc_t<SIMD, 1, SIMD, 1, reg_layout::tiled>;
+
+ using tile_acc_t = subgroup::tile_t<dtype_acc, tile_desc_t>;
+ using tile_a_t = subgroup::tile_t<dtype_a, tile_desc_t>;
+ using tile_b_t = subgroup::tile_t<dtype_b, tile_desc_t>;
+ using tile_c_t = subgroup::tile_t<dtype_c, tile_desc_t>;
+
+ using local_acc_payload_t = subgroup::mem_payload_t<
+ mem_desc_t<dtype_acc, mem_layout::row_major, mem_space::local>,
+ tile_desc_t,
+ subgroup::msg_type_v<tile_desc_t, mem_space::local>, arch_tag>;
+
+ using global_acc_payload_t = subgroup::mem_payload_t<
+ mem_desc_t<dtype_acc, mem_layout::row_major, mem_space::global>,
+ tile_desc_t,
+ subgroup::msg_type_v<tile_desc_t, mem_space::global>, arch_tag>;
+
+ using global_a_payload_t = subgroup::mem_payload_t<
+ mem_desc_t<dtype_a, mem_layout::row_major, mem_space::global>,
+ tile_desc_t,
+ subgroup::msg_type_v<tile_desc_t, mem_space::global>, arch_tag>;
+
+ using global_b_payload_t = subgroup::mem_payload_t<
+ mem_desc_t<dtype_b, mem_layout::row_major, mem_space::global>,
+ tile_desc_t,
+ subgroup::msg_type_v<tile_desc_t, mem_space::global>, arch_tag>;
+
+ using global_c_payload_t = subgroup::mem_payload_t<
+ mem_desc_t<dtype_c, mem_layout::row_major, mem_space::global>,
+ tile_desc_t,
+ subgroup::msg_type_v<tile_desc_t, mem_space::global>, arch_tag>;
+
+ const int seq_inc = 1 - (2 * dir_id);
+ const int seq_start_y = (seq_len - 1) * dir_id;
+ const uint32_t local_id = item.get_local_linear_id();
+ const uint32_t minigroup_offset
+ = (local_id % ((hidden_size + SIMD - 1) / SIMD)) * SIMD;
+
+ tile_a_t x_tile;
+ global_a_payload_t x_tile_payload;
+ x_tile_payload.init(x_dir, figo_size, seq_len, figo_size,
+ local_id * SIMD, seq_start_y);
+
+ tile_acc_t h_tile;
+ local_acc_payload_t h_tile_payload;
+ h_tile_payload.init(
+ slm_h_offset, hidden_size, 1, hidden_size, minigroup_offset, 0);
+
+ tile_acc_t c_tile;
+ local_acc_payload_t c_tile_payload;
+ c_tile_payload.init(
+ slm_c_offset, hidden_size, 1, hidden_size, minigroup_offset, 0);
+
+ if (local_id < (hidden_size / SIMD)) {
+ tile_b_t h_tile_init;
+ global_b_payload_t h_tile_payload_init;
+ h_tile_payload_init.init(context_h_init, hidden_size, 1,
+ hidden_size, minigroup_offset, 0);
+
+ tile_b_t c_tile_init;
+ global_b_payload_t c_tile_payload_init;
+ c_tile_payload_init.init(context_c_init, hidden_size, 1,
+ hidden_size, minigroup_offset, 0);
+
+ tile_load<cache_hint::uncached, cache_hint::uncached>(
+ h_tile_init, h_tile_payload_init);
+ tile_load<cache_hint::uncached, cache_hint::uncached>(
+ c_tile_init, c_tile_payload_init);
+ h_tile.reg = xetla_cvt<dtype_acc, dtype_b, SIMD>(h_tile_init.reg);
+ c_tile.reg = xetla_cvt<dtype_acc, dtype_b, SIMD>(c_tile_init.reg);
+ tile_store(h_tile, h_tile_payload);
+ tile_store(c_tile, c_tile_payload);
+ }
+ xetla_fence<memory_kind::untyped_global>();
+ nbarrier.arrive_wait();
+
+ tile_c_t out_tile;
+ global_c_payload_t out_tile_payload;
+ out_tile_payload.init(hidden_history, hidden_size, seq_len,
+ hidden_size * directions,
+ hidden_size * dir_id + minigroup_offset, seq_start_y);
+
+ tile_acc_t figo_tile;
+ local_acc_payload_t figo_tile_payload;
+ figo_tile_payload.init(
+ slm_figo_offset, figo_size, 1, figo_size, local_id * SIMD, 0);
+
+ tile_acc_t f_tile;
+ local_acc_payload_t f_tile_payload;
+ f_tile_payload.init(slm_figo_offset, hidden_size, 1, hidden_size,
+ minigroup_offset, 0);
+
+ tile_acc_t i_tile;
+ local_acc_payload_t i_tile_payload;
+ i_tile_payload.init(slm_figo_offset + hidden_size * sizeof(dtype_acc),
+ hidden_size, 1, hidden_size, minigroup_offset, 0);
+
+ tile_acc_t g_tile;
+ local_acc_payload_t g_tile_payload;
+ g_tile_payload.init(
+ slm_figo_offset + hidden_size * 2 * sizeof(dtype_acc),
+ hidden_size, 1, hidden_size, minigroup_offset, 0);
+
+ tile_acc_t o_tile;
+ local_acc_payload_t o_tile_payload;
+ o_tile_payload.init(
+ slm_figo_offset + hidden_size * 3 * sizeof(dtype_acc),
+ hidden_size, 1, hidden_size, minigroup_offset, 0);
+
+#ifdef UNROLL_SEQ_LEN
+ for (int iii = 0; iii < seq_len / UNROLL_SEQ_LEN; iii++) {
+#pragma unroll
+ for (int ii = 0; ii < UNROLL_SEQ_LEN; ii++) {
+ int i = ii * UNROLL_SEQ_LEN + iii;
+#else
+ for (int i = 0; i < seq_len; i++) {
+#endif
+ tile_load<cache_hint::uncached, cache_hint::cached>(
+ x_tile, x_tile_payload);
+ x_tile_payload.template update_tdesc<tdesc_update_dir::y_dir>(
+ seq_inc);
+
+ typename gemm_t::matAcc_t matAcc;
+ gemm.run(matAcc);
+
+ figo_tile.reg = matAcc.reg + x_tile.reg;
+ if (local_id < (hidden_size * 2 / SIMD)
+ || local_id >= (hidden_size * 3 / SIMD)) {
+ figo_tile.reg
+ = xetla_sigmoid<dtype_acc, SIMD>(figo_tile.reg);
+ } else {
+ figo_tile.reg = xetla_tanh<dtype_acc, SIMD>(figo_tile.reg);
+ }
+ tile_store(figo_tile, figo_tile_payload);
+ xetla_fence<memory_kind::shared_local>();
+ nbarrier.arrive_wait();
+
+ if (local_id < (hidden_size / SIMD)) {
+ tile_load(f_tile, f_tile_payload);
+ tile_load(i_tile, i_tile_payload);
+ tile_load(g_tile, g_tile_payload);
+ tile_load(o_tile, o_tile_payload);
+
+ tile_load(c_tile, c_tile_payload);
+
+ c_tile.reg *= f_tile.reg;
+ i_tile.reg *= g_tile.reg;
+ c_tile.reg += i_tile.reg;
+
+ tile_store(c_tile, c_tile_payload);
+
+ h_tile.reg = xetla_tanh<dtype_acc, SIMD>(c_tile.reg)
+ * o_tile.reg;
+
+ tile_store(h_tile, h_tile_payload);
+
+ out_tile.reg
+ = xetla_cvt<dtype_c, dtype_acc, SIMD>(h_tile.reg);
+ tile_store<cache_hint::write_back, cache_hint::write_back>(
+ out_tile, out_tile_payload);
+ out_tile_payload
+ .template update_tdesc<tdesc_update_dir::y_dir>(
+ seq_inc);
+ }
+ xetla_fence<memory_kind::shared_local>();
+ nbarrier.arrive_wait();
+ }
+#ifdef UNROLL_SEQ_LEN
+ }
+#endif
+ if (local_id < (hidden_size / SIMD)) {
+ tile_load(h_tile, h_tile_payload);
+ tile_load(c_tile, c_tile_payload);
+
+ tile_c_t h_tile_out;
+ global_c_payload_t h_tile_payload_out;
+ h_tile_payload_out.init(context_h_out, hidden_size, 1, hidden_size,
+ minigroup_offset, 0);
+
+ tile_c_t c_tile_out;
+ global_c_payload_t c_tile_payload_out;
+ c_tile_payload_out.init(context_c_out, hidden_size, 1, hidden_size,
+ minigroup_offset, 0);
+
+ h_tile_out.reg = xetla_cvt<dtype_c, dtype_acc, SIMD>(h_tile.reg);
+ c_tile_out.reg = xetla_cvt<dtype_c, dtype_acc, SIMD>(c_tile.reg);
+
+ tile_store<cache_hint::write_back, cache_hint::write_back>(
+ h_tile_out, h_tile_payload_out);
+ tile_store<cache_hint::write_back, cache_hint::write_back>(
+ c_tile_out, c_tile_payload_out);
+ }
+ }
+};
diff --git a/src/plugins/intel_gpu/src/kernel_selector/cm_kernels/xetla_lstm_gemm.cpp b/src/plugins/intel_gpu/src/kernel_selector/cm_kernels/xetla_lstm_gemm.cpp
new file mode 100644
index 00000000000..4d1f1867e13
--- /dev/null
+++ b/src/plugins/intel_gpu/src/kernel_selector/cm_kernels/xetla_lstm_gemm.cpp
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (c) 2022-2025 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.
+ *******************************************************************************/
+
+namespace KERNEL_NAME {
+
+#include "include/xetla_lstm.h"
+
+#define dtype_a fp16
+#define dtype_b fp16
+#define dtype_c float
+#define dtype_acc float
+
+//#define INPUT_SIZE 64 // or 256
+#define hidden_size 128
+#define directions 2
+
+#define mem_layout_x mem_layout::row_major
+#define mem_layout_w mem_layout::col_major
+#define mem_layout_out mem_layout::row_major
+
+#define mem_space_x mem_space::global
+#define mem_space_w mem_space::global
+#define mem_space_out mem_space::global
+
+#define arch_tag gpu_arch::Xe
+
+_GENX_MAIN_ void KERNEL_NAME(
+ dtype_a *x [[type("svmptr_t")]],
+ dtype_b *W [[type("svmptr_t")]],
+ dtype_b *B [[type("svmptr_t")]],
+ int *sequence_lengths [[type("svmptr_t")]],
+ dtype_acc *out [[type("svmptr_t")]]) {
+ sycl::nd_item<3> item;
+ using gemm_t = __xetla_kernel_lstm_gemm<dtype_a, dtype_b, dtype_c,
+ dtype_acc, INPUT_SIZE, hidden_size, directions, mem_layout_x,
+ mem_layout_w, mem_layout_out, mem_space_x, mem_space_w,
+ mem_space_out, arch_tag>;
+ if constexpr (gemm_t::gemm_t::barrier_count != 0) {
+ cm_nbarrier_init(gemm_t::gemm_t::barrier_count);
+ }
+ if constexpr (gemm_t::gemm_t::slm_size != 0) {
+ cm_slm_init(gemm_t::gemm_t::slm_size);
+ }
+ gemm_t::run(item, x, W, B, sequence_lengths, out);
+}
+}
diff --git a/src/plugins/intel_gpu/src/kernel_selector/cm_kernels/xetla_lstm_loop.cpp b/src/plugins/intel_gpu/src/kernel_selector/cm_kernels/xetla_lstm_loop.cpp
new file mode 100644
index 00000000000..84eb4a88444
--- /dev/null
+++ b/src/plugins/intel_gpu/src/kernel_selector/cm_kernels/xetla_lstm_loop.cpp
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2022-2025 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.
+ *******************************************************************************/
+
+namespace KERNEL_NAME {
+
+#include "include/xetla_lstm.h"
+
+#define dtype_a float
+#define dtype_b fp16
+#define dtype_c fp16
+#define dtype_acc float
+
+//#define INPUT_SIZE 64 // or 256
+#define hidden_size 128
+#define directions 2
+
+#define mem_layout_x mem_layout::row_major
+#define mem_layout_r mem_layout::col_major
+#define mem_layout_out mem_layout::row_major
+
+#define mem_space_x mem_space::global
+#define mem_space_r mem_space::global
+#define mem_space_out mem_space::global
+
+#define arch_tag gpu_arch::Xe
+
+_GENX_MAIN_ void KERNEL_NAME(dtype_a *x [[type("svmptr_t")]],
+ dtype_b *initial_hidden_state [[type("svmptr_t")]],
+ dtype_b *initial_cell_state [[type("svmptr_t")]],
+ dtype_b *R [[type("svmptr_t")]],
+ int *sequence_lengths [[type("svmptr_t")]],
+ dtype_c *hidden_history [[type("svmptr_t")]],
+ dtype_c *hidden_state [[type("svmptr_t")]],
+ dtype_c *cell_state [[type("svmptr_t")]]) {
+ sycl::nd_item<3> item;
+ using loop_t = __xetla_kernel_lstm_loop<dtype_a, dtype_b, dtype_c,
+ dtype_acc, INPUT_SIZE, hidden_size, directions, mem_layout_x,
+ mem_layout_r, mem_layout_out, mem_space_x, mem_space_r,
+ mem_space_out, arch_tag>;
+ if constexpr (loop_t::barrier_count != 0) {
+ cm_nbarrier_init(loop_t::barrier_count);
+ }
+ if constexpr (loop_t::slm_size != 0) { cm_slm_init(loop_t::slm_size); }
+ loop_t::run(item, x, initial_hidden_state, initial_cell_state, R,
+ sequence_lengths, hidden_history, hidden_state, cell_state);
+}
+}
diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernel_base_cm.h b/src/plugins/intel_gpu/src/kernel_selector/kernel_base_cm.h
index 6e2c8e00fe5..0d46cf7b4bf 100644
--- a/src/plugins/intel_gpu/src/kernel_selector/kernel_base_cm.h
+++ b/src/plugins/intel_gpu/src/kernel_selector/kernel_base_cm.h
@@ -27,8 +27,7 @@ protected:
if (codes.size()) {
kernel_string->str = codes[0];
- kernel_string->jit = "#include <cm/cm.h>\n#include <cm/cmtl.h>\n";
- kernel_string->jit += jit.first;
+ kernel_string->jit = jit.first;
kernel_string->undefs = jit.second;
kernel_string->options = " -cmc ";
@@ -39,5 +38,18 @@ protected:
return kernel_string;
}
+ std::pair<std::string, std::string> CreateJit(const JitConstants& constants) const {
+ std::string defs, undefs;
+ for (auto& definition : constants.GetDefinitions()) {
+ auto &name = definition.first;
+ auto &value = definition.second;
+ defs += "\n#define " + name + " " + value + "\n";
+ undefs += "\n#ifdef " + name + "\n";
+ undefs += "\n#undef " + name + "\n";
+ undefs += "\n#endif\n";
+ }
+
+ return std::pair<std::string, std::string>(defs, undefs);
+ }
};
} // namespace kernel_selector
diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/lstm/cm/lstm_seq_cm.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/lstm/cm/lstm_seq_cm.cpp
new file mode 100644
index 00000000000..35170e0b19d
--- /dev/null
+++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/lstm/cm/lstm_seq_cm.cpp
@@ -0,0 +1,178 @@
+// Copyright (C) 2018-2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "lstm_seq_cm.h"
+#include "kernel_selector_utils.h"
+#include "common_tools.h"
+
+namespace kernel_selector {
+
+ParamsKey LSTMSeqKernel_CM::GetSupportedKey() const {
+ ParamsKey k;
+ k.EnableInputDataType(Datatype::INT32);
+ k.EnableInputDataType(Datatype::F16);
+ k.EnableInputDataType(Datatype::F32);
+ k.EnableOutputDataType(Datatype::F16);
+ k.EnableOutputDataType(Datatype::F32);
+ k.EnableDifferentTypes();
+ k.EnableInputLayout(DataLayout::bfyx);
+ k.EnableAllOutputLayout();
+ k.EnableTensorOffset();
+ k.EnableTensorPitches();
+ k.EnableBatching();
+ return k;
+}
+
+KernelsData LSTMSeqKernel_CM::GetKernelsData(const Params& params) const {
+ if (!Validate(params)) {
+ return {};
+ }
+ auto shape = GetShape(params);
+
+ KernelData kd = KernelData::Default<lstm_params>(params, 2);
+ auto options = std::string(" -Qxcm_jit_option=-DPASTokenReduction "
+ " -mllvm --vc-disable-indvars-opt=true "
+ " /Qxcm_jit_option=-enableBCR "
+ " -fcm-pointer /Qxcm_doubleGRF "
+ " -DXETLA_CODE_BASE=__CM__ ");
+ auto shape_key = std::string {"is"} + std::to_string(shape.input_size);
+ auto gemm_entry_point = std::string {"xetla_lstm_gemm_"} + shape_key;
+ auto loop_entry_point = std::string {"xetla_lstm_loop_"} + shape_key;
+
+ auto constants = JitConstants{};
+ constants.AddConstant({MakeJitConstant("INPUT_SIZE", std::to_string(shape.input_size))});
+
+ constants.AddConstant({MakeJitConstant("KERNEL_NAME", gemm_entry_point)});
+ auto gemm_jit = CreateJit(constants);
+
+ constants.RemoveConstant("KERNEL_NAME");
+ constants.AddConstant({MakeJitConstant("KERNEL_NAME", loop_entry_point)});
+ auto loop_jit = CreateJit(constants);
+
+
+ // Request temporary buffers
+ kd.internalBufferDataType = Datatype::F32;
+ auto temp_buffer_size = shape.num_dir * shape.seq_len * shape.batch_size * shape.hidden_size * shape.num_gates * sizeof(float);
+ kd.internalBufferSizes.push_back(temp_buffer_size);
+
+ auto& gemm_part = kd.kernels[0];
+ gemm_part.params.arguments.push_back({ArgumentDescriptor::Types::INPUT, 0});
+ gemm_part.params.arguments.push_back({ArgumentDescriptor::Types::INPUT, 3});
+ gemm_part.params.arguments.push_back({ArgumentDescriptor::Types::INPUT, 5});
+ gemm_part.params.arguments.push_back({ArgumentDescriptor::Types::INPUT, 6});
+ gemm_part.params.arguments.push_back({ArgumentDescriptor::Types::INTERNAL_BUFFER, 0});
+
+ // Calc gws, lws
+ {
+ size_t matrix_m_ih = shape.seq_len;
+ size_t matrix_n_ih = shape.hidden_size * shape.num_gates;
+
+ size_t wg_m_ih = 40;
+ size_t wg_n_ih = 256;
+
+ size_t sg_m_ih = 24;
+ size_t sg_n_ih = 32;
+
+ size_t local_kslicing_ih = 1;
+ size_t subgroup_range_m = (wg_m_ih + sg_m_ih - 1) / sg_m_ih;
+ size_t subgroup_range_n = (wg_n_ih + sg_n_ih - 1) / sg_n_ih;
+
+ size_t group_range_m = (matrix_m_ih + wg_m_ih - 1) / wg_m_ih;
+ size_t group_range_n = (matrix_n_ih + wg_n_ih - 1) / wg_n_ih;
+
+ gemm_part.params.workGroups.local = {subgroup_range_n, subgroup_range_m, local_kslicing_ih};
+ gemm_part.params.workGroups.global = {group_range_n*subgroup_range_n, group_range_m*subgroup_range_m, shape.num_dir*local_kslicing_ih};
+ }
+ gemm_part.code.kernelString = GetKernelString("xetla_lstm_gemm", gemm_jit, gemm_entry_point);
+ gemm_part.code.kernelString->options += options;
+ gemm_part.code.kernelString->batch_compilation = true;
+
+ auto& loop_part = kd.kernels[1];
+ loop_part.params.arguments.push_back({ArgumentDescriptor::Types::INTERNAL_BUFFER, 0});
+ loop_part.params.arguments.push_back({ArgumentDescriptor::Types::INPUT, 1});
+ loop_part.params.arguments.push_back({ArgumentDescriptor::Types::INPUT, 2});
+ loop_part.params.arguments.push_back({ArgumentDescriptor::Types::INPUT, 4});
+ loop_part.params.arguments.push_back({ArgumentDescriptor::Types::INPUT, 6});
+ loop_part.params.arguments.push_back({ArgumentDescriptor::Types::OUTPUT, 0});
+ loop_part.params.arguments.push_back({ArgumentDescriptor::Types::OUTPUT, 1});
+ loop_part.params.arguments.push_back({ArgumentDescriptor::Types::OUTPUT, 2});
+
+ // Calc gws, lws
+ {
+ size_t wg_m_hh = 1;
+ size_t wg_n_hh = shape.hidden_size * shape.num_gates;
+
+ size_t sg_m_hh = 1;
+ size_t sg_n_hh = 16;
+
+ size_t matrix_m_hh = 1;
+ size_t matrix_n_hh = shape.hidden_size * shape.num_gates;
+
+ size_t group_range_m = (matrix_m_hh + wg_m_hh - 1) / wg_m_hh;
+ size_t group_range_n = (matrix_n_hh + wg_n_hh - 1) / wg_n_hh;
+ size_t subgroup_range_m = (wg_m_hh + sg_m_hh - 1) / sg_m_hh;
+ size_t subgroup_range_n = (wg_n_hh + sg_n_hh - 1) / sg_n_hh;
+
+ loop_part.params.workGroups.local = {subgroup_range_n, subgroup_range_m, 1};
+ loop_part.params.workGroups.global = {group_range_n*subgroup_range_n, group_range_m*subgroup_range_m, shape.num_dir};
+ }
+ loop_part.code.kernelString = GetKernelString("xetla_lstm_loop", loop_jit, loop_entry_point);
+ loop_part.code.kernelString->options += options;
+ loop_part.code.kernelString->batch_compilation = true;
+
+ return {kd};
+}
+
+KernelsPriority LSTMSeqKernel_CM::GetKernelsPriority(const Params& /*params*/) const {
+ return FORCE_PRIORITY_1;
+}
+
+bool LSTMSeqKernel_CM::Validate(const Params& p) const {
+ const lstm_params& orgParams = static_cast<const lstm_params&>(p);
+ const auto expected_inputs = 7;
+
+ const auto &seq_lengths = orgParams.inputs[expected_inputs-1];
+ if (seq_lengths.GetLayout() != DataLayout::bfyx || seq_lengths.GetDType() != kernel_selector::Datatype::INT32) {
+ return false;
+ }
+ for (int i = 0; i < expected_inputs - 1; i++) {
+ const auto &dtensor = orgParams.inputs[i];
+ if (dtensor.GetLayout() != DataLayout::bfyx || dtensor.GetDType() != kernel_selector::Datatype::F16) {
+ return false;
+ }
+ }
+
+ if (orgParams.activations.size() != 3 ||
+ orgParams.activations[0].function != ActivationFunction::LOGISTIC ||
+ orgParams.activations[1].function != ActivationFunction::HYPERBOLIC_TAN ||
+ orgParams.activations[2].function != ActivationFunction::HYPERBOLIC_TAN) {
+ return false;
+ }
+
+ auto shape = GetShape(p);
+ if (shape.hidden_size != 128 || shape.batch_size != 1 || shape.num_dir != 2 ||
+ (shape.input_size != 64 && shape.input_size != 256)) {
+ return false;
+ }
+
+ return true;
+}
+LSTMSeqKernel_CM::lstm_shape LSTMSeqKernel_CM::GetShape(const Params& params) const {
+ const lstm_params& orgParams = static_cast<const lstm_params&>(params);
+ const auto &x = orgParams.inputs[0];
+ const auto &ini_hidden = orgParams.inputs[1];
+ const auto &out = orgParams.outputs[0];
+
+ lstm_shape shape;
+ shape.num_gates = 4; // always 4
+ shape.batch_size = x.Batch().v;
+ shape.hidden_size = ini_hidden.Y().v;
+ shape.input_size = x.Y().v;
+ shape.seq_len = out.Y().v;
+ shape.num_dir = ini_hidden.Feature().v;
+
+ return shape;
+}
+
+} // namespace kernel_selector
diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/lstm/cm/lstm_seq_cm.h b/src/plugins/intel_gpu/src/kernel_selector/kernels/lstm/cm/lstm_seq_cm.h
new file mode 100644
index 00000000000..d73fac8a167
--- /dev/null
+++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/lstm/cm/lstm_seq_cm.h
@@ -0,0 +1,26 @@
+// Copyright (C) 2018-2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include "kernel_base_cm.h"
+#include "lstm/lstm_kernel_base.h"
+
+namespace kernel_selector {
+class LSTMSeqKernel_CM : public KernelBaseCM {
+public:
+ LSTMSeqKernel_CM() : KernelBaseCM("lstm_gemm_loop") {}
+ virtual ~LSTMSeqKernel_CM() {}
+
+ KernelsData GetKernelsData(const Params& params) const override;
+ KernelsPriority GetKernelsPriority(const Params& params) const override;
+ ParamsKey GetSupportedKey() const override;
+ bool Validate(const Params& p) const override;
+private:
+ struct lstm_shape{
+ size_t batch_size, input_size, hidden_size, seq_len, num_dir, num_gates;
+ };
+ lstm_shape GetShape(const Params& params) const;
+};
+} // namespace kernel_selector
diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/lstm/cm/lstm_seq_cm_kernel_selector.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/lstm/cm/lstm_seq_cm_kernel_selector.cpp
new file mode 100644
index 00000000000..de9bfec2205
--- /dev/null
+++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/lstm/cm/lstm_seq_cm_kernel_selector.cpp
@@ -0,0 +1,17 @@
+// Copyright (C) 2018-2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "lstm_seq_cm_kernel_selector.h"
+#include "lstm_seq_cm.h"
+
+
+namespace kernel_selector {
+lstm_seq_cm_kernel_selector::lstm_seq_cm_kernel_selector() {
+ Attach<LSTMSeqKernel_CM>();
+}
+
+KernelsData lstm_seq_cm_kernel_selector::GetBestKernels(const Params& params) const {
+ return GetNaiveBestKernel(params, KernelType::LSTM_SEQ_CELL);
+}
+} // namespace kernel_selector
diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/lstm/cm/lstm_seq_cm_kernel_selector.h b/src/plugins/intel_gpu/src/kernel_selector/kernels/lstm/cm/lstm_seq_cm_kernel_selector.h
new file mode 100644
index 00000000000..1aec010859f
--- /dev/null
+++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/lstm/cm/lstm_seq_cm_kernel_selector.h
@@ -0,0 +1,23 @@
+// Copyright (C) 2018-2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include "kernel_selector.h"
+
+namespace kernel_selector {
+class lstm_seq_cm_kernel_selector : public kernel_selector_base {
+public:
+ static lstm_seq_cm_kernel_selector& Instance() {
+ static lstm_seq_cm_kernel_selector instance_;
+ return instance_;
+ }
+
+ lstm_seq_cm_kernel_selector();
+
+ virtual ~lstm_seq_cm_kernel_selector() {}
+
+ KernelsData GetBestKernels(const Params& params) const override;
+};
+} // namespace kernel_selector
diff --git a/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp b/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp
index f6bf70c77c1..6fe6cb14cd5 100644
--- a/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp
+++ b/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp
@@ -279,6 +279,7 @@ static bool is_decompression_multiply(const std::shared_ptr<const ov::Node> node
namespace cldnn {
extern bool query_microkernels_supported(cldnn::engine& e, const cldnn::ExecutionConfig& config);
+extern bool check_cm_jit_support(cldnn::engine& e, const cldnn::ExecutionConfig& config);
} // namespace cldnn
namespace ov::intel_gpu {
@@ -531,6 +532,50 @@ void TransformationsPipeline::apply(std::shared_ptr<ov::Model> func) {
manager.register_pass<ov::pass::BidirectionalRNNSequenceDecomposition>();
}
+ // Disable Bidirectional LSTM decomposition if node is supported by XeTLA
+ pass_config->set_callback<ov::pass::BidirectionalLSTMSequenceDecomposition>(
+ [&](const_node_ptr &node) -> bool {
+ const auto &lstm_seq = ov::as_type_ptr<const ov::op::v5::LSTMSequence>(node);
+
+ auto &engine = m_context->get_engine();
+ if (!cldnn::check_cm_jit_support(engine, config) || engine.get_device_info().arch != cldnn::gpu_arch::xe2) {
+ return false;
+ }
+
+ if (lstm_seq->get_clip() > 0.f) {
+ return false;
+ }
+
+ const auto &activations = lstm_seq->get_activations();
+ if (activations.size() != 3 ||
+ activations[0].compare("sigmoid") != 0 || activations[1].compare("tanh") != 0 || activations[2].compare("tanh") != 0) {
+ return false;
+ }
+
+ if (lstm_seq->get_output_element_type(0) != ov::element::f16) {
+ return false;
+ }
+
+ if (lstm_seq->is_dynamic()) {
+ return false;
+ }
+ const auto &input = lstm_seq->get_input_shape(0);
+ const auto &output = lstm_seq->get_output_shape(0);
+ if (input.size() != 3 || output.size() != 4) {
+ return false;
+ }
+ auto batch_size = input[0];
+ auto input_size = input[2];
+ auto num_dir = output[1];
+ auto hidden_size = output[3];
+
+ if (hidden_size != 128 || batch_size != 1 || num_dir != 2 || (input_size != 64 && input_size != 256)) {
+ return false;
+ }
+
+ return true;
+ });
+
manager.register_pass<ConvertShapeOf1To3>();
manager.register_pass<ov::pass::ConvertNMS1ToNMS9>();
manager.register_pass<ov::pass::ConvertNMS3ToNMS9>();
diff --git a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/lstm_sequence.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/lstm_sequence.cpp
index a9b7a0b4dca..77554fd0533 100644
--- a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/lstm_sequence.cpp
+++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/lstm_sequence.cpp
@@ -94,4 +94,28 @@ INSTANTIATE_TEST_SUITE_P(smoke_LSTMSequenceCommonClip, LSTMSequenceTest,
::testing::Values(ov::test::utils::DEVICE_GPU)),
LSTMSequenceTest::getTestCaseName);
+
+std::vector<size_t> seq_lengths_cm{2};
+std::vector<size_t> batch_cm{1};
+std::vector<size_t> hidden_size_cm{128};
+std::vector<size_t> input_size_cm{64, 256};
+std::vector<std::vector<std::string>> activations_cm = {{"sigmoid", "tanh", "tanh"}};
+std::vector<float> clip_cm{0};
+std::vector<ov::element::Type> netPrecisions_cm = {ov::element::f16};
+
+INSTANTIATE_TEST_SUITE_P(LSTMSequenceCM, LSTMSequenceTest,
+ ::testing::Combine(
+ ::testing::Values(ov::test::utils::SequenceTestsMode::PURE_SEQ),
+ ::testing::ValuesIn(seq_lengths_cm),
+ ::testing::ValuesIn(batch_cm),
+ ::testing::ValuesIn(hidden_size_cm),
+ ::testing::ValuesIn(input_size_cm),
+ ::testing::ValuesIn(activations_cm),
+ ::testing::ValuesIn(clip_cm),
+ ::testing::Values(ov::op::RecurrentSequenceDirection::BIDIRECTIONAL),
+ ::testing::Values(ov::test::utils::InputLayerType::CONSTANT),
+ ::testing::ValuesIn(netPrecisions_cm),
+ ::testing::Values(ov::test::utils::DEVICE_GPU)),
+ LSTMSequenceTest::getTestCaseName);
+
} // namespace
diff --git a/src/plugins/intel_gpu/thirdparty/CMakeLists.txt b/src/plugins/intel_gpu/thirdparty/CMakeLists.txt
index 475e9213ecf..b4c1e3f71a7 100644
--- a/src/plugins/intel_gpu/thirdparty/CMakeLists.txt
+++ b/src/plugins/intel_gpu/thirdparty/CMakeLists.txt
@@ -2,6 +2,8 @@
# SPDX-License-Identifier: Apache-2.0
#
+set(XETLA_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/xetla/include/" CACHE PATH "Path to XeTLA headers")
+
#
# oneDNN for GPU plugin
#
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/LICENSE b/src/plugins/intel_gpu/thirdparty/xetla/LICENSE
new file mode 100644
index 00000000000..46808898b73
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/LICENSE
@@ -0,0 +1,193 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ ============================================================================
+
+ Copyright (c) 2022-2023 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.
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/README.md b/src/plugins/intel_gpu/thirdparty/xetla/README.md
new file mode 100644
index 00000000000..d124ba902d2
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/README.md
@@ -0,0 +1,26 @@
+# Intel® Xe Templates for Linear Algebra
+
+This is the bare-bones version of Intel® Xe Templates for Linear Algebra (Intel® XeTLA) which only supports CM. If you want to contribute to XeTLA or use full version, please contact Yershov, Dmitry B.
+
+## Security
+
+See Intel's [Security Center](https://www.intel.com/content/www/us/en/security-center/default.html)
+for information on how to report a potential security issue or vulnerability.
+
+See also: [Security Policy](/SECURITY.md)
+
+## Copyright
+
+Copyright (c) 2022-2023 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](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.
+
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/SECURITY.md b/src/plugins/intel_gpu/thirdparty/xetla/SECURITY.md
new file mode 100755
index 00000000000..c560937cc93
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/SECURITY.md
@@ -0,0 +1,6 @@
+[README](/README.md#Security) > **Security Policy**
+# Security Policy
+Intel is committed to rapidly addressing security vulnerabilities affecting our customers and providing clear guidance on the solution, impact, severity and mitigation.
+
+## Reporting a Vulnerability
+Please report any security vulnerabilities in this project [utilizing the guidelines here](https://www.intel.com/content/www/us/en/security-center/vulnerability-handling-guidelines.html).
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/common/common.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/common/common.hpp
new file mode 100644
index 00000000000..0fb26d30e0e
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/common/common.hpp
@@ -0,0 +1,23 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#include "common/core/core.hpp"
+#include "common/utils/utils.hpp"
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/arch_config.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/arch_config.hpp
new file mode 100644
index 00000000000..43784d6cf90
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/arch_config.hpp
@@ -0,0 +1,93 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#ifdef _WIN32
+#include "../../../common/core/cm/common.hpp"
+#else
+#include "common/core/cm/common.hpp"
+#endif
+
+namespace gpu::xetla {
+
+/// @addtogroup xetla_core_arch_config
+/// @{
+
+template <msg_type message_type, gpu_arch arch_tag>
+struct load_store_attr_t {};
+template <>
+struct load_store_attr_t<msg_type::block_2d, gpu_arch::Xe> {
+ static constexpr uint32_t max_load_height_in_elem = 32;
+ static constexpr uint32_t max_load_width_in_bytes = 64;
+ static constexpr uint32_t max_trans_load_width_in_bytes = 32;
+ static constexpr uint32_t special_trans_load_width_in_bytes = 32;
+ static constexpr uint32_t max_vnni_load_width_in_elems = 16;
+ static constexpr uint32_t min_vnni_load_height_in_bytes = 4;
+
+ static constexpr uint32_t max_store_height_in_elem = 8;
+ static constexpr uint32_t max_store_width_in_bytes = 64;
+
+ static constexpr uint32_t max_load_size_in_bytes = 2048;
+ static constexpr uint32_t max_store_size_in_bytes = 512;
+
+ static constexpr uint32_t special_prefetch_width_in_bytes = 64;
+
+ static constexpr uint32_t cache_line_size_in_bytes = 64;
+ static constexpr uint32_t alignment_in_bytes = 8;
+};
+
+template <gpu_arch arch_tag>
+struct mma_attr_t {};
+template <>
+struct mma_attr_t<gpu_arch::Xe> {
+ static constexpr uint32_t mma_m_in_elem = 8;
+ static constexpr uint32_t mma_n_in_elem = 16;
+ static constexpr uint32_t mma_k_in_bytes = 32;
+};
+
+template <grf_mode grf_num_mode, gpu_arch arch_tag>
+struct register_attr_t {};
+template <grf_mode grf_num_mode>
+struct register_attr_t<grf_num_mode, gpu_arch::Xe> {
+ static constexpr uint32_t acc_reg_in_bytes
+ = (grf_num_mode == grf_mode::normal) ? 4 * 64 : 8 * 64;
+ static constexpr uint32_t grf_in_bytes
+ = (grf_num_mode == grf_mode::normal) ? 128 * 64 : 256 * 64;
+ static constexpr uint32_t reg_in_bytes = 64;
+};
+
+template <gpu_arch arch_tag>
+struct arch_attr_t {};
+template <>
+struct arch_attr_t<gpu_arch::Xe> {
+ template <msg_type message_type = msg_type::block_2d>
+ using load_store_attr = load_store_attr_t<message_type, gpu_arch::Xe>;
+
+ template <grf_mode grf_num_mode = grf_mode::double_grf>
+ using register_attr = register_attr_t<grf_num_mode, gpu_arch::Xe>;
+
+ using mma_attr = mma_attr_t<gpu_arch::Xe>;
+
+ static constexpr uint32_t max_wg_num = 64;
+};
+
+/// @} xetla_core_arch_config
+
+} // namespace gpu::xetla
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/barrier.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/barrier.hpp
new file mode 100644
index 00000000000..37ec95b1372
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/barrier.hpp
@@ -0,0 +1,73 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#ifdef _WIN32
+#include "../../../common/core/cm/common.hpp"
+#else
+#include "common/core/cm/common.hpp"
+#endif
+
+namespace gpu::xetla {
+
+/// @addtogroup xetla_core_barrier
+/// @{
+
+/// @brief Initialize the number of named barrier index for a kernel.
+/// Available only on PVC. Only need to initialize once at the beginning.
+///
+/// @tparam NbarCount - number of named barriers.
+template <uint8_t NbarCount>
+__XETLA_API void xetla_nbarrier_init() {
+ cm_nbarrier_init(NbarCount);
+}
+
+/// @brief Perform signal operation for the given named barrier id.
+/// Available only on PVC.
+///
+/// @param barrier_id [in] is the named barrier id.
+///
+/// @param producer_consumer_mode [in] is 2-bit flag to indicate if it's
+/// producer-consumer mode(0x0) or producer mode (0x1) or consumer mode (0x2).
+/// User must ensure the input value is set correctly and higher order bits are cleared.
+///
+/// @param num_producers [in] is the number of producers.
+///
+/// @param num_consumers [in] is the number of consumers.
+__XETLA_API void named_barrier_signal(uint8_t barrier_id,
+ uint8_t producer_consumer_mode, uint32_t num_producers,
+ uint32_t num_consumers) {
+
+ cm_nbarrier_signal((uint32_t)barrier_id, (uint32_t)producer_consumer_mode,
+ num_producers, num_consumers);
+}
+
+/// @brief Wait on a named barrier.
+/// Available only on PVC
+///
+/// @param barrier_id [in] is the named barrier id.
+/// It’s value cannot exceed the total count of initialized named barriers.
+__XETLA_API void named_barrier_wait(uint8_t barrier_id) {
+ cm_nbarrier_wait(barrier_id);
+}
+
+/// @} xetla_core_barrier
+
+} // namespace gpu::xetla
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/base_consts.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/base_consts.hpp
new file mode 100644
index 00000000000..338acf45add
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/base_consts.hpp
@@ -0,0 +1,35 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#ifdef _WIN32
+#include "../../../common/core/cm/common.hpp"
+#else
+#include "common/core/cm/common.hpp"
+#endif
+
+namespace gpu::xetla {
+
+/// @addtogroup xetla_core_base_types
+/// @{
+
+/// @} xetla_core_base_types
+
+} // namespace gpu::xetla
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/base_ops.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/base_ops.hpp
new file mode 100644
index 00000000000..96892630133
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/base_ops.hpp
@@ -0,0 +1,70 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#ifdef _WIN32
+#include "../../../common/core/cm/common.hpp"
+#else
+#include "common/core/cm/common.hpp"
+#endif
+
+namespace gpu::xetla {
+
+/// @addtogroup xetla_core_base_ops
+/// @{
+
+/// @brief xetla format.
+/// Alias to CM `.format<...>()`;
+/// @note usage:
+/// ```
+/// [xetla_vector|xetla_vector_ref|xetla_matrix_ref].xetla_format<type>(): returns a reference to the calling object interpreted as a new xetla_vector_ref (1D).
+///
+/// [xetla_vector|xetla_vector_ref|xetla_matrix_ref].xetla_format<type, rows, columns>(): returns a reference to the calling object interpreted as a new xetla_matrix_ref (2D).
+/// ```
+///
+#define xetla_format format
+
+/// @brief xetla select.
+/// Alias to CM `.select<...>()`;
+/// @note usage:
+/// ```
+/// [xetla_vector|xetla_vector_ref].xetla_select<size, stride>(uint16_t offset=0): returns a reference to the sub-vector starting from the offset-th element.
+///
+/// [xetla_matrix_ref].xetla_select<size_y, stride_y, size_x, stride_x>(uint16_t offset_y=0, uint16_t offset_x=0): returns a reference to the sub-matrix starting from the (offset_y, offset_x)-th element.
+/// ```
+///
+#define xetla_select select
+
+/// @brief xetla merge.
+/// Alias to `.merge(...)`. Replaces part of the underlying data with the one taken from the other object according to a mask.
+/// @note usage:
+/// ```
+/// [xetla_vector|xetla_vector_ref].xetla_merge(xetla_vector<Ty, N>Val, xetla_mask<N>mask): only elements in lanes with non-zero mask predicate are assigned from corresponding Val elements.
+///
+/// [xetla_vector|xetla_vector_ref].xetla_merge(xetla_vector<Ty, N>Val1, xetla_vector<Ty, N>Val2, xetla_mask<N>mask): non-zero in a mask's lane tells to take corresponding element from Val1, zero - from Val2.
+/// ```
+///
+#define xetla_merge merge
+
+// TODO add replicate, iselect
+
+/// @} xetla_core_base_ops
+
+} // namespace gpu::xetla
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/base_types.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/base_types.hpp
new file mode 100644
index 00000000000..297cd941623
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/base_types.hpp
@@ -0,0 +1,242 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#ifdef _WIN32
+#include "../../../common/core/cm/common.hpp"
+#else
+#include "common/core/cm/common.hpp"
+#endif
+
+namespace gpu::xetla {
+
+/// @addtogroup xetla_core_base_types
+/// @{
+
+/// @brief xetla bf16 data type.
+/// The difference between bf16 and fp32 is:
+///
+/// fp32: 0_00000000_00000000000000000000000
+///
+/// bf16: 0_00000000_0000000
+/// @note
+/// The member function in bf16 class is only used in host side.
+/// For device side, we will automatically convert it to its native type.
+/// @see native_type_t
+///
+struct bf16 {
+ uint16_t data;
+
+ operator float() const {
+ uint32_t temp = data;
+ temp = temp << 0x10;
+ return *reinterpret_cast<float *>(&temp);
+ }
+ bf16() = default;
+ bf16(float val) { data = (*reinterpret_cast<uint32_t *>(&val)) >> 0x10; }
+
+ bf16 &operator=(float val) {
+ this->data = (*reinterpret_cast<uint32_t *>(&val)) >> 0x10;
+ return *this;
+ }
+};
+
+using fp16 = half;
+
+/// @brief xetla tf32 data type.
+/// The difference between tf32 and fp32 is:
+///
+/// fp32: 0_00000000_00000000000000000000000
+///
+/// tf32: 0_00000000_0000000000
+/// @note
+/// The member function in tf32 class is only used in host side.
+/// For device side, we will automatically convert it to its native type.
+/// @see native_type_t
+///
+struct tf32 {
+ uint32_t data;
+ operator float() const {
+ uint32_t temp = data;
+ return *reinterpret_cast<float *>(&temp);
+ }
+
+ tf32(float val) {
+ data = (*reinterpret_cast<uint32_t *>(&val)) & 0xFFFFE000;
+ }
+
+ tf32 &operator=(float val) {
+ this->data = (*reinterpret_cast<uint32_t *>(&val)) & 0xFFFFE000;
+ return *this;
+ }
+};
+
+template <typename T>
+struct get_packed_num {
+ static constexpr uint32_t value = 1;
+};
+
+/// @brief Used to check if the type is xetla internal data type
+/// @tparam T is the data type
+template <typename T>
+struct is_internal_type {
+ static constexpr bool value = std::is_same<remove_const_t<T>, bf16>::value
+ || std::is_same<remove_const_t<T>, tf32>::value;
+};
+
+/// @brief Used to check if the type is floating_point.
+/// @tparam T is the data type
+template <typename T>
+struct is_floating_point {
+ static constexpr bool value = std::is_same<remove_const_t<T>, bf16>::value
+ || std::is_same<remove_const_t<T>, fp16>::value
+ || std::is_same<remove_const_t<T>, tf32>::value
+ || std::is_same<remove_const_t<T>, float>::value
+ || std::is_same<remove_const_t<T>, double>::value;
+};
+
+/// @brief Used to check if the type is floating_point.
+/// @tparam T is the data type
+template <typename T>
+struct is_integral {
+ static constexpr bool value = std::is_same<remove_const_t<T>, int8_t>::value
+ || std::is_same<remove_const_t<T>, uint8_t>::value
+ || std::is_same<remove_const_t<T>, int16_t>::value
+ || std::is_same<remove_const_t<T>, uint16_t>::value
+ || std::is_same<remove_const_t<T>, int32_t>::value
+ || std::is_same<remove_const_t<T>, uint32_t>::value
+ || std::is_same<remove_const_t<T>, int64_t>::value
+ || std::is_same<remove_const_t<T>, uint64_t>::value;
+};
+
+/// @brief Set the native data type of T
+/// @tparam T is the data type
+template <typename T>
+struct native_type {
+ using type = T;
+};
+
+/// @brief Set bfloat16 as the native data type of bf16
+template <>
+struct native_type<bf16> {
+ using type = short;
+};
+
+/// @brief Set uint32_t as the native data type of tf32
+template <>
+struct native_type<tf32> {
+ using type = int;
+};
+
+/// @brief Return the native data type of T
+template <typename T>
+using native_type_t = typename native_type<T>::type;
+
+/// @brief Get the unit representation of type T
+template <typename T>
+struct uint_type {
+ static constexpr bool is_uint8 = sizeof(T) == 1;
+ static constexpr bool is_uint16 = sizeof(T) == 2;
+ static constexpr bool is_uint32 = sizeof(T) == 4;
+ static constexpr bool is_uint64 = sizeof(T) == 8;
+ using type = typename std::conditional<is_uint8, uint8_t,
+ typename std::conditional<is_uint16, uint16_t,
+ typename std::conditional<is_uint32, uint32_t,
+ typename std::conditional<is_uint64, uint64_t,
+ void>::type>::type>::type>::type;
+};
+
+/// @brief Get the unit representation based on Size
+template <int Size>
+struct get_uint_type {
+ static constexpr bool is_uint8 = Size == 1;
+ static constexpr bool is_uint16 = Size == 2;
+ static constexpr bool is_uint32 = Size == 4;
+ static constexpr bool is_uint64 = Size == 8;
+ using type = typename std::conditional<is_uint8, uint8_t,
+ typename std::conditional<is_uint16, uint16_t,
+ typename std::conditional<is_uint32, uint32_t,
+ typename std::conditional<is_uint64, uint64_t,
+ void>::type>::type>::type>::type;
+};
+/// @brief Return the uint representation of type T
+template <typename T>
+using uint_type_t = typename uint_type<T>::type;
+
+/// @brief Return the uint representation based on Size
+template <int Size>
+using get_uint_type_t = typename get_uint_type<Size>::type;
+
+/// @brief wrapper for xetla_vector.
+/// Alias to CM `vector`.
+/// @tparam Ty data type in xetla_vector.
+/// @tparam N data length in xetla_vector.
+///
+template <typename Ty, uint32_t N>
+using xetla_vector = vector<native_type_t<Ty>, N>;
+
+/// @brief wrapper for xetla_mask.
+/// Alias to CM `vector<uint16_t, N>`.
+/// @tparam N data length in xetla_mask.
+///
+template <uint32_t N>
+using xetla_mask = vector<uint16_t, N>;
+
+/// @brief wrapper for xetla_mask_int.
+/// Alias to CM integer as packed mask.
+/// @tparam N number of bits as mask in xetla_mask_int.
+///
+template <uint32_t N>
+using xetla_mask_int = uint32_t;
+
+/// Alias to `(empty)` if go with CM path.
+/// @see gpu::xetla::core::xetla_matrix_ref gpu::xetla::core::xetla_vector_ref
+#define __REF__
+
+/// @brief wrapper for xetla_vector_ref.
+/// Alias to `vector_ref` if go with CM path.
+/// @note Need to be used together with `__REF__`, i.e. `"xetla_vector_ref __REF__"` is the full declaration of xetla vector reference.
+/// @tparam Ty data type in xetla_vector.
+/// @tparam N data length in xetla_vector.
+///
+template <typename Ty, uint32_t N>
+using xetla_vector_ref = vector_ref<native_type_t<Ty>, N>;
+
+///
+/// @brief Description of nd tensor descriptor for load and store.
+///
+using xetla_tdescriptor = xetla_vector<uint32_t, 16>;
+
+/// @brief Alias to xetla_vector<uint32_t, 16> reference.
+#define xetla_tdescriptor_ref xetla_vector_ref<uint32_t, 16> __REF__
+
+/// @brief wrapper for xetla_matrix_ref.
+/// Alias to `matrix_ref` if go with CM path.
+/// @note Need to be used together with `__REF__`, i.e. `"xetla_matrix_ref __REF__"` is the full declaration of xetla matrix reference.
+/// @tparam Ty data type in xetla_matrix_ref.
+/// @tparam N1 row num in xetla_matrix_ref.
+/// @tparam N2 col num in xetla_matrix_ref.
+///
+template <typename Ty, uint32_t N1, uint32_t N2>
+using xetla_matrix_ref = matrix_ref<native_type_t<Ty>, N1, N2>;
+
+/// @} xetla_core_base_types
+
+} // namespace gpu::xetla
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/bit_mask_manipulation.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/bit_mask_manipulation.hpp
new file mode 100644
index 00000000000..6e17aa558fe
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/bit_mask_manipulation.hpp
@@ -0,0 +1,287 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#ifdef _WIN32
+#include "../../../common/core/cm/base_types.hpp"
+#include "../../../common/core/cm/common.hpp"
+#else
+#include "common/core/cm/base_types.hpp"
+#include "common/core/cm/common.hpp"
+#endif
+
+namespace gpu::xetla {
+
+/// @addtogroup xetla_core_bit_manipulation
+/// @{
+
+/// Shift left operation (vector version)
+/// @tparam T0 element type of the returned vector. Must be any integer type.
+/// @tparam T1 element type of the input vector. Must be any integer type.
+/// @tparam SZ size of the input and returned vector.
+/// @tparam U type of scalar operand \p src1. Must be any integer type.
+/// @param src0 the input vector.
+/// @param src1 the number of bit positions the input vector shall be shifted.
+/// @param sat enables/disables the saturation (off by default). Possible
+/// values: saturation_on/saturation_off.
+/// @return vector of shifted left values.
+template <typename T0, typename T1, int SZ, typename U,
+ class Sat = xetla_saturation_off_tag>
+__XETLA_API xetla_vector<T0, SZ> xetla_shl(
+ xetla_vector<T1, SZ> src0, U src1, Sat sat = {}) {
+ return cm_shl<T0, T1, SZ, U>(src0, src1, Sat::value);
+}
+
+/// Shift left operation (scalar version)
+/// @tparam T0 element type of the returned value. Must be any integer type.
+/// @tparam T1 element type of the input value. Must be any integer type.
+/// @tparam T2 type of scalar operand \p src1. Must be any integer type.
+/// @param src0 the input value.
+/// @param src1 the number of bit positions the input vector shall be shifted.
+/// @param sat enables/disables the saturation (off by default). Possible
+/// values: saturation_on/saturation_off.
+/// @return shifted left value.
+template <typename T0, typename T1, typename T2,
+ class Sat = xetla_saturation_off_tag>
+typename std::remove_const<T0>::type xetla_shl(T1 src0, T2 src1, Sat sat = {}) {
+ return cm_shl<T0, T1, T2>(src0, src1, Sat::value);
+}
+
+/// Shift right operation (vector version)
+/// @tparam T0 element type of the returned vector. Must be any integer type.
+/// @tparam T1 element type of the input vector. Must be any integer type.
+/// @tparam SZ size of the input and returned vector.
+/// @tparam U type of scalar operand \p src1. Must be any integer type.
+/// @param src0 the input vector.
+/// @param src1 the number of bit positions the input vector shall be shifted.
+/// @param sat enables/disables the saturation (off by default). Possible
+/// values: saturation_on/saturation_off.
+/// @return vector of shifted right values.
+template <typename T0, typename T1, int SZ, typename U,
+ class Sat = xetla_saturation_off_tag>
+__XETLA_API xetla_vector<T0, SZ> xetla_shr(
+ xetla_vector<T1, SZ> src0, U src1, Sat sat = {}) {
+ return cm_shr<T0, T1, SZ, U>(src0, src1, Sat::value);
+}
+
+/// Shift right operation (scalar version)
+/// @tparam T0 element type of the returned value. Must be any integer type.
+/// @tparam T1 element type of the input value. Must be any integer type.
+/// @tparam T2 type of scalar operand \p src1. Must be any integer type.
+/// @param src0 the input value.
+/// @param src1 the number of bit positions the input vector shall be shifted.
+/// @param sat enables/disables the saturation (off by default). Possible
+/// values: saturation_on/saturation_off.
+/// @return shifted right value.
+template <typename T0, typename T1, typename T2,
+ class Sat = xetla_saturation_off_tag>
+__XETLA_API typename std::remove_const<T0>::type xetla_shr(
+ T1 src0, T2 src1, Sat sat = {}) {
+ return cm_shr<T0, T1, T2>(src0, src1, Sat::value);
+}
+
+/// Rotate left operation with two vector inputs
+/// @tparam T0 element type of the returned vector. Must be any integer type.
+/// @tparam T1 element type of the input vector. Must be any integer type.
+/// @tparam SZ size of the input and returned vectors.
+/// @param src0 the input vector.
+/// @param src1 the vector with number of bit positions by which the elements of
+/// the input vector \p src0 shall be rotated.
+/// @return vector of rotated elements.
+template <typename T0, typename T1, int SZ>
+__XETLA_API xetla_vector<T0, SZ> xetla_rol(
+ xetla_vector<T1, SZ> src0, xetla_vector<T1, SZ> src1) {
+ return cm_rol<T0, T1, SZ>(src0, src1);
+}
+
+/// Rotate left operation with a vector and a scalar inputs
+/// @tparam T0 element type of the returned vector. Must be any integer type.
+/// @tparam T1 element type of the input vector. Must be any integer type.
+/// @tparam SZ size of the input and returned vectors.
+/// @tparam U type of scalar operand \p src1. Must be any integer type.
+/// @param src0 the input vector.
+/// @param src1 the number of bit positions the input vector shall be rotated.
+/// @return vector of rotated elements.
+template <typename T0, typename T1, int SZ, typename U>
+__XETLA_API std::enable_if_t<std::is_integral<T0>::value
+ && std::is_integral<T1>::value && std::is_integral<U>::value
+ && is_xetla_scalar<U>::value,
+ xetla_vector<T0, SZ>>
+xetla_rol(xetla_vector<T1, SZ> src0, U src1) {
+ return cm_rol<T0, T1, SZ, U>(src0, src1);
+}
+
+/// Rotate left operation with two scalar inputs
+/// @tparam T0 element type of the returned value. Must be any integer type.
+/// @tparam T1 element type of the input value. Must be any integer type.
+/// @tparam T2 type of scalar operand \p src1. Must be any integer type.
+/// @param src0 the input value.
+/// @param src1 the number of bit positions the input vector shall be rotated.
+/// @return rotated left value.
+template <typename T0, typename T1, typename T2>
+__XETLA_API std::enable_if_t<std::is_integral<T0>::value
+ && std::is_integral<T1>::value && std::is_integral<T2>::value,
+ remove_const_t<T0>>
+xetla_rol(T1 src0, T2 src1) {
+ return cm_rol<T0, T1, T2>(src0, src1);
+}
+
+/// Rotate right operation with two vector inputs
+/// @tparam T0 element type of the returned vector. Must be any integer type.
+/// @tparam T1 element type of the input vector. Must be any integer type.
+/// @tparam SZ size of the input and returned vectors.
+/// @param src0 the input vector.
+/// @param src1 the vector with number of bit positions by which the elements of
+/// the input vector \p src0 shall be rotated.
+/// @return vector of rotated elements.
+template <typename T0, typename T1, int SZ>
+__XETLA_API xetla_vector<T0, SZ> xetla_ror(
+ xetla_vector<T1, SZ> src0, xetla_vector<T1, SZ> src1) {
+ return cm_ror<T0, T1, SZ>(src0, src1);
+}
+
+/// Rotate right operation with a vector and a scalar inputs
+/// @tparam T0 element type of the returned vector. Must be any integer type.
+/// @tparam T1 element type of the input vector. Must be any integer type.
+/// @tparam SZ size of the input and returned vectors.
+/// @tparam U type of scalar operand \p src1. Must be any integer type.
+/// @param src0 the input vector.
+/// @param src1 the number of bit positions the input vector shall be rotated.
+/// @return vector of rotated elements.
+template <typename T0, typename T1, int SZ, typename U>
+__XETLA_API std::enable_if_t<std::is_integral<T0>::value
+ && std::is_integral<T1>::value && std::is_integral<U>::value
+ && is_xetla_scalar<U>::value,
+ xetla_vector<T0, SZ>>
+xetla_ror(xetla_vector<T1, SZ> src0, U src1) {
+ return cm_ror<T0, T1, SZ, U>(src0, src1);
+}
+
+/// Rotate right operation with two scalar inputs
+/// @tparam T0 element type of the returned value. Must be any integer type.
+/// @tparam T1 element type of the input value. Must be any integer type.
+/// @tparam T2 type of scalar operand \p src1. Must be any integer type.
+/// @param src0 the input value.
+/// @param src1 the number of bit positions the input vector shall be rotated.
+/// @return rotated right value.
+template <typename T0, typename T1, typename T2>
+__XETLA_API std::enable_if_t<std::is_integral<T0>::value
+ && std::is_integral<T1>::value && std::is_integral<T2>::value,
+ remove_const_t<T0>>
+xetla_ror(T1 src0, T2 src1) {
+ return cm_ror<T0, T1, T2>(src0, src1);
+}
+
+/// Logical Shift Right (vector version)
+/// @tparam T0 element type of the returned vector. Must be any integer type.
+/// @tparam T1 element type of the input vector. Must be any integer type.
+/// @tparam SZ size of the input and returned vectors.
+/// @tparam U type of scalar operand \p src1. Must be any integer type.
+/// @param src0 the input vector.
+/// @param src1 the number of bit positions the input vector shall be shifted.
+/// @param sat enables/disables the saturation (off by default). Possible
+/// values: saturation_on/saturation_off.
+/// @return vector of shifted elements.
+template <typename T0, typename T1, int SZ, typename U,
+ class Sat = xetla_saturation_off_tag>
+__XETLA_API xetla_vector<T0, SZ> xetla_lsr(
+ xetla_vector<T1, SZ> src0, U src1, Sat sat = {}) {
+ return cm_lsr<T0, T1, SZ, U>(src0, src1, Sat::value);
+}
+
+/// Logical Shift Right (scalar version)
+/// @tparam T0 element type of the returned value. Must be any integer type.
+/// @tparam T1 element type of the input value \p src0. Must be any integer
+/// type.
+/// @tparam T2 type of scalar operand \p src1. Must be any integer type.
+/// @param src0 the input value.
+/// @param src1 the number of bit positions the input vector shall be shifted.
+/// @param sat enables/disables the saturation (off by default). Possible
+/// values: saturation_on/saturation_off.
+/// @return shifted value.
+template <typename T0, typename T1, typename T2,
+ class Sat = xetla_saturation_off_tag>
+__XETLA_API typename std::remove_const<T0>::type xetla_lsr(
+ T1 src0, T2 src1, Sat sat = {}) {
+ return cm_lsr<T0, T1, T2>(src0, src1, Sat::value);
+}
+
+/// Arithmetical Shift Right (vector version)
+/// @tparam T0 element type of the returned vector. Must be any integer type.
+/// @tparam T1 element type of the input vector. Must be any integer type.
+/// @tparam SZ size of the input and returned vectors.
+/// @tparam U type of scalar operand \p src1. Must be any integer type.
+/// @param src0 the input vector.
+/// @param src1 the number of bit positions the input vector shall be shifted.
+/// @param sat enables/disables the saturation (off by default). Possible
+/// values: saturation_on/saturation_off.
+/// @return vector of shifted elements.
+template <typename T0, typename T1, int SZ, typename U,
+ class Sat = xetla_saturation_off_tag>
+__XETLA_API xetla_vector<T0, SZ> xetla_asr(
+ xetla_vector<T1, SZ> src0, U src1, Sat sat = {}) {
+ return cm_asr<T0, T1, SZ, U>(src0, src1, Sat::value);
+}
+
+/// Arithmetical Shift Right (scalar version)
+/// @tparam T0 element type of the returned value. Must be any integer type.
+/// @tparam T1 element type of the input value \p src0. Must be any integer
+/// type.
+/// @tparam T2 type of scalar operand \p src1. Must be any integer type.
+/// @param src0 the input value.
+/// @param src1 the number of bit positions the input vector shall be shifted.
+/// @param sat enables/disables the saturation (off by default). Possible
+/// values: saturation_on/saturation_off.
+/// @return shifted value.
+template <typename T0, typename T1, typename T2,
+ class Sat = xetla_saturation_off_tag>
+__XETLA_API typename std::remove_const<T0>::type xetla_asr(
+ T1 src0, T2 src1, Sat sat = {}) {
+ return cm_asr<T0, T1, T2>(src0, src1, Sat::value);
+}
+
+/// Pack a xetla_mask into a single unsigned 32-bit integer value.
+/// i'th bit in the returned value is set to the result of comparison of the
+/// i'th element of the input argument to zero. "equals to zero" gives \c 0,
+/// "not equal to zero" gives \c 1. Remaining (if any) bits if the result are
+/// filled with \c 0.
+/// @tparam N Size of the input mask.
+/// @param src0 The input mask.
+/// @return The packed mask as an <code> unsigned int</code> 32-bit value.
+template <int N>
+__XETLA_API uint32_t xetla_pack_mask(xetla_mask<N> src0) {
+ return cm_pack_mask<N>(src0);
+}
+
+/// Unpack an unsigned 32-bit integer value into a xetla_mask. Only \c N least
+/// significant bits are used, where \c N is the number of elements in the
+/// result mask. Each input bit is stored into the corresponding vector element
+/// of the output mask.
+/// @tparam N Size of the output mask.
+/// @param src0 The input packed mask.
+/// @return The unpacked mask as a xetla_mask object.
+template <int N>
+__XETLA_API xetla_mask<N> xetla_unpack_mask(uint32_t src0) {
+ return cm_unpack_mask<uint16_t, N>(src0);
+}
+
+/// @} xetla_core_bit_manipulation
+
+} // namespace gpu::xetla
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/common.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/common.hpp
new file mode 100644
index 00000000000..d385b5b5b51
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/common.hpp
@@ -0,0 +1,227 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#ifndef XETLA_NO_CM_INCLUDE
+#include <cm/cm.h>
+#include <cm/cmtl.h>
+#endif
+
+template <class T>
+using remove_const_t = typename std::remove_const<T>::type;
+
+/// @addtogroup xetla_core
+/// @{
+
+/// @brief KERNEL_MAIN macro.
+/// Alias to CM `"_GENX_MAIN_"`.
+///
+#define KERNEL_MAIN _GENX_MAIN_
+
+/// @brief KERNEL_FUNC macro.
+/// Alias to empty.
+///
+#define KERNEL_FUNC
+
+/// @} xetla_core
+
+#define __XETLA_API inline
+
+#define XETLA_WARNING(msg) CM_STATIC_WARNING(0, msg)
+
+#define XETLA_MARKER(message) [[deprecated(message)]]
+
+#define DEVICE_PRINTF(s, ...) \
+ do { \
+ } while (0)
+
+#define DEVICE_ASSERT(c, s, ...) \
+ do { \
+ } while (0);
+
+template <auto val>
+XETLA_MARKER("Help function to print value")
+inline constexpr void XETLA_PRINT() {}
+template <typename type>
+XETLA_MARKER("Help function to print type")
+inline constexpr void XETLA_PRINT() {}
+
+namespace gpu::xetla {
+
+enum class gpu_arch : uint8_t { Xe = 0 };
+enum class grf_mode : uint8_t { normal = 0, double_grf = 1 };
+
+enum class mem_layout : uint8_t {
+ row_major = 0,
+ col_major = 1,
+ nhwc = 2,
+ hwio = 3,
+};
+enum class mem_space : uint8_t { global = 0, local = 1 };
+enum class msg_type : uint8_t {
+ block_2d = 0,
+ block_1d = 1,
+ scatter = 2,
+ atomic_add = 3,
+ unaligned_2d = 4
+ // prefetch_2d = 4,
+ // prefetch_1d = 5
+};
+/// L1 or L2 cache hint kinds.
+enum class cache_hint : uint8_t {
+ none = 0,
+ uncached = 1,
+ cached = 2,
+ write_back = 3,
+ write_through = 4,
+ streaming = 5,
+ read_invalidate = 6
+};
+
+/// Data size or format to read or store
+enum class data_size : uint8_t {
+ default_size = 0,
+ u8 = 1,
+ u16 = 2,
+ u32 = 3,
+ u64 = 4,
+ u8u32 = 5, /// load 8b, zero extend to 32b; store the opposite
+ u16u32 = 6, /// load 16b, zero extend to 32b; store the opposite
+ u16u32h = 7, /// load 16b into high 16 of each 32b; store the high 16
+};
+
+/// The specific LSC shared function to fence with xetla_fence
+enum class memory_kind : uint8_t {
+ untyped_global = 0, /// untyped global memory
+ untyped_global_low_pri = 1, /// low-priority untyped global memory
+ typed_global = 2, /// typed global memory
+ shared_local = 3, /// shared local memory
+};
+
+/// The xetla_fence operation to apply to caches
+enum class fence_op : uint8_t {
+ none = 0, /// no operation
+ evict = 1, /// dirty lines evicted and invalidated from L1
+ invalidate = 2, /// invalidate all clean lines
+ discard = 3, /// direct and clean lines are discarded w/o eviction
+ clean = 4, /// dirty lines are written to memory, but retained in cache
+ /// in clean state
+ flushl2 = 5, /// flush only L2
+};
+/// The scope that xetla_fence operation should apply to
+enum class fence_scope : uint8_t {
+ group = 0, /// flush out to the threadgroup's scope
+ local = 1, /// flush out to the local scope
+ tile = 2, /// tile, flush out to several DSSs
+ gpu = 3, /// entire GPU, flush out to the GPUs LLC
+ gpus = 4, /// all GPUs in the system, flush out to memory shared by all GPUs
+ system = 5, /// the entire system memory space
+ sysacq = 6, /// the entire system memory space with system-acquire semantics
+};
+
+/// Represents an atomic operation. Operations always return the old value(s) of
+/// the target memory location(s) as it was before the operation was applied.
+enum class atomic_op : uint8_t {
+ /// Atomic increment of memory data and return the old value.
+ iinc = 0x0,
+ /// Atomic decrement of memory data and return the old value.
+ idec = 0x1,
+ /// Atomic signed int add of src1 from memory data and return the old value.
+ iadd = 0x2,
+ /// Atomic signed int subtract of src1 from memory data and return the old value.
+ isub = 0x3,
+ /// Atomic store the signed int min of src1 and memory data and return the old value.
+ smin = 0x4,
+ /// Atomic store the signed int max of src1 and memory data and return the old value.
+ smax = 0x5,
+ /// Atomic bit-compare src1_X and memory data and replace if equal with src1_Y. Returns the old value.
+ cmpxchg = 0x6,
+ /// Atomic float add of src1 from memory data and return the old value.
+ fadd = 0x7,
+ /// Atomic float subtract of src1 from memory data and return the old value.
+ fsub = 0x8,
+ /// Atomic store the float min of src1 and memory data and return the old value.
+ fmin = 0x9,
+ /// Atomic store the float max of src1 and memory data and return the old value.
+ fmax = 0xa,
+ /// Atomic float compare src1_X and memory data and replace if equal with src1_Y. Returns the old value.
+ fcmpxchg = 0xb,
+ /// Atomic store the unsigned int min of src1 and memory data and return the old value.
+ umin = 0xc,
+ /// Atomic store the unsigned int max of src1 and memory data and return the old value.
+ umax = 0xd,
+ /// Atomic store the bitwise AND of src1 and memory data and return the old value.
+ bit_and = 0xe,
+ /// Atomic store the bitwise OR of src1 and memory data and return the old value.
+ bit_or = 0xf,
+ /// Atomic store the bitwise XOR of src1 and memory data and return the old value.
+ bit_xor = 0x10,
+ /// Atomic read of the memory data value, without modifying the data.
+ load = 0x11,
+ /// Atomic store untyped data to memory.
+ store = 0x12
+};
+
+/// xetla dpas argument typ
+enum class argument_type : uint8_t {
+ U2 = 2, // unsigned 2 bits
+ S2 = 3, // signed 2 bits
+ U4 = 4, // unsigned 4 bits
+ S4 = 5, // signed 4 bits
+ U8 = 6, // unsigned 8 bits
+ S8 = 7, // signed 8 bits
+ BF16 = 8, // bfloat 16
+ FP16 = 9, // half float
+ TF32 = 12, // tensorfloat 32
+ DF = 13, // double (64bits)
+ NUM_ARG_TYPES = 14
+};
+
+// Saturation tag
+class xetla_saturation_on_tag {
+public:
+ static constexpr int value = _GENX_SAT;
+};
+
+class xetla_saturation_off_tag {
+public:
+ static constexpr int value = _GENX_NOSAT;
+};
+
+template <typename T>
+using is_xetla_scalar = typename details::is_cm_scalar<T>;
+
+/// xetla reduce op
+enum class reduce_op : uint8_t {
+ sum = 0, // performance reduce_sum
+ prod = 1, // performance reduce_prod
+ min = 2, // performance reduce_min
+ max = 3, // performance reduce_max
+};
+
+/// SW_BARRIER, insert software scheduling barrier, for better code control
+///
+#define SW_BARRIER() cm_fence(CM_SW_BARRIER)
+
+__XETLA_API void xetla_wait(uint16_t val) {
+ __cm_builtin_dummy_mov(val);
+}
+
+} // namespace gpu::xetla
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/core.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/core.hpp
new file mode 100644
index 00000000000..695e2e36cfb
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/core.hpp
@@ -0,0 +1,97 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+/// @defgroup xetla_core XeTLA Core
+
+/// Some terminologies used in the API documentation:
+/// - *word* - 2 bytes.
+/// - *dword* ("double word") - 4 bytes.
+/// - *qword* ("quad word") - 8 bytes.
+/// - *oword* ("octal word") - 16 bytes.
+///
+
+/// @addtogroup xetla_core
+/// @{
+
+/// @defgroup xetla_core_base_types Base types
+/// Defines vector, vector reference and matrix reference data types.
+
+/// @defgroup xetla_core_base_ops Base ops
+/// Defines base ops for vector, vector reference and matrix reference data types.
+
+/// @defgroup xetla_core_memory Memory access APIs
+/// Defines XeTLA APIs to access memory, including read, write and atomic.
+
+/// @defgroup xetla_core_barrier Synchronization APIs
+/// Defines XeTLA APIs for synchronization primitives.
+
+/// @defgroup xetla_core_math Math operation APIs
+/// Defines math operations on XeTLA vector data types.
+
+/// @defgroup xetla_core_bit_manipulation Bit and mask manipulation APIs
+/// Defines bitwise operations.
+
+/// @defgroup xetla_core_conv Explicit conversion APIs
+/// Defines explicit conversions (with and without saturation), truncation etc. between XeTLA vector types.
+
+/// @defgroup xetla_core_raw_send Raw send APIs
+/// Implements the \c send instruction to send messages to variaous components
+/// of the Intel(R) processor graphics, as defined in the documentation at [here](https://01.org/sites/default/files/documentation/intel-gfx-prm-osrc-icllp-vol02a-commandreference-instructions_2.pdf)
+
+/// @defgroup xetla_core_misc Miscellaneous XeTLA convenience functions
+/// Wraps some useful functions.
+
+/// @defgroup xetla_core_arch_config Arch config information
+/// Defines some hardware arch related information, mainly used to do HW limitation check.
+
+/// @} xetla_core
+
+#ifdef _WIN32
+#include "../../../common/core/cm/arch_config.hpp"
+#include "../../../common/core/cm/barrier.hpp"
+#include "../../../common/core/cm/base_consts.hpp"
+#include "../../../common/core/cm/base_ops.hpp"
+#include "../../../common/core/cm/base_types.hpp"
+#include "../../../common/core/cm/bit_mask_manipulation.hpp"
+#include "../../../common/core/cm/debug.hpp"
+#include "../../../common/core/cm/explicit_conv.hpp"
+#include "../../../common/core/cm/math_fma.hpp"
+#include "../../../common/core/cm/math_general.hpp"
+#include "../../../common/core/cm/math_mma.hpp"
+#include "../../../common/core/cm/memory.hpp"
+#include "../../../common/core/cm/misc.hpp"
+#include "../../../common/core/cm/raw_send.hpp"
+#else
+#include "common/core/cm/arch_config.hpp"
+#include "common/core/cm/barrier.hpp"
+#include "common/core/cm/base_consts.hpp"
+#include "common/core/cm/base_ops.hpp"
+#include "common/core/cm/base_types.hpp"
+#include "common/core/cm/bit_mask_manipulation.hpp"
+#include "common/core/cm/debug.hpp"
+#include "common/core/cm/explicit_conv.hpp"
+#include "common/core/cm/math_fma.hpp"
+#include "common/core/cm/math_general.hpp"
+#include "common/core/cm/math_mma.hpp"
+#include "common/core/cm/memory.hpp"
+#include "common/core/cm/misc.hpp"
+#include "common/core/cm/raw_send.hpp"
+#endif
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/debug.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/debug.hpp
new file mode 100644
index 00000000000..c4176597080
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/debug.hpp
@@ -0,0 +1,45 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+#pragma once
+
+#ifdef _WIN32
+#include "../../../common/core/cm/base_ops.hpp"
+#include "../../../common/core/cm/base_types.hpp"
+#include "../../../common/core/cm/common.hpp"
+#include "../../../common/core/cm/math_general.hpp"
+#else
+#include "common/core/cm/base_ops.hpp"
+#include "common/core/cm/base_types.hpp"
+#include "common/core/cm/common.hpp"
+#include "common/core/cm/math_general.hpp"
+#endif
+
+namespace gpu::xetla {
+
+#define XETLA_PRINTF(s, ...) \
+ do { \
+ } while (0)
+
+#define XETLA_ASSERT(c, s, ...) \
+ do { \
+ } while (0)
+
+#define DEBUG_INVOKE(level, ...) \
+ do { \
+ } while (0)
+
+} // namespace gpu::xetla
\ No newline at end of file
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/explicit_conv.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/explicit_conv.hpp
new file mode 100644
index 00000000000..867d933dd8c
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/explicit_conv.hpp
@@ -0,0 +1,158 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#ifdef _WIN32
+#include "../../../common/core/cm/base_ops.hpp"
+#include "../../../common/core/cm/base_types.hpp"
+#include "../../../common/core/cm/common.hpp"
+#include "../../../common/core/cm/math_general.hpp"
+#else
+#include "common/core/cm/base_ops.hpp"
+#include "common/core/cm/base_types.hpp"
+#include "common/core/cm/common.hpp"
+#include "common/core/cm/math_general.hpp"
+#endif
+
+namespace gpu::xetla {
+
+/// @addtogroup xetla_core_conv
+/// @{
+
+//template <typename T_dst, typename T_src, int N>
+//__XETLA_API xetla_vector<T_dst, N> xetla_cvt(xetla_vector<T_src, N> src) {}
+
+/// @brief xetla explicit data conversion for standard data types(integer,float,half)
+/// @tparam T_dst is the destination data type.
+/// @tparam T_src is the source data type.
+/// @tparam N is the element number in xetla_vector.
+template <typename T_dst, typename T_src, int N>
+__XETLA_API typename std::enable_if_t<!(is_internal_type<T_dst>::value)
+ && !(is_internal_type<T_src>::value),
+ xetla_vector<T_dst, N>>
+xetla_cvt(xetla_vector<T_src, N> src) {
+ xetla_vector<T_dst, N> dst = src;
+ return dst;
+}
+
+/// @brief xetla explicit data conversion, fp32->bf16.
+/// @tparam T_dst is the float32 data type.
+/// @tparam T_src is the bfloat16 data type.
+/// @tparam N is the element number in xetla_vector.
+template <typename T_dst, typename T_src, int N>
+__XETLA_API typename std::enable_if_t<std::is_same<T_dst, bf16>::value
+ && std::is_same<T_src, float>::value,
+ xetla_vector<T_dst, N>>
+xetla_cvt(xetla_vector<T_src, N> src) {
+ return cm_bf_cvt<half, T_src, N>(src).xetla_format<native_type_t<T_dst>>();
+}
+
+/// @brief xetla explicit data conversion, bf16->fp32.
+/// @tparam T_dst is the bfloat16 data type.
+/// @tparam T_src is the float32 data type.
+/// @tparam N is the element number in xetla_vector.
+template <typename T_dst, typename T_src, int N>
+__XETLA_API typename std::enable_if_t<std::is_same<T_dst, float>::value
+ && std::is_same<T_src, bf16>::value,
+ xetla_vector<T_dst, N>>
+xetla_cvt(xetla_vector<T_src, N> src) {
+ return cm_bf_cvt<T_dst, half, N>(src.xetla_format<half>());
+}
+
+/// @brief xetla explicit data conversion, fp32->tf32.
+/// @tparam T_dst is the float32 data type.
+/// @tparam T_src is the tensor_float32 data type.
+/// @tparam N is the element number in xetla_vector.
+template <typename T_dst, typename T_src, int N>
+__XETLA_API typename std::enable_if_t<std::is_same<T_dst, tf32>::value
+ && std::is_same<T_src, float>::value,
+ xetla_vector<T_dst, N>>
+xetla_cvt(xetla_vector<T_src, N> src) {
+ return cm_tf32_cvt<native_type_t<T_dst>, T_src, N>(src);
+}
+
+/// @brief xetla explicit data conversion, tf32->fp32.
+/// @tparam T_dst is the tensor_float32 data type.
+/// @tparam T_src is the float32 data type.
+/// @tparam N is the element number in xetla_vector.
+template <typename T_dst, typename T_src, int N>
+__XETLA_API typename std::enable_if_t<std::is_same<T_dst, float>::value
+ && std::is_same<T_src, tf32>::value,
+ xetla_vector<T_dst, N>>
+xetla_cvt(xetla_vector<T_src, N> src) {
+ return src.xetla_format<float>();
+}
+
+/// @brief xetpp explicit data conversion with scaling, int32->fp16.
+/// @tparam T_dst is the half data type.
+/// @tparam T_src is the int32 data type.
+/// @tparam N is the element number in xetla_vector.
+template <typename T_dst, typename T_src, int N>
+__XETLA_API typename std::enable_if_t<std::is_same<T_dst, fp16>::value
+ && std::is_same<T_src, int32_t>::value,
+ xetla_vector<T_dst, N>>
+xetla_cvt(xetla_vector<T_src, N> src, float scaling_value) {
+ xetla_vector<T_dst, N> dst = scaling_value * src;
+ return dst;
+}
+
+/// @brief xetpp explicit data conversion with re-quantization, int32->int8.
+/// @tparam T_dst is the int32 data type.
+/// @tparam T_src is the int8 data type.
+/// @tparam N is the element number in xetla_vector.
+template <typename T_dst, typename T_src, int N>
+__XETLA_API typename std::enable_if_t<std::is_same<T_dst, int8_t>::value
+ && std::is_same<T_src, int32_t>::value,
+ xetla_vector<T_dst, N>>
+xetla_cvt(xetla_vector<T_src, N> src, float scaling_value) {
+ auto dst = xetla_vector<T_dst, N>(
+ xetla_rnde<float>(scaling_value * src), SAT);
+ return dst;
+}
+
+/// @brief xetpp explicit data conversion with scaling and quantization, float32->int8.
+/// @tparam T_dst is the int8 data type.
+/// @tparam T_src is the float32 data type.
+/// @tparam N is the element number in xetla_vector.
+template <typename T_dst, typename T_src, int N>
+__XETLA_API typename std::enable_if_t<std::is_same<T_dst, int8_t>::value
+ && std::is_same<T_src, float>::value,
+ xetla_vector<T_dst, N>>
+xetla_cvt(xetla_vector<T_src, N> src, float scaling_value) {
+ auto dst = xetla_vector<T_dst, N>(
+ xetla_rnde<float>(scaling_value * src), SAT);
+ return dst;
+}
+
+/// @brief xetla explicit data conversion, same type.
+/// @tparam T_dst is the dst data type.
+/// @tparam T_src is the src data type.
+/// @tparam N is the element number in xetla_vector.
+template <typename T_dst, typename T_src, int N>
+__XETLA_API typename std::enable_if_t<std::is_same<T_dst, T_src>::value
+ && is_internal_type<T_src>::value,
+ xetla_vector<T_dst, N>>
+xetla_cvt(xetla_vector<T_src, N> src) {
+ return src;
+}
+
+/// @} xetla_core_conv
+
+} // namespace gpu::xetla
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/math_fma.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/math_fma.hpp
new file mode 100644
index 00000000000..098bd1dbd9f
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/math_fma.hpp
@@ -0,0 +1,35 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#ifdef _WIN32
+#include "../../../common/core/cm/common.hpp"
+#else
+#include "common/core/cm/common.hpp"
+#endif
+
+namespace gpu::xetla {
+
+/// @addtogroup xetla_core_math
+/// @{
+
+/// @} xetla_core_math
+
+} // namespace gpu::xetla
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/math_general.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/math_general.hpp
new file mode 100644
index 00000000000..1c0fb305a6b
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/math_general.hpp
@@ -0,0 +1,624 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#ifdef _WIN32
+#include "../../../common/core/cm/base_ops.hpp"
+#include "../../../common/core/cm/base_types.hpp"
+#include "../../../common/core/cm/common.hpp"
+#else
+#include "common/core/cm/base_ops.hpp"
+#include "common/core/cm/base_types.hpp"
+#include "common/core/cm/common.hpp"
+#endif
+
+namespace gpu::xetla {
+
+/// @addtogroup xetla_core_math
+/// @{
+
+/// Get absolute value (vector version)
+/// @tparam T0 element type of the returned vector.
+/// @tparam T1 element type of the input vector.
+/// @tparam SZ size of the input and returned vector.
+/// @param src0 the input vector.
+/// @return vector of absolute values.
+template <typename T0, typename T1, int SZ>
+__XETLA_API xetla_vector<T0, SZ> xetla_abs(xetla_vector<T1, SZ> src0) {
+ static_assert(!(is_internal_type<T0>::value || is_internal_type<T1>::value),
+ "The internal types are not yet supported!");
+ return cm_abs<T0, T1, SZ>(src0);
+}
+
+/// Get absolute value (scalar version)
+/// @tparam T0 element type of the returned value.
+/// @tparam T1 element type of the input value.
+/// @param src0 the source operand.
+/// @return absolute value.
+template <typename T0, typename T1>
+std::enable_if_t<!std::is_same<remove_const_t<T0>, remove_const_t<T1>>::value,
+ remove_const_t<T0>>
+ __XETLA_API xetla_abs(T1 src0) {
+ static_assert(!(is_internal_type<T0>::value || is_internal_type<T1>::value),
+ "The internal types are not yet supported!");
+ return cm_abs<T0, T1>(src0);
+}
+
+/// Get absolute value (vector version). This is a specialization of a version
+/// with three template parameters, where the element types of the input and
+/// output vector are the same.
+/// @tparam T1 element type of the input and output vectors.
+/// @tparam SZ size of the input and returned vectors.
+/// @param src0 the input vector.
+/// @return vector of absolute values.
+template <typename T1, int SZ>
+__XETLA_API xetla_vector<T1, SZ> xetla_abs(xetla_vector<T1, SZ> src0) {
+ static_assert(!(is_internal_type<T1>::value),
+ "The internal types are not yet supported!");
+ return cm_abs<T1, SZ>(src0);
+}
+
+/// Get absolute value (scalar version). This is a specialization of a version
+/// with two template parameters, where the types of the input and output value
+/// are the same.
+/// @tparam T1 element type of the input and output value.
+/// @param src0 the source operand.
+/// @return absolute value.
+template <typename T1>
+__XETLA_API typename std::remove_const<T1>::type xetla_abs(T1 src0) {
+ static_assert(!(is_internal_type<T1>::value),
+ "The internal types are not yet supported!");
+ return cm_abs<T1>(src0);
+}
+
+/// Selects component-wise the maximum of the two vectors.
+/// The source operands must be both of integer or both of floating-point type.
+/// @tparam T element type of the input and return vectors.
+/// @tparam SZ size of the input and returned vectors.
+/// @param src0 the input vector.
+/// @param src1 the input vector.
+/// @param sat enables/disables the saturation (off by default). Possible
+/// values: saturation_on/saturation_off.
+/// @return vector of component-wise maximum elements.
+
+template <typename T, int SZ, typename Sat = xetla_saturation_off_tag>
+__XETLA_API xetla_vector<T, SZ> xetla_max(
+ xetla_vector<T, SZ> src0, xetla_vector<T, SZ> src1, Sat sat = {}) {
+ static_assert(!(is_internal_type<T>::value),
+ "The internal types are not yet supported!");
+ return cm_max<T, T, SZ, xetla_vector<T, SZ>>(src0, src1, Sat::value);
+}
+
+/// Selects maximums for each element of the input vector and a scalar.
+/// The source operands must be both of integer or both of
+/// floating-point type.
+/// @tparam T element type of the input and return vectors.
+/// @tparam SZ size of the input and returned vectors.
+/// @param src0 the input vector.
+/// @param src1 the scalar value.
+/// @param sat enables/disables the saturation (off by default). Possible
+/// values: saturation_on/saturation_off.
+/// @return vector of component-wise maximum elements.
+template <typename T, int SZ, typename Sat = xetla_saturation_off_tag>
+__XETLA_API xetla_vector<T, SZ> xetla_max(
+ xetla_vector<T, SZ> src0, T src1, Sat sat = {}) {
+ static_assert(!(is_internal_type<T>::value),
+ "The internal types are not yet supported!");
+ return cm_max<T, T, SZ, T>(src0, src1, Sat::value);
+}
+
+/// Selects maximums for each element of the input scalar and a vector.
+/// The source operands must be both of integer or both of
+/// floating-point type.
+/// @tparam T element type of the input and return vectors.
+/// @tparam SZ size of the input and returned vectors.
+/// @param src0 the scalar value.
+/// @param src1 the input vector.
+/// @param sat enables/disables the saturation (off by default). Possible
+/// values: saturation_on/saturation_off.
+/// @return vector of component-wise maximum elements.
+template <typename T, int SZ, typename Sat = xetla_saturation_off_tag>
+__XETLA_API xetla_vector<T, SZ> xetla_max(
+ T src0, xetla_vector<T, SZ> src1, Sat sat = {}) {
+ static_assert(!(is_internal_type<T>::value),
+ "The internal types are not yet supported!");
+ return cm_max<T, T, xetla_vector<T, SZ>>(src0, src1, Sat::value);
+}
+
+/// Selects maximum between two scalar values.
+/// The source operands must be both of integer or both of floating-point type.
+/// @tparam T element type of the input and return vectors.
+/// @param src0 the scalar value.
+/// @param src1 the scalar value.
+/// @param sat enables/disables the saturation (off by default). Possible
+/// values: saturation_on/saturation_off.
+/// @return maximum value between the two inputs.
+template <typename T, typename Sat = xetla_saturation_off_tag>
+__XETLA_API T xetla_max(T src0, T src1, Sat sat = {}) {
+ static_assert(!(is_internal_type<T>::value),
+ "The internal types are not yet supported!");
+ return cm_max<T, T, T>(src0, src1, Sat::value);
+}
+
+/// Selects component-wise the minimum of the two vectors.
+/// The source operands must be both of integer or both of floating-point type.
+/// @tparam T element type of the input and return vectors.
+/// @tparam SZ size of the input and returned vectors.
+/// @param src0 the input vector.
+/// @param src1 the input vector.
+/// @param sat enables/disables the saturation (off by default). Possible
+/// values: saturation_on/saturation_off.
+/// @return vector of component-wise minimum elements.
+
+template <typename T, int SZ, typename Sat = xetla_saturation_off_tag>
+__XETLA_API xetla_vector<T, SZ> xetla_min(
+ xetla_vector<T, SZ> src0, xetla_vector<T, SZ> src1, Sat sat = {}) {
+ static_assert(!(is_internal_type<T>::value),
+ "The internal types are not yet supported!");
+ return cm_min<T, T, SZ, xetla_vector<T, SZ>>(src0, src1, Sat::value);
+}
+
+/// Selects minimums for each element of the input vector and a scalar.
+/// The source operands must be both of integer or both of
+/// floating-point type.
+/// @tparam T element type of the input and return vectors.
+/// @tparam SZ size of the input and returned vectors.
+/// @param src0 the input vector.
+/// @param src1 the scalar value.
+/// @param sat enables/disables the saturation (off by default). Possible
+/// values: saturation_on/saturation_off.
+/// @return vector of component-wise minimum elements.
+template <typename T, int SZ, typename Sat = xetla_saturation_off_tag>
+__XETLA_API xetla_vector<T, SZ> xetla_min(
+ xetla_vector<T, SZ> src0, T src1, Sat sat = {}) {
+ static_assert(!(is_internal_type<T>::value),
+ "The internal types are not yet supported!");
+ return cm_min<T, T, SZ, T>(src0, src1, Sat::value);
+}
+
+/// Selects minimums for each element of the input scalar and a vector.
+/// The source operands must be both of integer or both of
+/// floating-point type.
+/// @tparam T element type of the input and return vectors.
+/// @tparam SZ size of the input and returned vectors.
+/// @param src0 the scalar value.
+/// @param src1 the input vector.
+/// @param sat enables/disables the saturation (off by default). Possible
+/// values: saturation_on/saturation_off.
+/// @return vector of component-wise minimum elements.
+template <typename T, int SZ, typename Sat = xetla_saturation_off_tag>
+__XETLA_API xetla_vector<T, SZ> xetla_min(
+ T src0, xetla_vector<T, SZ> src1, Sat sat = {}) {
+ static_assert(!(is_internal_type<T>::value),
+ "The internal types are not yet supported!");
+ return cm_min<T, T, xetla_vector<T, SZ>>(src0, src1, Sat::value);
+}
+
+/// Selects minimum between two scalar values.
+/// The source operands must be both of integer or both of floating-point type.
+/// @tparam T element type of the input and return vectors.
+/// @param src0 the scalar value.
+/// @param src1 the scalar value.
+/// @param sat enables/disables the saturation (off by default). Possible
+/// values: saturation_on/saturation_off.
+/// @return minimum value between the two inputs.
+template <typename T, typename Sat = xetla_saturation_off_tag>
+__XETLA_API T xetla_min(T src0, T src1, Sat sat = {}) {
+ static_assert(!(is_internal_type<T>::value),
+ "The internal types are not yet supported!");
+ return cm_min<T, T, T>(src0, src1, Sat::value);
+}
+
+/// @brief Calculate exponent value for each element of the input vector, the base is e.
+/// @tparam T element type of the input and return vectors.
+/// @tparam SZ size of the input and returned vectors.
+/// @param src the input vector.
+/// @param sat enables/disables the saturation (off by default). Possible
+/// values: saturation_on/saturation_off.
+/// @return vector of component-wise exponent elements.
+template <class T, int SZ, typename Sat = xetla_saturation_off_tag>
+__XETLA_API xetla_vector<T, SZ> xetla_exp(
+ xetla_vector<T, SZ> src, Sat sat = {}) {
+ static_assert((std::is_same<remove_const_t<T>, float>::value)
+ || (std::is_same<remove_const_t<T>, fp16>::value),
+ "Only support fp32 and fp16");
+ constexpr float log2e = 1.442695f;
+ return cm_exp<SZ>(xetla_vector<T, SZ>(src * log2e), Sat::value);
+}
+
+/// @brief Calculate exponent value of a scalar, the base is e.
+/// @tparam T element type of the input and return a scalar.
+/// @param src the scalar value.
+/// @param sat enables/disables the saturation (off by default). Possible
+/// values: saturation_on/saturation_off.
+/// @return exponent value.
+template <class T, typename Sat = xetla_saturation_off_tag>
+__XETLA_API T xetla_exp(T src, Sat sat = {}) {
+ static_assert((std::is_same<remove_const_t<T>, float>::value)
+ || (std::is_same<remove_const_t<T>, fp16>::value),
+ "Only support fp32 and fp16");
+ constexpr float log2e = 1.442695f;
+ return cm_exp(T(src * log2e), Sat::value);
+}
+
+/// @brief Calculate exponent value for each element of the input vector, the base is 2.
+/// @tparam T element type of the input and return vectors.
+/// @tparam SZ size of the input and returned vectors.
+/// @param src the input vector.
+/// @param sat enables/disables the saturation (off by default). Possible
+/// values: saturation_on/saturation_off.
+/// @return vector of component-wise exponent elements.
+template <class T, int SZ, typename Sat = xetla_saturation_off_tag>
+__XETLA_API xetla_vector<T, SZ> xetla_exp2(
+ xetla_vector<T, SZ> src, Sat sat = {}) {
+ static_assert((std::is_same<remove_const_t<T>, float>::value)
+ || (std::is_same<remove_const_t<T>, fp16>::value),
+ "Only support fp32 and fp16");
+ return cm_exp<SZ>(src, Sat::value);
+}
+
+/// @brief Calculate exponent value of a scalar, the base is 2.
+/// @tparam T element type of the input and return a scalar.
+/// @param src the scalar value.
+/// @param sat enables/disables the saturation (off by default). Possible
+/// values: saturation_on/saturation_off.
+/// @return exponent value.
+template <class T, typename Sat = xetla_saturation_off_tag>
+__XETLA_API T xetla_exp2(T src, Sat sat = {}) {
+ static_assert((std::is_same<remove_const_t<T>, float>::value)
+ || (std::is_same<remove_const_t<T>, fp16>::value),
+ "Only support fp32 and fp16");
+ return cm_exp(src, Sat::value);
+}
+
+/// @brief Calculate the inversion, i.e. 1/x (vector version).
+/// @tparam T Is the element data type
+/// @tparam SZ Is the element num in the vector
+/// @tparam Sat Is the saturation flag(off by default). Possible values: saturation_on/saturation_off.
+/// @param src Is the input vector.
+/// @return Returns the result of 1/x
+template <typename T, int SZ, typename Sat = xetla_saturation_off_tag>
+__XETLA_API xetla_vector<T, SZ> xetla_inv(
+ xetla_vector<T, SZ> src, Sat sat = {}) {
+ static_assert((std::is_same<remove_const_t<T>, float>::value)
+ || (std::is_same<remove_const_t<T>, fp16>::value),
+ "Only support fp32 and fp16");
+ return cm_inv(src, Sat::value);
+}
+
+/// @brief Calculate the inversion, i.e. 1/x (scalar version).
+/// @tparam T Is the element data type
+/// @tparam Sat Is the saturation flag(off by default). Possible values: saturation_on/saturation_off.
+/// @param src Is the input scalar.
+/// @return Returns the result of 1/x
+template <typename T, typename Sat = xetla_saturation_off_tag>
+__XETLA_API T xetla_inv(T src, Sat sat = {}) {
+ static_assert((std::is_same<remove_const_t<T>, float>::value)
+ || (std::is_same<remove_const_t<T>, fp16>::value),
+ "Only support fp32 and fp16");
+ return cm_inv(src, Sat::value);
+}
+
+/// @brief Calculate the square root, i.e. x^(1/2), this is not IEEE754-compatible (vector version).
+/// @tparam T Is the element data type
+/// @tparam SZ Is the element num in the vector
+/// @tparam Sat Is the saturation flag(off by default). Possible values: saturation_on/saturation_off.
+/// @param src Is the input vector.
+/// @return Returns the result of x^(1/2)
+template <typename T, int SZ, typename Sat = xetla_saturation_off_tag>
+__XETLA_API xetla_vector<T, SZ> xetla_sqrt(
+ xetla_vector<T, SZ> src, Sat sat = {}) {
+ static_assert((std::is_same<remove_const_t<T>, float>::value)
+ || (std::is_same<remove_const_t<T>, fp16>::value),
+ "Only support fp32 and fp16");
+ return cm_sqrt(src, Sat::value);
+}
+
+/// @brief Calculate the square root, i.e. x^(1/2), this is not IEEE754-compatible (scalar version).
+/// @tparam T Is the element data type
+/// @tparam Sat Is the saturation flag(off by default). Possible values: saturation_on/saturation_off.
+/// @param src Is the input vector.
+/// @return Returns the result of x^(1/2)
+template <typename T, typename Sat = xetla_saturation_off_tag>
+__XETLA_API T xetla_sqrt(T src, Sat sat = {}) {
+ static_assert((std::is_same<remove_const_t<T>, float>::value)
+ || (std::is_same<remove_const_t<T>, fp16>::value),
+ "Only support fp32 and fp16");
+ return cm_sqrt(src, Sat::value);
+}
+
+/// @brief Calculate the square root, i.e. x^(1/2), IEEE754-compatible (vector version).
+/// @tparam T Is the element data type
+/// @tparam SZ Is the element num in the vector
+/// @tparam Sat Is the saturation flag(off by default). Possible values: saturation_on/saturation_off.
+/// @param src Is the input vector.
+/// @return Returns the result of x^(1/2)
+template <typename T, int SZ, typename Sat = xetla_saturation_off_tag>
+__XETLA_API xetla_vector<T, SZ> xetla_sqrt_ieee(
+ xetla_vector<T, SZ> src, Sat sat = {}) {
+ static_assert((std::is_same<remove_const_t<T>, float>::value)
+ || (std::is_same<remove_const_t<T>, double>::value),
+ "Only support fp32 and fp16");
+ return cm_sqrt_ieee(src, Sat::value);
+}
+
+/// @brief Calculate the square root, i.e. x^(1/2), IEEE754-compatible (scalar version).
+/// @tparam T Is the element data type
+/// @tparam Sat Is the saturation flag(off by default). Possible values: saturation_on/saturation_off.
+/// @param src Is the input vector.
+/// @return Returns the result of x^(1/2)
+template <typename T, typename Sat = xetla_saturation_off_tag>
+__XETLA_API T xetla_sqrt_ieee(T src, Sat sat = {}) {
+ static_assert((std::is_same<remove_const_t<T>, float>::value)
+ || (std::is_same<remove_const_t<T>, double>::value),
+ "Only support fp32 and fp16");
+ return cm_sqrt_ieee(src, Sat::value);
+}
+
+/// @brief Calculate the inversion of square root, i.e. 1/sqrt(x) (vector version).
+/// @tparam T Is the element data type
+/// @tparam SZ Is the element num in the vector
+/// @tparam Sat Is the saturation flag(off by default). Possible values: saturation_on/saturation_off.
+/// @param src Is the input vector.
+/// @return Returns the result of 1/sqrt(x)
+template <typename T, int SZ, typename Sat = xetla_saturation_off_tag>
+__XETLA_API xetla_vector<T, SZ> xetla_rsqrt(
+ xetla_vector<T, SZ> src, Sat sat = {}) {
+ static_assert((std::is_same<remove_const_t<T>, float>::value)
+ || (std::is_same<remove_const_t<T>, fp16>::value),
+ "Only support fp32 and fp16");
+ return cm_rsqrt(src, Sat::value);
+}
+
+/// @brief Calculate the inversion of square root, i.e. 1/sqrt(x) (scalar version).
+/// @tparam T Is the element data type
+/// @tparam Sat Is the saturation flag(off by default). Possible values: saturation_on/saturation_off.
+/// @param src Is the input vector.
+/// @return Returns the result of 1/sqrt(x)
+template <typename T, typename Sat = xetla_saturation_off_tag>
+__XETLA_API T xetla_rsqrt(T src, Sat sat = {}) {
+ static_assert((std::is_same<remove_const_t<T>, float>::value)
+ || (std::is_same<remove_const_t<T>, fp16>::value),
+ "Only support fp32 and fp16");
+ return cm_rsqrt(src, Sat::value);
+}
+
+/// @brief Calculate the tanh (vector version).
+/// @tparam T Is the element data type
+/// @tparam SZ Is the element num in the vector
+/// @param src Is the input vector.
+/// @return Returns the result of tanh(x)
+template <typename T, int SZ>
+__XETLA_API xetla_vector<T, SZ> xetla_tanh(xetla_vector<T, SZ> src) {
+ static_assert(std::is_same<remove_const_t<T>, float>::value,
+ "Only support fp32! ");
+ constexpr uint32_t flag_elems = 8 * 16;
+ xetla_vector<T, SZ> ret;
+#pragma unroll
+ for (int i = 0; i < SZ / flag_elems; i++) {
+ auto src_sub = src.xetla_select<flag_elems, 1>(i * flag_elems);
+ auto ret_sub = ret.xetla_select<flag_elems, 1>(i * flag_elems);
+ xetla_mask<flag_elems> mask = src_sub >= 10;
+ xetla_vector<T, flag_elems> exp2x
+ = xetla_exp<T, flag_elems>(src_sub * 2.f);
+ ret_sub = (exp2x - 1.f) / (exp2x + 1.f);
+ xetla_vector<T, flag_elems> ones(1);
+ ret_sub.xetla_merge(ones, mask);
+ }
+ if constexpr (SZ % flag_elems != 0) {
+ constexpr uint32_t start_pos = SZ / flag_elems * flag_elems;
+ constexpr uint32_t remain_elems = SZ % flag_elems;
+
+ auto src_sub = src.xetla_select<remain_elems, 1>(start_pos);
+ auto ret_sub = ret.xetla_select<remain_elems, 1>(start_pos);
+ xetla_mask<remain_elems> mask = src_sub >= 10;
+ xetla_vector<T, remain_elems> exp2x
+ = xetla_exp<T, remain_elems>(src_sub * 2.f);
+ ret_sub = (exp2x - 1.f) / (exp2x + 1.f);
+ xetla_vector<T, remain_elems> ones(1);
+ ret_sub.xetla_merge(ones, mask);
+ }
+
+ return ret;
+}
+
+/// @brief Calculate the tanh (scalar version).
+/// @tparam T Is the element data type
+/// @tparam SZ Is the element num in the vector
+/// @param src Is the input vector.
+/// @return Returns the result of tanh(x)
+template <typename T>
+__XETLA_API T xetla_tanh(T src) {
+ static_assert(std::is_same<remove_const_t<T>, float>::value,
+ "Only support fp32! ");
+ T exp2x = xetla_exp<T>(src * 2.f);
+ T ret = (exp2x - 1.f) / (exp2x + 1.f);
+ return (src >= 10) ? 1 : ret;
+}
+
+/// @brief Calculate sigmoid value for each element of the input vector.
+/// @tparam T element type of the input and return vectors.
+/// @tparam SZ size of the input and returned vectors.
+/// @param src the input vector.
+/// @return vector of sigmoid of component-wise elements.
+template <typename T, int SZ>
+__XETLA_API xetla_vector<T, SZ> xetla_sigmoid(xetla_vector<T, SZ> src) {
+ static_assert((std::is_same<remove_const_t<T>, float>::value)
+ || (std::is_same<remove_const_t<T>, fp16>::value),
+ "Only support fp32 and fp16");
+ xetla_mask<SZ> mask = src <= -10;
+ xetla_vector<T, SZ> exp = xetla_exp<T, SZ>(-src);
+ xetla_vector<T, SZ> ret_sub = 1.f / (exp + 1.f);
+ ret_sub.xetla_merge(0, mask);
+
+ return ret_sub;
+}
+
+/// @brief Calculate sigmoid of a scalar.
+/// @tparam T element type of the input and return a scalar.
+/// @param src the scalar value.
+/// @return sigmoid value.
+template <typename T>
+__XETLA_API T xetla_sigmoid(T src) {
+ static_assert((std::is_same<remove_const_t<T>, float>::value)
+ || (std::is_same<remove_const_t<T>, fp16>::value),
+ "Only support fp32 and fp16");
+ T exp = xetla_exp<T>(-src);
+ T ret = 1.f / (exp + 1.f);
+ return (src <= -10) ? 0 : ret;
+}
+
+/// Add two unsigned integer vectors, return the result and in-place update the carry.
+/// @tparam T element type of the src, should be uint32_t.
+/// @tparam SZ element num of the vector.
+/// @param src0 is the src0 of the add operation.
+/// @param src1 is the src1 of the add operation.
+/// @param carry is the carry of the add operation.
+/// @return result of the src0 + src1.
+template <typename T, int SZ>
+__XETLA_API xetla_vector<T, SZ> xetla_add_c(xetla_vector<T, SZ> src0,
+ xetla_vector<T, SZ> src1, xetla_vector_ref<T, SZ> __REF__ carry) {
+ static_assert((std::is_same<remove_const_t<T>, uint32_t>::value),
+ "For addc, only uint32_t is supported");
+ return cm_addc(src0, src1, carry);
+}
+
+/// Add one unsigned integer vectors with a scalar, return the result and in-place update the carry.
+/// @tparam T element type of the src, should be uint32_t.
+/// @tparam SZ element num of the vector.
+/// @param src0 is the src0 of the add operation.
+/// @param src1 is the src1 of the add operation.
+/// @param carry is the carry of the add operation.
+/// @return result of the src0 + src1.
+template <typename T, int SZ>
+__XETLA_API xetla_vector<T, SZ> xetla_add_c(xetla_vector<T, SZ> src0, T src1,
+ xetla_vector_ref<T, SZ> __REF__ carry) {
+ static_assert((std::is_same<remove_const_t<T>, uint32_t>::value),
+ "For addc, only uint32_t is supported");
+ return cm_addc(src0, src1, carry);
+}
+
+/// @brief Multiply src0 with src1, return the hi part and in-place update the lo part.
+/// @tparam T0 Return data type, should be 32 bit integer.
+/// @tparam T1 Type of src0, should be 32 bit integer.
+/// @tparam T2 Type of src1, should be 32 bit integer.
+/// @tparam SZ Element num of the vector.
+/// @param lo is the low 32 bit part of the result.
+/// @param src0 is the src0 of the mul operation.
+/// @param src1 is the src1 of the mul operation.
+/// @return return the high 32 bit part of the result.
+template <typename T0, typename T1, typename T2, int SZ>
+__XETLA_API xetla_vector<T0, SZ> xetla_imul(xetla_vector_ref<T0, SZ> __REF__ lo,
+ xetla_vector<T1, SZ> src0, T2 src1) {
+ return cm_imul(lo, src0, src1);
+}
+
+/// Performs reduction over elements of the input vector.
+/// @tparam T0 type of the return value.
+/// @tparam T1 element type of the input vector.
+/// @tparam SZ size of the input vector.
+/// @tparam BinaryOperation type representing the operation. Can be an
+/// instantion of one of the following types:
+/// \li \c reduce_op::sum, performs reduce sum operation
+/// \li \c reduce_op::prod, performs reduce prod operation
+/// \li \c reduce_op::min, performs reduce min operation
+/// \li \c reduce_op::max, performs reduce max operation
+/// @param v the vector to perform reduction on
+/// @return result of the reduction
+template <typename T0, typename T1, int SZ, reduce_op BinaryOperation>
+__XETLA_API T0 xetla_reduce(xetla_vector<T1, SZ> v) {
+ if constexpr (BinaryOperation == reduce_op::sum) {
+ return cm_sum<T0, T1, SZ>(v);
+ } else if constexpr (BinaryOperation == reduce_op::prod) {
+ return cm_prod<T0, T1, SZ>(v);
+ } else if constexpr (BinaryOperation == reduce_op::min) {
+ return cm_reduced_min<T0, T1, SZ>(v);
+ } else if constexpr (BinaryOperation == reduce_op::max) {
+ return cm_reduced_max<T0, T1, SZ>(v);
+ }
+}
+
+/// Get rounded value
+/// @tparam T element type of the input vector.
+/// @tparam SZ size of the input and returned vector.
+/// @param src0 the input vector.
+/// @return vector of rounded values.
+template <typename T, int SZ>
+__XETLA_API xetla_vector<T, SZ> xetla_rnde(xetla_vector<T, SZ> src0) {
+ static_assert(!(is_internal_type<T>::value),
+ "The internal types are not yet supported!");
+ return cm_rnde<T, SZ>(src0);
+}
+
+/// Adds two vectors with saturation
+/// The source operands must be both of floating-point type.
+/// @tparam T0 element type of the input vectors.
+/// @tparam T1 element type of the return vector.
+/// @tparam SZ size of the input and returned vectors.
+/// @param src0 the input vector.
+/// @param src1 the input vector.
+/// @param sat enables/disables the saturation (off by default). Possible
+/// values: saturation_on/saturation_off.
+/// @return vector of component-wise additive elements.
+template <typename T1, typename T0, int SZ,
+ typename Sat = xetla_saturation_off_tag>
+__XETLA_API xetla_vector<T1, SZ> xetla_add(
+ xetla_vector<T0, SZ> src0, xetla_vector<T0, SZ> src1, Sat sat = {}) {
+ static_assert(
+ !((is_internal_type<T0>::value) || (is_internal_type<T1>::value)),
+ "The internal types are not yet supported!");
+ return cm_add<T1>(src0, src1, sat.value);
+}
+
+/// Saturation function.
+/// @tparam T0 element type of the input vectors.
+/// @tparam T1 element type of the return vector.
+/// @tparam SZ size of the input and returned vectors.
+template <typename T1, typename T0, int SZ>
+__XETLA_API xetla_vector<T1, SZ> xetla_sat(xetla_vector<T0, SZ> src) {
+ static_assert(
+ !((is_internal_type<T0>::value) || (is_internal_type<T1>::value)),
+ "The internal types are not yet supported!");
+ return xetla_vector<T1, SZ>(src, SAT);
+}
+
+/// Count number of bits set in the source operand per element.
+/// @param src0 the source operand to count bits in.
+/// @return a vector of \c uint32_t, where each element is set to bit count of
+/// the corresponding element of the source operand.
+template <typename T, int N>
+__XETLA_API std::enable_if_t<std::is_integral<T>::value && (sizeof(T) <= 4),
+ xetla_vector<uint32_t, N>>
+xetla_cbit(xetla_vector<T, N> src) {
+ return cm_cbit<T, N>(src);
+}
+
+/// Scalar version of \c cbit - both input and output are scalars rather
+/// than vectors.
+template <typename T>
+__XETLA_API std::enable_if_t<std::is_integral<T>::value && (sizeof(T) <= 4),
+ uint32_t>
+xetla_cbit(T src) {
+ return cm_cbit<T>(src);
+}
+
+/// @} xetla_core_math
+
+} // namespace gpu::xetla
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/math_mma.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/math_mma.hpp
new file mode 100644
index 00000000000..601620f83de
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/math_mma.hpp
@@ -0,0 +1,147 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#ifdef _WIN32
+#include "../../../common/core/cm/common.hpp"
+#else
+#include "common/core/cm/common.hpp"
+#endif
+
+namespace gpu::xetla {
+namespace detail {
+
+///
+///@brief convert normal data type to dpas argument type
+///
+///
+template <typename dtype>
+constexpr gpu::xetla::argument_type mma_argument_type() {
+ return gpu::xetla::argument_type::U2;
+}
+
+template <>
+constexpr gpu::xetla::argument_type mma_argument_type<tf32>() {
+ return gpu::xetla::argument_type::TF32;
+}
+
+template <>
+constexpr gpu::xetla::argument_type mma_argument_type<float>() {
+ return gpu::xetla::argument_type::TF32;
+}
+
+template <>
+constexpr gpu::xetla::argument_type mma_argument_type<int8_t>() {
+ return gpu::xetla::argument_type::S8;
+}
+
+template <>
+constexpr gpu::xetla::argument_type mma_argument_type<uint8_t>() {
+ return gpu::xetla::argument_type::U8;
+}
+
+template <>
+constexpr gpu::xetla::argument_type mma_argument_type<bf16>() {
+ return gpu::xetla::argument_type::BF16;
+}
+
+template <>
+constexpr gpu::xetla::argument_type mma_argument_type<fp16>() {
+ return gpu::xetla::argument_type::FP16;
+}
+
+/// @brief lookup table for dpas argument type
+///
+///
+template <gpu::xetla::argument_type arg_type>
+constexpr CmPrecisionType get_argument_type() {
+ static_assert(arg_type == gpu::xetla::argument_type::U2
+ || arg_type == gpu::xetla::argument_type::S2
+ || arg_type == gpu::xetla::argument_type::U4
+ || arg_type == gpu::xetla::argument_type::S4
+ || arg_type == gpu::xetla::argument_type::U8
+ || arg_type == gpu::xetla::argument_type::S8
+ || arg_type == gpu::xetla::argument_type::FP16
+ || arg_type == gpu::xetla::argument_type::BF16
+ || arg_type == gpu::xetla::argument_type::TF32,
+ "Unsupported argument type");
+ switch (arg_type) {
+ case gpu::xetla::argument_type::U2:
+ return CmPrecisionType::CM_Precision_U2;
+ case gpu::xetla::argument_type::S2:
+ return CmPrecisionType::CM_Precision_S2;
+ case gpu::xetla::argument_type::U4:
+ return CmPrecisionType::CM_Precision_U4;
+ case gpu::xetla::argument_type::S4:
+ return CmPrecisionType::CM_Precision_S4;
+ case gpu::xetla::argument_type::U8:
+ return CmPrecisionType::CM_Precision_U8;
+ case gpu::xetla::argument_type::S8:
+ return CmPrecisionType::CM_Precision_S8;
+ case gpu::xetla::argument_type::BF16:
+ return CmPrecisionType::CM_Precision_BF16;
+ case gpu::xetla::argument_type::FP16:
+ return CmPrecisionType::CM_Precision_FP16;
+ case gpu::xetla::argument_type::TF32:
+ return CmPrecisionType::CM_Precision_TF32;
+ default:;
+ }
+}
+} // namespace detail
+
+/// @addtogroup xetla_core_math
+/// @{
+
+///
+///@brief description of xetla mma
+/// perform matrix multiply add operation
+///@tparam src1_precision is the data precision of src1
+///@tparam src2_precision is the data precision of src2
+///@tparam systolic_depth is the depth of mma (i.e k dimension size in dword)
+///@tparam repeat_count is the row (m) of mma (mxkxn)
+///@tparam T is the data type of src0 and dst
+///@tparam T1 is the data type of src1
+///@tparam T2 is the data type of src2
+///@tparam N is the total number of elements in src0 and dst
+///@tparam N1 is the total number of elements in src1
+///@tparam N2 is the total number of elements in src2
+///@tparam Sat is saturation flag
+///@param src0 [in] is src0
+///@param src1 [in] is src1
+///@param src2 [in] is src2
+///@param sat [in] is saturation flag
+///@return is dst, a xetla_vector of type T and element size of N
+///
+
+/// todo: we need to remove argument_type and get the currect precision based on data type
+template <argument_type src1_precision, argument_type src2_precision,
+ int systolic_depth, int repeat_count, typename T, typename T1,
+ typename T2, int N, int N1, int N2,
+ typename Sat = xetla_saturation_off_tag>
+__XETLA_API xetla_vector<T, N> xetla_mma(xetla_vector<T, N> src0,
+ xetla_vector<T1, N1> src1, xetla_vector<T2, N2> src2, Sat sat = {}) {
+ return cm_dpas<detail::get_argument_type<src1_precision>(),
+ detail::get_argument_type<src2_precision>(), systolic_depth,
+ repeat_count>(src0, src1, src2, Sat::value);
+}
+
+/// @} xetla_core_math
+
+} // namespace gpu::xetla
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/memory.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/memory.hpp
new file mode 100644
index 00000000000..e405cc2848b
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/memory.hpp
@@ -0,0 +1,605 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#ifdef _WIN32
+#include "../../../common/core/cm/base_ops.hpp"
+#include "../../../common/core/cm/base_types.hpp"
+#include "../../../common/core/cm/common.hpp"
+#include "../../../common/utils/cm/limitation.hpp"
+
+#else
+#include "common/core/cm/base_ops.hpp"
+#include "common/core/cm/base_types.hpp"
+#include "common/core/cm/common.hpp"
+#include "common/utils/cm/limitation.hpp"
+#endif
+
+namespace gpu::xetla {
+
+namespace detail {
+
+/// @brief lookup table for cache hint.
+///
+///
+constexpr CacheHint get_cache_hint(gpu::xetla::cache_hint ch) {
+ switch (ch) {
+ case gpu::xetla::cache_hint::none: return CacheHint::Default;
+ case gpu::xetla::cache_hint::uncached: return CacheHint::Uncached;
+ case gpu::xetla::cache_hint::cached: return CacheHint::Cached;
+ case gpu::xetla::cache_hint::write_back: return CacheHint::WriteBack;
+ case gpu::xetla::cache_hint::write_through:
+ return CacheHint::WriteThrough;
+ case gpu::xetla::cache_hint::streaming: return CacheHint::Streaming;
+ case gpu::xetla::cache_hint::read_invalidate:
+ return CacheHint::ReadInvalidate;
+ }
+}
+
+/// @brief lookup table for data size.
+///
+///
+constexpr DataSize get_data_size(gpu::xetla::data_size ds) {
+ switch (ds) {
+ case gpu::xetla::data_size::default_size: return DataSize::Default;
+ case gpu::xetla::data_size::u8: return DataSize::U8;
+ case gpu::xetla::data_size::u16: return DataSize::U16;
+ case gpu::xetla::data_size::u32: return DataSize::U32;
+ case gpu::xetla::data_size::u64: return DataSize::U64;
+ case gpu::xetla::data_size::u8u32: return DataSize::U8U32;
+ case gpu::xetla::data_size::u16u32: return DataSize::U16U32;
+ case gpu::xetla::data_size::u16u32h: return DataSize::U16U32H;
+ }
+}
+
+/// @brief lookup table for memory kind.
+///
+///
+constexpr LSC_SFID get_memory_kind(gpu::xetla::memory_kind mk) {
+ switch (mk) {
+ case gpu::xetla::memory_kind::untyped_global: return LSC_SFID::LSC_UGM;
+ case gpu::xetla::memory_kind::untyped_global_low_pri:
+ return LSC_SFID::LSC_UGML;
+ case gpu::xetla::memory_kind::typed_global: return LSC_SFID::LSC_TGM;
+ case gpu::xetla::memory_kind::shared_local: return LSC_SFID::LSC_SLM;
+ }
+}
+
+/// @brief lookup table for fence op.
+///
+///
+constexpr LSC_FENCE_OP get_fence_op(gpu::xetla::fence_op fo) {
+ switch (fo) {
+ case gpu::xetla::fence_op::none: return LSC_FENCE_OP::LSC_FENCE_OP_NONE;
+ case gpu::xetla::fence_op::evict:
+ return LSC_FENCE_OP::LSC_FENCE_OP_EVICT;
+ case gpu::xetla::fence_op::invalidate:
+ return LSC_FENCE_OP::LSC_FENCE_OP_INVALIDATE;
+ case gpu::xetla::fence_op::discard:
+ return LSC_FENCE_OP::LSC_FENCE_OP_DISCARD;
+ case gpu::xetla::fence_op::clean:
+ return LSC_FENCE_OP::LSC_FENCE_OP_CLEAN;
+ case gpu::xetla::fence_op::flushl2:
+ return LSC_FENCE_OP::LSC_FENCE_OP_FLUSHL3;
+ }
+}
+
+/// @brief lookup table for fence scope.
+///
+///
+constexpr LSC_SCOPE get_fence_scope(gpu::xetla::fence_scope fs) {
+ switch (fs) {
+ case gpu::xetla::fence_scope::group: return LSC_SCOPE::LSC_SCOPE_GROUP;
+ case gpu::xetla::fence_scope::local: return LSC_SCOPE::LSC_SCOPE_LOCAL;
+ case gpu::xetla::fence_scope::tile: return LSC_SCOPE::LSC_SCOPE_TILE;
+ case gpu::xetla::fence_scope::gpu: return LSC_SCOPE::LSC_SCOPE_GPU;
+ case gpu::xetla::fence_scope::gpus: return LSC_SCOPE::LSC_SCOPE_GPUS;
+ case gpu::xetla::fence_scope::system:
+ return LSC_SCOPE::LSC_SCOPE_SYSTEM;
+ case gpu::xetla::fence_scope::sysacq:
+ return LSC_SCOPE::LSC_SCOPE_SYSACQ;
+ }
+}
+
+/// @brief lookup table for atomic op.
+///
+///
+constexpr AtomicOp get_atomic_op(gpu::xetla::atomic_op ao) {
+ switch (ao) {
+ case gpu::xetla::atomic_op::iinc: return AtomicOp::IINC;
+ case gpu::xetla::atomic_op::idec: return AtomicOp::IDEC;
+ case gpu::xetla::atomic_op::iadd: return AtomicOp::IADD;
+ case gpu::xetla::atomic_op::isub: return AtomicOp::ISUB;
+ case gpu::xetla::atomic_op::smin: return AtomicOp::SMIN;
+ case gpu::xetla::atomic_op::smax: return AtomicOp::SMAX;
+ case gpu::xetla::atomic_op::cmpxchg: return AtomicOp::ICAS;
+ case gpu::xetla::atomic_op::fadd: return AtomicOp::FADD;
+ case gpu::xetla::atomic_op::fsub: return AtomicOp::FSUB;
+ case gpu::xetla::atomic_op::fmin: return AtomicOp::FMIN;
+ case gpu::xetla::atomic_op::fmax: return AtomicOp::FMAX;
+ case gpu::xetla::atomic_op::fcmpxchg: return AtomicOp::FCAS;
+ case gpu::xetla::atomic_op::umin: return AtomicOp::UMIN;
+ case gpu::xetla::atomic_op::umax: return AtomicOp::UMAX;
+ case gpu::xetla::atomic_op::bit_and: return AtomicOp::AND;
+ case gpu::xetla::atomic_op::bit_or: return AtomicOp::OR;
+ case gpu::xetla::atomic_op::bit_xor: return AtomicOp::XOR;
+ case gpu::xetla::atomic_op::load: return AtomicOp::LOAD;
+ case gpu::xetla::atomic_op::store: return AtomicOp::STORE;
+ default: return AtomicOp::STORE;
+ }
+}
+} // namespace detail
+
+/// @addtogroup xetla_core_memory
+/// @{
+
+/// @brief Stateless scattered prefetch.
+/// Prefetches elements located at specified address.
+///
+/// Supported platforms: DG2, PVC
+///
+/// VISA instruction: lsc_load.ugm
+///
+/// @tparam Ty is element type.
+/// @tparam NElts is the number of elements to prefetch per address (i.e. vector_size per SIMD channel).
+/// @tparam DS is the data size.
+/// @tparam L1H is L1 cache hint.
+/// @tparam L2H is L2 cache hint.
+/// @tparam N is the number of SIMD channels (platform dependent).
+/// @param p [in] is the base pointer.
+/// @param offsets [in] is the zero-based offsets in bytes.
+/// @param pred [in] is predicates.
+///
+template <typename Ty, uint8_t NElts = 1,
+ data_size DS = data_size::default_size,
+ cache_hint L1H = cache_hint::cached,
+ cache_hint L2H = cache_hint::cached, int N>
+__XETLA_API void xetla_prefetch_global(
+ Ty *p, xetla_vector<uint32_t, N> offsets, xetla_mask<N> pred = 1) {
+ using T = native_type_t<Ty>;
+ constexpr DataSize _DS = details::lsc_expand_ds(
+ details::lsc_data_size<T, gpu::xetla::detail::get_data_size(DS)>());
+ cm_ptr_prefetch<details::lsc_vector_size<NElts>(), _DS,
+ gpu::xetla::detail::get_cache_hint(L1H),
+ gpu::xetla::detail::get_cache_hint(L2H), N>(
+ (const unsigned *const)p, offsets, pred);
+}
+
+/// @brief Stateless block prefetch (transposed gather with 1 channel).
+/// Prefetches elements located at specified address.
+///
+/// Supported platforms: DG2, PVC
+///
+/// VISA instruction: lsc_load.ugm
+///
+/// @tparam Ty is element type.
+/// @tparam NElts is the number of elements to prefetch per address (i.e. vector_size per SIMD channel).
+/// @tparam DS is the data size.
+/// @tparam L1H is L1 cache hint.
+/// @tparam L2H is L2 cache hint.
+/// @param p [in] is the base pointer.
+/// @param offset [in] is the zero-based offset in bytes.
+///
+template <typename Ty, uint8_t NElts = 1,
+ data_size DS = data_size::default_size,
+ cache_hint L1H = cache_hint::cached,
+ cache_hint L2H = cache_hint::cached>
+__XETLA_API void xetla_prefetch_global(Ty *p, uint64_t offset = 0) {
+ using T = native_type_t<Ty>;
+ constexpr DataSize _DS = details::lsc_expand_ds(
+ details::lsc_data_size<T, gpu::xetla::detail::get_data_size(DS)>());
+ cm_ptr_prefetch<NElts, _DS, gpu::xetla::detail::get_cache_hint(L1H),
+ gpu::xetla::detail::get_cache_hint(L2H)>(
+ (const unsigned *const)p, offset);
+}
+
+/// @brief Stateless scattered load.
+/// Collects elements located at specified address and returns them
+/// to a single \ref xetla_vector object.
+///
+/// Supported platforms: DG2, PVC
+///
+/// VISA instruction: lsc_load.ugm
+///
+/// @tparam Ty is element type.
+/// @tparam NElts is the number of elements to load per address (i.e. vector_size per SIMD channel).
+/// @tparam DS is the data size.
+/// @tparam L1H is L1 cache hint.
+/// @tparam L2H is L2 cache hint.
+/// @tparam N is the number of SIMD channels (platform dependent).
+/// @param p [in] is the base pointer.
+/// @param offsets [in] is the zero-based offsets in bytes.
+/// @param pred [in] is predicates.
+/// @return is a xetla_vector of type T and size N * NElts.
+///
+template <typename Ty, uint8_t NElts = 1,
+ data_size DS = data_size::default_size,
+ cache_hint L1H = cache_hint::none, cache_hint L2H = cache_hint::none,
+ int N, typename Toffset = uint32_t>
+__XETLA_API xetla_vector<Ty, N * NElts> xetla_load_global(
+ Ty *p, xetla_vector<Toffset, N> offsets, xetla_mask<N> pred = 1) {
+ using T = native_type_t<Ty>;
+ return cm_ptr_load<T, details::lsc_vector_size<NElts>(),
+ gpu::xetla::detail::get_data_size(DS),
+ gpu::xetla::detail::get_cache_hint(L1H),
+ gpu::xetla::detail::get_cache_hint(L2H), N>((T *)p, offsets, pred);
+}
+
+/// @brief Stateless block load (transposed gather with 1 channel).
+/// Collects elements located at specified address and returns them
+/// to a single \ref xetla_vector object.
+///
+/// Supported platforms: DG2, PVC
+///
+/// VISA instruction: lsc_load.ugm
+///
+/// @tparam Ty is element type.
+/// @tparam NElts is the number of elements to load per address (i.e. vector_size per SIMD channel).
+/// @tparam DS is the data size.
+/// @tparam L1H is L1 cache hint.
+/// @tparam L2H is L2 cache hint.
+/// @param p [in] is the base pointer.
+/// @param offset [in] is the zero-based offset in bytes.
+/// @return is a xetla_vector of type T and size NElts.
+///
+template <typename Ty, uint8_t NElts = 1,
+ data_size DS = data_size::default_size,
+ cache_hint L1H = cache_hint::none, cache_hint L2H = cache_hint::none>
+__XETLA_API xetla_vector<Ty, NElts> xetla_load_global(
+ Ty *p, uint64_t offset = 0) {
+ using T = native_type_t<Ty>;
+ return cm_ptr_load<T, NElts, gpu::xetla::detail::get_data_size(DS),
+ gpu::xetla::detail::get_cache_hint(L1H),
+ gpu::xetla::detail::get_cache_hint(L2H)>((T *)p, offset);
+}
+
+/// @brief Stateless scattered store.
+/// Writes elements to specific address.
+///
+/// Supported platforms: DG2, PVC
+///
+/// VISA instruction: lsc_store.ugm
+///
+/// @tparam Ty is element type.
+/// @tparam NElts is the number of elements to store per address (i.e. vector_size per SIMD channel).
+/// @tparam DS is the data size.
+/// @tparam L1H is L1 cache hint.
+/// @tparam L2H is L2 cache hint.
+/// @tparam N is the number of SIMD channels (platform dependent).
+/// @param p [in] is the base pointer.
+/// @param offsets [in] is the zero-based offsets in bytes.
+/// @param vals [in] is values to store.
+/// @param pred [in] is predicates.
+///
+template <typename Ty, uint8_t NElts = 1,
+ data_size DS = data_size::default_size,
+ cache_hint L1H = cache_hint::none, cache_hint L2H = cache_hint::none,
+ int N>
+__XETLA_API void xetla_store_global(Ty *p, xetla_vector<uint32_t, N> offsets,
+ xetla_vector<Ty, N * NElts> vals, xetla_mask<N> pred = 1) {
+ using T = native_type_t<Ty>;
+ cm_ptr_store<T, details::lsc_vector_size<NElts>(),
+ gpu::xetla::detail::get_data_size(DS),
+ gpu::xetla::detail::get_cache_hint(L1H),
+ gpu::xetla::detail::get_cache_hint(L2H), N>(
+ (T *)p, offsets, vals, pred);
+}
+
+/// @brief Stateless block store (transposed scatter with 1 channel).
+/// Writes elements to specific address.
+///
+/// Supported platforms: DG2, PVC
+///
+/// VISA instruction: lsc_store.ugm
+///
+/// @tparam Ty is element type.
+/// @tparam NElts is the number of elements to store per address (i.e. vector_size per SIMD channel).
+/// @tparam DS is the data size.
+/// @tparam L1H is L1 cache hint.
+/// @tparam L2H is L2 cache hint.
+/// @param p [in] is the base pointer.
+/// @param offset [in] is the zero-based offset in bytes.
+/// @param vals [in] is values to store.
+///
+template <typename Ty, uint8_t NElts = 1,
+ data_size DS = data_size::default_size,
+ cache_hint L1H = cache_hint::none, cache_hint L2H = cache_hint::none>
+__XETLA_API void xetla_store_global(
+ Ty *p, uint64_t offset, xetla_vector<Ty, NElts> vals) {
+ using T = native_type_t<Ty>;
+ cm_ptr_store<T, NElts, gpu::xetla::detail::get_data_size(DS),
+ gpu::xetla::detail::get_cache_hint(L1H),
+ gpu::xetla::detail::get_cache_hint(L2H)>((T *)p, offset, vals);
+}
+
+/// @brief Stateless scattered atomic (0 src).
+/// Supported platforms: DG2, PVC
+/// VISA instruction: lsc_atomic_<OP>.ugm
+///
+/// @tparam Op is operation type.
+/// @tparam T is element type.
+/// @tparam N is the number of SIMD channels (platform dependent).
+/// @tparam DS is the data size.
+/// @tparam L1H is L1 cache hint.
+/// @tparam L2H is L2 cache hint.
+/// @param p [in] is the base pointer.
+/// @param offsets [in] is the zero-based offsets.
+/// @param pred [in] is predicates.
+///
+template <atomic_op Op, typename T, int N,
+ data_size DS = data_size::default_size,
+ cache_hint L1H = cache_hint::none, cache_hint L2H = cache_hint::none>
+__XETLA_API xetla_vector<T, N> xetla_atomic_global(
+ T *p, xetla_vector<uint32_t, N> offsets, xetla_mask<N> pred) {
+ static_assert(!(is_internal_type<T>::value),
+ "The internal types are not yet supported!");
+ return cm_ptr_atomic<gpu::xetla::detail::get_atomic_op(Op), T,
+ VectorSize::N1, gpu::xetla::detail::get_data_size(DS),
+ gpu::xetla::detail::get_cache_hint(L1H),
+ gpu::xetla::detail::get_cache_hint(L2H)>(p, offsets, pred);
+}
+
+/// @brief Stateless scattered atomic (1 src).
+/// Supported platforms: DG2, PVC
+/// VISA instruction: lsc_atomic_<OP>.ugm
+///
+/// @tparam Op is operation type.
+/// @tparam T is element type.
+/// @tparam N is the number of SIMD channels (platform dependent).
+/// @tparam DS is the data size.
+/// @tparam L1H is L1 cache hint.
+/// @tparam L2H is L2 cache hint.
+/// @param p [in] is the base pointer.
+/// @param offsets [in] is the zero-based offsets.
+/// @param src0 [in] is the first atomic operand.
+/// @param pred [in] is predicates.
+///
+template <atomic_op Op, typename T, int N,
+ data_size DS = data_size::default_size,
+ cache_hint L1H = cache_hint::none, cache_hint L2H = cache_hint::none>
+__XETLA_API xetla_vector<T, N> xetla_atomic_global(T *p,
+ xetla_vector<uint32_t, N> offsets, xetla_vector<T, N> src0,
+ xetla_mask<N> pred) {
+ static_assert(!(is_internal_type<T>::value),
+ "The internal types are not yet supported!");
+ return cm_ptr_atomic<gpu::xetla::detail::get_atomic_op(Op), T,
+ VectorSize::N1, gpu::xetla::detail::get_data_size(DS),
+ gpu::xetla::detail::get_cache_hint(L1H),
+ gpu::xetla::detail::get_cache_hint(L2H)>(p, offsets, src0, pred);
+}
+
+/// @brief Stateless scattered atomic (2 src).
+/// Supported platforms: DG2, PVC
+/// VISA instruction: lsc_atomic_<OP>.ugm
+///
+/// @tparam Op is operation type.
+/// @tparam T is element type.
+/// @tparam N is the number of SIMD channels (platform dependent).
+/// @tparam DS is the data size.
+/// @tparam L1H is L1 cache hint.
+/// @tparam L2H is L2 cache hint.
+/// @param p [in] is the base pointer.
+/// @param offsets [in] is the zero-based offsets.
+/// @param src0 [in] is the first atomic operand.
+/// @param src1 [in] is the second atomic operand.
+/// @param pred [in] is predicates.
+///
+template <atomic_op Op, typename T, int N,
+ data_size DS = data_size::default_size,
+ cache_hint L1H = cache_hint::none, cache_hint L2H = cache_hint::none>
+__XETLA_API xetla_vector<T, N> xetla_atomic_global(T *p,
+ xetla_vector<uint32_t, N> offsets, xetla_vector<T, N> src0,
+ xetla_vector<T, N> src1, xetla_mask<N> pred) {
+ static_assert(!(is_internal_type<T>::value),
+ "The internal types are not yet supported!");
+ return cm_ptr_atomic<gpu::xetla::detail::get_atomic_op(Op), T,
+ VectorSize::N1, gpu::xetla::detail::get_data_size(DS),
+ gpu::xetla::detail::get_cache_hint(L1H),
+ gpu::xetla::detail::get_cache_hint(L2H)>(
+ p, offsets, src0, src1, pred);
+}
+/// @brief Declare per-work-group slm size.
+/// @tparam SLMSize Shared Local Memory (SLM) size (in Bytes).
+template <uint32_t SLMSize>
+__XETLA_API void xetla_local_init() {
+ cm_slm_init(SLMSize);
+}
+
+/// @brief SLM scattered load.
+/// Collects elements located at slm and returns them as a single \ref xetla_vector object.
+///
+/// Supported platforms: DG2, PVC
+///
+/// VISA instruction: lsc_load.slm
+///
+/// @tparam Ty is element type.
+/// @tparam NElts is the number of elements to load per address (i.e. vector_size per SIMD channel).
+/// @tparam DS is the data size.
+/// @tparam N is the number of SIMD channels (platform dependent).
+/// @param offsets [in] is the zero-based offsets for SLM buffer in bytes.
+/// @param pred [in] is predicates.
+/// @return is a xetla_vector of type T and size N * NElts.
+///
+template <typename Ty, uint8_t NElts = 1,
+ data_size DS = data_size::default_size, int N>
+__XETLA_API xetla_vector<Ty, N * NElts> xetla_load_local(
+ xetla_vector<uint32_t, N> offsets, xetla_mask<N> pred = 1) {
+ using T = native_type_t<Ty>;
+ return cm_load_slm<T, details::lsc_vector_size<NElts>(),
+ gpu::xetla::detail::get_data_size(DS), N>(offsets, pred);
+}
+
+/// @brief SLM block load. (transposed gather with 1 channel).
+/// Collects elements located at slm and returns them as a single \ref xetla_vector object.
+///
+/// Supported platforms: DG2, PVC
+///
+/// VISA instruction: lsc_load.slm
+///
+/// @tparam Ty is element type.
+/// @tparam NElts is the number of elements to load per address (i.e. vector_size per SIMD channel).
+/// @tparam DS is the data size.
+/// @param offset [in] is the zero-based offset for SLM buffer in bytes.
+/// @return is a xetla_vector of type T and size NElts.
+///
+template <typename Ty, uint8_t NElts = 1,
+ data_size DS = data_size::default_size>
+__XETLA_API xetla_vector<Ty, NElts> xetla_load_local(uint32_t offset) {
+ using T = native_type_t<Ty>;
+ return cm_load_slm<T, NElts, gpu::xetla::detail::get_data_size(DS)>(offset);
+}
+
+/// @brief SLM scattered store.
+/// Scatters elements located to slm.
+///
+/// Supported platforms: DG2, PVC
+///
+/// VISA instruction: lsc_store.slm
+///
+/// @tparam Ty is element type.
+/// @tparam NElts is the number of elements to store per address (i.e. vector_size per SIMD channel).
+/// @tparam DS is the data size.
+/// @tparam N is the number of SIMD channels (platform dependent).
+/// @param offsets [in] is the zero-based offsets for SLM buffer in bytes.
+/// @param vals [in] is values to store.
+/// @param pred [in] is predicates.
+///
+template <typename Ty, uint8_t NElts = 1,
+ data_size DS = data_size::default_size, int N>
+__XETLA_API void xetla_store_local(xetla_vector<uint32_t, N> offsets,
+ xetla_vector<Ty, N * NElts> vals, xetla_mask<N> pred = 1) {
+ using T = native_type_t<Ty>;
+ cm_store_slm<T, details::lsc_vector_size<NElts>(),
+ gpu::xetla::detail::get_data_size(DS), N>(offsets, vals, pred);
+}
+
+/// @brief SLM block store (transposed SLM scatter with 1 channel).
+/// Scatters elements located to slm.
+///
+/// Supported platforms: DG2, PVC
+///
+/// VISA instruction: lsc_store.slm
+///
+/// @tparam Ty is element type.
+/// @tparam NElts is the number of elements to store per address (i.e. vector_size per SIMD channel).
+/// @tparam DS is the data size.
+/// @param offset [in] is the zero-based offset for SLM buffer in bytes.
+/// @param vals [in] is values to store.
+///
+template <typename Ty, uint8_t NElts = 1,
+ data_size DS = data_size::default_size>
+__XETLA_API void xetla_store_local(
+ uint32_t offset, xetla_vector<Ty, NElts> vals) {
+ using T = native_type_t<Ty>;
+ cm_store_slm<T, NElts, gpu::xetla::detail::get_data_size(DS)>(offset, vals);
+}
+
+/// @brief SLM scattered atomic (0 src).
+/// Supported platforms: DG2, PVC
+/// VISA instruction: lsc_atomic_<OP>.slm
+///
+/// @tparam Op is operation type.
+/// @tparam T is element type.
+/// @tparam N is the number of SIMD channels (platform dependent).
+/// @tparam DS is the data size.
+/// @param offsets [in] is the zero-based offsets.
+/// @param pred [in] is predicates.
+///
+template <atomic_op Op, typename T, int N,
+ data_size DS = data_size::default_size>
+__XETLA_API xetla_vector<T, N> xetla_atomic_local(
+ xetla_vector<uint32_t, N> offsets, xetla_mask<N> pred) {
+ static_assert(!(is_internal_type<T>::value),
+ "The internal types are not yet supported!");
+ return cm_atomic_slm<gpu::xetla::detail::get_atomic_op(Op), T,
+ VectorSize::N1, gpu::xetla::detail::get_data_size(DS),
+ CacheHint::Default, CacheHint::Default, N>(offsets, pred);
+}
+
+/// @brief SLM scattered atomic (1 src).
+/// Supported platforms: DG2, PVC
+/// VISA instruction: lsc_atomic_<OP>.slm
+///
+/// @tparam Op is operation type.
+/// @tparam T is element type.
+/// @tparam N is the number of SIMD channels (platform dependent).
+/// @tparam DS is the data size.
+/// @param offsets [in] is the zero-based offsets.
+/// @param src0 [in] is the first atomic operand.
+/// @param pred [in] is predicates.
+///
+template <atomic_op Op, typename T, int N,
+ data_size DS = data_size::default_size>
+__XETLA_API xetla_vector<T, N> xetla_atomic_local(
+ xetla_vector<uint32_t, N> offsets, xetla_vector<T, N> src0,
+ xetla_mask<N> pred) {
+ static_assert(!(is_internal_type<T>::value),
+ "The internal types are not yet supported!");
+ return cm_atomic_slm<gpu::xetla::detail::get_atomic_op(Op), T,
+ VectorSize::N1, gpu::xetla::detail::get_data_size(DS),
+ CacheHint::Default, CacheHint::Default, N>(offsets, src0, pred);
+}
+
+/// @brief SLM scattered atomic (2 src).
+/// Supported platforms: DG2, PVC
+/// VISA instruction: lsc_atomic_<OP>.slm
+///
+/// @tparam Op is operation type.
+/// @tparam T is element type.
+/// @tparam N is the number of SIMD channels (platform dependent).
+/// @tparam DS is the data size.
+/// @param offsets [in] is the zero-based offsets.
+/// @param src0 [in] is the first atomic operand.
+/// @param src1 [in] is the second atomic operand.
+/// @param pred [in] is predicates.
+///
+template <atomic_op Op, typename T, int N,
+ data_size DS = data_size::default_size>
+__XETLA_API xetla_vector<T, N> xetla_atomic_local(
+ xetla_vector<uint32_t, N> offsets, xetla_vector<T, N> src0,
+ xetla_vector<T, N> src1, xetla_mask<N> pred) {
+ static_assert(!(is_internal_type<T>::value),
+ "The internal types are not yet supported!");
+ return cm_atomic_slm<gpu::xetla::detail::get_atomic_op(Op), T,
+ VectorSize::N1, gpu::xetla::detail::get_data_size(DS),
+ CacheHint::Default, CacheHint::Default, N>(
+ offsets, src0, src1, pred);
+}
+
+/// @brief Memory fence.
+/// Supported platforms: DG2, PVC
+///
+/// @tparam Kind is the Sfid shaded function.
+/// @tparam FenceOp is the fence operation.
+/// @tparam Scope is the operation scope.
+/// @tparam N is the number of SIMD channels (platform dependent).
+/// @param pred is predicates.
+template <memory_kind Kind = memory_kind::untyped_global,
+ fence_op FenceOp = fence_op::none,
+ fence_scope Scope = fence_scope::group, int N = 16>
+__XETLA_API void xetla_fence(xetla_mask<N> pred = 1) {
+ cm_fence<gpu::xetla::detail::get_memory_kind(Kind),
+ gpu::xetla::detail::get_fence_op(FenceOp),
+ gpu::xetla::detail::get_fence_scope(Scope), N>();
+}
+
+/// @} xetla_core_memory
+
+} // namespace gpu::xetla
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/misc.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/misc.hpp
new file mode 100644
index 00000000000..1d7e4b4fc5a
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/misc.hpp
@@ -0,0 +1,39 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#ifdef _WIN32
+#include "../../../common/core/cm/base_ops.hpp"
+#include "../../../common/core/cm/base_types.hpp"
+#include "../../../common/core/cm/common.hpp"
+#else
+#include "common/core/cm/base_ops.hpp"
+#include "common/core/cm/base_types.hpp"
+#include "common/core/cm/common.hpp"
+#endif
+
+namespace gpu::xetla {
+
+/// @addtogroup xetla_core_misc
+/// @{
+
+/// @} xetla_core_misc
+
+} // namespace gpu::xetla
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/raw_send.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/raw_send.hpp
new file mode 100644
index 00000000000..5b7e6375de5
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/cm/raw_send.hpp
@@ -0,0 +1,154 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#ifdef _WIN32
+#include "../../../common/core/cm/base_ops.hpp"
+#include "../../../common/core/cm/base_types.hpp"
+#include "../../../common/core/cm/common.hpp"
+#else
+#include "common/core/cm/base_ops.hpp"
+#include "common/core/cm/base_types.hpp"
+#include "common/core/cm/common.hpp"
+#endif
+
+namespace gpu::xetla {
+
+/// @addtogroup xetla_core_raw_send
+/// @{
+
+/// @brief Raw send with one source operand and one destination operand.
+///
+/// @tparam T1 is the data type of the msgDst.
+/// @tparam n1 is the data length of the msgDst.
+/// @tparam T2 is the data type of the msgSrc0.
+/// @tparam n2 is the data length of the msgSrc0.
+/// @tparam execSize is the execution size.
+/// @tparam sfid is the shared function ID.
+/// @tparam numSrc0 is the number of GRFs for source-0.
+/// @tparam numDst is the number of GRFs for destination.
+/// @tparam isEOT is the flag that indicates whether this is an EOT message (optional - default to 0).
+/// @tparam isSendc is the flag that indicates whether sendc should be used (optional - default to 0).
+/// @tparam N is the SIMD channel num of the mask (optional - default to 16).
+/// @param msgDst [in|out] is the destination operand of the send message.
+/// @param msgSrc0 [in] is the first source operand of the send message.
+/// @param exDesc [in] is the extended message descriptor.
+/// @param msgDesc [in] is the message descriptor.
+/// @param mask [in] is the predicate to specify enabled channels (optional - default to on).
+///
+template <typename T1, uint32_t n1, typename T2, uint32_t n2, uint8_t execSize,
+ uint8_t sfid, uint8_t numSrc0, uint8_t numDst, uint8_t isEOT = 0,
+ uint8_t isSendc = 0, int N = 16>
+__XETLA_API void xetla_raw_send(xetla_vector_ref<T1, n1> __REF__ msgDst,
+ xetla_vector<T2, n2> msgSrc0, uint32_t exDesc, uint32_t msgDesc,
+ xetla_mask<N> mask = 1) {
+ cm_raw_send(msgDst, msgSrc0, 0, exDesc, msgDesc, execSize, sfid, numSrc0, 0,
+ numDst, isEOT, isSendc, mask);
+}
+
+/// @brief Raw send with two source operands and one destination operand.
+///
+/// @tparam T1 is the data type of the msgDst.
+/// @tparam n1 is the data length of the msgDst.
+/// @tparam T2 is the data type of the msgSrc0.
+/// @tparam n2 is the data length of the msgSrc0.
+/// @tparam T3 is the data type of the msgSrc1.
+/// @tparam n3 is the data length of the msgSrc1.
+/// @tparam execSize is the execution size.
+/// @tparam sfid is the shared function ID.
+/// @tparam numSrc0 is the number of GRFs for source-0.
+/// @tparam numSrc1 is the number of GRFs for source-1.
+/// @tparam numDst is the number of GRFs for destination.
+/// @tparam isEOT is the flag that indicates whether this is an EOT message (optional - default to 0).
+/// @tparam isSendc is the flag that indicates whether sendc should be used (optional - default to 0).
+/// @tparam N is the SIMD channel num of the mask (optional - default to 16).
+/// @param msgDst [in|out] is the destination operand of the send message.
+/// @param msgSrc0 [in] is the first source operand of the send message.
+/// @param msgSrc1 [in] is the second source operand of the send message.
+/// @param exDesc [in] is the extended message descriptor.
+/// @param msgDesc [in] is the message descriptor.
+/// @param mask [in] is the predicate to specify enabled channels (optional - default to on).
+///
+template <typename T1, uint32_t n1, typename T2, uint32_t n2, typename T3,
+ uint32_t n3, uint8_t execSize, uint8_t sfid, uint8_t numSrc0,
+ uint8_t numSrc1, uint8_t numDst, uint8_t isEOT = 0, uint8_t isSendc = 0,
+ int N = 16>
+__XETLA_API void xetla_raw_send(xetla_vector_ref<T1, n1> __REF__ msgDst,
+ xetla_vector<T2, n2> msgSrc0, xetla_vector<T3, n3> msgSrc1,
+ uint32_t exDesc, uint32_t msgDesc, xetla_mask<N> mask = 1) {
+ cm_raw_send(msgDst, msgSrc0, msgSrc1, exDesc, msgDesc, execSize, sfid,
+ numSrc0, numSrc1, numDst, isEOT, isSendc, mask);
+}
+
+/// @brief Raw send with one source operand and no return.
+///
+/// @tparam T1 is the data type of the msgSrc0.
+/// @tparam n1 is the data length of the msgSrc0.
+/// @tparam execSize is the execution size.
+/// @tparam sfid is the shared function ID.
+/// @tparam numSrc0 is the number of GRFs for source-0.
+/// @tparam isEOT is the flag that indicates whether this is an EOT message (optional - default to 0).
+/// @tparam isSendc is the flag that indicates whether sendc should be used (optional - default to 0).
+/// @tparam N is the SIMD channel num of the mask (optional - default to 16).
+/// @param msgSrc0 [in] is the first source operand of the send message.
+/// @param exDesc [in] is the extended message descriptor.
+/// @param msgDesc [in] is the message descriptor.
+/// @param mask [in] is the predicate to specify enabled channels (optional - default to on).
+///
+template <typename T1, uint32_t n1, uint8_t execSize, uint8_t sfid,
+ uint8_t numSrc0, uint8_t isEOT = 0, uint8_t isSendc = 0, int N = 16>
+__XETLA_API void xetla_raw_send(xetla_vector<T1, n1> msgSrc0, uint32_t exDesc,
+ uint32_t msgDesc, xetla_mask<N> mask = 1) {
+ cm_raw_send(0, msgSrc0, 0, exDesc, msgDesc, execSize, sfid, numSrc0, 0, 0,
+ isEOT, isSendc, mask);
+}
+
+/// @brief Raw send with two source operands and no return.
+///
+/// @tparam T1 is the data type of the msgSrc0.
+/// @tparam n1 is the data length of the msgSrc0.
+/// @tparam T2 is the data type of the msgSrc1.
+/// @tparam n2 is the data length of the msgSrc1.
+/// @tparam execSize is the execution size.
+/// @tparam sfid is the shared function ID.
+/// @tparam numSrc0 is the number of GRFs for source-0.
+/// @tparam numSrc1 is the number of GRFs for source-1.
+/// @tparam isEOT is the flag that indicates whether this is an EOT message (optional - default to 0).
+/// @tparam isSendc is the flag that indicates whether sendc should be used (optional - default to 0).
+/// @tparam N is the SIMD channel num of the mask (optional - default to 16).
+/// @param msgSrc0 [in] is the first source operand of the send message.
+/// @param msgSrc1 [in] is the second source operand of the send message.
+/// @param exDesc [in] is the extended message descriptor.
+/// @param msgDesc [in] is the message descriptor.
+/// @param mask [in] is the predicate to specify enabled channels (optional - default to on).
+///
+template <typename T1, uint32_t n1, typename T2, uint32_t n2, uint8_t execSize,
+ uint8_t sfid, uint8_t numSrc0, uint8_t numSrc1, uint8_t isEOT = 0,
+ uint8_t isSendc = 0, int N = 16>
+__XETLA_API void xetla_raw_send(xetla_vector<T1, n1> msgSrc0,
+ xetla_vector<T2, n2> msgSrc1, uint32_t exDesc, uint32_t msgDesc,
+ xetla_mask<N> mask = 1) {
+ cm_raw_send(0, msgSrc0, msgSrc1, exDesc, msgDesc, execSize, sfid, numSrc0,
+ numSrc1, 0, isEOT, isSendc, mask);
+}
+
+/// @} xetla_core_raw_send
+
+} // namespace gpu::xetla
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/core.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/core.hpp
new file mode 100644
index 00000000000..9b590ea3054
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/common/core/core.hpp
@@ -0,0 +1 @@
+#include "common/core/cm/core.hpp"
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/common/utils/cm/common.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/common/utils/cm/common.hpp
new file mode 100644
index 00000000000..a4b2478955a
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/common/utils/cm/common.hpp
@@ -0,0 +1,248 @@
+/*******************************************************************************
+ * Copyright (c) 2022-2023 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.
+ *******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#ifdef _WIN32
+#include "../../../common/core/cm/core.hpp"
+#else
+#include "common/core/cm/core.hpp"
+#endif
+
+#ifndef XETLA_NO_CM_INCLUDE
+#include <cm/cmtl.h>
+#endif
+
+namespace gpu::xetla {
+namespace detail {
+
+///
+///@brief Get the element size code object
+///
+///@param element_size
+///@return constexpr uint32_t
+///
+template <uint32_t element_size>
+constexpr uint32_t get_element_size_code() {
+ static_assert(element_size == 1 || element_size == 2 || element_size == 4
+ || element_size == 8,
+ "element_size not supported!");
+ switch (element_size) {
+ case 1: return 0;
+ case 2: return 1;
+ case 4: return 2;
+ case 8: return 3;
+ }
+}
+
+enum class lsc_action { prefetch, load, store, atomic };
+
+template <lsc_action Action, cache_hint L1H, cache_hint L2H, gpu_arch arch_tag>
+constexpr std::enable_if_t<arch_tag == gpu_arch::Xe, void>
+check_lsc_cache_hint() {
+ if constexpr (Action == lsc_action::prefetch) {
+ static_assert(
+ ((L2H == cache_hint::uncached || L2H == cache_hint::cached)
+ && (L1H == cache_hint::uncached
+ || L1H == cache_hint::cached
+ || L1H == cache_hint::streaming)),
+ "cache hint type not supported!");
+ } else if constexpr (Action == lsc_action::load) {
+ static_assert((L1H == cache_hint::none && L2H == cache_hint::none)
+ || ((L2H == cache_hint::uncached)
+ && (L1H == cache_hint::uncached
+ || L1H == cache_hint::cached
+ || L1H == cache_hint::streaming))
+ || ((L2H == cache_hint::cached)
+ && (L1H == cache_hint::uncached
+ || L1H == cache_hint::cached
+ || L1H == cache_hint::streaming
+ || L1H == cache_hint::read_invalidate)),
+ "unsupported cache hint!");
+ } else if constexpr (Action == lsc_action::store) {
+ static_assert((L1H == cache_hint::none && L2H == cache_hint::none)
+ || ((L2H == cache_hint::uncached)
+ && (L1H == cache_hint::uncached
+ || L1H == cache_hint::write_through
+ || L1H == cache_hint::streaming))
+ || ((L2H == cache_hint::write_back)
+ && (L1H == cache_hint::uncached
+ || L1H == cache_hint::write_through
+ || L1H == cache_hint::streaming
+ || L1H == cache_hint::write_back)),
+ "unsupported cache hint!");
+ } else if constexpr (Action == lsc_action::atomic) {
+ static_assert((L1H == cache_hint::none && L2H == cache_hint::none)
+ || (L1H == cache_hint::uncached
+ && (L2H == cache_hint::uncached
+ || L2H == cache_hint::write_back)),
+ "unsupported cache hint!");
+ }
+}
+
+template <cache_hint L1H, cache_hint L2H, gpu_arch arch_tag>
+constexpr std::enable_if_t<arch_tag == gpu_arch::Xe, uint32_t>
+get_load_cache_hint_code() {
+ check_lsc_cache_hint<lsc_action::load, L1H, L2H, arch_tag>();
+ if (L1H == cache_hint::none && L2H == cache_hint::none) {
+ return 0;
+ } else if (L2H == cache_hint::uncached) {
+ if (L1H == cache_hint::uncached) { return 1; }
+ if (L1H == cache_hint::cached) { return 3; }
+ if (L1H == cache_hint::streaming) { return 5; }
+ } else if (L2H == cache_hint::cached) {
+ if (L1H == cache_hint::uncached) { return 2; }
+ if (L1H == cache_hint::cached) { return 4; }
+ if (L1H == cache_hint::streaming) { return 6; }
+ if (L1H == cache_hint::read_invalidate) { return 7; }
+ }
+}
+
+template <cache_hint L1H, cache_hint L2H, gpu_arch arch_tag>
+constexpr std::enable_if_t<arch_tag == gpu_arch::Xe, uint32_t>
+get_prefetch_cache_hint_code() {
+ check_lsc_cache_hint<lsc_action::prefetch, L1H, L2H, arch_tag>();
+ if (L2H == cache_hint::uncached) {
+ if (L1H == cache_hint::uncached) { return 1; }
+ if (L1H == cache_hint::cached) { return 3; }
+ if (L1H == cache_hint::streaming) { return 5; }
+ } else if (L2H == cache_hint::cached) {
+ if (L1H == cache_hint::uncached) { return 2; }
+ if (L1H == cache_hint::cached) { return 4; }
+ if (L1H == cache_hint::streaming) { return 6; }
+ }
+}
+
+template <cache_hint L1H, cache_hint L2H, gpu_arch arch_tag>
+constexpr std::enable_if_t<arch_tag == gpu_arch::Xe, uint32_t>
+get_store_cache_hint_code() {
+ check_lsc_cache_hint<lsc_action::store, L1H, L2H, arch_tag>();
+ if (L1H == cache_hint::none && L2H == cache_hint::none) {
+ return 0;
+ } else if (L2H == cache_hint::uncached) {
+ if (L1H == cache_hint::uncached) { return 1; }
+ if (L1H == cache_hint::write_through) { return 3; }
+ if (L1H == cache_hint::streaming) { return 5; }
+ } else if (L2H == cache_hint::write_back) {
+ if (L1H == cache_hint::uncached) { return 2; }
+ if (L1H == cache_hint::write_through) { return 4; }
+ if (L1H == cache_hint::streaming) { return 6; }
+ if (L1H == cache_hint::write_back) { return 7; }
+ }
+}
+
+template <cache_hint L1H, cache_hint L2H, gpu_arch arch_tag>
+constexpr std::enable_if_t<arch_tag == gpu_arch::Xe, uint32_t>
+get_atomic_cache_hint_code() {
+ check_lsc_cache_hint<lsc_action::atomic, L1H, L2H, arch_tag>();
+ if (L1H == cache_hint::none && L2H == cache_hint::none) {
+ return 0;
+ } else if (L2H == cache_hint::uncached) {
+ if (L1H == cache_hint::uncached) { return 1; }
+ if (L1H == cache_hint::write_through) { return 3; }
+ if (L1H == cache_hint::streaming) { return 5; }
+ } else if (L2H == cache_hint::write_back) {
+ if (L1H == cache_hint::uncached) { return 2; }
+ if (L1H == cache_hint::write_through) { return 4; }
+ if (L1H == cache_hint::streaming) { return 6; }
+ if (L1H == cache_hint::write_back) { return 7; }
+ }
+}
+
+template <uint32_t num_channel>
+constexpr uint32_t get_execSize_code() {
+ static_assert(num_channel == 1 || num_channel == 2 || num_channel == 4
+ || num_channel == 8 || num_channel == 16
+ || num_channel == 32,
+ "num_channel not supported!");
+ switch (num_channel) {
+ case 1: return 0;
+ case 2: return 1;
+ case 4: return 2;
+ case 8: return 3;
+ case 16: return 4;
+ case 32: return 5;
+ }
+}
+
+template <atomic_op Op>
+constexpr uint32_t get_atomic_opcode() {
+ static_assert(Op == atomic_op::fadd || Op == atomic_op::fmax
+ || Op == atomic_op::iadd,
+ "Other atomic op didn't added");
+ switch (Op) {
+ case atomic_op::fadd: return 19;
+ case atomic_op::fmax: return 22;
+ case atomic_op::iadd: return 12;
+ }
+}
+
+} // namespace detail
+
+///
+///@brief tile layout in register
+/// linear: linear layout with one tile
+/// tiled: 2d block stacked in raster order
+/// vnni_tiled: vnni pack with 2d block and 2d block stacked in raster order
+/// for dword and qword, there is no impact
+/// for word, two rows are interleaved, i.e.
+/// a0 b0 c0 d0 ==> a0 a1 b0 b1 c0 c1 d0 d1
+/// a1 b1 c1 d1
+/// for byte, four rows are interleaved and formed one row, i.e.
+/// a0 b0 c0 d0 ==> a0 a1 a2 a3 b0 b1 b2 b3 c0 c1 c2 c3 d0 d1 d2 d3
+/// a1 b1 c1 d1
+/// a2 b2 c2 d2
+/// a3 b3 c3 d3
+///
+enum class reg_layout : uint8_t {
+ linear = 0,
+ tiled = 1,
+ vnni_tiled = 2,
+ transpose_tiled = 3,
+ /// this is vnni tiled format, but for each block, they are stored in col
+ /// major order
+ vnni_tiled_col_major = 4
+};
+enum class store_op : uint8_t {
+ normal = 0,
+ atomic_fadd = 1,
+ atomic_iadd = 2,
+ scattered_transpose = 3,
+ block_1d = 4
+};
+enum class mma_engine : uint8_t { xmx = 0, fpu = 1 };
+// enum class trans_mode : uint8_t { none = 0, transpose = 1 };
+enum class memory_op : uint8_t { load = 0, store = 1 };
+enum class tdesc_update_dir : uint8_t { x_dir = 0, y_dir = 1 };
+enum class post_kind : uint8_t {
+ none = 0,
+ relu = 1,
+ gelu = 2,
+ gelu_bwd_w = 3,
+ sigmoid = 4,
+ tanh = 5
+};
+enum class pre_kind : uint8_t { none = 0, bias_add = 1, res_add = 2 };
+enum class offset_mode : uint8_t {
+ const_offset = 0,
+ cyclic_offset = 1,
+ acyclic_offset = 2
+};
+
+} // namespace gpu::xetla
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/common/utils/cm/dict.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/common/utils/cm/dict.hpp
new file mode 100644
index 00000000000..1eaeee49dab
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/common/utils/cm/dict.hpp
@@ -0,0 +1,247 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+#pragma once
+
+#ifdef _WIN32
+#include "../../../common/utils/cm/common.hpp"
+#else
+#include "common/utils/cm/common.hpp"
+#endif
+
+namespace gpu::xetla {
+
+// meta_value type
+
+namespace impl {
+struct meta_impl_base {
+ struct _default {};
+};
+
+static constexpr meta_impl_base::_default meta_impl_base_default;
+
+template <typename T, auto value_>
+struct meta_value_impl : meta_impl_base {
+ using type = T;
+ static constexpr T value = value_;
+};
+
+template <typename T = meta_impl_base::_default>
+struct meta_type_impl : meta_impl_base {
+ using type = T;
+};
+} // namespace impl
+
+template <auto d_ = impl::meta_impl_base_default, typename T = decltype(d_)>
+using meta_value = impl::meta_value_impl<T, d_>;
+
+template <auto d_ = impl::meta_impl_base_default, typename T = decltype(d_)>
+using meta_value_t = typename meta_value<d_, T>::type;
+
+template <typename T = impl::meta_impl_base::_default>
+using meta_type = impl::meta_type_impl<T>;
+
+template <typename T>
+using meta_type_t = typename T::type;
+
+// shape type
+
+template <auto... dims>
+struct shape {
+ static constexpr size_t size = sizeof...(dims);
+
+ struct impl {
+ template <size_t i_, size_t cur_, auto... dims_>
+ struct dim_impl;
+
+ template <size_t i_, auto dim, auto... dims_>
+ struct dim_impl<i_, i_, dim, dims_...> {
+ static constexpr auto value = dim;
+ };
+
+ template <size_t i_, size_t cur_, auto dim, auto... dims_>
+ struct dim_impl<i_, cur_, dim, dims_...>
+ : dim_impl<i_, cur_ + 1, dims_...> {
+ static_assert(i_ < size, "i_ exceeded shape size");
+ static_assert(cur_ < size, "cur_ exceeded shape size");
+ };
+ };
+
+ template <size_t i>
+ static constexpr auto dim() {
+ return impl::template dim_impl<i, 0, dims...>::value;
+ }
+};
+
+template <auto... dims>
+static inline constexpr auto shape_v = shape<dims...> {};
+
+// dict type
+
+template <auto key_, typename val_>
+struct elem_t {
+ static constexpr auto key = key_;
+ using value = val_;
+};
+
+template <auto key_, typename T>
+struct elem_t_t : elem_t<key_, meta_type<T>> {};
+
+template <auto key_, auto val_, typename T = decltype(val_)>
+struct elem_v_t : elem_t<key_, meta_value<val_, T>> {};
+
+template <typename... Args>
+struct dict_t {
+ static constexpr size_t arg_size = sizeof...(Args);
+
+ struct impl {
+ template <typename T>
+ struct type_identity {
+ using type = T;
+ };
+
+ struct empty_dict : type_identity<dict_t<>> {};
+ using this_t = dict_t<Args...>;
+
+ static constexpr int key_not_found = -1;
+
+ template <auto value_, typename type_>
+ struct find_elem_impl_ret_type {
+ static constexpr auto value = value_;
+ using type = type_;
+ };
+
+ template <auto key_, size_t cur_, typename... Elems>
+ struct find_elem_impl;
+
+ template <auto key_, size_t cur_, typename elem_, typename... Elems>
+ struct find_elem_impl<key_, cur_, elem_, Elems...> {
+ static constexpr bool match_key = (key_ == elem_::key);
+ using ret = typename std::conditional<match_key,
+ find_elem_impl_ret_type<cur_, elem_>,
+ find_elem_impl<key_, cur_ + 1, Elems...>>::type;
+ static constexpr int value = ret::value;
+ using type = typename ret::type;
+ };
+
+ template <auto key_, size_t cur_>
+ struct find_elem_impl<key_, cur_> {
+ static constexpr int value = key_not_found;
+ using type = void;
+ };
+
+ template <auto key_>
+ static constexpr int find_elem_index
+ = find_elem_impl<key_, 0, Args...>::value;
+
+ template <auto key_>
+ struct find_elem : find_elem_impl<key_, 0, Args...>::type {};
+
+ template <typename... Elems>
+ struct prepend_key_impl : type_identity<dict_t<Elems..., Args...>> {};
+
+ template <typename... Elems>
+ struct append_key_impl : type_identity<dict_t<Args..., Elems...>> {};
+
+ template <typename dict_t_>
+ struct merge_dict_impl;
+
+ template <typename... Elems>
+ struct merge_dict_impl<dict_t<Elems...>> : append_key_impl<Elems...> {};
+
+ template <typename dict_t_, int cur_i, int begin_i, int end_i>
+ struct slicing_key_impl : empty_dict {};
+
+ template <int cur_i, int begin_i, int end_i, typename e_,
+ typename... Elems>
+ struct slicing_key_impl<dict_t<e_, Elems...>, cur_i, begin_i, end_i> {
+ using nxt_dict = typename std::conditional<(cur_i + 1 < end_i)
+ && (sizeof...(Elems) > 0),
+ slicing_key_impl<dict_t<Elems...>, cur_i + 1, begin_i,
+ end_i>,
+ empty_dict>::type::type;
+ using type = typename std::conditional<(begin_i <= cur_i)
+ && (cur_i < end_i),
+ typename nxt_dict::impl::template prepend_key_impl<e_>,
+ type_identity<nxt_dict>>::type::type;
+ };
+
+ template <typename dict_t_, typename e_, int e_index>
+ struct replace_key_impl {
+ using pre_dict = typename slicing_key_impl<dict_t_, 0, 0,
+ e_index>::type::impl::template append_key_impl<e_>::type;
+ using post_dict = typename slicing_key_impl<dict_t_, 0, e_index + 1,
+ dict_t_::arg_size>::type;
+ using type = typename pre_dict::impl::template merge_dict_impl<
+ post_dict>::type;
+ };
+
+ template <typename dict_t_, typename... Elems>
+ struct update_dict_impl : type_identity<dict_t_> {};
+
+ template <typename dict_t_, typename e_, typename... Elems>
+ struct update_dict_impl<dict_t_, e_, Elems...>
+ : update_dict_impl<typename update_dict_impl<dict_t_, e_>::type,
+ Elems...> {};
+
+ template <typename dict_t_, typename e_, typename... Elems>
+ struct update_dict_impl<dict_t_, dict_t<e_, Elems...>>
+ : update_dict_impl<dict_t_, e_, Elems...> {};
+
+ template <typename dict_t_, typename e_>
+ struct update_dict_impl<dict_t_, e_> {
+ static constexpr int e_index
+ = dict_t_::impl::template find_elem_index<e_::key>;
+ using type = typename std::conditional<e_index != key_not_found,
+ replace_key_impl<dict_t_, e_, e_index>,
+ typename dict_t_::impl::template append_key_impl<e_>>::
+ type::type;
+ };
+
+ template <typename U, template <typename> typename G>
+ struct update_generator_impl {
+ using res_t = typename G<U>::type;
+ using type = typename update_dict_impl<this_t, res_t>::type;
+ };
+ };
+
+ template <auto key_>
+ using find_elem_t = typename impl::template find_elem<key_>::value;
+
+ template <auto key_>
+ using find_elem_v_type = decltype(find_elem_t<key_>::value);
+
+ template <auto key_>
+ static inline constexpr find_elem_v_type<key_> find_elem_v
+ = find_elem_t<key_>::value;
+
+ template <typename e_, typename... Elems>
+ using update_t =
+ typename impl::template update_dict_impl<typename impl::this_t, e_,
+ Elems...>::type;
+
+ template <typename T>
+ using update_dict_t =
+ typename impl::template update_dict_impl<typename impl::this_t,
+ T>::type;
+
+ template <template <typename> typename G>
+ using update_generator_t =
+ typename impl::template update_generator_impl<typename impl::this_t,
+ G>::type;
+};
+
+} // namespace gpu::xetla
\ No newline at end of file
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/common/utils/cm/fastmath.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/common/utils/cm/fastmath.hpp
new file mode 100644
index 00000000000..cc411cc98ae
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/common/utils/cm/fastmath.hpp
@@ -0,0 +1,118 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#ifdef _WIN32
+#include "../../../common/utils/cm/common.hpp"
+#else
+#include "common/utils/cm/common.hpp"
+#endif
+
+namespace gpu::xetla {
+
+///@brief Host side utility function to compute number of leading zeros in the binary representation
+inline int clz(int x) {
+
+ for (int i = 31; i >= 0; i--) {
+
+ if ((1 << i) & x) { return (31 - i); }
+ }
+ return 32;
+}
+
+///@brief Host side utility function to compute log2 function
+inline int find_log2(int x) {
+
+ int a = int(31 - clz(x));
+ a = a + ((x & (x - 1)) != 0);
+ return a;
+}
+
+///Fast division + modulus operation
+///Host code pre-computes values to avoid expensive operations in kernel code
+struct FastDivMod {
+
+ int divisor;
+ unsigned int multiplier;
+ unsigned int shift_right;
+
+ ///Constructor, called in Hostcode to pre-compute multiplier and shift_right;
+ inline FastDivMod() : divisor(0), multiplier(0), shift_right(0) {}
+
+ inline FastDivMod(
+ uint32_t divisor_, uint32_t multiplier_, uint32_t shift_right_)
+ : divisor(divisor_)
+ , multiplier(multiplier_)
+ , shift_right(shift_right_) {}
+
+ inline FastDivMod(int divisor_) : divisor(divisor_) {
+
+ if (divisor != 1) {
+ unsigned int p = 31 + find_log2(divisor);
+ unsigned m = unsigned(
+ ((1ull << p) + unsigned(divisor) - 1) / unsigned(divisor));
+
+ multiplier = m;
+ shift_right = p - 32;
+ } else {
+
+ multiplier = 0;
+ shift_right = 0;
+ }
+ }
+
+ inline void query_all(int &divisor_, unsigned int &multiplier_,
+ unsigned int &shift_right_) const {
+ divisor_ = divisor;
+ multiplier_ = multiplier;
+ shift_right_ = shift_right;
+ }
+
+ operator int() const { return divisor; }
+
+ __XETLA_API KERNEL_FUNC void set_divmod(
+ int divisor_, unsigned int multiplier_, unsigned int shift_right_) {
+ divisor = divisor_;
+ multiplier = multiplier_;
+ shift_right = shift_right_;
+ }
+
+ ///@brief Kernel side function to find quotient and remainder
+ __XETLA_API KERNEL_FUNC void fast_divmod(
+ int &quotient, int &remainder, int dividend) const {
+
+ quotient = int((divisor != 1)
+ ? int(((int64_t)dividend * multiplier) >> 32)
+ >> shift_right
+ : dividend);
+
+ remainder = dividend - (quotient * divisor);
+ }
+
+ ///@brief kernel side utility functions for query of quotient
+ __XETLA_API KERNEL_FUNC int div(int dividend) const {
+
+ int quotient, remainder;
+ fast_divmod(quotient, remainder, dividend);
+ return quotient;
+ }
+};
+
+} // namespace gpu::xetla
\ No newline at end of file
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/common/utils/cm/limitation.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/common/utils/cm/limitation.hpp
new file mode 100644
index 00000000000..004e0ff7335
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/common/utils/cm/limitation.hpp
@@ -0,0 +1,157 @@
+/*******************************************************************************
+ * Copyright (c) 2022-2023 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.
+ *******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#ifdef _WIN32
+#include "../../../common/core/cm/common.hpp"
+#include "../../../common/utils/cm/tensor_descriptor.hpp"
+#else
+#include "common/core/cm/common.hpp"
+#include "common/utils/cm/tensor_descriptor.hpp"
+#endif
+
+#define IN_RANGE(x, l, r) ((x) >= (l) && (x) <= (r))
+
+namespace gpu::xetla {
+
+typedef uint64_t size_t;
+
+namespace core {
+template <gpu_arch arch, typename T>
+struct general_1d {
+ template <uint8_t NElts>
+ static inline bool check_restriction(uint64_t offset, uint64_t p = 0) {
+ return true;
+ }
+
+ template <uint8_t NElts, int N, typename Toffset = uint32_t>
+ static inline bool check_restriction(
+ xetla_vector<Toffset, N> offsets, uint64_t p = 0) {
+ return true;
+ }
+};
+
+template <gpu_arch arch, typename T>
+class block_2d {
+public:
+ template <bool transpose, bool vnni_transform>
+ static inline bool check_load(xetla_tdescriptor tdesc) {
+ return true;
+ }
+
+ static inline bool check_store(xetla_tdescriptor tdesc) { return true; }
+
+ static inline bool check_tensor(
+ uint64_t base, uint32_t width, uint32_t height, uint32_t pitch) {
+ return true;
+ }
+};
+} // namespace core
+
+namespace subgroup {
+template <gpu_arch arch, typename dtype, typename mem_dtype>
+struct check_load {
+ template <bool mem_transform, size_t block_size_x>
+ struct global_2d {};
+
+ struct global_1d {};
+
+ template <bool mem_transform, size_t block_size_x>
+ struct unaligned_2d {};
+
+ template <mem_layout memory_layout, size_t block_size_x, size_t tile_bytes,
+ size_t min_bytes, size_t block_bytes, size_t num_channel_x,
+ size_t num_channel>
+ struct local_scatter {};
+
+ struct local_1d {};
+};
+
+template <gpu_arch arch, typename dtype, typename mem_dtype = uint32_t>
+struct check_store {
+ template <size_t block_size_x>
+ struct global_2d {};
+
+ struct global_1d {};
+
+ template <size_t block_size_x>
+ struct unaligned_2d {};
+
+ template <size_t tile_bytes, size_t min_store_bytes, size_t block_bytes,
+ size_t num_channel_x, size_t num_channel>
+ struct global_atomic {};
+
+ template <size_t tile_bytes, size_t min_bytes, size_t block_bytes,
+ size_t num_channel_x, size_t num_channel>
+ struct local_scatter {};
+
+ template <size_t tile_bytes, size_t min_store_bytes, size_t block_bytes,
+ size_t num_channel_x, size_t num_channel>
+ struct local_scatter_vnni_col {};
+
+ struct local_1d {};
+};
+} // namespace subgroup
+
+namespace group {
+
+template <gpu_arch arch>
+struct gemm {
+ struct default_fpu {
+ template <typename dtype_a, typename dtype_b, typename dtype_mma_a,
+ typename dtype_mma_b, typename dtype_mma_acc>
+ struct check_dtype_default {};
+
+ template <mem_layout mem_layout_a, mem_layout mem_layout_b,
+ mem_space mem_space_a, mem_space mem_space_b>
+ struct check_memory_default {};
+
+ template <typename dtype_mma, int tile_size_x_a, int tile_size_y_a,
+ int block_size_x_a, int block_size_y_a, int tile_size_x_b,
+ int tile_size_y_b, int block_size_x_b, int block_size_y_b>
+ struct check_tile_size_default {};
+ };
+
+ struct default_xmx {
+ template <typename dtype_a, typename dtype_b, typename dtype_mma_a,
+ typename dtype_mma_b>
+ struct check_dtype_default {};
+
+ template <mem_layout mem_layout_a, mem_layout mem_layout_b,
+ mem_space mem_space_a, mem_space mem_space_b>
+ struct check_memory_default {};
+
+ template <typename dtype_mma, int tile_size_x_a, int tile_size_y_a,
+ int block_size_x_a, int block_size_y_a, int tile_size_x_b,
+ int tile_size_y_b, int block_size_x_b, int block_size_y_b>
+ struct check_tile_size_default {};
+ };
+};
+} // namespace group
+
+namespace kernel {
+template <gpu_arch arch, typename T>
+class general_1d {
+public:
+ static inline bool check_alignment(T *base, uint32_t pitch) { return true; }
+};
+} // namespace kernel
+
+} // namespace gpu::xetla
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/common/utils/cm/memory_descriptor.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/common/utils/cm/memory_descriptor.hpp
new file mode 100644
index 00000000000..ebb631b3ab1
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/common/utils/cm/memory_descriptor.hpp
@@ -0,0 +1,363 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#ifdef _WIN32
+#include "../../../common/utils/cm/common.hpp"
+#include "../../../common/utils/cm/raw_send_load_store.hpp"
+#else
+#include "common/utils/cm/common.hpp"
+#include "common/utils/cm/raw_send_load_store.hpp"
+#endif
+
+namespace gpu::xetla {
+
+template <int dim = 2>
+struct mem_coord_t {};
+template <>
+struct mem_coord_t<2> {
+ int x;
+ int y;
+ inline mem_coord_t(int x_, int y_) : x(x_), y(y_) {}
+ inline mem_coord_t() = default;
+ inline mem_coord_t(const mem_coord_t<2> &coord) {
+ this->x = coord.x;
+ this->y = coord.y;
+ }
+ inline mem_coord_t<2> &operator=(const mem_coord_t<2> &coord) {
+ this->x = coord.x;
+ this->y = coord.y;
+ return *this;
+ }
+ inline void init(int x_, int y_) {
+ this->x = x_;
+ this->y = y_;
+ }
+};
+
+template <>
+struct mem_coord_t<4> {
+ int x;
+ int y;
+ int z;
+ int w;
+};
+
+template <int dim = 2>
+struct mem_shape_t {};
+template <>
+struct mem_shape_t<2> {
+ uint32_t x;
+ uint32_t y;
+ uint32_t stride_x;
+ inline mem_shape_t() = default;
+ inline mem_shape_t(
+ uint32_t shape_x_, uint32_t shape_y_, uint32_t row_stride_)
+ : x(shape_x_), y(shape_y_), stride_x(row_stride_) {}
+ inline mem_shape_t(const mem_shape_t<2> &shape) {
+ this->x = shape.x;
+ this->y = shape.y;
+ this->stride_x = shape.stride_x;
+ }
+ inline mem_shape_t<2> &operator=(const mem_shape_t<2> &shape) {
+ this->x = shape.x;
+ this->y = shape.y;
+ this->stride_x = shape.stride_x;
+ return *this;
+ }
+ inline void init(
+ uint32_t shape_x_, uint32_t shape_y_, uint32_t row_stride_) {
+ this->x = shape_x_;
+ this->y = shape_y_;
+ this->stride_x = row_stride_;
+ }
+};
+
+template <>
+struct mem_shape_t<4> {
+ uint32_t x = 0;
+ uint32_t y = 0;
+ uint32_t z = 0;
+ uint32_t w = 0;
+ uint32_t stride_x = 0;
+ uint32_t stride_y = 0;
+ uint32_t stride_z = 0;
+
+ inline mem_shape_t() = default;
+ inline mem_shape_t(uint32_t size0_, uint32_t size1_, uint32_t size2_,
+ uint32_t size3_, uint32_t stride0_, uint32_t stride1_,
+ uint32_t stride2_)
+ : x(size0_)
+ , y(size1_)
+ , z(size2_)
+ , w(size3_)
+ , stride_x(stride0_)
+ , stride_y(stride1_)
+ , stride_z(stride2_) {}
+ inline mem_shape_t(
+ uint32_t size0_, uint32_t size1_, uint32_t size2_, uint32_t size3_)
+ : x(size0_)
+ , y(size1_)
+ , z(size2_)
+ , w(size3_)
+ , stride_x(size0_)
+ , stride_y(size1_)
+ , stride_z(size2_) {}
+ // these methods are here because without them cm produces this error
+ // "warning: undefined value is referenced after decomposition"
+ inline mem_shape_t(const mem_shape_t<4> &shape)
+ : x(shape.x)
+ , y(shape.y)
+ , z(shape.z)
+ , w(shape.w)
+ , stride_x(shape.stride_x)
+ , stride_y(shape.stride_y)
+ , stride_z(shape.stride_z) {}
+ inline mem_shape_t<4> &operator=(const mem_shape_t<4> &shape) {
+ this->x = shape.x;
+ this->y = shape.y;
+ this->z = shape.z;
+ this->w = shape.w;
+ this->stride_x = shape.stride_x;
+ this->stride_y = shape.stride_y;
+ this->stride_z = shape.stride_z;
+ return *this;
+ }
+};
+
+template <typename dtype_, mem_space space_>
+struct mem_base_t {};
+template <typename dtype_>
+struct mem_base_t<dtype_, mem_space::global> {
+ using dtype = dtype_;
+ dtype *base;
+ inline mem_base_t() = default;
+ inline mem_base_t(dtype *base_) : base(base_) {}
+ inline mem_base_t(const mem_base_t<dtype, mem_space::global> &mem_base)
+ : base(mem_base.base) {}
+ inline mem_base_t<dtype, mem_space::global> &operator=(
+ const mem_base_t<dtype, mem_space::global> &mem_base) {
+ this->base = mem_base.base;
+ return *this;
+ }
+ inline void init(dtype *base_) { base = base_; }
+ inline void update(int offset) { base = base + offset; }
+};
+template <typename dtype_>
+struct mem_base_t<dtype_, mem_space::local> {
+ using dtype = dtype_;
+ uint32_t base;
+ inline mem_base_t() = default;
+ inline mem_base_t(uint32_t base_) : base(base_) {}
+ inline mem_base_t(const mem_base_t<dtype, mem_space::local> &mem_base)
+ : base(mem_base.base) {}
+ inline mem_base_t<dtype, mem_space::local> &operator=(
+ const mem_base_t<dtype, mem_space::local> &mem_base) {
+ this->base = mem_base.base;
+ return *this;
+ }
+ inline void init(uint32_t base_) { base = base_; }
+ inline void update(int offset) { base = base + offset * sizeof(dtype); }
+};
+
+template <typename dtype_, mem_layout layout_, mem_space space_,
+ uint32_t alignment_ = 8, int dim_ = 2>
+struct mem_desc_t {};
+
+template <typename dtype_, mem_layout layout_, mem_space space_,
+ uint32_t alignment_>
+struct mem_desc_t<dtype_, layout_, space_, alignment_, 2> {
+ using dtype = dtype_;
+ static constexpr mem_layout layout = layout_;
+ static constexpr mem_space space = space_;
+ static constexpr int dim = 2;
+ static constexpr uint32_t alignment = alignment_;
+ static constexpr uint32_t alignment_in_bytes = alignment_ * sizeof(dtype);
+
+ static constexpr bool is_col_major = layout == mem_layout::col_major;
+ static constexpr bool is_local = space == mem_space::local;
+ using shape_t = mem_shape_t<dim>;
+ using coord_t = mem_coord_t<dim>;
+ using base_t = mem_base_t<dtype, space>;
+
+ using this_type_t = mem_desc_t<dtype, layout_, space_, alignment, 2>;
+
+ inline mem_desc_t() = default;
+ inline mem_desc_t(base_t base_, shape_t shape_, coord_t coord_)
+ : base(base_), shape(shape_), coord(coord_) {}
+ // Be aware of the risks: Rule of three (copy constructor, copy assignment, destructor)
+ // Please check if you need to add self-define destructor
+ // inline ~mem_desc_t(){}
+ inline mem_desc_t(const this_type_t &mem_desc)
+ : base(mem_desc.base), shape(mem_desc.shape), coord(mem_desc.coord) {}
+
+ inline this_type_t &operator=(const this_type_t &mem_desc) {
+ this->base = mem_desc.base;
+ this->shape = mem_desc.shape;
+ this->coord = mem_desc.coord;
+ return *this;
+ }
+ inline void init(base_t base_, shape_t shape_, coord_t coord_) {
+ base = base_;
+ shape = shape_;
+ coord = coord_;
+ }
+ inline void update_coord(int offset_x, int offset_y) {
+ coord.x += offset_x;
+ coord.y += offset_y;
+ }
+
+ inline void set_coord(int offset_x, int offset_y) {
+ coord.x = offset_x;
+ coord.y = offset_y;
+ }
+
+ inline void update_coord_x(int offset_x) { coord.x += offset_x; }
+ inline void update_coord_y(int offset_y) { coord.y += offset_y; }
+ inline xetla_tdescriptor get_tdesc() {
+ uint32_t width = is_col_major ? shape.y : shape.x;
+ uint32_t height = is_col_major ? shape.x : shape.y;
+ uint32_t pitch = shape.stride_x;
+ int coord_x = is_col_major ? coord.y : coord.x;
+ int coord_y = is_col_major ? coord.x : coord.y;
+ return xetla_get_tdesc<dtype>(
+ base.base, width, height, pitch, coord_x, coord_y);
+ }
+
+ shape_t shape;
+ coord_t coord;
+ base_t base;
+};
+
+template <typename dtype_, mem_layout layout_, mem_space space_,
+ uint32_t alignment_>
+struct mem_desc_t<dtype_, layout_, space_, alignment_, 4> {
+ using dtype = dtype_;
+ static constexpr mem_layout layout = layout_;
+ static constexpr mem_space space = space_;
+ static constexpr uint32_t alignment = alignment_;
+ static constexpr uint32_t alignment_in_bytes = alignment * sizeof(dtype);
+ static constexpr int dim = 4;
+
+ static constexpr bool is_local = (space == mem_space::local);
+ using shape_t = mem_shape_t<dim>;
+ using coord_t = mem_coord_t<dim>;
+ using base_t = mem_base_t<dtype, space>;
+
+ using this_type_t = mem_desc_t<dtype, layout_, space_, alignment, 4>;
+
+ // without this constructor some compiler versions can incorrectly
+ // initialize the struct, probably due to some bug
+ inline mem_desc_t(base_t base_, shape_t shape_, coord_t coord_)
+ : base(base_), shape(shape_), coord(coord_) {};
+
+ inline void update_coord(
+ int offset_x, int offset_y, int offset_z, int offset_w) {
+ coord.x += offset_x;
+ coord.y += offset_y;
+ coord.z += offset_z;
+ coord.w += offset_w;
+ }
+ inline void update_coord_x(int offset_x) { coord.x += offset_x; }
+ inline void update_coord_y(int offset_y) { coord.y += offset_y; }
+ inline void update_coord_z(int offset_z) { coord.z += offset_z; }
+ inline void update_coord_w(int offset_w) { coord.w += offset_w; }
+ inline xetla_tdescriptor get_tdesc() {
+ uint32_t width = shape.x; // in NHWC this is C
+ uint32_t height = shape.y; // in NHWC this is W
+ uint32_t pitch = shape.stride_x;
+ int coord_x = coord.x; // in NHWC this is offset in channels
+ int coord_y = coord.y; // in NHWC this is offset in width
+
+ dtype *base_ptr = base.base;
+ return xetla_get_tdesc<dtype>(
+ base_ptr, width, height, pitch, coord_x, coord_y);
+ }
+ inline uint32_t get_shape_x(void) { return shape.x; }
+ inline uint32_t get_shape_y(void) { return shape.y; }
+ inline uint32_t get_shape_z(void) { return shape.z; }
+ inline uint32_t get_shape_w(void) { return shape.w; }
+
+ inline uint32_t get_stride_x(void) { return shape.stride_x; }
+ inline uint32_t get_stride_y(void) { return shape.stride_y; }
+ inline uint32_t get_stride_z(void) { return shape.stride_z; }
+
+ inline int32_t get_coord_x(void) { return coord.x; }
+ inline int32_t get_coord_y(void) { return coord.y; }
+ inline int32_t get_coord_z(void) { return coord.z; }
+ inline int32_t get_coord_w(void) { return coord.w; }
+
+ template <int32_t N>
+ inline xetla_vector<int32_t, N> get_base_offset_from_z(
+ xetla_vector<int32_t, N> offset) {
+ xetla_vector<int32_t, N> ret
+ = (offset + coord.z) * (shape.stride_x * shape.stride_y);
+ return ret;
+ }
+
+ inline int32_t get_base_offset_from_z(int32_t offset) {
+ int32_t ret = (offset + coord.z) * shape.stride_x * shape.stride_y;
+ return ret;
+ }
+
+ template <int32_t N>
+ inline xetla_mask<N> get_mask_from_z(xetla_vector<int32_t, N> offset) {
+ xetla_mask<N> mask
+ = (offset + coord.z >= 0) & (offset + coord.z < shape.z);
+ return mask;
+ }
+
+ inline int get_mask_from_z(int32_t offset) {
+ int mask = (offset + coord.z >= 0) & (offset + coord.z < shape.z);
+ return mask;
+ }
+
+ inline int32_t get_base_offset_from_w(int32_t offset) {
+ int32_t ret = (offset + coord.w) * shape.stride_x * shape.stride_y
+ * shape.stride_z;
+ return ret;
+ }
+
+ template <int32_t N>
+ inline xetla_vector<int32_t, N> get_base_offset_from_w(
+ xetla_vector<int32_t, N> offset) {
+ xetla_vector<int32_t, N> ret = (offset + coord.w) * shape.stride_x
+ * shape.stride_y * shape.stride_z;
+ return ret;
+ }
+
+ template <int32_t N>
+ inline xetla_mask<N> get_mask_from_w(xetla_vector<int32_t, N> offset) {
+ xetla_mask<N> mask
+ = (offset + coord.w >= 0) & (offset + coord.w < shape.w);
+ return mask;
+ }
+
+ inline int get_mask_from_w(int32_t offset) {
+ int mask = (offset + coord.w >= 0) & (offset + coord.w < shape.w);
+ return mask;
+ }
+
+ base_t base;
+ shape_t shape;
+ coord_t coord;
+};
+
+} // namespace gpu::xetla
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/common/utils/cm/misc.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/common/utils/cm/misc.hpp
new file mode 100644
index 00000000000..b4134764bd1
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/common/utils/cm/misc.hpp
@@ -0,0 +1,181 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#ifdef _WIN32
+#include "../../../common/utils/cm/common.hpp"
+#include "../../../common/utils/cm/nd_item.hpp"
+#else
+#include "common/utils/cm/common.hpp"
+#include "common/utils/cm/nd_item.hpp"
+#endif
+
+__XETLA_API constexpr uint32_t div_round_up(uint32_t n, uint32_t d) {
+ return (n + d - 1) / d;
+}
+
+__XETLA_API constexpr int div_round_down(int n, int d) {
+ // Numbers are rounded down towards the next lowest number
+ // e.g. -2.0/3.0 ~ -0.666 -> -1.
+ return (n - (((n % d) + d) % d)) / d;
+}
+
+__XETLA_API constexpr int modulo(int n, int d) {
+ // Calculates modulo based on definition that uses floored divison.
+ // Result has the same sign as d.
+ return (d + (n % d)) % d;
+}
+
+namespace gpu::xetla {
+
+/// @addtogroup xetla_util_misc
+/// @{
+
+/// @brief Returns time stamp
+///
+/// @return vecotor <uint32_t, 4> contain time stamp
+///
+__XETLA_API xetla_vector<uint32_t, 4> get_time_stamp() {
+ return cm_rdtsc();
+}
+
+///
+/// @brief xetla_vector generation.
+/// Commonly used to generate simd channel id.
+///
+/// @tparam Ty is type of xetla_vector generated. Only `int` type(or types that can be implicitly converted to int) is allowed.
+/// @tparam N is the number of elements in xetla_vector generated.
+/// @param InitVal [in] is the starting value of xetla_vector generation.
+/// @param Step [in] is the step value between adjacent elements.
+/// @return xetla_vector<Ty, N> [out] is the return vector.
+///
+template <typename Ty, int N>
+__XETLA_API xetla_vector<Ty, N> xetla_vector_gen(int InitVal, int Step) {
+ xetla_vector<Ty, N> tmp;
+ cmtl::cm_vector_assign(tmp, InitVal, Step);
+ return tmp;
+}
+
+template <uint32_t N>
+__XETLA_API xetla_mask_int<N> xetla_mask_int_gen(uint32_t mask_val) {
+ return mask_val;
+}
+
+template <typename dtype_acc, uint32_t N, uint32_t num_flag = 4,
+ typename dtype_mask = uint8_t>
+__XETLA_API xetla_vector<dtype_acc, N> drop_out(xetla_vector<dtype_acc, N> in,
+ xetla_vector<dtype_mask, N> mask, dtype_acc scale) {
+ xetla_vector<dtype_acc, N> out = in * scale;
+ constexpr uint32_t unroll_size = num_flag * 16;
+ SW_BARRIER();
+#pragma unroll
+ for (int i = 0; i < N / unroll_size; i++) {
+ xetla_mask<unroll_size> mask_flag
+ = mask.xetla_select<unroll_size, 1>(i * unroll_size) > 0;
+ out.xetla_select<unroll_size, 1>(i * unroll_size)
+ .xetla_merge(0, mask_flag);
+ }
+ if constexpr (N % unroll_size != 0) {
+ constexpr uint32_t remain_len = N % unroll_size;
+ constexpr uint32_t remain_start = N / unroll_size * unroll_size;
+ xetla_mask<remain_len> mask_flag
+ = mask.xetla_select<remain_len, 1>(remain_start) > 0;
+ out.xetla_select<remain_len, 1>(remain_start).xetla_merge(0, mask_flag);
+ }
+ return out;
+}
+
+template <reduce_op reduce_kind, typename dtype, int size>
+__XETLA_API typename std::enable_if_t<reduce_kind == reduce_op::sum,
+ xetla_vector<dtype, size>>
+reduce_helper(xetla_vector<dtype, size> a, xetla_vector<dtype, size> b) {
+ return a + b;
+}
+
+template <reduce_op reduce_kind, typename dtype, int size>
+__XETLA_API typename std::enable_if_t<reduce_kind == reduce_op::prod,
+ xetla_vector<dtype, size>>
+reduce_helper(xetla_vector<dtype, size> a, xetla_vector<dtype, size> b) {
+ return a * b;
+}
+
+template <reduce_op reduce_kind, typename dtype, int size>
+__XETLA_API typename std::enable_if_t<reduce_kind == reduce_op::max,
+ xetla_vector<dtype, size>>
+reduce_helper(xetla_vector<dtype, size> a, xetla_vector<dtype, size> b) {
+ xetla_vector<dtype, size> out;
+ xetla_mask<size> mask = a > b;
+ out.xetla_merge(a, b, mask);
+ return out;
+}
+
+template <reduce_op reduce_kind, typename dtype, int size>
+__XETLA_API typename std::enable_if_t<reduce_kind == reduce_op::min,
+ xetla_vector<dtype, size>>
+reduce_helper(xetla_vector<dtype, size> a, xetla_vector<dtype, size> b) {
+ xetla_vector<dtype, size> out;
+ xetla_mask<size> mask = a < b;
+ out.xetla_merge(a, b, mask);
+ return out;
+}
+
+template <reduce_op reduce_kind, typename dtype, int N_x, int N_y>
+__XETLA_API typename std::enable_if_t<N_y == 1, xetla_vector<dtype, N_x>>
+recur_row_reduce(xetla_vector<dtype, N_x> in) {
+ return in;
+}
+template <reduce_op reduce_kind, typename dtype, int N_x, int N_y>
+__XETLA_API typename std::enable_if_t<(N_y > 1), xetla_vector<dtype, N_x>>
+recur_row_reduce(xetla_vector<dtype, N_x * N_y> in) {
+ static_assert(((N_y) & (N_y - 1)) == 0, "N_y should be power of 2");
+ xetla_vector<dtype, N_x * N_y / 2> temp;
+ temp = reduce_helper<reduce_kind, dtype, N_x * N_y / 2>(
+ in.xetla_select<N_x * N_y / 2, 1>(0),
+ in.xetla_select<N_x * N_y / 2, 1>(N_x * N_y / 2));
+
+ return recur_row_reduce<reduce_kind, dtype, N_x, N_y / 2>(temp);
+}
+
+template <reduce_op reduce_kind, typename dtype, int N_x, int N_y>
+__XETLA_API typename std::enable_if_t<N_x == 1, xetla_vector<dtype, N_y>>
+recur_col_reduce(xetla_vector<dtype, N_y> in) {
+ return in;
+}
+template <reduce_op reduce_kind, typename dtype, int N_x, int N_y>
+__XETLA_API typename std::enable_if_t<(N_x > 1), xetla_vector<dtype, N_y>>
+recur_col_reduce(xetla_vector<dtype, N_x * N_y> in) {
+ static_assert(((N_x) & (N_x - 1)) == 0, "N_x should be power of 2");
+ xetla_vector<dtype, N_x * N_y / 2> temp;
+ auto in_2d = in.xetla_format<dtype, N_y, N_x>();
+ temp = reduce_helper<reduce_kind, dtype, N_y * N_x / 2>(
+ in_2d.xetla_select<N_y, 1, N_x / 2, 1>(0, 0),
+ in_2d.xetla_select<N_y, 1, N_x / 2, 1>(0, N_x / 2));
+
+ return recur_col_reduce<reduce_kind, dtype, N_x / 2, N_y>(temp);
+}
+
+/// @brief get linear group id of the last two dimensions.
+/// @tparam item Is the given sycl::nd_item<3>.
+__XETLA_API uint32_t get_2d_group_linear_id(sycl::nd_item<3> &item) {
+ return item.get_group(2) + item.get_group(1) * item.get_group_range(2);
+}
+/// @} xetla_util_misc
+
+} // namespace gpu::xetla
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/common/utils/cm/nd_item.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/common/utils/cm/nd_item.hpp
new file mode 100644
index 00000000000..37adcb90128
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/common/utils/cm/nd_item.hpp
@@ -0,0 +1,95 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#ifdef _WIN32
+#include "../../../common/utils/cm/common.hpp"
+#else
+#include "common/utils/cm/common.hpp"
+#endif
+
+namespace sycl {
+
+/// @brief The item struct to explict identify the group / local id information
+///
+/// @tparam dims The dimension for the execution item
+///
+template <int dims = 1>
+class nd_item {
+public:
+ inline nd_item() = default;
+ /// @brief Returns the group id for the requested dimensions.
+ ///
+ /// @param dimension The requested dimension
+ /// @return uint32_t The group id
+ ///
+ inline uint32_t get_group(int dimension) const {
+ return cm_group_id(dims - 1 - dimension);
+ }
+
+ /// @brief Returns local id in the work group for the requested dimensions
+ ///
+ /// @param dimension The requested dimension
+ /// @return uint32_t The local id
+ ///
+ inline uint32_t get_local_id(int dimension) const {
+ return cm_local_id(dims - 1 - dimension);
+ }
+
+ /// @brief Returns local size in the work group for the requested dimensions
+ ///
+ /// @param dimension The requested dimension
+ /// @return uint32_t The local size
+ ///
+ inline uint32_t get_local_range(int dimension) const {
+ return cm_local_size(dims - 1 - dimension);
+ }
+
+ /// @brief Returns local linear id in the work group
+ /// @note The right-most term in the object’s range varies fastest in the linearization.
+ /// @return uint32_t The local linear id
+ ///
+ inline uint32_t get_local_linear_id() const {
+ if constexpr (dims == 1) { return get_local_id(0); }
+ if constexpr (dims == 2) {
+ return get_local_id(1) + get_local_id(0) * get_local_range(1);
+ }
+ if constexpr (dims == 3) {
+ return get_local_id(2) + get_local_id(1) * get_local_range(2)
+ + get_local_id(0) * get_local_range(1) * get_local_range(2);
+ }
+ }
+
+ /// @brief Returns global linear id
+ ///
+ /// @return uint32_t The global linear id
+ ///
+ inline uint32_t get_global_linear_id() const {
+ return cm_linear_global_id();
+ }
+
+ inline uint32_t get_group_range(int dimension) const {
+ return cm_group_count(dims - 1 - dimension);
+ }
+
+ inline uint32_t get_group_linear_id() const { return cm_linear_group_id(); }
+};
+
+} // namespace sycl
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/common/utils/cm/rand.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/common/utils/cm/rand.hpp
new file mode 100644
index 00000000000..6329d81da9d
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/common/utils/cm/rand.hpp
@@ -0,0 +1,170 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#ifdef _WIN32
+#include "../../../common/utils/cm/common.hpp"
+#else
+#include "common/utils/cm/common.hpp"
+#endif
+
+namespace gpu::xetla {
+
+/// @addtogroup xetla_util_rand
+/// @{
+
+template <uint32_t SIMD = 16, uint32_t round = 7>
+struct xetla_rand_t {
+ xetla_vector<uint32_t, 2 * SIMD> key;
+ xetla_vector<uint32_t, 4 * SIMD> counter;
+ static constexpr uint32_t kPhilox10A = 0x9E3779B9;
+ static constexpr uint32_t kPhilox10B = 0xBB67AE85;
+ static constexpr uint32_t kPhiloxSA = 0xD2511F53;
+ static constexpr uint32_t kPhiloxSB = 0xCD9E8D57;
+
+ __XETLA_API void init(uint64_t seed, uint64_t subseq, uint64_t offset) {
+ xetla_vector<uint64_t, 1> seed_v = seed;
+ xetla_vector<uint64_t, 1> offset_v = offset;
+ xetla_vector<uint64_t, 1> subseq_v = subseq * SIMD;
+
+ auto key_2d = key.xetla_format<uint32_t, 2, SIMD>();
+ key_2d.row(0) = uint32_t(seed_v.xetla_format<uint32_t>()[0]);
+ key_2d.row(1) = uint32_t(seed_v.xetla_format<uint32_t>()[1]);
+
+ xetla_vector<uint32_t, SIMD> channel_id
+ = xetla_vector_gen<uint32_t, SIMD>(0, 1);
+ auto counter_2d = counter.xetla_format<uint32_t, 4, SIMD>();
+ counter_2d.row(0) = uint32_t(offset_v.xetla_format<uint32_t>()[0]);
+ counter_2d.row(1) = uint32_t(offset_v.xetla_format<uint32_t>()[1]);
+ counter_2d.row(2) = uint32_t(subseq_v.xetla_format<uint32_t>()[0]);
+ counter_2d.row(3) = uint32_t(subseq_v.xetla_format<uint32_t>()[1]);
+ counter_2d.row(2) += channel_id;
+ }
+
+ __XETLA_API xetla_vector<uint32_t, 4 * SIMD> rand() {
+ xetla_vector<uint32_t, 2 *SIMD> key_ = key;
+ xetla_vector<uint32_t, 4 *SIMD> counter_ = counter;
+ auto key_2d_ = key_.xetla_format<uint32_t, 2, SIMD>();
+
+#pragma unroll
+ for (int i = 0; i < round; i++) {
+ counter_ = single_round(counter_, key_);
+ key_2d_.row(0) += kPhilox10A;
+ key_2d_.row(1) += kPhilox10B;
+ }
+ xetla_vector<uint32_t, 4 *SIMD> output = single_round(counter_, key_);
+ incr();
+ return output;
+ }
+
+private:
+ __XETLA_API xetla_vector<uint32_t, 4 * SIMD> single_round(
+ xetla_vector<uint32_t, 4 * SIMD> counter_,
+ xetla_vector<uint32_t, 2 * SIMD> key_) {
+ xetla_vector<uint32_t, 4 * SIMD> ret;
+ auto ret_2d = ret.xetla_format<uint32_t, 4, SIMD>();
+ auto key_2d_ = key_.xetla_format<uint32_t, 2, SIMD>();
+ auto counter_2d_ = counter_.xetla_format<uint32_t, 4, SIMD>();
+
+ xetla_vector<uint32_t, SIMD> res0_lo;
+ xetla_vector<uint32_t, SIMD> res1_lo;
+ xetla_vector<uint32_t, SIMD> res0_hi
+ = xetla_imul<uint32_t, uint32_t, uint32_t, SIMD>(
+ res0_lo.xetla_format<uint32_t>(), counter_2d_.row(0),
+ kPhiloxSA);
+ xetla_vector<uint32_t, SIMD> res1_hi
+ = xetla_imul<uint32_t, uint32_t, uint32_t, SIMD>(
+ res1_lo.xetla_format<uint32_t>(), counter_2d_.row(2),
+ kPhiloxSB);
+
+ ret_2d.row(0) = res1_hi ^ counter_2d_.row(1) ^ key_2d_.row(0);
+ ret_2d.row(1) = res1_lo;
+ ret_2d.row(2) = res0_hi ^ counter_2d_.row(3) ^ key_2d_.row(1);
+ ret_2d.row(3) = res0_lo;
+
+ return ret;
+ }
+
+ __XETLA_API void incr() {
+ auto counter_2d = counter.xetla_format<uint32_t, 4, SIMD>();
+ xetla_vector<uint32_t, SIMD> carry;
+
+ counter_2d.row(0) = xetla_add_c<uint32_t, SIMD>(
+ counter_2d.row(0), 1, carry.xetla_format<uint32_t>());
+ counter_2d.row(1) = xetla_add_c<uint32_t, SIMD>(
+ counter_2d.row(1), carry, carry.xetla_format<uint32_t>());
+ counter_2d.row(2) = xetla_add_c<uint32_t, SIMD>(
+ counter_2d.row(2), carry, carry.xetla_format<uint32_t>());
+ counter_2d.row(3) += carry;
+ }
+};
+
+template <uint32_t SZ, typename dtype_mask = uint8_t, uint32_t random_simd = 16>
+struct dropout_fwd_t {
+ static constexpr uint32_t random_len = 4 * random_simd;
+ xetla_rand_t<random_simd> rand_gen;
+ xetla_vector<dtype_mask, SZ> mask;
+ uint32_t threshold;
+ float scale;
+
+ __XETLA_API void init(uint64_t seed, uint64_t subseq, uint64_t offset,
+ uint32_t threshold_, float scale_) {
+ rand_gen.init(seed, subseq, offset);
+ this->threshold = threshold_;
+ this->scale = scale_;
+ }
+
+ template <typename dtype>
+ __XETLA_API xetla_vector<dtype, SZ> process(xetla_vector<dtype, SZ> input) {
+ xetla_vector<dtype, SZ> output = input;
+#pragma unroll
+ for (int i = 0; i < SZ / random_len; i++) {
+ auto out_sub = output.xetla_select<random_len, 1>(i * random_len);
+ auto mask_sub = mask.xetla_select<random_len, 1>(i * random_len);
+ xetla_vector<uint32_t, random_len> rand_val = rand_gen.rand();
+ xetla_mask<random_len> mask_flag = rand_val < threshold;
+ out_sub.xetla_merge(0, mask_flag);
+ mask_sub.xetla_merge(1, 0, mask_flag);
+ out_sub = out_sub * scale;
+ }
+ if constexpr (SZ % random_len != 0) {
+ constexpr uint32_t remain_len = SZ % random_len;
+ constexpr uint32_t remain_start = SZ / random_len * random_len;
+ auto out_sub = output.xetla_select<remain_len, 1>(remain_start);
+ auto mask_sub = mask.xetla_select<remain_len, 1>(remain_start);
+ // dropout, still generate random_len
+ xetla_vector<uint32_t, random_len> rand_val = rand_gen.rand();
+ xetla_mask<random_len> mask_flag = rand_val < threshold;
+ out_sub.xetla_merge(0, mask_flag.xetla_select<remain_len, 1>(0));
+ mask_sub.xetla_merge(
+ 1, 0, mask_flag.xetla_select<remain_len, 1>(0));
+ out_sub = out_sub * scale;
+ }
+ return output;
+ }
+
+ __XETLA_API xetla_vector<dtype_mask, SZ> get_mask() {
+ return mask;
+ }
+};
+
+/// @} xetla_util_rand
+
+} // namespace gpu::xetla
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/common/utils/cm/raw_send_load_store.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/common/utils/cm/raw_send_load_store.hpp
new file mode 100644
index 00000000000..12f6317e138
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/common/utils/cm/raw_send_load_store.hpp
@@ -0,0 +1,386 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#ifdef _WIN32
+#include "../../../common/utils/cm/common.hpp"
+#include "../../../common/utils/cm/limitation.hpp"
+#else
+#include "common/utils/cm/common.hpp"
+#include "common/utils/cm/limitation.hpp"
+#endif
+
+namespace gpu::xetla {
+
+/// @addtogroup xetla_util_tensor_load_store
+/// @{
+
+/// @} xetla_util_tensor_load_store
+
+/// @addtogroup xetla_util_tensor_load_store
+/// @{
+
+/// @brief Tensor descriptor construction(global memory version).
+/// Constructs a tensor descriptor based on the given arguments.
+/// @tparam Ty is the data type per element.
+/// @tparam block_width is the width of the block to be loaded.
+/// @tparam block_height is the height of the block to be loaded.
+/// @tparam array_len is the array length of the block to be loaded.
+/// @param tdesc [in|out] is the reference of tensor descriptor.
+/// @param p [in] is the base address pointer of the tensor.
+/// @param tensor_width [in] is the width of the tensor.
+/// @param tensor_height [in] is the height of the tensor.
+/// @param tensor_pitch [in] is the pitch(physical width of tensor in memory).
+/// @param offset_x [in] is the x coordinate of the start point.
+/// @param offset_y [in] is the y coordinate of the start point.
+///
+template <typename Ty, uint32_t block_width = 1, uint32_t block_height = 1,
+ uint8_t array_len = 1>
+__XETLA_API void xetla_fill_tdesc(xetla_tdescriptor_ref tdesc, Ty *p,
+ int tensor_width, int tensor_height, int tensor_pitch, int offset_x,
+ int offset_y) {
+ detail::xetla_set_tensor_base_address(tdesc, (uint64_t)p);
+ detail::xetla_set_tensor_width_x(tdesc, tensor_width * sizeof(Ty) - 1);
+ detail::xetla_set_tensor_width_y(tdesc, tensor_height - 1);
+ detail::xetla_set_tensor_pitch_x(tdesc, tensor_pitch * sizeof(Ty) - 1);
+ detail::xetla_set_tensor_offset_x(tdesc, offset_x);
+ detail::xetla_set_tensor_offset_y(tdesc, offset_y);
+ uint32_t block_widthx_widthy_arrlen = (block_width - 1)
+ | ((block_height - 1) << 8) | ((array_len - 1) << 16);
+ detail::xetla_set_block_widthx_widthy_arrlen(
+ tdesc, block_widthx_widthy_arrlen);
+}
+
+/// @brief Tensor descriptor construction(local memory version).
+/// Constructs a tensor descriptor based on the given arguments, keep the same format as the global memory version.
+/// @tparam Ty is the data type per element.
+/// @param tdesc [in|out] is the reference of tensor descriptor.
+/// @param base_address [in] is the local memory base address of the tensor.
+/// @param tensor_width [in] is the width of the tensor.
+/// @param tensor_height [in] is the height of the tensor.
+/// @param tensor_pitch [in] is the pitch(physical width of tensor in memory).
+/// @param offset_x [in] is the x coordinate of the start point.
+/// @param offset_y [in] is the y coordinate of the start point.
+///
+template <typename Ty>
+__XETLA_API void xetla_fill_tdesc(xetla_tdescriptor_ref tdesc,
+ uint32_t base_address, int tensor_width, int tensor_height,
+ int tensor_pitch, int offset_x, int offset_y) {
+ detail::xetla_set_tensor_base_address(tdesc, base_address);
+ detail::xetla_set_tensor_width_x(tdesc, tensor_width * sizeof(Ty));
+ detail::xetla_set_tensor_width_y(tdesc, tensor_height);
+ detail::xetla_set_tensor_pitch_x(tdesc, tensor_pitch * sizeof(Ty));
+ detail::xetla_set_tensor_offset_x(tdesc, offset_x);
+ detail::xetla_set_tensor_offset_y(tdesc, offset_y);
+}
+
+/// @brief Generate a new tensor descriptor(global memory version).
+/// Generate a tensor descriptor based on the given arguments.
+/// @tparam Ty is the data type per element.
+/// @tparam block_width is the width of the block to be loaded.
+/// @tparam block_height is the height of the block to be loaded.
+/// @tparam array_len is the array length of the block to be loaded.
+/// @param p [in] is the base address pointer of the tensor.
+/// @param tensor_width [in] is the width of the tensor.
+/// @param tensor_height [in] is the height of the tensor.
+/// @param tensor_pitch [in] is the pitch(physical width of tensor in memory).
+/// @param offset_x [in] is the x coordinate of the start point.
+/// @param offset_y [in] is the y coordinate of the start point.
+/// @return return a new tensor
+///
+template <typename Ty, uint32_t block_width = 1, uint32_t block_height = 1,
+ uint8_t array_len = 1>
+__XETLA_API xetla_tdescriptor xetla_get_tdesc(Ty *p, int tensor_width,
+ int tensor_height, int tensor_pitch, int offset_x, int offset_y) {
+ xetla_tdescriptor tdesc;
+ auto tdesc_ref = tdesc.xetla_format<uint32_t>();
+ detail::xetla_set_tensor_base_address(tdesc_ref, (uint64_t)p);
+ detail::xetla_set_tensor_width_x(tdesc_ref, tensor_width * sizeof(Ty) - 1);
+ detail::xetla_set_tensor_width_y(tdesc_ref, tensor_height - 1);
+ detail::xetla_set_tensor_pitch_x(tdesc_ref, tensor_pitch * sizeof(Ty) - 1);
+ detail::xetla_set_tensor_offset_x(tdesc_ref, offset_x);
+ detail::xetla_set_tensor_offset_y(tdesc_ref, offset_y);
+ uint32_t block_widthx_widthy_arrlen = (block_width - 1)
+ | ((block_height - 1) << 8) | ((array_len - 1) << 16);
+ detail::xetla_set_block_widthx_widthy_arrlen(
+ tdesc_ref, block_widthx_widthy_arrlen);
+ return tdesc;
+}
+
+/// @brief Generate a new tensor descriptor(local memory version).
+/// Constructs a tensor descriptor based on the given arguments, keep the same format as the global memory version.
+/// @tparam Ty is the data type per element.
+/// @param base_address [in] is the local memory base address of the tensor.
+/// @param tensor_width [in] is the width of the tensor.
+/// @param tensor_height [in] is the height of the tensor.
+/// @param tensor_pitch [in] is the pitch(physical width of tensor in memory).
+/// @param offset_x [in] is the x coordinate of the start point.
+/// @param offset_y [in] is the y coordinate of the start point.
+/// @return return a new tensor descriptor
+///
+template <typename Ty>
+__XETLA_API xetla_tdescriptor xetla_get_tdesc(uint32_t base_address,
+ int tensor_width, int tensor_height, int tensor_pitch, int offset_x,
+ int offset_y) {
+ xetla_tdescriptor tdesc;
+ auto tdesc_ref = tdesc.xetla_format<uint32_t>();
+ detail::xetla_set_tensor_base_address(tdesc_ref, base_address);
+ detail::xetla_set_tensor_width_x(tdesc_ref, tensor_width * sizeof(Ty));
+ detail::xetla_set_tensor_width_y(tdesc_ref, tensor_height);
+ detail::xetla_set_tensor_pitch_x(tdesc_ref, tensor_pitch * sizeof(Ty));
+ detail::xetla_set_tensor_offset_x(tdesc_ref, offset_x);
+ detail::xetla_set_tensor_offset_y(tdesc_ref, offset_y);
+ return tdesc;
+}
+
+/// @brief Update the x coordinate in the given tensor descriptor.
+/// @param tdesc [in|out] is the reference of tensor descriptor.
+/// @param doffset_x [in] is the offset (in number of data elements) in x direction.
+__XETLA_API void xetla_update_tdesc_offsetx(
+ xetla_tdescriptor_ref tdesc, int32_t doffset_x) {
+ detail::xetla_set_tensor_offset_x(
+ tdesc, detail::xetla_get_tensor_offset_x(tdesc) + doffset_x);
+}
+
+/// @brief Update the y coordinate in the given tensor descriptor.
+/// @param tdesc [in|out] is the reference of tensor descriptor.
+/// @param doffset_y [in] is the offset (in number of data elements) in y direction.
+__XETLA_API void xetla_update_tdesc_offsety(
+ xetla_tdescriptor_ref tdesc, int32_t doffset_y) {
+ detail::xetla_set_tensor_offset_y(
+ tdesc, detail::xetla_get_tensor_offset_y(tdesc) + doffset_y);
+}
+
+/// @brief Update the base in the given tensor descriptor.
+/// @param tdesc [in|out] is the reference of tensor descriptor.
+/// @param base_offset [in] is the offset to update base address.
+__XETLA_API void xetla_update_tdesc_base_address(
+ xetla_tdescriptor_ref tdesc, int32_t base_offset) {
+ detail::xetla_set_tensor_base_address(
+ tdesc, detail::xetla_get_tensor_base_address(tdesc) + base_offset);
+}
+
+/// @brief Set width in the given tensor descriptor.
+/// @tparam Ty is the data type per element.
+/// @param tdesc [in|out] is the reference of tensor descriptor.
+/// @param size [in] is the new width.
+template <typename Ty>
+__XETLA_API void xetla_set_tdesc_width(
+ xetla_tdescriptor_ref tdesc, int32_t size) {
+ detail::xetla_set_tensor_width_x(tdesc, size * sizeof(Ty) - 1);
+}
+
+/// @brief Set pitch in the given tensor descriptor.
+/// @tparam Ty is the data type per element.
+/// @param tdesc [in|out] is the reference of tensor descriptor.
+/// @param size [in] is the new pitch.
+template <typename Ty>
+__XETLA_API void xetla_set_tdesc_pitch(
+ xetla_tdescriptor_ref tdesc, int32_t size) {
+ detail::xetla_set_tensor_pitch_x(tdesc, size * sizeof(Ty) - 1);
+}
+
+/// @brief Set height in the given tensor descriptor.
+/// @param tdesc [in|out] is the reference of tensor descriptor.
+/// @param size [in] is the new height.
+__XETLA_API void xetla_set_tdesc_height(
+ xetla_tdescriptor_ref tdesc, int32_t size) {
+ detail::xetla_set_tensor_width_y(tdesc, size - 1);
+}
+
+/// @brief mask tdesc load_store op. If mask is 1 tdesc is unchanged. If mask is 0 then using this
+/// tdesc for load would produce zero result, using this tdesc for store preforms no mem update.
+/// @param tdesc [in|out] is the reference of tensor descriptor.
+/// @param mask [in] is the mask.
+__XETLA_API void xetla_tdesc_mask_op(
+ xetla_tdescriptor_ref tdesc, uint16_t mask) {
+ // +1 here since width is -1 encoded in tdesc
+ uint32_t width = detail::xetla_get_tensor_width_x(tdesc) + 1;
+
+ // adding width to offset_x if mask is 0 would produce zero on load and no memory update
+ // on store
+
+ // if mask is 0 then mask-1 is 0xFFFFFFFF and doing & with width update the offset.
+ // if mask is 1 then mask-1 is 0x00000000 and doing & with width keeps tdesc as is.
+ xetla_update_tdesc_offsetx(tdesc, width & (uint32_t)(mask - 1));
+}
+
+///
+/// @brief Tensor load API.
+/// This is tensor load API from global to registers.
+/// @tparam Ty is the data type per element.
+/// @tparam N is the total number of elements to load.
+/// @tparam L1H is L1$ cache hint.
+/// @tparam L2H is L2$ cache hint.
+/// @tparam transpose is a flag to indicate whether the data is transposed during load.
+/// @tparam transform is a flag to indicate whether the data is transformed (data pack inside dword) during load.
+/// @param tdesc [in] is tensor descriptor including tensor base address, tensor dimensions, block size, etc.
+/// @return __XETLA_API xetla_vector is data returned from the load.
+///
+template <typename Ty, uint32_t N, cache_hint L1H = cache_hint::none,
+ cache_hint L2H = cache_hint::none, bool transpose = false,
+ bool transform = false, gpu_arch arch_tag = gpu_arch::Xe>
+__XETLA_API std::enable_if_t<arch_tag == gpu_arch::Xe, xetla_vector<Ty, N>>
+xetla_tload_global(xetla_tdescriptor tdesc) {
+
+ constexpr uint32_t numDst = 31 < ((N * sizeof(Ty) + 63) / 64)
+ ? 31
+ : ((N * sizeof(Ty) + 63) / 64);
+ uint32_t msg_desc = 3;
+ msg_desc |= (transform ? 1 : 0) << 7;
+ msg_desc |= detail::get_element_size_code<sizeof(Ty)>() << 9;
+ msg_desc |= (transpose ? 1 : 0) << 15;
+ msg_desc |= detail::get_load_cache_hint_code<L1H, L2H, arch_tag>() << 17;
+ msg_desc |= 1 << 25;
+ msg_desc |= numDst << 20;
+
+ constexpr uint32_t numSrc0 = 1;
+ constexpr uint32_t execSize = 0;
+ constexpr uint32_t sfid = 0xF;
+ constexpr uint32_t exDesc = 0;
+
+ constexpr uint32_t ret_N = (N * sizeof(Ty)) >= 32 ? N : 32 / sizeof(Ty);
+ xetla_vector<Ty, ret_N> ret;
+
+ xetla_raw_send<Ty, ret_N, uint32_t, 16, execSize, sfid, numSrc0, numDst>(
+ ret.xetla_format<native_type_t<Ty>>(), tdesc, exDesc, msg_desc);
+
+ return ret.xetla_select<N, 1>(0);
+}
+
+///
+/// @brief Tensor store API.
+/// Tensor store API is to store a n-d (e.g. n=2) tensor into global using tensor descriptor.
+/// @tparam Ty is the data type per element.
+/// @tparam N is the number of elements to store.
+/// @tparam L1H is L1 cache hint.
+/// @tparam L2H is L2 cache hint.
+/// @param tdesc [in] is tensor descriptor including tensor base address, tensor dimensions, block size, etc.
+/// @param data [in] is tensor data to store.
+/// @return __XETLA_API none.
+///
+template <typename Ty, uint32_t N, cache_hint L1H = cache_hint::none,
+ cache_hint L2H = cache_hint::none, gpu_arch arch_tag = gpu_arch::Xe>
+__XETLA_API std::enable_if_t<arch_tag == gpu_arch::Xe, void>
+xetla_tstore_global(xetla_tdescriptor tdesc, xetla_vector<Ty, N> data) {
+
+ uint32_t msg_desc = 7; // store operation
+ msg_desc |= detail::get_element_size_code<sizeof(Ty)>() << 9;
+ msg_desc |= detail::get_store_cache_hint_code<L1H, L2H, arch_tag>() << 17;
+ msg_desc |= 1 << 25;
+
+ constexpr uint32_t numSrc1 = (N * sizeof(Ty) + 63) / 64;
+ constexpr uint32_t numSrc0 = 1;
+ constexpr uint32_t execSize = 0;
+ constexpr uint32_t sfid = 0xF;
+ constexpr uint32_t exDesc = 0;
+
+ xetla_raw_send<uint32_t, 16, Ty, N, execSize, sfid, numSrc0, numSrc1>(
+ tdesc, data, exDesc, msg_desc);
+}
+
+///
+/// @brief Tensor prefetch API.
+/// This is tensor prefetch API from global memory to L1$/L2$.
+/// @tparam Ty is the data type per element.
+/// @tparam L1H is L1$ cache hit.
+/// @tparam L2H is L2$ cache hit.
+/// @param tdesc is tensor descriptor including tensor base address, tensor dimensions, block size, etc.
+/// @return __XETLA_API none.
+///
+template <typename Ty, cache_hint L1H = cache_hint::cached,
+ cache_hint L2H = cache_hint::cached, gpu_arch arch_tag = gpu_arch::Xe>
+__XETLA_API std::enable_if_t<arch_tag == gpu_arch::Xe, void>
+xetla_tprefetch_global(xetla_tdescriptor tdesc, uint16_t pred = 1) {
+
+ uint32_t msg_desc = 3;
+ msg_desc |= 0 << 7;
+ msg_desc |= detail::get_element_size_code<sizeof(Ty)>() << 9;
+ msg_desc |= 0 << 15;
+ msg_desc |= detail::get_prefetch_cache_hint_code<L1H, L2H, arch_tag>()
+ << 17;
+ msg_desc |= 1 << 25;
+
+ constexpr uint32_t numSrc0 = 1;
+ constexpr uint32_t execSize = 0;
+ constexpr uint32_t sfid = 0xF;
+ constexpr uint32_t exDesc = 0;
+
+ xetla_mask<16> mask = pred;
+
+ xetla_raw_send<uint32_t, 16, execSize, sfid, numSrc0>(
+ tdesc, exDesc, msg_desc, mask);
+}
+
+///
+/// @brief Tensor atomic store API.
+/// Tensor atomic store API is to store a n-d (e.g. n=2) tensor into global.
+/// @tparam Ty is the data type per element.
+/// @tparam N is the number of elements to store.
+/// @tparam L1H is L1 cache hint.
+/// @tparam L2H is L2 cache hint.
+/// @tparam Toffset is the offset data type.
+/// @param base_address [in] is the 64bit base address of the surface.
+/// @param offset [in] is the address offset for each channel, default is 32bits.
+/// @param data [in] is tensor data to store.
+/// @return none.
+///
+template <typename Ty, uint32_t N, cache_hint L1H = cache_hint::none,
+ cache_hint L2H = cache_hint::none, atomic_op Op,
+ gpu_arch arch_tag = gpu_arch::Xe, typename Toffset = uint32_t>
+__XETLA_API std::enable_if_t<arch_tag == gpu_arch::Xe, void>
+xetla_tatomic_store_global(uint64_t base_address,
+ xetla_vector<Toffset, N> offset, xetla_vector<Ty, N> data,
+ xetla_mask<N> pred = 1) {
+
+ constexpr uint32_t numSrc0 = (N * sizeof(uint64_t) + 63) / 64;
+ constexpr uint32_t numSrc1 = (N * sizeof(Ty) + 63) / 64;
+ constexpr uint32_t num_dest = (N * sizeof(Ty) + 63) / 64;
+
+ // disable u16 for now, since there is no usage
+ static_assert(
+ sizeof(Ty) == 4 || sizeof(Ty) == 8, "element_size not supported!");
+ uint32_t element_size_code;
+ if constexpr (sizeof(Ty) == 4) {
+ element_size_code = 2;
+ } else if constexpr (sizeof(Ty) == 8) {
+ element_size_code = 3;
+ }
+
+ uint32_t msg_desc = detail::get_atomic_opcode<Op>();
+ ///only support 64bit address
+ msg_desc |= 3 << 7;
+ msg_desc |= element_size_code << 9;
+ msg_desc |= detail::get_atomic_cache_hint_code<L1H, L2H, arch_tag>() << 17;
+ msg_desc |= numSrc0 << 25;
+
+ constexpr uint32_t execSize = gpu::xetla::detail::get_execSize_code<N>();
+ constexpr uint32_t sfid = 0xF;
+ constexpr uint32_t exDesc = 0;
+
+ xetla_vector<uint64_t, N> address = base_address + offset;
+
+ xetla_raw_send<uint64_t, N, Ty, N, execSize, sfid, numSrc0, numSrc1>(
+ address, data, exDesc, msg_desc, pred);
+}
+
+/// @} xetla_util_tensor_load_store
+
+} // namespace gpu::xetla
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/common/utils/cm/raw_send_nbarrier.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/common/utils/cm/raw_send_nbarrier.hpp
new file mode 100644
index 00000000000..32773eb3e8e
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/common/utils/cm/raw_send_nbarrier.hpp
@@ -0,0 +1,90 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#ifdef _WIN32
+#include "../../../common/utils/cm/common.hpp"
+#else
+#include "common/utils/cm/common.hpp"
+#endif
+
+namespace gpu::xetla {
+
+/// @addtogroup xetla_util_named_barrier
+/// @{
+
+enum class nbarrier_role : uint8_t {
+ producer_consumer = 0,
+ producer = 1,
+ consumer = 2
+};
+
+///
+/// @brief xetla nbarrier definition API.
+/// This is the API to define a named barrier within subgroup.
+/// @tparam num_producers is the number of subgroups participating the barrier as producer.
+/// @tparam num_consumers is the number of subgroups participating the barrier as consumer.
+///
+template <uint8_t num_producers = 1, uint8_t num_consumers = 1,
+ gpu_arch arch_tag = gpu_arch::Xe>
+struct xetla_nbarrier_t {
+ ///
+ /// @brief Description of named barrier objection.
+ ///
+ xetla_vector<uint32_t, 16> nbar;
+ uint32_t barrier_id;
+
+ /// @param role is the role of subgroup when participating the barrier.
+ /// @param nbarrier_id [in] is the id of the barrier.
+ /// note: all subgroups participating the barrier should have the same barrier_id.
+ __XETLA_API void init_nbarrier(uint8_t nbarrier_id,
+ nbarrier_role role = nbarrier_role::producer_consumer) {
+ nbar[2] = (uint32_t)nbarrier_id | uint32_t((uint8_t)role << 14)
+ | uint32_t(num_producers << 16) | uint32_t(num_consumers << 24);
+ barrier_id = nbarrier_id;
+ }
+
+ /// @brief named barrier signal from subgroup.
+ /// @param bar is the named barrier object.
+ ///
+ __XETLA_API void arrive() {
+ constexpr uint32_t sfid = 0x3;
+ constexpr uint32_t exDesc = sfid;
+ constexpr uint32_t msg_desc = 0x2000004;
+ constexpr uint32_t execSize = 0;
+
+ xetla_raw_send<uint32_t, 16, execSize, sfid, 1>(nbar, exDesc, msg_desc);
+ }
+
+ /// @brief named barrier wait within subgroup.
+ ///
+ __XETLA_API void wait() { named_barrier_wait(barrier_id); }
+
+ /// @brief named barrier signal from subgroup.
+ ///
+ __XETLA_API void arrive_wait() {
+ arrive();
+ wait();
+ }
+};
+
+/// @} xetla_util_named_barrier
+
+} // namespace gpu::xetla
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/common/utils/cm/tensor_descriptor.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/common/utils/cm/tensor_descriptor.hpp
new file mode 100644
index 00000000000..73397231df9
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/common/utils/cm/tensor_descriptor.hpp
@@ -0,0 +1,99 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#ifdef _WIN32
+#include "../../../common/core/cm/core.hpp"
+#else
+#include "common/core/cm/core.hpp"
+#endif
+
+namespace gpu::xetla {
+
+namespace detail {
+__XETLA_API void xetla_set_tensor_base_address(
+ xetla_tdescriptor_ref desc, uint64_t base_address) {
+ desc.xetla_format<uint64_t>().xetla_select<1, 1>(0) = base_address;
+}
+__XETLA_API void xetla_set_tensor_base_address(
+ xetla_tdescriptor_ref desc, uint32_t base_address) {
+ desc.xetla_format<uint32_t>().xetla_select<1, 1>(0) = base_address;
+}
+__XETLA_API uint64_t xetla_get_tensor_base_address(xetla_tdescriptor desc) {
+ return desc.xetla_format<uint64_t>().xetla_select<1, 1>(0)[0];
+}
+
+__XETLA_API void xetla_set_tensor_width_x(
+ xetla_tdescriptor_ref desc, uint32_t width_x) {
+ desc.xetla_format<uint32_t>().xetla_select<1, 1>(2) = width_x;
+}
+__XETLA_API uint32_t xetla_get_tensor_width_x(xetla_tdescriptor desc) {
+ return desc.xetla_format<uint32_t>().xetla_select<1, 1>(2)[0];
+}
+
+__XETLA_API void xetla_set_tensor_width_y(
+ xetla_tdescriptor_ref desc, uint32_t width_y) {
+ desc.xetla_format<uint32_t>().xetla_select<1, 1>(3) = width_y;
+}
+__XETLA_API uint32_t xetla_get_tensor_width_y(xetla_tdescriptor desc) {
+ return desc.xetla_format<uint32_t>().xetla_select<1, 1>(3)[0];
+}
+
+__XETLA_API void xetla_set_tensor_pitch_x(
+ xetla_tdescriptor_ref desc, uint32_t pitch_x) {
+ desc.xetla_format<uint32_t>().xetla_select<1, 1>(4) = pitch_x;
+}
+__XETLA_API uint32_t xetla_get_tensor_pitch_x(xetla_tdescriptor desc) {
+ return desc.xetla_format<uint32_t>().xetla_select<1, 1>(4)[0];
+}
+
+__XETLA_API void xetla_set_tensor_offset_x(
+ xetla_tdescriptor_ref desc, int32_t offset_x) {
+ desc.xetla_format<int32_t>().xetla_select<1, 1>(5) = offset_x;
+}
+__XETLA_API int32_t xetla_get_tensor_offset_x(xetla_tdescriptor desc) {
+ return desc.xetla_format<int32_t>().xetla_select<1, 1>(5)[0];
+}
+
+__XETLA_API void xetla_set_tensor_offset_y(
+ xetla_tdescriptor_ref desc, int32_t offset_y) {
+ desc.xetla_format<int32_t>().xetla_select<1, 1>(6) = offset_y;
+}
+__XETLA_API int32_t xetla_get_tensor_offset_y(xetla_tdescriptor desc) {
+ return desc.xetla_format<int32_t>().xetla_select<1, 1>(6)[0];
+}
+
+__XETLA_API void xetla_set_block_widthx_widthy_arrlen(
+ xetla_tdescriptor_ref desc, uint32_t block_widthx_widthy_arrlen) {
+ desc.xetla_format<uint32_t>().xetla_select<1, 1>(7)
+ = block_widthx_widthy_arrlen;
+}
+__XETLA_API uint8_t xetla_get_block_width_x(xetla_tdescriptor desc) {
+ return desc.xetla_format<uint8_t>().xetla_select<1, 1>(28)[0];
+}
+__XETLA_API uint8_t xetla_get_block_width_y(xetla_tdescriptor desc) {
+ return desc.xetla_format<uint8_t>().xetla_select<1, 1>(29)[0];
+}
+__XETLA_API uint8_t xetla_get_block_array_len(xetla_tdescriptor desc) {
+ return desc.xetla_format<uint8_t>().xetla_select<1, 1>(30)[0];
+}
+} // namespace detail
+
+} // namespace gpu::xetla
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/common/utils/cm/utils.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/common/utils/cm/utils.hpp
new file mode 100644
index 00000000000..f6346ec9ef5
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/common/utils/cm/utils.hpp
@@ -0,0 +1,65 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+#pragma once
+
+/// @defgroup xetla_util XeTLA Utility
+/// This is low level API wrapper for utility functions.
+/// Including the tensor prefetch/load/store API based on xetla_raw_send, simd_lane id generation API and so on.
+
+/// @addtogroup xetla_util
+/// @{
+
+/// @defgroup xetla_util_tensor_load_store Tensor load store API
+/// Implements the tensor load store functionality using raw send instructions.
+
+/// @defgroup xetla_util_misc Util misc API
+/// Implements some useful and commonly used APIs, such as vector generation API.
+
+/// @defgroup xetla_util_rand Random number generator API
+/// Philox rng, will generate 4 uint32_t random number per call.
+
+/// @defgroup xetla_util_group XeTLA Group
+/// This is a group API to define operation scope.
+
+/// @defgroup xetla_util_named_barrier Named barrier API
+/// This is a raw_send based named barrier API.
+
+/// @} xetla_util
+
+#ifdef _WIN32
+#include "../../../common/utils/cm/common.hpp"
+#include "../../../common/utils/cm/dict.hpp"
+#include "../../../common/utils/cm/fastmath.hpp"
+#include "../../../common/utils/cm/memory_descriptor.hpp"
+#include "../../../common/utils/cm/misc.hpp"
+#include "../../../common/utils/cm/nd_item.hpp"
+#include "../../../common/utils/cm/rand.hpp"
+#include "../../../common/utils/cm/raw_send_load_store.hpp"
+#include "../../../common/utils/cm/raw_send_nbarrier.hpp"
+#include "../../../common/utils/cm/work_group.hpp"
+#else
+#include "common/utils/cm/common.hpp"
+#include "common/utils/cm/dict.hpp"
+#include "common/utils/cm/fastmath.hpp"
+#include "common/utils/cm/memory_descriptor.hpp"
+#include "common/utils/cm/misc.hpp"
+#include "common/utils/cm/nd_item.hpp"
+#include "common/utils/cm/rand.hpp"
+#include "common/utils/cm/raw_send_load_store.hpp"
+#include "common/utils/cm/raw_send_nbarrier.hpp"
+#include "common/utils/cm/work_group.hpp"
+#endif
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/common/utils/cm/work_group.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/common/utils/cm/work_group.hpp
new file mode 100644
index 00000000000..7929dcdd18f
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/common/utils/cm/work_group.hpp
@@ -0,0 +1,56 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#ifdef _WIN32
+#include "../../../common/utils/cm/common.hpp"
+#else
+#include "common/utils/cm/common.hpp"
+#endif
+
+namespace gpu::xetla {
+
+/// @addtogroup xetla_util_group
+/// @{
+
+/// @brief Define a workgroup scope for a specific problem shape.
+/// The size of the workgroup should <= group size.
+/// @tparam size_ Is the number of subgroups within a workgroup.
+template <uint32_t size_>
+struct work_group_t {
+private:
+ uint32_t sg_id;
+
+public:
+ static constexpr uint32_t size = size_;
+ __XETLA_API constexpr uint32_t get_size() { return size; }
+ __XETLA_API uint32_t get_id() { return sg_id; }
+ __XETLA_API void init(uint32_t id) { sg_id = id; }
+ inline work_group_t(uint32_t id) : sg_id(id) {}
+ inline work_group_t() = default;
+ template <uint32_t scope_size>
+ __XETLA_API work_group_t<scope_size> partition() {
+ work_group_t<scope_size> wtile;
+ wtile.init(sg_id % scope_size);
+ return wtile;
+ }
+};
+/// @} xetla_util_group
+} // namespace gpu::xetla
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/common/utils/utils.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/common/utils/utils.hpp
new file mode 100644
index 00000000000..b6ef776ee06
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/common/utils/utils.hpp
@@ -0,0 +1 @@
+#include "../../common/utils/cm/utils.hpp"
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/group/cooperative_reduction.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/group/cooperative_reduction.hpp
new file mode 100644
index 00000000000..dc44f076871
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/group/cooperative_reduction.hpp
@@ -0,0 +1,221 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#include "group/tile_shape.hpp"
+#include "subgroup/subgroup.hpp"
+
+namespace gpu::xetla::group {
+
+/// @brief Workgroups to do the cooperative reduction.
+/// @tparam reduce_kind Is the reduction type.
+/// @tparam tile_shape Is the group-level tile shape.
+/// @tparam matAcc_t Is the input mat type.
+/// @tparam num_cooperative_wg Is the number of workgroups to do the cooperation.
+/// @tparam arch_tag Is the HW architecture.
+template <reduce_op reduce_kind, typename tile_shape, typename matAcc_t,
+ uint32_t num_cooperative_wg, gpu_arch arch_tag,
+ mem_space space_ = mem_space::local, class enable = void>
+class cooperative_reduce_t {};
+
+/// @brief Workgroups to do the cooperative reduction. Specialized for Xe architecture.
+template <reduce_op reduce_kind, typename tile_shape_, typename matAcc_t,
+ uint32_t num_cooperative_wg, gpu_arch arch_tag_>
+class cooperative_reduce_t<reduce_kind, tile_shape_, matAcc_t,
+ num_cooperative_wg, arch_tag_, mem_space::local,
+ std::enable_if_t<((arch_tag_ == gpu_arch::Xe))
+ && (tile_shape_::dim == 2)>> {
+public:
+ static constexpr gpu_arch arch_tag = arch_tag_;
+ using tile_shape = tile_shape_;
+ using dtype = typename matAcc_t::dtype;
+
+private:
+ static constexpr uint32_t sg_tile_m = tile_shape::sg_tile_size_y;
+ static constexpr uint32_t sg_tile_n = tile_shape::sg_tile_size_x;
+ static constexpr uint32_t wg_size_x = tile_shape::wg_size_x;
+ static constexpr uint32_t wg_size_y = tile_shape::wg_size_y;
+ static constexpr uint32_t real_wg_tile_m = sg_tile_m * wg_size_y;
+ static constexpr uint32_t real_wg_tile_n = sg_tile_n * wg_size_x;
+
+ static constexpr uint32_t wg_tile_size
+ = real_wg_tile_m * real_wg_tile_n * sizeof(dtype);
+ using work_group_t = typename tile_shape::work_group_t;
+ static constexpr uint32_t work_group_size = work_group_t::size;
+ // cooperative split, y dir first
+ static_assert((num_cooperative_wg & (num_cooperative_wg - 1)) == 0,
+ "num_cooperative_wg should be power of 2");
+
+public:
+ static constexpr uint32_t coop_num_y
+ = gpu::xetla::subgroup::detail::gcd<num_cooperative_wg,
+ sg_tile_m>::value;
+ static constexpr uint32_t coop_remain_num_x
+ = num_cooperative_wg / coop_num_y;
+ static constexpr bool has_redundant_wg
+ = (coop_remain_num_x * 16) > sg_tile_n;
+ static constexpr uint32_t tile_size_y = sg_tile_m / coop_num_y;
+ static constexpr uint32_t tile_size_x
+ = has_redundant_wg ? 16 : sg_tile_n / coop_remain_num_x;
+ static constexpr uint32_t coop_num_x = sg_tile_n / tile_size_x;
+ static constexpr uint32_t num_reduce_wg = coop_num_x * coop_num_y;
+
+private:
+ static constexpr uint32_t src_block_size_x = matAcc_t::block_size_x;
+ static constexpr uint32_t src_block_size_y = matAcc_t::block_size_y;
+
+ static constexpr uint32_t block_size_x
+ = gpu::xetla::subgroup::detail::gcd<tile_size_x,
+ src_block_size_x>::value;
+ static constexpr uint32_t block_size_y
+ = (tile_size_y > src_block_size_y) ? src_block_size_y : tile_size_y;
+
+ using local_st_tile_desc_t = subgroup::tile_desc_t<sg_tile_n, sg_tile_m,
+ src_block_size_x, src_block_size_y, reg_layout::tiled>;
+ using local_st_tile_t = subgroup::tile_t<dtype, local_st_tile_desc_t>;
+ using local_st_payload_t = subgroup::mem_payload_t<
+ mem_desc_t<dtype, mem_layout::row_major, mem_space::local>,
+ local_st_tile_desc_t,
+ subgroup::msg_type_v<local_st_tile_desc_t, mem_space::local>,
+ arch_tag>;
+ using local_ld_tile_desc_t = subgroup::tile_desc_t<tile_size_x, tile_size_y,
+ block_size_x, block_size_y, reg_layout::tiled>;
+ using local_ld_tile_t = subgroup::tile_t<dtype, local_ld_tile_desc_t>;
+ using local_ld_payload_t = subgroup::mem_payload_t<
+ mem_desc_t<dtype, mem_layout::row_major, mem_space::local>,
+ local_ld_tile_desc_t,
+ subgroup::msg_type_v<local_ld_tile_desc_t, mem_space::local>,
+ arch_tag>;
+
+public:
+ using mat_slice_t = subgroup::tile_t<dtype, local_ld_tile_desc_t>;
+
+ static constexpr uint32_t barrier_count = work_group_size;
+ static constexpr uint32_t slm_size = wg_tile_size * num_cooperative_wg;
+
+ uint32_t coop_id;
+ uint32_t coop_id_x;
+ uint32_t coop_id_y;
+ inline cooperative_reduce_t(uint32_t coop_id_) : coop_id(coop_id_) {
+ coop_id_x = coop_id % coop_remain_num_x;
+ coop_id_y = coop_id / coop_remain_num_x;
+ }
+ inline bool is_valid_post_process_wg() { return coop_id_x < coop_num_x; }
+
+ /// @brief Cooperative workgroup reduction.
+ /// 1) each workgroup stores tile data to local memory ->
+ /// 2) cross workgroup (but still within a group) sync ->
+ /// 3) workgroups loads slice of tile data, do the reduction.
+ /// @note only workgroups with coop_id_x < coop_num_x have valid data.
+ /// @param g Is the workgroup of the current tile.
+ /// @param mat_slice Is the output of the reduction. Each workgroup only keeps part of the tile data.
+ /// @param matAcc Is the input of the reduction.
+ /// @param slm_base Is the slm base address.
+ /// @param nbarrier_base Is the named barrier base.
+ inline KERNEL_FUNC void operator()(work_group_t &g, mat_slice_t &mat_slice,
+ matAcc_t &matAcc, uint32_t slm_base = 0,
+ uint32_t nbarrier_base = 0) {
+ uint32_t sg_idx = g.get_id() % wg_size_x;
+ uint32_t sg_idy = g.get_id() / wg_size_x;
+
+ int32_t slm_store_offset_x = sg_idx * sg_tile_n;
+ int32_t slm_store_offset_y
+ = coop_id * real_wg_tile_m + sg_idy * sg_tile_m;
+ local_st_tile_t local_st;
+ local_st_payload_t local_st_payload(slm_base, real_wg_tile_n,
+ real_wg_tile_m * num_cooperative_wg, real_wg_tile_n,
+ slm_store_offset_x, slm_store_offset_y);
+ local_st.reg = matAcc.reg;
+ tile_store(local_st, local_st_payload);
+
+ xetla_nbarrier_t<num_cooperative_wg, num_cooperative_wg, arch_tag>
+ nbarrier;
+ uint32_t nbar_id = nbarrier_base + g.get_id();
+ nbarrier.init_nbarrier(nbar_id, nbarrier_role::producer_consumer);
+ xetla_fence<memory_kind::shared_local>();
+ nbarrier.arrive();
+ nbarrier.wait();
+
+ if (is_valid_post_process_wg()) {
+ // nbarrier.init_nbarrier(nbar_id, nbarrier_role::consumer);
+ // nbarrier.arrive();
+ int32_t slm_load_offset_x
+ = sg_idx * sg_tile_n + coop_id_x * tile_size_x;
+ int32_t slm_load_offset_y
+ = sg_idy * sg_tile_m + coop_id_y * tile_size_y;
+
+ local_ld_tile_t local_ld;
+ local_ld_payload_t local_ld_payload(slm_base, real_wg_tile_n,
+ real_wg_tile_m * num_cooperative_wg, real_wg_tile_n,
+ slm_load_offset_x, slm_load_offset_y);
+
+ tile_load(local_ld, local_ld_payload);
+ mat_slice.reg = local_ld.reg;
+#pragma unroll
+ for (int i = 1; i < num_cooperative_wg; i++) {
+ local_ld_payload.template update_tdesc<tdesc_update_dir::y_dir>(
+ real_wg_tile_m);
+ tile_load(local_ld, local_ld_payload);
+ mat_slice.reg = reduce_helper<reduce_kind, dtype>(
+ mat_slice.reg, local_ld.reg);
+ }
+ }
+ }
+};
+
+/// @brief Workgroups to do the cooperative reduction.
+/// Specialized for Xe architecture with 1 workgroups.
+template <reduce_op reduce_kind, typename tile_shape_, typename matAcc_t,
+ gpu_arch arch_tag_>
+class cooperative_reduce_t<reduce_kind, tile_shape_, matAcc_t, 1, arch_tag_,
+ mem_space::local,
+ std::enable_if_t<((arch_tag_ == gpu_arch::Xe))
+ && (tile_shape_::dim == 2)>> {
+public:
+ static constexpr gpu_arch arch_tag = arch_tag_;
+ using tile_shape = tile_shape_;
+ using dtype = typename matAcc_t::dtype;
+
+private:
+ using work_group_t = typename tile_shape::work_group_t;
+
+public:
+ using mat_slice_t = matAcc_t;
+ static constexpr uint32_t barrier_count = 0;
+ static constexpr uint32_t slm_size = 0;
+ static constexpr uint32_t coop_num_x = 1;
+ static constexpr uint32_t coop_num_y = 1;
+ uint32_t coop_id;
+ uint32_t coop_id_x;
+ uint32_t coop_id_y;
+ inline cooperative_reduce_t(uint32_t coop_id_) {
+ coop_id = 0;
+ coop_id_x = 0;
+ coop_id_y = 0;
+ }
+ inline bool is_valid_post_process_wg() { return true; }
+
+ inline KERNEL_FUNC void operator()(work_group_t &g, mat_slice_t &mat_slice,
+ matAcc_t &matAcc, uint32_t slm_base = 0,
+ uint32_t nbarrier_base = 0) {
+ mat_slice.reg = matAcc.reg;
+ }
+};
+} // namespace gpu::xetla::group
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/group/epilogue/api.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/group/epilogue/api.hpp
new file mode 100644
index 00000000000..c6b560b0d23
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/group/epilogue/api.hpp
@@ -0,0 +1,39 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#include "group/epilogue/common.hpp"
+
+namespace gpu::xetla::group {
+
+/// @addtogroup xetla_epilogue
+/// @{
+
+/// @brief Is the epilogue functor.
+/// @tparam epilogue_policy Is the epilogue policy.
+/// @tparam tile_shape Is the workgroup-level tile shape.
+/// @tparam mem_desc_c Is the memory descriptor of matC.
+template <typename epilogue_policy, typename tile_shape, typename mem_desc_c,
+ class enable = void>
+class epilogue_t {};
+
+/// @} xetla_epilogue
+
+} // namespace gpu::xetla::group
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/group/epilogue/common.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/group/epilogue/common.hpp
new file mode 100644
index 00000000000..6b488decb09
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/group/epilogue/common.hpp
@@ -0,0 +1,32 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#include "group/tile_shape.hpp"
+#include "subgroup/subgroup.hpp"
+
+namespace gpu::xetla::group {
+
+/// @addtogroup xetla_epilogue
+/// @{
+
+/// @} xetla_epilogue
+
+} // namespace gpu::xetla::group
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/group/epilogue/epilogue.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/group/epilogue/epilogue.hpp
new file mode 100644
index 00000000000..33498d74870
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/group/epilogue/epilogue.hpp
@@ -0,0 +1,30 @@
+
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+/// @defgroup xetla_epilogue XeTLA EPILOGUE
+/// This is a epilogue API to compute matC = tile_op(matAcc).
+
+#include "group/epilogue/api.hpp"
+#include "group/epilogue/common.hpp"
+#include "group/epilogue/epilogue_policy.hpp"
+#include "group/epilogue/impl/tile_op_xe.hpp"
+#include "group/tile_shape.hpp"
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/group/epilogue/epilogue_policy.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/group/epilogue/epilogue_policy.hpp
new file mode 100644
index 00000000000..88f1e52d79a
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/group/epilogue/epilogue_policy.hpp
@@ -0,0 +1,40 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#include "group/epilogue/common.hpp"
+
+namespace gpu::xetla::group {
+
+/// @addtogroup xetla_epilogue
+/// @{
+
+/// @brief Epilogue policy for tile_op + store C fusion.
+/// @tparam tile_op_t_ Is the tile_op functor.
+/// @tparam arch_tag_ Is the HW architecture.
+template <typename tile_op_t_, gpu_arch arch_tag_>
+struct epilogue_policy_tile_op {
+ using tile_op_t = tile_op_t_;
+ static constexpr gpu_arch arch_tag = arch_tag_;
+};
+
+/// @} xetla_epilogue
+
+} // namespace gpu::xetla::group
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/group/epilogue/impl/tile_op_xe.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/group/epilogue/impl/tile_op_xe.hpp
new file mode 100644
index 00000000000..5376009508a
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/group/epilogue/impl/tile_op_xe.hpp
@@ -0,0 +1,137 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#include "group/epilogue/api.hpp"
+#include "group/epilogue/common.hpp"
+#include "group/epilogue/epilogue_policy.hpp"
+
+namespace gpu::xetla::group {
+
+/// @addtogroup xetla_epilogue
+/// @{
+
+/// @brief Is the epilogue functor specialized for epilogue_policy_tile_op and Xe architecture.
+template <typename tile_op_t_, typename tile_shape_, typename mem_desc_c_t_,
+ gpu_arch arch_tag_>
+class epilogue_t<epilogue_policy_tile_op<tile_op_t_, arch_tag_>, tile_shape_,
+ mem_desc_c_t_, std::enable_if_t<(arch_tag_ == gpu_arch::Xe)>> {
+public:
+ using epilogue_policy = epilogue_policy_tile_op<tile_op_t_, arch_tag_>;
+ using tile_op_t = typename epilogue_policy::tile_op_t;
+ using tile_shape = tile_shape_;
+ using mem_desc_c_t = mem_desc_c_t_;
+ static constexpr gpu_arch arch_tag = arch_tag_;
+ static constexpr uint32_t barrier_count = 0;
+ static constexpr uint32_t slm_size = mem_desc_c_t::is_local
+ ? tile_shape::wg_tile_size_x * tile_shape::wg_tile_size_y
+ : 0;
+
+ /// @brief Epilogue arguments.
+ struct arguments_t {
+ /// @brief Is tile_op arguments, could be a single
+ /// tile_op argument or chained_tile_op_args.
+ typename tile_op_t::arguments_t tile_op_args;
+
+ /// @brief Constructs a new arguments t object.
+ inline arguments_t() = default;
+
+ /// @brief Constructs a new arguments t object.
+ /// @param tile_op_args_ Is tile_op arguments, could be a single
+ /// tile_op argument or chained_tile_op_args.
+ inline arguments_t(typename tile_op_t::arguments_t tile_op_args_)
+ : tile_op_args(tile_op_args_) {}
+ // Be aware of the risks: Rule of three (copy constructor, copy assignment, destructor)
+ // Please check if you need to add self-define destructor
+ // inline ~arguments_t(){}
+ inline arguments_t(const arguments_t &args)
+ : tile_op_args(args.tile_op_args) {}
+
+ inline arguments_t &operator=(const arguments_t &args) {
+ this->tile_op_args = args.tile_op_args;
+ return *this;
+ }
+
+ /// @brief Explicit initialization function.
+ /// @param tile_op_args_ Is tile_op arguments, could be a single
+ /// tile_op argument or chained_tile_op_args.
+ inline void init(typename tile_op_t::arguments_t tile_op_args_) {
+ tile_op_args = tile_op_args_;
+ }
+ };
+
+private:
+ using work_group_t = typename tile_shape::work_group_t;
+ static constexpr uint32_t sg_tile_m = tile_shape::sg_tile_size_y;
+ static constexpr uint32_t sg_tile_n = tile_shape::sg_tile_size_x;
+ static constexpr uint32_t wg_size_x = tile_shape::wg_size_x;
+ static constexpr uint32_t wg_size_y = tile_shape::wg_size_y;
+ using dtype_c = typename mem_desc_c_t::dtype;
+ static constexpr mem_layout mem_layout_c = mem_desc_c_t::layout;
+ static constexpr mem_space mem_space_c = mem_desc_c_t::space;
+
+ /// @brief Updates tile base descriptor based on the tid.
+ __XETLA_API static void update_sg_tile_tdesc(
+ work_group_t &g, mem_desc_c_t &mem_desc_c) {
+ int32_t sg_idx = g.get_id() % wg_size_x;
+ int32_t sg_idy = g.get_id() / wg_size_x;
+ int32_t tile_offset_n = sg_idx * sg_tile_n;
+ int32_t tile_offset_m = sg_idy * sg_tile_m;
+ mem_desc_c.update_coord(tile_offset_n, tile_offset_m);
+ }
+
+public:
+ static constexpr msg_type msg_type_c
+ = (mem_space_c == mem_space::global ? msg_type::block_2d
+ : msg_type::scatter);
+
+ /// @brief Default epilogue.
+ /// 1) Call tile_op/chained_tile_op 2) Convert dtype_acc to dtype_c
+ /// 3) Overwrite/reduce_sum to memory.
+ /// @tparam matAcc_t Is the type of the input tile.
+ /// @param g Is the workgroup of the current tile.
+ /// @param matAcc Is the input tile.
+ /// @param mem_desc_c Is the memory description of matC, including base, shape and coordinate.
+ /// @param args Is the additional arguments for epilogue.
+ /// @param slm_base Is the slm base address.
+ /// @param nbarrier_base Is the named barrier base.
+ template <typename matAcc_t>
+ __XETLA_API KERNEL_FUNC void operator()(work_group_t &g, matAcc_t &matAcc,
+ mem_desc_c_t mem_desc_c, arguments_t args = {},
+ uint32_t slm_base = 0, uint32_t nbarrier_base = 0) {
+ using mat_tile_desc = typename matAcc_t::tile_desc;
+ using matC_t = subgroup::tile_t<dtype_c, mat_tile_desc>;
+ using matC_payload_t = subgroup::mem_payload_t<mem_desc_c_t,
+ mat_tile_desc, msg_type_c, arch_tag>;
+ update_sg_tile_tdesc(g, mem_desc_c);
+ tile_op_t tile_op;
+ tile_op(matAcc, mem_desc_c.coord, args.tile_op_args, slm_base,
+ nbarrier_base);
+ matC_t matC;
+ matC_payload_t matC_payload(mem_desc_c);
+ subgroup::elemwise_cvt(matC, matAcc);
+ subgroup::tile_store<cache_hint::streaming, cache_hint::write_back>(
+ matC, matC_payload);
+ }
+};
+
+/// @} xetla_epilogue
+
+} // namespace gpu::xetla::group
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/group/gemm/api.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/group/gemm/api.hpp
new file mode 100644
index 00000000000..56fcca4265e
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/group/gemm/api.hpp
@@ -0,0 +1,80 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#include "group/gemm/common.hpp"
+
+namespace gpu::xetla::group {
+
+/// @addtogroup xetla_gemm
+/// @{
+
+/// @brief Gemm default pre_processing functor.
+/// @tparam tile_shape Is the workgroup-level tile shape.
+/// @tparam arch_tag Is the HW architecture.
+template <typename tile_shape, gpu_arch arch_tag, class enable = void>
+struct pre_processing_default_t {};
+
+/// @brief Gemm pre_processing functor with applying relu op to matA.
+/// @tparam tile_shape Is the workgroup-level tile shape.
+/// @tparam arch_tag Is the HW architecture.
+template <typename tile_shape, gpu_arch arch_tag, class enable = void>
+struct pre_processing_matA_neg_filter_t {};
+
+/// @brief Gemm functor.
+/// @tparam compute_policy Is the compute algorithm of gemm implementation.
+/// @tparam tile_shape Is the workgroup-level tile shape.
+/// @tparam mem_desc_a Is the memory descriptor of matA.
+/// @tparam mem_desc_b Is the memory descriptor of matB.
+/// @tparam pre_processing Is the pre_processing functor.
+template <typename compute_policy, typename tile_shape, typename mem_desc_a,
+ typename mem_desc_b,
+ typename pre_processing
+ = pre_processing_default_t<tile_shape, compute_policy::arch_tag>,
+ typename mem_desc_as = void, typename mem_desc_bs = void,
+ class enable = void>
+class gemm_t {};
+
+/// @brief Gemm selection functor.
+/// @tparam dtype_a Is the memory data type of matA.
+/// @tparam dtype_b Is the memory data type of matB.
+/// @tparam mem_layout_a Is the memory layout of matA.
+/// @tparam mem_layout_b Is the memory layout of matB.
+/// @tparam mem_space_a Is the memory space of matA.
+/// @tparam mem_space_b Is the memory space of matB.
+/// @tparam alignment_a Is the memory alignment of matA.
+/// @tparam alignment_b Is the memory alignment of matB.
+/// @tparam dtype_acc Is the compute data type.
+/// @tparam tile_shape Is the workgroup-level tile shape.
+/// @tparam k_stride Is the accumulate stride along k-dim.
+/// @tparam engine Is the compute engine type.
+/// @tparam arch_tag Is the HW architecture.
+/// @tparam stages Is the prefetch distance.
+/// @tparam sync_freq Is the group sync frequency.
+template <typename dtype_a, typename dtype_b, mem_layout mem_layout_a,
+ mem_layout mem_layout_b, mem_space mem_space_a, mem_space mem_space_b,
+ int alignment_a, int alignment_b, typename dtype_acc,
+ typename tile_shape, int k_stride, mma_engine engine, gpu_arch arch_tag,
+ int stages = 3, int sync_freq = 0, class enable = void>
+class gemm_selector_t {};
+
+/// @} xetla_gemm
+
+} // namespace gpu::xetla::group
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/group/gemm/common.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/group/gemm/common.hpp
new file mode 100644
index 00000000000..505907a55e0
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/group/gemm/common.hpp
@@ -0,0 +1,66 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#include "common/common.hpp"
+#include "subgroup/subgroup.hpp"
+
+namespace gpu::xetla::group {
+
+/// @brief Compute attribute for gemm.
+/// @tparam dtype_a_ Is the memory data type of matA.
+/// @tparam dtype_b_ Is the memory data type of matB.
+/// @tparam dtype_acc_ Is the compute data type.
+template <typename dtype_a_, typename dtype_b_, typename dtype_acc_,
+ typename dtype_aci_ = void, typename dtype_as_ = void,
+ typename dtype_bs_ = void, typename dtype_cs_ = void>
+struct compute_attr_t {
+ using dtype_a = dtype_a_;
+ using dtype_b = dtype_b_;
+ using dtype_acc = dtype_acc_;
+ using dtype_aci = dtype_aci_;
+ using dtype_as = dtype_as_;
+ using dtype_bs = dtype_bs_;
+ using dtype_cs = dtype_cs_;
+};
+
+/// @brief Fine-tune knobs for gemm.
+/// @tparam k_stride_ Is the accumulate stride along k-dim.
+/// @tparam stages_ Is the prefetch distance.
+/// @tparam sync_freq_ Is the group sync frequency.
+template <int k_stride_ = 8, int stages_ = 3, int sync_freq_ = 0>
+struct perf_tuning_knob_t {
+ static constexpr int k_stride = k_stride_;
+ static constexpr int stages = stages_;
+ static constexpr int sync_freq = sync_freq_;
+};
+
+template <typename mem_desc_t_a, typename tile_shape_t,
+ typename perf_tuning_knob_>
+constexpr bool is_slm_trans_a() {
+ return (mem_desc_t_a::layout == mem_layout::col_major)
+ //only for 8bit and 16bit
+ && (sizeof(typename mem_desc_t_a::dtype) <= sizeof(uint16_t)
+ && (tile_shape_t::sg_tile_size_y % 16 == 0)
+ && (perf_tuning_knob_::is_slm_transa)
+ && (tile_shape_t::wg_size_x > 1));
+}
+
+} // namespace gpu::xetla::group
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/group/gemm/compute_policy.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/group/gemm/compute_policy.hpp
new file mode 100644
index 00000000000..297d6eb90a7
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/group/gemm/compute_policy.hpp
@@ -0,0 +1,103 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#include "group/gemm/common.hpp"
+
+namespace gpu::xetla::group {
+
+/// @addtogroup xetla_gemm
+/// @{
+
+/// @brief Compute policy for xmx engine.
+/// @tparam compute_attr_ Is compute-related attributes.
+/// @tparam perf_tuning_knob_ Is performance-related knobs.
+/// @tparam arch_tag_ Is the HW architecture.
+template <typename compute_attr_, typename perf_tuning_knob_,
+ gpu_arch arch_tag_>
+struct compute_policy_default_xmx {};
+
+/// @brief Specialized for Xe architecture.
+template <typename compute_attr_, typename perf_tuning_knob_>
+struct compute_policy_default_xmx<compute_attr_, perf_tuning_knob_,
+ gpu_arch::Xe> {
+ using compute_attr = compute_attr_;
+ using perf_tuning_knob = perf_tuning_knob_;
+ static constexpr int k_stride = perf_tuning_knob::k_stride;
+ static constexpr int stages = perf_tuning_knob::stages;
+ static constexpr int sync_freq = perf_tuning_knob::sync_freq;
+ static constexpr gpu_arch arch_tag = gpu_arch::Xe;
+ using dtype_mma_acc = typename compute_attr::dtype_acc;
+ using dtype_mma_a = typename compute_attr::dtype_a;
+ using dtype_mma_b = typename compute_attr::dtype_b;
+
+ using mma_attr = typename arch_attr_t<arch_tag>::mma_attr;
+
+ static constexpr uint32_t mma_k_in_bytes = mma_attr::mma_k_in_bytes;
+ static constexpr uint32_t mma_n_in_elem = mma_attr::mma_n_in_elem;
+
+ static constexpr uint32_t block_bytes_x_a = mma_k_in_bytes;
+ static constexpr uint32_t block_size_x_a
+ = block_bytes_x_a / sizeof(dtype_mma_a);
+ static constexpr uint32_t block_size_y_a = 16;
+
+ static constexpr uint32_t block_size_x_b = mma_n_in_elem;
+ static constexpr uint32_t block_bytes_y_b = mma_k_in_bytes;
+ static constexpr uint32_t block_size_y_b
+ = block_bytes_y_b / sizeof(dtype_mma_b);
+ static_assert(block_size_x_a == block_size_y_b,
+ "mat_a x need to match with mat_b y");
+};
+
+/// @brief Compute policy for fpu engine.
+/// @tparam compute_attr_ Is compute-related attributes.
+/// @tparam perf_tuning_knob_ Is performance-related knobs.
+/// @tparam arch_tag_ Is the HW architecture.
+template <typename compute_attr_, typename perf_tuning_knob_,
+ gpu_arch arch_tag_>
+struct compute_policy_default_fpu {};
+
+/// @brief Specialized for Xe architecture.
+template <typename compute_attr_, typename perf_tuning_knob_>
+struct compute_policy_default_fpu<compute_attr_, perf_tuning_knob_,
+ gpu_arch::Xe> {
+ using compute_attr = compute_attr_;
+ using perf_tuning_knob = perf_tuning_knob_;
+ static constexpr int k_stride = perf_tuning_knob::k_stride;
+ static constexpr int stages = perf_tuning_knob::stages;
+ static constexpr int sync_freq = perf_tuning_knob::sync_freq;
+ static constexpr gpu_arch arch_tag = gpu_arch::Xe;
+ using dtype_mma_acc = typename compute_attr::dtype_acc;
+ using dtype_mma_a = typename compute_attr::dtype_a;
+ using dtype_mma_b = typename compute_attr::dtype_b;
+
+ static constexpr uint32_t block_bytes_x_a = 32;
+ static constexpr uint32_t block_size_x_a
+ = block_bytes_x_a / sizeof(dtype_mma_a);
+ static constexpr uint32_t block_size_y_a = 16;
+ static constexpr uint32_t block_bytes_x_b = 64;
+ static constexpr uint32_t block_size_x_b
+ = block_bytes_x_b / sizeof(dtype_mma_b);
+ static constexpr uint32_t block_size_y_b = block_size_x_a;
+};
+
+/// @} xetla_gemm
+
+} // namespace gpu::xetla::group
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/group/gemm/gemm.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/group/gemm/gemm.hpp
new file mode 100644
index 00000000000..10a54116427
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/group/gemm/gemm.hpp
@@ -0,0 +1,32 @@
+
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+/// @defgroup xetla_gemm XeTLA GEMM
+/// This is a gemm API to compute matAcc = matA * matB.
+
+#include "group/gemm/api.hpp"
+#include "group/gemm/common.hpp"
+#include "group/gemm/compute_policy.hpp"
+#include "group/gemm/impl/default_xmx_xe.hpp"
+#include "group/gemm/impl/pre_processing_xe.hpp"
+#include "group/gemm/impl/selector_xe.hpp"
+#include "group/tile_shape.hpp"
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/group/gemm/impl/default_xmx_xe.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/group/gemm/impl/default_xmx_xe.hpp
new file mode 100644
index 00000000000..e95442b2c0c
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/group/gemm/impl/default_xmx_xe.hpp
@@ -0,0 +1,370 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#include "group/gemm/api.hpp"
+#include "group/gemm/compute_policy.hpp"
+
+namespace gpu::xetla::group {
+
+/// @addtogroup xetla_gemm
+/// @{
+
+/// @brief Is the gemm functor for Xe architecture and matrix engine.
+template <typename compute_attr_, typename perf_tuning_knob_,
+ typename tile_shape_, typename mem_desc_a_t_, typename mem_desc_b_t_,
+ typename pre_processing_t_, gpu_arch arch_tag_>
+class gemm_t<
+ compute_policy_default_xmx<compute_attr_, perf_tuning_knob_, arch_tag_>,
+ tile_shape_, // tile shape of workgroup-level gemm
+ mem_desc_a_t_, // memory attribute of matA
+ mem_desc_b_t_, // memory attribute of matB
+ pre_processing_t_, // pre_processing functor
+ std::enable_if_t<(arch_tag_ == gpu_arch::Xe)>> {
+public:
+ using mem_desc_a_t = mem_desc_a_t_;
+ using mem_desc_b_t = mem_desc_b_t_;
+ using tile_shape = tile_shape_;
+ using pre_processing_t = pre_processing_t_;
+ using compute_policy = compute_policy_default_xmx<compute_attr_,
+ perf_tuning_knob_, arch_tag_>;
+ static constexpr uint32_t k_stride = compute_policy::k_stride;
+ static constexpr uint32_t sg_tile_m = tile_shape::sg_tile_size_y;
+ static constexpr uint32_t sg_tile_n = tile_shape::sg_tile_size_x;
+ static constexpr uint32_t wg_size_x = tile_shape::wg_size_x;
+ static constexpr uint32_t wg_size_y = tile_shape::wg_size_y;
+ using work_group_t = typename tile_shape::work_group_t;
+
+ constexpr static gpu_arch arch_tag = compute_policy::arch_tag;
+
+ static constexpr mem_layout mem_layout_a = mem_desc_a_t::layout;
+ static constexpr mem_layout mem_layout_b = mem_desc_b_t::layout;
+ static constexpr bool is_col_major_a
+ = mem_layout_a == mem_layout::col_major;
+ static constexpr bool is_col_major_b
+ = mem_layout_b == mem_layout::col_major;
+
+private:
+ /******** set data type **********/
+ using dtype_a = typename mem_desc_a_t::dtype;
+ using dtype_b = typename mem_desc_b_t::dtype;
+ using dtype_mma_acc = typename compute_policy::dtype_mma_acc;
+ using dtype_mma_a = typename compute_policy::dtype_mma_a;
+ using dtype_mma_b = typename compute_policy::dtype_mma_b;
+
+ using check_dtype
+ = group::gemm<gpu_arch::Xe>::default_xmx::check_dtype_default<
+ dtype_a, dtype_b, dtype_mma_a, dtype_mma_b>;
+
+ /******** set memory attribute **********/
+ static constexpr mem_space mem_space_a = mem_desc_a_t::space;
+ static constexpr mem_space mem_space_b = mem_desc_b_t::space;
+
+ static constexpr bool is_local_a = mem_space_a == mem_space::local;
+ static constexpr bool is_local_b = mem_space_b == mem_space::local;
+ static constexpr tdesc_update_dir update_dir_a = is_col_major_a
+ ? tdesc_update_dir::y_dir
+ : tdesc_update_dir::x_dir;
+ static constexpr tdesc_update_dir update_dir_b = is_col_major_b
+ ? tdesc_update_dir::x_dir
+ : tdesc_update_dir::y_dir;
+
+ using check_memory
+ = group::gemm<gpu_arch::Xe>::default_xmx::check_memory_default<
+ mem_layout_a, mem_layout_b, mem_space_a, mem_space_b>;
+
+ static constexpr uint32_t stages = compute_policy::stages;
+ static constexpr uint32_t sync_freq = compute_policy::sync_freq;
+
+ /******** set tile layout && worker scope **********/
+ static constexpr uint32_t tile_size_x_a = k_stride;
+ static constexpr uint32_t tile_size_y_a = sg_tile_m;
+ static constexpr uint32_t tile_size_x_b = sg_tile_n;
+ static constexpr uint32_t tile_size_y_b = k_stride;
+ static constexpr uint32_t tile_size_x_c = sg_tile_n;
+ static constexpr uint32_t tile_size_y_c = sg_tile_m;
+ static constexpr uint32_t block_size_x_a = compute_policy::block_size_x_a;
+ static constexpr uint32_t block_size_y_a
+ = (compute_policy::block_size_y_a > tile_size_y_a)
+ ? tile_size_y_a
+ : compute_policy::block_size_y_a;
+ static constexpr uint32_t block_size_x_b = compute_policy::block_size_x_b;
+ static constexpr uint32_t block_size_y_b = compute_policy::block_size_y_b;
+
+ using check_tile_size = group::gemm<
+ gpu_arch::Xe>::default_xmx::check_tile_size_default<dtype_mma_a,
+ tile_size_x_a, tile_size_y_a, block_size_x_a, block_size_y_a,
+ tile_size_x_b, tile_size_y_b, block_size_x_b, block_size_y_b>;
+
+ /******** set tile **********/
+ static constexpr reg_layout reg_layout_a = reg_layout::tiled;
+ using matA_tile_desc_t = subgroup::tile_desc_t<tile_size_x_a, tile_size_y_a,
+ block_size_x_a, block_size_y_a, reg_layout_a>;
+ using matA_t = subgroup::tile_t<dtype_a, matA_tile_desc_t>;
+ using matA_payload_t = subgroup::mem_payload_t<mem_desc_a_t,
+ matA_tile_desc_t,
+ is_local_a ? msg_type::scatter : msg_type::block_2d, arch_tag>;
+ using matA_acc_t = subgroup::tile_t<dtype_mma_a, matA_tile_desc_t>;
+ using matA_prefetch_payload_t = subgroup::prefetch_payload_t<mem_desc_a_t,
+ subgroup::tile_desc_t<tile_size_x_a, tile_size_y_a, 1, 1>,
+ wg_size_x, arch_tag>;
+ static constexpr reg_layout reg_layout_b
+ = sizeof(dtype_b) < sizeof(uint32_t) ? reg_layout::vnni_tiled
+ : reg_layout::tiled;
+ using matB_tile_desc_t = subgroup::tile_desc_t<tile_size_x_b, tile_size_y_b,
+ block_size_x_b, block_size_y_b, reg_layout_b>;
+ using matB_t = subgroup::tile_t<dtype_b, matB_tile_desc_t>;
+ using matB_payload_t = subgroup::mem_payload_t<mem_desc_b_t,
+ matB_tile_desc_t,
+ is_local_b ? msg_type::scatter : msg_type::block_2d, arch_tag>;
+ using matB_acc_t = subgroup::tile_t<dtype_mma_b, matB_tile_desc_t>;
+ using matB_prefetch_payload_t = subgroup::prefetch_payload_t<mem_desc_b_t,
+ subgroup::tile_desc_t<tile_size_x_b, tile_size_y_b, 1, 1>,
+ wg_size_y, arch_tag>;
+
+public:
+ using matAcc_tile_desc_t = subgroup::tile_desc_t<tile_size_x_c,
+ tile_size_y_c, block_size_x_b, block_size_y_a, reg_layout::tiled>;
+ using matAcc_t = subgroup::tile_t<dtype_mma_acc, matAcc_tile_desc_t>;
+
+private:
+ using tile_mma = subgroup::tile_mma_t<matAcc_t, matAcc_t, matB_acc_t,
+ matA_acc_t, mma_engine::xmx, arch_tag>;
+ static constexpr bool enable_periodic_sync = (sync_freq != 0);
+ static constexpr uint32_t barrier_count_x = wg_size_y > 1 ? wg_size_x : 0;
+ static constexpr uint32_t barrier_count_y = wg_size_x > 1 ? wg_size_y : 0;
+
+public:
+ static constexpr uint32_t barrier_count
+ = enable_periodic_sync ? barrier_count_x + barrier_count_y : 0;
+
+ static constexpr uint32_t slm_size = 0;
+
+ static constexpr msg_type msg_type_a = matA_payload_t::message_type;
+ static constexpr msg_type msg_type_b = matB_payload_t::message_type;
+
+ using pre_processing_arg_t = typename pre_processing_t::arguments_t;
+
+ /// @brief Arguments for gemm.
+ /// User should prepare matA_base_desc, matB_base_desc, inner_loop_count...
+ struct arguments_t {
+ /// @brief Is the memory description of matA, including base, shape and coordinate.
+ mem_desc_a_t matA_base_desc;
+ /// @brief Is the memory description of matB, including base, shape and coordinate.
+ mem_desc_b_t matB_base_desc;
+ /// @brief Is the total inner loop count required to compute the entire K-dim.
+ uint32_t inner_loop_count;
+ /// @brief Is the arguments for pre-processing functor.
+ pre_processing_arg_t pre_processing_args;
+
+ /// @brief Default construct.
+ inline arguments_t() = default;
+
+ /// @brief Constructs a new arguments t object.
+ /// @param matA_desc Is the memory description of matA, including base, shape and coordinate.
+ /// @param matB_desc Is the memory description of matB, including base, shape and coordinate.
+ /// @param loop_count Is the total inner loop count required to compute the entire K-dim.
+ /// @param args Is the arguments for pre-processing functor.
+ inline arguments_t(mem_desc_a_t matA_desc, mem_desc_b_t matB_desc,
+ uint32_t loop_count, pre_processing_arg_t args = {})
+ : matA_base_desc(matA_desc)
+ , matB_base_desc(matB_desc)
+ , inner_loop_count(loop_count)
+ , pre_processing_args(args) {}
+ // Be aware of the risks: Rule of three (copy constructor, copy assignment, destructor)
+ // Please check if you need to add self-define destructor
+ // inline ~arguments_t(){}
+ inline arguments_t(const arguments_t &args)
+ : matA_base_desc(args.matA_base_desc)
+ , matB_base_desc(args.matB_base_desc)
+ , inner_loop_count(args.inner_loop_count)
+ , pre_processing_args(args.pre_processing_args) {}
+ inline arguments_t &operator=(const arguments_t &args) {
+ this->matA_base_desc = args.matA_base_desc;
+ this->matB_base_desc = args.matB_base_desc;
+ this->inner_loop_count = args.inner_loop_count;
+ this->pre_processing_args = args.pre_processing_args;
+ return *this;
+ }
+
+ /// @brief Explicit initialization function.
+ /// @param matA_desc Is the memory description of matA, including base, shape and coordinate.
+ /// @param matB_desc Is the memory description of matB, including base, shape and coordinate.
+ /// @param loop_count Is the total inner loop count required to compute the entire K-dim.
+ /// @param args Is the arguments for pre-processing functor.
+ inline void init(mem_desc_a_t matA_desc, mem_desc_b_t matB_desc,
+ uint32_t loop_count, pre_processing_arg_t args = {}) {
+ matA_base_desc = matA_desc;
+ matB_base_desc = matB_desc;
+ inner_loop_count = loop_count;
+ pre_processing_args = args;
+ }
+ };
+
+ /// @brief Gets the subgroup-level tile offset x.
+ /// @param g Is the workgroup of the current tile.
+ /// @return Subgroup-level tile offset x.
+ __XETLA_API static int get_matC_offset_x(work_group_t &g) {
+ int32_t sg_idx = g.get_id() % wg_size_x;
+ return sg_idx * sg_tile_n;
+ }
+
+ /// @brief Gets the subgroup-level tile offset y.
+ /// @param g Is the workgroup of the current tile.
+ /// @return Subgroup-level tile offset y.
+ __XETLA_API static int get_matC_offset_y(work_group_t &g) {
+ int32_t sg_idy = g.get_id() / wg_size_x;
+ return sg_idy * sg_tile_m;
+ }
+
+ XETLA_MARKER(
+ "This release function will wait until all the r/w and nbarrier "
+ "id used in this gemm have been committed. By default, it will "
+ "use barrier_id 0 to do the entire workgroup sync if wg_size > 1. "
+ "If you call this function, please set a free barrier id or make "
+ "sure barrier_id 0 is not being occupied and you need to allocate "
+ "one more barrier count in addition to the gemm barrier counts.")
+ __XETLA_API static void release(uint8_t nbarrier_id = 0) {
+ static constexpr bool need_local_fence
+ = (mem_space_a == mem_space::local)
+ || (mem_space_b == mem_space::local);
+ if constexpr (need_local_fence) {
+ xetla_fence<memory_kind::shared_local>();
+ }
+ xetla_fence<memory_kind::untyped_global>();
+ static constexpr uint32_t wg_size = wg_size_x * wg_size_y;
+ if constexpr (wg_size > 1) {
+ xetla_nbarrier_t<wg_size, wg_size, arch_tag> nbarrier;
+ nbarrier.init_nbarrier(
+ nbarrier_id, nbarrier_role::producer_consumer);
+ nbarrier.arrive_wait();
+ }
+ }
+
+ /// @brief Main execution function for gemm.
+ /// The basic process is load data -> matrix multiply.
+ /// @param g Is the workgroup of the current tile.
+ /// @param matAcc Is the reference of the accumulation buffer.
+ /// @param args Is the gemm::arguments_t.
+ /// @param slm_base Is the slm base address.
+ /// @param nbarrier_base Is the named barrier base.
+ __XETLA_API KERNEL_FUNC void operator()(work_group_t &g, matAcc_t &matAcc,
+ arguments_t args, uint32_t slm_base = 0,
+ uint32_t nbarrier_base = 0) {
+ int32_t sg_idx = g.get_id() % wg_size_x;
+ int32_t sg_idy = g.get_id() / wg_size_x;
+
+ XETLA_ASSERT(g.get_id() < (wg_size_x * wg_size_y),
+ "Thread id(%d) should less than wg_size(%d)", g.get_id(),
+ wg_size_x * wg_size_y);
+
+ update_sg_tile_tdesc(args, sg_idx, sg_idy);
+ pre_processing_t pre_processing;
+ matA_t matA;
+ matB_t matB;
+ // >>>>>>>>>>>>>>>>>> pre_processing init
+ pre_processing.init(g, args.pre_processing_args);
+ matA_payload_t matA_payload(args.matA_base_desc);
+ matB_payload_t matB_payload(args.matB_base_desc);
+ matA_prefetch_payload_t matA_prefetch_payload(
+ args.matA_base_desc, sg_idx);
+ matB_prefetch_payload_t matB_prefetch_payload(
+ args.matB_base_desc, sg_idy);
+ xetla_nbarrier_t<wg_size_x, wg_size_x, arch_tag> nbarrier_a;
+ nbarrier_a.init_nbarrier(
+ sg_idy + nbarrier_base, nbarrier_role::producer_consumer);
+ xetla_nbarrier_t<wg_size_y, wg_size_y, arch_tag> nbarrier_b;
+ nbarrier_b.init_nbarrier(sg_idx + barrier_count_y + nbarrier_base,
+ nbarrier_role::producer_consumer);
+
+#pragma unroll
+ for (int i = 0; i < stages; i++) {
+ subgroup::tile_prefetch<cache_hint::cached, cache_hint::cached>(
+ matA_prefetch_payload);
+ subgroup::tile_prefetch<cache_hint::cached, cache_hint::cached>(
+ matB_prefetch_payload);
+ matA_prefetch_payload.template update_tdesc<update_dir_a>(
+ matA_t::tile_size_x);
+ matB_prefetch_payload.template update_tdesc<update_dir_b>(
+ matB_t::tile_size_y);
+ }
+
+ for (int i = 0; i < args.inner_loop_count; i++) {
+ if constexpr (enable_periodic_sync) {
+ if ((i % sync_freq) == 0) {
+ if constexpr (wg_size_x > 1) { nbarrier_a.arrive(); }
+ if constexpr (wg_size_y > 1) { nbarrier_b.arrive(); }
+ }
+ }
+ subgroup::tile_load<cache_hint::cached, cache_hint::cached>(
+ matB, matB_payload);
+ subgroup::tile_load<cache_hint::cached, cache_hint::cached>(
+ matA, matA_payload);
+ if constexpr (stages != 0) {
+ subgroup::tile_prefetch<cache_hint::cached, cache_hint::cached>(
+ matA_prefetch_payload);
+ subgroup::tile_prefetch<cache_hint::cached, cache_hint::cached>(
+ matB_prefetch_payload);
+ }
+ SW_BARRIER();
+ matA_payload.template update_tdesc<update_dir_a>(
+ matA_t::tile_size_x);
+ matB_payload.template update_tdesc<update_dir_b>(
+ matB_t::tile_size_y);
+ if constexpr (stages != 0) {
+ matA_prefetch_payload.template update_tdesc<update_dir_a>(
+ matA_t::tile_size_x);
+ matB_prefetch_payload.template update_tdesc<update_dir_b>(
+ matB_t::tile_size_y);
+ }
+ SW_BARRIER();
+ matA_acc_t matA_acc;
+ matB_acc_t matB_acc;
+ subgroup::elemwise_cvt(matA_acc, matA);
+ subgroup::vnni_transform(matB_acc, matB);
+ pre_processing(matA_acc, matB_acc, matA, matB);
+ SW_BARRIER();
+ tile_mma::mma(matAcc, matAcc, matB_acc, matA_acc);
+ SW_BARRIER();
+ if constexpr (enable_periodic_sync) {
+ if ((i % sync_freq) == 0) {
+ if constexpr (wg_size_x > 1) { nbarrier_a.wait(); }
+ if constexpr (wg_size_y > 1) { nbarrier_b.wait(); }
+ }
+ }
+ }
+ SW_BARRIER();
+ }
+
+private:
+ /// @brief Updates tile base descriptor based on the tid.
+ __XETLA_API static void update_sg_tile_tdesc(
+ arguments_t &args, int32_t sg_idx, int32_t sg_idy) {
+ int32_t tile_offset_n = sg_idx * sg_tile_n;
+ int32_t tile_offset_m = sg_idy * sg_tile_m;
+
+ args.matA_base_desc.update_coord_y(tile_offset_m);
+ args.matB_base_desc.update_coord_x(tile_offset_n);
+ }
+};
+
+/// @} xetla_gemm
+
+} // namespace gpu::xetla::group
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/group/gemm/impl/pre_processing_xe.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/group/gemm/impl/pre_processing_xe.hpp
new file mode 100644
index 00000000000..9a871cbad11
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/group/gemm/impl/pre_processing_xe.hpp
@@ -0,0 +1,54 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#include "group/gemm/api.hpp"
+#include "group/gemm/common.hpp"
+
+namespace gpu::xetla::group {
+
+/// @addtogroup xetla_gemm
+/// @{
+
+/// @brief gemm default pre_processing functor. Specialized for Xe architecture.
+template <typename tile_shape_, gpu_arch arch_tag>
+class pre_processing_default_t<tile_shape_, arch_tag,
+ std::enable_if_t<(arch_tag == gpu_arch::Xe)>> {
+ using tile_shape = tile_shape_;
+ using work_group_t = typename tile_shape::work_group_t;
+
+public:
+ struct arguments_t {};
+
+ inline pre_processing_default_t() = default;
+
+ inline pre_processing_default_t(work_group_t &g, arguments_t &args) {}
+
+ inline void init(work_group_t &g, arguments_t &args) {}
+
+ template <typename matA_acc_t, typename matB_acc_t, typename matA_t,
+ typename matB_t>
+ inline KERNEL_FUNC void operator()(matA_acc_t &matA_acc,
+ matB_acc_t &matB_acc, matA_t &matA, matB_t &matB) {}
+};
+
+/// @} xetla_gemm
+
+} // namespace gpu::xetla::group
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/group/gemm/impl/selector_xe.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/group/gemm/impl/selector_xe.hpp
new file mode 100644
index 00000000000..0548386ab96
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/group/gemm/impl/selector_xe.hpp
@@ -0,0 +1,74 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#include "group/gemm/api.hpp"
+#include "group/gemm/compute_policy.hpp"
+
+namespace gpu::xetla::group {
+namespace detail {
+
+template <typename dtype_a, typename dtype_b, int alignment_a, int alignment_b,
+ gpu_arch arch_tag>
+class check_2d_block_pitch_alignment {
+ using load_store_attr = typename arch_attr_t<
+ arch_tag>::template load_store_attr<msg_type::block_2d>;
+ static constexpr int alignment_bytes = load_store_attr::alignment_in_bytes;
+ static constexpr int alignment_bytes_a = alignment_a * sizeof(dtype_a);
+ static constexpr int alignment_bytes_b = alignment_b * sizeof(dtype_b);
+
+public:
+ static constexpr bool value = (alignment_bytes_a % alignment_bytes == 0)
+ && (alignment_bytes_b % alignment_bytes == 0);
+};
+
+} // namespace detail
+
+/// @addtogroup xetla_gemm
+/// @{
+
+/// @brief Selects 2d block && xmx based gemm.
+template <typename dtype_a, typename dtype_b, mem_layout mem_layout_a,
+ mem_layout mem_layout_b, mem_space mem_space_a, mem_space mem_space_b,
+ int alignment_a, int alignment_b, typename dtype_acc,
+ typename tile_shape, int k_stride, gpu_arch arch_tag, int stages,
+ int sync_freq>
+class gemm_selector_t<dtype_a, dtype_b, mem_layout_a, mem_layout_b, mem_space_a,
+ mem_space_b, alignment_a, alignment_b, dtype_acc, tile_shape, k_stride,
+ mma_engine::xmx, arch_tag, stages, sync_freq,
+ std::enable_if_t<detail::check_2d_block_pitch_alignment<dtype_a,
+ dtype_b, alignment_a, alignment_b, arch_tag>::value>> {
+ using mem_desc_a
+ = mem_desc_t<dtype_a, mem_layout_a, mem_space_a, alignment_a>;
+ using mem_desc_b
+ = mem_desc_t<dtype_b, mem_layout_b, mem_space_b, alignment_b>;
+ using compute_attr = compute_attr_t<dtype_a, dtype_b, dtype_acc>;
+ using perf_tuning_knob = perf_tuning_knob_t<k_stride, stages, sync_freq>;
+ using compute_policy = compute_policy_default_xmx<compute_attr,
+ perf_tuning_knob, arch_tag>;
+ using pre_processing = pre_processing_default_t<tile_shape, arch_tag>;
+
+public:
+ using gemm = gemm_t<compute_policy, tile_shape, mem_desc_a, mem_desc_b,
+ pre_processing>;
+};
+
+/// @} xetla_gemm
+} // namespace gpu::xetla::group
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/group/global_reduction.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/group/global_reduction.hpp
new file mode 100644
index 00000000000..2f93c4b40c8
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/group/global_reduction.hpp
@@ -0,0 +1,460 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#include "group/tile_shape.hpp"
+#include "subgroup/subgroup.hpp"
+
+namespace gpu::xetla::group {
+
+/// @brief Cross group global reduction.
+/// @tparam reduce_kind Is the reduction type.
+/// @tparam tile_shape_acc Is the group-level tile shape for accumulation tile.
+/// @tparam tile_shape_cnt Is the group-level tile shape for counter tile.
+/// @tparam mem_desc_acc_t Is the memory descriptor of accumulation buffer.
+/// @tparam mem_desc_cnt_t Is the memory descriptor of counter buffer.
+/// @tparam num_group_reduction Is the number of workgroups to do the reduction.
+/// @tparam counter_size Is the stride to the next counter.
+/// @tparam arch_tag Is the HW architecture.
+template <reduce_op reduce_kind, typename tile_shape_acc,
+ typename tile_shape_cnt, typename mem_desc_acc_t,
+ typename mem_desc_cnt_t, uint32_t num_group_reduction,
+ uint32_t counter_size, gpu_arch arch_tag, class enable = void>
+class global_reduce_t {};
+
+/// @brief Cross group global reduction. Specialized for reduce_op::sum and Xe architecture.
+template <typename tile_shape_acc_, typename tile_shape_cnt_,
+ typename mem_desc_acc_t_, typename mem_desc_cnt_t_,
+ uint32_t num_group_reduction, uint32_t counter_size, gpu_arch arch_tag_>
+class global_reduce_t<reduce_op::sum, tile_shape_acc_, tile_shape_cnt_,
+ mem_desc_acc_t_, mem_desc_cnt_t_, num_group_reduction, counter_size,
+ arch_tag_,
+ std::enable_if_t<((arch_tag_ == gpu_arch::Xe))
+ && (tile_shape_acc_::dim == 2)>> {
+public:
+ static constexpr gpu_arch arch_tag = arch_tag_;
+ using tile_shape_acc = tile_shape_acc_;
+ using tile_shape_cnt = tile_shape_cnt_;
+ using mem_desc_acc_t = mem_desc_acc_t_;
+ using mem_desc_cnt_t = mem_desc_cnt_t_;
+ using dtype_acc = typename mem_desc_acc_t::dtype;
+ using dtype_cnt = typename mem_desc_cnt_t::dtype;
+
+private:
+ static constexpr uint32_t acc_sg_tile_y = tile_shape_acc::sg_tile_size_y;
+ static constexpr uint32_t acc_sg_tile_x = tile_shape_acc::sg_tile_size_x;
+ static constexpr uint32_t cnt_sg_tile_y = tile_shape_cnt::sg_tile_size_y;
+ static constexpr uint32_t cnt_sg_tile_x = tile_shape_cnt::sg_tile_size_x;
+ static constexpr uint32_t wg_size_x = tile_shape_acc::wg_size_x;
+ static constexpr uint32_t wg_size_y = tile_shape_acc::wg_size_y;
+ static_assert((tile_shape_acc::wg_size_x == tile_shape_cnt::wg_size_x)
+ && (tile_shape_acc::wg_size_y == tile_shape_cnt::wg_size_y),
+ "acc and cnt wg shape need to be matched");
+ using work_group_t = typename tile_shape_acc::work_group_t;
+
+ /// @brief Updates tile base descriptor based on the tid.
+ inline void update_sg_tile_tdesc(work_group_t &g,
+ mem_desc_acc_t &mem_desc_acc, mem_desc_cnt_t &mem_desc_cnt) {
+ int32_t sg_idx = g.get_id() % wg_size_x;
+ int32_t sg_idy = g.get_id() / wg_size_x;
+ int32_t acc_tile_offset_x = sg_idx * acc_sg_tile_x;
+ int32_t acc_tile_offset_y = sg_idy * acc_sg_tile_y;
+ mem_desc_acc.update_coord(acc_tile_offset_x, acc_tile_offset_y);
+ int32_t cnt_tile_offset_x = sg_idx * cnt_sg_tile_x;
+ int32_t cnt_tile_offset_y = sg_idy * cnt_sg_tile_y;
+ mem_desc_cnt.update_coord(cnt_tile_offset_x, cnt_tile_offset_y);
+ }
+
+ inline uint32_t update_reduce_counter(mem_desc_cnt_t &mem_desc_cnt) {
+ constexpr uint32_t SIMD = 16;
+ uint32_t pitch_in_bytes = mem_desc_cnt.shape.stride_x
+ * sizeof(dtype_cnt) * counter_size;
+ uint32_t offset_x = mem_desc_cnt.coord.x;
+ uint32_t offset_y = mem_desc_cnt.coord.y;
+ uint64_t address = (uint64_t)mem_desc_cnt.base.base
+ + offset_y * pitch_in_bytes
+ + offset_x * sizeof(dtype_cnt) * counter_size;
+ xetla_vector<uint32_t, SIMD> offsets
+ = xetla_vector_gen<uint32_t, SIMD>(0, 1);
+ offsets *= sizeof(dtype_cnt);
+ xetla_mask<SIMD> pred(0);
+ pred[0] = 1;
+ xetla_vector<dtype_cnt, SIMD> ret = xetla_atomic_global<atomic_op::iinc,
+ dtype_cnt, SIMD, data_size::default_size, cache_hint::uncached,
+ cache_hint::write_back>((dtype_cnt *)address, offsets, pred);
+ return ret[0];
+ }
+
+ inline void clean_reduce_counter(mem_desc_cnt_t &mem_desc_cnt) {
+ uint32_t pitch_in_bytes = mem_desc_cnt.shape.stride_x
+ * sizeof(dtype_cnt) * counter_size;
+ uint32_t offset_x = mem_desc_cnt.coord.x;
+ uint32_t offset_y = mem_desc_cnt.coord.y;
+ uint64_t address = (uint64_t)mem_desc_cnt.base.base
+ + offset_y * pitch_in_bytes
+ + offset_x * sizeof(dtype_cnt) * counter_size;
+ xetla_vector<dtype_cnt, 1> zeros(0);
+
+ xetla_store_global<dtype_cnt, 1, data_size::default_size,
+ cache_hint::uncached, cache_hint::write_back>(
+ (dtype_cnt *)address, 0, zeros);
+ }
+
+public:
+ static constexpr uint32_t barrier_count = 0;
+ static constexpr uint32_t slm_size = 0;
+ uint32_t reduce_id = 0;
+
+ inline bool is_last_group() {
+ return reduce_id == (num_group_reduction - 1);
+ }
+
+ /// @brief Global reduction.
+ /// 1) each group stores tile data to global memory by using global atomic add ->
+ /// 2) after reduction complete, update the counter by using atomic inc ->
+ /// 3) the last group load the data back to EU, and clean the accumulation buffer and counter buffer.
+ /// @note only the last group has the valid data.
+ /// @param g Is the workgroup of the current tile.
+ /// @param matAcc Is the input of the reduction.
+ /// @param mem_desc_acc Is the memory descriptor of accumulation buffer.
+ /// @param mem_desc_cnt Is the memory descriptor of counter buffer.
+ /// @param slm_base Is the slm base address.
+ /// @param nbarrier_base Is the named barrier base.
+ template <typename matAcc_t>
+ __XETLA_API KERNEL_FUNC void operator()(work_group_t &g, matAcc_t &matAcc,
+ mem_desc_acc_t mem_desc_acc, mem_desc_cnt_t mem_desc_cnt,
+ uint32_t slm_base = 0, uint32_t nbarrier_base = 0) {
+ static_assert(std::is_same<typename matAcc_t::dtype, dtype_acc>::value,
+ "matAcc_t::dtype should match with dtype_acc");
+ update_sg_tile_tdesc(g, mem_desc_acc, mem_desc_cnt);
+ using matAcc_tile_desc_t = typename matAcc_t::tile_desc;
+ using matAcc_store_payload_t = subgroup::mem_payload_t<mem_desc_acc_t,
+ matAcc_tile_desc_t, msg_type::atomic_add, arch_tag>;
+ matAcc_store_payload_t matAcc_store_payload(mem_desc_acc);
+ subgroup::tile_store<cache_hint::uncached, cache_hint::write_back>(
+ matAcc, matAcc_store_payload);
+ xetla_fence<memory_kind::untyped_global, fence_op::none,
+ fence_scope::tile>();
+ reduce_id = update_reduce_counter(mem_desc_cnt);
+ if (reduce_id == (num_group_reduction - 1)) {
+ using matAcc_payload_t = subgroup::mem_payload_t<mem_desc_acc_t,
+ matAcc_tile_desc_t, msg_type::block_2d, arch_tag>;
+ matAcc_payload_t matAcc_payload(mem_desc_acc);
+ subgroup::tile_load(matAcc, matAcc_payload);
+ clean_reduce_counter(mem_desc_cnt);
+ using mat_zero_t = subgroup::tile_t<dtype_acc, matAcc_tile_desc_t>;
+ mat_zero_t mat_zero;
+ mat_zero.reg = 0;
+ subgroup::tile_store<cache_hint::uncached, cache_hint::write_back>(
+ mat_zero, matAcc_payload);
+ SW_BARRIER();
+ }
+ }
+};
+
+/// @brief Cross group global reduction. Specialized for num_group_reduction=1 and Xe architecture.
+template <typename tile_shape_acc_, typename tile_shape_cnt_,
+ typename mem_desc_acc_t_, typename mem_desc_cnt_t_,
+ uint32_t counter_size_, gpu_arch arch_tag_>
+class global_reduce_t<reduce_op::sum, tile_shape_acc_, tile_shape_cnt_,
+ mem_desc_acc_t_, mem_desc_cnt_t_, 1, counter_size_, arch_tag_,
+ std::enable_if_t<((arch_tag_ == gpu_arch::Xe))
+ && (tile_shape_acc_::dim == 2)>> {
+public:
+ static constexpr gpu_arch arch_tag = arch_tag_;
+ using tile_shape_acc = tile_shape_acc_;
+ using tile_shape_cnt = tile_shape_cnt_;
+ using mem_desc_acc_t = mem_desc_acc_t_;
+ using mem_desc_cnt_t = mem_desc_cnt_t_;
+ using dtype_acc = typename mem_desc_acc_t::dtype;
+
+private:
+ using work_group_t = typename tile_shape_acc::work_group_t;
+
+public:
+ static constexpr uint32_t barrier_count = 0;
+ static constexpr uint32_t slm_size = 0;
+ inline bool is_last_group() { return true; }
+
+ template <typename matAcc_t>
+ inline KERNEL_FUNC void operator()(work_group_t &g, matAcc_t &matAcc,
+ mem_desc_acc_t mem_desc_acc, mem_desc_cnt_t mem_desc_cnt,
+ uint32_t slm_base = 0, uint32_t nbarrier_base = 0) {}
+};
+
+/// @brief Cross group global reduction. Specialized for reduce_op::sum and 4 dimensional tiles
+template <typename tile_shape_acc_, typename tile_shape_cnt_,
+ typename mem_desc_acc_t_, typename mem_desc_cnt_t_,
+ uint32_t num_group_reduction, uint32_t counter_size, gpu_arch arch_tag_>
+class global_reduce_t<reduce_op::sum, tile_shape_acc_, tile_shape_cnt_,
+ mem_desc_acc_t_, mem_desc_cnt_t_, num_group_reduction, counter_size,
+ arch_tag_,
+ std::enable_if_t<((arch_tag_ == gpu_arch::Xe))
+ && (tile_shape_acc_::dim == 4)>> {
+public:
+ static constexpr gpu_arch arch_tag = arch_tag_;
+ using tile_shape_acc = tile_shape_acc_;
+ using tile_shape_cnt = tile_shape_cnt_;
+ using mem_desc_acc_t = mem_desc_acc_t_;
+ using mem_desc_cnt_t = mem_desc_cnt_t_;
+ using dtype_acc = typename mem_desc_acc_t::dtype;
+ using dtype_cnt = typename mem_desc_cnt_t::dtype;
+
+private:
+ static constexpr uint32_t acc_sg_tile_n = tile_shape_acc::sg_tile_size_n;
+ static constexpr uint32_t acc_sg_tile_p = tile_shape_acc::sg_tile_size_p;
+ static constexpr uint32_t acc_sg_tile_q = tile_shape_acc::sg_tile_size_q;
+ static constexpr uint32_t acc_sg_tile_k = tile_shape_acc::sg_tile_size_k;
+
+ static constexpr uint32_t wg_size_n = tile_shape_acc::wg_size_n;
+ static constexpr uint32_t wg_size_p = tile_shape_acc::wg_size_p;
+ static constexpr uint32_t wg_size_q = tile_shape_acc::wg_size_q;
+ static constexpr uint32_t wg_size_k = tile_shape_acc::wg_size_k;
+
+ static constexpr uint32_t cnt_sg_tile_n = tile_shape_cnt::sg_tile_size_n;
+ static constexpr uint32_t cnt_sg_tile_p = tile_shape_cnt::sg_tile_size_p;
+ static constexpr uint32_t cnt_sg_tile_q = tile_shape_cnt::sg_tile_size_q;
+ static constexpr uint32_t cnt_sg_tile_k = tile_shape_cnt::sg_tile_size_k;
+
+ static_assert((tile_shape_acc::wg_size_n == tile_shape_cnt::wg_size_n),
+ "acc and cnt wg_szie_n shape need to be matched");
+ static_assert((tile_shape_acc::wg_size_p == tile_shape_cnt::wg_size_p),
+ "acc and cnt wg_szie_n shape need to be matched");
+ static_assert((tile_shape_acc::wg_size_q == tile_shape_cnt::wg_size_q),
+ "acc and cnt wg_szie_n shape need to be matched");
+ static_assert((tile_shape_acc::wg_size_k == tile_shape_cnt::wg_size_k),
+ "acc and cnt wg_szie_n shape need to be matched");
+
+ static_assert((tile_shape_acc::wg_size_n == tile_shape_cnt::wg_size_n)
+ && (tile_shape_acc::wg_size_p == tile_shape_cnt::wg_size_p)
+ && (tile_shape_acc::wg_size_q == tile_shape_cnt::wg_size_q)
+ && (tile_shape_acc::wg_size_k == tile_shape_cnt::wg_size_k),
+ "acc and cnt wg shape need to be matched");
+ using work_group_t = typename tile_shape_acc::work_group_t;
+
+ /// @brief Updates tile base descriptor based on the tid.
+ inline void update_sg_tile_tdesc(work_group_t &g,
+ mem_desc_acc_t &mem_desc_acc, mem_desc_cnt_t &mem_desc_cnt) {
+ int32_t sg_idk = g.get_id() % wg_size_k;
+ int32_t sg_idq = (g.get_id() / wg_size_k) % wg_size_q;
+ int32_t sg_idp = (g.get_id() / (wg_size_k * wg_size_q)) % wg_size_p;
+ int32_t sg_idn = (g.get_id() / (wg_size_k * wg_size_q * wg_size_p))
+ % wg_size_n;
+
+ int32_t acc_tile_offset_n = sg_idn * acc_sg_tile_n;
+ int32_t acc_tile_offset_p = sg_idp * acc_sg_tile_p;
+ int32_t acc_tile_offset_q = sg_idq * acc_sg_tile_q;
+ int32_t acc_tile_offset_k = sg_idk * acc_sg_tile_k;
+ mem_desc_acc.update_coord(acc_tile_offset_k, acc_tile_offset_q,
+ acc_tile_offset_p, acc_tile_offset_n);
+
+ int32_t cnt_tile_offset_n = sg_idn * cnt_sg_tile_n;
+ int32_t cnt_tile_offset_p = sg_idp * cnt_sg_tile_p;
+ int32_t cnt_tile_offset_q = sg_idq * cnt_sg_tile_q;
+ int32_t cnt_tile_offset_k = sg_idk * cnt_sg_tile_k;
+ mem_desc_cnt.update_coord(cnt_tile_offset_k, cnt_tile_offset_q,
+ cnt_tile_offset_p, cnt_tile_offset_n);
+ }
+
+ inline uint32_t update_reduce_counter(mem_desc_cnt_t &mem_desc_cnt) {
+ constexpr uint32_t SIMD = 16;
+ mem_shape_t<4> shape = mem_desc_cnt.shape;
+ mem_coord_t<4> coord = mem_desc_cnt.coord;
+
+ uint32_t pitch_in_bytes
+ = shape.stride_x * sizeof(dtype_cnt) * counter_size;
+ uint32_t offset_x = coord.x;
+
+ uint32_t offset_y = coord.w * shape.stride_z * shape.stride_y
+ + coord.z * shape.stride_y + coord.y;
+ uint64_t address = (uint64_t)mem_desc_cnt.base.base
+ + offset_y * pitch_in_bytes
+ + offset_x * sizeof(dtype_cnt) * counter_size;
+ xetla_vector<uint32_t, SIMD> offsets
+ = xetla_vector_gen<uint32_t, SIMD>(0, 1);
+ offsets *= sizeof(dtype_cnt);
+ xetla_mask<SIMD> pred(0);
+ pred[0] = 1;
+ xetla_vector<dtype_cnt, SIMD> ret = xetla_atomic_global<atomic_op::iinc,
+ dtype_cnt, SIMD, data_size::default_size, cache_hint::uncached,
+ cache_hint::write_back>((dtype_cnt *)address, offsets, pred);
+
+ return ret[0];
+ }
+
+ inline void clean_reduce_counter(mem_desc_cnt_t &mem_desc_cnt) {
+ mem_shape_t<4> shape = mem_desc_cnt.shape;
+ mem_coord_t<4> coord = mem_desc_cnt.coord;
+
+ uint32_t pitch_in_bytes
+ = shape.stride_x * sizeof(dtype_cnt) * counter_size;
+ uint32_t offset_x = coord.x;
+
+ uint32_t offset_y = coord.w * shape.stride_z * shape.stride_y
+ + coord.z * shape.stride_y + coord.y;
+ uint64_t address = (uint64_t)mem_desc_cnt.base.base
+ + offset_y * pitch_in_bytes
+ + offset_x * sizeof(dtype_cnt) * counter_size;
+ xetla_vector<dtype_cnt, 1> zeros(0);
+
+ xetla_store_global<dtype_cnt, 1, data_size::default_size,
+ cache_hint::uncached, cache_hint::write_back>(
+ (dtype_cnt *)address, 0, zeros);
+ }
+
+public:
+ static constexpr uint32_t barrier_count = 0;
+ static constexpr uint32_t slm_size = 0;
+ uint32_t reduce_id = 0;
+
+ inline bool is_last_group() {
+ return reduce_id == (num_group_reduction - 1);
+ }
+
+ /// @brief Global reduction.
+ /// 1) each group stores tile data to global memory by using global atomic add ->
+ /// 2) after reduction complete, update the counter by using atomic inc ->
+ /// 3) the last group load the data back to EU, and clean the accumulation buffer and counter buffer.
+ /// @note only the last group has the valid data.
+ /// @param g Is the workgroup of the current tile.
+ /// @param matAcc Is the input of the reduction.
+ /// @param mem_desc_acc Is the memory descriptor of accumulation buffer.
+ /// @param mem_desc_cnt Is the memory descriptor of counter buffer.
+ /// @param slm_base Is the slm base address.
+ /// @param nbarrier_base Is the named barrier base.
+ template <typename matAcc_t, int sg_tile_n, int sg_tile_p>
+ __XETLA_API KERNEL_FUNC void operator()(work_group_t &g,
+ matAcc_t matAcc[sg_tile_n][sg_tile_p], mem_desc_acc_t mem_desc_acc,
+ mem_desc_cnt_t mem_desc_cnt, uint32_t slm_base = 0,
+ uint32_t nbarrier_base = 0) {
+ static_assert(std::is_same<typename matAcc_t::dtype, dtype_acc>::value,
+ "matAcc_t::dtype should match with dtype_acc");
+
+ update_sg_tile_tdesc(g, mem_desc_acc, mem_desc_cnt);
+
+ using matAcc_tile_desc_t = typename matAcc_t::tile_desc;
+ using matAcc_store_payload_t = subgroup::mem_payload_t<
+ mem_desc_t<dtype_acc, mem_layout::nhwc, mem_space::global, 8,
+ 4>,
+ matAcc_tile_desc_t, msg_type::atomic_add, arch_tag>;
+
+ matAcc_store_payload_t matAcc_store_payload(mem_desc_acc);
+
+#pragma unroll
+ for (uint32_t n = 0; n < sg_tile_n; n++) {
+#pragma unroll
+ for (uint32_t p = 0; p < sg_tile_p; p++) {
+
+ int32_t offset_n = mem_desc_acc.get_base_offset_from_w(n);
+ int32_t offset_p = mem_desc_acc.get_base_offset_from_z(p);
+ int mask_n = mem_desc_acc.get_mask_from_w(n);
+ int mask_p = mem_desc_acc.get_mask_from_z(p);
+ int32_t base_offset = (offset_n + offset_p) * sizeof(dtype_acc);
+
+ matAcc_store_payload.set_tdesc_base_address_masked(
+ (uint64_t)mem_desc_acc.base.base + base_offset,
+ mask_n & mask_p);
+
+ subgroup::tile_store<cache_hint::uncached,
+ cache_hint::write_back>(
+ matAcc[n][p], matAcc_store_payload);
+ }
+ }
+
+ xetla_fence<memory_kind::untyped_global, fence_op::none,
+ fence_scope::group>();
+
+ reduce_id = update_reduce_counter(mem_desc_cnt);
+ if (reduce_id == (num_group_reduction - 1)) {
+ using matAcc_payload_t = subgroup::mem_payload_t<
+ mem_desc_t<dtype_acc, mem_layout::nhwc, mem_space::global,
+ 8, 4>,
+ matAcc_tile_desc_t, msg_type::block_2d, arch_tag>;
+ matAcc_payload_t matAcc_payload(mem_desc_acc);
+
+ using mat_zero_t = subgroup::tile_t<dtype_acc, matAcc_tile_desc_t>;
+ mat_zero_t mat_zero;
+ mat_zero.reg = 0;
+
+#pragma unroll
+ for (uint32_t n = 0; n < sg_tile_n; n++) {
+#pragma unroll
+ for (uint32_t p = 0; p < sg_tile_p; p++) {
+ int32_t offset_n = mem_desc_acc.get_base_offset_from_w(n);
+ int32_t offset_p = mem_desc_acc.get_base_offset_from_z(p);
+ int mask_n = mem_desc_acc.get_mask_from_w(n);
+ int mask_p = mem_desc_acc.get_mask_from_z(p);
+ int32_t base_offset
+ = (offset_n + offset_p) * sizeof(dtype_acc);
+
+ matAcc_payload.set_tdesc_base_address_masked(
+ (uint64_t)mem_desc_acc.base.base + base_offset,
+ mask_n & mask_p);
+
+ subgroup::tile_load(matAcc[n][p], matAcc_payload);
+ SW_BARRIER();
+
+ subgroup::tile_store<cache_hint::uncached,
+ cache_hint::write_back>(mat_zero, matAcc_payload);
+ }
+ }
+
+ clean_reduce_counter(mem_desc_cnt);
+ SW_BARRIER();
+ }
+ }
+};
+
+/// @brief Cross group global reduction. Specialized for num_group_reduction=1
+template <typename tile_shape_acc_, typename tile_shape_cnt_,
+ typename mem_desc_acc_t_, typename mem_desc_cnt_t_,
+ uint32_t counter_size_, gpu_arch arch_tag_>
+class global_reduce_t<reduce_op::sum, tile_shape_acc_, tile_shape_cnt_,
+ mem_desc_acc_t_, mem_desc_cnt_t_, 1, counter_size_, arch_tag_,
+ std::enable_if_t<((arch_tag_ == gpu_arch::Xe))
+ && (tile_shape_acc_::dim == 4)>> {
+public:
+ static constexpr gpu_arch arch_tag = arch_tag_;
+ using tile_shape_acc = tile_shape_acc_;
+ using tile_shape_cnt = tile_shape_cnt_;
+ using mem_desc_acc_t = mem_desc_acc_t_;
+ using mem_desc_cnt_t = mem_desc_cnt_t_;
+ using dtype_acc = typename mem_desc_acc_t::dtype;
+
+private:
+ using work_group_t = typename tile_shape_acc::work_group_t;
+
+ static constexpr uint32_t acc_sg_tile_n = tile_shape_acc::sg_tile_size_n;
+ static constexpr uint32_t acc_sg_tile_p = tile_shape_acc::sg_tile_size_p;
+ static constexpr uint32_t acc_sg_tile_q = tile_shape_acc::sg_tile_size_q;
+ static constexpr uint32_t acc_sg_tile_k = tile_shape_acc::sg_tile_size_k;
+
+public:
+ static constexpr uint32_t barrier_count = 0;
+ static constexpr uint32_t slm_size = 0;
+ inline bool is_last_group() { return true; }
+
+ template <typename matAcc_t, int sg_tile_n, int sg_tile_p>
+ inline KERNEL_FUNC void operator()(work_group_t &g,
+ matAcc_t matAcc[sg_tile_n][sg_tile_p], mem_desc_acc_t mem_desc_acc,
+ mem_desc_cnt_t mem_desc_cnt, uint32_t slm_base = 0,
+ uint32_t nbarrier_base = 0) {}
+};
+} // namespace gpu::xetla::group
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/group/group.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/group/group.hpp
new file mode 100644
index 00000000000..a195daee615
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/group/group.hpp
@@ -0,0 +1,25 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#include "group/cooperative_reduction.hpp"
+#include "group/epilogue/epilogue.hpp"
+#include "group/gemm/gemm.hpp"
+#include "group/global_reduction.hpp"
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/group/tile_shape.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/group/tile_shape.hpp
new file mode 100644
index 00000000000..a05faeee910
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/group/tile_shape.hpp
@@ -0,0 +1,51 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#include "common/common.hpp"
+
+namespace gpu::xetla::group {
+
+template <auto... Args>
+struct tile_shape_t;
+
+/// @brief Workgroup level tile shape description.
+/// Describes the task assignment and layout of subgroups in a group.
+/// @tparam wg_tile_size_x_ Is the workgroup level tile size in x direction.
+/// @tparam wg_tile_size_y_ Is the workgroup level tile size in y direction.
+/// @tparam sg_tile_size_x_ Is the subgroup level tile size in x direction.
+/// @tparam sg_tile_size_y_ Is the subgroup level tile size in y direction.
+template <uint32_t wg_tile_size_x_, uint32_t wg_tile_size_y_,
+ uint32_t sg_tile_size_x_, uint32_t sg_tile_size_y_>
+struct tile_shape_t<wg_tile_size_x_, wg_tile_size_y_, sg_tile_size_x_,
+ sg_tile_size_y_> {
+ static constexpr uint32_t dim = 2;
+ static constexpr uint32_t wg_tile_size_x = wg_tile_size_x_;
+ static constexpr uint32_t wg_tile_size_y = wg_tile_size_y_;
+ static constexpr uint32_t sg_tile_size_x = sg_tile_size_x_;
+ static constexpr uint32_t sg_tile_size_y = sg_tile_size_y_;
+
+ static constexpr uint32_t wg_size_x
+ = (wg_tile_size_x + sg_tile_size_x - 1) / sg_tile_size_x;
+ static constexpr uint32_t wg_size_y
+ = (wg_tile_size_y + sg_tile_size_y - 1) / sg_tile_size_y;
+ using work_group_t = work_group_t<wg_size_x * wg_size_y>;
+};
+} // namespace gpu::xetla::group
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/kernel/gemm/api.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/kernel/gemm/api.hpp
new file mode 100644
index 00000000000..0d61718e377
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/kernel/gemm/api.hpp
@@ -0,0 +1,43 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#include "kernel/gemm/common.hpp"
+
+namespace gpu::xetla::kernel {
+
+/// @addtogroup xetla_gemm_universal
+/// @{
+
+/// @brief GEMM_UNIVERSAL functor.
+/// The basic functionality of xetla GEMM_UNIVERSAL is to calculate the \f$C = A \times B\f$.
+///
+/// For advanced usages, xetla GEMM_UNIVERSAL can also support:
+/// - \f$C = tileOp(A \times B)\f$ by configuring the tile_op_t in epilogue.
+/// @tparam dispatch_policy Is the dispatch algorithm of the GEMM_UNIVERSAL implementation.
+/// @tparam gemm_t Is the gemm functor.
+/// @tparam epilogue_t Is the epilogue functor.
+template <typename dispatch_policy, typename gemm_t, typename epilogue_t,
+ class enable = void>
+class gemm_universal_t {};
+
+/// @} xetla_gemm_universal
+
+} // namespace gpu::xetla::kernel
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/kernel/gemm/common.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/kernel/gemm/common.hpp
new file mode 100644
index 00000000000..584f9cba6bb
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/kernel/gemm/common.hpp
@@ -0,0 +1,29 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#include "common/common.hpp"
+#include "group/group.hpp"
+#include "subgroup/subgroup.hpp"
+
+namespace gpu::xetla::kernel {
+namespace detail {} // namespace detail
+
+} // namespace gpu::xetla::kernel
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/kernel/gemm/dispatch_policy.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/kernel/gemm/dispatch_policy.hpp
new file mode 100644
index 00000000000..3dcabed5276
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/kernel/gemm/dispatch_policy.hpp
@@ -0,0 +1,70 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#include "kernel/gemm/common.hpp"
+
+namespace gpu::xetla::kernel {
+/// @addtogroup xetla_gemm_universal
+/// @{
+
+/// @brief Default GROUP_SWIZZLE implementation.
+/// A general GROUP_SWIZZLE implementation to get an workgroup id .
+/// @tparam arch_tag_ Is the HW architecture.
+template <gpu_arch arch_tag_>
+struct group_swizzle_default {
+public:
+ static constexpr gpu_arch arch_tag = arch_tag_;
+
+ inline group_swizzle_default() = default;
+
+ template <int idx>
+ static __XETLA_API int get_tile_idx(sycl::nd_item<3> &item) {
+ return item.get_group(idx);
+ }
+ // correct group range, nothing will be done under this swizzle policy
+ static __XETLA_API void update_group_range(
+ uint32_t &group_range_m, uint32_t &group_range_n) {}
+};
+
+/// @brief Default GEMM_UNIVERSAL implementation.
+/// A general GEMM_UNIVERSAL implementation to provide a composition point of gemm_universal and epilogue.
+/// @tparam arch_tag_ Is the HW architecture.
+template <typename group_swizzle_policy_>
+struct dispatch_policy_default {
+ using group_swizzle_policy = group_swizzle_policy_;
+ static constexpr gpu_arch arch_tag = group_swizzle_policy::arch_tag;
+};
+
+/// @brief Kslicing GEMM_UNIVERSAL implementation.
+/// A special GEMM_UNIVERSAL implementation to increase the hardware occupancy by splitting the GEMM_UNIVERSAL task along k dimension.
+/// It includes inter-group reduction (by using global atomic) and intra-group reduction (by using local memory for data exchange).
+/// @tparam num_global_kslicing_ Is the k dim split ratio between groups.
+/// @tparam num_local_kslicing_ Is the k dim split ratio within a group.
+/// @tparam arch_tag_ Is the HW architecture.
+template <typename group_swizzle_policy_, int global_ratio_ = 1,
+ int local_ratio_ = 1>
+struct dispatch_policy_kslicing {
+ using group_swizzle_policy = group_swizzle_policy_;
+ static constexpr int global_ratio = global_ratio_;
+ static constexpr int local_ratio = local_ratio_;
+ static constexpr gpu_arch arch_tag = group_swizzle_policy::arch_tag;
+};
+} // namespace gpu::xetla::kernel
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/kernel/gemm/gemm.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/kernel/gemm/gemm.hpp
new file mode 100644
index 00000000000..7807e4a36c8
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/kernel/gemm/gemm.hpp
@@ -0,0 +1,28 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+/// @defgroup xetla_gemm_universal XeTLA GEMM_UNIVERSAL
+/// This is a gemm_universal API built on top of xetla group level API to provide a more convenient way to compose a GEMM_UNIVERSAL kernel.
+
+#include "kernel/gemm/api.hpp"
+#include "kernel/gemm/common.hpp"
+#include "kernel/gemm/dispatch_policy.hpp"
+#include "kernel/gemm/impl/kslicing_xe.hpp"
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/kernel/gemm/impl/kslicing_xe.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/kernel/gemm/impl/kslicing_xe.hpp
new file mode 100644
index 00000000000..87bb31421f0
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/kernel/gemm/impl/kslicing_xe.hpp
@@ -0,0 +1,394 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#include "kernel/gemm/api.hpp"
+#include "kernel/gemm/common.hpp"
+#include "kernel/gemm/dispatch_policy.hpp"
+
+namespace gpu::xetla::kernel {
+
+/// @addtogroup xetla_gemm_universal
+/// @{
+
+/// @brief Is the gemm_universal functor, specialized in kslicing dispatch policy and Xe architecture.
+///
+/// @tparam num_global_kslicing_ Is the k dim split ratio between groups.
+/// @tparam num_local_kslicing_ Is the k dim split ratio within a group.
+/// @tparam gemm_t_ Is the gemm functor to compose a GEMM_UNIVERSAL.
+/// @tparam epilogue_t_ Is the epilogue functor to compose a GEMM_UNIVERSAL.
+template <int num_global_kslicing_, int num_local_kslicing_, typename gemm_t_,
+ typename epilogue_t_, typename group_swizzle_>
+class gemm_universal_t<dispatch_policy_kslicing<group_swizzle_,
+ num_global_kslicing_, num_local_kslicing_>,
+ gemm_t_, epilogue_t_,
+ std::enable_if_t<(group_swizzle_::arch_tag == gpu_arch::Xe)>> {
+ using gemm_t = gemm_t_;
+ using epilogue_t = epilogue_t_;
+ using gemm_args_t = typename gemm_t::arguments_t;
+ using epilogue_args_t = typename epilogue_t::arguments_t;
+ using tile_shape = typename gemm_t::tile_shape;
+ using group_swizzle_t = group_swizzle_;
+
+ static constexpr uint32_t wg_tile_m = tile_shape::wg_tile_size_y;
+ static constexpr uint32_t wg_tile_n = tile_shape::wg_tile_size_x;
+ static constexpr uint32_t sg_tile_m = tile_shape::sg_tile_size_y;
+ static constexpr uint32_t sg_tile_n = tile_shape::sg_tile_size_x;
+ static constexpr uint32_t wg_size_y = tile_shape::wg_size_y;
+ static constexpr uint32_t wg_size_x = tile_shape::wg_size_x;
+ static constexpr uint32_t real_wg_tile_m = sg_tile_m * wg_size_y;
+ static constexpr uint32_t real_wg_tile_n = sg_tile_n * wg_size_x;
+
+ static constexpr uint32_t k_stride = gemm_t::k_stride;
+ using work_group_t = typename gemm_t::work_group_t;
+ static constexpr uint32_t work_group_size = work_group_t::size;
+
+ static constexpr gpu_arch arch_tag = group_swizzle_t::arch_tag;
+ static_assert(arch_tag == gemm_t::arch_tag, "arch_tag should be the same");
+ static_assert(
+ arch_tag == epilogue_t::arch_tag, "arch_tag should be the same");
+ static_assert(std::is_same<typename gemm_t::tile_shape,
+ typename epilogue_t::tile_shape>::value,
+ "tile_shape should be the same");
+
+ using mem_desc_a_t = typename gemm_t::mem_desc_a_t;
+ using mem_desc_b_t = typename gemm_t::mem_desc_b_t;
+ using mem_desc_c_t = typename epilogue_t::mem_desc_c_t;
+ using matA_base_t = typename mem_desc_a_t::base_t;
+ using matB_base_t = typename mem_desc_b_t::base_t;
+ using matC_base_t = typename mem_desc_c_t::base_t;
+ using dtype_a = typename mem_desc_a_t::dtype;
+ using dtype_b = typename mem_desc_b_t::dtype;
+ using dtype_c = typename mem_desc_c_t::dtype;
+ using matAcc_t = typename gemm_t::matAcc_t;
+ using dtype_acc = typename matAcc_t::dtype;
+ using mem_desc_acc_t
+ = mem_desc_t<dtype_acc, mem_layout::row_major, mem_space::global>;
+ using mem_desc_cnt_t
+ = mem_desc_t<uint32_t, mem_layout::row_major, mem_space::global>;
+ using acc_base_t = typename mem_desc_acc_t::base_t;
+ using cnt_base_t = typename mem_desc_cnt_t::base_t;
+
+ static constexpr uint32_t num_global_kslicing = num_global_kslicing_;
+ static constexpr uint32_t num_local_kslicing = num_local_kslicing_;
+ static_assert((num_global_kslicing > 0) && (num_local_kslicing > 0),
+ "min slicing ratio is 1");
+
+ static_assert((num_local_kslicing & (num_local_kslicing - 1)) == 0,
+ "num_local_kslicing should be power of 2!");
+
+ using kslicing_t = group::cooperative_reduce_t<reduce_op::sum, tile_shape,
+ matAcc_t, num_local_kslicing, arch_tag>;
+ using mat_slice_t = typename kslicing_t::mat_slice_t;
+ static constexpr uint32_t ks_coop_num_x = kslicing_t::coop_num_x;
+ static constexpr uint32_t ks_coop_num_y = kslicing_t::coop_num_y;
+
+ static constexpr uint32_t gemm_nbarr_count = gemm_t::barrier_count;
+ static constexpr uint32_t gemm_slm_size = gemm_t::slm_size;
+
+ static constexpr uint32_t epilogue_nbarr_count = epilogue_t::barrier_count;
+ static constexpr uint32_t epilogue_slm_size = epilogue_t::slm_size;
+
+ static constexpr uint32_t kslicing_nbarr_count = kslicing_t::barrier_count;
+ static constexpr uint32_t kslicing_slm_size = kslicing_t::slm_size;
+
+ static constexpr uint32_t counter_size = 8;
+
+ static constexpr uint32_t alignment = 8 / sizeof(dtype_acc);
+
+ using tile_shape_cnt = group::tile_shape_t<ks_coop_num_x * wg_size_x,
+ ks_coop_num_y * wg_size_y, ks_coop_num_x, ks_coop_num_y>;
+
+ using global_group_reduce_t = group::global_reduce_t<reduce_op::sum,
+ tile_shape, tile_shape_cnt, mem_desc_acc_t, mem_desc_cnt_t,
+ num_global_kslicing, counter_size, arch_tag>;
+
+public:
+ /// @brief GEMM_UNIVERSAL arguments.
+ /// This is the interface for users to pass the application-related runtime variables.
+ struct arguments_t {
+ /// @brief Is the size of the m dimension of the matrix multiplication (m x k x n).
+ uint32_t matrix_m;
+ /// @brief Is the size of the k dimension of the matrix multiplication (m x k x n).
+ uint32_t matrix_k;
+ /// @brief Is the size of the n dimension of the matrix multiplication (m x k x n).
+ uint32_t matrix_n;
+ /// @brief Is the base address of matrix A.
+ matA_base_t matA_base;
+ /// @brief Is the leading dimension (pitch) size of the matrix A in memory.
+ uint32_t matA_ld;
+ /// @brief Is the base address of matrix B.
+ matB_base_t matB_base;
+ /// @brief Is the leading dimension (pitch) size of the matrix B in memory.
+ uint32_t matB_ld;
+ /// @brief Is the base address of matrix C.
+ matC_base_t matC_base;
+ /// @brief Is the leading dimension (pitch) size of the matrix C in memory.
+ uint32_t matC_ld;
+ /// @brief Is the base address of accumulation buffer.
+ acc_base_t acc_base;
+ /// @brief Is the base address of counter buffer.
+ cnt_base_t cnt_base;
+ /// @brief Is the epilogue arguments.
+ epilogue_args_t epilogue_args;
+
+ /// @brief Constructs arguments with default method.
+ inline arguments_t() = default;
+
+ /// @brief Set for device copyable
+ static constexpr bool host_callable = true;
+
+ // Be aware of the risks: Rule of three (copy constructor, copy assignment, destructor)
+ // Please check if you need to add self-define destructor
+ // ~arguments_t(){}
+
+ /// @brief Constructs arguments with initialization list.
+ /// @param matrix_m_ Is the size of the m dimension of the matrix multiplication (m x k x n).
+ /// @param matrix_k_ Is the size of the k dimension of the matrix multiplication (m x k x n).
+ /// @param matrix_n_ Is the size of the n dimension of the matrix multiplication (m x k x n).
+ /// @param matA_base_ Is the base address of matrix A.
+ /// @param matA_ld_ Is the leading dimension (pitch) size of the matrix A in memory.
+ /// @param matB_base_ Is the base address of matrix B.
+ /// @param matB_ld_ Is the leading dimension (pitch) size of the matrix B in memory.
+ /// @param matC_base_ Is the base address of matrix C.
+ /// @param matC_ld_ Is the leading dimension (pitch) size of the matrix C in memory.
+ /// @param epilogue_args_ Is the epilogue arguments.
+ inline arguments_t(uint32_t matrix_m_, uint32_t matrix_k_,
+ uint32_t matrix_n_, matA_base_t matA_base_, uint32_t matA_ld_,
+ matB_base_t matB_base_, uint32_t matB_ld_,
+ matC_base_t matC_base_, uint32_t matC_ld_,
+ acc_base_t acc_base_ = {}, cnt_base_t cnt_base_ = {},
+ epilogue_args_t epilogue_args_ = {})
+ : matrix_m(matrix_m_)
+ , matrix_k(matrix_k_)
+ , matrix_n(matrix_n_)
+ , matA_base(matA_base_)
+ , matA_ld(matA_ld_)
+ , matB_base(matB_base_)
+ , matB_ld(matB_ld_)
+ , matC_base(matC_base_)
+ , matC_ld(matC_ld_)
+ , acc_base(acc_base_)
+ , cnt_base(cnt_base_)
+ , epilogue_args(epilogue_args_) {}
+ inline arguments_t(const arguments_t &args)
+ : matrix_m(args.matrix_m)
+ , matrix_k(args.matrix_k)
+ , matrix_n(args.matrix_n)
+ , matA_base(args.matA_base)
+ , matA_ld(args.matA_ld)
+ , matB_base(args.matB_base)
+ , matB_ld(args.matB_ld)
+ , matC_base(args.matC_base)
+ , matC_ld(args.matC_ld)
+ , acc_base(args.acc_base)
+ , cnt_base(args.cnt_base)
+ , epilogue_args(args.epilogue_args) {}
+ // Be aware of the risks: Rule of three (copy constructor, copy assignment, destructor)
+ // Please check if you need to add self-define destructor
+ // inline ~arguments_t(){}
+ inline arguments_t &operator=(const arguments_t &args) {
+ this->matrix_m = args.matrix_m;
+ this->matrix_k = args.matrix_k;
+ this->matrix_n = args.matrix_n;
+ this->matA_base = args.matA_base;
+ this->matA_ld = args.matA_ld;
+ this->matB_base = args.matB_base;
+ this->matB_ld = args.matB_ld;
+ this->matC_base = args.matC_base;
+ this->matC_ld = args.matC_ld;
+ this->acc_base = args.acc_base;
+ this->cnt_base = args.cnt_base;
+ this->epilogue_args = args.epilogue_args;
+ return *this;
+ }
+ };
+
+ /// @brief Gets named_barrier id consumption count.
+ /// Users query and get a named_barrier id consumption count in compile time.
+ /// @return The count of named barriers required.
+ __XETLA_API static constexpr uint32_t get_barrier_count() {
+ constexpr uint32_t count = gemm_nbarr_count * num_local_kslicing
+ + kslicing_nbarr_count
+ + epilogue_nbarr_count * num_local_kslicing;
+ static_assert(
+ count <= 32, "The named_barrier count should be less than 32!");
+ return count;
+ }
+
+ /// @brief Gets local memory size consumption.
+ /// Users query and get a local memory consumption size in compile time.
+ /// @return The size of local memory required.
+ __XETLA_API static constexpr uint32_t get_slm_size() {
+ constexpr uint32_t size = gemm_slm_size * num_local_kslicing
+ + kslicing_slm_size + epilogue_slm_size * num_local_kslicing;
+ static_assert(size <= (128 * 1024),
+ "The local memory size should be less than 128KB!");
+ return size;
+ }
+
+ /// @brief Main execution function for GEMM_UNIVERSAL.
+ /// The processing order is 1) set group-level base and boundary, split group to workgroups ->
+ /// 2) num_local_kslicing x gemms -> 3) local kslicing -> 4) num_local_kslicing x epilogues.
+ /// @param item Is the sycl::nd_item, returns execution related information, such as workgroup id, subgroup id...
+ /// @param args Is the GEMM_UNIVERSAL arguments for application-related runtime variables.
+ /// @param slm_base Is the slm base address.
+ /// @param nbarrier_base Is the named barrier base.
+ __XETLA_API KERNEL_FUNC void operator()(sycl::nd_item<3> &item,
+ const arguments_t &args, uint32_t slm_base = 0,
+ uint32_t nbarrier_base = 0) const {
+ // set up workgroup level coordinates and boundaries
+ work_group_t g(item.get_local_linear_id() % work_group_size);
+ uint32_t wg_id = item.get_local_linear_id() / work_group_size;
+ group_swizzle_t group_swizzle;
+ int start_m = group_swizzle.template get_tile_idx<1>(item) * wg_tile_m;
+ int start_n = group_swizzle.template get_tile_idx<2>(item) * wg_tile_n;
+ int start_k = 0;
+ uint32_t wg_tile_k = args.matrix_k;
+ uint32_t boundary_n = (start_n + wg_tile_n) > args.matrix_n
+ ? args.matrix_n
+ : (start_n + wg_tile_n);
+ uint32_t boundary_m = (start_m + wg_tile_m) > args.matrix_m
+ ? args.matrix_m
+ : (start_m + wg_tile_m);
+ uint32_t boundary_k = wg_tile_k;
+ if constexpr (num_global_kslicing > 1) {
+ wg_tile_k = (wg_tile_k + num_global_kslicing - 1)
+ / num_global_kslicing;
+ start_k = start_k
+ + group_swizzle.template get_tile_idx<0>(item) * wg_tile_k;
+ boundary_k = (start_k + wg_tile_k) > boundary_k
+ ? boundary_k
+ : (start_k + wg_tile_k);
+ }
+ if constexpr (num_local_kslicing > 1) {
+ wg_tile_k
+ = (wg_tile_k + num_local_kslicing - 1) / num_local_kslicing;
+ start_k = start_k + wg_id * wg_tile_k;
+ boundary_k = (start_k + wg_tile_k) > boundary_k
+ ? boundary_k
+ : (start_k + wg_tile_k);
+ }
+
+ // set up arguments
+ uint32_t gemm_slm_base = slm_base;
+ uint32_t gemm_nbarr_base = nbarrier_base;
+ if constexpr (num_local_kslicing > 1) {
+ gemm_slm_base = slm_base + wg_id * gemm_slm_size;
+ gemm_nbarr_base = nbarrier_base + wg_id * gemm_nbarr_count;
+ }
+ uint32_t kslicing_slm_base
+ = slm_base + num_local_kslicing * gemm_slm_size;
+ uint32_t kslicing_nbarr_base
+ = nbarrier_base + num_local_kslicing * gemm_nbarr_count;
+ uint32_t epilogue_slm_base = kslicing_slm_base + kslicing_slm_size;
+ uint32_t epilogue_nbarr_base
+ = kslicing_nbarr_base + kslicing_nbarr_count;
+
+ mem_desc_a_t mem_desc_a;
+ mem_desc_b_t mem_desc_b;
+ mem_desc_c_t mem_desc_c;
+ //setup for matA
+ if constexpr (mem_desc_a_t::is_local) {
+ mem_desc_a.init(args.matA_base,
+ {wg_tile_k, real_wg_tile_m, wg_tile_k}, {0, 0});
+ } else {
+ mem_desc_a.init(args.matA_base,
+ {boundary_k, boundary_m, args.matA_ld}, {start_k, start_m});
+ }
+ //setup for matB
+ if constexpr (mem_desc_b_t::is_local) {
+ mem_desc_b.init(args.matB_base,
+ {real_wg_tile_n, wg_tile_k, real_wg_tile_n}, {0, 0});
+ } else {
+ mem_desc_b.init(args.matB_base,
+ {boundary_n, boundary_k, args.matB_ld}, {start_n, start_k});
+ }
+
+ uint32_t inner_loop_count = (wg_tile_k + k_stride - 1) / k_stride;
+ gemm_args_t gemm_args(mem_desc_a, mem_desc_b, inner_loop_count);
+ matAcc_t matAcc;
+ matAcc.init(0);
+ gemm_t gemm;
+ gemm(g, matAcc, gemm_args, gemm_slm_base, gemm_nbarr_base);
+
+ kslicing_t kslicing(wg_id);
+ mat_slice_t mat_slice;
+ kslicing(g, mat_slice, matAcc, kslicing_slm_base, kslicing_nbarr_base);
+ if (kslicing.is_valid_post_process_wg()) {
+ //setup for matC
+ //set up cooperative offset for matC store
+ int32_t coop_offset_x
+ = kslicing.coop_id_x * mat_slice_t::tile_size_x;
+ int32_t coop_offset_y
+ = kslicing.coop_id_y * mat_slice_t::tile_size_y;
+ int32_t acc_start_x = start_n + coop_offset_x;
+ int32_t acc_start_y = start_m + coop_offset_y;
+ int32_t cnt_start_x = group_swizzle.template get_tile_idx<2>(item)
+ * tile_shape_cnt::wg_tile_size_x
+ + kslicing.coop_id_x;
+ int32_t cnt_start_y = group_swizzle.template get_tile_idx<1>(item)
+ * tile_shape_cnt::wg_tile_size_y
+ + kslicing.coop_id_y;
+ uint32_t group_range_x = item.get_group_range(2);
+ uint32_t group_range_y = item.get_group_range(1);
+ uint32_t cnt_size_x
+ = group_range_x * tile_shape_cnt::wg_tile_size_x;
+ uint32_t cnt_size_y
+ = group_range_y * tile_shape_cnt::wg_tile_size_y;
+
+ uint32_t acc_aligned_n
+ = (args.matrix_n + alignment - 1) / alignment * alignment;
+
+ uint32_t acc_boundary_n = (start_n + wg_tile_n) > acc_aligned_n
+ ? acc_aligned_n
+ : start_n + wg_tile_n;
+
+ mem_desc_acc_t mem_desc_acc(args.acc_base,
+ {acc_boundary_n, boundary_m, acc_aligned_n},
+ {acc_start_x, acc_start_y});
+ mem_desc_cnt_t mem_desc_cnt(args.cnt_base,
+ {cnt_size_x, cnt_size_y, cnt_size_x},
+ {cnt_start_x, cnt_start_y});
+
+ global_group_reduce_t global_group_reduce;
+ global_group_reduce(g, mat_slice, mem_desc_acc, mem_desc_cnt);
+
+ if (global_group_reduce.is_last_group()) {
+ if constexpr (mem_desc_c_t::is_local) {
+ mem_desc_c.init(args.matC_base,
+ {real_wg_tile_n, real_wg_tile_m, real_wg_tile_n},
+ {coop_offset_x, coop_offset_y});
+ } else {
+ mem_desc_c.init(args.matC_base,
+ {boundary_n, boundary_m, args.matC_ld},
+ {start_n + coop_offset_x, start_m + coop_offset_y});
+ }
+ epilogue_t epilogue;
+ epilogue(g, mat_slice, mem_desc_c, args.epilogue_args,
+ epilogue_slm_base, epilogue_nbarr_base);
+ }
+ }
+ }
+};
+
+/// @} xetla_gemm_universal
+
+} // namespace gpu::xetla::kernel
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/kernel/kernel.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/kernel/kernel.hpp
new file mode 100644
index 00000000000..3c04902517d
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/kernel/kernel.hpp
@@ -0,0 +1,22 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#include "kernel/gemm/gemm.hpp"
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/subgroup/subgroup.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/subgroup/subgroup.hpp
new file mode 100644
index 00000000000..240aa7b90a7
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/subgroup/subgroup.hpp
@@ -0,0 +1,22 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#include "subgroup/tile/tile.hpp"
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/subgroup/tile/api.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/subgroup/tile/api.hpp
new file mode 100644
index 00000000000..905e901a906
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/subgroup/tile/api.hpp
@@ -0,0 +1,125 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#include "subgroup/tile/common.hpp"
+
+namespace gpu::xetla::subgroup {
+
+/// @brief Is the xetla tile mma operation definition API.
+/// @tparam matAcc_dst_t Is the tile type for dst data of matC.
+/// @tparam matAcc_src_t Is the tile type for src data of matC.
+/// @tparam matB_t Is the tile type for matB.
+/// @tparam matA_t Is the tile type for matA.
+/// @tparam engine Is the compute engine, fpu or xmx.
+/// @tparam arch_tag Is the hardware architecture tag.
+template <typename matAcc_dst_t, typename matAcc_src_t, typename matB_t,
+ typename matA_t, mma_engine engine, gpu_arch arch_tag,
+ typename enable = void>
+struct tile_mma_t {};
+
+template <typename matAcc_dst_t, typename matAcc_src_t, typename matB_t,
+ typename matA_t, typename matBS_t, typename matAS_t, uint32_t scalings,
+ mma_engine engine, gpu_arch arch_tag, typename enable = void>
+struct tile_bmma_t {};
+
+/// @brief Is to illustrate the memory information
+/// @tparam mem_desc Is the memory descriptor
+/// @tparam tile_desc Is the tile descriptor
+/// @tparam message_type Is the form will be used to load/store
+template <typename mem_desc, typename tile_desc, msg_type message_type,
+ gpu_arch arch_tag, typename enable = void>
+struct mem_payload_t {};
+
+/// @brief Is to illustrate the memory information to prefetch data to cache.
+/// @tparam mem_desc Is the memory descriptor
+/// @tparam tile_desc_ Is the tile descriptor.
+/// @tparam cooperative_num_ Is the thread nums to prefetch data.
+/// @tparam arch_tag Is the hardware architecture tag.
+template <typename mem_desc_, typename tile_desc_, uint32_t cooperative_num_,
+ gpu_arch arch_tag, typename enable = void>
+struct prefetch_payload_t {};
+
+/// @brief Is to illustrate the tile information about a sub matrix.
+/// @tparam tile_size_x_ Is the horizon tile size.
+/// @tparam tile_size_y_ Is the vertical tile size.
+/// @tparam block_size_x_ Is the horizon block size.
+/// @tparam block_size_y_ Is the vertical block size.
+/// @tparam reg_layout_ Is the register layout i.e. tiled, vnni_tiled and so on.
+/// @tparam gpu_arch_ Is the hardware architecture tag.
+template <uint32_t tile_size_x_, uint32_t tile_size_y_, uint32_t block_size_x_,
+ uint32_t block_size_y_, reg_layout reg_layout_ = reg_layout::tiled,
+ bool col_majored_ = false>
+struct tile_desc_t {
+ static constexpr uint32_t tile_size_x = tile_size_x_;
+ static constexpr uint32_t tile_size_y = tile_size_y_;
+
+ static constexpr uint32_t block_size_x = block_size_x_;
+ static constexpr uint32_t block_size_y = block_size_y_;
+ static constexpr uint32_t remained_size_y = tile_size_y % block_size_y;
+
+ static constexpr reg_layout register_layout = reg_layout_;
+ static constexpr bool reg_transpose
+ = reg_layout_ == reg_layout::transpose_tiled;
+
+ static_assert(
+ tile_size_x >= block_size_x, "tile_size_x should >= block_size_x ");
+ static_assert(
+ tile_size_y >= block_size_y, "tile_size_y should >= block_size_y ");
+ static_assert((tile_size_y == 1) || (block_size_y == 1)
+ || ((block_size_x & (block_size_x - 1)) == 0),
+ "if tile_size_y/block_size_y > 1, block_size_x should be power of "
+ "2 ");
+ static_assert(tile_size_x % (block_size_x) == 0,
+ "Tile_size_x should be a multiple of block_size_x ");
+
+ static constexpr uint32_t num_block_x = tile_size_x / block_size_x;
+ static constexpr uint32_t num_block_y = tile_size_y / block_size_y;
+ static constexpr uint32_t num_block
+ = num_block_x * (num_block_y + (remained_size_y > 0 ? 1 : 0));
+
+ static constexpr uint32_t block_elems = block_size_x * block_size_y;
+ static constexpr uint32_t tile_elems = tile_size_x * tile_size_y;
+ static constexpr bool col_majored = col_majored_;
+};
+
+/// @brief Is a struct contains some register file.
+/// @tparam dtype_ Is the data type.
+/// @tparam tile_desc_ Is tile_desc_t struct.
+template <typename dtype_, typename tile_desc_, bool dst_ = true>
+struct tile_t : public tile_desc_ {
+ using dtype = dtype_;
+ using tile_desc = tile_desc_;
+ static constexpr bool dst = dst_;
+ xetla_vector<dtype, tile_desc::tile_elems> reg;
+
+ // Cannot init value by constructor
+ inline tile_t(native_type_t<dtype> val) {
+ static_assert(!is_internal_type<dtype>::value,
+ "compiler currently does NOT support using plained BF16 data "
+ "to initialize a BF16 data");
+ this->reg = val;
+ }
+
+ inline tile_t() = default;
+ __XETLA_API void init(native_type_t<dtype> val) { this->reg = val; }
+};
+
+} // namespace gpu::xetla::subgroup
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/subgroup/tile/chained_tile_op.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/subgroup/tile/chained_tile_op.hpp
new file mode 100644
index 00000000000..f32539064e4
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/subgroup/tile/chained_tile_op.hpp
@@ -0,0 +1,126 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#include "subgroup/tile/common.hpp"
+
+namespace gpu::xetla::subgroup {
+
+template <int idx, typename tile_op_args_t>
+struct tile_op_arg_helper_t {
+ tile_op_args_t args;
+ inline tile_op_arg_helper_t(tile_op_args_t args_) : args(args_) {}
+ // Be aware of the risks: Rule of three (copy constructor, copy assignment, destructor)
+ // Please check if you need to add self-define destructor
+ // ~tile_op_arg_helper_t(){}
+ inline tile_op_arg_helper_t(
+ const tile_op_arg_helper_t<idx, tile_op_args_t> &args_helper)
+ : args(args_helper.args) {}
+ // Be aware of the risks: Rule of three (copy constructor, copy assignment, destructor)
+ // Please check if you need to add self-define destructor
+ // inline ~tile_op_arg_helper_t(){}
+ inline tile_op_arg_helper_t &operator=(
+ const tile_op_arg_helper_t<idx, tile_op_args_t> &args_helper) {
+ this->args = args_helper.args;
+ return *this;
+ }
+ inline tile_op_arg_helper_t() = default;
+ // Be aware of the risks: Rule of three (copy constructor, copy assignment, destructor)
+ // Please check if you need to add self-define destructor
+ // ~tile_op_arg_helper_t(){}
+
+ inline tile_op_args_t get_args() const { return args; }
+ inline void set_args(const tile_op_args_t &new_args) { args = new_args; }
+};
+
+template <int idx, typename... tile_op_args_t>
+struct chained_tile_op_arg_t {};
+
+template <int idx, typename curr_args_t, typename... remain_args_t>
+struct chained_tile_op_arg_t<idx, curr_args_t, remain_args_t...>
+ : public tile_op_arg_helper_t<idx, curr_args_t>,
+ public chained_tile_op_arg_t<idx + 1, remain_args_t...> {
+ inline chained_tile_op_arg_t() = default;
+ inline chained_tile_op_arg_t(
+ curr_args_t curr_args, remain_args_t... remain_args)
+ : tile_op_arg_helper_t<idx, curr_args_t>(curr_args)
+ , chained_tile_op_arg_t<idx + 1, remain_args_t...>(remain_args...) {}
+
+ inline chained_tile_op_arg_t(
+ chained_tile_op_arg_t<idx, curr_args_t, remain_args_t...> const
+ &args)
+ = default;
+
+ template <int idx_, typename T>
+ inline T get() const {
+ return this->tile_op_arg_helper_t<idx_, T>::get_args();
+ }
+ template <int idx_, typename T>
+ inline void set(T new_args) {
+ this->tile_op_arg_helper_t<idx_, T>::set_args(new_args);
+ }
+};
+
+template <typename... tile_op_t>
+struct chained_tile_op_t {
+ using arguments_t
+ = chained_tile_op_arg_t<0, typename tile_op_t::arguments_t...>;
+ static constexpr int list_size = sizeof...(tile_op_t);
+ template <typename matAcc_t, typename coord_t>
+ __XETLA_API KERNEL_FUNC void operator()(matAcc_t &matAcc,
+ const coord_t &coord, const arguments_t &args_helper,
+ uint32_t slm_base = 0, uint32_t nbarrier_base = 0) {
+ if constexpr (list_size == 0) {
+ return;
+ } else {
+ chained_tile_op_helper<tile_op_t...> chained_tile_op;
+ chained_tile_op(
+ matAcc, coord, args_helper, slm_base, nbarrier_base);
+ }
+ }
+
+private:
+ template <typename... total_tile_op_t>
+ struct chained_tile_op_helper {};
+
+ template <typename curr_tile_op_t, typename... remain_tile_op_t>
+ struct chained_tile_op_helper<curr_tile_op_t, remain_tile_op_t...> {
+ using curr_tile_op_args_t = typename curr_tile_op_t::arguments_t;
+ static constexpr int curr_idx
+ = list_size - sizeof...(remain_tile_op_t) - 1;
+ template <typename matAcc_t, typename coord_t>
+ __XETLA_API KERNEL_FUNC void operator()(matAcc_t &matAcc,
+ const coord_t &coord, const arguments_t &args_helper,
+ uint32_t slm_base = 0, uint32_t nbarrier_base = 0) {
+ curr_tile_op_t curr_tile_op;
+ //call the actual tile op
+ curr_tile_op(matAcc, coord,
+ args_helper.template get<curr_idx, curr_tile_op_args_t>(),
+ slm_base, nbarrier_base);
+ if constexpr (sizeof...(remain_tile_op_t) > 0) {
+ chained_tile_op_helper<remain_tile_op_t...> remain_tile_op;
+ remain_tile_op(
+ matAcc, coord, args_helper, slm_base, nbarrier_base);
+ }
+ }
+ };
+};
+
+} // namespace gpu::xetla::subgroup
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/subgroup/tile/common.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/subgroup/tile/common.hpp
new file mode 100644
index 00000000000..364bf6561e1
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/subgroup/tile/common.hpp
@@ -0,0 +1,331 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#include "common/common.hpp"
+
+namespace gpu::xetla::subgroup {
+
+namespace detail {
+
+/// @brief Compute next power of 2 of a constexpr with guaranteed compile-time
+/// evaluation.
+///
+/// @tparam N
+/// @tparam K
+/// @tparam K_gt_eq_N
+template <uint32_t N, uint32_t K, bool K_gt_eq_N>
+struct NextPowerOf2;
+
+/// @brief
+///
+/// @tparam N
+/// @tparam K
+template <uint32_t N, uint32_t K>
+struct NextPowerOf2<N, K, true> {
+ static constexpr uint32_t get() { return K; }
+};
+
+/// @brief
+///
+/// @tparam N
+/// @tparam K
+template <uint32_t N, uint32_t K>
+struct NextPowerOf2<N, K, false> {
+ static constexpr uint32_t get() {
+ return NextPowerOf2<N, K * 2, K * 2 >= N>::get();
+ }
+};
+
+/// @brief Get the Next Power Of2 object
+///
+/// @tparam N
+/// @return constexpr uint32_t
+template <uint32_t N>
+constexpr uint32_t getNextPowerOf2() {
+ return NextPowerOf2<N, 1, (1 >= N)>::get();
+}
+
+/// @brief Get the Next Power Of2<0> object
+///
+/// @tparam
+/// @return constexpr uint32_t
+template <>
+constexpr uint32_t getNextPowerOf2<0>() {
+ return 0;
+}
+
+/// @brief
+///
+/// @tparam a
+/// @tparam b
+template <uint32_t a, uint32_t b>
+struct gcd {
+ static constexpr uint32_t value = gcd<b, a % b>::value;
+};
+
+/// @brief
+///
+/// @tparam a
+template <uint32_t a>
+struct gcd<a, 0> {
+ static constexpr uint32_t value = a;
+};
+
+enum class process_flag : uint8_t { load = 0, store = 1 };
+
+template <uint32_t remained_len, uint32_t base_len, process_flag flag,
+ cache_hint L1, cache_hint L2, typename payload_t, typename tile_t>
+__XETLA_API typename std::enable_if_t<base_len == 0> process_1d_tail(
+ tile_t &tile, payload_t &payload, uint32_t offset) {}
+
+template <uint32_t remained_len, uint32_t base_len, process_flag flag,
+ cache_hint L1, cache_hint L2, typename payload_t, typename tile_t>
+__XETLA_API typename std::enable_if_t<base_len == 0> process_1d_tail(
+ tile_t &tile, payload_t &payload, uint32_t offset,
+ uint32_t address_offset) {}
+
+template <uint32_t remained_len, uint32_t base_len, process_flag flag,
+ cache_hint L1, cache_hint L2, typename payload_t, typename tile_t>
+__XETLA_API typename std::enable_if_t<base_len != 0
+ && payload_t::memory_space == mem_space::global>
+process_1d_tail(tile_t &tile, payload_t &payload, uint32_t offset) {
+ using dtype = typename payload_t::dtype;
+ using mem_dtype = typename payload_t::mem_dtype;
+ if constexpr (remained_len >= base_len) {
+ uint32_t address_offset = offset * sizeof(dtype);
+ auto reg_sub
+ = tile.reg.xetla_select<base_len * payload_t::scale_factor, 1>(
+ offset);
+ if constexpr (flag == process_flag::load) {
+ reg_sub.xetla_format<mem_dtype>() = xetla_load_global<mem_dtype,
+ base_len, data_size::default_size, L1, L2>(
+ payload.base_ptr, payload.base_offset + address_offset);
+ } else {
+ xetla_store_global<mem_dtype, base_len, data_size::default_size, L1,
+ L2>(payload.base_ptr, payload.base_offset + address_offset,
+ reg_sub.xetla_format<mem_dtype>());
+ }
+ process_1d_tail<remained_len - base_len, (base_len >> 1), flag, L1, L2>(
+ tile, payload, offset + base_len * payload_t::scale_factor);
+ } else {
+ process_1d_tail<remained_len, (base_len >> 1), flag, L1, L2>(
+ tile, payload, offset);
+ }
+}
+
+template <uint32_t remained_len, uint32_t base_len, process_flag flag,
+ cache_hint L1, cache_hint L2, typename payload_t, typename tile_t>
+__XETLA_API typename std::enable_if_t<base_len != 0
+ && payload_t::memory_space == mem_space::local>
+process_1d_tail(tile_t &tile, payload_t &payload, uint32_t offset,
+ uint32_t address_offset) {
+ using dtype = typename payload_t::dtype;
+ using mem_dtype = typename payload_t::mem_dtype;
+ if constexpr (remained_len >= base_len) {
+ auto reg_sub
+ = tile.reg.xetla_select<base_len * payload_t::scale_factor, 1>(
+ offset);
+ if constexpr (flag == process_flag::load) {
+ reg_sub.xetla_format<mem_dtype>() = xetla_load_local<mem_dtype,
+ base_len, data_size::default_size>(
+ payload.base_address + payload.address + address_offset);
+ } else {
+ xetla_store_local<mem_dtype, base_len>(
+ payload.base_address + payload.address + address_offset,
+ reg_sub.xetla_format<mem_dtype>());
+ }
+ process_1d_tail<remained_len - base_len, (base_len >> 1), flag, L1, L2,
+ payload_t, tile_t>(tile, payload,
+ offset + base_len * payload_t::scale_factor,
+ address_offset
+ + base_len * payload_t::scale_factor
+ * sizeof(typename tile_t::dtype));
+ } else {
+ process_1d_tail<remained_len, (base_len >> 1), flag, L1, L2, payload_t,
+ tile_t>(tile, payload, offset, address_offset);
+ }
+}
+
+// This will end up with base_len equal to 8 because we had made tile_size_x
+// divisible by 8/16/32, depends on dtype
+// this is for prefetch only and use different func arg compare with load/store
+template <uint32_t remained_len, uint32_t base_len, cache_hint L1,
+ cache_hint L2, typename payload_t>
+__XETLA_API typename std::enable_if_t<(base_len < 8)> process_1d_tail(
+ payload_t &payload, uint32_t offset) {
+ using dtype = typename payload_t::dtype;
+ using prefetch_dtype = typename payload_t::prefetch_dtype;
+ uint32_t address_offset = offset * sizeof(dtype);
+ constexpr uint32_t prefetch_min_size = 64 / sizeof(prefetch_dtype);
+ if constexpr (remained_len > 0) {
+ xetla_prefetch_global<prefetch_dtype, prefetch_min_size,
+ data_size::default_size, L1, L2>(
+ payload.base_ptr, payload.base_offset + address_offset);
+ }
+}
+
+template <uint32_t remained_len, uint32_t base_len, cache_hint L1,
+ cache_hint L2, typename payload_t>
+__XETLA_API typename std::enable_if_t<base_len >= 8> process_1d_tail(
+ payload_t &payload, uint32_t offset) {
+ using dtype = typename payload_t::dtype;
+ using prefetch_dtype = typename payload_t::prefetch_dtype;
+ if constexpr (remained_len >= base_len) {
+ uint32_t address_offset = offset * sizeof(dtype);
+ xetla_prefetch_global<prefetch_dtype, base_len, data_size::default_size,
+ L1, L2>(payload.base_ptr, payload.base_offset + address_offset);
+ process_1d_tail<remained_len - base_len, (base_len >> 1), L1, L2,
+ payload_t>(
+ payload, offset + base_len * payload_t::scale_factor);
+ } else {
+ process_1d_tail<remained_len, (base_len >> 1), L1, L2, payload_t>(
+ payload, offset);
+ }
+}
+
+template <uint32_t num_tdesc, uint32_t size_x, uint32_t size_y,
+ uint32_t scale_factor, uint8_t arr_len, bool trans>
+__XETLA_API static void reset_tile_desc_core(
+ xetla_matrix_ref<uint32_t, num_tdesc, 16> __REF__ payload_row) {
+#pragma unroll
+ for (int j = 0; j < num_tdesc; j++) {
+ constexpr uint8_t block_width
+ = trans ? (size_y / scale_factor) : (size_x / scale_factor);
+ constexpr uint8_t block_height = trans ? size_x : size_y;
+ constexpr uint32_t block_widthx_widthy_arrlen = (block_width - 1)
+ | ((block_height - 1) << 8) | ((arr_len - 1) << 16);
+ gpu::xetla::detail::xetla_set_block_widthx_widthy_arrlen(
+ payload_row.row(j), block_widthx_widthy_arrlen);
+ }
+}
+
+} // namespace detail
+
+template <typename T_dst, typename T_src>
+struct is_same_layout {
+ static constexpr bool value = (T_src::block_size_y == T_dst::block_size_y)
+ && (T_src::block_size_x == T_dst::block_size_x)
+ && (T_src::tile_size_y == T_dst::tile_size_y)
+ && (T_src::tile_size_x == T_dst::tile_size_x);
+};
+
+template <typename T_dst, typename T_src>
+struct is_1d_src {
+ static constexpr bool value = (T_src::tile_elems == T_dst::tile_elems)
+ && (T_src::block_size_y == 1) && (T_src::tile_size_y == 1);
+};
+
+template <typename T_dst, typename T_src>
+struct is_same_tile {
+ static constexpr bool value = (T_src::tile_size_y == T_dst::tile_size_y)
+ && (T_src::tile_size_x == T_dst::tile_size_x);
+};
+
+template <typename T_dst, typename T_src>
+struct is_same_elements {
+ static constexpr bool value = (T_src::tile_elems == T_dst::tile_elems);
+};
+
+template <typename T_dst, typename T_src>
+struct is_floating_to_integer {
+ static constexpr bool value
+ = is_floating_point<typename T_src::dtype>::value
+ && is_integral<typename T_dst::dtype>::value;
+};
+
+template <typename tile_desc_, mem_space memory_space,
+ mem_layout memory_layout = mem_layout::row_major>
+struct msg_type_query {
+ static constexpr msg_type value = memory_space == mem_space::global
+ ? (((tile_desc_::tile_size_y == 1)
+ && (memory_layout == mem_layout::row_major))
+ ? msg_type::block_1d
+ : msg_type::block_2d)
+ : (((tile_desc_::tile_size_y == 1)
+ && (memory_layout == mem_layout::row_major))
+ ? msg_type::block_1d
+ : msg_type::scatter);
+};
+
+template <typename tile_desc_, mem_space memory_space>
+constexpr msg_type msg_type_v = msg_type_query<tile_desc_, memory_space>::value;
+
+template <typename dtype, uint32_t tile_size_x, uint32_t tile_size_y,
+ gpu_arch arch_tag, mem_layout mem_layout_ = mem_layout::row_major,
+ reg_layout reg_layout_ = reg_layout::tiled>
+struct get_load_block_size_auto {};
+
+template <typename dtype, uint32_t tile_size_x, uint32_t tile_size_y>
+struct get_load_block_size_auto<dtype, tile_size_x, tile_size_y, gpu_arch::Xe,
+ mem_layout::row_major, reg_layout::tiled> {
+private:
+ using load_store_attr = arch_attr_t<gpu_arch::Xe>::template load_store_attr<
+ msg_type::block_2d>;
+ static constexpr uint32_t max_load_height_in_elem
+ = load_store_attr::max_load_height_in_elem;
+ static constexpr uint32_t max_load_width_in_bytes
+ = load_store_attr::max_load_width_in_bytes;
+ static constexpr uint32_t max_load_width_in_elem
+ = max_load_width_in_bytes / sizeof(dtype);
+
+public:
+ // block_size_x should be power of 2 and tile_size_x should be divided by block_size_x
+ static constexpr uint32_t block_size_x
+ = detail::gcd<tile_size_x, max_load_width_in_elem>::value;
+ static constexpr uint32_t block_size_y
+ = max_load_height_in_elem > tile_size_y ? tile_size_y
+ : max_load_height_in_elem;
+};
+
+template <typename dtype, uint32_t tile_size_x, uint32_t tile_size_y,
+ gpu_arch arch_tag, mem_layout mem_layout_ = mem_layout::row_major,
+ reg_layout reg_layout_ = reg_layout::tiled>
+struct get_store_block_size_auto {};
+
+template <typename dtype, uint32_t tile_size_x, uint32_t tile_size_y>
+struct get_store_block_size_auto<dtype, tile_size_x, tile_size_y, gpu_arch::Xe,
+ mem_layout::row_major, reg_layout::tiled> {
+private:
+ using load_store_attr = arch_attr_t<gpu_arch::Xe>::template load_store_attr<
+ msg_type::block_2d>;
+ static constexpr uint32_t max_store_height_in_elem
+ = load_store_attr::max_store_height_in_elem;
+ static constexpr uint32_t max_store_width_in_bytes
+ = load_store_attr::max_store_width_in_bytes;
+ static constexpr uint32_t max_store_width_in_elem
+ = max_store_width_in_bytes / sizeof(dtype);
+
+public:
+ // block_size_x should be power of 2 and tile_size_x should be divided by block_size_x
+ static constexpr uint32_t block_size_x
+ = detail::gcd<tile_size_x, max_store_width_in_elem>::value;
+ static constexpr uint32_t block_size_y
+ = max_store_height_in_elem > tile_size_y ? tile_size_y
+ : max_store_height_in_elem;
+};
+
+// This type tag represents "global atomic oob check on" behavior
+struct global_atomic_oob_check_on_tag : std::true_type {};
+
+// This type tag represents "global atomic oob check off" behavior
+struct global_atomic_oob_check_off_tag : std::false_type {};
+
+} // namespace gpu::xetla::subgroup
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/subgroup/tile/impl/fma_xe.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/subgroup/tile/impl/fma_xe.hpp
new file mode 100644
index 00000000000..1726fde47a0
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/subgroup/tile/impl/fma_xe.hpp
@@ -0,0 +1,255 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#include "subgroup/tile/api.hpp"
+
+namespace gpu::xetla::subgroup {
+
+/// @brief Is the tile mma operation functor, specialized for Xe and fpu engine.
+template <typename matAcc_dst_t_, typename matAcc_src_t_, typename matB_t_,
+ typename matA_t_, gpu_arch arch_tag_>
+struct tile_mma_t<matAcc_dst_t_, matAcc_src_t_, matB_t_, matA_t_,
+ mma_engine::fpu, arch_tag_,
+ std::enable_if_t<(arch_tag_ == gpu_arch::Xe)>> {
+ using matA_t = matA_t_;
+ using matB_t = matB_t_;
+ using matSrc_t = matAcc_src_t_;
+ using matDst_t = matAcc_dst_t_;
+ using dtype_a = typename matA_t::dtype;
+ using dtype_b = typename matB_t::dtype;
+ using dtype_src = typename matSrc_t::dtype;
+ using dtype_dst = typename matDst_t::dtype;
+
+ using register_attr =
+ typename arch_attr_t<arch_tag_>::template register_attr<>;
+
+ static_assert(matA_t::reg_transpose,
+ "For FMAOp GEMM, the register layout of matA should be col-major");
+ static_assert(!matB_t::reg_transpose,
+ "For FMAOp GEMM, the register layout of matB should be row-major");
+
+ static constexpr uint32_t a_tile_size_y = matA_t::tile_size_y;
+ static constexpr uint32_t a_tile_size_x = matA_t::tile_size_x;
+ static constexpr uint32_t a_tile_elems = matA_t::tile_elems;
+ static constexpr uint32_t a_block_size_w = matA_t::block_size_y;
+ static constexpr uint32_t a_block_size_h = matA_t::block_size_x;
+ static constexpr uint32_t a_block_elems = matA_t::block_elems;
+
+ static constexpr uint32_t b_tile_size_x = matB_t::tile_size_x;
+ static constexpr uint32_t b_tile_size_y = matB_t::tile_size_y;
+ static constexpr uint32_t b_tile_elems = matB_t::tile_elems;
+ static constexpr uint32_t b_block_size_x = matB_t::block_size_x;
+ static constexpr uint32_t b_block_size_y = matB_t::block_size_y;
+ static constexpr uint32_t b_block_elems = matB_t::block_elems;
+
+ static constexpr uint32_t tile_size_m = matDst_t::tile_size_y;
+ static constexpr uint32_t tile_size_k = a_tile_size_x;
+ static constexpr uint32_t tile_size_n = matDst_t::tile_size_x;
+ static constexpr uint32_t tile_elems = tile_size_m * tile_size_n;
+ static constexpr uint32_t block_size_n = matDst_t::block_size_x;
+ static constexpr uint32_t block_size_k = a_block_size_h;
+ static constexpr uint32_t block_size_m = matDst_t::block_size_y;
+ static constexpr uint32_t block_elems = block_size_m * block_size_n;
+
+ static_assert(tile_size_m == matA_t::tile_size_y,
+ "matAcc tile m should match with matA tile m");
+ static_assert(a_tile_size_x == b_tile_size_y,
+ "matA tile k should match with matB tile k");
+ static_assert(tile_size_n == matB_t::tile_size_x,
+ "matAcc tile n should match with matB tile n");
+ static_assert(block_size_m == a_block_size_w,
+ "matAcc block m should match with matA block m");
+ static_assert(block_size_n == b_block_size_x,
+ "matAcc block n should match with matB block n");
+ static_assert((tile_size_k % block_size_k) == 0,
+ "matAcc tile_size_k should be a multiple of block_size_k");
+
+ static constexpr int32_t num_block_n = matDst_t::num_block_x;
+ static constexpr int32_t num_block_m = matDst_t::num_block_y;
+ static constexpr int32_t num_block_k = tile_size_k / block_size_k;
+
+ static constexpr int32_t mma_m = register_attr::acc_reg_in_bytes
+ / (block_size_n * sizeof(dtype_dst));
+
+ template <int blk_m, int blk_n, int blk_k>
+ __XETLA_API static void mma_core(
+ xetla_vector_ref<dtype_dst, blk_m * blk_n> __REF__ dst,
+ xetla_vector_ref<dtype_src, blk_m * blk_n> __REF__ src,
+ xetla_vector_ref<dtype_b, blk_k * blk_n> __REF__ b_block,
+ xetla_vector_ref<dtype_a, blk_m * blk_k> __REF__ a_block) {
+ auto dst_blk_2d = dst.xetla_format<dtype_dst, blk_m, blk_n>();
+ auto b_blk_2d = b_block.xetla_format<dtype_dst, blk_k, blk_n>();
+ auto src_blk_2d = src.xetla_format<dtype_src, blk_m, blk_n>();
+#pragma unroll
+ for (int i = 0; i < blk_m / mma_m; i++) {
+ xetla_vector<dtype_dst, mma_m * blk_n> dst_tmp;
+ auto dst_tmp_2d = dst_tmp.xetla_format<dtype_dst, mma_m, blk_n>();
+#pragma unroll
+ for (int i_acc = 0; i_acc < mma_m; i_acc++) {
+ dst_tmp_2d.row(i_acc)
+ = a_block[i_acc + i * mma_m] * b_blk_2d.row(0)
+ + src_blk_2d.row(i_acc + i * mma_m);
+ }
+#pragma unroll
+ for (int k = 1; k < blk_k - 1; k++) {
+ for (int i_acc = 0; i_acc < mma_m; i_acc++) {
+ int a_offset = k * blk_m + i_acc + i * mma_m;
+ dst_tmp_2d.row(i_acc)
+ += a_block[a_offset] * b_blk_2d.row(k);
+ }
+ }
+ for (int i_acc = 0; i_acc < mma_m; i_acc++) {
+ int a_offset = (blk_k - 1) * blk_m + i_acc + i * mma_m;
+ dst_blk_2d.row(i_acc + i * mma_m)
+ = a_block[a_offset] * b_blk_2d.row(blk_k - 1)
+ + dst_tmp_2d.row(i_acc);
+ }
+ SW_BARRIER();
+ }
+
+ if constexpr ((blk_m % mma_m) != 0) {
+ constexpr uint32_t tail_start_m = blk_m / mma_m * mma_m;
+ constexpr uint32_t tail_m = blk_m % mma_m;
+ xetla_vector<dtype_dst, tail_m * blk_n> dst_tmp;
+ auto dst_tmp_2d = dst_tmp.xetla_format<dtype_dst, tail_m, blk_n>();
+#pragma unroll
+ for (int i_acc = 0; i_acc < tail_m; i_acc++) {
+ dst_tmp_2d.row(i_acc)
+ = a_block[i_acc + tail_start_m] * b_blk_2d.row(0)
+ + src_blk_2d.row(i_acc + tail_start_m);
+ }
+#pragma unroll
+ for (int k = 1; k < blk_k - 1; k++) {
+ for (int i_acc = 0; i_acc < tail_m; i_acc++) {
+ int a_offset = k * blk_m + i_acc + tail_start_m;
+ dst_tmp_2d.row(i_acc)
+ += a_block[a_offset] * b_blk_2d.row(k);
+ }
+ }
+ for (int i_acc = 0; i_acc < tail_m; i_acc++) {
+ int a_offset = (blk_k - 1) * blk_m + i_acc + tail_start_m;
+ dst_blk_2d.row(i_acc + tail_start_m)
+ = a_block[a_offset] * b_blk_2d.row(blk_k - 1)
+ + dst_tmp_2d.row(i_acc);
+ }
+ }
+ }
+
+ __XETLA_API static void mma(
+ matDst_t &dst, matSrc_t &src, matB_t &b, matA_t &a) {
+ { //k_blk=0
+ auto b_reg
+ = b.reg.xetla_select<b_block_size_y * b_tile_size_x, 1>(0);
+#pragma unroll
+ for (int i = 0; i < tile_size_m / block_size_m; i++) {
+ auto a_block = a.reg.xetla_select<a_block_elems, 1>(
+ i * num_block_k * a_block_elems);
+#pragma unroll
+ for (int j = 0; j < num_block_n; j++) {
+ auto b_block = b_reg.xetla_select<b_block_elems, 1>(
+ j * b_block_elems);
+ auto src_block = src.reg.xetla_select<block_elems, 1>(
+ (i * num_block_n + j) * block_elems);
+ auto dst_block = dst.reg.xetla_select<block_elems, 1>(
+ (i * num_block_n + j) * block_elems);
+ mma_core<block_size_m, block_size_n, block_size_k>(
+ dst_block, src_block, b_block, a_block);
+ }
+ }
+
+ // process the tail
+ if constexpr ((tile_size_m % block_size_m) != 0) {
+ constexpr uint32_t tail_start_m
+ = tile_size_m / block_size_m * block_size_m;
+ constexpr uint32_t a_tail_blk_w = a_tile_size_y - tail_start_m;
+ constexpr uint32_t a_tail_blk_elems
+ = a_block_size_h * a_tail_blk_w;
+ constexpr uint32_t tail_size_m = tile_size_m - tail_start_m;
+ constexpr uint32_t acc_tail_blk_elems
+ = tail_size_m * block_size_n;
+ auto a_block = a.reg.xetla_select<a_tail_blk_elems, 1>(
+ a_tile_size_x * tail_start_m);
+#pragma unroll
+ for (int j = 0; j < num_block_n; j++) {
+ auto b_block = b_reg.xetla_select<b_block_elems, 1>(
+ j * b_block_elems);
+ auto src_block
+ = src.reg.xetla_select<acc_tail_blk_elems, 1>(
+ (tail_start_m * tile_size_n)
+ + j * acc_tail_blk_elems);
+ auto dst_block
+ = dst.reg.xetla_select<acc_tail_blk_elems, 1>(
+ (tail_start_m * tile_size_n)
+ + j * acc_tail_blk_elems);
+ mma_core<tail_size_m, block_size_n, block_size_k>(
+ dst_block, src_block, b_block, a_block);
+ }
+ }
+ }
+ // different K block
+#pragma unroll
+ for (int k_i = 1; k_i < num_block_k; k_i++) {
+
+ auto b_reg = b.reg.xetla_select<b_block_size_y * b_tile_size_x, 1>(
+ k_i * b_block_size_y * b_tile_size_x);
+#pragma unroll
+ for (int i = 0; i < tile_size_m / block_size_m; i++) {
+ auto a_block = a.reg.xetla_select<a_block_elems, 1>(
+ (i * num_block_k + k_i) * a_block_elems);
+#pragma unroll
+ for (int j = 0; j < num_block_n; j++) {
+ auto b_block = b_reg.xetla_select<b_block_elems, 1>(
+ j * b_block_elems);
+ auto dst_block = dst.reg.xetla_select<block_elems, 1>(
+ (i * num_block_n + j) * block_elems);
+ mma_core<block_size_m, block_size_n, block_size_k>(
+ dst_block, dst_block, b_block, a_block);
+ }
+ }
+ // process the tail
+ if constexpr ((tile_size_m % block_size_m) != 0) {
+ constexpr uint32_t tail_start_m
+ = tile_size_m / block_size_m * block_size_m;
+ constexpr uint32_t a_tail_blk_w = a_tile_size_y - tail_start_m;
+ constexpr uint32_t a_tail_blk_elems
+ = a_block_size_h * a_tail_blk_w;
+ constexpr uint32_t tail_size_m = tile_size_m - tail_start_m;
+ constexpr uint32_t acc_tail_blk_elems
+ = tail_size_m * block_size_n;
+ auto a_block = a.reg.xetla_select<a_tail_blk_elems, 1>(
+ a_tile_size_x * tail_start_m + k_i * a_tail_blk_elems);
+#pragma unroll
+ for (int j = 0; j < num_block_n; j++) {
+ auto b_block = b_reg.xetla_select<b_block_elems, 1>(
+ j * b_block_elems);
+ auto dst_block
+ = dst.reg.xetla_select<acc_tail_blk_elems, 1>(
+ (tail_start_m * tile_size_n)
+ + j * acc_tail_blk_elems);
+ mma_core<tail_size_m, block_size_n, block_size_k>(
+ dst_block, dst_block, b_block, a_block);
+ }
+ }
+ }
+ }
+};
+
+} // namespace gpu::xetla::subgroup
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/subgroup/tile/impl/load_xe.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/subgroup/tile/impl/load_xe.hpp
new file mode 100644
index 00000000000..16a0fb62ab0
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/subgroup/tile/impl/load_xe.hpp
@@ -0,0 +1,926 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#include "subgroup/tile/api.hpp"
+#include "subgroup/tile/impl/op_function.hpp"
+#include "subgroup/tile/impl/payload_xe.hpp"
+
+namespace gpu::xetla::subgroup {
+
+namespace detail {
+template <typename tile_t, typename payload_t>
+struct check_load_type {
+ static constexpr bool is_global_2d_xe
+ = (payload_t::memory_space == mem_space::global
+ && (payload_t::message_type == msg_type::block_2d)
+ && (payload_t::arch_tag == gpu_arch::Xe));
+
+ static constexpr bool is_global_block_1d_xe
+ = ((payload_t::memory_space == mem_space::global)
+ && (tile_t::tile_size_y == 1) && (tile_t::block_size_y == 1)
+ && (payload_t::message_type == msg_type::block_1d)
+ && (payload_t::arch_tag == gpu_arch::Xe));
+
+ static constexpr bool is_global_unaligned_2d_xe
+ = ((payload_t::memory_space == mem_space::global)
+ && (payload_t::message_type == msg_type::unaligned_2d)
+ && (payload_t::arch_tag == gpu_arch::Xe));
+
+ static constexpr bool is_local_scatter_xe
+ = ((payload_t::memory_space == mem_space::local)
+ && (payload_t::message_type == msg_type::scatter)
+ && (payload_t::arch_tag == gpu_arch::Xe));
+
+ static constexpr bool is_local_block_1d_xe
+ = ((payload_t::memory_space == mem_space::local)
+ && (tile_t::block_size_y == 1)
+ && (payload_t::message_type == msg_type::block_1d)
+ && (payload_t::arch_tag == gpu_arch::Xe));
+};
+
+} // namespace detail
+
+/// @brief This function loads data from 2D memory surface.
+/// Loads an array of rectangular regions (X,Y)..(X+W,Y+H) from memory into registers.
+/// Each block will be loaded serially by its corresponding payload.
+/// @tparam tile_t Is the tile_t struct contains registers.
+/// These registers will be the destination of load operation.
+/// @tparam payload_t Is the mem_payload_t struct describing the memory information
+/// Payload indicates the source of load operation.
+/// @tparam L1 Is the cache hint for L1 cache.
+/// @tparam L2 Is the cache hint for L2 cache.
+/// @param tile Is the tile object with type tile_t, holds the return data of the loads.
+/// @param payload Is the payload object with type payload_t. Contains all the information for loads.
+/// @return No return, update in place.
+template <cache_hint L1 = cache_hint::cached,
+ cache_hint L2 = cache_hint::cached, typename tile_t, typename payload_t>
+__XETLA_API typename std::enable_if_t<tile_t::dst
+ && detail::check_load_type<tile_t, payload_t>::is_global_2d_xe>
+tile_load(tile_t &tile, payload_t &payload) {
+ using dtype = typename tile_t::dtype;
+ using load_dtype = typename payload_t::mem_dtype;
+ using tile_desc = typename tile_t::tile_desc;
+ using check_load = typename subgroup::check_load<gpu_arch::Xe, dtype,
+ load_dtype>::template global_2d<payload_t::mem_transform,
+ tile_desc::block_size_x>;
+
+ static constexpr uint32_t tile_size_x = tile_desc::tile_size_x;
+ static constexpr uint32_t tile_size_y = tile_desc::tile_size_y;
+ static constexpr uint32_t block_size_x = tile_desc::block_size_x;
+ static constexpr uint32_t block_size_y = tile_desc::block_size_y;
+ static constexpr uint32_t remained_size_y = tile_desc::remained_size_y;
+
+ static constexpr uint32_t block_elems = tile_desc::block_elems;
+
+ static constexpr uint32_t num_block_x = tile_desc::num_block_x;
+ static constexpr uint32_t num_block_y = tile_desc::num_block_y;
+ static constexpr uint32_t num_block = tile_desc::num_block;
+
+ static constexpr gpu_arch arch_tag = payload_t::arch_tag;
+
+ static constexpr reg_layout reg_layout_ = tile_desc::register_layout;
+ static constexpr bool is_vnni_reverse = payload_t::mem_dword_transpose
+ && ((reg_layout_ == reg_layout::tiled)
+ || (reg_layout_ == reg_layout::transpose_tiled));
+ static constexpr bool reg_transpose = tile_desc::reg_transpose;
+
+ static constexpr mem_layout mem_layout_ = payload_t::memory_layout;
+ static constexpr bool mem_transpose = payload_t::mem_transpose;
+ static constexpr bool trans = reg_transpose ^ mem_transpose;
+ static constexpr uint32_t scale_factor = payload_t::scale_factor;
+
+ static constexpr bool mem_transform = payload_t::mem_transform;
+
+ using load_store_attr = typename arch_attr_t<
+ arch_tag>::template load_store_attr<msg_type::block_2d>;
+ static constexpr uint32_t elems_per_CL
+ = load_store_attr::cache_line_size_in_bytes / sizeof(dtype);
+ static constexpr uint32_t elems_per_reg
+ = arch_attr_t<arch_tag>::template register_attr<>::reg_in_bytes
+ / sizeof(dtype);
+ static constexpr int32_t max_load_block_height
+ = load_store_attr::max_load_height_in_elem;
+ static constexpr int32_t max_block_width
+ = load_store_attr::max_load_width_in_bytes / sizeof(dtype);
+ static constexpr int32_t max_trans_block_width
+ = load_store_attr::max_trans_load_width_in_bytes / sizeof(dtype);
+ static constexpr int32_t special_trans_block_width
+ = load_store_attr::special_trans_load_width_in_bytes
+ / sizeof(dtype);
+ static constexpr int32_t trans_block_width_limit
+ = (block_size_y % special_trans_block_width) == 0
+ ? special_trans_block_width
+ : max_trans_block_width;
+ static constexpr int32_t max_vnni_block_width
+ = load_store_attr::max_vnni_load_width_in_elems;
+
+ static constexpr uint32_t ld_blk_size_y_limit
+ = mem_transpose ? trans_block_width_limit : max_load_block_height;
+ static constexpr uint32_t ld_blk_size_y = reg_transpose
+ ? block_size_y
+ : (block_size_y > ld_blk_size_y_limit ? ld_blk_size_y_limit
+ : block_size_y);
+
+ // array len is used to make sure memory load is cache line aligned
+ // disabled while register or memory transpose
+ static constexpr uint8_t arr_len_candidate
+ = (reg_transpose
+ || mem_transpose
+ // block elements should be integer
+ // times of register bytes
+ || ((block_size_y * block_size_x) % elems_per_reg != 0)
+ // tail blocks also need to meet above condition
+ || (((tile_size_y % block_size_y) * block_size_x)
+ % elems_per_reg
+ != 0))
+ || (block_size_y > ld_blk_size_y_limit)
+ ? 1
+ : (((tile_size_x % elems_per_CL) == 0)
+ ? (((elems_per_CL % block_size_x) == 0)
+ ? elems_per_CL / block_size_x
+ : 1)
+ : ((tile_size_x < elems_per_CL)
+ ? (tile_size_x / block_size_x)
+ : 1));
+ static constexpr bool is_valid_arr_len_candidate = (arr_len_candidate == 1)
+ || (arr_len_candidate == 2) || (arr_len_candidate == 4);
+
+ static constexpr uint8_t arr_len
+ = is_valid_arr_len_candidate ? arr_len_candidate : 1;
+
+ static_assert(reg_transpose || mem_transpose
+ || (!mem_transpose
+ && (block_size_x * arr_len) <= max_block_width),
+ "When reg_transpose was disabled, check 2d block width "
+ "restriction");
+ static_assert(!reg_transpose
+ || (!mem_transpose
+ && (block_size_x * arr_len)
+ <= trans_block_width_limit)
+ || (mem_transpose
+ && (block_size_y * arr_len) <= max_block_width),
+ "When reg_transpose was enabled, check 2d block width "
+ "restriction");
+ static_assert(!reg_transpose
+ || (!mem_transpose
+ && (block_size_y <= max_load_block_height))
+ || (mem_transpose
+ && (block_size_x) <= max_load_block_height),
+ "When reg_transpose was enabled, check 2d block height "
+ "restriction");
+ static_assert(tile_size_x % (block_size_x * arr_len) == 0,
+ "tile_size_x should be a multiple of (block_size_x * arr_len)");
+ static_assert(
+ (reg_transpose
+ && ((block_size_x * sizeof(dtype)) % sizeof(load_dtype)
+ == 0))
+ || ((block_size_y * sizeof(dtype)) % sizeof(load_dtype)
+ == 0),
+ "check vnni limitation for DW transpose");
+
+ auto payload_2d = payload.payloads.xetla_format<uint32_t, num_block, 16>();
+ uint32_t base_offset_y = 0;
+#pragma unroll
+ for (int i = 0; i < num_block_y; ++i) {
+ constexpr uint32_t load_block_elems = block_elems * arr_len;
+ auto payload_row = payload_2d.xetla_select<num_block_x, 1, 16, 1>(
+ i * num_block_x, 0);
+ detail::reset_tile_desc_core<num_block_x, block_size_x, ld_blk_size_y,
+ scale_factor, arr_len, mem_transpose>(payload_row);
+#pragma unroll
+ for (int j = 0; j < num_block_x; j += arr_len) {
+ xetla_tdescriptor tdesc = payload_row.row(j);
+ auto reg_blk = tile.reg.xetla_select<load_block_elems, 1>(
+ (i * num_block_x + j) * block_elems);
+ constexpr uint32_t ld_blk_height = (reg_transpose && trans)
+ ? detail::getNextPowerOf2<ld_blk_size_y>()
+ : ld_blk_size_y;
+ constexpr uint32_t tmp_size
+ = ld_blk_height * block_size_x * arr_len;
+ xetla_vector<dtype, tmp_size> reg_tmp;
+#pragma unroll
+ for (int ii = 0; ii < block_size_y / ld_blk_size_y; ++ii) {
+ constexpr uint32_t load_elems
+ = ld_blk_size_y * block_size_x * arr_len;
+
+ reg_tmp.xetla_format<native_type_t<load_dtype>>()
+ = xetla_tload_global<load_dtype,
+ ld_blk_height * block_size_x * arr_len
+ / scale_factor,
+ L1, L2, trans, mem_transform, arch_tag>(tdesc);
+
+ if constexpr (reg_transpose && trans) {
+ reg_blk.xetla_select<load_elems, 1>(ii * load_elems)
+ .xetla_format<native_type_t<load_dtype>>()
+ = reg_tmp.xetla_format<load_dtype,
+ block_size_x / scale_factor,
+ ld_blk_height>()
+ .xetla_select<block_size_x / scale_factor,
+ 1, ld_blk_size_y, 1>(0, 0);
+ } else {
+ reg_blk.xetla_select<tmp_size, 1>(ii * tmp_size) = reg_tmp;
+ }
+
+ if constexpr (mem_transpose) {
+ xetla_update_tdesc_offsetx(tdesc.xetla_format<uint32_t>(),
+ ld_blk_size_y / scale_factor);
+ } else {
+ xetla_update_tdesc_offsety(
+ tdesc.xetla_format<uint32_t>(), ld_blk_size_y);
+ }
+ }
+ // exceed HW limitation
+ if constexpr (block_size_y % ld_blk_size_y != 0) {
+ constexpr uint32_t remained_start_y
+ = block_size_y / ld_blk_size_y * ld_blk_size_y;
+ constexpr uint32_t remained_start
+ = remained_start_y * block_size_x * arr_len;
+ constexpr uint32_t remained_blk_size_y
+ = block_size_y % ld_blk_size_y;
+ constexpr uint32_t load_elems
+ = remained_blk_size_y * block_size_x * arr_len;
+
+ constexpr uint8_t block_width = mem_transpose
+ ? (remained_blk_size_y / scale_factor)
+ : block_size_x;
+ constexpr uint8_t block_height
+ = trans ? block_size_x : remained_blk_size_y;
+ constexpr uint32_t block_widthx_widthy_arrlen
+ = (block_width - 1) | ((block_height - 1) << 8);
+ gpu::xetla::detail::xetla_set_block_widthx_widthy_arrlen(
+ tdesc.xetla_format<uint32_t>(),
+ block_widthx_widthy_arrlen);
+
+ reg_blk.xetla_select<load_elems, 1>(remained_start)
+ .xetla_format<native_type_t<load_dtype>>()
+ = xetla_tload_global<load_dtype,
+ (load_elems / scale_factor), L1, L2, trans,
+ mem_transform, arch_tag>(tdesc);
+ }
+ }
+ }
+ // process tail
+ if constexpr (remained_size_y > 0) {
+ constexpr uint32_t remained_block_elems
+ = block_size_x * remained_size_y;
+ constexpr uint32_t processed_elems
+ = num_block_y * num_block_x * block_elems;
+
+ static constexpr int32_t tail_trans_block_width_limit
+ = (remained_size_y % special_trans_block_width) == 0
+ ? special_trans_block_width
+ : max_trans_block_width;
+
+ static constexpr uint32_t tail_ld_blk_size_y_limit = mem_transpose
+ ? tail_trans_block_width_limit
+ : max_load_block_height;
+
+ constexpr uint32_t remained_ld_blk_size_y
+ = (!reg_transpose
+ && (remained_size_y > tail_ld_blk_size_y_limit))
+ ? tail_ld_blk_size_y_limit
+ : remained_size_y;
+ auto payload_row = payload_2d.xetla_select<num_block_x, 1, 16, 1>(
+ num_block_y * num_block_x, 0);
+ detail::reset_tile_desc_core<num_block_x, block_size_x,
+ remained_ld_blk_size_y, scale_factor, arr_len, mem_transpose>(
+ payload_row);
+#pragma unroll
+ for (int j = 0; j < num_block_x; j += arr_len) {
+ xetla_tdescriptor tdesc = payload_row.row(j);
+ auto reg_blk
+ = tile.reg.xetla_select<remained_block_elems * arr_len, 1>(
+ processed_elems + j * remained_block_elems);
+ constexpr uint32_t ld_blk_height = (reg_transpose && trans)
+ ? detail::getNextPowerOf2<remained_ld_blk_size_y>()
+ : remained_ld_blk_size_y;
+ constexpr uint32_t tmp_size
+ = ld_blk_height * block_size_x * arr_len;
+ xetla_vector<dtype, tmp_size> reg_tmp;
+#pragma unroll
+ for (int ii = 0; ii < remained_size_y / remained_ld_blk_size_y;
+ ++ii) {
+ constexpr uint32_t load_elems
+ = remained_ld_blk_size_y * block_size_x * arr_len;
+
+ reg_tmp.xetla_format<native_type_t<load_dtype>>()
+ = xetla_tload_global<load_dtype,
+ (ld_blk_height * block_size_x * arr_len
+ / scale_factor),
+ L1, L2, trans, mem_transform, arch_tag>(tdesc);
+
+ if constexpr (reg_transpose && trans) {
+ reg_blk.xetla_select<load_elems, 1>(ii * load_elems)
+ .xetla_format<native_type_t<load_dtype>>()
+ = reg_tmp.xetla_format<load_dtype,
+ block_size_x / scale_factor,
+ ld_blk_height>()
+ .xetla_select<block_size_x / scale_factor,
+ 1, remained_ld_blk_size_y, 1>(
+ 0, 0);
+ } else {
+ reg_blk.xetla_select<tmp_size, 1>(ii * tmp_size) = reg_tmp;
+ }
+ if constexpr (mem_transpose) {
+ xetla_update_tdesc_offsetx(tdesc.xetla_format<uint32_t>(),
+ remained_ld_blk_size_y / scale_factor);
+ } else {
+ xetla_update_tdesc_offsety(tdesc.xetla_format<uint32_t>(),
+ remained_ld_blk_size_y);
+ }
+ }
+ constexpr uint32_t final_ld_blk_size_y
+ = remained_size_y % remained_ld_blk_size_y;
+ if constexpr (final_ld_blk_size_y != 0) {
+ constexpr uint32_t final_start = remained_size_y
+ / remained_ld_blk_size_y * remained_ld_blk_size_y
+ * block_size_x * arr_len;
+ constexpr uint32_t final_load_elems
+ = final_ld_blk_size_y * block_size_x * arr_len;
+ constexpr uint8_t block_width = mem_transpose
+ ? (final_ld_blk_size_y / scale_factor)
+ : block_size_x;
+ constexpr uint8_t block_height
+ = trans ? block_size_x : final_ld_blk_size_y;
+ constexpr uint32_t block_widthx_widthy_arrlen
+ = (block_width - 1) | ((block_height - 1) << 8);
+ gpu::xetla::detail::xetla_set_block_widthx_widthy_arrlen(
+ tdesc.xetla_format<uint32_t>(),
+ block_widthx_widthy_arrlen);
+ reg_blk.xetla_select<final_load_elems, 1>(final_start)
+ .xetla_format<native_type_t<load_dtype>>()
+ = xetla_tload_global<load_dtype,
+ final_load_elems / scale_factor, L1, L2, trans,
+ mem_transform, arch_tag>(tdesc);
+ }
+ }
+ }
+
+ if constexpr (is_vnni_reverse) {
+ SW_BARRIER();
+ vnni_reverse(tile);
+ }
+}
+
+template <cache_hint L1 = cache_hint::cached,
+ cache_hint L2 = cache_hint::cached, typename tile_t, typename payload_t>
+__XETLA_API typename std::enable_if_t<!tile_t::dst> tile_load(
+ tile_t &tile, payload_t &payload) {
+ using dtype = typename tile_t::dtype;
+ using load_dtype = typename payload_t::mem_dtype;
+ using tile_desc = typename tile_t::tile_desc;
+ using check_load = typename subgroup::check_load<gpu_arch::Xe, dtype,
+ load_dtype>::template global_2d<payload_t::mem_transform,
+ tile_desc::block_size_x>;
+
+ static constexpr uint32_t tile_size_x = tile_desc::tile_size_x;
+ static constexpr uint32_t tile_size_y = tile_desc::tile_size_y;
+ static constexpr uint32_t block_size_x = tile_desc::block_size_x;
+ static constexpr uint32_t block_size_y = tile_desc::block_size_y;
+ static constexpr uint32_t remained_size_y = tile_desc::remained_size_y;
+
+ static constexpr uint32_t block_elems = tile_desc::block_elems;
+
+ static constexpr uint32_t num_block_x = tile_desc::num_block_x;
+ static constexpr uint32_t num_block_y = tile_desc::num_block_y;
+ static constexpr uint32_t num_block = tile_desc::num_block;
+
+ static constexpr gpu_arch arch_tag = payload_t::arch_tag;
+
+ static constexpr reg_layout reg_layout_ = tile_desc::register_layout;
+ static constexpr bool is_vnni_reverse = payload_t::mem_dword_transpose
+ && ((reg_layout_ == reg_layout::tiled)
+ || (reg_layout_ == reg_layout::transpose_tiled));
+ static constexpr bool reg_transpose = tile_desc::reg_transpose;
+
+ static constexpr mem_layout mem_layout_ = payload_t::memory_layout;
+ static constexpr bool mem_transpose = payload_t::mem_transpose;
+ static constexpr bool trans = reg_transpose ^ mem_transpose;
+ static constexpr uint32_t scale_factor = payload_t::scale_factor;
+
+ static constexpr bool mem_transform = payload_t::mem_transform;
+
+ using load_store_attr = typename arch_attr_t<
+ arch_tag>::template load_store_attr<msg_type::block_2d>;
+ static constexpr uint32_t elems_per_CL
+ = load_store_attr::cache_line_size_in_bytes / sizeof(dtype);
+ static constexpr uint32_t elems_per_reg
+ = arch_attr_t<arch_tag>::template register_attr<>::reg_in_bytes
+ / sizeof(dtype);
+ static constexpr int32_t max_load_block_height
+ = load_store_attr::max_load_height_in_elem;
+ static constexpr int32_t max_block_width
+ = load_store_attr::max_load_width_in_bytes / sizeof(dtype);
+ static constexpr int32_t max_trans_block_width
+ = load_store_attr::max_trans_load_width_in_bytes / sizeof(dtype);
+ static constexpr int32_t special_trans_block_width
+ = load_store_attr::special_trans_load_width_in_bytes
+ / sizeof(dtype);
+ static constexpr int32_t trans_block_width_limit
+ = (block_size_y % special_trans_block_width) == 0
+ ? special_trans_block_width
+ : max_trans_block_width;
+ static constexpr int32_t max_vnni_block_width
+ = load_store_attr::max_vnni_load_width_in_elems;
+
+ static constexpr uint32_t ld_blk_size_y_limit
+ = mem_transpose ? trans_block_width_limit : max_load_block_height;
+ static constexpr uint32_t ld_blk_size_y = reg_transpose
+ ? block_size_y
+ : (block_size_y > ld_blk_size_y_limit ? ld_blk_size_y_limit
+ : block_size_y);
+
+ // array len is used to make sure memory load is cache line aligned
+ // disabled while register or memory transpose
+ static constexpr uint8_t arr_len_candidate
+ = (reg_transpose
+ || mem_transpose
+ // block elements should be integer
+ // times of register bytes
+ || ((block_size_y * block_size_x) % elems_per_reg != 0)
+ // tail blocks also need to meet above condition
+ || (((tile_size_y % block_size_y) * block_size_x)
+ % elems_per_reg
+ != 0))
+ || (block_size_y > ld_blk_size_y_limit)
+ ? 1
+ : (((tile_size_x % elems_per_CL) == 0)
+ ? (((elems_per_CL % block_size_x) == 0)
+ ? elems_per_CL / block_size_x
+ : 1)
+ : ((tile_size_x < elems_per_CL)
+ ? (tile_size_x / block_size_x)
+ : 1));
+ static constexpr bool is_valid_arr_len_candidate = (arr_len_candidate == 1)
+ || (arr_len_candidate == 2) || (arr_len_candidate == 4);
+
+ static constexpr uint8_t arr_len
+ = is_valid_arr_len_candidate ? arr_len_candidate : 1;
+
+ static_assert(reg_transpose || mem_transpose
+ || (!mem_transpose
+ && (block_size_x * arr_len) <= max_block_width),
+ "When reg_transpose was disabled, check 2d block width "
+ "restriction");
+ static_assert(!reg_transpose
+ || (!mem_transpose
+ && (block_size_x * arr_len)
+ <= trans_block_width_limit)
+ || (mem_transpose
+ && (block_size_y * arr_len) <= max_block_width),
+ "When reg_transpose was enabled, check 2d block width "
+ "restriction");
+ static_assert(!reg_transpose
+ || (!mem_transpose
+ && (block_size_y <= max_load_block_height))
+ || (mem_transpose
+ && (block_size_x) <= max_load_block_height),
+ "When reg_transpose was enabled, check 2d block height "
+ "restriction");
+ static_assert(tile_size_x % (block_size_x * arr_len) == 0,
+ "tile_size_x should be a multiple of (block_size_x * arr_len)");
+ static_assert(
+ (reg_transpose
+ && ((block_size_x * sizeof(dtype)) % sizeof(load_dtype)
+ == 0))
+ || ((block_size_y * sizeof(dtype)) % sizeof(load_dtype)
+ == 0),
+ "check vnni limitation for DW transpose");
+
+ auto payload_2d = payload.payloads.xetla_format<uint32_t, num_block, 16>();
+ uint32_t base_offset_y = 0;
+#pragma unroll
+ for (int i = 0; i < num_block_y; ++i) {
+ constexpr uint32_t load_block_elems = block_elems * arr_len;
+ auto payload_row = payload_2d.xetla_select<num_block_x, 1, 16, 1>(
+ i * num_block_x, 0);
+ detail::reset_tile_desc_core<num_block_x, block_size_x, ld_blk_size_y,
+ scale_factor, arr_len, mem_transpose>(payload_row);
+#pragma unroll
+ for (int j = 0; j < num_block_x; j += arr_len) {
+ xetla_tdescriptor tdesc = payload_row.row(j);
+ constexpr uint32_t ld_blk_height = (reg_transpose && trans)
+ ? detail::getNextPowerOf2<ld_blk_size_y>()
+ : ld_blk_size_y;
+#pragma unroll
+ for (int ii = 0; ii < block_size_y / ld_blk_size_y; ++ii) {
+ xetla_tprefetch_global<load_dtype, L1, L2, arch_tag>(tdesc);
+ if constexpr (mem_transpose) {
+ xetla_update_tdesc_offsetx(tdesc.xetla_format<uint32_t>(),
+ ld_blk_size_y / scale_factor);
+ } else {
+ xetla_update_tdesc_offsety(
+ tdesc.xetla_format<uint32_t>(), ld_blk_size_y);
+ }
+ }
+ // exceed HW limitation
+ if constexpr (block_size_y % ld_blk_size_y != 0) {
+ constexpr uint32_t remained_start_y
+ = block_size_y / ld_blk_size_y * ld_blk_size_y;
+ constexpr uint32_t remained_start
+ = remained_start_y * block_size_x * arr_len;
+ constexpr uint32_t remained_blk_size_y
+ = block_size_y % ld_blk_size_y;
+ constexpr uint32_t load_elems
+ = remained_blk_size_y * block_size_x * arr_len;
+
+ constexpr uint8_t block_width = mem_transpose
+ ? (remained_blk_size_y / scale_factor)
+ : block_size_x;
+ constexpr uint8_t block_height
+ = trans ? block_size_x : remained_blk_size_y;
+ constexpr uint32_t block_widthx_widthy_arrlen
+ = (block_width - 1) | ((block_height - 1) << 8);
+ gpu::xetla::detail::xetla_set_block_widthx_widthy_arrlen(
+ tdesc.xetla_format<uint32_t>(),
+ block_widthx_widthy_arrlen);
+ xetla_tprefetch_global<load_dtype, L1, L2, arch_tag>(tdesc);
+ }
+ }
+ }
+ // process tail
+ if constexpr (remained_size_y > 0) {
+ constexpr uint32_t remained_block_elems
+ = block_size_x * remained_size_y;
+ constexpr uint32_t processed_elems
+ = num_block_y * num_block_x * block_elems;
+
+ static constexpr int32_t tail_trans_block_width_limit
+ = (remained_size_y % special_trans_block_width) == 0
+ ? special_trans_block_width
+ : max_trans_block_width;
+
+ static constexpr uint32_t tail_ld_blk_size_y_limit = mem_transpose
+ ? tail_trans_block_width_limit
+ : max_load_block_height;
+
+ constexpr uint32_t remained_ld_blk_size_y
+ = (!reg_transpose
+ && (remained_size_y > tail_ld_blk_size_y_limit))
+ ? tail_ld_blk_size_y_limit
+ : remained_size_y;
+ auto payload_row = payload_2d.xetla_select<num_block_x, 1, 16, 1>(
+ num_block_y * num_block_x, 0);
+ detail::reset_tile_desc_core<num_block_x, block_size_x,
+ remained_ld_blk_size_y, scale_factor, arr_len, mem_transpose>(
+ payload_row);
+#pragma unroll
+ for (int j = 0; j < num_block_x; j += arr_len) {
+ xetla_tdescriptor tdesc = payload_row.row(j);
+ constexpr uint32_t ld_blk_height = (reg_transpose && trans)
+ ? detail::getNextPowerOf2<remained_ld_blk_size_y>()
+ : remained_ld_blk_size_y;
+#pragma unroll
+ for (int ii = 0; ii < remained_size_y / remained_ld_blk_size_y;
+ ++ii) {
+ xetla_tprefetch_global<load_dtype, L1, L2, arch_tag>(tdesc);
+ }
+ constexpr uint32_t final_ld_blk_size_y
+ = remained_size_y % remained_ld_blk_size_y;
+ if constexpr (final_ld_blk_size_y != 0) {
+ constexpr uint32_t final_start = remained_size_y
+ / remained_ld_blk_size_y * remained_ld_blk_size_y
+ * block_size_x * arr_len;
+ constexpr uint32_t final_load_elems
+ = final_ld_blk_size_y * block_size_x * arr_len;
+ constexpr uint8_t block_width = mem_transpose
+ ? (final_ld_blk_size_y / scale_factor)
+ : block_size_x;
+ constexpr uint8_t block_height
+ = trans ? block_size_x : final_ld_blk_size_y;
+ constexpr uint32_t block_widthx_widthy_arrlen
+ = (block_width - 1) | ((block_height - 1) << 8);
+ gpu::xetla::detail::xetla_set_block_widthx_widthy_arrlen(
+ tdesc.xetla_format<uint32_t>(),
+ block_widthx_widthy_arrlen);
+ xetla_tprefetch_global<load_dtype, L1, L2, arch_tag>(tdesc);
+ }
+ }
+ }
+}
+
+/// @brief This function loads data from memory.
+/// For each enabled SIMT lane, a vector is read from memory into registers.
+/// @tparam tile_t Is the tile_t struct contains registers.
+/// These registers will be the destination of load operation.
+/// @tparam payload_t Is the mem_payload_t struct describing the memory information.
+/// Payload indicates the source of load operation.
+/// @tparam L1 Is the cache hint for L1 cache.
+/// @tparam L2 Is the cache hint for L2 cache.
+/// @param tile Is the tile object with type tile_t, holds the return data of the loads.
+/// @param payload Is the payload object with type payload_t. Contains all the information for loads.
+/// @return No return, update in place.
+template <cache_hint L1 = cache_hint::cached,
+ cache_hint L2 = cache_hint::cached, typename tile_t, typename payload_t>
+__XETLA_API typename std::enable_if_t<
+ detail::check_load_type<tile_t, payload_t>::is_global_block_1d_xe>
+tile_load(tile_t &tile, payload_t &payload) {
+ using dtype = typename tile_t::dtype;
+ using load_dtype = typename payload_t::mem_dtype;
+ using check_load = typename subgroup::check_load<gpu_arch::Xe, dtype,
+ load_dtype>::global_1d;
+
+ static constexpr uint32_t tile_size_x = tile_t::tile_size_x;
+ static constexpr uint32_t scale_factor = payload_t::scale_factor;
+ constexpr uint32_t load_len = tile_size_x / scale_factor;
+
+ if constexpr (load_len >= 64) {
+#pragma unroll
+ for (int i = 0; i < load_len / 64; i++) {
+ uint32_t offset_x = i * 64 * scale_factor;
+ auto reg_sub
+ = tile.reg.xetla_select<64 * scale_factor, 1>(offset_x);
+ uint32_t address_offset = offset_x * sizeof(dtype);
+ reg_sub.xetla_format<load_dtype>() = xetla_load_global<load_dtype,
+ 64, data_size::default_size, L1, L2>(
+ payload.base_ptr, payload.base_offset + address_offset);
+ }
+ }
+ constexpr uint32_t tail_len = load_len % 64;
+ uint32_t tail_offset = load_len / 64 * 64 * scale_factor;
+ detail::process_1d_tail<tail_len, 32, detail::process_flag::load, L1, L2>(
+ tile, payload, tail_offset);
+}
+
+/// @brief This function loads data from unaligned-2D memory surface.
+/// Loads an array of rectangular regions (X,Y)..(X+W,Y+H) from memory into registers.
+/// Each block will be loaded serially by its corresponding payload.
+/// @tparam tile_t Is the tile_t struct contains registers.
+/// These registers will be the destination of load operation.
+/// @tparam payload_t Is the mem_payload_t struct describing the memory information.
+/// Payload indicates the source of load operation.
+/// @tparam L1 Is the cache hint for L1 cache.
+/// @tparam L3 Is the cache hint for L3 cache.
+/// @param tile Is the tile object with type tile_t, holds the return data of the loads.
+/// @param payload Is the payload object with type payload_t. Contains all the information for loads.
+/// @return No return, update in place.
+template <cache_hint L1 = cache_hint::cached,
+ cache_hint L3 = cache_hint::cached, typename tile_t, typename payload_t,
+ typename oob_check_tag = global_atomic_oob_check_on_tag>
+__XETLA_API typename std::enable_if_t<
+ detail::check_load_type<tile_t, payload_t>::is_global_unaligned_2d_xe>
+tile_load(tile_t &tile, payload_t &payload, oob_check_tag tag = {}) {
+ constexpr bool oob_check = std::is_same<oob_check_tag,
+ global_atomic_oob_check_on_tag>::value;
+ using dtype = typename payload_t::dtype;
+ using tile_desc = typename payload_t::tile_desc;
+ using load_dtype = typename payload_t::mem_dtype;
+ using check_load = typename subgroup::check_load<gpu_arch::Xe, dtype,
+ load_dtype>::template unaligned_2d<payload_t::mem_transform,
+ tile_desc::block_size_x>;
+ constexpr uint32_t num_channel_y = payload_t::num_channel_y;
+ constexpr uint32_t load_elems = num_channel_y * payload_t::num_channel_x;
+ constexpr uint32_t scale_factor = payload_t::scale_factor;
+
+#pragma unroll
+ for (int i = 0; i < tile_desc::tile_size_y / tile_desc::block_size_y; i++) {
+ uint32_t offset_y = i * tile_desc::block_size_y;
+#pragma unroll
+ for (int j = 0; j < tile_desc::num_block_x; j++) {
+ uint32_t offset_x = j * tile_desc::block_size_x;
+ auto reg_sub = tile.reg.xetla_select<tile_desc::block_elems, 1>(
+ (i * tile_desc::num_block_x + j) * tile_desc::block_elems);
+ xetla_mask<load_elems> pred_x = oob_check
+ ? payload.step_x + payload.base_x + offset_x
+ < payload.width_in_elems
+ : 1;
+#pragma unroll
+ for (int sub_block_y = 0; sub_block_y < tile_desc::block_size_y;
+ sub_block_y += num_channel_y) {
+ xetla_vector<load_dtype, load_elems> reg_tmp;
+ xetla_mask<load_elems> pred_y = oob_check
+ ? payload.step_y + payload.base_y + offset_y
+ + sub_block_y
+ < payload.height_in_elems
+ : 1;
+
+ uint32_t address_offset = payload_t::trans
+ ? offset_x * payload.pitch_in_bytes
+ + (offset_y + sub_block_y) * sizeof(dtype)
+ : offset_x * sizeof(dtype)
+ + (offset_y + sub_block_y)
+ * payload.pitch_in_bytes;
+
+ reg_tmp = xetla_load_global<load_dtype, 1,
+ data_size::default_size, L1, L3, load_elems>(
+ payload.base_ptr,
+ payload.channel_offset + payload.base_offset
+ + address_offset,
+ pred_x && pred_y);
+ reg_tmp.xetla_merge(reg_tmp, 0, pred_x && pred_y);
+
+ reg_sub.xetla_select<load_elems * scale_factor, 1>(
+ sub_block_y * tile_desc::block_size_x)
+ .xetla_format<load_dtype>()
+ = reg_tmp;
+ }
+ }
+ }
+ //process the tail
+ if constexpr ((tile_desc::tile_size_y % tile_desc::block_size_y) != 0) {
+ constexpr uint32_t remained_size_y = tile_desc::remained_size_y;
+ constexpr uint32_t offset_y = tile_desc::tile_size_y - remained_size_y;
+ constexpr uint32_t processed_elems = offset_y * tile_desc::tile_size_x;
+ constexpr uint32_t remain_block_elems
+ = remained_size_y * tile_desc::block_size_x;
+#pragma unroll
+ for (int j = 0; j < tile_desc::num_block_x; j++) {
+ uint32_t offset_x = j * tile_desc::block_size_x;
+ auto reg_sub = tile.reg.xetla_select<remain_block_elems, 1>(
+ processed_elems + j * remain_block_elems);
+ xetla_mask<load_elems> pred_x = oob_check
+ ? payload.step_x + payload.base_x + offset_x
+ < payload.width_in_elems
+ : 1;
+#pragma unroll
+ for (int sub_block_y = 0; sub_block_y < remained_size_y;
+ sub_block_y += num_channel_y) {
+ xetla_vector<load_dtype, load_elems> reg_tmp;
+ xetla_mask<load_elems> pred_y = oob_check
+ ? payload.step_y + payload.base_y + offset_y
+ + sub_block_y
+ < payload.height_in_elems
+ : 1;
+
+ uint32_t address_offset = payload_t::trans
+ ? offset_x * payload.pitch_in_bytes
+ + (offset_y + sub_block_y) * sizeof(dtype)
+ : offset_x * sizeof(dtype)
+ + (offset_y + sub_block_y)
+ * payload.pitch_in_bytes;
+
+ reg_tmp = xetla_load_global<load_dtype, 1,
+ data_size::default_size, L1, L3, load_elems>(
+ payload.base_ptr,
+ payload.channel_offset + payload.base_offset
+ + address_offset,
+ pred_x && pred_y);
+
+ reg_tmp.xetla_merge(reg_tmp, 0, pred_x && pred_y);
+
+ reg_sub.xetla_select<load_elems * scale_factor, 1>(
+ sub_block_y * tile_desc::block_size_x)
+ .xetla_format<load_dtype>()
+ = reg_tmp;
+ }
+ }
+ }
+
+ if constexpr (payload_t::mem_transform) {
+ SW_BARRIER();
+ vnni_convert(tile);
+ }
+}
+
+/// @brief Is the data load func from local shared memory to register file, which
+/// supports the memory surface is 1d or 2d scenario. And we always assume data in SLM
+/// is row major.
+/// @tparam tile_t Is the tile_t struct contains registers
+/// These registers will be the destination of load operation.
+/// @tparam payload_t Is the mem_payload_t struct describing the memory information.
+/// Payload indicates the source of load operation.
+/// @tparam L1 Is the cache hint for L1 cache.
+/// @tparam L2 Is the cache hint for L2 cache.
+/// @param tile Is the tile object with type tile_t, holds the return data of the loads.
+/// @param payload Is the payload object with type payload_t. Contains all the information for loads.
+/// @return No return, update in place.
+template <cache_hint L1 = cache_hint::cached,
+ cache_hint L2 = cache_hint::cached, typename tile_t, typename payload_t>
+__XETLA_API typename std::enable_if_t<
+ detail::check_load_type<tile_t, payload_t>::is_local_scatter_xe>
+tile_load(tile_t &tile, payload_t &payload) {
+ using dtype = typename payload_t::dtype;
+ using tile_desc = typename payload_t::tile_desc;
+ using load_dtype = typename payload_t::mem_dtype;
+ using check_load = typename subgroup::check_load<gpu_arch::Xe, dtype,
+ load_dtype>::template local_scatter<payload_t::memory_layout,
+ payload_t::tile_desc::block_size_x, payload_t::tile_bytes,
+ payload_t::min_bytes, payload_t::block_bytes,
+ payload_t::num_channel_x, payload_t::num_channel>;
+
+ constexpr uint32_t num_channel_y = payload_t::num_channel_y;
+ constexpr uint32_t load_elems = num_channel_y * tile_desc::block_size_x;
+ static constexpr bool mem_transform = payload_t::mem_transform;
+
+#pragma unroll
+ for (int i = 0; i < tile_desc::tile_size_y / tile_desc::block_size_y; i++) {
+ uint32_t offset_y = i * tile_desc::block_size_y;
+#pragma unroll
+ for (int j = 0; j < tile_desc::num_block_x; j++) {
+ uint32_t offset_x = j * tile_desc::block_size_x;
+ auto reg_sub = tile.reg.xetla_select<tile_desc::block_elems, 1>(
+ (i * tile_desc::num_block_x + j) * tile_desc::block_elems);
+#pragma unroll
+ for (int sub_block_y = 0; sub_block_y < tile_desc::block_size_y;
+ sub_block_y += num_channel_y) {
+ uint32_t address_offset = offset_x * sizeof(dtype)
+ + (sub_block_y + offset_y) * payload.pitch_in_bytes;
+ reg_sub.xetla_select<load_elems, 1>(
+ sub_block_y * tile_desc::block_size_x)
+ .xetla_format<load_dtype>()
+ = xetla_load_local<load_dtype>(
+ payload.address + address_offset);
+ }
+ }
+ }
+ //process the tail
+ if constexpr ((tile_desc::tile_size_y % tile_desc::block_size_y) != 0) {
+ constexpr uint32_t remained_size_y = tile_desc::remained_size_y;
+ constexpr uint32_t offset_y = tile_desc::tile_size_y - remained_size_y;
+ constexpr uint32_t processed_elems = offset_y * tile_desc::tile_size_x;
+ constexpr uint32_t remain_block_elems
+ = remained_size_y * tile_desc::block_size_x;
+#pragma unroll
+ for (int j = 0; j < tile_desc::num_block_x; j++) {
+ uint32_t offset_x = j * tile_desc::block_size_x;
+ auto reg_sub = tile.reg.xetla_select<remain_block_elems, 1>(
+ processed_elems + j * remain_block_elems);
+#pragma unroll
+ for (int sub_block_y = 0; sub_block_y < remained_size_y;
+ sub_block_y += num_channel_y) {
+ uint32_t address_offset = offset_x * sizeof(dtype)
+ + (sub_block_y + offset_y) * payload.pitch_in_bytes;
+ reg_sub.xetla_select<load_elems, 1>(
+ sub_block_y * tile_desc::block_size_x)
+ .xetla_format<load_dtype>()
+ = xetla_load_local<load_dtype>(
+ payload.address + address_offset);
+ }
+ }
+ }
+ if constexpr (mem_transform) {
+ SW_BARRIER();
+ vnni_convert(tile);
+ }
+}
+
+/// @brief Is the data load func from shared local memory to register file, which
+/// supports the memory surface is 1d scenario. And the src memory layout is always
+/// row major.
+/// @tparam tile_t Is the tile_t struct contains registers.
+/// These registers will be the destination of load operation.
+/// @tparam payload_t Is the mem_payload_t struct describing the memory information.
+/// Payload indicates the source of load operation.
+/// @tparam L1 Is the cache hint for L1 cache.
+/// @tparam L2 Is the cache hint for L2 cache.
+/// @param tile Is the tile object with type tile_t, holds the return data of the loads.
+/// @param payload Is the payload object with type payload_t. Contains all the information for loads.
+/// @return No return, update in place.
+template <cache_hint L1 = cache_hint::cached,
+ cache_hint L2 = cache_hint::cached, typename tile_t, typename payload_t>
+__XETLA_API typename std::enable_if_t<
+ detail::check_load_type<tile_t, payload_t>::is_local_block_1d_xe>
+tile_load(tile_t &tile, payload_t &payload) {
+ using dtype = typename tile_t::dtype;
+ using tile_desc = typename tile_t::tile_desc;
+ using load_dtype = typename payload_t::mem_dtype;
+ using check_load = typename subgroup::check_load<gpu_arch::Xe, dtype,
+ load_dtype>::local_1d;
+
+ constexpr uint32_t scale_factor = payload_t::scale_factor;
+ constexpr uint32_t load_len = tile_desc::tile_size_x / scale_factor;
+#pragma unroll
+ for (int i = 0; i < tile_desc::tile_size_y; i++) {
+ uint32_t offset_y = i * tile_desc::tile_size_x;
+ uint32_t address_offset_y = i * payload.pitch_in_bytes;
+ if constexpr (load_len >= 64) {
+#pragma unroll
+ for (int j = 0; j < load_len / 64; j++) {
+ uint32_t offset_x = j * 64 * scale_factor;
+ auto reg_sub = tile.reg.xetla_select<64 * scale_factor, 1>(
+ offset_x + offset_y);
+ uint32_t address_offset
+ = address_offset_y + offset_x * sizeof(dtype);
+ reg_sub.xetla_format<load_dtype>()
+ = xetla_load_local<load_dtype, 64,
+ data_size::default_size>(payload.base_address
+ + payload.address + address_offset);
+ }
+ }
+ uint32_t tail_offset = offset_y + load_len / 64 * 64 * scale_factor;
+ uint32_t tail_address_offset = address_offset_y
+ + load_len / 64 * 64 * scale_factor * sizeof(dtype);
+ detail::process_1d_tail<load_len % 64, 32, detail::process_flag::load,
+ L1, L2>(tile, payload, tail_offset, tail_address_offset);
+ }
+}
+
+} // namespace gpu::xetla::subgroup
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/subgroup/tile/impl/mma_xe.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/subgroup/tile/impl/mma_xe.hpp
new file mode 100644
index 00000000000..3e447046e9a
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/subgroup/tile/impl/mma_xe.hpp
@@ -0,0 +1,260 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#include "subgroup/tile/api.hpp"
+
+namespace gpu::xetla::subgroup {
+
+/// @brief Is the tile mma operation functor, specialized for Xe and matrix engine.
+template <typename matAcc_dst_t_, typename matAcc_src_t_, typename matB_t_,
+ typename matA_t_, gpu_arch arch_tag_>
+struct tile_mma_t<matAcc_dst_t_, matAcc_src_t_, matB_t_, matA_t_,
+ mma_engine::xmx, arch_tag_,
+ std::enable_if_t<(arch_tag_ == gpu_arch::Xe)>> {
+ using matA_t = matA_t_;
+ using matB_t = matB_t_;
+ using matSrc_t = matAcc_src_t_;
+ using matDst_t = matAcc_dst_t_;
+ using dtype_a = typename matA_t::dtype;
+ using dtype_b = typename matB_t::dtype;
+ using dtype_src = typename matSrc_t::dtype;
+ using dtype_dst = typename matDst_t::dtype;
+
+ using mma_attr = typename arch_attr_t<arch_tag_>::mma_attr;
+
+ static constexpr uint32_t a_tile_size_y = matA_t::tile_size_y;
+ static constexpr uint32_t a_tile_size_x = matA_t::tile_size_x;
+ static constexpr uint32_t a_tile_elems = matA_t::tile_elems;
+ static constexpr uint32_t a_block_size_y = matA_t::block_size_y;
+ static constexpr uint32_t a_block_size_x = matA_t::block_size_x;
+ static constexpr uint32_t a_block_elems = matA_t::block_elems;
+
+ static constexpr uint32_t b_tile_size_x = matB_t::tile_size_x;
+ static constexpr uint32_t b_tile_size_y = matB_t::tile_size_y;
+ static constexpr uint32_t b_tile_elems = matB_t::tile_elems;
+ static constexpr uint32_t b_block_size_x = matB_t::block_size_x;
+ static constexpr uint32_t b_block_size_y = matB_t::block_size_y;
+ static constexpr uint32_t b_block_elems = matB_t::block_elems;
+
+ static constexpr uint32_t tile_size_m = matDst_t::tile_size_y;
+ static constexpr uint32_t tile_size_k = a_tile_size_x;
+ static constexpr uint32_t tile_size_n = matDst_t::tile_size_x;
+ static constexpr uint32_t tile_elems = tile_size_m * tile_size_n;
+ static constexpr uint32_t block_size_n = matDst_t::block_size_x;
+ static constexpr uint32_t block_size_k
+ = a_block_size_x; //cannot use b_block_size_y
+ static constexpr uint32_t block_size_m = matDst_t::block_size_y;
+ static constexpr uint32_t block_elems = block_size_m * block_size_n;
+
+ static_assert(tile_size_m == matA_t::tile_size_y,
+ "matAcc tile m should match with matA tile m");
+ static_assert(a_tile_size_x == b_tile_size_y,
+ "matA tile k should match with matB tile k");
+ static_assert(tile_size_n == matB_t::tile_size_x,
+ "matAcc tile n should match with matB tile n");
+ static_assert(block_size_m == a_block_size_y,
+ "matAcc block m should match with matA block m");
+ static_assert(block_size_n == b_block_size_x,
+ "matAcc block n should match with matB block n");
+ static_assert(b_block_size_y % a_block_size_x == 0,
+ "matA block k should match with matB block k");
+ static_assert((tile_size_k % block_size_k) == 0,
+ "matAcc tile_size_k should be a multiple of block_size_k");
+ static_assert((block_size_k == 32 / sizeof(dtype_a)),
+ "DPAS depth only support the value of 32 / sizeof(dtype_a). "
+ "Currently we don't support the "
+ "splitting of block when call the DPAS");
+
+ static constexpr int32_t num_block_n = matDst_t::num_block_x;
+ static constexpr int32_t num_block_m = matDst_t::num_block_y;
+ static constexpr int32_t num_block_k = tile_size_k / block_size_k;
+ static constexpr int32_t num_block_mma_b = b_block_size_y / block_size_k;
+ static constexpr uint32_t b_block_mma_elems
+ = b_block_elems / num_block_mma_b;
+
+ static constexpr int32_t mma_m = mma_attr::mma_m_in_elem;
+ static constexpr int32_t mma_k
+ = mma_attr::mma_k_in_bytes / sizeof(uint32_t);
+ static_assert(tile_size_m % mma_m == 0,
+ "tile_size_m shoud be a multiple of mma_m");
+
+ __XETLA_API static void mma(
+ matDst_t &dst, matSrc_t &src, matB_t &b, matA_t &a) {
+ constexpr int32_t a_mma_elems = mma_m * a_block_size_x;
+ constexpr int32_t c_mma_elems = mma_m * block_size_n;
+#pragma unroll
+ for (int j = 0; j < num_block_n; j++) {
+#pragma unroll
+ for (int i = 0; i < tile_size_m / block_size_m; i++) {
+ auto src_block = src.reg.xetla_select<block_elems, 1>(
+ (i * num_block_n + j) * block_elems);
+ auto dst_block = dst.reg.xetla_select<block_elems, 1>(
+ (i * num_block_n + j) * block_elems);
+#pragma unroll
+ for (int mma_i = 0; mma_i < block_size_m / mma_m; mma_i++) {
+ auto src_sub_blk = src_block.xetla_select<c_mma_elems, 1>(
+ mma_i * c_mma_elems);
+ auto dst_sub_blk = dst_block.xetla_select<c_mma_elems, 1>(
+ mma_i * c_mma_elems);
+ { //k=0
+ auto a_block = a.reg.xetla_select<a_block_elems, 1>(
+ (i * num_block_k) * a_block_elems);
+ auto a_sub_blk = a_block.xetla_select<a_mma_elems, 1>(
+ mma_i * a_mma_elems);
+ auto b_blk = b.reg.xetla_select<b_block_elems, 1>(
+ j * b_block_elems);
+ auto b_sub_blk
+ = b_blk.xetla_select<b_block_mma_elems, 1>(0);
+ dst_sub_blk = xetla_mma<
+ gpu::xetla::detail::mma_argument_type<
+ dtype_b>(),
+ gpu::xetla::detail::mma_argument_type<
+ dtype_a>(),
+ mma_k, mma_m, dtype_src, uint32_t, uint32_t,
+ c_mma_elems,
+ b_block_mma_elems
+ / (sizeof(uint32_t) / sizeof(dtype_b)),
+ a_mma_elems
+ / (sizeof(uint32_t) / sizeof(dtype_a))>(
+ src_sub_blk, b_sub_blk.xetla_format<uint32_t>(),
+ a_sub_blk.xetla_format<uint32_t>());
+ }
+
+#pragma unroll
+ for (int k = 1; k < num_block_k; k++) {
+ auto a_block = a.reg.xetla_select<a_block_elems, 1>(
+ (i * num_block_k + k) * a_block_elems);
+ auto a_sub_blk = a_block.xetla_select<a_mma_elems, 1>(
+ mma_i * a_mma_elems);
+ int inter_k_b = k / num_block_mma_b;
+ int inner_k_b = k % num_block_mma_b;
+ auto b_blk = b.reg.xetla_select<b_block_elems, 1>(
+ (j + inter_k_b * num_block_n) * b_block_elems);
+ auto b_sub_blk
+ = b_blk.xetla_select<b_block_mma_elems, 1>(
+ inner_k_b * b_block_mma_elems);
+ dst_sub_blk = xetla_mma<
+ gpu::xetla::detail::mma_argument_type<
+ dtype_b>(),
+ gpu::xetla::detail::mma_argument_type<
+ dtype_a>(),
+ mma_k, mma_m, dtype_src, uint32_t, uint32_t,
+ c_mma_elems,
+ b_block_mma_elems
+ / (sizeof(uint32_t) / sizeof(dtype_b)),
+ a_mma_elems
+ / (sizeof(uint32_t) / sizeof(dtype_a))>(
+ dst_sub_blk, b_sub_blk.xetla_format<uint32_t>(),
+ a_sub_blk.xetla_format<uint32_t>());
+ }
+ }
+ }
+ if constexpr ((tile_size_m % block_size_m) != 0) {
+ constexpr uint32_t tail_block_size_m
+ = tile_size_m % block_size_m;
+ constexpr uint32_t tail_block_elems
+ = block_size_n * tail_block_size_m;
+ constexpr uint32_t a_tail_block_elems
+ = tail_block_size_m * a_block_size_x;
+ constexpr uint32_t tail_m_start
+ = tile_size_m / block_size_m * block_size_m;
+ constexpr uint32_t tail_elems_start
+ = tail_m_start * tile_size_n;
+ constexpr uint32_t a_tail_elems_start
+ = tail_m_start * a_tile_size_x;
+ auto src_block = src.reg.xetla_select<tail_block_elems, 1>(
+ tail_elems_start + j * tail_block_elems);
+ auto dst_block = dst.reg.xetla_select<tail_block_elems, 1>(
+ tail_elems_start + j * tail_block_elems);
+#pragma unroll
+ for (int mma_i = 0; mma_i < tail_block_size_m / mma_m;
+ mma_i++) {
+ auto src_sub_blk = src_block.xetla_select<c_mma_elems, 1>(
+ mma_i * c_mma_elems);
+ auto dst_sub_blk = dst_block.xetla_select<c_mma_elems, 1>(
+ mma_i * c_mma_elems);
+ { //k=0
+ auto a_block
+ = a.reg.xetla_select<a_tail_block_elems, 1>(
+ a_tail_elems_start);
+ auto a_sub_blk = a_block.xetla_select<a_mma_elems, 1>(
+ mma_i * a_mma_elems);
+ auto b_blk = b.reg.xetla_select<b_block_elems, 1>(
+ j * b_block_elems);
+ auto b_sub_blk
+ = b_blk.xetla_select<b_block_mma_elems, 1>(0);
+
+ dst_sub_blk = xetla_mma<
+ gpu::xetla::detail::mma_argument_type<
+ dtype_b>(),
+ gpu::xetla::detail::mma_argument_type<
+ dtype_a>(),
+ mma_k, mma_m, dtype_src, uint32_t, uint32_t,
+ c_mma_elems,
+ b_block_mma_elems
+ / (sizeof(uint32_t) / sizeof(dtype_b)),
+ a_mma_elems
+ / (sizeof(uint32_t) / sizeof(dtype_a))>(
+ src_sub_blk, b_sub_blk.xetla_format<uint32_t>(),
+ a_sub_blk.xetla_format<uint32_t>());
+ }
+#pragma unroll
+ for (int k = 1; k < num_block_k; k++) {
+ auto a_block
+ = a.reg.xetla_select<a_tail_block_elems, 1>(
+ a_tail_elems_start
+ + k * a_tail_block_elems);
+ auto a_sub_blk = a_block.xetla_select<a_mma_elems, 1>(
+ mma_i * a_mma_elems);
+ int inter_k_b = k / num_block_mma_b;
+ int inner_k_b = k % num_block_mma_b;
+ auto b_blk = b.reg.xetla_select<b_block_elems, 1>(
+ (j + inter_k_b * num_block_n) * b_block_elems);
+ auto b_sub_blk
+ = b_blk.xetla_select<b_block_mma_elems, 1>(
+ inner_k_b * b_block_mma_elems);
+
+ dst_sub_blk = xetla_mma<
+ gpu::xetla::detail::mma_argument_type<
+ dtype_b>(),
+ gpu::xetla::detail::mma_argument_type<
+ dtype_a>(),
+ mma_k, mma_m, dtype_src, uint32_t, uint32_t,
+ c_mma_elems,
+ b_block_mma_elems
+ / (sizeof(uint32_t) / sizeof(dtype_b)),
+ a_mma_elems
+ / (sizeof(uint32_t) / sizeof(dtype_a))>(
+ dst_sub_blk, b_sub_blk.xetla_format<uint32_t>(),
+ a_sub_blk.xetla_format<uint32_t>());
+ }
+ }
+ }
+ }
+ if constexpr (num_block_k > 1) {
+ constexpr uint32_t last_uint16_idx
+ = tile_elems * sizeof(dtype_dst) / sizeof(uint16_t) - 1;
+ xetla_wait(dst.reg.xetla_format<uint16_t>()[0]);
+ }
+ }
+};
+
+} // namespace gpu::xetla::subgroup
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/subgroup/tile/impl/op_function.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/subgroup/tile/impl/op_function.hpp
new file mode 100644
index 00000000000..a3585e29bd3
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/subgroup/tile/impl/op_function.hpp
@@ -0,0 +1,657 @@
+/*******************************************************************************
+ * Copyright (c) 2022-2023 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.
+ *******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#include "subgroup/tile/api.hpp"
+#include "subgroup/tile/common.hpp"
+
+namespace gpu::xetla::subgroup {
+/// @brief Is the element wise data conversion, the src and dst tile should have the same layout.
+///
+/// @tparam T_dst Is the destination tile data type.
+/// @tparam T_src Is the source tile data type.
+/// @param dst Is the reference of the destination tile object.
+/// @param src Is the reference of the destination tile object.
+/// @return No return, in-place update in the destination tile.
+template <typename T_dst, typename T_src>
+__XETLA_API
+ typename std::enable_if_t<(T_src::register_layout != reg_layout::linear)
+ && (T_dst::register_layout != reg_layout::linear)
+ && (is_same_elements<T_dst, T_src>::value)
+ && (!is_floating_to_integer<T_dst, T_src>::value)>
+ elemwise_cvt(T_dst &dst, T_src &src) {
+ constexpr uint32_t block_size_x = T_dst::block_size_x;
+ constexpr uint32_t tile_elems = T_dst::tile_elems;
+ using dtype_src = typename T_src::dtype;
+ using dtype_dst = typename T_dst::dtype;
+ if constexpr (std::is_same<dtype_src, dtype_dst>::value) {
+ dst.reg = xetla_cvt<dtype_dst, dtype_src>(src.reg);
+ } else {
+#pragma unroll
+ for (int i = 0; i < tile_elems; i += block_size_x) {
+ dst.reg.xetla_select<block_size_x, 1>(i)
+ = xetla_cvt<dtype_dst, dtype_src, block_size_x>(
+ src.reg.xetla_select<block_size_x, 1>(i));
+ }
+ }
+}
+
+/// @brief Is the element wise data conversion from floating point to integral,
+/// the src and dst tile should have the same layout.
+/// @tparam T_dst Is the destination tile data type.
+/// @tparam T_src Is the source tile data type.
+/// @param dst Is the reference of the destination tile object.
+/// @param src Is the reference of the destination tile object.
+/// @return No return, in-place update in the destination tile.
+template <typename T_dst, typename T_src>
+__XETLA_API
+ typename std::enable_if_t<(T_src::register_layout != reg_layout::linear)
+ && (T_dst::register_layout != reg_layout::linear)
+ && is_same_layout<T_dst, T_src>::value
+ && is_floating_to_integer<T_dst, T_src>::value>
+ elemwise_cvt(T_dst &dst, T_src &src) {
+ constexpr uint32_t block_size_x = T_dst::block_size_x;
+ constexpr uint32_t tile_elems = T_dst::tile_elems;
+ using dtype_src = typename T_src::dtype;
+ using dtype_dst = typename T_dst::dtype;
+
+ xetla_vector<dtype_src, tile_elems> rnde_reg;
+ //rnde
+#pragma unroll
+ for (int i = 0; i < tile_elems; i += block_size_x) {
+ rnde_reg.xetla_select<block_size_x, 1>(i)
+ = xetla_rnde<dtype_src, block_size_x>(
+ src.reg.xetla_select<block_size_x, 1>(i));
+ }
+ //sat
+#pragma unroll
+ for (int i = 0; i < tile_elems; i += block_size_x) {
+ dst.reg.xetla_select<block_size_x, 1>(i)
+ = xetla_sat<dtype_dst, dtype_src, block_size_x>(
+ rnde_reg.xetla_select<block_size_x, 1>(i));
+ }
+}
+
+/// @brief element wise data conversion with scaling, the src and dst tile should have the same layout.
+/// @tparam T_dst is the destination tile data type.
+/// @tparam T_src is the source tile data type.
+/// @param dst is the reference of the destination tile object.
+/// @param src is the reference of the destination tile object.
+/// @param scale is the scaling value to be applied before the assignment.
+/// @return no return, in-place update in the destination tile.
+template <typename T_dst, typename T_src>
+__XETLA_API
+ typename std::enable_if_t<(T_src::register_layout != reg_layout::linear)
+ && (T_dst::register_layout != reg_layout::linear)
+ && is_same_layout<T_dst, T_src>::value>
+ elemwise_cvt(T_dst &dst, T_src &src, float scale) {
+ dst.reg = xetla_cvt<typename T_dst::dtype, typename T_src::dtype>(
+ src.reg, scale);
+}
+
+/// @brief Converts tiled layout to vnni_tiled layout format.
+///
+/// @tparam T Is the tile data type.
+/// @param mat_Acc Is the reference of the tile object.
+/// @return No return, update the data in-place.
+template <typename T>
+__XETLA_API
+ typename std::enable_if_t<T::register_layout == reg_layout::vnni_tiled>
+ vnni_convert(T &mat_Acc) {
+ constexpr uint32_t tile_size_y = T::tile_size_y;
+ constexpr uint32_t tile_size_x = T::tile_size_x;
+ constexpr uint32_t tile_elems = tile_size_y * tile_size_x;
+ constexpr uint32_t block_size_y = T::block_size_y;
+ constexpr uint32_t block_size_x = T::block_size_x;
+ constexpr uint32_t block_elems = block_size_y * block_size_x;
+ constexpr int32_t num_block_x = tile_size_x / block_size_x;
+ using dtype = typename T::dtype;
+ constexpr int32_t vnni_stride = sizeof(uint32_t) / sizeof(dtype);
+ constexpr int32_t move_cols = block_size_x * vnni_stride;
+ constexpr int32_t move_rows = block_size_y / vnni_stride;
+ xetla_vector<dtype, tile_elems> rdst;
+ static_assert(block_size_y % vnni_stride == 0, "vnni alignement check");
+ if constexpr (tile_size_x == 1) { return; }
+#pragma unroll
+ for (int i = 0; i < tile_size_y / block_size_y; i++) {
+#pragma unroll
+ for (int j = 0; j < num_block_x; j++) {
+ auto reg = (mat_Acc.reg)
+ .xetla_select<block_elems, 1>(
+ (i * num_block_x + j) * block_elems);
+ auto reg_2d = reg.xetla_format<native_type_t<dtype>, block_size_y,
+ block_size_x>();
+ auto reg_dst = rdst.xetla_select<block_elems, 1>(
+ (i * num_block_x + j) * block_elems);
+ auto reg_dst_2d = reg_dst.xetla_format<native_type_t<dtype>,
+ move_rows, move_cols>();
+#pragma unroll
+ for (int vnni_i = 0; vnni_i < vnni_stride; vnni_i++) {
+ reg_dst_2d
+ .xetla_select<move_rows, 1, block_size_x, vnni_stride>(
+ 0, vnni_i)
+ = reg_2d.xetla_select<move_rows, vnni_stride,
+ block_size_x, 1>(vnni_i, 0);
+ }
+ }
+ }
+ // process the tail
+ if constexpr ((tile_size_y % block_size_y) != 0) {
+ constexpr int i = tile_size_y / block_size_y;
+ constexpr uint32_t remain_elems_start = i * block_size_y * tile_size_x;
+ constexpr uint32_t remain_size_y = tile_size_y % block_size_y;
+ constexpr uint32_t remain_block_elems = remain_size_y * block_size_x;
+ static_assert(
+ remain_size_y % vnni_stride == 0, "vnni alignement check");
+ constexpr int32_t remain_move_cols = block_size_x * vnni_stride;
+ constexpr int32_t remain_move_rows = remain_size_y / vnni_stride;
+#pragma unroll
+ for (int j = 0; j < num_block_x; j++) {
+ auto reg = (mat_Acc.reg)
+ .xetla_select<remain_block_elems, 1>(
+ remain_elems_start
+ + j * remain_block_elems);
+ auto reg_2d = reg.xetla_format<native_type_t<dtype>, remain_size_y,
+ block_size_x>();
+ auto reg_dst = rdst.xetla_select<remain_block_elems, 1>(
+ remain_elems_start + j * remain_block_elems);
+ auto reg_dst_2d = reg_dst.xetla_format<native_type_t<dtype>,
+ remain_move_rows, remain_move_cols>();
+ for (int vnni_i = 0; vnni_i < vnni_stride; vnni_i++) {
+ reg_dst_2d.xetla_select<remain_move_rows, 1, block_size_x,
+ vnni_stride>(0, vnni_i)
+ = reg_2d.xetla_select<remain_move_rows, vnni_stride,
+ block_size_x, 1>(vnni_i, 0);
+ }
+ }
+ }
+ mat_Acc.reg = rdst;
+}
+
+/// @brief Converts vnni_tiled layout format to tiled layout.
+///
+/// @tparam T Is the tile data type.
+/// @param mat_Acc Is the reference of the tile object.
+/// @return No return, update the data in-place.
+template <typename T>
+__XETLA_API typename std::enable_if_t<T::register_layout == reg_layout::tiled
+ || T::register_layout == reg_layout::vnni_tiled>
+vnni_reverse(T &mat_Acc) {
+ constexpr uint32_t tile_size_y = T::tile_size_y;
+ constexpr uint32_t tile_size_x = T::tile_size_x;
+ constexpr uint32_t tile_elems = tile_size_y * tile_size_x;
+ constexpr uint32_t block_size_y = T::block_size_y;
+ constexpr uint32_t block_size_x = T::block_size_x;
+ constexpr uint32_t block_elems = block_size_y * block_size_x;
+ constexpr int32_t num_block_x = tile_size_x / block_size_x;
+ using dtype = typename T::dtype;
+ constexpr int32_t vnni_stride = sizeof(uint32_t) / sizeof(dtype);
+ constexpr int32_t move_cols = block_size_x * vnni_stride;
+ constexpr int32_t move_rows = block_size_y / vnni_stride;
+ xetla_vector<dtype, tile_elems> rdst;
+ static_assert(block_size_y % vnni_stride == 0, "vnni alignement check");
+ if constexpr (tile_size_x == 1) { return; }
+#pragma unroll
+ for (int i = 0; i < tile_size_y / block_size_y; i++) {
+#pragma unroll
+ for (int j = 0; j < num_block_x; j++) {
+ auto reg = (mat_Acc.reg)
+ .xetla_select<block_elems, 1>(
+ (i * num_block_x + j) * block_elems);
+ auto reg_2d = reg.xetla_format<native_type_t<dtype>, move_rows,
+ move_cols>();
+ auto reg_dst = rdst.xetla_select<block_elems, 1>(
+ (i * num_block_x + j) * block_elems);
+ auto reg_dst_2d = reg_dst.xetla_format<native_type_t<dtype>,
+ block_size_y, block_size_x>();
+#pragma unroll
+ for (int vnni_i = 0; vnni_i < vnni_stride; vnni_i++) {
+ reg_dst_2d
+ .xetla_select<move_rows, vnni_stride, block_size_x, 1>(
+ vnni_i, 0)
+ = reg_2d.xetla_select<move_rows, 1, block_size_x,
+ vnni_stride>(0, vnni_i);
+ }
+ }
+ }
+ // process the tail
+ if constexpr ((tile_size_y % block_size_y) != 0) {
+ constexpr int i = tile_size_y / block_size_y;
+ constexpr uint32_t remain_elems_start = i * block_size_y * tile_size_x;
+ constexpr uint32_t remain_size_y = tile_size_y % block_size_y;
+ constexpr uint32_t remain_block_elems = remain_size_y * block_size_x;
+ static_assert(
+ remain_size_y % vnni_stride == 0, "vnni alignement check");
+ constexpr int32_t remain_move_cols = block_size_x * vnni_stride;
+ constexpr int32_t remain_move_rows = remain_size_y / vnni_stride;
+#pragma unroll
+ for (int j = 0; j < num_block_x; j++) {
+ auto reg = (mat_Acc.reg)
+ .xetla_select<remain_block_elems, 1>(
+ remain_elems_start
+ + j * remain_block_elems);
+ auto reg_2d = reg.xetla_format<native_type_t<dtype>,
+ remain_move_rows, remain_move_cols>();
+ auto reg_dst = rdst.xetla_select<remain_block_elems, 1>(
+ remain_elems_start + j * remain_block_elems);
+ auto reg_dst_2d = reg_dst.xetla_format<native_type_t<dtype>,
+ remain_size_y, block_size_x>();
+ for (int vnni_i = 0; vnni_i < vnni_stride; vnni_i++) {
+ reg_dst_2d.xetla_select<remain_move_rows, vnni_stride,
+ block_size_x, 1>(vnni_i, 0)
+ = reg_2d.xetla_select<remain_move_rows, 1, block_size_x,
+ vnni_stride>(0, vnni_i);
+ }
+ }
+ }
+ mat_Acc.reg = rdst;
+}
+
+/// @brief Converts vnni_tiled layout format to transpose_tiled layout.
+///
+/// @tparam T Is the tile data type.
+/// @param mat_Acc Is the reference of the tile object.
+/// @return No return, update the data in-place.
+template <typename T>
+__XETLA_API typename std::enable_if_t<T::register_layout
+ == reg_layout::transpose_tiled>
+vnni_reverse(T &mat_Acc) {
+ constexpr uint32_t tile_size_y = T::tile_size_y;
+ constexpr uint32_t tile_size_x = T::tile_size_x;
+ constexpr uint32_t tile_elems = tile_size_y * tile_size_x;
+ constexpr uint32_t block_size_y = T::block_size_y;
+ constexpr uint32_t block_size_x = T::block_size_x;
+ constexpr uint32_t block_elems = block_size_y * block_size_x;
+ constexpr int32_t num_block_x = tile_size_x / block_size_x;
+ using dtype = typename T::dtype;
+ constexpr int32_t vnni_stride = sizeof(uint32_t) / sizeof(dtype);
+ constexpr int32_t move_cols = block_size_y * vnni_stride;
+ constexpr int32_t move_rows = block_size_x / vnni_stride;
+ xetla_vector<dtype, tile_elems> rdst;
+ static_assert(block_size_x % vnni_stride == 0, "vnni alignement check");
+ if constexpr (tile_size_y == 1) { return; }
+#pragma unroll
+ for (int i = 0; i < tile_size_y / block_size_y; i++) {
+#pragma unroll
+ for (int j = 0; j < num_block_x; j++) {
+ auto reg = (mat_Acc.reg)
+ .xetla_select<block_elems, 1>(
+ (i * num_block_x + j) * block_elems);
+ auto reg_2d = reg.xetla_format<native_type_t<dtype>, move_rows,
+ move_cols>();
+ auto reg_dst = rdst.xetla_select<block_elems, 1>(
+ (i * num_block_x + j) * block_elems);
+ //transpose
+ auto reg_dst_2d = reg_dst.xetla_format<native_type_t<dtype>,
+ block_size_x, block_size_y>();
+ for (int vnni_i = 0; vnni_i < vnni_stride; vnni_i++) {
+ reg_dst_2d
+ .xetla_select<move_rows, vnni_stride, block_size_y, 1>(
+ vnni_i, 0)
+ = reg_2d.xetla_select<move_rows, 1, block_size_y,
+ vnni_stride>(0, vnni_i);
+ }
+ }
+ }
+ // process the tail
+ if constexpr ((tile_size_y % block_size_y) != 0) {
+ constexpr int i = tile_size_y / block_size_y;
+ constexpr uint32_t remain_elems_start = i * block_size_y * tile_size_x;
+ constexpr uint32_t remain_size_y = tile_size_y % block_size_y;
+ constexpr uint32_t remain_block_elems = remain_size_y * block_size_x;
+ constexpr int32_t remain_move_cols = remain_size_y * vnni_stride;
+ constexpr int32_t remain_move_rows = block_size_x / vnni_stride;
+#pragma unroll
+ for (int j = 0; j < num_block_x; j++) {
+ auto reg = (mat_Acc.reg)
+ .xetla_select<remain_block_elems, 1>(
+ remain_elems_start
+ + j * remain_block_elems);
+ auto reg_2d = reg.xetla_format<native_type_t<dtype>,
+ remain_move_rows, remain_move_cols>();
+ auto reg_dst = rdst.xetla_select<remain_block_elems, 1>(
+ remain_elems_start + j * remain_block_elems);
+ //transpose
+ auto reg_dst_2d = reg_dst.xetla_format<native_type_t<dtype>,
+ block_size_x, remain_size_y>();
+
+ for (int vnni_i = 0; vnni_i < vnni_stride; vnni_i++) {
+ reg_dst_2d.xetla_select<remain_move_rows, vnni_stride,
+ remain_size_y, 1>(vnni_i, 0)
+ = reg_2d.xetla_select<remain_move_rows, 1,
+ remain_size_y, vnni_stride>(0, vnni_i);
+ }
+ }
+ }
+ mat_Acc.reg = rdst;
+}
+
+/// @brief Changes vnni layout.
+///
+/// @tparam T_dst Is the destination tile data type.
+/// @tparam T_src Is the source tile data type.
+/// @param dst Is the reference of the destination tile object.
+/// @param src Is the reference of the destination tile object.
+/// @return No return, in-place update in the destination tile.
+template <typename T_dst, typename T_src>
+__XETLA_API typename std::enable_if_t<is_same_layout<T_dst, T_src>::value>
+vnni_transform(T_dst &dst, T_src &src) {
+ constexpr uint32_t tile_size_y = T_dst::tile_size_y;
+ constexpr uint32_t tile_size_x = T_dst::tile_size_x;
+ constexpr uint32_t tile_elems = tile_size_y * tile_size_x;
+ constexpr uint32_t block_size_y = T_dst::block_size_y;
+ constexpr uint32_t block_size_x = T_dst::block_size_x;
+ constexpr uint32_t block_elems = block_size_y * block_size_x;
+ constexpr int32_t num_block_x = tile_size_x / block_size_x;
+ using dtype_dst = typename T_dst::dtype;
+ using dtype_src = typename T_src::dtype;
+ constexpr uint32_t vnni_row_src = sizeof(uint32_t) / sizeof(dtype_src);
+ constexpr uint32_t vnni_row_dst = sizeof(uint32_t) / sizeof(dtype_dst);
+ constexpr int32_t vnni_row
+ = vnni_row_src > vnni_row_dst ? vnni_row_src : vnni_row_dst;
+ static_assert(block_size_y % vnni_row == 0);
+ static_assert(tile_size_y % vnni_row == 0);
+ constexpr int32_t move_elems = vnni_row * block_size_x;
+ xetla_vector<dtype_dst, tile_elems> reg_src
+ = xetla_cvt<dtype_dst, dtype_src, tile_elems>(src.reg);
+ if constexpr (sizeof(dtype_src) == sizeof(dtype_dst)) {
+ dst.reg = reg_src;
+ return;
+ }
+ xetla_vector<dtype_dst, tile_elems> reg_dst;
+ constexpr uint32_t scale_factor
+ = detail::gcd<vnni_row_src, vnni_row_dst>::value;
+ using move_dtype = get_uint_type_t<sizeof(dtype_dst) * scale_factor>;
+ constexpr uint32_t select_stride = vnni_row / scale_factor;
+#pragma unroll
+ for (int i = 0; i < tile_size_y / block_size_y; i++) {
+#pragma unroll
+ for (int j = 0; j < num_block_x; j++) {
+ auto reg_src_blk = reg_src.xetla_select<block_elems, 1>(
+ (i * num_block_x + j) * block_elems);
+ auto reg_dst_blk = reg_dst.xetla_select<block_elems, 1>(
+ (i * num_block_x + j) * block_elems);
+ for (int row_i = 0; row_i < block_size_y; row_i += vnni_row) {
+ auto reg_src_move
+ = reg_src_blk
+ .xetla_select<move_elems, 1>(
+ row_i * block_size_x)
+ .xetla_format<native_type_t<move_dtype>>();
+ auto reg_dst_move
+ = reg_dst_blk
+ .xetla_select<move_elems, 1>(
+ row_i * block_size_x)
+ .xetla_format<native_type_t<move_dtype>>();
+#pragma unroll
+ for (int move_i = 0; move_i < select_stride; move_i++) {
+ if constexpr (sizeof(dtype_dst) > sizeof(dtype_src)) {
+ reg_dst_move.xetla_select<block_size_x, 1>(
+ move_i * block_size_x)
+ = reg_src_move.xetla_select<block_size_x,
+ select_stride>(move_i);
+ } else {
+ reg_dst_move.xetla_select<block_size_x, select_stride>(
+ move_i)
+ = reg_src_move.xetla_select<block_size_x, 1>(
+ move_i * block_size_x);
+ }
+ }
+ }
+ }
+ }
+ // process the tail
+ if constexpr ((tile_size_y % block_size_y) != 0) {
+ constexpr int i = tile_size_y / block_size_y;
+ constexpr uint32_t remain_elems_start = i * block_size_y * tile_size_x;
+ constexpr uint32_t remain_size_y = tile_size_y % block_size_y;
+ constexpr uint32_t remain_block_elems = remain_size_y * block_size_x;
+#pragma unroll
+ for (int j = 0; j < num_block_x; j++) {
+ auto reg_src_blk = reg_src.xetla_select<remain_block_elems, 1>(
+ remain_elems_start + j * remain_block_elems);
+ auto reg_dst_blk = reg_dst.xetla_select<remain_block_elems, 1>(
+ remain_elems_start + j * remain_block_elems);
+ // for mma, here we can guarantee that the remaining is a multiple of
+ // vnni_row
+ for (int row_i = 0; row_i < remain_size_y; row_i += vnni_row) {
+ auto reg_src_move
+ = reg_src_blk
+ .xetla_select<move_elems, 1>(
+ row_i * block_size_x)
+ .xetla_format<native_type_t<move_dtype>>();
+ auto reg_dst_move
+ = reg_dst_blk
+ .xetla_select<move_elems, 1>(
+ row_i * block_size_x)
+ .xetla_format<native_type_t<move_dtype>>();
+#pragma unroll
+ for (int move_i = 0; move_i < select_stride; move_i++) {
+ if constexpr (sizeof(dtype_dst) > sizeof(dtype_src)) {
+ reg_dst_move.xetla_select<block_size_x, 1>(
+ move_i * block_size_x)
+ = reg_src_move.xetla_select<block_size_x,
+ select_stride>(move_i);
+ } else {
+ reg_dst_move.xetla_select<block_size_x, select_stride>(
+ move_i)
+ = reg_src_move.xetla_select<block_size_x, 1>(
+ move_i * block_size_x);
+ }
+ }
+ }
+ }
+ }
+ dst.reg = reg_dst;
+}
+
+/// @brief Broadcasts 1d src tile to the entire 2d tile, as well as do the data conversion.
+///
+/// @tparam T_dst Is the destination tile data type.
+/// @tparam T_src Is the source tile data type, interpreted as 1D data.
+/// @param dst Is the reference of the destination tile object.
+/// @param src Is the reference of the destination tile object.
+/// @return No return, in-place update in the destination tile.
+template <typename T_dst, typename T_src>
+__XETLA_API
+ typename std::enable_if_t<(T_dst::register_layout == reg_layout::tiled)
+ && (T_src::register_layout == reg_layout::tiled)
+ && (T_src::tile_size_x == T_dst::tile_size_x)
+ && (T_src::tile_size_y == 1)>
+ row_broadcast(T_dst &dst, T_src &src) {
+ static constexpr uint32_t dst_tile_size_y = T_dst::tile_size_y;
+ static constexpr uint32_t dst_tile_size_x = T_dst::tile_size_x;
+ static constexpr uint32_t dst_tile_elems = T_dst::tile_elems;
+ static constexpr uint32_t dst_block_size_y = T_dst::block_size_y;
+ static constexpr uint32_t dst_block_size_x = T_dst::block_size_x;
+ static constexpr uint32_t dst_block_elems = T_dst::block_elems;
+ static constexpr int32_t dst_num_block_y = T_dst::num_block_y;
+ static constexpr int32_t dst_num_block_x = T_dst::num_block_x;
+ using dst_dtype = typename T_dst::dtype;
+ using src_dtype = typename T_src::dtype;
+
+#pragma unroll
+ for (int i = 0; i < dst_tile_size_y / dst_block_size_y; i++) {
+#pragma unroll
+ for (int j = 0; j < dst_num_block_x; j++) {
+ auto dst_reg
+ = (dst.reg)
+ .xetla_select<dst_block_elems, 1>(
+ (i * dst_num_block_x + j)
+ * dst_block_elems)
+ .xetla_format<native_type_t<dst_dtype>,
+ dst_block_size_y, dst_block_size_x>();
+#pragma unroll
+ for (int row_i = 0; row_i < dst_block_size_y; row_i++) {
+ auto src_reg = src.reg.xetla_select<dst_block_size_x, 1>(
+ j * dst_block_size_x);
+ dst_reg.row(row_i)
+ = xetla_cvt<dst_dtype, src_dtype, dst_block_size_x>(
+ src_reg);
+ }
+ }
+ }
+
+ // process the tail
+ if constexpr ((dst_tile_size_y % dst_block_size_y) != 0) {
+ constexpr uint32_t tail_start_y
+ = dst_tile_size_y / dst_block_size_y * dst_block_size_y;
+ constexpr int32_t dst_tail_size_y = dst_tile_size_y % dst_block_size_y;
+ constexpr int32_t dst_tail_block_elems
+ = dst_tail_size_y * dst_block_size_x;
+#pragma unroll
+ for (int j = 0; j < dst_num_block_x; j++) {
+ auto dst_reg = (dst.reg)
+ .xetla_select<dst_tail_block_elems, 1>(
+ tail_start_y * dst_tile_size_x
+ + j * dst_tail_block_elems)
+ .xetla_format<native_type_t<dst_dtype>,
+ dst_tail_size_y, dst_block_size_x>();
+#pragma unroll
+ for (int row_i = 0; row_i < dst_tail_size_y; row_i++) {
+ auto src_reg = src.reg.xetla_select<dst_block_size_x, 1>(
+ j * dst_block_size_x);
+ dst_reg.row(row_i)
+ = xetla_cvt<dst_dtype, src_dtype, dst_block_size_x>(
+ src_reg);
+ }
+ }
+ }
+}
+
+/// @brief convert 2d tile in a tiled register layout to a 2d tile in a linear register layout
+///
+/// @tparam T_dst Is the destination tile data type.
+/// @tparam T_src Is the source tile data type.
+/// @param dst Is the reference of the destination tile object.
+/// @param src Is the reference of the destination tile object.
+/// @return No return, in-place update in the destination tile.
+template <typename T_dst, typename T_src>
+__XETLA_API typename std::enable_if_t<(T_dst::register_layout
+ == reg_layout::linear)
+ && (T_src::register_layout == reg_layout::tiled)
+ && (T_src::tile_size_x == T_dst::tile_size_x)
+ && (T_src::tile_size_y == T_dst::tile_size_y)
+ && (T_dst::tile_size_x == T_dst::block_size_x)
+ && (T_dst::tile_size_y == T_dst::block_size_y)
+ && (std::is_same<typename T_dst::dtype, typename T_src::dtype>::value)>
+layout_convert(T_dst &dst, T_src &src) {
+ using tile_desc = typename T_src::tile_desc;
+ using dtype = typename T_dst::dtype;
+ static constexpr uint32_t num_block_x = tile_desc::num_block_x;
+ static constexpr uint32_t num_block_y = tile_desc::num_block_y;
+ static constexpr uint32_t block_elems = tile_desc::block_elems;
+ static constexpr uint32_t block_size_x = tile_desc::block_size_x;
+ static constexpr uint32_t block_size_y = tile_desc::block_size_y;
+ static constexpr uint32_t tile_size_x = tile_desc::tile_size_x;
+ static constexpr uint32_t tile_size_y = tile_desc::tile_size_y;
+
+ auto dst_reg = dst.reg.xetla_format<native_type_t<dtype>, tile_size_y,
+ tile_size_x>();
+#pragma unroll
+ for (int i = 0; i < num_block_y; ++i) {
+ uint32_t offset_y = i * block_size_y;
+#pragma unroll
+ for (int j = 0; j < num_block_x; ++j) {
+ uint32_t offset_x = j * block_size_x;
+ auto src_reg = src.reg.xetla_select<block_elems, 1>(
+ (i * num_block_x + j) * block_elems);
+ dst_reg.xetla_select<block_size_y, 1, block_size_x, 1>(
+ offset_y, offset_x)
+ = src_reg;
+ }
+ }
+ // process the tail
+ if constexpr (tile_desc::remained_size_y > 0) {
+ constexpr uint32_t remained_size_y = tile_desc::remained_size_y;
+ constexpr uint32_t offset_y = tile_size_y - remained_size_y;
+ constexpr uint32_t processed_elems = offset_y * tile_size_x;
+ constexpr uint32_t remained_block_elems
+ = remained_size_y * block_size_x;
+#pragma unroll
+ for (int j = 0; j < num_block_x; ++j) {
+ uint32_t offset_x = j * block_size_x;
+ auto src_reg = src.reg.xetla_select<remained_block_elems, 1>(
+ processed_elems + j * remained_block_elems);
+ dst_reg.xetla_select<remained_size_y, 1, block_size_x, 1>(
+ offset_y, offset_x)
+ = src_reg;
+ }
+ }
+}
+
+/// @brief convert 2d tile in a linear register layout to a 2d tile in a tiled register layout
+///
+/// @tparam T_dst Is the destination tile data type.
+/// @tparam T_src Is the source tile data type.
+/// @param dst Is the reference of the destination tile object.
+/// @param src Is the reference of the destination tile object.
+/// @return No return, in-place update in the destination tile.
+template <typename T_dst, typename T_src>
+__XETLA_API typename std::enable_if_t<(T_dst::register_layout
+ == reg_layout::tiled)
+ && (T_src::register_layout == reg_layout::linear)
+ && (T_dst::tile_size_x == T_src::tile_size_x)
+ && (T_dst::tile_size_y == T_src::tile_size_y)
+ && (T_src::tile_size_x == T_src::block_size_x)
+ && (T_src::tile_size_y == T_src::block_size_y)
+ && (std::is_same<typename T_dst::dtype, typename T_src::dtype>::value)>
+layout_convert(T_dst &dst, T_src &src) {
+ using tile_desc = typename T_dst::tile_desc;
+ using dtype = typename T_dst::dtype;
+ static constexpr uint32_t num_block_x = tile_desc::num_block_x;
+ static constexpr uint32_t num_block_y = tile_desc::num_block_y;
+ static constexpr uint32_t block_elems = tile_desc::block_elems;
+ static constexpr uint32_t block_size_x = tile_desc::block_size_x;
+ static constexpr uint32_t block_size_y = tile_desc::block_size_y;
+ static constexpr uint32_t tile_size_x = tile_desc::tile_size_x;
+ static constexpr uint32_t tile_size_y = tile_desc::tile_size_y;
+
+ auto src_reg = src.reg.xetla_format<native_type_t<dtype>, tile_size_y,
+ tile_size_x>();
+#pragma unroll
+ for (int i = 0; i < num_block_y; ++i) {
+ uint32_t offset_y = i * block_size_y;
+#pragma unroll
+ for (int j = 0; j < num_block_x; ++j) {
+ uint32_t offset_x = j * block_size_x;
+ auto dst_reg = dst.reg.xetla_select<block_elems, 1>(
+ (i * num_block_x + j) * block_elems);
+ dst_reg = src_reg.xetla_select<block_size_y, 1, block_size_x, 1>(
+ offset_y, offset_x);
+ }
+ }
+ // process the tail
+ if constexpr (tile_desc::remained_size_y > 0) {
+ constexpr uint32_t remained_size_y = tile_desc::remained_size_y;
+ constexpr uint32_t offset_y = tile_size_y - remained_size_y;
+ constexpr uint32_t processed_elems = offset_y * tile_size_x;
+ constexpr uint32_t remained_block_elems
+ = remained_size_y * block_size_x;
+#pragma unroll
+ for (int j = 0; j < num_block_x; ++j) {
+ uint32_t offset_x = j * block_size_x;
+ auto dst_reg = dst.reg.xetla_select<remained_block_elems, 1>(
+ processed_elems + j * remained_block_elems);
+ dst_reg = src_reg.xetla_select<remained_size_y, 1, block_size_x, 1>(
+ offset_y, offset_x);
+ }
+ }
+}
+} // namespace gpu::xetla::subgroup
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/subgroup/tile/impl/payload_xe.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/subgroup/tile/impl/payload_xe.hpp
new file mode 100644
index 00000000000..c718962a8fd
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/subgroup/tile/impl/payload_xe.hpp
@@ -0,0 +1,1615 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#include "subgroup/tile/api.hpp"
+#include "subgroup/tile/impl/op_function.hpp"
+
+namespace gpu::xetla::subgroup {
+
+/// @brief Is to describe the global memory surface for block-2d load/store
+/// for each block in one tile, a payload message is prepared here.
+/// in tile_load case, memory transpose, register transpose, memory transform
+/// and dword transpose can be enable.
+/// While in tile store case, we only support row major store, no register
+/// operations can be applied.
+/// @tparam dtype Is the data type
+/// @tparam tile_desc_ Is the tile descriptor
+/// @tparam mem_layout_ Is the memory layout
+template <typename dtype_, typename tile_desc_, mem_layout mem_layout_,
+ gpu_arch arch_tag_, uint32_t alignment_, uint32_t dim_>
+struct mem_payload_t<
+ mem_desc_t<dtype_, mem_layout_, mem_space::global, alignment_, dim_>,
+ tile_desc_, msg_type::block_2d, arch_tag_,
+ std::enable_if_t<(arch_tag_ == gpu_arch::Xe)>> {
+ using tile_desc = tile_desc_;
+ using mem_desc_t = mem_desc_t<dtype_, mem_layout_, mem_space::global,
+ alignment_, dim_>;
+ using dtype = dtype_;
+ static constexpr msg_type message_type = msg_type::block_2d;
+ static constexpr mem_space memory_space = mem_space::global;
+ static constexpr mem_layout memory_layout = mem_layout_;
+ static constexpr gpu_arch arch_tag = arch_tag_;
+
+private:
+ static constexpr uint32_t block_size_x = tile_desc::block_size_x;
+ static constexpr uint32_t block_size_y = tile_desc::block_size_y;
+ static constexpr uint32_t num_block_x = tile_desc::num_block_x;
+ static constexpr uint32_t num_block_y = tile_desc::num_block_y;
+ static constexpr uint32_t num_block = tile_desc::num_block;
+ static constexpr uint32_t remained_size_y = tile_desc::remained_size_y;
+ using this_payload_t = mem_payload_t<mem_desc_t, tile_desc,
+ msg_type::block_2d, arch_tag>;
+
+public:
+ static constexpr bool mem_transpose
+ = memory_layout == mem_layout::col_major;
+
+ static constexpr reg_layout register_layout = tile_desc::register_layout;
+ static constexpr bool reg_transpose
+ = register_layout == reg_layout::transpose_tiled;
+ static constexpr bool trans = mem_transpose ^ reg_transpose;
+
+ static constexpr bool mem_transform = (sizeof(dtype) < 4) && !mem_transpose
+ && (register_layout == reg_layout::vnni_tiled
+ || register_layout == reg_layout::vnni_tiled_col_major);
+ static constexpr bool mem_dword_transpose = (sizeof(dtype) < 4) && trans;
+
+ using mem_dtype = typename std::conditional<mem_dword_transpose, uint32_t,
+ dtype>::type;
+ static constexpr uint32_t scale_factor = sizeof(mem_dtype) / sizeof(dtype);
+
+ xetla_vector<uint32_t, 16 * num_block> payloads;
+
+ inline mem_payload_t(const this_payload_t &rhs) {
+ this->payloads = rhs.payloads;
+ }
+
+ inline mem_payload_t(mem_desc_t &mem_desc) {
+ xetla_tdescriptor base_tdesc = mem_desc.get_tdesc();
+ int32_t offset
+ = gpu::xetla::detail::xetla_get_tensor_offset_x(base_tdesc)
+ / int32_t(scale_factor);
+ gpu::xetla::detail::xetla_set_tensor_offset_x(
+ base_tdesc.xetla_format<uint32_t>(), offset);
+ prepare_tdesc(base_tdesc);
+ }
+
+ inline mem_payload_t(dtype *p, uint32_t surface_width,
+ uint32_t surface_height, uint32_t surface_pitch,
+ int32_t surface_offset_x = 0, int32_t surface_offset_y = 0) {
+ xetla_tdescriptor base_tdesc;
+ xetla_fill_tdesc(base_tdesc.xetla_format<uint32_t>(), p, surface_width,
+ surface_height, surface_pitch,
+ surface_offset_x / int32_t(scale_factor), surface_offset_y);
+ prepare_tdesc(base_tdesc);
+ }
+
+ __XETLA_API void init(mem_desc_t &mem_desc) {
+ xetla_tdescriptor base_tdesc = mem_desc.get_tdesc();
+ int32_t offset
+ = gpu::xetla::detail::xetla_get_tensor_offset_x(base_tdesc)
+ / int32_t(scale_factor);
+ gpu::xetla::detail::xetla_set_tensor_offset_x(
+ base_tdesc.xetla_format<uint32_t>(), offset);
+ prepare_tdesc(base_tdesc);
+ }
+
+ __XETLA_API void init(xetla_tdescriptor base_tdesc) {
+ int32_t offset
+ = gpu::xetla::detail::xetla_get_tensor_offset_x(base_tdesc)
+ / int32_t(scale_factor);
+ gpu::xetla::detail::xetla_set_tensor_offset_x(
+ base_tdesc.xetla_format<uint32_t>(), offset);
+ prepare_tdesc(base_tdesc);
+ }
+
+ __XETLA_API void init(dtype *p, uint32_t surface_width,
+ uint32_t surface_height, uint32_t surface_pitch,
+ int32_t surface_offset_x = 0, int32_t surface_offset_y = 0) {
+ xetla_tdescriptor base_tdesc;
+ xetla_fill_tdesc(base_tdesc.xetla_format<uint32_t>(), p, surface_width,
+ surface_height, surface_pitch,
+ surface_offset_x / int32_t(scale_factor), surface_offset_y);
+ prepare_tdesc(base_tdesc);
+ }
+
+ inline mem_payload_t() = default;
+ // Be aware of the risks: Rule of three (copy constructor, copy assignment, destructor)
+ // Please check if you need to add self-define destructor
+ // ~mem_payload_t(){}
+
+ inline this_payload_t &operator=(const this_payload_t &rhs) {
+ this->payloads = rhs.payloads;
+ return *this;
+ }
+
+ template <tdesc_update_dir update_dir = tdesc_update_dir::x_dir>
+ __XETLA_API void update_tdesc(int offset) {
+ auto payloads_2d = payloads.xetla_format<uint32_t, num_block, 16>();
+ if constexpr (update_dir == tdesc_update_dir::x_dir) {
+#pragma unroll
+ for (int i = 0; i < num_block; i++) {
+ xetla_update_tdesc_offsetx(
+ payloads_2d.row(i), offset / int32_t(scale_factor));
+ }
+ } else {
+#pragma unroll
+ for (int i = 0; i < num_block; i++) {
+ xetla_update_tdesc_offsety(payloads_2d.row(i), offset);
+ }
+ }
+ }
+
+ __XETLA_API void update_tdesc_base_address(int offset) {
+ auto payloads_2d = payloads.xetla_format<uint32_t, num_block, 16>();
+#pragma unroll
+ for (int i = 0; i < num_block; i++) {
+ xetla_update_tdesc_base_address(payloads_2d.row(i), offset);
+ }
+ }
+
+ __XETLA_API void set_tdesc_width(uint32_t size) {
+ auto payloads_2d = payloads.xetla_format<uint32_t, num_block, 16>();
+#pragma unroll
+ for (int i = 0; i < num_block; i++) {
+ xetla_set_tdesc_width<dtype>(payloads_2d.row(i), size);
+ }
+ }
+
+ __XETLA_API void set_tdesc_pitch(uint32_t size) {
+ auto payloads_2d = payloads.xetla_format<uint32_t, num_block, 16>();
+#pragma unroll
+ for (int i = 0; i < num_block; i++) {
+ xetla_set_tdesc_pitch<dtype>(payloads_2d.row(i), size);
+ }
+ }
+
+ __XETLA_API void set_tdesc_height(uint32_t size) {
+ auto payloads_2d = payloads.xetla_format<uint32_t, num_block, 16>();
+#pragma unroll
+ for (int i = 0; i < num_block; i++) {
+ xetla_set_tdesc_height(payloads_2d.row(i), size);
+ }
+ }
+
+ __XETLA_API void update_tdesc_base_address_masked(
+ int offset, uint16_t mask = 1) {
+ auto payloads_2d = payloads.xetla_format<uint32_t, num_block, 16>();
+#pragma unroll
+ for (int i = 0; i < num_block; i++) {
+ xetla_update_tdesc_base_address(payloads_2d.row(i), offset);
+ }
+
+#pragma unroll
+ for (int i = 0; i < num_block; i++) {
+ xetla_tdesc_mask_op(payloads_2d.row(i), mask);
+ }
+ }
+ __XETLA_API void set_tdesc_base_address_masked(
+ uint64_t offset, uint16_t mask = 1) {
+ auto payloads_2d = payloads.xetla_format<uint32_t, num_block, 16>();
+#pragma unroll
+ for (int i = 0; i < num_block; i++) {
+ gpu::xetla::detail::xetla_set_tensor_base_address(
+ payloads_2d.row(i), offset);
+ }
+
+#pragma unroll
+ for (int i = 0; i < num_block; i++) {
+ xetla_tdesc_mask_op(payloads_2d.row(i), mask);
+ }
+ }
+
+ __XETLA_API void set_tdesc_base_address(uint64_t addr) {
+ auto payloads_2d = payloads.xetla_format<uint32_t, num_block, 16>();
+#pragma unroll
+ for (int i = 0; i < num_block; i++) {
+ gpu::xetla::detail::xetla_set_tensor_base_address(
+ payloads_2d.row(i), addr);
+ }
+ }
+
+ __XETLA_API void set_offset(int32_t offset_x, int32_t offset_y) {
+ auto payloads_2d = payloads.xetla_format<uint32_t, num_block, 16>();
+ constexpr uint32_t arr_len = 1;
+ int32_t base_offset_y = offset_y;
+#pragma unroll
+ for (int i = 0; i < num_block_y; i++) {
+ auto tdesc_row_2d = payloads_2d.xetla_select<num_block_x, 1, 16, 1>(
+ i * num_block_x, 0);
+
+ int32_t base_offset_x = offset_x;
+#pragma unroll
+ for (int j = 0; j < num_block_x; j++) {
+ // To mimic dw transpose for word/byte data type with transpose and pack
+ constexpr uint8_t block_width = mem_transpose
+ ? (block_size_y / scale_factor)
+ : (block_size_x / scale_factor);
+ constexpr uint8_t block_height
+ = mem_transpose ? block_size_x : block_size_y;
+ constexpr uint32_t block_widthx_widthy_arrlen
+ = (block_width - 1) | ((block_height - 1) << 8)
+ | ((arr_len - 1) << 16);
+ gpu::xetla::detail::xetla_set_block_widthx_widthy_arrlen(
+ tdesc_row_2d.row(j), block_widthx_widthy_arrlen);
+
+ int32_t offset_width = mem_transpose
+ ? (base_offset_y / int32_t(scale_factor))
+ : (base_offset_x / int32_t(scale_factor));
+ int32_t offset_height
+ = mem_transpose ? base_offset_x : base_offset_y;
+
+ gpu::xetla::detail::xetla_set_tensor_offset_x(
+ tdesc_row_2d.row(j), offset_width);
+ gpu::xetla::detail::xetla_set_tensor_offset_y(
+ tdesc_row_2d.row(j), offset_height);
+
+ base_offset_x += block_size_x * arr_len;
+ }
+ base_offset_y += block_size_y;
+ }
+ // process the tail
+ if constexpr (remained_size_y > 0) {
+ auto tdesc_row_2d = payloads_2d.xetla_select<num_block_x, 1, 16, 1>(
+ num_block_y * num_block_x, 0);
+ // this is exactly copy paste from above. so maybe worth createing some function
+ int32_t base_offset_x = offset_x;
+#pragma unroll
+ for (int j = 0; j < num_block_x; j++) {
+ // To mimic dw transpose for word/byte data type with transpose and pack
+ constexpr uint8_t block_width = mem_transpose
+ ? (block_size_y / scale_factor)
+ : (block_size_x / scale_factor);
+ constexpr uint8_t block_height
+ = mem_transpose ? block_size_x : block_size_y;
+ constexpr uint32_t block_widthx_widthy_arrlen
+ = (block_width - 1) | ((block_height - 1) << 8)
+ | ((arr_len - 1) << 16);
+ gpu::xetla::detail::xetla_set_block_widthx_widthy_arrlen(
+ tdesc_row_2d.row(j), block_widthx_widthy_arrlen);
+
+ int32_t offset_width = mem_transpose
+ ? (base_offset_y / int32_t(scale_factor))
+ : (base_offset_x / int32_t(scale_factor));
+ int32_t offset_height
+ = mem_transpose ? base_offset_x : base_offset_y;
+
+ gpu::xetla::detail::xetla_set_tensor_offset_x(
+ tdesc_row_2d.row(j), offset_width);
+ gpu::xetla::detail::xetla_set_tensor_offset_y(
+ tdesc_row_2d.row(j), offset_height);
+
+ base_offset_x += block_size_x;
+ }
+ }
+ }
+
+private:
+ __XETLA_API void prepare_tdesc(xetla_tdescriptor base_tdesc) {
+ auto payloads_2d = payloads.xetla_format<uint32_t, num_block, 16>();
+ uint32_t base_offset_y = 0;
+#pragma unroll
+ for (int i = 0; i < num_block_y; i++) {
+ auto tdesc_row_2d = payloads_2d.xetla_select<num_block_x, 1, 16, 1>(
+ i * num_block_x, 0);
+ prepare_tile_desc_core<num_block_x, block_size_x, block_size_y, 1,
+ mem_transpose>(tdesc_row_2d, base_tdesc, base_offset_y);
+ base_offset_y += block_size_y;
+ }
+ // process the tail
+ if constexpr (remained_size_y > 0) {
+ auto tdesc_row_2d = payloads_2d.xetla_select<num_block_x, 1, 16, 1>(
+ num_block_y * num_block_x, 0);
+ prepare_tile_desc_core<num_block_x, block_size_x, remained_size_y,
+ 1, mem_transpose>(tdesc_row_2d, base_tdesc, base_offset_y);
+ }
+ }
+
+ template <uint32_t num_tdesc, uint32_t size_x, uint32_t size_y,
+ uint8_t arr_len, bool trans>
+ __XETLA_API static void prepare_tile_desc_core(
+ xetla_matrix_ref<uint32_t, num_tdesc, 16> __REF__ payloads_row_2d,
+ xetla_tdescriptor base_tdesc, uint32_t base_offset_y) {
+ uint32_t base_offset_x = 0;
+#pragma unroll
+ for (int j = 0; j < num_tdesc; j++) {
+ payloads_row_2d.row(j) = base_tdesc;
+ // To mimic dw transpose for word/byte data type with transpose and pack
+ constexpr uint8_t block_width
+ = trans ? (size_y / scale_factor) : (size_x / scale_factor);
+ constexpr uint8_t block_height = trans ? size_x : size_y;
+ constexpr uint32_t block_widthx_widthy_arrlen = (block_width - 1)
+ | ((block_height - 1) << 8) | ((arr_len - 1) << 16);
+ gpu::xetla::detail::xetla_set_block_widthx_widthy_arrlen(
+ payloads_row_2d.row(j), block_widthx_widthy_arrlen);
+
+ // To mimic dw transpose for word/byte data type with transpose and pack
+ uint32_t offset_width = trans
+ ? (base_offset_y / int32_t(scale_factor))
+ : (base_offset_x / int32_t(scale_factor));
+ uint32_t offset_height = trans ? base_offset_x : base_offset_y;
+
+ xetla_update_tdesc_offsetx(payloads_row_2d.row(j), offset_width);
+ xetla_update_tdesc_offsety(payloads_row_2d.row(j), offset_height);
+ base_offset_x += size_x * arr_len;
+ }
+ }
+};
+
+/// @brief Is to describe the global memory surface for block-1d load/store
+/// For a block-1d payload message we need to set the base address and
+/// offset of surface.
+/// memory transpose and register operations can not be applied here.
+/// 2d and 1d surface both can be accepted here
+/// @tparam dtype Is the data type
+/// @tparam tile_desc_ Is the tile descriptor
+/// @tparam mem_layout_ Is the memory layout
+template <typename dtype_, typename tile_desc_, gpu_arch arch_tag_,
+ uint32_t alignment_>
+struct mem_payload_t<mem_desc_t<dtype_, mem_layout::row_major,
+ mem_space::global, alignment_>,
+ tile_desc_, msg_type::block_1d, arch_tag_,
+ std::enable_if_t<(arch_tag_ == gpu_arch::Xe)>> {
+ using mem_desc_t = mem_desc_t<dtype_, mem_layout::row_major,
+ mem_space::global, alignment_>;
+ using dtype = dtype_;
+ using tile_desc = tile_desc_;
+ static constexpr mem_space memory_space = mem_space::global;
+ static constexpr mem_layout memory_layout = mem_layout::row_major;
+ static constexpr msg_type message_type = msg_type::block_1d;
+ static constexpr uint32_t alignment_in_bytes
+ = mem_desc_t::alignment_in_bytes;
+ static constexpr gpu_arch arch_tag = arch_tag_;
+ static_assert((alignment_in_bytes % sizeof(uint32_t)) == 0,
+ "alignment should at least DW aligned");
+
+private:
+ static constexpr uint32_t tile_size_x = tile_desc::tile_size_x;
+ static constexpr uint32_t tile_size_y = tile_desc::tile_size_y;
+ static_assert(tile_size_y == 1,
+ "For tile_size_y > 1 case, please use 2d block message! ");
+ using this_payload_t = mem_payload_t<mem_desc_t, tile_desc,
+ msg_type::block_1d, arch_tag>;
+
+public:
+ static constexpr uint32_t bytes_per_row = tile_size_x * sizeof(dtype);
+ using mem_dtype = typename std::conditional<
+ (bytes_per_row % sizeof(uint64_t) == 0)
+ && (alignment_in_bytes % sizeof(uint64_t) == 0),
+ uint64_t,
+ typename std::conditional<(bytes_per_row % sizeof(uint32_t) == 0),
+ uint32_t, dtype>::type>::type;
+ static constexpr uint32_t scale_factor = sizeof(mem_dtype) / sizeof(dtype);
+
+ uint64_t base_offset;
+ mem_dtype *base_ptr;
+ uint32_t pitch_in_bytes;
+
+ inline mem_payload_t(mem_desc_t &mem_tdesc) {
+ pitch_in_bytes = mem_tdesc.shape.stride_x * sizeof(dtype);
+ uint32_t offset_x = mem_tdesc.coord.x;
+ uint32_t offset_y = mem_tdesc.coord.y;
+ base_offset = offset_y * pitch_in_bytes + offset_x * sizeof(dtype);
+ base_ptr = (mem_dtype *)mem_tdesc.base.base;
+ }
+
+ inline mem_payload_t(dtype *p, int surface_width, int surface_height,
+ int surface_pitch, int surface_offset_x, int surface_offset_y) {
+ pitch_in_bytes = surface_pitch * sizeof(dtype);
+ uint32_t offset_x = surface_offset_x;
+ uint32_t offset_y = surface_offset_y;
+ base_offset = offset_y * pitch_in_bytes + offset_x * sizeof(dtype);
+ base_ptr = (mem_dtype *)p;
+ }
+
+ __XETLA_API void init(mem_desc_t &mem_tdesc) {
+ pitch_in_bytes = mem_tdesc.shape.stride_x * sizeof(dtype);
+ uint32_t offset_x = mem_tdesc.coord.x;
+ uint32_t offset_y = mem_tdesc.coord.y;
+ base_offset = offset_y * pitch_in_bytes + offset_x * sizeof(dtype);
+ base_ptr = (mem_dtype *)mem_tdesc.base.base;
+ }
+
+ __XETLA_API void init(dtype *p, int surface_width, int surface_height,
+ int surface_pitch, int surface_offset_x, int surface_offset_y) {
+ pitch_in_bytes = surface_pitch * sizeof(dtype);
+ uint32_t offset_x = surface_offset_x;
+ uint32_t offset_y = surface_offset_y;
+ base_offset = offset_y * pitch_in_bytes + offset_x * sizeof(dtype);
+ base_ptr = (mem_dtype *)p;
+ }
+
+ inline mem_payload_t(const this_payload_t &rhs) {
+ this->base_offset = rhs.base_offset;
+ this->base_ptr = rhs.base_ptr;
+ this->pitch_in_bytes = rhs.pitch_in_bytes;
+ }
+
+ inline mem_payload_t() = default;
+ inline this_payload_t &operator=(const this_payload_t &rhs) {
+ this->base_offset = rhs.base_offset;
+ this->base_ptr = rhs.base_ptr;
+ this->pitch_in_bytes = rhs.pitch_in_bytes;
+ return *this;
+ }
+
+ template <tdesc_update_dir update_dir = tdesc_update_dir::x_dir>
+ __XETLA_API void update_tdesc(int offset) {
+ if constexpr (update_dir == tdesc_update_dir::x_dir) {
+ base_offset += int64_t(offset) * sizeof(dtype);
+ } else {
+ base_offset += int64_t(offset) * pitch_in_bytes;
+ }
+ }
+};
+
+/// @brief Is to describe the global memory surface for atomic store
+/// For atomic store, we need to prepare necessary information for
+/// each simd channel.
+/// @tparam dtype Is the data type
+/// @tparam tile_desc_ Is the tile descriptor
+/// @tparam mem_layout_ Is the memory layout
+template <typename dtype_, typename tile_desc_, mem_layout mem_layout_,
+ gpu_arch arch_tag_, uint32_t alignment_, uint32_t dim_>
+struct mem_payload_t<
+ mem_desc_t<dtype_, mem_layout_, mem_space::global, alignment_, dim_>,
+ tile_desc_, msg_type::atomic_add, arch_tag_,
+ std::enable_if_t<(arch_tag_ == gpu_arch::Xe)>> {
+ using mem_desc_t = mem_desc_t<dtype_, mem_layout_, mem_space::global,
+ alignment_, dim_>;
+
+ using dtype = dtype_;
+ using tile_desc = tile_desc_;
+ static constexpr mem_space memory_space = mem_space::global;
+ static constexpr mem_layout memory_layout = mem_layout_;
+ static constexpr msg_type message_type = msg_type::atomic_add;
+ static constexpr uint32_t alignment_in_bytes
+ = mem_desc_t::alignment_in_bytes;
+ static constexpr gpu_arch arch_tag = arch_tag_;
+ static_assert(
+ sizeof(dtype) >= 2, "for atomic add, we only support W, DW or QW");
+
+private:
+ static constexpr uint32_t tile_size_x = tile_desc::tile_size_x;
+ static constexpr uint32_t tile_size_y = tile_desc::tile_size_y;
+ static constexpr uint32_t block_size_x = tile_desc::block_size_x;
+ static constexpr uint32_t block_size_y = tile_desc::block_size_y;
+ using this_payload_t = mem_payload_t<mem_desc_t, tile_desc,
+ msg_type::atomic_add, arch_tag>;
+
+public:
+ static constexpr uint32_t tile_bytes
+ = tile_size_x * tile_size_y * sizeof(dtype);
+ static constexpr uint32_t block_bytes
+ = block_size_x * block_size_y * sizeof(dtype);
+
+ // for pvc, we can use simd16 or simd32
+ static constexpr uint32_t min_store_bytes = 16 * sizeof(dtype);
+ static constexpr uint32_t max_store_bytes = 32 * sizeof(dtype);
+ static constexpr uint32_t num_channel
+ = ((tile_bytes % max_store_bytes) == 0
+ && (block_bytes % max_store_bytes) == 0)
+ ? 32
+ : 16;
+
+ static constexpr uint32_t num_channel_x = block_size_x;
+ static constexpr uint32_t num_channel_y = num_channel / num_channel_x;
+ static constexpr uint32_t store_elems = num_channel_y * block_size_x;
+
+ //may need to set it to be configurable later
+ using Toffset = uint32_t;
+
+ xetla_vector<Toffset, num_channel> channel_offset;
+ xetla_vector<uint32_t, num_channel> step_x;
+ xetla_vector<uint32_t, num_channel> step_y;
+ uint32_t pitch_in_bytes;
+ uint32_t width_in_elems;
+ uint32_t height_in_elems;
+ uint32_t base_x;
+ uint32_t base_y;
+ uint64_t base_pointer;
+
+ inline mem_payload_t(mem_desc_t &mem_tdesc) {
+ pitch_in_bytes = mem_tdesc.shape.stride_x * sizeof(dtype);
+ base_x = mem_tdesc.coord.x;
+ base_y = mem_tdesc.coord.y;
+ width_in_elems = mem_tdesc.shape.x;
+ height_in_elems = mem_tdesc.shape.y;
+ base_pointer = (uint64_t)mem_tdesc.base.base;
+ base_pointer += base_y * pitch_in_bytes + base_x * sizeof(dtype);
+ xetla_vector<uint32_t, num_channel> channel_index
+ = xetla_vector_gen<uint32_t, num_channel>(0, 1);
+ step_x = channel_index % num_channel_x;
+ step_y = channel_index / num_channel_x;
+ channel_offset = step_x * sizeof(dtype) + step_y * pitch_in_bytes;
+ }
+
+ inline mem_payload_t(dtype *p, int surface_width, int surface_height,
+ int surface_pitch, int surface_offset_x, int surface_offset_y) {
+ pitch_in_bytes = surface_pitch * sizeof(dtype);
+ base_x = surface_offset_x;
+ base_y = surface_offset_y;
+ width_in_elems = surface_width;
+ height_in_elems = surface_height;
+ base_pointer = (uint64_t)p;
+ base_pointer += base_y * pitch_in_bytes + base_x * sizeof(dtype);
+ xetla_vector<uint32_t, num_channel> channel_index
+ = xetla_vector_gen<uint32_t, num_channel>(0, 1);
+ step_x = channel_index % num_channel_x;
+ step_y = channel_index / num_channel_x;
+ channel_offset = step_x * sizeof(dtype) + step_y * pitch_in_bytes;
+ }
+
+ __XETLA_API void init(dtype *p, int surface_width, int surface_height,
+ int surface_pitch, int surface_offset_x, int surface_offset_y) {
+ pitch_in_bytes = surface_pitch * sizeof(dtype);
+ base_x = surface_offset_x;
+ base_y = surface_offset_y;
+ width_in_elems = surface_width;
+ height_in_elems = surface_height;
+ base_pointer = (uint64_t)p;
+ base_pointer += base_y * pitch_in_bytes + base_x * sizeof(dtype);
+ xetla_vector<uint32_t, num_channel> channel_index
+ = xetla_vector_gen<uint32_t, num_channel>(0, 1);
+ step_x = channel_index % num_channel_x;
+ step_y = channel_index / num_channel_x;
+ channel_offset = step_x * sizeof(dtype) + step_y * pitch_in_bytes;
+ }
+
+ __XETLA_API void init(mem_desc_t &mem_tdesc) {
+ pitch_in_bytes = mem_tdesc.shape.stride_x * sizeof(dtype);
+ base_x = mem_tdesc.coord.x;
+ base_y = mem_tdesc.coord.y;
+ width_in_elems = mem_tdesc.shape.x;
+ height_in_elems = mem_tdesc.shape.y;
+ base_pointer = (uint64_t)mem_tdesc.base.base;
+ base_pointer += base_y * pitch_in_bytes + base_x * sizeof(dtype);
+ xetla_vector<uint32_t, num_channel> channel_index
+ = xetla_vector_gen<uint32_t, num_channel>(0, 1);
+ step_x = channel_index % num_channel_x;
+ step_y = channel_index / num_channel_x;
+ channel_offset = step_x * sizeof(dtype) + step_y * pitch_in_bytes;
+ }
+
+ inline mem_payload_t(const this_payload_t &rhs) {
+ this->pitch_in_bytes = rhs.pitch_in_bytes;
+ this->width_in_elems = rhs.width_in_elems;
+ this->height_in_elems = rhs.height_in_elems;
+ this->base_x = rhs.base_x;
+ this->base_y = rhs.base_y;
+ this->base_pointer = rhs.base_pointer;
+ this->channel_offset = rhs.channel_offset;
+ this->step_x = rhs.step_x;
+ this->step_y = rhs.step_y;
+ }
+
+ inline mem_payload_t() = default;
+ inline this_payload_t &operator=(const this_payload_t &rhs) {
+ this->pitch_in_bytes = rhs.pitch_in_bytes;
+ this->width_in_elems = rhs.width_in_elems;
+ this->height_in_elems = rhs.height_in_elems;
+ this->base_x = rhs.base_x;
+ this->base_y = rhs.base_y;
+ this->base_pointer = rhs.base_pointer;
+ this->channel_offset = rhs.channel_offset;
+ this->step_x = rhs.step_x;
+ this->step_y = rhs.step_y;
+ return *this;
+ }
+
+ template <tdesc_update_dir update_dir = tdesc_update_dir::x_dir>
+ __XETLA_API void update_tdesc(int offset) {
+ if constexpr (update_dir == tdesc_update_dir::x_dir) {
+ base_pointer += int64_t(offset) * sizeof(dtype);
+ base_x += offset;
+ } else {
+ base_pointer += int64_t(offset) * pitch_in_bytes;
+ base_y += offset;
+ }
+ }
+
+ __XETLA_API void set_tdesc_base_address_masked(
+ uint64_t offset, uint16_t mask = 1) {
+ base_pointer = offset;
+ base_pointer += base_y * pitch_in_bytes + base_x * sizeof(dtype);
+ base_x += width_in_elems & (uint32_t)(mask - 1);
+ }
+};
+
+/// @brief Is to describe the shared local memory surface for block-1d load/store
+/// 1. data located in shared local memory 2. tile will be loaded / stored in 1d mode.
+/// @tparam dtype Is the data type
+/// @tparam tile_desc_ Is the tile descriptor
+/// @tparam mem_layout_ Is the memory layout
+template <typename dtype_, typename tile_desc_, gpu_arch arch_tag_,
+ uint32_t alignment_>
+struct mem_payload_t<
+ mem_desc_t<dtype_, mem_layout::row_major, mem_space::local, alignment_>,
+ tile_desc_, msg_type::block_1d, arch_tag_,
+ std::enable_if_t<(arch_tag_ == gpu_arch::Xe)>> {
+ using mem_desc_t = mem_desc_t<dtype_, mem_layout::row_major,
+ mem_space::local, alignment_>;
+ using dtype = dtype_;
+ using tile_desc = tile_desc_;
+ static constexpr mem_space memory_space = mem_space::local;
+ static constexpr mem_layout memory_layout = mem_layout::row_major;
+ static constexpr msg_type message_type = msg_type::block_1d;
+ static constexpr uint32_t alignment_in_bytes
+ = mem_desc_t::alignment_in_bytes;
+ static_assert((alignment_in_bytes % sizeof(uint32_t)) == 0,
+ "alignment should at least DW aligned");
+ static constexpr gpu_arch arch_tag = arch_tag_;
+
+private:
+ static constexpr uint32_t tile_size_x = tile_desc::tile_size_x;
+ static constexpr uint32_t tile_size_y = tile_desc::tile_size_y;
+ static constexpr uint32_t block_size_x = tile_desc::block_size_x;
+ static constexpr uint32_t block_size_y = tile_desc::block_size_y;
+ using this_payload_t = mem_payload_t<mem_desc_t, tile_desc,
+ msg_type::block_1d, arch_tag>;
+
+public:
+ static constexpr uint32_t tile_bytes
+ = tile_size_x * tile_size_y * sizeof(dtype);
+ static constexpr uint32_t block_bytes
+ = block_size_x * block_size_y * sizeof(dtype);
+ static constexpr uint32_t bytes_per_row = block_size_x * sizeof(dtype);
+ using mem_dtype = typename std::conditional<
+ (bytes_per_row % sizeof(uint64_t) == 0)
+ && (alignment_in_bytes % sizeof(uint64_t) == 0),
+ uint64_t,
+ typename std::conditional<(bytes_per_row % sizeof(uint32_t) == 0),
+ uint32_t, dtype>::type>::type;
+ static constexpr uint32_t scale_factor = sizeof(mem_dtype) / sizeof(dtype);
+
+ uint32_t base_address;
+ uint32_t address;
+ uint32_t pitch_in_bytes;
+
+ __XETLA_API void init(mem_desc_t &mem_tdesc) {
+ base_address = mem_tdesc.base.base;
+ pitch_in_bytes = mem_tdesc.shape.stride_x * sizeof(dtype);
+ uint32_t offset_x = mem_tdesc.coord.x;
+ uint32_t offset_y = mem_tdesc.coord.y;
+ address = offset_y * pitch_in_bytes + offset_x * sizeof(dtype);
+ }
+
+ __XETLA_API void init(uint32_t base, uint32_t surface_width,
+ uint32_t surface_height, uint32_t surface_pitch,
+ int32_t surface_offset_x, int32_t surface_offset_y) {
+ base_address = base;
+ uint32_t offset_x = surface_offset_x;
+ uint32_t offset_y = surface_offset_y;
+ pitch_in_bytes = surface_pitch * sizeof(dtype);
+ address = offset_y * pitch_in_bytes + offset_x * sizeof(dtype);
+ }
+
+ inline mem_payload_t(mem_desc_t &mem_tdesc) { init(mem_tdesc); }
+ inline mem_payload_t(uint32_t base, uint32_t surface_width,
+ uint32_t surface_height, uint32_t surface_pitch,
+ int32_t surface_offset_x, int32_t surface_offset_y) {
+ init(base, surface_width, surface_height, surface_pitch,
+ surface_offset_x, surface_offset_y);
+ }
+
+ inline mem_payload_t(const this_payload_t &rhs) {
+ this->base_address = rhs.base_address;
+ this->address = rhs.address;
+ this->pitch_in_bytes = rhs.pitch_in_bytes;
+ }
+
+ inline mem_payload_t() = default;
+ inline this_payload_t &operator=(const this_payload_t &rhs) {
+ this->base_address = rhs.base_address;
+ this->address = rhs.address;
+ this->pitch_in_bytes = rhs.pitch_in_bytes;
+ return *this;
+ }
+
+ template <tdesc_update_dir update_dir = tdesc_update_dir::x_dir>
+ __XETLA_API void update_tdesc(int32_t offset) {
+ if constexpr (update_dir == tdesc_update_dir::x_dir) {
+ address += offset * sizeof(dtype);
+ } else {
+ address += offset * pitch_in_bytes;
+ }
+ }
+
+ __XETLA_API void set_base_address(uint32_t base) {
+ this->base_address = base;
+ }
+};
+
+/// @brief Is to describe the global memory surface for unaligned-2d load/store
+/// for each block in one tile, a payload message is prepared here.
+/// in tile_load case, memory transpose, register transpose, memory transform
+/// and dword transpose can be enable.
+/// While in tile store case, we only support row major store, no register
+/// operations can be applied.
+/// @tparam dtype Is the data type
+/// @tparam tile_desc_ Is the tile descriptor
+/// @tparam mem_layout_ Is the memory layout
+template <typename dtype_, typename tile_desc_, mem_layout mem_layout_,
+ uint32_t alignment_, gpu_arch arch_tag_>
+struct mem_payload_t<
+ mem_desc_t<dtype_, mem_layout_, mem_space::global, alignment_>,
+ tile_desc_, msg_type::unaligned_2d, arch_tag_,
+ std::enable_if_t<(arch_tag_ == gpu_arch::Xe)>> {
+ using dtype = dtype_;
+ using mem_desc_t
+ = mem_desc_t<dtype_, mem_layout_, mem_space::global, alignment_>;
+ using tile_desc = tile_desc_;
+ static constexpr mem_space memory_space = mem_space::global;
+ static constexpr mem_layout memory_layout = mem_layout_;
+ static constexpr msg_type message_type = msg_type::unaligned_2d;
+ static constexpr uint32_t alignment_in_bytes
+ = mem_desc_t::alignment_in_bytes;
+ static constexpr gpu_arch arch_tag = arch_tag_;
+
+private:
+ static constexpr uint32_t tile_size_x = tile_desc::tile_size_x;
+ static constexpr uint32_t tile_size_y = tile_desc::tile_size_y;
+ static constexpr uint32_t block_size_x = tile_desc::block_size_x;
+ static constexpr uint32_t block_size_y = tile_desc::block_size_y;
+
+ using this_payload_t = mem_payload_t<mem_desc_t, tile_desc,
+ msg_type::unaligned_2d, arch_tag_>;
+
+public:
+ static constexpr bool mem_transpose
+ = memory_layout == mem_layout::col_major;
+
+ static constexpr reg_layout register_layout = tile_desc::register_layout;
+ static constexpr bool reg_transpose
+ = register_layout == reg_layout::transpose_tiled;
+ static constexpr bool trans = mem_transpose ^ reg_transpose;
+
+ static constexpr bool mem_transform = (sizeof(dtype) < 4)
+ && (register_layout == reg_layout::vnni_tiled
+ || register_layout == reg_layout::vnni_tiled_col_major);
+
+ static constexpr uint32_t tile_bytes
+ = tile_size_x * tile_size_y * sizeof(dtype);
+ static constexpr uint32_t block_bytes
+ = block_size_x * block_size_y * sizeof(dtype);
+
+ using mem_dtype = typename std::conditional<
+ (alignment_in_bytes % sizeof(uint64_t) == 0), uint64_t,
+ typename std::conditional<(alignment_in_bytes % sizeof(uint32_t)
+ == 0),
+ uint32_t, dtype>::type>::type;
+ static constexpr uint32_t scale_factor = sizeof(mem_dtype) / sizeof(dtype);
+
+ // for pvc, we can use simd16 or simd32
+ static constexpr uint32_t min_store_bytes = 16 * sizeof(dtype);
+ static constexpr uint32_t max_store_bytes = 32 * sizeof(dtype);
+ static constexpr uint32_t num_channel
+ = ((tile_bytes % max_store_bytes) == 0
+ && (block_bytes % max_store_bytes) == 0)
+ ? 32
+ : 16;
+
+ static constexpr uint32_t num_channel_x
+ = block_size_x * sizeof(dtype) / sizeof(mem_dtype);
+ static constexpr uint32_t num_channel_y = num_channel / num_channel_x;
+
+ xetla_vector<uint32_t, num_channel> channel_offset;
+ xetla_vector<uint32_t, num_channel> step_x;
+ xetla_vector<uint32_t, num_channel> step_y;
+
+ uint64_t base_offset;
+ uint32_t base_x;
+ uint32_t base_y;
+ uint32_t width_in_elems;
+ uint32_t height_in_elems;
+
+ mem_dtype *base_ptr;
+ uint32_t pitch_in_bytes;
+
+ inline mem_payload_t(mem_desc_t &mem_tdesc) {
+ pitch_in_bytes = mem_tdesc.shape.stride_x * sizeof(dtype);
+ base_x = mem_tdesc.coord.x;
+ base_y = mem_tdesc.coord.y;
+ width_in_elems = mem_tdesc.shape.x;
+ height_in_elems = mem_tdesc.shape.y;
+ base_offset = trans ? base_x * pitch_in_bytes + base_y * sizeof(dtype)
+ : base_y * pitch_in_bytes + base_x * sizeof(dtype);
+ base_ptr = (mem_dtype *)mem_tdesc.base.base;
+
+ xetla_vector<uint32_t, num_channel> channel_index
+ = xetla_vector_gen<uint32_t, num_channel>(0, 1);
+ step_x = channel_index % num_channel_x;
+ step_y = channel_index / num_channel_x;
+ channel_offset = trans
+ ? step_y * sizeof(mem_dtype) + step_x * pitch_in_bytes
+ : step_x * sizeof(mem_dtype) + step_y * pitch_in_bytes;
+ }
+
+ inline mem_payload_t(dtype *p, int surface_width, int surface_height,
+ int surface_pitch, int surface_offset_x, int surface_offset_y) {
+ pitch_in_bytes = surface_pitch * sizeof(dtype);
+ base_x = surface_offset_x;
+ base_y = surface_offset_y;
+ width_in_elems = surface_width;
+ height_in_elems = surface_height;
+ base_offset = trans ? base_x * pitch_in_bytes + base_y * sizeof(dtype)
+ : base_y * pitch_in_bytes + base_x * sizeof(dtype);
+ base_ptr = (mem_dtype *)p;
+
+ xetla_vector<uint32_t, num_channel> channel_index
+ = xetla_vector_gen<uint32_t, num_channel>(0, 1);
+ step_x = channel_index % num_channel_x;
+ step_y = channel_index / num_channel_x;
+ channel_offset = trans
+ ? step_y * sizeof(mem_dtype) + step_x * pitch_in_bytes
+ : step_x * sizeof(mem_dtype) + step_y * pitch_in_bytes;
+ }
+
+ __XETLA_API void init(mem_desc_t &mem_tdesc) {
+ pitch_in_bytes = mem_tdesc.shape.stride_x * sizeof(dtype);
+ base_x = mem_tdesc.coord.x;
+ base_y = mem_tdesc.coord.y;
+ width_in_elems = mem_tdesc.shape.x;
+ height_in_elems = mem_tdesc.shape.y;
+ base_offset = trans ? base_x * pitch_in_bytes + base_y * sizeof(dtype)
+ : base_y * pitch_in_bytes + base_x * sizeof(dtype);
+ base_ptr = (mem_dtype *)mem_tdesc.base.base;
+
+ xetla_vector<uint32_t, num_channel> channel_index
+ = xetla_vector_gen<uint32_t, num_channel>(0, 1);
+ step_x = channel_index % num_channel_x;
+ step_y = channel_index / num_channel_x;
+ channel_offset = trans
+ ? step_y * sizeof(mem_dtype) + step_x * pitch_in_bytes
+ : step_x * sizeof(mem_dtype) + step_y * pitch_in_bytes;
+ }
+
+ __XETLA_API void init(dtype *p, int surface_width, int surface_height,
+ int surface_pitch, int surface_offset_x, int surface_offset_y) {
+ pitch_in_bytes = surface_pitch * sizeof(dtype);
+ base_x = surface_offset_x;
+ base_y = surface_offset_y;
+ width_in_elems = surface_width;
+ height_in_elems = surface_height;
+ base_offset = trans ? base_x * pitch_in_bytes + base_y * sizeof(dtype)
+ : base_y * pitch_in_bytes + base_x * sizeof(dtype);
+ base_ptr = (mem_dtype *)p;
+
+ xetla_vector<uint32_t, num_channel> channel_index
+ = xetla_vector_gen<uint32_t, num_channel>(0, 1);
+ step_x = channel_index % num_channel_x;
+ step_y = channel_index / num_channel_x;
+ channel_offset = trans
+ ? step_y * sizeof(mem_dtype) + step_x * pitch_in_bytes
+ : step_x * sizeof(mem_dtype) + step_y * pitch_in_bytes;
+ }
+
+ inline mem_payload_t(const this_payload_t &rhs) {
+ this->base_offset = rhs.base_offset;
+ this->base_ptr = rhs.base_ptr;
+ this->pitch_in_bytes = rhs.pitch_in_bytes;
+ this->base_x = rhs.base_x;
+ this->base_y = rhs.base_y;
+ this->width_in_elems = rhs.width_in_elems;
+ this->height_in_elems = rhs.height_in_elems;
+
+ this->step_x = rhs.step_x;
+ this->step_y = rhs.step_y;
+
+ this->channel_offset = rhs.channel_offset;
+ }
+
+ inline mem_payload_t() = default;
+ inline this_payload_t &operator=(const this_payload_t &rhs) {
+ this->base_offset = rhs.base_offset;
+ this->base_ptr = rhs.base_ptr;
+ this->pitch_in_bytes = rhs.pitch_in_bytes;
+ this->base_x = rhs.base_x;
+ this->base_y = rhs.base_y;
+ this->width_in_elems = rhs.width_in_elems;
+ this->height_in_elems = rhs.height_in_elems;
+
+ this->step_x = rhs.step_x;
+ this->step_y = rhs.step_y;
+ this->channel_offset = rhs.channel_offset;
+
+ return *this;
+ }
+
+ template <tdesc_update_dir update_dir = tdesc_update_dir::x_dir>
+ __XETLA_API void update_tdesc(int offset) {
+ if constexpr (update_dir == tdesc_update_dir::x_dir) {
+ base_offset += int64_t(offset) * sizeof(dtype);
+ trans ? base_y += offset : base_x += offset;
+ } else {
+ base_offset += int64_t(offset) * pitch_in_bytes;
+ trans ? base_x += offset : base_y += offset;
+ }
+ }
+};
+
+/// @brief Is to describe the shared local memory surface for scatter load/store
+/// 1. data located in shared local memory 2. tile will be loaded / stored in scatter mode
+/// @tparam dtype Is the data type
+/// @tparam tile_desc_ Is the tile descriptor
+/// @tparam mem_layout_ Is the memory layout
+template <typename dtype_, typename tile_desc_, gpu_arch arch_tag_,
+ uint32_t alignment_>
+struct mem_payload_t<
+ mem_desc_t<dtype_, mem_layout::row_major, mem_space::local, alignment_>,
+ tile_desc_, msg_type::scatter, arch_tag_,
+ std::enable_if_t<(arch_tag_ == gpu_arch::Xe)>> {
+ using mem_desc_t = mem_desc_t<dtype_, mem_layout::row_major,
+ mem_space::local, alignment_>;
+ using dtype = dtype_;
+ using tile_desc = tile_desc_;
+ static constexpr mem_space memory_space = mem_space::local;
+ static constexpr mem_layout memory_layout = mem_layout::row_major;
+ static constexpr msg_type message_type = msg_type::scatter;
+ static constexpr uint32_t alignment_in_bytes
+ = mem_desc_t::alignment_in_bytes;
+ static constexpr gpu_arch arch_tag = arch_tag_;
+
+private:
+ static constexpr uint32_t tile_size_x = tile_desc::tile_size_x;
+ static constexpr uint32_t tile_size_y = tile_desc::tile_size_y;
+ static constexpr uint32_t block_size_x = tile_desc::block_size_x;
+ static constexpr uint32_t block_size_y = tile_desc::block_size_y;
+ using this_payload_t
+ = mem_payload_t<mem_desc_t, tile_desc, msg_type::scatter, arch_tag>;
+
+public:
+ static constexpr reg_layout register_layout = tile_desc::register_layout;
+ static constexpr bool mem_transform
+ = (sizeof(dtype) < 4) && register_layout == reg_layout::vnni_tiled;
+
+ static constexpr uint32_t tile_bytes
+ = tile_size_x * tile_size_y * sizeof(dtype);
+ static constexpr uint32_t block_bytes
+ = block_size_x * block_size_y * sizeof(dtype);
+ using mem_dtype = typename std::conditional<
+ (block_bytes % (16 * sizeof(uint64_t)) == 0), uint64_t,
+ typename std::conditional<(block_bytes % (16 * sizeof(uint32_t))
+ == 0),
+ uint32_t, dtype>::type>::type;
+ // we can use simd16 or simd32
+ static constexpr uint32_t min_bytes = 16 * sizeof(mem_dtype);
+ static constexpr uint32_t max_bytes = 32 * sizeof(mem_dtype);
+
+ static constexpr uint32_t num_channel
+ = ((tile_bytes % max_bytes) == 0 && (block_bytes % max_bytes) == 0)
+ ? 32
+ : 16;
+ static constexpr uint32_t num_channel_x
+ = block_size_x * sizeof(dtype) / sizeof(mem_dtype);
+ static constexpr uint32_t num_channel_y = num_channel / num_channel_x;
+ xetla_vector<uint32_t, num_channel> address;
+ uint32_t pitch_in_bytes;
+ uint32_t wg_width_in_bytes;
+ uint32_t wg_height_in_elems;
+
+ inline mem_payload_t(mem_desc_t &mem_tdesc) {
+ xetla_tdescriptor base_tdesc = mem_tdesc.get_tdesc();
+ pitch_in_bytes = base_tdesc[4];
+ wg_width_in_bytes = base_tdesc[2];
+ wg_height_in_elems = base_tdesc[3];
+ uint32_t offset_x = base_tdesc[5];
+ uint32_t offset_y = base_tdesc[6];
+ uint32_t start_address = base_tdesc[0];
+ start_address += offset_y * pitch_in_bytes + offset_x * sizeof(dtype);
+ xetla_vector<uint32_t, num_channel> channel_index
+ = xetla_vector_gen<uint32_t, num_channel>(0, 1);
+ address = start_address
+ + (channel_index % num_channel_x) * sizeof(mem_dtype)
+ + (channel_index / num_channel_x) * pitch_in_bytes;
+ }
+
+ inline mem_payload_t(uint32_t base, int surface_width, int surface_height,
+ int surface_pitch, int surface_offset_x, int surface_offset_y) {
+ pitch_in_bytes = surface_pitch * sizeof(dtype);
+ wg_width_in_bytes = surface_width * sizeof(dtype);
+ wg_height_in_elems = surface_height;
+ uint32_t offset_x = surface_offset_x;
+ uint32_t offset_y = surface_offset_y;
+ uint32_t start_address = base;
+ start_address += offset_y * pitch_in_bytes + offset_x * sizeof(dtype);
+ xetla_vector<uint32_t, num_channel> channel_index
+ = xetla_vector_gen<uint32_t, num_channel>(0, 1);
+ address = start_address
+ + (channel_index % num_channel_x) * sizeof(mem_dtype)
+ + (channel_index / num_channel_x) * pitch_in_bytes;
+ }
+
+ __XETLA_API void init(uint32_t base, int surface_width, int surface_height,
+ int surface_pitch, int surface_offset_x, int surface_offset_y) {
+ pitch_in_bytes = surface_pitch * sizeof(dtype);
+ wg_width_in_bytes = surface_width * sizeof(dtype);
+ wg_height_in_elems = surface_height;
+ uint32_t offset_x = surface_offset_x;
+ uint32_t offset_y = surface_offset_y;
+ uint32_t start_address = base;
+ start_address += offset_y * pitch_in_bytes + offset_x * sizeof(dtype);
+ xetla_vector<uint32_t, num_channel> channel_index
+ = xetla_vector_gen<uint32_t, num_channel>(0, 1);
+ address = start_address
+ + (channel_index % num_channel_x) * sizeof(mem_dtype)
+ + (channel_index / num_channel_x) * pitch_in_bytes;
+ }
+
+ __XETLA_API void init(mem_desc_t &mem_tdesc) {
+ xetla_tdescriptor base_tdesc = mem_tdesc.get_tdesc();
+ pitch_in_bytes = base_tdesc[4];
+ wg_width_in_bytes = base_tdesc[2];
+ wg_height_in_elems = base_tdesc[3];
+ uint32_t offset_x = base_tdesc[5];
+ uint32_t offset_y = base_tdesc[6];
+ uint32_t start_address = base_tdesc[0];
+ start_address += offset_y * pitch_in_bytes + offset_x * sizeof(dtype);
+ xetla_vector<uint32_t, num_channel> channel_index
+ = xetla_vector_gen<uint32_t, num_channel>(0, 1);
+ address = start_address
+ + (channel_index % num_channel_x) * sizeof(mem_dtype)
+ + (channel_index / num_channel_x) * pitch_in_bytes;
+ }
+
+ inline mem_payload_t(const this_payload_t &rhs) {
+ this->address = rhs.address;
+ this->pitch_in_bytes = rhs.pitch_in_bytes;
+ this->wg_width_in_bytes = rhs.wg_width_in_bytes;
+ this->wg_height_in_elems = rhs.wg_height_in_elems;
+ }
+
+ inline mem_payload_t() = default;
+ inline this_payload_t &operator=(const this_payload_t &rhs) {
+ this->address = rhs.address;
+ this->pitch_in_bytes = rhs.pitch_in_bytes;
+ this->wg_width_in_bytes = rhs.wg_width_in_bytes;
+ this->wg_height_in_elems = rhs.wg_height_in_elems;
+ return *this;
+ }
+
+ template <tdesc_update_dir update_dir = tdesc_update_dir::x_dir>
+ __XETLA_API void update_tdesc(int offset) {
+ if constexpr (update_dir == tdesc_update_dir::x_dir) {
+ address += offset * sizeof(dtype);
+ } else {
+ address += offset * pitch_in_bytes;
+ }
+ }
+};
+
+/// @brief Is to describe the shared local memory surface for scattering store
+/// 1. data located in shared local memory 2. tile will be stored in scatter mode
+/// 3. data in register file is vnni packed and col majored.
+/// @tparam dtype Is the data type
+/// @tparam tile_desc_ Is the tile descriptor
+/// @tparam mem_layout_ Is the memory layout
+/// @note this is used for Atrans SLM path, so, we can add more limitation for best performance.
+template <typename dtype_, uint32_t tile_size_x_, uint32_t tile_size_y_,
+ uint32_t block_size_x_, uint32_t block_size_y_, gpu_arch arch_tag_,
+ uint32_t alignment_>
+struct mem_payload_t<
+ mem_desc_t<dtype_, mem_layout::row_major, mem_space::local, alignment_>,
+ tile_desc_t<tile_size_x_, tile_size_y_, block_size_x_, block_size_y_,
+ reg_layout::vnni_tiled_col_major>,
+ msg_type::scatter, arch_tag_,
+ std::enable_if_t<(arch_tag_ == gpu_arch::Xe)>> {
+ using mem_desc_t = mem_desc_t<dtype_, mem_layout::row_major,
+ mem_space::local, alignment_>;
+ using dtype = dtype_;
+ using tile_desc = tile_desc_t<tile_size_x_, tile_size_y_, block_size_x_,
+ block_size_y_, reg_layout::vnni_tiled_col_major>;
+ static constexpr mem_space memory_space = mem_space::local;
+ static constexpr mem_layout memory_layout = mem_layout::row_major;
+ static constexpr msg_type message_type = msg_type::scatter;
+ static constexpr uint32_t alignment_in_bytes
+ = mem_desc_t::alignment_in_bytes;
+ static constexpr gpu_arch arch_tag = arch_tag_;
+
+private:
+ static constexpr uint32_t tile_size_x = tile_desc::tile_size_x;
+ static constexpr uint32_t tile_size_y = tile_desc::tile_size_y;
+ static constexpr uint32_t block_size_x = tile_desc::block_size_x;
+ static constexpr uint32_t block_size_y = tile_desc::block_size_y;
+ using this_payload_t
+ = mem_payload_t<mem_desc_t, tile_desc, msg_type::scatter, arch_tag>;
+
+public:
+ static constexpr uint32_t tile_bytes
+ = tile_size_x * tile_size_y * sizeof(dtype);
+ static constexpr uint32_t block_bytes
+ = block_size_x * block_size_y * sizeof(dtype);
+ using store_dtype = uint32_t;
+ static constexpr uint32_t vnni_scale_factor
+ = sizeof(store_dtype) / sizeof(dtype);
+ static_assert(block_size_x % 16 == 0,
+ "block size x at least need to be 16 channel aligned");
+ static constexpr uint32_t num_channel = block_size_x;
+ static constexpr uint32_t max_vector_size = (block_size_x == 16) ? 8 : 4;
+ static constexpr uint32_t num_vector_size
+ = detail::gcd<tile_size_y / vnni_scale_factor,
+ max_vector_size>::value;
+ static constexpr uint32_t store_elems
+ = num_channel * num_vector_size * vnni_scale_factor;
+
+ uint32_t base_address;
+ uint32_t pitch_in_bytes;
+ xetla_vector<uint32_t, num_channel> channel_address;
+
+ __XETLA_API void init(mem_desc_t &mem_tdesc) {
+ base_address = mem_tdesc.base.base;
+ pitch_in_bytes = mem_tdesc.shape.stride_x * sizeof(dtype);
+ uint32_t offset_x = mem_tdesc.coord.x; //because this is row-major
+ uint32_t offset_y = mem_tdesc.coord.y;
+ uint32_t offset_address
+ = offset_y * pitch_in_bytes + offset_x * sizeof(dtype);
+ xetla_vector<uint32_t, num_channel> channel_index
+ = xetla_vector_gen<uint32_t, num_channel>(0, 1);
+ channel_address = offset_address + channel_index * pitch_in_bytes;
+ }
+ __XETLA_API void init(uint32_t base, uint32_t surface_width,
+ uint32_t surface_height, uint32_t surface_pitch,
+ int32_t surface_offset_x, int32_t surface_offset_y) {
+ base_address = base;
+ pitch_in_bytes = surface_pitch * sizeof(dtype);
+ uint32_t offset_x = surface_offset_x;
+ uint32_t offset_y = surface_offset_y;
+ uint32_t offset_address
+ = offset_y * pitch_in_bytes + offset_x * sizeof(dtype);
+ xetla_vector<uint32_t, num_channel> channel_index
+ = xetla_vector_gen<uint32_t, num_channel>(0, 1);
+ channel_address = offset_address + channel_index * pitch_in_bytes;
+ }
+
+ inline mem_payload_t(uint32_t base, uint32_t surface_width,
+ uint32_t surface_height, uint32_t surface_pitch,
+ int32_t surface_offset_x, int32_t surface_offset_y) {
+ init(base, surface_width, surface_height, surface_pitch,
+ surface_offset_x, surface_offset_y);
+ }
+ // Be aware of the risks: Rule of three (copy constructor, copy assignment, destructor)
+ // Please check if you need to add self-define destructor
+ // ~mem_payload_t(){}
+ inline mem_payload_t(mem_desc_t &mem_tdesc) { init(mem_tdesc); }
+
+ inline mem_payload_t(const this_payload_t &rhs) {
+ this->base_address = rhs.base_address;
+ this->pitch_in_bytes = rhs.pitch_in_bytes;
+ this->channel_address = rhs.channel_address;
+ }
+
+ inline mem_payload_t() = default;
+ inline this_payload_t &operator=(const this_payload_t &rhs) {
+ this->base_address = rhs.base_address;
+ this->pitch_in_bytes = rhs.pitch_in_bytes;
+ this->channel_address = rhs.channel_address;
+ return *this;
+ }
+
+ template <tdesc_update_dir update_dir = tdesc_update_dir::x_dir>
+ __XETLA_API void update_tdesc(int offset) {
+ if constexpr (update_dir == tdesc_update_dir::x_dir) {
+ channel_address += offset * sizeof(dtype);
+ } else {
+ channel_address += offset * pitch_in_bytes;
+ }
+ }
+
+ __XETLA_API void set_base_address(uint32_t base) {
+ this->base_address = base;
+ }
+};
+
+/// @brief Is to describe the global memory surface to prefetch data to cache
+/// data in global memory will be prefetched into 2d tile
+/// @tparam tile_desc_ Is the tile descriptor
+/// @tparam dtype Is the data type
+/// @tparam mem_layout Is the data layout
+/// @tparam num_coop_sg_ Is the thread nums to prefetch data
+template <typename dtype_, uint32_t tile_size_x_, uint32_t tile_size_y_,
+ uint32_t block_size_x_, uint32_t block_size_y_, mem_layout mem_layout_,
+ uint32_t alignment_, uint32_t num_coop_sg_, reg_layout reg_layout_,
+ gpu_arch arch_tag_>
+struct prefetch_payload_t<
+ mem_desc_t<dtype_, mem_layout_, mem_space::global, alignment_>,
+ tile_desc_t<tile_size_x_, tile_size_y_, block_size_x_, block_size_y_,
+ reg_layout_>,
+ num_coop_sg_, arch_tag_,
+ std::enable_if_t<(arch_tag_ == gpu_arch::Xe)>> {
+ using dtype = dtype_;
+ using mem_desc_t
+ = mem_desc_t<dtype_, mem_layout_, mem_space::global, alignment_>;
+ using tile_desc = tile_desc_t<tile_size_x_, tile_size_y_, block_size_x_,
+ block_size_y_, reg_layout_>;
+ static constexpr mem_space memory_space = mem_space::global;
+ static constexpr mem_layout memory_layout = mem_layout_;
+ static constexpr gpu_arch arch_tag = arch_tag_;
+
+ static constexpr uint32_t tile_size_x = tile_desc::tile_size_x;
+ static constexpr uint32_t tile_size_y = tile_desc::tile_size_y;
+
+ // private:
+ static constexpr bool is_col_major = mem_layout_ == mem_layout::col_major;
+ static constexpr uint32_t mem_tile_size_w
+ = is_col_major ? tile_size_y : tile_size_x;
+ static constexpr uint32_t mem_tile_size_h
+ = is_col_major ? tile_size_x : tile_size_y;
+ using load_store_attr = typename arch_attr_t<
+ arch_tag>::template load_store_attr<msg_type::block_2d>;
+ static constexpr uint32_t special_prefetch_width
+ = load_store_attr::special_prefetch_width_in_bytes / sizeof(dtype);
+ static constexpr uint32_t normal_prefetch_width
+ = load_store_attr::max_load_width_in_bytes / sizeof(dtype);
+ static constexpr bool is_special_prefetch
+ = (mem_tile_size_w % special_prefetch_width) == 0;
+
+ static constexpr uint32_t block_size_w = is_special_prefetch
+ ? special_prefetch_width
+ : (normal_prefetch_width > mem_tile_size_w ? mem_tile_size_w
+ : normal_prefetch_width);
+ static constexpr uint32_t block_size_h
+ = load_store_attr::max_load_height_in_elem;
+ //could have over-prefetch, but that's should be fine
+ static constexpr uint32_t max_num_block_w
+ = (mem_tile_size_w + block_size_w - 1) / block_size_w;
+ static constexpr uint32_t num_coop_sg = num_coop_sg_;
+ static constexpr uint32_t num_coop_sg_w
+ = detail::gcd<num_coop_sg, max_num_block_w>::value;
+ static constexpr uint32_t num_coop_sg_h = num_coop_sg / num_coop_sg_w;
+
+ static constexpr uint32_t num_block_w = max_num_block_w / num_coop_sg_w;
+ static constexpr uint32_t tile_size_w = block_size_w * num_block_w;
+ static constexpr uint32_t tile_size_h
+ = (mem_tile_size_h + num_coop_sg_h - 1) / num_coop_sg_h;
+ static constexpr uint32_t num_block_h
+ = (tile_size_h + block_size_h - 1) / block_size_h;
+ using this_payload_t
+ = prefetch_payload_t<mem_desc_t, tile_desc, num_coop_sg_, arch_tag>;
+
+public:
+ static constexpr uint32_t num_tdesc = num_block_w * num_block_h;
+ xetla_vector<uint32_t, num_tdesc * 16> tdesc_prefetch;
+
+ inline prefetch_payload_t(const this_payload_t &rhs) {
+ this->tdesc_prefetch = rhs.tdesc_prefetch;
+ }
+
+ inline prefetch_payload_t() = default;
+
+ inline this_payload_t &operator=(const this_payload_t &rhs) {
+ this->tdesc_prefetch = rhs.tdesc_prefetch;
+ return *this;
+ }
+
+ inline prefetch_payload_t(mem_desc_t &mem_desc, uint32_t coop_id = 0) {
+ xetla_tdescriptor base_tdesc = mem_desc.get_tdesc();
+ uint32_t coop_id_x = coop_id % num_coop_sg_w;
+ uint32_t coop_id_y = coop_id / num_coop_sg_w;
+ xetla_update_tdesc_offsetx(
+ base_tdesc.xetla_format<uint32_t>(), coop_id_x * tile_size_w);
+ xetla_update_tdesc_offsety(
+ base_tdesc.xetla_format<uint32_t>(), coop_id_y * tile_size_h);
+ prepare_tdesc(base_tdesc);
+ }
+
+ inline prefetch_payload_t(dtype *p, int surface_width, int surface_height,
+ int surface_pitch, int surface_offset_x, int surface_offset_y,
+ uint32_t coop_id = 0) {
+ uint32_t coop_id_x = coop_id % num_coop_sg_w;
+ uint32_t coop_id_y = coop_id / num_coop_sg_w;
+ xetla_tdescriptor base_tdesc;
+ xetla_fill_tdesc(base_tdesc.xetla_format<uint32_t>(), p, surface_width,
+ surface_height, surface_pitch,
+ surface_offset_x + coop_id_x * tile_size_w,
+ surface_offset_y + coop_id_y * tile_size_h);
+ prepare_tdesc(base_tdesc);
+ }
+
+ inline void init(xetla_tdescriptor base_tdesc, uint32_t coop_id = 0) {
+ uint32_t coop_id_x = coop_id % num_coop_sg_w;
+ uint32_t coop_id_y = coop_id / num_coop_sg_w;
+ xetla_update_tdesc_offsetx(
+ base_tdesc.xetla_format<uint32_t>(), coop_id_x * tile_size_w);
+ xetla_update_tdesc_offsety(
+ base_tdesc.xetla_format<uint32_t>(), coop_id_y * tile_size_h);
+ prepare_tdesc(base_tdesc);
+ }
+ // Be aware of the risks: Rule of three (copy constructor, copy assignment, destructor)
+ // Please check if you need to add self-define destructor
+ // ~prefetch_payload_t(){}
+
+ template <tdesc_update_dir update_dir = tdesc_update_dir::x_dir>
+ __XETLA_API void update_tdesc(int offset) {
+ auto tdesc_2d = tdesc_prefetch.xetla_format<uint32_t, num_tdesc, 16>();
+ if constexpr (update_dir == tdesc_update_dir::x_dir) {
+#pragma unroll
+ for (int i = 0; i < num_tdesc; i++) {
+ xetla_update_tdesc_offsetx(tdesc_2d.row(i), offset);
+ }
+ } else {
+#pragma unroll
+ for (int i = 0; i < num_tdesc; i++) {
+ xetla_update_tdesc_offsety(tdesc_2d.row(i), offset);
+ }
+ }
+ }
+ __XETLA_API void set_tdesc_width(uint32_t size) {
+ auto tdesc_2d = tdesc_prefetch.xetla_format<uint32_t, num_tdesc, 16>();
+#pragma unroll
+ for (int i = 0; i < num_tdesc; i++) {
+ xetla_set_tdesc_width<dtype>(tdesc_2d.row(i), size);
+ }
+ }
+
+ __XETLA_API void set_tdesc_pitch(uint32_t size) {
+ auto tdesc_2d = tdesc_prefetch.xetla_format<uint32_t, num_tdesc, 16>();
+#pragma unroll
+ for (int i = 0; i < num_tdesc; i++) {
+ xetla_set_tdesc_pitch<dtype>(tdesc_2d.row(i), size);
+ }
+ }
+
+ __XETLA_API void set_tdesc_height(uint32_t size) {
+ auto tdesc_2d = tdesc_prefetch.xetla_format<uint32_t, num_tdesc, 16>();
+#pragma unroll
+ for (int i = 0; i < num_tdesc; i++) {
+ xetla_set_tdesc_height(tdesc_2d.row(i), size);
+ }
+ }
+
+ __XETLA_API void update_tdesc_base_address(int offset) {
+ auto tdesc_2d = tdesc_prefetch.xetla_format<uint32_t, num_tdesc, 16>();
+#pragma unroll
+ for (int i = 0; i < num_tdesc; i++) {
+ xetla_update_tdesc_base_address(tdesc_2d.row(i), offset);
+ }
+ }
+
+ __XETLA_API void set_tdesc_base_address(uint64_t addr) {
+ auto tdesc_2d = tdesc_prefetch.xetla_format<uint32_t, num_tdesc, 16>();
+#pragma unroll
+ for (int i = 0; i < num_tdesc; i++) {
+ gpu::xetla::detail::xetla_set_tensor_base_address(
+ tdesc_2d.row(i), addr);
+ }
+ }
+
+ __XETLA_API void update_tdesc_base_address_masked(
+ int offset, uint16_t mask = 1) {
+ auto tdesc_2d = tdesc_prefetch.xetla_format<uint32_t, num_tdesc, 16>();
+#pragma unroll
+ for (int i = 0; i < num_tdesc; i++) {
+ xetla_update_tdesc_base_address(tdesc_2d.row(i), offset);
+ }
+
+#pragma unroll
+ for (int i = 0; i < num_tdesc; i++) {
+ xetla_tdesc_mask_op(tdesc_2d.row(i), mask);
+ }
+ }
+
+ __XETLA_API void set_offset(
+ int32_t offset_x, int32_t offset_y, uint32_t coop_id = 0) {
+ uint32_t coop_id_x = coop_id % num_coop_sg_w;
+ uint32_t coop_id_y = coop_id / num_coop_sg_w;
+
+ auto tdesc_2d = tdesc_prefetch.xetla_format<uint32_t, num_tdesc, 16>();
+ int32_t base_offset_y = offset_y
+ + (is_col_major ? coop_id_x * tile_size_w
+ : coop_id_y * tile_size_h);
+#pragma unroll
+ for (int i = 0; i < num_block_h; i++) {
+ auto tdesc_row_2d = tdesc_2d.xetla_select<num_block_w, 1, 16, 1>(
+ i * num_block_w, 0);
+
+ int32_t base_offset_x = offset_x
+ + (is_col_major ? coop_id_y * tile_size_h
+ : coop_id_x * tile_size_w);
+#pragma unroll
+ for (int j = 0; j < num_block_w; j++) {
+ int32_t offset_width
+ = is_col_major ? base_offset_y : base_offset_x;
+ int32_t offset_height
+ = is_col_major ? base_offset_x : base_offset_y;
+ gpu::xetla::detail::xetla_set_tensor_offset_x(
+ tdesc_row_2d.row(j), offset_width);
+ gpu::xetla::detail::xetla_set_tensor_offset_y(
+ tdesc_row_2d.row(j), offset_height);
+
+ base_offset_x += block_size_w;
+ }
+ base_offset_y += block_size_h;
+ }
+ }
+
+private:
+ __XETLA_API void prepare_tdesc(xetla_tdescriptor base_tdesc) {
+ auto tdesc_2d = tdesc_prefetch.xetla_format<uint32_t, num_tdesc, 16>();
+ uint32_t base_offset_y = 0;
+#pragma unroll
+ for (int i = 0; i < tile_size_h / block_size_h; i++) {
+ auto tdesc_row_2d = tdesc_2d.xetla_select<num_block_w, 1, 16, 1>(
+ i * num_block_w, 0);
+ prepare_tile_desc_core<num_block_w, block_size_w, block_size_h>(
+ tdesc_row_2d, base_tdesc, base_offset_y);
+ base_offset_y += block_size_h;
+ }
+ if constexpr ((tile_size_h % block_size_h) != 0) {
+ constexpr int i = tile_size_h / block_size_h;
+ auto tdesc_row_2d = tdesc_2d.xetla_select<num_block_w, 1, 16, 1>(
+ i * num_block_w, 0);
+ constexpr uint32_t remain_size_y = tile_size_h % block_size_h;
+ prepare_tile_desc_core<num_block_w, block_size_w, remain_size_y>(
+ tdesc_row_2d, base_tdesc, base_offset_y);
+ }
+ }
+
+ template <int32_t num_tdesc, uint32_t size_x, uint32_t size_y>
+ __XETLA_API static void prepare_tile_desc_core(
+ xetla_matrix_ref<uint32_t, num_tdesc, 16> __REF__ tdesc_2d,
+ xetla_tdescriptor base_tdesc, uint32_t base_offset_y) {
+ uint32_t base_offset_x = 0;
+#pragma unroll
+ for (int j = 0; j < num_tdesc; j++) {
+ tdesc_2d.row(j) = base_tdesc;
+
+ constexpr uint32_t block_widthx_widthy_arrlen
+ = (size_x - 1) | ((size_y - 1) << 8);
+ gpu::xetla::detail::xetla_set_block_widthx_widthy_arrlen(
+ tdesc_2d.row(j), block_widthx_widthy_arrlen);
+
+ xetla_update_tdesc_offsetx(tdesc_2d.row(j), base_offset_x);
+ xetla_update_tdesc_offsety(tdesc_2d.row(j), base_offset_y);
+ base_offset_x += size_x;
+ }
+ }
+};
+
+/// @brief Is to describe the memory memory to prefetch data to cache
+/// data in global memory will be prefetched into 1d tile
+/// @tparam tile_desc_ Is the tile descriptor
+/// @tparam dtype Is the data type
+/// @tparam mem_layout Is the data layout
+/// @tparam num_coop_sg_ Is the thread nums to prefetch data
+template <typename dtype_, uint32_t tile_size_x_, uint32_t block_size_x_,
+ mem_layout mem_layout_, uint32_t alignment_, uint32_t num_coop_sg_,
+ reg_layout reg_layout_, gpu_arch arch_tag_>
+struct prefetch_payload_t<
+ mem_desc_t<dtype_, mem_layout_, mem_space::global, alignment_>,
+ tile_desc_t<tile_size_x_, 1, block_size_x_, 1, reg_layout_>,
+ num_coop_sg_, arch_tag_,
+ std::enable_if_t<(arch_tag_ == gpu_arch::Xe)>> {
+ using dtype = dtype_;
+ using mem_desc_t
+ = mem_desc_t<dtype_, mem_layout_, mem_space::global, alignment_>;
+ // CL aligned, so we can use uint64_t
+ using prefetch_dtype = uint64_t;
+ using tile_desc
+ = tile_desc_t<tile_size_x_, 1, block_size_x_, 1, reg_layout_>;
+ static constexpr mem_space memory_space = mem_space::global;
+ static constexpr mem_layout memory_layout = mem_layout_;
+ static constexpr gpu_arch arch_tag = arch_tag_;
+
+private:
+ // Fetches the entire CL.
+ static constexpr uint32_t cacheline_elems = 64 / sizeof(dtype);
+ static constexpr uint32_t mem_block_nums
+ = (tile_desc::tile_size_x + cacheline_elems - 1) / cacheline_elems;
+ static constexpr uint32_t num_coop_sg = num_coop_sg_;
+
+ // For mem_tile_nums < num_coop_sg cases, mem_tile_size_x will be CL length
+ // which might lead to illegal read.
+ // there are num_coop_sg threads to prefetch mem_block_nums
+ // each thread will prefetch mem_tile_size_x elements
+ static constexpr uint32_t mem_tile_size_x = mem_block_nums > num_coop_sg
+ ? (mem_block_nums + num_coop_sg - 1) / num_coop_sg *cacheline_elems
+ : 0;
+ using this_payload_t
+ = prefetch_payload_t<mem_desc_t, tile_desc, num_coop_sg_, arch_tag>;
+
+ // Fixed prefetch_dtype, close this assertion
+ // static_assert(sizeof(prefetch_dtype) >= 4,
+ // "prefetch dtype size should at least DW aligned");
+
+public:
+ static constexpr uint32_t scale_factor
+ = sizeof(prefetch_dtype) / sizeof(dtype);
+ uint32_t base_offset;
+ prefetch_dtype *base_ptr;
+ uint32_t pitch_in_bytes;
+
+ inline prefetch_payload_t(const this_payload_t &rhs) {
+ this->base_offset = rhs.base_offset;
+ this->base_ptr = rhs.base_ptr;
+ this->pitch_in_bytes = rhs.pitch_in_bytes;
+ }
+
+ inline prefetch_payload_t() = default;
+
+ inline this_payload_t &operator=(const this_payload_t &rhs) {
+ this->base_offset = rhs.base_offset;
+ this->base_ptr = rhs.base_ptr;
+ this->pitch_in_bytes = rhs.pitch_in_bytes;
+ return *this;
+ }
+
+ inline prefetch_payload_t(mem_desc_t &mem_desc, uint32_t coop_id = 0) {
+ pitch_in_bytes = mem_desc.shape.stride_x * sizeof(dtype);
+ uint32_t offset_x = mem_desc.coord.x;
+ uint32_t offset_y = mem_desc.coord.y;
+ base_offset = offset_y * pitch_in_bytes + offset_x * sizeof(dtype);
+ uint64_t ptr_temp = (uint64_t)mem_desc.base.base;
+ base_ptr = (prefetch_dtype *)ptr_temp
+ + (coop_id % num_coop_sg) * mem_tile_size_x;
+ }
+
+ inline prefetch_payload_t(dtype *p, int surface_width, int surface_height,
+ int surface_pitch, int surface_offset_x, int surface_offset_y,
+ uint32_t coop_id = 0) {
+ pitch_in_bytes = surface_pitch * sizeof(dtype);
+ uint32_t offset_x = surface_offset_x;
+ uint32_t offset_y = surface_offset_y;
+ base_offset = offset_y * pitch_in_bytes + offset_x * sizeof(dtype);
+ base_ptr = (prefetch_dtype *)p
+ + (coop_id % num_coop_sg) * mem_tile_size_x;
+ }
+
+ template <tdesc_update_dir update_dir = tdesc_update_dir::x_dir>
+ __XETLA_API void update_tdesc(int offset) {
+ if constexpr (update_dir == tdesc_update_dir::x_dir) {
+ base_offset += offset * sizeof(dtype);
+ } else {
+ base_offset += offset * pitch_in_bytes;
+ }
+ }
+};
+
+/// @brief Is to describe the memory infomation to prefetch data to cache
+/// data located in shared local memory, nothing will do.
+/// @tparam tile_desc_ Is the tile descriptor
+/// @tparam dtype Is the data type
+/// @tparam mem_layout Is the data layout
+/// @tparam num_coop_sg_ Is the thread nums to prefetch data
+template <typename dtype_, typename tile_desc_, mem_layout mem_layout_,
+ uint32_t alignment_, uint32_t num_coop_sg_, gpu_arch arch_tag_>
+struct prefetch_payload_t<
+ mem_desc_t<dtype_, mem_layout_, mem_space::local, alignment_>,
+ tile_desc_, num_coop_sg_, arch_tag_,
+ std::enable_if_t<(arch_tag_ == gpu_arch::Xe)>> {
+ using dtype = dtype_;
+ using mem_desc_t
+ = mem_desc_t<dtype_, mem_layout_, mem_space::local, alignment_>;
+ using tile_desc = tile_desc_;
+ static constexpr mem_space memory_space = mem_space::local;
+ static constexpr mem_layout memory_layout = mem_layout_;
+ static constexpr gpu_arch arch_tag = arch_tag_;
+
+ inline prefetch_payload_t(mem_desc_t &mem_desc, uint32_t coop_id = 0) {}
+
+ inline prefetch_payload_t(dtype *p, int surface_width, int surface_height,
+ int surface_pitch, int surface_offset_x, int surface_offset_y,
+ uint32_t coop_id = 0) {}
+
+ template <tdesc_update_dir update_dir = tdesc_update_dir::x_dir>
+ __XETLA_API void update_tdesc(int offset) {}
+};
+
+} // namespace gpu::xetla::subgroup
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/subgroup/tile/impl/prefetch_xe.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/subgroup/tile/impl/prefetch_xe.hpp
new file mode 100644
index 00000000000..52822cfb1ee
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/subgroup/tile/impl/prefetch_xe.hpp
@@ -0,0 +1,119 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#include "subgroup/tile/api.hpp"
+#include "subgroup/tile/impl/op_function.hpp"
+#include "subgroup/tile/impl/payload_xe.hpp"
+
+namespace gpu::xetla::subgroup {
+namespace detail {
+template <typename payload_t>
+struct check_prefetch_type {
+ static constexpr bool is_global_2d_xe
+ = ((payload_t::memory_space == mem_space::global)
+ && (payload_t::tile_desc::tile_size_y != 1)
+ && (payload_t::arch_tag == gpu_arch::Xe));
+
+ static constexpr bool is_global_block_1d_xe
+ = ((payload_t::memory_space == mem_space::global)
+ && (payload_t::tile_desc::tile_size_y == 1)
+ && (payload_t::arch_tag == gpu_arch::Xe));
+
+ static constexpr bool is_local_xe
+ = ((payload_t::memory_space == mem_space::local)
+ && (payload_t::arch_tag == gpu_arch::Xe));
+};
+
+} // namespace detail
+
+/// @brief Is prefetch data func, which data located in global memory is prefetched to
+/// cache, where has higher bandwidth. e.g. In gemm, prefetch next iteration data for mma
+/// consumption. This func is specicalized for block 2d scenario.
+/// @tparam payload_t Is the mem_payload_t struct illustrating memory info
+/// payload indicates the source of prefetch operation.
+/// @tparam L1 Is cache hint for L1 cache.
+/// @tparam L2 Is cache hint for L2 cache.
+/// @param payload Is the payload object with type payload_t. Contains all the information for prefetches.
+template <cache_hint L1 = cache_hint::cached,
+ cache_hint L2 = cache_hint::cached, typename payload_t>
+__XETLA_API typename std::enable_if_t<
+ detail::check_prefetch_type<payload_t>::is_global_2d_xe>
+tile_prefetch(payload_t &payload, uint16_t pred = 1) {
+ using dtype = typename payload_t::dtype;
+ static constexpr uint32_t num_tdesc = payload_t::num_tdesc;
+ auto tdesc_2d
+ = payload.tdesc_prefetch.xetla_format<uint32_t, num_tdesc, 16>();
+
+#pragma unroll
+ for (int i = 0; i < num_tdesc; i++) {
+ xetla_mask<16> mask = pred;
+ xetla_tprefetch_global<dtype, L1, L2, payload_t::arch_tag>(
+ tdesc_2d.row(i), pred);
+ }
+}
+
+/// @brief Is prefetch data func, which data located in global memory is prefetched to
+/// cache, where has higher bandwidth. e.g. In gemm, prefetch next iteration data for mma
+/// consumption. This func is specicalized for block 1d scenario.
+/// @tparam payload_t Is the mem_payload_t struct illustrating memory info
+/// payload indicates the source of prefetch operation
+/// @tparam L1 Is cache hint for L1 cache.
+/// @tparam L2 Is cache hint for L2 cache.
+/// @param payload Is the payload object with type payload_t. Contains all the information for prefetches.
+template <cache_hint L1 = cache_hint::cached,
+ cache_hint L2 = cache_hint::cached, typename payload_t>
+__XETLA_API typename std::enable_if_t<
+ detail::check_prefetch_type<payload_t>::is_global_block_1d_xe>
+tile_prefetch(payload_t &payload) {
+ using dtype = typename payload_t::dtype;
+ using tile_desc = typename payload_t::tile_desc;
+ using prefetch_dtype = typename payload_t::prefetch_dtype;
+ constexpr uint32_t prefetch_len
+ = tile_desc::tile_size_x / payload_t::scale_factor;
+ if constexpr (prefetch_len >= 64) {
+#pragma unroll
+ for (int j = 0; j < prefetch_len / 64; j++) {
+ uint32_t offset_x = j * 64 * payload_t::scale_factor;
+ uint32_t address_offset = offset_x * sizeof(dtype);
+ xetla_prefetch_global<prefetch_dtype, 64, data_size::default_size,
+ L1, L2>(
+ payload.base_ptr, payload.base_offset + address_offset);
+ }
+ }
+ constexpr uint32_t tail_len = prefetch_len % 64;
+ uint32_t tail_offset = prefetch_len / 64 * 64 * payload_t::scale_factor;
+ detail::process_1d_tail<tail_len, 32, L1, L2, payload_t>(
+ payload, tail_offset);
+}
+
+/// @brief Is prefetch data func.
+/// Current shared local memory prefetch is not supported yet. Only used to keep the consistency with global prefetch.
+/// @tparam payload_t Is the mem_payload_t struct illustrating memory info.
+/// @tparam L1 Is cache hint for L1 cache.
+/// @tparam L2 Is cache hint for L2 cache.
+/// @param payload Is the payload object with type payload_t. Contains all the information for prefetches.
+template <cache_hint L1 = cache_hint::cached,
+ cache_hint L2 = cache_hint::cached, typename payload_t>
+__XETLA_API typename std::enable_if_t<
+ detail::check_prefetch_type<payload_t>::is_local_xe>
+tile_prefetch(payload_t &payload) {}
+
+} // namespace gpu::xetla::subgroup
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/subgroup/tile/impl/reduction.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/subgroup/tile/impl/reduction.hpp
new file mode 100644
index 00000000000..9bdd0140990
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/subgroup/tile/impl/reduction.hpp
@@ -0,0 +1,375 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#include "subgroup/tile/api.hpp"
+#include "subgroup/tile/common.hpp"
+
+namespace gpu::xetla::subgroup {
+
+// dim=0 : reduce along y dir;
+// dim=1 : reduce along x dir;
+template <reduce_op reduce_kind, typename dtype_out, typename dtype_acc,
+ int dim, typename mat_t>
+__XETLA_API typename std::enable_if_t<(dim == 1),
+ xetla_vector<dtype_out, mat_t::tile_size_y>>
+tile_reduce(mat_t &src) {
+ static constexpr uint32_t tile_size_y = mat_t::tile_size_y;
+ static constexpr uint32_t tile_size_x = mat_t::tile_size_x;
+ static constexpr uint32_t tile_elems = mat_t::tile_elems;
+ static constexpr uint32_t block_size_y = mat_t::block_size_y;
+ static constexpr uint32_t block_size_x = mat_t::block_size_x;
+ static constexpr uint32_t block_elems = mat_t::block_elems;
+ static constexpr int32_t num_block_y = mat_t::num_block_y;
+ static constexpr int32_t num_block_x = mat_t::num_block_x;
+ using dtype = typename mat_t::dtype;
+ /// The idea is
+ /// 1) allocate a temp buffer;
+ /// 2) reduce the entire tile into temp buffer;
+ /// 3) reduce within temp buffer
+ xetla_vector<dtype_acc, tile_size_y * block_size_x> acc;
+#pragma unroll
+ for (int i = 0; i < tile_size_y / block_size_y; i++) {
+ //j=0, initial the buffer
+ {
+ auto src_reg = (src.reg).xetla_select<block_elems, 1>(
+ (i * num_block_x) * block_elems);
+ auto src_reg_acc
+ = xetla_cvt<dtype_acc, dtype, block_elems>(src_reg);
+ auto dst_reg_acc
+ = acc.xetla_select<block_elems, 1>(i * block_elems);
+ dst_reg_acc = src_reg_acc;
+ }
+#pragma unroll
+ for (int j = 1; j < num_block_x; j++) {
+ auto src_reg = (src.reg).xetla_select<block_elems, 1>(
+ (i * num_block_x + j) * block_elems);
+ auto src_reg_acc
+ = xetla_cvt<dtype_acc, dtype, block_elems>(src_reg);
+ auto dst_reg_acc
+ = acc.xetla_select<block_elems, 1>(i * block_elems);
+ dst_reg_acc = reduce_helper<reduce_kind, dtype_acc, block_elems>(
+ dst_reg_acc, src_reg_acc);
+ }
+ }
+
+ // process the tail
+ if constexpr ((tile_size_y % block_size_y) != 0) {
+ constexpr uint32_t tail_start_y
+ = tile_size_y / block_size_y * block_size_y;
+ constexpr uint32_t tail_size_y = tile_size_y % block_size_y;
+ constexpr uint32_t tail_block_elems = tail_size_y * block_size_x;
+ //j=0, initial the buffer
+ {
+ auto src_reg = (src.reg).xetla_select<tail_block_elems, 1>(
+ tail_start_y * tile_size_x);
+ auto src_reg_acc
+ = xetla_cvt<dtype_acc, dtype, tail_block_elems>(src_reg);
+ auto dst_reg_acc = acc.xetla_select<tail_block_elems, 1>(
+ tail_start_y * block_size_x);
+ dst_reg_acc = src_reg_acc;
+ }
+#pragma unroll
+ for (int j = 1; j < num_block_x; j++) {
+ auto src_reg = (src.reg).xetla_select<tail_block_elems, 1>(
+ tail_start_y * tile_size_x + j * tail_block_elems);
+ auto src_reg_acc
+ = xetla_cvt<dtype_acc, dtype, tail_block_elems>(src_reg);
+ auto dst_reg_acc = acc.xetla_select<tail_block_elems, 1>(
+ tail_start_y * block_size_x);
+ dst_reg_acc
+ = reduce_helper<reduce_kind, dtype_acc, tail_block_elems>(
+ dst_reg_acc, src_reg_acc);
+ }
+ }
+
+ xetla_vector<dtype_acc, tile_size_y> out = recur_col_reduce<reduce_kind,
+ dtype_acc, block_size_x, tile_size_y>(acc);
+
+ return xetla_cvt<dtype_out, dtype_acc, tile_size_y>(out);
+}
+
+template <reduce_op reduce_kind, typename dtype_out, typename dtype_acc,
+ int dim, typename mat_t>
+__XETLA_API typename std::enable_if_t<(dim == 0),
+ xetla_vector<dtype_out, mat_t::tile_size_x>>
+tile_reduce(mat_t &src) {
+ static constexpr uint32_t tile_size_y = mat_t::tile_size_y;
+ static constexpr uint32_t tile_size_x = mat_t::tile_size_x;
+ static constexpr uint32_t tile_elems = mat_t::tile_elems;
+ static constexpr uint32_t block_size_y = mat_t::block_size_y;
+ static constexpr uint32_t block_size_x = mat_t::block_size_x;
+ static constexpr uint32_t block_elems = mat_t::block_elems;
+ static constexpr int32_t num_block_y = mat_t::num_block_y;
+ static constexpr int32_t num_block_x = mat_t::num_block_x;
+ using dtype = typename mat_t::dtype;
+ static constexpr uint32_t num_acc = 8;
+ static constexpr uint32_t first_block_size_y
+ = (tile_size_y / block_size_y == 0) ? (tile_size_y % block_size_y)
+ : block_size_y;
+ static constexpr uint32_t acc_size_y
+ = (num_acc > first_block_size_y) ? first_block_size_y : num_acc;
+ /// The idea is
+ /// 1) allocate a temp buffer;
+ /// 2) reduce the entire tile into temp buffer;
+ /// 3) reduce within temp buffer
+ /// This will introduce additional instructions to initialize the temp
+ /// buffer, but will have more parallelism
+ static constexpr uint32_t first_block_elems
+ = first_block_size_y * block_size_x;
+ static constexpr uint32_t acc_block_elems = acc_size_y * block_size_x;
+ xetla_vector<dtype_acc, acc_size_y * tile_size_x> acc;
+#pragma unroll
+ for (int j = 0; j < num_block_x; j++) {
+ auto src_reg = (src.reg).xetla_select<first_block_elems, 1>(
+ j * first_block_elems);
+ auto src_reg_acc
+ = xetla_cvt<dtype_acc, dtype, first_block_elems>(src_reg);
+ acc.xetla_select<acc_block_elems, 1>(j * acc_block_elems)
+ = src_reg_acc.xetla_select<acc_block_elems, 1>(0);
+ }
+
+#pragma unroll
+ for (int i = 0; i < tile_size_y / block_size_y; i++) {
+#pragma unroll
+ for (int j = 0; j < num_block_x; j++) {
+ auto src_reg = (src.reg).xetla_select<block_elems, 1>(
+ (i * num_block_x + j) * block_elems);
+ auto src_reg_acc
+ = xetla_cvt<dtype_acc, dtype, block_elems>(src_reg);
+ auto dst_reg_acc
+ = acc.xetla_select<acc_block_elems, 1>(j * acc_block_elems);
+#pragma unroll
+ for (int row_i = 0; row_i < block_size_y / acc_size_y; row_i++) {
+ if (i == 0 && row_i == 0) continue;
+ dst_reg_acc = reduce_helper<reduce_kind, dtype_acc,
+ acc_block_elems>(dst_reg_acc,
+ src_reg_acc.xetla_select<acc_block_elems, 1>(
+ row_i * acc_block_elems));
+ }
+ // process the tail
+ if constexpr ((block_size_y % acc_size_y) != 0) {
+ constexpr uint32_t acc_tail_start_y
+ = block_size_y / acc_size_y * acc_size_y;
+ constexpr uint32_t acc_tail_size_y = block_size_y % acc_size_y;
+ constexpr uint32_t acc_tail_block_elems
+ = acc_tail_size_y * block_size_x;
+ auto dst_reg_acc_tail
+ = dst_reg_acc.xetla_select<acc_tail_block_elems>(0);
+ dst_reg_acc_tail = reduce_helper<reduce_kind, dtype_acc,
+ acc_tail_block_elems>(dst_reg_acc_tail,
+ src_reg_acc.xetla_select<acc_tail_block_elems, 1>(
+ acc_tail_start_y * block_size_x));
+ }
+ }
+ }
+
+ // process the tail
+ if constexpr ((tile_size_y % block_size_y) != 0) {
+ constexpr uint32_t tail_start_y
+ = tile_size_y / block_size_y * block_size_y;
+ constexpr uint32_t tail_size_y = tile_size_y % block_size_y;
+ constexpr uint32_t tail_block_elems = tail_size_y * block_size_x;
+#pragma unroll
+ for (int j = 0; j < num_block_x; j++) {
+ auto src_reg = (src.reg).xetla_select<tail_block_elems, 1>(
+ tail_start_y * tile_size_x + j * tail_block_elems);
+ auto src_reg_acc
+ = xetla_cvt<dtype_acc, dtype, tail_block_elems>(src_reg);
+ auto dst_reg_acc
+ = acc.xetla_select<acc_block_elems, 1>(j * acc_block_elems);
+#pragma unroll
+ for (int row_i = 0; row_i < tail_size_y / acc_size_y; row_i++) {
+ if ((tile_size_y / block_size_y == 0) && row_i == 0) continue;
+ dst_reg_acc = reduce_helper<reduce_kind, dtype_acc,
+ acc_block_elems>(dst_reg_acc,
+ src_reg_acc.xetla_select<acc_block_elems, 1>(
+ row_i * acc_block_elems));
+ }
+ // process the tail
+ if constexpr ((tail_size_y % acc_size_y) != 0) {
+ constexpr uint32_t acc_tail_start_y
+ = tail_size_y / acc_size_y * acc_size_y;
+ constexpr uint32_t acc_tail_size_y = tail_size_y % acc_size_y;
+ constexpr uint32_t acc_tail_block_elems
+ = acc_tail_size_y * block_size_x;
+ auto dst_reg_acc_tail
+ = dst_reg_acc.xetla_select<acc_tail_block_elems>(0);
+ dst_reg_acc_tail = reduce_helper<reduce_kind, dtype_acc,
+ acc_tail_block_elems>(dst_reg_acc_tail,
+ src_reg_acc.xetla_select<acc_tail_block_elems, 1>(
+ acc_tail_start_y * block_size_x));
+ }
+ }
+ }
+
+ xetla_vector<dtype_acc, tile_size_x> out;
+#pragma unroll
+ for (int i = 0; i < acc_size_y; i++) {
+#pragma unroll
+ for (int j = 0; j < num_block_x; j++) {
+ auto reg_acc
+ = acc.xetla_select<acc_block_elems, 1>(j * acc_block_elems);
+ auto reg_acc_2d = reg_acc.xetla_format<dtype_acc, acc_size_y,
+ block_size_x>();
+ if (i == 0) {
+ out.xetla_select<block_size_x, 1>(j * block_size_x)
+ = reg_acc_2d.row(i);
+ } else {
+ out.xetla_select<block_size_x, 1>(j * block_size_x)
+ = reduce_helper<reduce_kind, dtype_acc, block_size_x>(
+ out.xetla_select<block_size_x, 1>(
+ j * block_size_x),
+ reg_acc_2d.row(i));
+ }
+ }
+ }
+
+ return xetla_cvt<dtype_out, dtype_acc, tile_size_x>(out);
+}
+
+/// @brief Reduce 2d src tile to the 1d tile, and output to 1d dst.
+///
+/// @tparam T_dst Is the destination tile data type, interpreted as 1d data.
+/// @tparam T_src Is the source tile data type, interpreted as 2d data.
+/// @tparam accumulate is to accumulate the old value or not.
+/// @tparam dtype_acc Is the accumulation data type, src ==> convert to
+/// dtype_acc ==> reduction + accumulation ==> convert to dtype_dst.
+/// @param dst Is the reference of the destination tile object.
+/// @param src Is the reference of the destination tile object.
+/// @return No return, in-place update in the destination tile.
+/// @note This is only for reduce add, and will be deprecated in future. Please use tile_reduce instead.
+template <typename T_dst, typename T_src, bool accumulate = true,
+ typename dtype_acc = float, uint32_t num_acc = 4>
+XETLA_MARKER(
+ "This is only for reduce add, and will be deprecated in future. "
+ "Please use tile_reduce instead.")
+__XETLA_API
+ typename std::enable_if_t<(T_dst::register_layout == reg_layout::tiled)
+ && (T_src::register_layout == reg_layout::tiled)
+ && (T_dst::tile_size_x == T_src::tile_size_x)
+ && (T_dst::tile_size_y == 1)> tile_row_reduce(T_dst &dst,
+ T_src &src) {
+ static constexpr uint32_t tile_size_y = T_src::tile_size_y;
+ static constexpr uint32_t tile_size_x = T_src::tile_size_x;
+ static constexpr uint32_t tile_elems = T_src::tile_elems;
+ static constexpr uint32_t block_size_y = T_src::block_size_y;
+ static constexpr uint32_t block_size_x = T_src::block_size_x;
+ static constexpr uint32_t block_elems = T_src::block_elems;
+ static constexpr int32_t num_block_y = T_src::num_block_y;
+ static constexpr int32_t num_block_x = T_src::num_block_x;
+ using dtype_dst = typename T_dst::dtype;
+ using dtype_src = typename T_src::dtype;
+ /// Here we rely on compiler to generate mixed mode for bf16
+ static constexpr uint32_t SIMD = 64 / sizeof(dtype_acc);
+ static constexpr uint32_t accum_len
+ = ((block_size_x % SIMD) && (sizeof(dtype_src) < 4)) == 0
+ ? SIMD
+ : block_size_x;
+ static constexpr uint32_t accum_elems = accum_len * block_size_y;
+ /// The idea is
+ /// 1) allocate a temp buffer;
+ /// 2) accumulate the entire tile into temp buffer;
+ /// 3) reduce within temp buffer
+ /// This will introduce additional instructions to initialize the temp
+ /// buffer, but will have more parallelism
+ xetla_vector<dtype_acc, tile_size_x * num_acc> acc(0);
+ auto acc_2d = acc.xetla_format<dtype_acc, num_acc, tile_size_x>();
+ if constexpr (accumulate) {
+ acc_2d.row(0) = xetla_cvt<dtype_acc, dtype_dst, tile_size_x>(dst.reg);
+ }
+#pragma unroll
+ for (int i = 0; i < tile_size_y / block_size_y; i++) {
+#pragma unroll
+ for (int j = 0; j < num_block_x; j++) {
+ auto src_reg = (src.reg).xetla_select<block_elems, 1>(
+ (i * num_block_x + j) * block_elems);
+ auto src_reg_dtype_acc
+ = xetla_cvt<dtype_acc, dtype_src, block_elems>(src_reg);
+ auto src_reg_2d = src_reg_dtype_acc.xetla_format<dtype_acc,
+ block_size_y, block_size_x>();
+#pragma unroll
+ for (int row_i = 0; row_i < block_size_y; row_i += num_acc) {
+#pragma unroll
+ for (int acc_i = 0;
+ (acc_i < num_acc) && (row_i + acc_i < block_size_y);
+ acc_i++) {
+ auto acc_sub = acc.xetla_select<block_size_x, 1>(
+ acc_i * tile_size_x + j * block_size_x);
+#pragma unroll
+ for (int k = 0; k < block_size_x / accum_len; k++) {
+ acc_sub.xetla_select<accum_len, 1>(k * accum_len)
+ = acc_sub.xetla_select<accum_len, 1>(
+ k * accum_len)
+ + src_reg_2d.row(row_i + acc_i)
+ .xetla_select<accum_len, 1>(
+ k * accum_len);
+ }
+ }
+ }
+ }
+ }
+
+ // process the tail
+ if constexpr ((tile_size_y % block_size_y) != 0) {
+ constexpr uint32_t tail_start_y
+ = tile_size_y / block_size_y * block_size_y;
+ constexpr uint32_t tail_size_y = tile_size_y % block_size_y;
+ constexpr uint32_t tail_block_elems = tail_size_y * block_size_x;
+#pragma unroll
+ for (int j = 0; j < num_block_x; j++) {
+ auto src_reg = (src.reg).xetla_select<tail_block_elems, 1>(
+ tail_start_y * tile_size_x + j * tail_block_elems);
+ auto src_reg_dtype_acc
+ = xetla_cvt<dtype_acc, dtype_src, tail_block_elems>(
+ src_reg);
+ auto src_reg_2d = src_reg_dtype_acc.xetla_format<dtype_acc,
+ tail_size_y, block_size_x>();
+#pragma unroll
+ for (int row_i = 0; row_i < tail_size_y; row_i += num_acc) {
+#pragma unroll
+ for (int acc_i = 0;
+ (acc_i < num_acc) && (row_i + acc_i < tail_size_y);
+ acc_i++) {
+ auto acc_sub = acc.xetla_select<block_size_x, 1>(
+ acc_i * tile_size_x + j * block_size_x);
+#pragma unroll
+ for (int k = 0; k < block_size_x / accum_len; k++) {
+ acc_sub.xetla_select<accum_len, 1>(k * accum_len)
+ = acc_sub.xetla_select<accum_len, 1>(
+ k * accum_len)
+ + src_reg_2d.row(row_i + acc_i)
+ .xetla_select<accum_len, 1>(
+ k * accum_len);
+ }
+ }
+ }
+ }
+ }
+
+#pragma unroll
+ for (int i = 1; i < num_acc; i++) {
+ acc_2d.row(0) += acc_2d.row(i);
+ }
+
+ dst.reg = xetla_cvt<dtype_dst, dtype_acc, tile_size_x>(acc_2d.row(0));
+}
+
+} // namespace gpu::xetla::subgroup
\ No newline at end of file
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/subgroup/tile/impl/store_xe.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/subgroup/tile/impl/store_xe.hpp
new file mode 100644
index 00000000000..084f17b59c1
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/subgroup/tile/impl/store_xe.hpp
@@ -0,0 +1,790 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#include "subgroup/tile/api.hpp"
+#include "subgroup/tile/impl/op_function.hpp"
+#include "subgroup/tile/impl/payload_xe.hpp"
+
+namespace gpu::xetla::subgroup {
+
+namespace detail {
+template <typename tile_t, typename payload_t>
+struct check_store_type {
+ static constexpr bool is_global_2d_xe
+ = (payload_t::memory_space == mem_space::global
+ && (payload_t::message_type == msg_type::block_2d)
+ && (payload_t::arch_tag == gpu_arch::Xe));
+
+ static constexpr bool is_global_block_1d_xe
+ = ((payload_t::memory_space == mem_space::global)
+ && (tile_t::tile_size_y == 1) && (tile_t::block_size_y == 1)
+ && (payload_t::message_type == msg_type::block_1d)
+ && (payload_t::arch_tag == gpu_arch::Xe));
+
+ static constexpr bool is_global_unaligned_2d_xe
+ = (payload_t::memory_space == mem_space::global
+ && (payload_t::message_type == msg_type::unaligned_2d)
+ && (payload_t::arch_tag == gpu_arch::Xe));
+
+ static constexpr bool is_global_atomic_xe
+ = ((payload_t::memory_space == mem_space::global)
+ && (payload_t::message_type == msg_type::atomic_add)
+ && (payload_t::arch_tag == gpu_arch::Xe));
+
+ static constexpr bool is_local_scatter_xe = ((payload_t::memory_space
+ == mem_space::local)
+ && (payload_t::message_type == msg_type::scatter)
+ && (payload_t::arch_tag == gpu_arch::Xe)
+ && (payload_t::tile_desc::register_layout == reg_layout::tiled
+ || payload_t::tile_desc::register_layout
+ == reg_layout::vnni_tiled));
+
+ static constexpr bool is_local_scatter_vnni_col_xe
+ = ((payload_t::memory_space == mem_space::local)
+ && (payload_t::message_type == msg_type::scatter)
+ && (payload_t::arch_tag == gpu_arch::Xe)
+ && (payload_t::tile_desc::register_layout
+ == reg_layout::vnni_tiled_col_major));
+
+ static constexpr bool is_local_block_1d_xe = ((payload_t::memory_space
+ == mem_space::local)
+ && (payload_t::message_type == msg_type::block_1d)
+ && (payload_t::arch_tag == gpu_arch::Xe)
+ && (payload_t::tile_desc::register_layout == reg_layout::tiled));
+};
+
+} // namespace detail
+
+/// @brief Is the func storing data from register file to global memory.
+/// store a rectangular region (X,Y)..(X+W,Y+H) into memory from registers.
+/// @tparam tile_t Is the tile_t struct contains registers
+/// These registers will be the source of store operation.
+/// @tparam payload_t Is the mem_payload_t struct describing the memory info
+/// payload indicates the destination of store operation.
+/// @tparam L1 Is the cache hint for L1 cache.
+/// @tparam L2 Is the cache hint for L2 cache.
+/// @param tile Is the tile object with type tile_t, contains the data to be stored.
+/// @param payload Is the payload object with type payload_t. Contains all the information for stores.
+template <cache_hint L1 = cache_hint::write_back,
+ cache_hint L2 = cache_hint::write_back, typename tile_t,
+ typename payload_t>
+__XETLA_API typename std::enable_if_t<
+ detail::check_store_type<tile_t, payload_t>::is_global_2d_xe>
+tile_store(tile_t &tile, payload_t &payload) {
+ using dtype = typename tile_t::dtype;
+ using tile_desc = typename tile_t::tile_desc;
+ using store_dtype = typename payload_t::mem_dtype;
+ using check_store =
+ typename subgroup::check_store<gpu_arch::Xe, dtype, store_dtype>::
+ template global_2d<payload_t::tile_desc::block_size_x>;
+
+ static constexpr uint32_t tile_size_x = tile_desc::tile_size_x;
+ static constexpr uint32_t tile_size_y = tile_desc::tile_size_y;
+ static constexpr uint32_t block_size_x = tile_desc::block_size_x;
+ static constexpr uint32_t block_size_y = tile_desc::block_size_y;
+ static constexpr uint32_t remained_size_y = tile_desc::remained_size_y;
+
+ static constexpr uint32_t block_elems = tile_desc::block_elems;
+
+ static constexpr uint32_t num_block_x = tile_desc::num_block_x;
+ static constexpr uint32_t num_block_y = tile_desc::num_block_y;
+ static constexpr uint32_t num_block = tile_desc::num_block;
+
+ using load_store_attr = typename arch_attr_t<
+ payload_t::arch_tag>::template load_store_attr<msg_type::block_2d>;
+
+ static constexpr int32_t max_block_width
+ = load_store_attr::max_load_width_in_bytes / sizeof(dtype);
+ static constexpr int32_t max_store_block_height
+ = load_store_attr::max_store_height_in_elem;
+ static_assert((max_block_width % block_size_x) == 0,
+ "max_block_width should be a multiply of block size x.");
+ static constexpr uint32_t elems_per_CL
+ = load_store_attr::cache_line_size_in_bytes / sizeof(dtype);
+ static constexpr uint32_t st_blk_size_y
+ = block_size_y > max_store_block_height ? max_store_block_height
+ : block_size_y;
+ // to make sure full CL store
+ static constexpr uint32_t st_block_x = ((tile_size_x % elems_per_CL) == 0)
+ ? elems_per_CL
+ : (((elems_per_CL % tile_size_x) == 0) ? tile_size_x
+ : block_size_x);
+
+ static constexpr uint8_t arr_len_candidate = st_block_x / block_size_x;
+ static constexpr bool is_valid_arr_len_candidate = (arr_len_candidate == 1)
+ || (arr_len_candidate == 2) || (arr_len_candidate == 4);
+
+ static constexpr uint8_t arr_len
+ = is_valid_arr_len_candidate ? arr_len_candidate : 1;
+
+ auto payload_2d = payload.payloads.xetla_format<uint32_t, num_block, 16>();
+ uint32_t base_offset_y = 0;
+#pragma unroll
+ for (int i = 0; i < num_block_y; ++i) {
+ constexpr uint32_t store_block_elems = block_elems * arr_len;
+ auto payload_row = payload_2d.xetla_select<num_block_x, 1, 16, 1>(
+ i * num_block_x, 0);
+ detail::reset_tile_desc_core<num_block_x, block_size_x * arr_len,
+ st_blk_size_y, 1, 1, false>(payload_row);
+ base_offset_y += block_size_y;
+#pragma unroll
+ for (int j = 0; j < num_block_x; j += arr_len) {
+ xetla_tdescriptor tdesc = payload_row.row(j);
+ auto reg_blk = tile.reg.xetla_select<store_block_elems, 1>(
+ (i * num_block_x + j) * block_elems);
+ xetla_vector<dtype, store_block_elems> combine_blk;
+ auto combine_blk_2d = combine_blk.xetla_format<native_type_t<dtype>,
+ block_size_y, block_size_x * arr_len>();
+#pragma unroll
+ for (int combine_i = 0; combine_i < arr_len; ++combine_i) {
+ combine_blk_2d.xetla_select<block_size_y, 1, block_size_x, 1>(
+ 0, combine_i * block_size_x)
+ = reg_blk.xetla_select<block_elems, 1>(
+ combine_i * block_elems);
+ }
+#pragma unroll
+ for (int ii = 0; ii < block_size_y / st_blk_size_y; ++ii) {
+ constexpr uint32_t store_elems
+ = st_blk_size_y * block_size_x * arr_len;
+ auto st_blk = combine_blk.xetla_select<store_elems, 1>(
+ ii * store_elems);
+ xetla_tstore_global<dtype, store_elems, L1, L2,
+ payload_t::arch_tag>(tdesc, st_blk);
+ xetla_update_tdesc_offsety(
+ tdesc.xetla_format<uint32_t>(), st_blk_size_y);
+ }
+ // exceed hardware limitation
+ if constexpr ((block_size_y % st_blk_size_y) != 0) {
+ constexpr uint32_t blk_remained_start = block_size_y
+ / st_blk_size_y * st_blk_size_y * block_size_x
+ * arr_len;
+ constexpr uint8_t blk_remained_y = block_size_y % st_blk_size_y;
+ constexpr uint8_t blk_remained_elems
+ = blk_remained_y * block_size_x * arr_len;
+ auto st_blk = combine_blk.xetla_select<blk_remained_elems, 1>(
+ blk_remained_start);
+ constexpr uint32_t block_widthx_widthy_arrlen
+ = (block_size_x * arr_len - 1)
+ | ((blk_remained_y - 1) << 8);
+ gpu::xetla::detail::xetla_set_block_widthx_widthy_arrlen(
+ tdesc.xetla_format<uint32_t>(),
+ block_widthx_widthy_arrlen);
+ xetla_tstore_global<dtype, blk_remained_elems, L1, L2,
+ payload_t::arch_tag>(tdesc, st_blk);
+ }
+ }
+ }
+ // process tail
+ if constexpr (remained_size_y > 0) {
+ constexpr uint32_t remained_block_elems
+ = block_size_x * remained_size_y;
+ constexpr uint32_t processed_elems
+ = num_block_y * num_block_x * block_elems;
+ constexpr uint32_t remained_st_blk_size_y
+ = st_blk_size_y > remained_size_y ? remained_size_y
+ : st_blk_size_y;
+ auto payload_row = payload_2d.xetla_select<num_block_x, 1, 16, 1>(
+ num_block_y * num_block_x, 0);
+ detail::reset_tile_desc_core<num_block_x, block_size_x * arr_len,
+ remained_st_blk_size_y, 1, 1, false>(payload_row);
+#pragma unroll
+ for (int j = 0; j < num_block_x; j += arr_len) {
+ xetla_tdescriptor tdesc = payload_row.row(j);
+ auto reg_blk
+ = tile.reg.xetla_select<remained_block_elems * arr_len, 1>(
+ processed_elems + j * remained_block_elems);
+ // Do combination
+ xetla_vector<dtype, remained_block_elems * arr_len> combine_blk;
+ auto combine_blk_2d = combine_blk.xetla_format<native_type_t<dtype>,
+ remained_size_y, block_size_x * arr_len>();
+#pragma unroll
+ for (int combine_i = 0; combine_i < arr_len; ++combine_i) {
+ combine_blk_2d
+ .xetla_select<remained_size_y, 1, block_size_x, 1>(
+ 0, combine_i * block_size_x)
+ = reg_blk.xetla_select<remained_block_elems, 1>(
+ combine_i * remained_block_elems);
+ }
+#pragma unroll
+ for (int ii = 0; ii < remained_size_y / remained_st_blk_size_y;
+ ++ii) {
+ constexpr uint32_t store_elems
+ = remained_st_blk_size_y * block_size_x * arr_len;
+ auto st_blk = combine_blk.xetla_select<store_elems, 1>(
+ ii * store_elems);
+ xetla_tstore_global<dtype, store_elems, L1, L2,
+ payload_t::arch_tag>(tdesc, st_blk);
+ xetla_update_tdesc_offsety(
+ tdesc.xetla_format<uint32_t>(), remained_st_blk_size_y);
+ }
+ constexpr uint32_t final_st_blk_size_y
+ = remained_size_y % remained_st_blk_size_y;
+ if constexpr (final_st_blk_size_y != 0) {
+ constexpr uint32_t final_start = remained_size_y
+ / remained_st_blk_size_y * remained_st_blk_size_y
+ * block_size_x * arr_len;
+ constexpr uint32_t final_store_elems
+ = final_st_blk_size_y * block_size_x * arr_len;
+ auto st_blk = combine_blk.xetla_select<final_store_elems, 1>(
+ final_start);
+ constexpr uint32_t block_widthx_widthy_arrlen
+ = (block_size_x * arr_len - 1)
+ | ((final_st_blk_size_y - 1) << 8);
+ gpu::xetla::detail::xetla_set_block_widthx_widthy_arrlen(
+ tdesc.xetla_format<uint32_t>(),
+ block_widthx_widthy_arrlen);
+ xetla_tstore_global<dtype, final_store_elems, L1, L2,
+ payload_t::arch_tag>(tdesc, st_blk);
+ }
+ }
+ }
+}
+
+/// @brief Is the func storing data from register file to global memory.
+/// For each enabled SIMT lane, a vector is written into memory from registers.
+/// @tparam tile_t Is the tile_t struct contains registers
+/// These registers will be the source of store operation.
+/// @tparam payload_t Is the mem_payload_t struct describing the memory info
+/// payload indicates the destination of store operation
+/// @tparam L1 Is the cache hint for L1 cache.
+/// @tparam L2 Is the cache hint for L2 cache.
+/// @param tile Is the tile object with type tile_t, contains the data to be stored.
+/// @param payload Is the payload object with type payload_t. Contains all the information for stores.
+template <cache_hint L1 = cache_hint::write_back,
+ cache_hint L2 = cache_hint::write_back, typename tile_t,
+ typename payload_t>
+__XETLA_API typename std::enable_if_t<
+ detail::check_store_type<tile_t, payload_t>::is_global_block_1d_xe>
+tile_store(tile_t &tile, payload_t &payload) {
+ using dtype = typename tile_t::dtype;
+ using store_dtype = typename payload_t::mem_dtype;
+ using check_store = typename subgroup::check_store<gpu_arch::Xe, dtype,
+ store_dtype>::global_1d;
+
+ static constexpr uint32_t tile_size_x = tile_t::tile_size_x;
+ static constexpr uint32_t scale_factor = payload_t::scale_factor;
+
+ constexpr uint32_t store_len = tile_size_x / scale_factor;
+ if constexpr (store_len >= 64) {
+#pragma unroll
+ for (int i = 0; i < store_len / 64; i++) {
+ uint32_t offset_x = i * 64 * scale_factor;
+ auto reg_sub
+ = tile.reg.xetla_select<64 * scale_factor, 1>(offset_x);
+ uint32_t address_offset = offset_x * sizeof(dtype);
+
+ xetla_store_global<store_dtype, 64, data_size::default_size, L1,
+ L2>(payload.base_ptr, payload.base_offset + address_offset,
+ reg_sub.xetla_format<store_dtype>());
+ }
+ }
+ constexpr uint32_t tail_len = store_len % 64;
+ uint32_t tail_offset = store_len / 64 * 64 * scale_factor;
+ detail::process_1d_tail<tail_len, 32, detail::process_flag::store, L1, L2>(
+ tile, payload, tail_offset);
+}
+
+/// @brief Is the func storing data from register file to unaligned global memory surface.
+/// store a rectangular region (X,Y)..(X+W,Y+H) into memory from registers.
+/// @tparam tile_t Is the tile_t struct contains registers
+/// These registers will be the source of store operation.
+/// @tparam payload_t Is the mem_payload_t struct describing the memory info
+/// payload indicates the destination of store operation.
+/// @tparam L1 Is the cache hint for L1 cache.
+/// @tparam L3 Is the cache hint for L3 cache.
+/// @param tile Is the tile object with type tile_t, contains the data to be stored.
+/// @param payload Is the payload object with type payload_t. Contains all the information for stores.
+/// @return No return, update in place.
+template <cache_hint L1 = cache_hint::write_back,
+ cache_hint L3 = cache_hint::write_back, typename tile_t,
+ typename payload_t,
+ typename oob_check_tag = global_atomic_oob_check_on_tag>
+__XETLA_API typename std::enable_if_t<
+ detail::check_store_type<tile_t, payload_t>::is_global_unaligned_2d_xe>
+tile_store(tile_t &tile, payload_t &payload, oob_check_tag tag = {}) {
+ constexpr bool oob_check = std::is_same<oob_check_tag,
+ global_atomic_oob_check_on_tag>::value;
+ using dtype = typename payload_t::dtype;
+ using tile_desc = typename payload_t::tile_desc;
+ using store_dtype = typename payload_t::mem_dtype;
+ using check_store =
+ typename subgroup::check_store<gpu_arch::Xe, dtype, store_dtype>::
+ template unaligned_2d<payload_t::tile_desc::block_size_x>;
+ static constexpr uint32_t block_size_x = tile_desc::block_size_x;
+ static constexpr uint32_t block_size_y = tile_desc::block_size_y;
+ // using num_block_x = tile_desc::num_block_x;
+ constexpr uint32_t num_channel_y = payload_t::num_channel_y;
+ constexpr uint32_t load_elems = num_channel_y * payload_t::num_channel_x;
+ constexpr uint32_t scale_factor = payload_t::scale_factor;
+
+#pragma unroll
+ for (int i = 0; i < tile_desc::tile_size_y / tile_desc::block_size_y; i++) {
+ uint32_t offset_y = i * tile_desc::block_size_y;
+#pragma unroll
+ for (int j = 0; j < tile_desc::num_block_x; j++) {
+ uint32_t offset_x = j * tile_desc::block_size_x;
+ auto reg_sub = tile.reg.xetla_select<tile_desc::block_elems, 1>(
+ (i * tile_desc::num_block_x + j) * tile_desc::block_elems);
+ xetla_mask<load_elems> pred_x = oob_check
+ ? payload.step_x + payload.base_x + offset_x
+ < payload.width_in_elems
+ : 1;
+#pragma unroll
+ for (int sub_block_y = 0; sub_block_y < tile_desc::block_size_y;
+ sub_block_y += num_channel_y) {
+ xetla_mask<load_elems> pred_y = oob_check
+ ? payload.step_y + payload.base_y + offset_y
+ + sub_block_y
+ < payload.height_in_elems
+ : 1;
+
+ uint32_t address_offset = offset_x * sizeof(dtype)
+ + (offset_y + sub_block_y) * payload.pitch_in_bytes;
+ xetla_store_global<store_dtype, 1, data_size::default_size, L1,
+ L3, load_elems>(payload.base_ptr,
+ (payload.base_offset + address_offset
+ + payload.channel_offset),
+ reg_sub.xetla_select<load_elems * scale_factor, 1>(
+ sub_block_y * tile_desc::block_size_x)
+ .xetla_format<store_dtype>(),
+ (pred_x && pred_y));
+ }
+ }
+ }
+ // process the tail
+ if constexpr ((tile_desc::tile_size_y % tile_desc::block_size_y) != 0) {
+ constexpr uint32_t remained_size_y = tile_desc::remained_size_y;
+ constexpr uint32_t offset_y = tile_desc::tile_size_y - remained_size_y;
+ constexpr uint32_t processed_elems = offset_y * tile_desc::tile_size_x;
+ constexpr uint32_t remain_block_elems
+ = remained_size_y * tile_desc::block_size_x;
+#pragma unroll
+ for (int j = 0; j < tile_desc::num_block_x; j++) {
+ uint32_t offset_x = j * tile_desc::block_size_x;
+ auto reg_sub = tile.reg.xetla_select<remain_block_elems, 1>(
+ processed_elems + j * remain_block_elems);
+ xetla_mask<load_elems> pred_x = oob_check
+ ? payload.step_x + payload.base_x + offset_x
+ < payload.width_in_elems
+ : 1;
+#pragma unroll
+ for (int sub_block_y = 0; sub_block_y < remained_size_y;
+ sub_block_y += num_channel_y) {
+ xetla_mask<load_elems> pred_y = oob_check
+ ? payload.step_y + payload.base_y + offset_y
+ + sub_block_y
+ < payload.height_in_elems
+ : 1;
+
+ uint32_t address_offset = offset_x * sizeof(dtype)
+ + (offset_y + sub_block_y) * payload.pitch_in_bytes;
+ xetla_store_global<store_dtype, 1, data_size::default_size, L1,
+ L3, load_elems>(payload.base_ptr,
+ (payload.base_offset + address_offset
+ + payload.channel_offset),
+ reg_sub.xetla_select<load_elems * scale_factor, 1>(
+ sub_block_y * tile_desc::block_size_x)
+ .xetla_format<store_dtype>(),
+ (pred_x && pred_y));
+ }
+ }
+ }
+}
+
+/// @brief Is the func storing data from register file to global memory
+/// enable atomic adding data into the same buffer, but support float32, float64, uint32_t,
+/// uint64_t and int type
+/// @tparam tile_t Is the tile_t struct contains registers
+/// These registers will be the source of store operation.
+/// @tparam payload_t Is the mem_payload_t struct describing the memory info
+/// payload indicates the destination of store operation
+/// @tparam L1 Is the cache hint for L1 cache.
+/// @tparam L2 Is the cache hint for L2 cache.
+/// @param tile Is the tile object with type tile_t, contains the data to be stored.
+/// @param payload Is the payload object with type payload_t. Contains all the information for stores.
+template <cache_hint L1 = cache_hint::uncached,
+ cache_hint L2 = cache_hint::write_back, typename tile_t,
+ typename payload_t,
+ typename oob_check_tag = global_atomic_oob_check_on_tag>
+__XETLA_API typename std::enable_if_t<
+ detail::check_store_type<tile_t, payload_t>::is_global_atomic_xe>
+tile_store(tile_t &tile, payload_t &payload, oob_check_tag tag = {}) {
+ constexpr bool oob_check = std::is_same<oob_check_tag,
+ global_atomic_oob_check_on_tag>::value;
+ using dtype = typename tile_t::dtype;
+ using tile_desc = typename tile_t::tile_desc;
+ using check_store = typename subgroup::check_store<gpu_arch::Xe,
+ dtype>::template global_atomic<payload_t::tile_bytes,
+ payload_t::min_store_bytes, payload_t::block_bytes,
+ payload_t::num_channel_x, payload_t::num_channel>;
+
+ static constexpr uint32_t tile_size_x = tile_desc::tile_size_x;
+ static constexpr uint32_t tile_size_y = tile_desc::tile_size_y;
+ static constexpr uint32_t block_size_x = tile_desc::block_size_x;
+ static constexpr uint32_t block_size_y = tile_desc::block_size_y;
+ static constexpr uint32_t block_elems = tile_desc::block_elems;
+ static constexpr uint32_t num_block_x = tile_desc::num_block_x;
+
+ static constexpr atomic_op op_kind
+ = (std::is_same<remove_const_t<dtype>, float>::value
+ || std::is_same<remove_const_t<dtype>, double>::value)
+ ? atomic_op::fadd
+ : atomic_op::iadd;
+
+#pragma unroll
+ for (int i = 0; i < tile_size_y / block_size_y; i++) {
+ uint32_t offset_y = i * block_size_y;
+#pragma unroll
+ for (int j = 0; j < num_block_x; j++) {
+ uint32_t offset_x = j * block_size_x;
+ auto reg_sub = tile.reg.xetla_select<block_elems, 1>(
+ (i * num_block_x + j) * block_elems);
+ xetla_mask<payload_t::num_channel> pred_x = oob_check
+ ? (payload.step_x + offset_x + payload.base_x)
+ < payload.width_in_elems
+ : 1;
+#pragma unroll
+ for (int sub_block_y = 0; sub_block_y < block_size_y;
+ sub_block_y += payload_t::num_channel_y) {
+ xetla_mask<payload_t::num_channel> pred_y = oob_check
+ ? (payload.step_y + offset_y + payload.base_y
+ + sub_block_y)
+ < payload.height_in_elems
+ : 1;
+ uint64_t address_offset = offset_x * sizeof(dtype)
+ + (sub_block_y + offset_y) * payload.pitch_in_bytes;
+
+ xetla_tatomic_store_global<dtype, payload_t::num_channel, L1,
+ L2, op_kind, payload_t::arch_tag,
+ typename payload_t::Toffset>(
+ payload.base_pointer + address_offset,
+ payload.channel_offset,
+ reg_sub.xetla_select<payload_t::store_elems, 1>(
+ sub_block_y * block_size_x),
+ pred_x & pred_y);
+ }
+ }
+ }
+ // process the tail
+ if constexpr ((tile_size_y % block_size_y) != 0) {
+ constexpr uint32_t remained_size_y = tile_desc::remained_size_y;
+ constexpr uint32_t offset_y = tile_size_y - remained_size_y;
+ constexpr uint32_t processed_elems = offset_y * tile_size_x;
+ constexpr uint32_t remain_block_elems = remained_size_y * block_size_x;
+#pragma unroll
+ for (int j = 0; j < num_block_x; j++) {
+ uint32_t offset_x = j * block_size_x;
+ auto reg_sub = tile.reg.xetla_select<remain_block_elems, 1>(
+ processed_elems + j * remain_block_elems);
+ xetla_mask<payload_t::num_channel> pred_x = oob_check
+ ? (payload.step_x + offset_x + payload.base_x)
+ < payload.width_in_elems
+ : 1;
+#pragma unroll
+ for (int sub_block_y = 0; sub_block_y < remained_size_y;
+ sub_block_y += payload_t::num_channel_y) {
+ xetla_mask<payload_t::num_channel> pred_y = oob_check
+ ? (payload.step_y + offset_y + payload.base_y
+ + sub_block_y)
+ < payload.height_in_elems
+ : 1;
+ uint64_t address_offset = offset_x * sizeof(dtype)
+ + (sub_block_y + offset_y) * payload.pitch_in_bytes;
+
+ xetla_tatomic_store_global<dtype, payload_t::num_channel, L1,
+ L2, op_kind, payload_t::arch_tag,
+ typename payload_t::Toffset>(
+ (uint64_t)payload.base_pointer + address_offset,
+ payload.channel_offset,
+ reg_sub.xetla_select<payload_t::store_elems, 1>(
+ sub_block_y * block_size_x),
+ pred_x & pred_y);
+ }
+ }
+ }
+}
+
+/// @brief Is the func storing data from register file to shared local memory,
+/// which supports the memory surface 2d scenario. And the dst memory layout is
+/// is always row major.
+/// @tparam tile_t Is the tile_t struct contains registers
+/// These registers will be the source of store operation.
+/// @tparam payload_t Is the mem_payload_t struct describing the memory info
+/// payload indicates the destination of store operation
+/// @tparam L1 Is the cache hint for L1 cache.
+/// @tparam L2 Is the cache hint for L2 cache.
+/// @param tile Is the tile object with type tile_t, contains the data to be stored.
+/// @param payload Is the payload object with type payload_t. Contains all the information for stores.
+template <cache_hint L1 = cache_hint::write_back,
+ cache_hint L2 = cache_hint::write_back, typename tile_t,
+ typename payload_t>
+__XETLA_API typename std::enable_if_t<
+ detail::check_store_type<tile_t, payload_t>::is_local_scatter_xe>
+tile_store(tile_t &tile, payload_t &payload) {
+ using dtype = typename tile_t::dtype;
+ using tile_desc = typename tile_t::tile_desc;
+ using store_dtype = typename payload_t::mem_dtype;
+ using check_store = typename subgroup::check_store<gpu_arch::Xe, dtype,
+ store_dtype>::template local_scatter<payload_t::tile_bytes,
+ payload_t::min_bytes, payload_t::block_bytes,
+ payload_t::num_channel_x, payload_t::num_channel>;
+
+ constexpr uint32_t num_channel_y = payload_t::num_channel_y;
+ constexpr uint32_t store_elems = num_channel_y * tile_desc::block_size_x;
+#pragma unroll
+ for (int i = 0; i < tile_desc::tile_size_y / tile_desc::block_size_y; i++) {
+ uint32_t offset_y = i * tile_desc::block_size_y;
+#pragma unroll
+ for (int j = 0; j < tile_desc::num_block_x; j++) {
+ uint32_t offset_x = j * tile_desc::block_size_x;
+ auto reg_sub = tile.reg.xetla_select<tile_desc::block_elems, 1>(
+ (i * tile_desc::num_block_x + j) * tile_desc::block_elems);
+#pragma unroll
+ for (int sub_block_y = 0; sub_block_y < tile_desc::block_size_y;
+ sub_block_y += num_channel_y) {
+ uint32_t address_offset = offset_x * sizeof(dtype)
+ + (sub_block_y + offset_y) * payload.pitch_in_bytes;
+ xetla_store_local<store_dtype>(payload.address + address_offset,
+ reg_sub.xetla_select<store_elems, 1>(
+ sub_block_y * tile_desc::block_size_x)
+ .xetla_format<store_dtype>());
+ }
+ }
+ }
+ // process the tail
+ if constexpr ((tile_desc::tile_size_y % tile_desc::block_size_y) != 0) {
+ constexpr uint32_t remained_size_y = tile_desc::remained_size_y;
+ constexpr uint32_t offset_y = tile_desc::block_size_y - remained_size_y;
+ constexpr uint32_t processed_elems = offset_y * tile_desc::tile_size_x;
+ constexpr uint32_t remain_block_elems
+ = remained_size_y * tile_desc::block_size_x;
+#pragma unroll
+ for (int j = 0; j < tile_desc::num_block_x; j++) {
+ uint32_t offset_x = j * tile_desc::block_size_x;
+ auto reg_sub = tile.reg.xetla_select<remain_block_elems, 1>(
+ processed_elems + j * remain_block_elems);
+#pragma unroll
+ for (int sub_block_y = 0; sub_block_y < remained_size_y;
+ sub_block_y += num_channel_y) {
+ uint32_t address_offset = offset_x * sizeof(dtype)
+ + (sub_block_y + offset_y) * payload.pitch_in_bytes;
+ xetla_store_local<store_dtype>(payload.address + address_offset,
+ reg_sub.xetla_select<store_elems, 1>(
+ sub_block_y * tile_desc::block_size_x)
+ .xetla_format<store_dtype>());
+ }
+ }
+ }
+}
+
+/// @brief Is the data store func from register file to local shared memory,
+/// where the data in register is vnni packed and col major. And we always assume
+/// the dst memory layout is row major.
+/// @tparam tile_t Is the tile_t struct contains registers
+/// These registers will be the source of store operation.
+/// @tparam payload_t Is the mem_payload_t struct describing the memory info
+/// payload indicates the destination of store operation
+/// @tparam L1 Is the cache hint for L1 cache.
+/// @tparam L2 Is the cache hint for L2 cache.
+/// @param tile Is the tile object with type tile_t, contains the data to be stored.
+/// @param payload Is the payload object with type payload_t. Contains all the information for stores.
+template <cache_hint L1 = cache_hint::write_back,
+ cache_hint L2 = cache_hint::write_back, typename tile_t,
+ typename payload_t>
+__XETLA_API typename std::enable_if_t<detail::check_store_type<tile_t,
+ payload_t>::is_local_scatter_vnni_col_xe>
+tile_store(tile_t &tile, payload_t &payload) {
+ using dtype = typename tile_t::dtype;
+ using tile_desc = typename tile_t::tile_desc;
+ using store_dtype = typename payload_t::store_dtype;
+
+ constexpr uint32_t vnni_scale_factor = payload_t::vnni_scale_factor;
+ constexpr uint32_t num_vector_size = payload_t::num_vector_size;
+ constexpr uint32_t store_elems = payload_t::store_elems;
+#pragma unroll
+ for (int i = 0; i < tile_desc::tile_size_y / tile_desc::block_size_y; i++) {
+ uint32_t offset_y = i * tile_desc::block_size_y;
+#pragma unroll
+ for (int j = 0; j < tile_desc::num_block_x; j++) {
+ uint32_t offset_x = j * tile_desc::block_size_x;
+ auto reg_sub = tile.reg.xetla_select<tile_desc::block_elems, 1>(
+ (i * tile_desc::num_block_x + j) * tile_desc::block_elems);
+#pragma unroll
+ for (int sub_block_y = 0; sub_block_y < tile_desc::block_size_y;
+ sub_block_y += num_vector_size * vnni_scale_factor) {
+ uint32_t address_offset = payload.base_address
+ + offset_x * payload.pitch_in_bytes
+ + (sub_block_y + offset_y) * sizeof(dtype);
+ xetla_store_local<store_dtype, num_vector_size>(
+ payload.channel_address + address_offset,
+ reg_sub.xetla_select<store_elems, 1>(
+ sub_block_y * tile_desc::block_size_x)
+ .xetla_format<store_dtype>());
+ }
+ }
+ }
+ // process the tail
+ if constexpr ((tile_desc::tile_size_y % tile_desc::block_size_y) != 0) {
+ constexpr uint32_t remained_size_y = tile_desc::remained_size_y;
+ constexpr uint32_t offset_y = tile_desc::tile_size_y - remained_size_y;
+ constexpr uint32_t processed_elems = offset_y * tile_desc::tile_size_x;
+ constexpr uint32_t remain_block_elems
+ = remained_size_y * tile_desc::block_size_x;
+#pragma unroll
+ for (int j = 0; j < tile_desc::num_block_x; j++) {
+ uint32_t offset_x = j * tile_desc::block_size_x;
+ auto reg_sub = tile.reg.xetla_select<remain_block_elems, 1>(
+ processed_elems + j * remain_block_elems);
+#pragma unroll
+ for (int sub_block_y = 0; sub_block_y < remained_size_y;
+ sub_block_y += num_vector_size * vnni_scale_factor) {
+ uint32_t address_offset = payload.base_address
+ + offset_x * payload.pitch_in_bytes
+ + (sub_block_y + offset_y) * sizeof(dtype);
+ xetla_store_local<store_dtype, num_vector_size>(
+ payload.channel_address + address_offset,
+ reg_sub.xetla_select<store_elems, 1>(
+ sub_block_y * tile_desc::block_size_x)
+ .xetla_format<store_dtype>());
+ }
+ }
+ }
+}
+
+/// @brief Is the data store func from register file to shared local memory,
+/// where supports memory surface 1d or 2d scenario, and we always assume dst memory
+/// layout is row major.
+/// @tparam tile_t Is the tile_t struct contains registers
+/// These registers will be the source of store operation.
+/// @tparam payload_t Is the mem_payload_t struct describing the memory info
+/// payload indicates the destination of store operation
+/// @tparam L1 Is the cache hint for L1 cache.
+/// @tparam L2 Is the cache hint for L2 cache.
+/// @param tile Is the tile object with type tile_t, contains the data to be stored.
+/// @param payload Is the payload object with type payload_t. Contains all the information for stores.
+template <cache_hint L1 = cache_hint::write_back,
+ cache_hint L2 = cache_hint::write_back, typename tile_t,
+ typename payload_t>
+__XETLA_API typename std::enable_if_t<
+ detail::check_store_type<tile_t, payload_t>::is_local_block_1d_xe
+ && tile_t::block_size_y != 1>
+tile_store(tile_t &tile, payload_t &payload) {
+ using dtype = typename tile_t::dtype;
+ using tile_desc = typename tile_t::tile_desc;
+ using store_dtype = typename payload_t::mem_dtype;
+ using check_store = typename subgroup::check_store<gpu_arch::Xe, dtype,
+ store_dtype>::local_1d;
+
+ constexpr uint32_t vector_size
+ = payload_t::bytes_per_row / sizeof(store_dtype);
+
+#pragma unroll
+ for (int i = 0; i < tile_desc::tile_size_y / tile_desc::block_size_y; i++) {
+ uint32_t offset_y = i * tile_desc::block_size_y;
+#pragma unroll
+ for (int j = 0; j < tile_desc::num_block_x; j++) {
+ uint32_t offset_x = j * tile_desc::block_size_x;
+ auto reg_sub = tile.reg.xetla_select<tile_desc::block_elems, 1>(
+ (i * tile_desc::num_block_x + j) * tile_desc::block_elems);
+ auto reg_sub_2d = reg_sub.xetla_format<dtype,
+ tile_desc::block_size_y, tile_desc::block_size_x>();
+ uint32_t address_offset = offset_x * sizeof(dtype)
+ + offset_y * payload.pitch_in_bytes;
+#pragma unroll
+ for (int row_i = 0; row_i < tile_desc::block_size_y; row_i++) {
+ xetla_store_local<store_dtype, vector_size>(payload.base_address
+ + payload.address + address_offset
+ + row_i * payload.pitch_in_bytes,
+ reg_sub_2d.row(row_i).xetla_format<store_dtype>());
+ }
+ }
+ }
+ // process the tail
+ if constexpr ((tile_desc::tile_size_y % tile_desc::block_size_y) != 0) {
+ constexpr uint32_t remained_size_y = tile_desc::remained_size_y;
+ constexpr uint32_t offset_y = tile_desc::tile_size_y - remained_size_y;
+ constexpr uint32_t processed_elems = offset_y * tile_desc::tile_size_x;
+ constexpr uint32_t remain_block_elems
+ = remained_size_y * tile_desc::block_size_x;
+#pragma unroll
+ for (int j = 0; j < tile_desc::num_block_x; j++) {
+ uint32_t offset_x = j * tile_desc::block_size_x;
+ auto reg_sub = tile.reg.xetla_select<remain_block_elems, 1>(
+ processed_elems + j * remain_block_elems);
+ auto reg_sub_2d = reg_sub.xetla_format<dtype, remained_size_y,
+ tile_desc::block_size_x>();
+ uint32_t address_offset = offset_x * sizeof(dtype)
+ + offset_y * payload.pitch_in_bytes;
+#pragma unroll
+ for (int row_i = 0; row_i < remained_size_y; row_i++) {
+ xetla_store_local<store_dtype, vector_size>(payload.base_address
+ + payload.address + address_offset
+ + row_i * payload.pitch_in_bytes,
+ reg_sub_2d.row(row_i).xetla_format<store_dtype>());
+ }
+ }
+ }
+}
+
+/// @brief Is the func storing data from register file to shared local memory,
+/// the data in registers will be stored to SLM in 1d mode, and we always assume dst memory
+/// layout is row major.
+/// @tparam tile_t Is the tile_t struct contains registers
+/// These registers will be the source of store operation.
+/// @tparam payload_t Is the mem_payload_t struct describing the memory info
+/// payload indicates the destination of store operation
+/// @tparam L1 Is the cache hint for L1 cache.
+/// @tparam L2 Is the cache hint for L2 cache.
+/// @param tile Is the tile object with type tile_t, contains the data to be stored.
+/// @param payload Is the payload object with type payload_t. Contains all the information for stores.
+template <cache_hint L1 = cache_hint::write_back,
+ cache_hint L2 = cache_hint::write_back, typename tile_t,
+ typename payload_t>
+__XETLA_API typename std::enable_if_t<
+ detail::check_store_type<tile_t, payload_t>::is_local_block_1d_xe
+ && tile_t::tile_size_y == 1 && tile_t::block_size_y == 1>
+tile_store(tile_t &tile, payload_t &payload) {
+ using dtype = typename tile_t::dtype;
+ using tile_desc = typename payload_t::tile_desc;
+ using store_dtype = typename payload_t::mem_dtype;
+ using check_store = typename subgroup::check_store<gpu_arch::Xe, dtype,
+ store_dtype>::local_1d;
+
+ constexpr uint32_t scale_factor = payload_t::scale_factor;
+ constexpr uint32_t store_len = tile_desc::tile_size_x / scale_factor;
+ if constexpr (store_len >= 64) {
+#pragma unroll
+ for (int j = 0; j < store_len / 64; j++) {
+ uint32_t offset_x = j * 64 * scale_factor;
+ auto reg_sub
+ = tile.reg.xetla_select<64 * scale_factor, 1>(offset_x);
+ uint32_t address_offset = offset_x * sizeof(dtype);
+ xetla_store_local<store_dtype, 64>(
+ payload.base_address + payload.address + address_offset,
+ reg_sub.xetla_format<store_dtype>());
+ }
+ }
+ uint32_t tail_offset = store_len / 64 * 64 * scale_factor;
+ detail::process_1d_tail<store_len % 64, 32, detail::process_flag::store, L1,
+ L2>(tile, payload, tail_offset, tail_offset * sizeof(dtype));
+}
+
+} // namespace gpu::xetla::subgroup
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/subgroup/tile/impl/tile_op_functor.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/subgroup/tile/impl/tile_op_functor.hpp
new file mode 100644
index 00000000000..4b5445a6c92
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/subgroup/tile/impl/tile_op_functor.hpp
@@ -0,0 +1,1506 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#include "subgroup/tile/api.hpp"
+#include "subgroup/tile/common.hpp"
+#include "subgroup/tile/impl/load_xe.hpp"
+#include "subgroup/tile/impl/payload_xe.hpp"
+#include "subgroup/tile/impl/prefetch_xe.hpp"
+#include "subgroup/tile/impl/reduction.hpp"
+#include "subgroup/tile/impl/store_xe.hpp"
+
+namespace gpu::xetla::subgroup {
+
+/// @brief Is none op functor, for placeholder purpose.
+/// Used in epilogue::tile_op or chained_tile_op.
+struct none_op_t {
+ struct arguments_t {};
+ template <typename matAcc_t, typename coord_t>
+ __XETLA_API KERNEL_FUNC void operator()(matAcc_t &matAcc,
+ const coord_t &coord, const arguments_t &args,
+ uint32_t slm_base = 0, uint32_t nbarrier_base = 0) {}
+ //none_op_t functor for dequant_op
+ template <typename mat_out_t, typename mat_in_t, typename coord_t>
+ __XETLA_API KERNEL_FUNC void operator()(mat_out_t &mat_out,
+ mat_in_t &mat_in, const coord_t &coord, const arguments_t &args) {
+ mat_out = mat_in;
+ }
+};
+
+/// @brief Is the element-wise relu op functor.
+/// Get the relu input from matAcc, update the relu output in place,
+/// Used in epilogue::tile_op or chained_tile_op.
+struct relu_op_t {
+ struct arguments_t {};
+ template <typename matAcc_t, typename coord_t>
+ __XETLA_API KERNEL_FUNC void operator()(matAcc_t &matAcc,
+ const coord_t &coord, const arguments_t &args,
+ uint32_t slm_base = 0, uint32_t nbarrier_base = 0) {
+ xetla_mask<matAcc_t::tile_elems> mask = matAcc.reg < 0;
+ matAcc.reg.xetla_merge(0, mask);
+ }
+};
+
+/// @brief Is the element-wise relu op functor with relu mask collection.
+/// Get the relu input from matAcc, update the relu output in place, store the mask in memory.
+/// The mask has the same layout as the relu output.
+/// Used in epilogue::tile_op or chained_tile_op.
+template <typename dtype_mask, gpu_arch arch_tag, class enable = void>
+struct relu_pack_mask_op_t {};
+
+template <typename dtype_mask_, gpu_arch arch_tag>
+struct relu_pack_mask_op_t<dtype_mask_, arch_tag,
+ std::enable_if_t<(arch_tag == gpu_arch::Xe)>> {
+ using dtype_mask = dtype_mask_;
+ using mem_desc_mask_t
+ = mem_desc_t<dtype_mask, mem_layout::row_major, mem_space::global>;
+ using shape_t = typename mem_desc_mask_t::shape_t;
+ using coord_t = typename mem_desc_mask_t::coord_t;
+ using base_t = typename mem_desc_mask_t::base_t;
+
+ static constexpr uint32_t simd_len = 16;
+ static constexpr uint32_t out_elems_per_step = 4 * simd_len;
+
+ struct arguments_t {
+ shape_t mask_shape;
+ base_t mask_base;
+ inline arguments_t() = default;
+ inline arguments_t(base_t mask_base_, shape_t mask_shape_)
+ : mask_base(mask_base_), mask_shape(mask_shape_) {}
+ };
+
+ template <typename matAcc_t>
+ __XETLA_API KERNEL_FUNC void operator()(matAcc_t &matAcc,
+ const coord_t &coord, const arguments_t &args,
+ uint32_t slm_base = 0, uint32_t nbarrier_base = 0) {
+ static constexpr uint32_t tile_size_x = matAcc_t::tile_size_x;
+ static constexpr uint32_t tile_size_y = matAcc_t::tile_size_y;
+ static constexpr uint32_t block_size_x = matAcc_t::block_size_x;
+ static constexpr uint32_t block_size_y = matAcc_t::block_size_y;
+ static constexpr int32_t num_block_x = matAcc_t::num_block_x;
+ static constexpr int32_t num_block_y = matAcc_t::num_block_y;
+ static constexpr uint32_t tile_elems = matAcc_t::tile_elems;
+ static constexpr uint32_t block_elems = matAcc_t::block_elems;
+
+ using mask_out_tile_desc_t = tile_desc_t<tile_size_x, tile_size_y,
+ block_size_x, block_size_y, reg_layout::tiled>;
+ using mask_out_tile_t = tile_t<dtype_mask, mask_out_tile_desc_t>;
+ using mask_out_payload_t = mem_payload_t<mem_desc_mask_t,
+ mask_out_tile_desc_t,
+ msg_type_v<mask_out_tile_desc_t, mem_desc_mask_t::space>,
+ arch_tag>;
+
+ mem_desc_mask_t mem_desc_mask(args.mask_base, args.mask_shape, coord);
+ mask_out_tile_t mask_out;
+ mask_out_payload_t mask_out_payload(mem_desc_mask);
+
+ if constexpr (tile_elems / out_elems_per_step != 0) {
+#pragma unroll
+ for (int i = 0; i < tile_elems / out_elems_per_step; ++i) {
+ auto out_sub = matAcc.reg.xetla_select<out_elems_per_step, 1>(
+ i * out_elems_per_step);
+ auto mask_sub
+ = mask_out.reg.xetla_select<out_elems_per_step, 1>(
+ i * out_elems_per_step);
+ xetla_mask<out_elems_per_step> mask_flag = out_sub < 0;
+ out_sub.xetla_merge(0, mask_flag);
+ mask_sub.xetla_merge(1, 0, mask_flag);
+ }
+ }
+
+ if constexpr (tile_elems % out_elems_per_step != 0) {
+ constexpr uint32_t remain_len = tile_elems % out_elems_per_step;
+ constexpr uint32_t remain_start
+ = tile_elems / out_elems_per_step * out_elems_per_step;
+ auto out_sub = matAcc.reg.xetla_select<remain_len, 1>(remain_start);
+ auto mask_sub
+ = mask_out.reg.xetla_select<remain_len, 1>(remain_start);
+ xetla_mask<remain_len> mask_flag = out_sub < 0;
+ out_sub.xetla_merge(0, mask_flag.xetla_select<remain_len, 1>(0));
+ mask_sub.xetla_merge(
+ 1, 0, mask_flag.xetla_select<remain_len, 1>(0));
+ }
+
+ tile_store<cache_hint::streaming>(mask_out, mask_out_payload);
+ }
+};
+
+/// @brief Is the relu-mask-based element-wise relu op functor.
+/// Get the relu input from matAcc, update the relu output in place using the mask stored in memory.
+/// The mask has the same layout as the relu output.
+/// Used in epilogue::tile_op or chained_tile_op.
+template <typename dtype_mask, gpu_arch arch_tag, class enable = void>
+struct relu_unpack_mask_op_t {};
+
+template <typename dtype_mask_, gpu_arch arch_tag>
+struct relu_unpack_mask_op_t<dtype_mask_, arch_tag,
+ std::enable_if_t<(arch_tag == gpu_arch::Xe)>> {
+ using dtype_mask = dtype_mask_;
+ using mem_desc_mask_t
+ = mem_desc_t<dtype_mask, mem_layout::row_major, mem_space::global>;
+ using shape_t = typename mem_desc_mask_t::shape_t;
+ using coord_t = typename mem_desc_mask_t::coord_t;
+ using base_t = typename mem_desc_mask_t::base_t;
+
+ static constexpr uint32_t simd_len = 16;
+ static constexpr uint32_t out_elems_per_step = 4 * simd_len;
+
+ struct arguments_t {
+ shape_t mask_shape;
+ base_t mask_base;
+ inline arguments_t() = default;
+ inline arguments_t(base_t mask_base_, shape_t mask_shape_)
+ : mask_base(mask_base_), mask_shape(mask_shape_) {}
+ };
+
+ template <typename matAcc_t>
+ __XETLA_API KERNEL_FUNC void operator()(matAcc_t &matAcc,
+ const coord_t &coord, const arguments_t &args,
+ uint32_t slm_base = 0, uint32_t nbarrier_base = 0) {
+ static constexpr uint32_t tile_size_x = matAcc_t::tile_size_x;
+ static constexpr uint32_t tile_size_y = matAcc_t::tile_size_y;
+ static constexpr uint32_t block_size_x = matAcc_t::block_size_x;
+ static constexpr uint32_t block_size_y = matAcc_t::block_size_y;
+ static constexpr int32_t num_block_x = matAcc_t::num_block_x;
+ static constexpr int32_t num_block_y = matAcc_t::num_block_y;
+ static constexpr uint32_t tile_elems = matAcc_t::tile_elems;
+ static constexpr uint32_t block_elems = matAcc_t::block_elems;
+
+ using mask_in_tile_desc_t = tile_desc_t<tile_size_x, tile_size_y,
+ block_size_x, block_size_y, reg_layout::tiled>;
+ using mask_in_tile_t = tile_t<dtype_mask, mask_in_tile_desc_t>;
+ using mask_in_payload_t
+ = mem_payload_t<mem_desc_mask_t, mask_in_tile_desc_t,
+ msg_type_v<mask_in_tile_desc_t, mem_desc_mask_t::space>,
+ arch_tag>;
+
+ mem_desc_mask_t mem_desc_mask(args.mask_base, args.mask_shape, coord);
+ mask_in_tile_t mask_in;
+ mask_in_payload_t mask_in_payload(mem_desc_mask);
+
+ tile_load<cache_hint::cached, cache_hint::cached>(
+ mask_in, mask_in_payload);
+
+ if constexpr (tile_elems / out_elems_per_step != 0) {
+#pragma unroll
+ for (int i = 0; i < tile_elems / out_elems_per_step; ++i) {
+ xetla_mask<out_elems_per_step> mask_flag
+ = mask_in.reg.xetla_select<out_elems_per_step, 1>(
+ i * out_elems_per_step)
+ > 0;
+ auto dst_reg = matAcc.reg.xetla_select<out_elems_per_step, 1>(
+ i * out_elems_per_step);
+ dst_reg.xetla_merge(0, mask_flag);
+ }
+ }
+
+ if constexpr (tile_elems % out_elems_per_step != 0) {
+ constexpr uint32_t remain_len = tile_elems % out_elems_per_step;
+ constexpr uint32_t remain_start
+ = tile_elems / out_elems_per_step * out_elems_per_step;
+ xetla_mask<remain_len> mask_flag
+ = mask_in.reg.xetla_select<remain_len, 1>(remain_start) > 0;
+ auto dst_reg = matAcc.reg.xetla_select<remain_len, 1>(remain_start);
+ dst_reg.xetla_merge(0, mask_flag);
+ }
+ }
+};
+
+/// @brief Is the element-wise tanh op functor.
+/// Get the tanh input from matAcc, update the the tanh output in place,
+/// Used in epilogue::tile_op or chained_tile_op.
+struct tanh_op_t {
+ struct arguments_t {};
+ template <typename matAcc_t, typename coord_t>
+ __XETLA_API KERNEL_FUNC void operator()(matAcc_t &matAcc,
+ const coord_t &coord, uint32_t slm_base = 0,
+ uint32_t nbarrier_base = 0) {
+ constexpr int elems = matAcc_t::tile_desc::block_elems;
+ constexpr int rounds = matAcc_t::tile_desc::tile_elems / elems;
+ using dtype = typename matAcc_t::dtype;
+#pragma unroll
+ for (int i = 0; i < rounds; ++i) {
+ auto sub_vec = matAcc.reg.xetla_select<elems, 1>(elems * i);
+ sub_vec = xetla_tanh<dtype, elems>(sub_vec);
+ }
+ constexpr int remaining_elems = matAcc_t::tile_desc::tile_elems % elems;
+ if constexpr (remaining_elems != 0) {
+ auto sub_vec = matAcc.reg.xetla_select<remaining_elems, 1>(
+ elems * (matAcc_t::tile_elems / elems));
+ sub_vec = xetla_tanh<dtype, remaining_elems>(sub_vec);
+ }
+ }
+};
+
+/// @brief Is the element-wise sigmoid op functor.
+/// Get the sigmoid input from matAcc, update the the sigmoid output in place,
+/// Used in epilogue::tile_op or chained_tile_op.
+struct sigmoid_op_t {
+ struct arguments_t {};
+ template <typename matAcc_t, typename coord_t>
+ __XETLA_API KERNEL_FUNC void operator()(matAcc_t &matAcc,
+ const coord_t &coord, uint32_t slm_base = 0,
+ uint32_t nbarrier_base = 0) {
+ constexpr int elems = matAcc_t::tile_desc::block_elems;
+ constexpr int rounds = matAcc_t::tile_desc::tile_elems / elems;
+#pragma unroll
+ for (int i = 0; i < rounds; ++i) {
+ auto sub_vec = matAcc.reg.xetla_select<elems, 1>(elems * i);
+ sub_vec = xetla_sigmoid<typename matAcc_t::dtype, elems>(sub_vec);
+ }
+ constexpr int remaining_elems = matAcc_t::tile_desc::tile_elems % elems;
+ if constexpr (remaining_elems != 0) {
+ auto sub_vec = matAcc.reg.xetla_select<remaining_elems, 1>(
+ elems * (matAcc_t::tile_elems / elems));
+ sub_vec = xetla_sigmoid<typename matAcc_t::dtype, remaining_elems>(
+ sub_vec);
+ }
+ }
+};
+
+/// @brief Is the element-wise silu op functor.
+/// Get the silu input from matAcc, update the the silu output in place,
+/// Used in epilogue::tile_op or chained_tile_op.
+struct silu_op_t {
+ struct arguments_t {};
+ template <typename matAcc_t, typename coord_t>
+ __XETLA_API KERNEL_FUNC void operator()(matAcc_t &matAcc,
+ const coord_t &coord, const arguments_t &args,
+ uint32_t slm_base = 0, uint32_t nbarrier_base = 0) {
+ constexpr int elems = matAcc_t::tile_desc::block_elems;
+ constexpr int rounds = matAcc_t::tile_desc::tile_elems / elems;
+#pragma unroll
+ for (int i = 0; i < rounds; ++i) {
+ auto sub_vec = matAcc.reg.xetla_select<elems, 1>(elems * i);
+ xetla_vector<typename matAcc_t::dtype, elems> sigmoid_value
+ = xetla_sigmoid<typename matAcc_t::dtype, elems>(sub_vec);
+ sub_vec = sub_vec * sigmoid_value;
+ }
+ constexpr int remaining_elems = matAcc_t::tile_desc::tile_elems % elems;
+ if constexpr (remaining_elems != 0) {
+ auto sub_vec = matAcc.reg.xetla_select<remaining_elems, 1>(
+ elems * (matAcc_t::tile_elems / elems));
+ xetla_vector<typename matAcc_t::dtype, remaining_elems>
+ sigmoid_value
+ = xetla_sigmoid<typename matAcc_t::dtype, remaining_elems>(
+ sub_vec);
+ sub_vec = sub_vec * sigmoid_value;
+ }
+ }
+};
+
+/// @brief Is the element-wise gelu inference forward op functor.
+/// Get the gelu input from matAcc, update the the gelu output in place,
+/// Used in epilogue::tile_op or chained_tile_op.
+struct gelu_fwd_op_t {
+ struct arguments_t {};
+ template <typename matAcc_t, typename coord_t>
+ __XETLA_API KERNEL_FUNC void operator()(matAcc_t &matAcc,
+ const coord_t &coord, const arguments_t &args,
+ uint32_t slm_base = 0, uint32_t nbarrier_base = 0) {
+ using dtype = typename matAcc_t::dtype;
+ constexpr dtype C0 = 0.044715f;
+ constexpr dtype sqrt_two_over_pi = 0.79788458347320556640625f;
+ // total flag register
+ constexpr int elems = 8 * 16;
+ constexpr int rounds = matAcc_t::tile_elems / elems;
+ if constexpr (rounds != 0) {
+#pragma unroll
+ for (int i = 0; i < rounds; ++i) {
+ auto sub_vec = matAcc.reg.xetla_select<elems, 1>(elems * i);
+ xetla_vector<dtype, elems> sub_vec_x = (sqrt_two_over_pi
+ * sub_vec * (1.f + C0 * sub_vec * sub_vec));
+ xetla_vector<dtype, elems> tanh_value
+ = xetla_tanh<dtype, elems>(sub_vec_x);
+ sub_vec = 0.5f * sub_vec * (1.f + tanh_value);
+ }
+ }
+
+ constexpr int remaining_elems = matAcc_t::tile_elems % elems;
+ if constexpr (remaining_elems != 0) {
+ auto sub_vec = matAcc.reg.xetla_select<remaining_elems, 1>(
+ elems * (matAcc_t::tile_elems / elems));
+ xetla_vector<dtype, remaining_elems> sub_vec_x = (sqrt_two_over_pi
+ * sub_vec * (1.f + C0 * sub_vec * sub_vec));
+ xetla_vector<dtype, remaining_elems> tanh_value
+ = xetla_tanh<dtype, remaining_elems>(sub_vec_x);
+ sub_vec = 0.5f * sub_vec * (1.f + tanh_value);
+ }
+ }
+};
+
+/// @brief Is the element-wise gelu training forward op functor.
+/// Get the gelu input from matAcc, update the the gelu output in place,
+/// and dump the intermediate buffer_w to memory for backward purpose.
+/// Used in epilogue::tile_op or chained_tile_op.
+/// @tparam dtype_out Is the data type of the intermediate buffer_w.
+/// @tparam arch_tag Is the hardware architecture tag.
+template <typename dtype_out, gpu_arch arch_tag, class enable = void>
+struct gelu_fwd_w_op_t {};
+/// @brief Is the element-wise gelu training forward op functor, specialized for Xe architecture.
+template <typename dtype_out_, gpu_arch arch_tag>
+struct gelu_fwd_w_op_t<dtype_out_, arch_tag,
+ std::enable_if_t<(arch_tag == gpu_arch::Xe)>> {
+ using dtype_out = dtype_out_;
+ using mem_desc_w_t
+ = mem_desc_t<dtype_out, mem_layout::row_major, mem_space::global>;
+ using shape_t = typename mem_desc_w_t::shape_t;
+ using coord_t = typename mem_desc_w_t::coord_t;
+ using base_t = typename mem_desc_w_t::base_t;
+
+ struct arguments_t {
+ shape_t shape;
+ base_t base;
+ inline arguments_t() = default;
+ inline arguments_t(base_t base_, shape_t shape_)
+ : base(base_), shape(shape_) {}
+ };
+ template <typename matAcc_t>
+ __XETLA_API KERNEL_FUNC void operator()(matAcc_t &matAcc,
+ const coord_t &coord, const arguments_t &args,
+ uint32_t slm_base = 0, uint32_t nbarrier_base = 0) {
+ using dtype_acc = typename matAcc_t::dtype;
+ static constexpr uint32_t tile_size_x = matAcc_t::tile_size_x;
+ static constexpr uint32_t tile_size_y = matAcc_t::tile_size_y;
+ static constexpr uint32_t block_size_x = matAcc_t::block_size_x;
+ static constexpr uint32_t block_size_y = matAcc_t::block_size_y;
+
+ mem_desc_w_t mem_desc_w(args.base, args.shape, coord);
+ using bwd_w_tile_desc_t = tile_desc_t<block_size_x, block_size_y,
+ block_size_x, block_size_y, reg_layout::tiled>;
+ using bwd_w_tile_t = tile_t<dtype_out, bwd_w_tile_desc_t>;
+ using bwd_w_payload_t = mem_payload_t<mem_desc_w_t, bwd_w_tile_desc_t,
+ msg_type::block_2d, arch_tag>;
+ bwd_w_tile_t bwd_w;
+ bwd_w_payload_t bwd_w_payload(mem_desc_w);
+ // start compute
+ constexpr dtype_acc c0 = 0.044715f;
+ constexpr dtype_acc d0 = 0.134145f;
+ constexpr dtype_acc sqrt_two_over_pi = 0.79788458347320556640625f;
+ constexpr uint32_t block_elems = matAcc_t::block_elems;
+ constexpr uint32_t num_block_x = matAcc_t::num_block_x;
+#pragma unroll
+ for (int i = 0; i < tile_size_y / block_size_y; ++i) {
+#pragma unroll
+ for (int j = 0; j < num_block_x; ++j) {
+ auto x = matAcc.reg.xetla_select<block_elems, 1>(
+ block_elems * (i * num_block_x + j));
+ xetla_vector<dtype_acc, block_elems> z
+ = xetla_tanh<dtype_acc, block_elems>(
+ sqrt_two_over_pi * (x + c0 * x * x * x));
+ xetla_vector<dtype_acc, block_elems> w = (0.5f * (1.f + z)
+ + 0.5f * x * (1.f - z * z)
+ * (sqrt_two_over_pi * (1.f + d0 * x * x)));
+ x = 0.5f * x * (1.f + z);
+ bwd_w.reg = xetla_cvt<dtype_out, dtype_acc, block_elems>(w);
+ tile_store<cache_hint::uncached>(bwd_w, bwd_w_payload);
+ bwd_w_payload.template update_tdesc<tdesc_update_dir::x_dir>(
+ block_size_x);
+ }
+ bwd_w_payload.template update_tdesc<tdesc_update_dir::x_dir>(
+ -1 * tile_size_x);
+ bwd_w_payload.template update_tdesc<tdesc_update_dir::y_dir>(
+ block_size_y);
+ }
+ if constexpr (tile_size_y % block_size_y != 0) {
+ constexpr uint32_t remain_size_y = tile_size_y % block_size_y;
+ constexpr uint32_t remain_y_start
+ = tile_size_y / block_size_y * block_size_y;
+ constexpr uint32_t remain_elems_start
+ = remain_y_start * tile_size_x;
+ constexpr uint32_t remain_block_elems
+ = remain_size_y * block_size_x;
+
+ using remain_bwd_w_tile_desc_t
+ = tile_desc_t<block_size_x, remain_size_y, block_size_x,
+ remain_size_y, reg_layout::tiled>;
+ using remain_bwd_w_tile_t
+ = tile_t<dtype_out, remain_bwd_w_tile_desc_t>;
+ using remain_bwd_w_payload_t = mem_payload_t<mem_desc_w_t,
+ remain_bwd_w_tile_desc_t, msg_type::block_2d, arch_tag>;
+
+ mem_desc_w.update_coord_y(remain_y_start);
+ remain_bwd_w_payload_t remain_bwd_w_payload(mem_desc_w);
+ remain_bwd_w_tile_t remain_bwd_w;
+#pragma unroll
+ for (int j = 0; j < num_block_x; ++j) {
+ auto x = matAcc.reg.xetla_select<remain_block_elems, 1>(
+ remain_elems_start + remain_block_elems * j);
+ xetla_vector<dtype_acc, remain_block_elems> z
+ = xetla_tanh<dtype_acc, remain_block_elems>(
+ sqrt_two_over_pi * (x + c0 * x * x * x));
+ xetla_vector<dtype_acc, remain_block_elems> w = (0.5f
+ * (1.f + z)
+ + 0.5f * x * (1.f - z * z)
+ * (sqrt_two_over_pi * (1.f + d0 * x * x)));
+ x = 0.5f * x * (1.f + z);
+ remain_bwd_w.reg
+ = xetla_cvt<dtype_out, dtype_acc, remain_block_elems>(
+ w);
+ tile_store<cache_hint::uncached>(
+ remain_bwd_w, remain_bwd_w_payload);
+ remain_bwd_w_payload
+ .template update_tdesc<tdesc_update_dir::x_dir>(
+ block_size_x);
+ }
+ }
+ }
+};
+
+/// @brief Is the element-wise gelu backward op functor.
+/// Load the gelu forward input buffer from memory and get the gradient data from matAcc, update the output in place.
+/// Used in epilogue::tile_op or chained_tile_op.
+/// @tparam dtype_in Is the data type of the gelu forward input buffer.
+/// @tparam arch_tag Is the hardware architecture tag.
+template <typename dtype_in, gpu_arch arch_tag, class enable = void>
+struct gelu_bwd_op_t {};
+/// @brief Is the element-wise gelu backward op functor, specialized for Xe architecture.
+template <typename dtype_in_, gpu_arch arch_tag>
+struct gelu_bwd_op_t<dtype_in_, arch_tag,
+ std::enable_if_t<(arch_tag == gpu_arch::Xe)>> {
+ using dtype_in = dtype_in_;
+ using mem_desc_x_t
+ = mem_desc_t<dtype_in, mem_layout::row_major, mem_space::global>;
+ using shape_t = typename mem_desc_x_t::shape_t;
+ using coord_t = typename mem_desc_x_t::coord_t;
+ using base_t = typename mem_desc_x_t::base_t;
+ struct arguments_t {
+ shape_t shape;
+ base_t base;
+ inline arguments_t() = default;
+ inline arguments_t(base_t base_, shape_t shape_)
+ : base(base_), shape(shape_) {}
+ };
+ template <typename matAcc_t>
+ __XETLA_API KERNEL_FUNC void operator()(matAcc_t &matAcc,
+ const coord_t &coord, const arguments_t &args,
+ uint32_t slm_base = 0, uint32_t nbarrier_base = 0) {
+ using dtype_acc = typename matAcc_t::dtype;
+ static constexpr uint32_t tile_size_x = matAcc_t::tile_size_x;
+ static constexpr uint32_t tile_size_y = matAcc_t::tile_size_y;
+ static constexpr uint32_t block_size_x = matAcc_t::block_size_x;
+ static constexpr uint32_t block_size_y = matAcc_t::block_size_y;
+
+ using bwd_x_tile_desc_t = tile_desc_t<tile_size_x, tile_size_y,
+ block_size_x, block_size_y, reg_layout::tiled>;
+ using bwd_x_tile_t = tile_t<dtype_in, bwd_x_tile_desc_t>;
+ using bwd_x_payload_t = mem_payload_t<mem_desc_x_t, bwd_x_tile_desc_t,
+ msg_type::block_2d, arch_tag>;
+ bwd_x_tile_t bwd_x;
+ // init tdesc
+ mem_desc_x_t mem_desc_x(args.base, args.shape, coord);
+ bwd_x_payload_t bwd_x_payload(mem_desc_x);
+ tile_load<cache_hint::cached, cache_hint::cached>(bwd_x, bwd_x_payload);
+ // start compute
+ constexpr dtype_acc c0 = 0.044715f;
+ constexpr dtype_acc d0 = 0.134145f;
+ constexpr dtype_acc sqrt_two_over_pi = 0.79788458347320556640625f;
+ constexpr uint32_t block_elems = matAcc_t::block_elems;
+ constexpr uint32_t num_block_x = matAcc_t::num_block_x;
+#pragma unroll
+ for (int i = 0; i < tile_size_y / block_size_y; ++i) {
+#pragma unroll
+ for (int j = 0; j < num_block_x; ++j) {
+ auto x_in = bwd_x.reg.xetla_select<block_elems, 1>(
+ block_elems * (i * num_block_x + j));
+ auto x = xetla_cvt<dtype_acc, dtype_in, block_elems>(x_in);
+ auto dy = matAcc.reg.xetla_select<block_elems, 1>(
+ block_elems * (i * num_block_x + j));
+ xetla_vector<dtype_acc, block_elems> z
+ = xetla_tanh<dtype_acc, block_elems>(
+ sqrt_two_over_pi * (x + c0 * x * x * x));
+ xetla_vector<dtype_acc, block_elems> w = (0.5f * (1.f + z)
+ + 0.5f * x * (1.f - z * z)
+ * (sqrt_two_over_pi * (1.f + d0 * x * x)));
+ dy = w * dy;
+ }
+ }
+ if constexpr (tile_size_y % block_size_y != 0) {
+ constexpr uint32_t remain_size_y = tile_size_y % block_size_y;
+ constexpr uint32_t remain_y_start
+ = tile_size_y / block_size_y * block_size_y;
+ constexpr uint32_t remain_elems_start
+ = remain_y_start * tile_size_x;
+ constexpr uint32_t remain_block_elems
+ = remain_size_y * block_size_x;
+#pragma unroll
+ for (int j = 0; j < num_block_x; ++j) {
+ auto x_in = bwd_x.reg.xetla_select<remain_block_elems, 1>(
+ remain_elems_start + remain_block_elems * j);
+ auto x = xetla_cvt<dtype_acc, dtype_in, remain_block_elems>(
+ x_in);
+ auto dy = matAcc.reg.xetla_select<remain_block_elems, 1>(
+ remain_elems_start + remain_block_elems * j);
+ xetla_vector<dtype_acc, remain_block_elems> z
+ = xetla_tanh<dtype_acc, remain_block_elems>(
+ sqrt_two_over_pi * (x + c0 * x * x * x));
+ xetla_vector<dtype_acc, remain_block_elems> w = (0.5f
+ * (1.f + z)
+ + 0.5f * x * (1.f - z * z)
+ * (sqrt_two_over_pi * (1.f + d0 * x * x)));
+ dy = w * dy;
+ }
+ }
+ }
+};
+
+/// @brief Is the bias_add op functor.
+/// Load the 1d bias data from memory and get the input from matAcc, update the output in place.
+/// Used in epilogue::tile_op or chained_tile_op.
+/// @tparam dtype_bias Is the data type of bias buffer.
+/// @tparam arch_tag Is the hardware architecture tag.
+template <typename dtype_bias, gpu_arch arch_tag, class enable = void>
+struct bias_add_op_t {};
+/// @brief Is the bias_add op functor, specialized for Xe architecture.
+template <typename dtype_bias_, gpu_arch arch_tag>
+struct bias_add_op_t<dtype_bias_, arch_tag,
+ std::enable_if_t<(arch_tag == gpu_arch::Xe)>> {
+ using dtype_bias = dtype_bias_;
+ using mem_desc_bias_t
+ = mem_desc_t<dtype_bias, mem_layout::row_major, mem_space::global>;
+ using shape_t = typename mem_desc_bias_t::shape_t;
+ using coord_t = typename mem_desc_bias_t::coord_t;
+ using base_t = typename mem_desc_bias_t::base_t;
+
+ struct arguments_t {
+ shape_t shape;
+ base_t base;
+ inline arguments_t() = default;
+ inline arguments_t(base_t base_, shape_t shape_)
+ : base(base_), shape(shape_) {}
+ };
+ template <typename matAcc_t>
+ __XETLA_API KERNEL_FUNC void operator()(matAcc_t &matAcc,
+ const coord_t &coord, const arguments_t &args,
+ uint32_t slm_base = 0, uint32_t nbarrier_base = 0) {
+ using dtype_acc = typename matAcc_t::dtype;
+ static constexpr uint32_t tile_size_x = matAcc_t::tile_size_x;
+ static constexpr uint32_t tile_size_y = matAcc_t::tile_size_y;
+ static constexpr uint32_t block_size_x = matAcc_t::block_size_x;
+ static constexpr uint32_t block_size_y = matAcc_t::block_size_y;
+ static constexpr int32_t num_block_x = matAcc_t::num_block_x;
+ static constexpr int32_t num_block_y = matAcc_t::num_block_y;
+ static constexpr uint32_t tile_elems = matAcc_t::tile_elems;
+ static constexpr uint32_t block_elems = matAcc_t::block_elems;
+
+ using bias_tile_desc_t = tile_desc_t<tile_size_x, 1, block_size_x, 1,
+ reg_layout::tiled>;
+ using bias_t = tile_t<dtype_bias, bias_tile_desc_t>;
+ using bias_payload_t = mem_payload_t<mem_desc_bias_t, bias_tile_desc_t,
+ msg_type_v<bias_tile_desc_t, mem_desc_bias_t::space>, arch_tag>;
+ coord_t bias_coord(coord.x, 0);
+ mem_desc_bias_t mem_desc_bias(args.base, args.shape, bias_coord);
+ bias_t bias;
+ bias_payload_t bias_payload(mem_desc_bias);
+ tile_load<cache_hint::cached, cache_hint::cached>(bias, bias_payload);
+
+#pragma unroll
+ for (int i = 0; i < tile_size_y / block_size_y; i++) {
+#pragma unroll
+ for (int j = 0; j < num_block_x; j++) {
+ auto dst_reg
+ = matAcc.reg
+ .xetla_select<block_elems, 1>(
+ (i * num_block_x + j) * block_elems)
+ .xetla_format<dtype_acc, block_size_y,
+ block_size_x>();
+#pragma unroll
+ for (int row_i = 0; row_i < block_size_y; row_i++) {
+ auto src_reg = bias.reg.xetla_select<block_size_x, 1>(
+ j * block_size_x);
+ dst_reg.row(row_i)
+ = xetla_cvt<dtype_acc, dtype_bias, block_size_x>(
+ src_reg)
+ + dst_reg.row(row_i);
+ }
+ }
+ }
+ // process the tail
+ if constexpr ((tile_size_y % block_size_y) != 0) {
+ constexpr uint32_t tail_start_y
+ = tile_size_y / block_size_y * block_size_y;
+ constexpr int32_t tail_size_y = tile_size_y % block_size_y;
+ constexpr int32_t tail_block_elems = tail_size_y * block_size_x;
+#pragma unroll
+ for (int j = 0; j < num_block_x; j++) {
+ auto dst_reg = matAcc.reg
+ .xetla_select<tail_block_elems, 1>(
+ tail_start_y * tile_size_x
+ + j * tail_block_elems)
+ .xetla_format<dtype_acc, tail_size_y,
+ block_size_x>();
+#pragma unroll
+ for (int row_i = 0; row_i < tail_size_y; row_i++) {
+ auto src_reg = bias.reg.xetla_select<block_size_x, 1>(
+ j * block_size_x);
+ dst_reg.row(row_i)
+ = xetla_cvt<dtype_acc, dtype_bias, block_size_x>(
+ src_reg)
+ + dst_reg.row(row_i);
+ }
+ }
+ }
+ }
+};
+
+/// @brief Is the element-wise along-height summing reduction op functor.
+/// Get the input from matAcc, reduce it along height by summing, add the computed output to data in memory.
+/// Used in epilogue::tile_op or chained_tile_op.
+template <typename dtype_sum, gpu_arch arch_tag, class enable = void>
+struct height_reduce_outer_sum_op_t {};
+
+template <typename dtype_sum_, gpu_arch arch_tag>
+struct height_reduce_outer_sum_op_t<dtype_sum_, arch_tag,
+ std::enable_if_t<(arch_tag == gpu_arch::Xe)>> {
+ using dtype_sum = dtype_sum_;
+ using base_t = typename mem_desc_t<dtype_sum, mem_layout::row_major,
+ mem_space::global>::base_t;
+
+ static constexpr uint32_t simd_len = 16;
+
+ struct arguments_t {
+ base_t sum_base;
+ inline arguments_t() = default;
+ inline arguments_t(base_t sum_base_) : sum_base(sum_base_) {}
+ };
+ template <typename matAcc_t, typename coord_t>
+ __XETLA_API KERNEL_FUNC void operator()(matAcc_t &matAcc,
+ const coord_t &coord, const arguments_t &args,
+ uint32_t slm_base = 0, uint32_t nbarrier_base = 0) {
+ using dtype_acc = typename matAcc_t::dtype;
+ static_assert(std::is_same<dtype_sum, dtype_acc>::value,
+ "dtype_sum shall match matAcc_t::dtype");
+
+ static constexpr uint32_t tile_size_x = matAcc_t::tile_size_x;
+
+ xetla_vector<dtype_sum, tile_size_x> row_reg
+ = tile_reduce<reduce_op::sum, dtype_sum, dtype_acc, 0>(matAcc);
+ xetla_vector<uint32_t, simd_len> offsets
+ = xetla_vector_gen<uint32_t, simd_len>(coord.x, 1);
+ xetla_mask<simd_len> pred(1);
+
+#pragma unroll
+ for (uint32_t pos_x = 0; pos_x < tile_size_x; pos_x += simd_len) {
+ xetla_atomic_global<is_integral<dtype_sum>::value ? atomic_op::iadd
+ : atomic_op::fadd,
+ dtype_sum, simd_len, data_size::default_size,
+ cache_hint::uncached, cache_hint::write_back>(
+ args.sum_base.base, (offsets + pos_x) * sizeof(dtype_sum),
+ row_reg.xetla_select<simd_len, 1>(pos_x), pred);
+ }
+ }
+};
+
+/// @brief Is MatAcc * vector scale + vector offset.
+/// @tparam scale_dtype Is the scale data type.
+/// @tparam offset_dtype Is the offset data type.
+/// @tparam arch_tag Is the hardware architecture tag.
+template <typename scale_dtype, typename offset_dtype, gpu_arch arch_tag,
+ class enable = void>
+struct scale_v_offset_v_op_t {};
+/// @brief Is the scale_v_offset_v op functor, specialized for Xe architecture.
+template <typename scale_dtype_, typename offset_dtype_, gpu_arch arch_tag>
+struct scale_v_offset_v_op_t<scale_dtype_, offset_dtype_, arch_tag,
+ std::enable_if_t<(arch_tag == gpu_arch::Xe)>> {
+ using scale_dtype = scale_dtype_;
+ using offset_dtype = offset_dtype_;
+
+ using scale_mem_desc_t
+ = mem_desc_t<scale_dtype, mem_layout::row_major, mem_space::global>;
+ using offset_mem_desc_t = mem_desc_t<offset_dtype, mem_layout::row_major,
+ mem_space::global>;
+
+ using scale_shape_t = typename scale_mem_desc_t::shape_t;
+ using scale_base_t = typename scale_mem_desc_t::base_t;
+
+ using offset_shape_t = typename offset_mem_desc_t::shape_t;
+ using offset_base_t = typename offset_mem_desc_t::base_t;
+
+ using coord_t = typename scale_mem_desc_t::coord_t;
+
+ struct arguments_t {
+ scale_base_t scale_base;
+ scale_shape_t scale_shape;
+ offset_base_t offset_base;
+ offset_shape_t offset_shape;
+ inline arguments_t() = default;
+ inline arguments_t(scale_base_t scale_base_, scale_shape_t scale_shape_,
+ offset_base_t offset_base_, offset_shape_t offset_shape_)
+ : scale_base(scale_base_)
+ , scale_shape(scale_shape_)
+ , offset_base(offset_base_)
+ , offset_shape(offset_shape_) {}
+ };
+ template <typename matAcc_t>
+ __XETLA_API KERNEL_FUNC void operator()(matAcc_t &matAcc,
+ const coord_t &coord, const arguments_t &args,
+ uint32_t slm_base = 0, uint32_t nbarrier_base = 0) {
+ using dtype_acc = typename matAcc_t::dtype;
+
+ static constexpr uint32_t tile_size_x = matAcc_t::tile_size_x;
+ static constexpr uint32_t tile_size_y = matAcc_t::tile_size_y;
+ static constexpr uint32_t block_size_x = matAcc_t::block_size_x;
+ static constexpr uint32_t block_size_y = matAcc_t::block_size_y;
+ static constexpr int32_t num_block_x = matAcc_t::num_block_x;
+ static constexpr int32_t num_block_y = matAcc_t::num_block_y;
+ static constexpr uint32_t tile_elems = matAcc_t::tile_elems;
+ static constexpr uint32_t block_elems = matAcc_t::block_elems;
+
+ using scale_tile_desc_t = tile_desc_t<tile_size_x, 1, block_size_x, 1,
+ reg_layout::tiled>;
+ using scale_tile_t = tile_t<scale_dtype, scale_tile_desc_t>;
+ using scale_payload_t
+ = mem_payload_t<scale_mem_desc_t, scale_tile_desc_t,
+ msg_type_v<scale_tile_desc_t, scale_mem_desc_t::space>,
+ arch_tag>;
+ coord_t scale_coord(coord.x, 0);
+ scale_mem_desc_t scale_mem_desc(
+ args.scale_base, args.scale_shape, scale_coord);
+ scale_tile_t scale_tile;
+ scale_payload_t scale_payload(scale_mem_desc);
+ tile_load<cache_hint::cached, cache_hint::cached>(
+ scale_tile, scale_payload);
+
+ using offset_tile_desc_t = tile_desc_t<tile_size_x, 1, block_size_x, 1,
+ reg_layout::tiled>;
+ using offset_tile_t = tile_t<offset_dtype, offset_tile_desc_t>;
+ using offset_payload_t = mem_payload_t<offset_mem_desc_t,
+ offset_tile_desc_t,
+ msg_type_v<offset_tile_desc_t, offset_mem_desc_t::space>,
+ arch_tag>;
+ coord_t offset_coord(coord.x, 0);
+ offset_mem_desc_t offset_mem_desc(
+ args.offset_base, args.offset_shape, offset_coord);
+ offset_tile_t offset_tile;
+ offset_payload_t offset_payload(offset_mem_desc);
+ tile_load<cache_hint::cached, cache_hint::cached>(
+ offset_tile, offset_payload);
+
+#pragma unroll
+ for (int i = 0; i < tile_size_y / block_size_y; i++) {
+#pragma unroll
+ for (int j = 0; j < num_block_x; j++) {
+ auto acc_reg = matAcc.reg.xetla_select<block_elems, 1>(
+ (i * num_block_x + j) * block_elems);
+ auto offset_reg = offset_tile.reg.xetla_select<block_size_x, 1>(
+ j * block_size_x);
+ auto scale_reg = scale_tile.reg.xetla_select<block_size_x, 1>(
+ j * block_size_x);
+#pragma unroll
+ for (int row_i = 0; row_i < block_size_y; row_i++) {
+ acc_reg.xetla_select<block_size_x, 1>(row_i * block_size_x)
+ = scale_reg
+ * acc_reg.xetla_select<block_size_x, 1>(
+ row_i * block_size_x)
+
+ + offset_reg;
+ }
+ }
+ }
+ // process the tail
+ if constexpr ((tile_size_y % block_size_y) != 0) {
+ constexpr uint32_t tail_start_y
+ = tile_size_y / block_size_y * block_size_y;
+ constexpr int32_t tail_size_y = tile_size_y % block_size_y;
+ constexpr int32_t tail_block_elems = tail_size_y * block_size_x;
+#pragma unroll
+ for (int j = 0; j < num_block_x; j++) {
+ auto acc_reg = matAcc.reg.xetla_select<tail_block_elems, 1>(
+ tail_start_y * tile_size_x + j * tail_block_elems);
+ auto offset_reg = offset_tile.reg.xetla_select<block_size_x, 1>(
+ j * block_size_x);
+ auto scale_reg = scale_tile.reg.xetla_select<block_size_x, 1>(
+ j * block_size_x);
+#pragma unroll
+ for (int row_i = 0; row_i < tail_size_y; row_i++) {
+ acc_reg.xetla_select<block_size_x, 1>(row_i * block_size_x)
+ = scale_reg
+ * acc_reg.xetla_select<block_size_x, 1>(
+ row_i * block_size_x)
+ + offset_reg;
+ }
+ }
+ }
+ }
+};
+
+/// @brief Is MatAcc * vector scale.
+/// @tparam scale_dtype Is the scale data type.
+/// @tparam arch_tag Is the hardware architecture tag.
+template <typename scale_dtype, gpu_arch arch_tag, class enable = void>
+struct scale_v_op_t {};
+/// @brief Is the scale_v op functor, specialized for Xe architecture.
+template <typename scale_dtype_, gpu_arch arch_tag>
+struct scale_v_op_t<scale_dtype_, arch_tag,
+ std::enable_if_t<(arch_tag == gpu_arch::Xe)>> {
+ using scale_dtype = scale_dtype_;
+
+ using scale_mem_desc_t
+ = mem_desc_t<scale_dtype, mem_layout::row_major, mem_space::global>;
+
+ using scale_shape_t = typename scale_mem_desc_t::shape_t;
+ using scale_base_t = typename scale_mem_desc_t::base_t;
+ using coord_t = typename scale_mem_desc_t::coord_t;
+
+ struct arguments_t {
+ scale_base_t scale_base;
+ scale_shape_t scale_shape;
+
+ inline arguments_t() = default;
+ inline arguments_t(scale_base_t scale_base_, scale_shape_t scale_shape_)
+ : scale_base(scale_base_), scale_shape(scale_shape_) {}
+ };
+ template <typename matAcc_t>
+ __XETLA_API KERNEL_FUNC void operator()(matAcc_t &matAcc,
+ const coord_t &coord, const arguments_t &args,
+ uint32_t slm_base = 0, uint32_t nbarrier_base = 0) {
+ using dtype_acc = typename matAcc_t::dtype;
+
+ static constexpr uint32_t tile_size_x = matAcc_t::tile_size_x;
+ static constexpr uint32_t tile_size_y = matAcc_t::tile_size_y;
+ static constexpr uint32_t block_size_x = matAcc_t::block_size_x;
+ static constexpr uint32_t block_size_y = matAcc_t::block_size_y;
+ static constexpr int32_t num_block_x = matAcc_t::num_block_x;
+ static constexpr int32_t num_block_y = matAcc_t::num_block_y;
+ static constexpr uint32_t tile_elems = matAcc_t::tile_elems;
+ static constexpr uint32_t block_elems = matAcc_t::block_elems;
+
+ using scale_tile_desc_t = tile_desc_t<tile_size_x, 1, block_size_x, 1,
+ reg_layout::tiled>;
+ using scale_tile_t = tile_t<scale_dtype, scale_tile_desc_t>;
+ using scale_payload_t
+ = mem_payload_t<scale_mem_desc_t, scale_tile_desc_t,
+ msg_type_v<scale_tile_desc_t, scale_mem_desc_t::space>,
+ arch_tag>;
+ coord_t scale_coord(coord.x, 0);
+ scale_mem_desc_t scale_mem_desc(
+ args.scale_base, args.scale_shape, scale_coord);
+ scale_tile_t scale_tile;
+ scale_payload_t scale_payload(scale_mem_desc);
+ tile_load<cache_hint::cached, cache_hint::cached>(
+ scale_tile, scale_payload);
+
+#pragma unroll
+ for (int i = 0; i < tile_size_y / block_size_y; i++) {
+#pragma unroll
+ for (int j = 0; j < num_block_x; j++) {
+ auto acc_reg = matAcc.reg.xetla_select<block_elems, 1>(
+ (i * num_block_x + j) * block_elems);
+ auto scale_reg = scale_tile.reg.xetla_select<block_size_x, 1>(
+ j * block_size_x);
+#pragma unroll
+ for (int row_i = 0; row_i < block_size_y; row_i++) {
+ acc_reg.xetla_select<block_size_x, 1>(row_i * block_size_x)
+ = scale_reg
+ * acc_reg.xetla_select<block_size_x, 1>(
+ row_i * block_size_x);
+ }
+ }
+ }
+ // process the tail
+ if constexpr ((tile_size_y % block_size_y) != 0) {
+ constexpr uint32_t tail_start_y
+ = tile_size_y / block_size_y * block_size_y;
+ constexpr int32_t tail_size_y = tile_size_y % block_size_y;
+ constexpr int32_t tail_block_elems = tail_size_y * block_size_x;
+#pragma unroll
+ for (int j = 0; j < num_block_x; j++) {
+ auto acc_reg = matAcc.reg.xetla_select<tail_block_elems, 1>(
+ tail_start_y * tile_size_x + j * tail_block_elems);
+ auto scale_reg = scale_tile.reg.xetla_select<block_size_x, 1>(
+ j * block_size_x);
+#pragma unroll
+ for (int row_i = 0; row_i < tail_size_y; row_i++) {
+ acc_reg.xetla_select<block_size_x, 1>(row_i * block_size_x)
+ = scale_reg
+ * acc_reg.xetla_select<block_size_x, 1>(
+ row_i * block_size_x);
+ }
+ }
+ }
+ }
+};
+
+/// @brief Is the element-wise reduce op functor.
+/// Load one buffer from memory and get another from matAcc,
+/// element-wise reduce and update the output in place.
+/// Used in epilogue::tile_op or chained_tile_op.
+/// @tparam reduce_kind Is the reduce type, can be sum, prod, min and max.
+/// @tparam dtype_in Is the memory side buffer data type.
+/// @tparam arch_tag Is the hardware architecture tag.
+template <reduce_op reduce_kind, typename dtype_in, gpu_arch arch_tag,
+ class enable = void>
+struct elemwise_reduce_op_t {};
+/// @brief Is the element-wise reduce op functor, specialized for Xe architecture.
+template <reduce_op reduce_kind_, typename dtype_in_, gpu_arch arch_tag>
+struct elemwise_reduce_op_t<reduce_kind_, dtype_in_, arch_tag,
+ std::enable_if_t<(arch_tag == gpu_arch::Xe)>> {
+ using dtype_in = dtype_in_;
+ using mem_desc_in_t
+ = mem_desc_t<dtype_in, mem_layout::row_major, mem_space::global>;
+ using shape_t = typename mem_desc_in_t::shape_t;
+ using coord_t = typename mem_desc_in_t::coord_t;
+ using base_t = typename mem_desc_in_t::base_t;
+ static constexpr reduce_op reduce_kind = reduce_kind_;
+
+ struct arguments_t {
+ shape_t shape;
+ base_t base;
+ inline arguments_t() = default;
+ inline arguments_t(base_t base_, shape_t shape_)
+ : base(base_), shape(shape_) {}
+ };
+ template <typename matAcc_t>
+ __XETLA_API KERNEL_FUNC void operator()(matAcc_t &matAcc,
+ const coord_t &coord, const arguments_t &args,
+ uint32_t slm_base = 0, uint32_t nbarrier_base = 0) {
+ using dtype_acc = typename matAcc_t::dtype;
+ static constexpr uint32_t tile_size_x = matAcc_t::tile_size_x;
+ static constexpr uint32_t tile_size_y = matAcc_t::tile_size_y;
+ static constexpr uint32_t block_size_x = matAcc_t::block_size_x;
+ static constexpr uint32_t block_size_y = matAcc_t::block_size_y;
+ static constexpr int32_t num_block_x = matAcc_t::num_block_x;
+ static constexpr int32_t num_block_y = matAcc_t::num_block_y;
+ static constexpr uint32_t tile_elems = matAcc_t::tile_elems;
+ static constexpr uint32_t block_elems = matAcc_t::block_elems;
+
+ using mat_in_tile_desc_t = tile_desc_t<tile_size_x, block_size_y,
+ block_size_x, block_size_y, reg_layout::tiled>;
+ using mat_in_tile_t = tile_t<dtype_in, mat_in_tile_desc_t>;
+ using mat_in_payload_t = mem_payload_t<mem_desc_in_t,
+ mat_in_tile_desc_t,
+ msg_type_v<mat_in_tile_desc_t, mem_desc_in_t::space>, arch_tag>;
+ using mat_in_tile_acc_t = tile_t<dtype_acc, mat_in_tile_desc_t>;
+ mem_desc_in_t mem_desc_in(args.base, args.shape, coord);
+ mat_in_tile_t mat_in;
+ mat_in_payload_t mat_in_payload(mem_desc_in);
+ mat_in_tile_acc_t mat_in_acc;
+
+#pragma unroll
+ for (int i = 0; i < tile_size_y / block_size_y; i++) {
+ tile_load<cache_hint::cached, cache_hint::cached>(
+ mat_in, mat_in_payload);
+ elemwise_cvt(mat_in_acc, mat_in);
+#pragma unroll
+ for (int j = 0; j < num_block_x; j++) {
+ auto dst_reg = matAcc.reg.xetla_select<block_elems, 1>(
+ (i * num_block_x + j) * block_elems);
+ auto src_reg = mat_in_acc.reg.xetla_select<block_elems, 1>(
+ j * block_elems);
+ dst_reg = reduce_helper<reduce_kind, dtype_acc, block_elems>(
+ src_reg, dst_reg);
+ }
+ mat_in_payload.template update_tdesc<tdesc_update_dir::y_dir>(
+ block_size_y);
+ }
+ // process the tail
+ if constexpr ((tile_size_y % block_size_y) != 0) {
+ constexpr uint32_t tail_start_y
+ = tile_size_y / block_size_y * block_size_y;
+ constexpr int32_t tail_size_y = tile_size_y % block_size_y;
+ constexpr int32_t tail_block_elems = tail_size_y * block_size_x;
+
+ using mat_tail_in_tile_desc_t = tile_desc_t<tile_size_x,
+ tail_size_y, block_size_x, tail_size_y, reg_layout::tiled>;
+ using mat_tail_in_tile_t
+ = tile_t<dtype_in, mat_tail_in_tile_desc_t>;
+ using mat_tail_in_payload_t = mem_payload_t<mem_desc_in_t,
+ mat_tail_in_tile_desc_t,
+ msg_type_v<mat_tail_in_tile_desc_t, mem_desc_in_t::space>,
+ arch_tag>;
+ using mat_tail_in_tile_acc_t
+ = tile_t<dtype_acc, mat_tail_in_tile_desc_t>;
+ mat_tail_in_tile_t mat_tail_in;
+ mat_tail_in_payload_t mat_tail_in_payload(mem_desc_in);
+ mat_tail_in_tile_acc_t mat_tail_in_acc;
+ mat_tail_in_payload.template update_tdesc<tdesc_update_dir::y_dir>(
+ tail_start_y);
+ tile_load<cache_hint::cached, cache_hint::cached>(
+ mat_tail_in, mat_tail_in_payload);
+ elemwise_cvt(mat_tail_in_acc, mat_tail_in);
+#pragma unroll
+ for (int j = 0; j < num_block_x; j++) {
+ auto dst_reg = matAcc.reg.xetla_select<tail_block_elems, 1>(
+ tail_start_y * tile_size_x + j * tail_block_elems);
+ auto src_reg
+ = mat_tail_in_acc.reg.xetla_select<tail_block_elems, 1>(
+ j * tail_block_elems);
+ dst_reg = reduce_helper<reduce_kind, dtype_acc,
+ tail_block_elems>(src_reg, dst_reg);
+ }
+ }
+ }
+};
+
+/// @brief Is the element-wise reduce op functor, specialized for stream_k dispatch
+///Load partial sum from scratchspace
+///Reduce in GRF
+///Store zero to scratchspace
+///Do these steps with smaller tiles to minimize GRF pressure
+/// @tparam reduce_kind Is the reduce type, can be sum, prod, min and max.
+/// @tparam dtype_in Is the memory side buffer data type.
+/// @tparam arch_tag Is the hardware architecture tag.
+template <reduce_op reduce_kind, typename dtype_in,
+ gpu_arch arch_tag = gpu_arch::Xe, class enable = void>
+struct elemwise_reduce_op_stream_k_t {};
+/// @brief Is the element-wise reduce op functor, specialized for Xe architecture.
+template <reduce_op reduce_kind_, typename dtype_in_, gpu_arch arch_tag>
+struct elemwise_reduce_op_stream_k_t<reduce_kind_, dtype_in_, arch_tag,
+ std::enable_if_t<(arch_tag == gpu_arch::Xe)>> {
+ using dtype_in = dtype_in_;
+ using mem_desc_in_t
+ = mem_desc_t<dtype_in, mem_layout::row_major, mem_space::global>;
+ using shape_t = typename mem_desc_in_t::shape_t;
+ using coord_t = typename mem_desc_in_t::coord_t;
+ using base_t = typename mem_desc_in_t::base_t;
+ static constexpr reduce_op reduce_kind = reduce_kind_;
+
+ struct arguments_t {
+ shape_t shape;
+ base_t base;
+ inline arguments_t() = default;
+ inline arguments_t(base_t base_, shape_t shape_)
+ : base(base_), shape(shape_) {}
+ };
+ template <typename matAcc_t>
+ __XETLA_API KERNEL_FUNC void operator()(matAcc_t &matAcc,
+ const coord_t &coord, const arguments_t &args,
+ uint32_t slm_base = 0, uint32_t nbarrier_base = 0) {
+ using dtype_acc = typename matAcc_t::dtype;
+ static constexpr uint32_t tile_size_x = matAcc_t::tile_size_x;
+ static constexpr uint32_t tile_size_y = matAcc_t::tile_size_y;
+ static constexpr uint32_t block_size_x = matAcc_t::block_size_x;
+ static constexpr uint32_t block_size_y = matAcc_t::block_size_y;
+ static constexpr int32_t num_block_x = matAcc_t::num_block_x;
+ static constexpr int32_t num_block_y = matAcc_t::num_block_y;
+ static constexpr uint32_t tile_elems = matAcc_t::tile_elems;
+ static constexpr uint32_t block_elems = matAcc_t::block_elems;
+
+ using mat_in_tile_desc_t = tile_desc_t<block_size_x, block_size_y,
+ block_size_x, block_size_y, reg_layout::tiled>;
+ using mat_in_tile_t = tile_t<dtype_in, mat_in_tile_desc_t>;
+ using mat_in_payload_t = mem_payload_t<mem_desc_in_t,
+ mat_in_tile_desc_t,
+ msg_type_v<mat_in_tile_desc_t, mem_desc_in_t::space>, arch_tag>;
+ mem_desc_in_t mem_desc_in(args.base, args.shape, coord);
+ mat_in_tile_t mat_in;
+ mat_in_tile_t mat_zero(0);
+ mat_in_payload_t mat_in_payload(mem_desc_in);
+
+#pragma unroll
+ for (int i = 0; i < tile_size_y / block_size_y; i++) {
+#pragma unroll
+ for (int j = 0; j < num_block_x; j++) {
+
+ tile_load<cache_hint::cached, cache_hint::cached>(
+ mat_in, mat_in_payload);
+ auto dst_reg = matAcc.reg.xetla_select<block_elems, 1>(
+ (i * num_block_x + j) * block_elems);
+
+ auto src_reg = mat_in.reg;
+ dst_reg = reduce_helper<reduce_kind, dtype_acc, block_elems>(
+ src_reg, dst_reg);
+
+ subgroup::tile_store<cache_hint::uncached,
+ cache_hint::write_back>(mat_zero, mat_in_payload);
+ mat_in_payload.template update_tdesc<tdesc_update_dir::x_dir>(
+ block_size_x);
+ }
+ mat_in_payload.template update_tdesc<tdesc_update_dir::x_dir>(
+ -num_block_x * block_size_x);
+ mat_in_payload.template update_tdesc<tdesc_update_dir::y_dir>(
+ block_size_y);
+ }
+ // process the tail
+ if constexpr ((tile_size_y % block_size_y) != 0) {
+ constexpr uint32_t tail_start_y
+ = tile_size_y / block_size_y * block_size_y;
+ constexpr int32_t tail_size_y = tile_size_y % block_size_y;
+ constexpr int32_t tail_block_elems = tail_size_y * block_size_x;
+#pragma unroll
+ for (int j = 0; j < num_block_x; j++) {
+
+ tile_load<cache_hint::cached, cache_hint::cached>(
+ mat_in, mat_in_payload);
+ auto dst_reg = matAcc.reg.xetla_select<tail_block_elems, 1>(
+ tail_start_y * tile_size_x + j * tail_block_elems);
+ auto src_reg = mat_in.reg.xetla_select<tail_block_elems, 1>(
+ tail_start_y * tile_size_x + j * tail_block_elems);
+ dst_reg = reduce_helper<reduce_kind, dtype_acc,
+ tail_block_elems>(src_reg, dst_reg);
+
+ subgroup::tile_store<cache_hint::uncached,
+ cache_hint::write_back>(mat_zero, mat_in_payload);
+
+ mat_in_payload.template update_tdesc<tdesc_update_dir::x_dir>(
+ block_size_x);
+ }
+ }
+ }
+};
+
+/// @brief Is the dropout op functor.
+/// Load the mask from memory and get input from matAcc,
+/// do the scaling and zero out, update the output in place.
+/// The mask has the same layout as the output.
+/// Used in epilogue::tile_op or chained_tile_op.
+/// @tparam dtype_mask Is the mask data type.
+/// @tparam arch_tag Is the hardware architecture tag.
+template <typename dtype_mask, gpu_arch arch_tag, class enable = void>
+struct dropout_op_t {};
+/// @brief Is the dropout op functor, specialized for Xe architecture.
+template <typename dtype_mask_, gpu_arch arch_tag>
+struct dropout_op_t<dtype_mask_, arch_tag,
+ std::enable_if_t<(arch_tag == gpu_arch::Xe)>> {
+ using dtype_mask = dtype_mask_;
+ using mem_desc_mask_t
+ = mem_desc_t<dtype_mask, mem_layout::row_major, mem_space::global>;
+ using shape_t = typename mem_desc_mask_t::shape_t;
+ using coord_t = typename mem_desc_mask_t::coord_t;
+ using base_t = typename mem_desc_mask_t::base_t;
+ static constexpr uint32_t num_flag = 4;
+ static constexpr uint32_t unroll_size = num_flag * 16;
+ struct arguments_t {
+ shape_t shape;
+ base_t base;
+ float prob;
+ float scale;
+ inline arguments_t() = default;
+ inline arguments_t(
+ base_t base_, shape_t shape_, float prob_, float scale_)
+ : base(base_), shape(shape_), prob(prob_), scale(scale_) {}
+ };
+
+ template <typename matAcc_t>
+ __XETLA_API KERNEL_FUNC void operator()(matAcc_t &matAcc,
+ const coord_t &coord, const arguments_t &args,
+ uint32_t slm_base = 0, uint32_t nbarrier_base = 0) {
+ using dtype_acc = typename matAcc_t::dtype;
+ static constexpr uint32_t tile_size_x = matAcc_t::tile_size_x;
+ static constexpr uint32_t tile_size_y = matAcc_t::tile_size_y;
+ static constexpr uint32_t block_size_x = matAcc_t::block_size_x;
+ static constexpr uint32_t block_size_y = matAcc_t::block_size_y;
+ static constexpr int32_t num_block_x = matAcc_t::num_block_x;
+ static constexpr int32_t num_block_y = matAcc_t::num_block_y;
+ static constexpr uint32_t tile_elems = matAcc_t::tile_elems;
+ static constexpr uint32_t block_elems = matAcc_t::block_elems;
+ if (args.prob == 0) { return; }
+ using mask_in_tile_desc_t = tile_desc_t<tile_size_x, tile_size_y,
+ block_size_x, block_size_y, reg_layout::tiled>;
+ using mask_in_tile_t = tile_t<dtype_mask, mask_in_tile_desc_t>;
+ using mask_in_payload_t
+ = mem_payload_t<mem_desc_mask_t, mask_in_tile_desc_t,
+ msg_type_v<mask_in_tile_desc_t, mem_desc_mask_t::space>,
+ arch_tag>;
+ mem_desc_mask_t mem_desc_mask(args.base, args.shape, coord);
+ mask_in_tile_t mask_in;
+ mask_in_payload_t mask_in_payload(mem_desc_mask);
+ tile_load<cache_hint::cached, cache_hint::cached>(
+ mask_in, mask_in_payload);
+ if constexpr (tile_elems / unroll_size != 0) {
+#pragma unroll
+ for (int i = 0; i < tile_elems / unroll_size; i++) {
+ xetla_mask<unroll_size> mask_flag
+ = mask_in.reg.xetla_select<unroll_size, 1>(
+ i * unroll_size)
+ > 0;
+ auto dst_reg = matAcc.reg.xetla_select<unroll_size, 1>(
+ i * unroll_size);
+ dst_reg *= args.scale;
+ dst_reg.xetla_merge(0, mask_flag);
+ }
+ }
+ if constexpr (tile_elems % unroll_size != 0) {
+ constexpr uint32_t remain_len = tile_elems % unroll_size;
+ constexpr uint32_t remain_start
+ = tile_elems / unroll_size * unroll_size;
+ xetla_mask<remain_len> mask_flag
+ = mask_in.reg.xetla_select<remain_len, 1>(remain_start) > 0;
+ auto dst_reg = matAcc.reg.xetla_select<remain_len, 1>(remain_start);
+ dst_reg *= args.scale;
+ dst_reg.xetla_merge(0, mask_flag);
+ }
+ }
+};
+
+/// @brief Is the random number generator and dropout op functor.
+/// Generate the mask data and get input from matAcc, do the scaling and zero out,
+/// update the output in place, dump the mask buffer to memory.
+/// The mask has the same layout as the output.
+/// Used in epilogue::tile_op or chained_tile_op.
+/// @tparam dtype_mask Is the mask data type.
+/// @tparam arch_tag Is the hardware architecture tag.
+template <typename dtype_mask, gpu_arch arch_tag, class enable = void>
+struct rng_dropout_op_t {};
+/// @brief Is the random number generator and dropout op functor, specialized for Xe architecture.
+template <typename dtype_mask_, gpu_arch arch_tag>
+struct rng_dropout_op_t<dtype_mask_, arch_tag,
+ std::enable_if_t<(arch_tag == gpu_arch::Xe)>> {
+ using dtype_mask = dtype_mask_;
+ using mem_desc_mask_t
+ = mem_desc_t<dtype_mask, mem_layout::row_major, mem_space::global>;
+ using shape_t = typename mem_desc_mask_t::shape_t;
+ using coord_t = typename mem_desc_mask_t::coord_t;
+ using base_t = typename mem_desc_mask_t::base_t;
+ static constexpr uint32_t random_simd = 16;
+ static constexpr uint32_t random_len = 4 * random_simd;
+ xetla_rand_t<random_simd> rand_gen;
+
+ struct arguments_t {
+ shape_t mask_shape;
+ base_t mask_base;
+ uint64_t *rand_offset_ptr;
+ float prob;
+ uint64_t rand_seed;
+
+ inline arguments_t() = default;
+ inline arguments_t(base_t mask_base_, shape_t mask_shape_, float prob_,
+ uint64_t *rand_offset_ptr_,
+ uint64_t rand_seed_ = 67280421310721)
+ : mask_base(mask_base_)
+ , mask_shape(mask_shape_)
+ , prob(prob_)
+ , rand_offset_ptr(rand_offset_ptr_)
+ , rand_seed(rand_seed_) {}
+ };
+
+ template <typename matAcc_t>
+ __XETLA_API KERNEL_FUNC void operator()(matAcc_t &matAcc,
+ const coord_t &coord, const arguments_t &args,
+ uint32_t slm_base = 0, uint32_t nbarrier_base = 0) {
+ using dtype_acc = typename matAcc_t::dtype;
+ static constexpr uint32_t tile_size_x = matAcc_t::tile_size_x;
+ static constexpr uint32_t tile_size_y = matAcc_t::tile_size_y;
+ static constexpr uint32_t block_size_x = matAcc_t::block_size_x;
+ static constexpr uint32_t block_size_y = matAcc_t::block_size_y;
+ static constexpr int32_t num_block_x = matAcc_t::num_block_x;
+ static constexpr int32_t num_block_y = matAcc_t::num_block_y;
+ static constexpr uint32_t tile_elems = matAcc_t::tile_elems;
+ static constexpr uint32_t block_elems = matAcc_t::block_elems;
+
+ using mask_out_tile_desc_t = tile_desc_t<tile_size_x, tile_size_y,
+ block_size_x, block_size_y, reg_layout::tiled>;
+ using mask_out_tile_t = tile_t<dtype_mask, mask_out_tile_desc_t>;
+ using mask_out_payload_t = mem_payload_t<mem_desc_mask_t,
+ mask_out_tile_desc_t,
+ msg_type_v<mask_out_tile_desc_t, mem_desc_mask_t::space>,
+ arch_tag>;
+ if (args.prob == 0) { return; }
+ //calculate the scale internally
+ float scale = 1.f / (1.f - args.prob);
+ uint32_t threshold = uint32_t(args.prob * float(4294967296));
+ xetla_vector<uint64_t, 1> rand_offset_v
+ = xetla_load_global<uint64_t, 1, data_size::default_size,
+ cache_hint::cached, cache_hint::cached>(
+ args.rand_offset_ptr, 0);
+ uint64_t rand_offset = rand_offset_v[0];
+ uint64_t rand_subseq = uint64_t(coord.y) << 32 | uint64_t(coord.x);
+ rand_gen.init(args.rand_seed, rand_subseq, rand_offset);
+
+ mem_desc_mask_t mem_desc_mask(args.mask_base, args.mask_shape, coord);
+ mask_out_tile_t mask_out;
+ mask_out_payload_t mask_out_payload(mem_desc_mask);
+ if constexpr (tile_elems / random_len != 0) {
+#pragma unroll
+ for (int i = 0; i < tile_elems / random_len; i++) {
+ auto out_sub = matAcc.reg.xetla_select<random_len, 1>(
+ i * random_len);
+ auto mask_sub = mask_out.reg.xetla_select<random_len, 1>(
+ i * random_len);
+ xetla_vector<uint32_t, random_len> rand_val = rand_gen.rand();
+ xetla_mask<random_len> mask_flag = rand_val < threshold;
+ out_sub *= scale;
+ out_sub.xetla_merge(0, mask_flag);
+ mask_sub.xetla_merge(1, 0, mask_flag);
+ }
+ }
+ if constexpr (tile_elems % random_len != 0) {
+ constexpr uint32_t remain_len = tile_elems % random_len;
+ constexpr uint32_t remain_start
+ = tile_elems / random_len * random_len;
+ auto out_sub = matAcc.reg.xetla_select<remain_len, 1>(remain_start);
+ auto mask_sub
+ = mask_out.reg.xetla_select<remain_len, 1>(remain_start);
+ // dropout, still generate random_len
+ xetla_vector<uint32_t, random_len> rand_val = rand_gen.rand();
+ xetla_mask<random_len> mask_flag = rand_val < threshold;
+ out_sub *= scale;
+ out_sub.xetla_merge(0, mask_flag.xetla_select<remain_len, 1>(0));
+ mask_sub.xetla_merge(
+ 1, 0, mask_flag.xetla_select<remain_len, 1>(0));
+ }
+ tile_store<cache_hint::streaming>(mask_out, mask_out_payload);
+ }
+};
+
+/// @brief Is the scalar_multiply op functor.
+/// Get the input from matAcc, multiply with a scalar, update the output in place.
+/// Used in epilogue::tile_op or chained_tile_op.
+/// @tparam dtype_in Is the data type of multiplier buffer.
+/// @tparam arch_tag Is the hardware architecture tag.
+template <typename dtype_in, gpu_arch arch_tag, class enable = void>
+struct scalar_mul_op_t {};
+/// @brief Is the scalar_multiply op functor, specialized for Xe architecture.
+template <typename dtype_in_, gpu_arch arch_tag>
+struct scalar_mul_op_t<dtype_in_, arch_tag,
+ std::enable_if_t<(arch_tag == gpu_arch::Xe)>> {
+ using dtype_in = dtype_in_;
+ using mem_desc_in_t
+ = mem_desc_t<dtype_in, mem_layout::row_major, mem_space::global>;
+ using coord_t = typename mem_desc_in_t::coord_t;
+
+ struct arguments_t {
+ dtype_in multiplier;
+ inline arguments_t() = default;
+ inline arguments_t(dtype_in multiplier_) : multiplier(multiplier_) {}
+ };
+
+ template <typename matAcc_t>
+ __XETLA_API KERNEL_FUNC void operator()(matAcc_t &matAcc, coord_t coord,
+ arguments_t args, uint32_t slm_base = 0,
+ uint32_t nbarrier_base = 0) {
+ using dtype_acc = typename matAcc_t::dtype;
+ static_assert(std::is_same<dtype_in, dtype_acc>::value,
+ "Given multiplier must have same type as matAcc!");
+ matAcc.reg *= args.multiplier;
+ }
+};
+
+/// @brief Is the linear_op functor.
+/// Multiply matAcc with a scalar, then add a bias, update the output in place.
+/// Used in epilogue::tile_op or chained_tile_op.
+/// @tparam dtype_in Is the data type of multiplier buffer.
+/// @tparam arch_tag Is the hardware architecture tag.
+template <typename dtype_in, gpu_arch arch_tag, class enable = void>
+struct linear_op_t {};
+/// @brief Is the linear_op functor, specialized for Xe architecture.
+template <typename dtype_in_, gpu_arch arch_tag>
+struct linear_op_t<dtype_in_, arch_tag,
+ std::enable_if_t<(arch_tag == gpu_arch::Xe)>> {
+ using dtype_in = dtype_in_;
+ using mem_desc_in_t
+ = mem_desc_t<dtype_in, mem_layout::row_major, mem_space::global>;
+ using shape_t = typename mem_desc_in_t::shape_t;
+ using coord_t = typename mem_desc_in_t::coord_t;
+ using base_t = typename mem_desc_in_t::base_t;
+
+ struct arguments_t {
+ shape_t shape;
+ base_t base;
+ dtype_in alpha;
+ dtype_in beta;
+ inline arguments_t() = default;
+ inline arguments_t(
+ base_t base_, shape_t shape_, dtype_in alpha_, dtype_in beta_)
+ : base(base_), shape(shape_), alpha(alpha_), beta(beta_) {}
+ };
+
+ template <typename matAcc_t>
+ __XETLA_API KERNEL_FUNC void operator()(matAcc_t &matAcc,
+ const coord_t &coord, const arguments_t &args,
+ uint32_t slm_base = 0, uint32_t nbarrier_base = 0) {
+ using dtype_acc = typename matAcc_t::dtype;
+ static constexpr uint32_t tile_size_x = matAcc_t::tile_size_x;
+ static constexpr uint32_t tile_size_y = matAcc_t::tile_size_y;
+ static constexpr uint32_t block_size_x = matAcc_t::block_size_x;
+ static constexpr uint32_t block_size_y = matAcc_t::block_size_y;
+ static constexpr uint32_t num_block_x = matAcc_t::num_block_x;
+ static constexpr uint32_t num_block_y = matAcc_t::num_block_y;
+ static constexpr uint32_t tile_elems = matAcc_t::tile_elems;
+ static constexpr uint32_t block_elems = matAcc_t::block_elems;
+ static constexpr uint32_t remained_size_y = tile_size_y % block_size_y;
+
+ using mat_in_tile_desc_t = tile_desc_t<tile_size_x, block_size_y,
+ block_size_x, block_size_y, reg_layout::tiled>;
+ using mat_in_tile_t = tile_t<dtype_in, mat_in_tile_desc_t>;
+ using mat_in_payload_t = mem_payload_t<mem_desc_in_t,
+ mat_in_tile_desc_t,
+ msg_type_v<mat_in_tile_desc_t, mem_desc_in_t::space>, arch_tag>;
+ using mat_in_tile_acc_t = tile_t<dtype_acc, mat_in_tile_desc_t>;
+ mem_desc_in_t mem_desc_in(args.base, args.shape, coord);
+ mat_in_tile_t mat_in;
+ mat_in_payload_t mat_in_payload(mem_desc_in);
+ mat_in_tile_acc_t mat_in_acc;
+
+ dtype_acc alpha = dtype_acc(args.alpha);
+ dtype_acc beta = dtype_acc(args.beta);
+ matAcc.reg *= alpha;
+
+#pragma unroll
+ for (uint32_t i = 0; i < num_block_y; ++i) {
+ tile_load<cache_hint::cached, cache_hint::cached>(
+ mat_in, mat_in_payload);
+ elemwise_cvt(mat_in_acc, mat_in);
+ mat_in_acc.reg *= beta;
+#pragma unroll
+ for (uint32_t j = 0; j < num_block_x; ++j) {
+ auto dst_reg = matAcc.reg.xetla_select<block_elems, 1>(
+ (i * num_block_x + j) * block_elems);
+ auto src_reg = mat_in_acc.reg.xetla_select<block_elems, 1>(
+ j * block_elems);
+ dst_reg = reduce_helper<reduce_op::sum, dtype_acc, block_elems>(
+ src_reg, dst_reg);
+ }
+ mat_in_payload.template update_tdesc<tdesc_update_dir::y_dir>(
+ block_size_y);
+ }
+ // process the tail
+ if constexpr (remained_size_y > 0) {
+ constexpr uint32_t tail_start_y = num_block_y * block_size_y;
+ constexpr uint32_t tail_block_elems
+ = remained_size_y * block_size_x;
+
+ using mat_tail_in_tile_desc_t
+ = tile_desc_t<tile_size_x, remained_size_y, block_size_x,
+ remained_size_y, reg_layout::tiled>;
+ using mat_tail_in_tile_t
+ = tile_t<dtype_in, mat_tail_in_tile_desc_t>;
+ using mat_tail_in_payload_t = mem_payload_t<mem_desc_in_t,
+ mat_tail_in_tile_desc_t,
+ msg_type_v<mat_tail_in_tile_desc_t, mem_desc_in_t::space>,
+ arch_tag>;
+ using mat_tail_in_tile_acc_t
+ = tile_t<dtype_acc, mat_tail_in_tile_desc_t>;
+
+ mat_tail_in_tile_t mat_tail_in;
+ mat_tail_in_payload_t mat_tail_in_payload(mem_desc_in);
+ mat_tail_in_tile_acc_t mat_tail_in_acc;
+ mat_tail_in_payload.template update_tdesc<tdesc_update_dir::y_dir>(
+ tail_start_y);
+ tile_load<cache_hint::cached, cache_hint::cached>(
+ mat_tail_in, mat_tail_in_payload);
+ elemwise_cvt(mat_tail_in_acc, mat_tail_in);
+ mat_tail_in_acc.reg *= beta;
+#pragma unroll
+ for (int j = 0; j < num_block_x; ++j) {
+ auto dst_reg = matAcc.reg.xetla_select<tail_block_elems, 1>(
+ tail_start_y * tile_size_x + j * tail_block_elems);
+ auto src_reg
+ = mat_tail_in_acc.reg.xetla_select<tail_block_elems, 1>(
+ j * tail_block_elems);
+ dst_reg = reduce_helper<reduce_op::sum, dtype_acc,
+ tail_block_elems>(src_reg, dst_reg);
+ }
+ }
+ }
+};
+
+} // namespace gpu::xetla::subgroup
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/subgroup/tile/tile.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/subgroup/tile/tile.hpp
new file mode 100644
index 00000000000..3cc22c3e938
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/subgroup/tile/tile.hpp
@@ -0,0 +1,33 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+
+#include "subgroup/tile/api.hpp"
+#include "subgroup/tile/chained_tile_op.hpp"
+#include "subgroup/tile/common.hpp"
+#include "subgroup/tile/impl/fma_xe.hpp"
+#include "subgroup/tile/impl/load_xe.hpp"
+#include "subgroup/tile/impl/mma_xe.hpp"
+#include "subgroup/tile/impl/op_function.hpp"
+#include "subgroup/tile/impl/payload_xe.hpp"
+#include "subgroup/tile/impl/prefetch_xe.hpp"
+#include "subgroup/tile/impl/reduction.hpp"
+#include "subgroup/tile/impl/store_xe.hpp"
+#include "subgroup/tile/impl/tile_op_functor.hpp"
diff --git a/src/plugins/intel_gpu/thirdparty/xetla/include/xetla.hpp b/src/plugins/intel_gpu/thirdparty/xetla/include/xetla.hpp
new file mode 100644
index 00000000000..86bf1ee00bb
--- /dev/null
+++ b/src/plugins/intel_gpu/thirdparty/xetla/include/xetla.hpp
@@ -0,0 +1,28 @@
+/*******************************************************************************
+* Copyright (c) 2022-2023 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.
+*******************************************************************************/
+
+/// @file
+/// C++ API
+
+#pragma once
+//Order of includes changed for windows build, otherwise file paths are resolved incorrectly
+
+// clang-format off
+#include "common/common.hpp"
+#include "group/group.hpp"
+#include "kernel/kernel.hpp"
+#include "subgroup/subgroup.hpp"
+// clang-format on