Skip to content

Commit 7d0f6e9

Browse files
Utilize padded info transposed by input_order for dynamic padding
1 parent 4a2ef81 commit 7d0f6e9

File tree

3 files changed

+11
-21
lines changed

3 files changed

+11
-21
lines changed

src/plugins/intel_gpu/src/kernel_selector/cl_kernels/gemm_tiled_opt.cl

+2-2
Original file line numberDiff line numberDiff line change
@@ -200,14 +200,14 @@ KERNEL(gemm_tiled_opt)(
200200
#endif // TRANSPOSE_INPUT0
201201
#if TRANSPOSE_INPUT1 == TRANSPOSE_X_LAST
202202
const __global INPUT1_TYPE* b_ptr = input1 + batch_offset_input1;
203-
#if HAS_DYNAMIC_N_PADDING || INPUT1_HAS_PADDING
203+
#if HAS_DYNAMIC_K_PADDING || INPUT1_HAS_PADDING
204204
const uint input1_offset = FUNC_CALL(get_input1_index)(OPTIONAL_SHAPE_INFO_TENSOR b, f, w, z, 1, tile_n_offset) - batch_offset_input1;
205205
#else
206206
const uint input1_offset = FUNC_CALL(get_input1_index)(OPTIONAL_SHAPE_INFO_TENSOR 0, 0, 0, 0, 1, 0);
207207
#endif
208208
#elif TRANSPOSE_INPUT1 == TRANSPOSE_Y_LAST
209209
const __global INPUT1_TYPE* b_ptr = input1 + batch_offset_input1;
210-
#if HAS_DYNAMIC_N_PADDING || INPUT1_HAS_PADDING
210+
#if HAS_DYNAMIC_K_PADDING || INPUT1_HAS_PADDING
211211
const uint input1_offset = FUNC_CALL(get_input1_index)(OPTIONAL_SHAPE_INFO_TENSOR b, f, w, z, 0, (tile_n_offset + 1)) - batch_offset_input1;
212212
const uint input1_offset1 = FUNC_CALL(get_input1_index)(OPTIONAL_SHAPE_INFO_TENSOR b, f, w, z, (TILE_K), tile_n_offset) - batch_offset_input1;
213213
#else

src/plugins/intel_gpu/src/kernel_selector/kernel_selector_utils.h

+7
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ struct DimensionAccessHelperJit : virtual DimensionAccessHelperBase {
5353
pad_before_after_sizes.push_back(toCodeString(d.pad.before));
5454
pad_before_after_sizes.push_back(toCodeString(d.pad.after));
5555
}
56+
57+
if (d.pad.is_dynamic || d.is_dynamic) {
58+
dims_padded.push_back(true);
59+
} else {
60+
dims_padded.push_back(false);
61+
}
5662
}
5763
}
5864
}
@@ -76,6 +82,7 @@ struct DimensionAccessHelperJit : virtual DimensionAccessHelperBase {
7682

7783
std::vector<std::string> dims_sizes;
7884
std::vector<std::string> pad_before_after_sizes;
85+
std::vector<bool> dims_padded;
7986
};
8087

8188
std::vector<size_t> GetImageSizes(const kernel_selector::WeightsTensor& dimensions, const WeightsLayout layout);

src/plugins/intel_gpu/src/kernel_selector/kernels/gemm/gemm_kernel_tiled_opt.cpp

+2-19
Original file line numberDiff line numberDiff line change
@@ -205,27 +205,10 @@ JitConstants GemmKernelTiledOpt::GetJitConstants(const gemm_params& params) cons
205205
else
206206
jit.AddConstant(MakeJitConstant("TRANSPOSE_OUTPUT", 0 /* set as TRANSPOSE_X_LAST */));
207207

208-
bool has_dynamic_k_padding = params.transpose_input0 ? params.inputs[0].Y().pad.is_dynamic
209-
: params.inputs[0].X().pad.is_dynamic;
210-
bool has_dynamic_n_padding = params.transpose_input1 ? params.inputs[1].Y().pad.is_dynamic
211-
: params.inputs[1].X().pad.is_dynamic;
208+
bool has_dynamic_k_padding = params.transpose_input0 ? dims0_padded.dims_padded[input0_dims[6]]
209+
: dims0_padded.dims_padded[input0_dims[7]];
212210
if (has_dynamic_k_padding)
213211
jit.AddConstant(MakeJitConstant("HAS_DYNAMIC_K_PADDING", 1));
214-
if (has_dynamic_n_padding)
215-
jit.AddConstant(MakeJitConstant("HAS_DYNAMIC_N_PADDING", 1));
216-
217-
auto hasDynamicPad = [](DataTensor dt) -> bool {
218-
auto dims = dt.GetDims();
219-
for (auto d : dims) {
220-
if (d.pad.is_dynamic)
221-
return true;
222-
}
223-
return false;
224-
};
225-
if (hasDynamicPad(params.inputs[0]))
226-
jit.AddConstant(MakeJitConstant("INPUT0_HAS_PADDING", 1));
227-
if (hasDynamicPad(params.inputs[1]))
228-
jit.AddConstant(MakeJitConstant("INPUT1_HAS_PADDING", 1));
229212
} else {
230213
auto get_transposed_dim_size = [](const kernel_selector::DataTensor &data_tensor,
231214
const std::vector<int64_t>& dims_order, const std::string dim) {

0 commit comments

Comments
 (0)