Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7a51796

Browse files
committedFeb 7, 2025·
fixed review comments
1 parent bf2f81e commit 7a51796

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed
 

‎src/plugins/intel_cpu/src/nodes/common/cpu_convert.cpp

+9-7
Original file line numberDiff line numberDiff line change
@@ -918,16 +918,18 @@ struct ConvertTo4BitPrecision<std::tuple<src_t, dst_t>> {
918918
auto src = static_cast<const src_t*>(ctx.srcPtr);
919919
auto dst = static_cast<uint8_t*>(ctx.dstPtr);
920920
// each byte must be fully processed within same thread
921-
auto work_amount = div_up(ctx.size, 2);
921+
auto work_amount = ctx.size / 2;
922+
auto has_tail = ctx.size % work_amount != 0;
922923
if (ctx.outType == ov::element::nf4) {
923924
parallel_for(work_amount, [&](size_t ib) {
924-
for (int i = 0; i < 2; i++) {
925-
int idx = ib * 2 + i;
926-
uint8_t val = idx % 2 == 0 ? 0 : dst[idx / 2];
927-
val = insert_half_byte(val, ConvertNF4::quantize(static_cast<float>(src[idx])), idx % 2);
928-
dst[idx / 2] = val;
929-
}
925+
size_t idx = ib*2;
926+
const auto val = insert_half_byte(0, ConvertNF4::quantize(static_cast<float>(src[idx])), false);
927+
dst[ib] = insert_half_byte(val, ConvertNF4::quantize(static_cast<float>(src[idx+1])), true);
930928
});
929+
930+
if (has_tail) {
931+
dst[work_amount] = insert_half_byte(0, ConvertNF4::quantize(static_cast<float>(src[2*work_amount])), false);
932+
}
931933
} else {
932934
OPENVINO_THROW("cpu_convert doesn't support output data type: ", ctx.outType, ". Not implemented.");
933935
}

‎src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/classes/conversion.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,9 @@ const std::vector<InputShape>& inShapes_4D_dynamic() {
312312
{
313313
{2, 4, 4, 1},
314314
{2, 17, 5, 4},
315-
{1, 2, 3, 4}
315+
{1, 2, 3, 4},
316+
// odd number of elements
317+
{1, 3, 3, 3}
316318
}
317319
},
318320
{

0 commit comments

Comments
 (0)