Commit 2b7d228
authored
[OV CPU] Convert Node converting integer to unsigned one, it did clamp (#32389)
As Convert Op's [Specification
](https://docs.openvino.ai/2025/documentation/openvino-ir-format/operation-sets/operation-specs/type/convert-1.html)
said.
> Conversion of negative signed integer to unsigned integer value
happens in accordance with c++ standard. Notably, result is the unique
value of the destination unsigned type that is congruent to the source
integer modulo 2^N (where N is the bit width of the destination type).
**For example, when an int32 value -1 is converted to uint32 the result
will be uint32 max which is 4,294,967,295.**
### Reproduce:
Test when int32 value -1 convert to uint8
- OV GPU/NPU, got 255 (match the spec)
- OV CPU, it uses the boundary to clamp, got 0, not 255 (did't match the
spec)
```
import openvino as ov
import numpy as np
input_data = np.full((2, 2), -1, dtype=np.int32)
expected_output_data = np.full((2, 2), 2**8 - 1, dtype=np.uint8)
input_param = ov.op.Parameter(ov.runtime.Type.i32, ov.Shape([2, 2]))
convert_op = ov.opset1.convert(input_param, destination_type=ov.runtime.Type.u8)
model = ov.Model(results=[convert_op], parameters=[input_param], name="int32_to_uint8_convert")
core = ov.Core()
compiled_model = core.compile_model(model, "CPU")
results = compiled_model(input_data)
actual_output_data = results[compiled_model.outputs[0]]
try:
print("--- Verification ---")
np.testing.assert_array_equal(actual_output_data, expected_output_data)
print("SUCCESS: Actual output matches expected output.")
except AssertionError as e:
print(f"FAILED: Output mismatch!\n{e}")
```
```
--- Verification ---
FAILED: Output mismatch!
Arrays are not equal
...
ACTUAL: array([[0, 0],[0, 0]], dtype=uint8)
DESIRED: array([[255, 255],[255, 255]], dtype=uint8)
```
### Tickets:
- *CVS-172796*1 parent 4c4f1f2 commit 2b7d228
File tree
8 files changed
+42
-10
lines changed- src
- frontends/onnx/tests
- tests_python
- plugins/intel_cpu
- src/nodes
- common
- executors/acl
8 files changed
+42
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
55 | 54 | | |
56 | 55 | | |
57 | 56 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
44 | 43 | | |
45 | 44 | | |
46 | 45 | | |
| |||
381 | 380 | | |
382 | 381 | | |
383 | 382 | | |
384 | | - | |
385 | | - | |
386 | | - | |
387 | | - | |
388 | 383 | | |
389 | 384 | | |
390 | 385 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
550 | 550 | | |
551 | 551 | | |
552 | 552 | | |
553 | | - | |
554 | | - | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
555 | 556 | | |
556 | 557 | | |
557 | 558 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
| 59 | + | |
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
77 | | - | |
| 77 | + | |
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
| |||
Lines changed: 10 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
79 | 80 | | |
80 | 81 | | |
81 | 82 | | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
82 | 92 | | |
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
29 | 35 | | |
30 | 36 | | |
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
14 | 17 | | |
15 | 18 | | |
Lines changed: 18 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
6 | 8 | | |
7 | 9 | | |
8 | 10 | | |
| |||
57 | 59 | | |
58 | 60 | | |
59 | 61 | | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
60 | 78 | | |
61 | 79 | | |
0 commit comments