Skip to content

Commit 37fba13

Browse files
shiyi9801akladiev
andauthored
Fix 1D transpose test case (#31842)
### Details: 1D transpose will run into the case of `jcp.n = 0`. When `jcp.n = 0` it should not directly fall through to `jcp.n = 1`, since for `jcp.ndims <= 1`, `parallel_for dst_dims[0]` will generate `dst_dims[0]` threads to access the same piece of memory at the same time, and will access out-of-bounds memory, which may lead into heap corruption. So in this case, a single thread should be enough. ### Tickets: - *172344* --------- Co-authored-by: Alina Kladieva <[email protected]>
1 parent 10a39aa commit 37fba13

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

src/plugins/intel_cpu/src/nodes/common/permute_kernel.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -231,15 +231,24 @@ void PermuteKernel::optimizedExecute(const uint8_t* src_data, const uint8_t* dst
231231

232232
switch (jcp.n) {
233233
case 0:
234-
// This is a degenerate case that is only possible if the tensor has 0 or 1st rank
235-
// Such a situation is possible in the following graph:
236-
// Parameter
237-
// |
238-
// Transpose
239-
// |
240-
// Result
241-
// The elimination of the Transpose node will not be performed
242-
// So copy from input buffer to output buffer without any permutation
234+
// This is a degenerate case that is only possible if the tensor has 0 or 1st rank
235+
// Such a situation is possible in the following graph:
236+
// Parameter
237+
// |
238+
// Transpose
239+
// |
240+
// Result
241+
// The elimination of the Transpose node will not be performed
242+
// So copy from input buffer to output buffer without any permutation
243+
{
244+
auto arg = jit_args_permute();
245+
246+
arg.src = src_data;
247+
arg.dst = dst_data;
248+
249+
(*permute_kernel)(&arg);
250+
}
251+
break;
243252
case 1:
244253
parallel_for(dst_dims[0], [&](int i0) {
245254
auto arg = jit_args_permute();

src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/instances/x64/transpose.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,25 @@ INSTANTIATE_TEST_SUITE_P(smoke_dynamicShapes5D_PermutePerChannels, TransposeLaye
173173
::testing::Values(additional_config),
174174
::testing::Values(CPUSpecificParams{})),
175175
TransposeLayerCPUTest::getTestCaseName);
176+
177+
const std::vector<InputShape> staticInputShapes1D = {InputShape{
178+
// dynamic
179+
{-1},
180+
// Static shapes
181+
{{24}}}
182+
};
183+
184+
const std::vector<std::vector<size_t>> inputOrder1D = {std::vector<size_t>{0}};
185+
186+
INSTANTIATE_TEST_SUITE_P(smoke_staticShapes1D_Transpose, TransposeLayerCPUTest,
187+
::testing::Combine(
188+
::testing::ValuesIn(staticInputShapes1D),
189+
::testing::ValuesIn(inputOrder1D),
190+
::testing::Values(ov::element::f32),
191+
::testing::Values(ov::test::utils::DEVICE_CPU),
192+
::testing::Values(additional_config),
193+
::testing::Values(CPUSpecificParams{})),
194+
TransposeLayerCPUTest::getTestCaseName);
176195
} // namespace
177196
} // namespace Transpose
178197
} // namespace test

0 commit comments

Comments
 (0)