Skip to content

[JAVA_API] Fix ElementType compatibility problem introduced in 2025.1 #963

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/java_api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ println 'CPU architecture: ' + arch


def nativesCPP;
def openvinoVersion = "2024.2"
def openvinoVersion = "2025.1"

def native_resources = []
def tbb_dir = System.getenv('TBB_DIR')
Expand Down
4 changes: 2 additions & 2 deletions modules/java_api/src/main/cpp/jni_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ static const ov::element::Type_t& get_ov_type(int type)
{
static const std::vector<ov::element::Type_t> java_type_to_ov_type
{
ov::element::Type_t::dynamic,
ov::element::Type_t::dynamic,
ov::element::Type_t::boolean,
ov::element::Type_t::bf16,
Expand All @@ -261,7 +260,8 @@ static const ov::element::Type_t& get_ov_type(int type)
ov::element::Type_t::f8e4m3,
ov::element::Type_t::f8e5m2,
ov::element::Type_t::string,
ov::element::Type_t::f4e2m1
ov::element::Type_t::f4e2m1,
ov::element::Type_t::f8e8m0
};

return java_type_to_ov_type.at(type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,33 @@
import java.util.Map;

public enum ElementType {
undefined(0),
dynamic(1),
bool(2),
bf16(3),
f16(4),
f32(5),
f64(6),
i4(7),
i8(8),
i16(9),
i32(10),
i64(11),
u1(12),
u2(13),
u3(14),
u4(15),
u6(16),
u8(17),
u16(18),
u32(19),
u64(20),
nf4(21),
f8e4m3(22),
f8e5m2(23),
string(24),
f4e2m1(25);
dynamic(0),
undefined(dynamic.value),
bool(1),
bf16(2),
f16(3),
f32(4),
f64(5),
i4(6),
i8(7),
i16(8),
i32(9),
i64(10),
u1(11),
u2(12),
u3(13),
u4(14),
u6(15),
u8(16),
u16(17),
u32(18),
u64(19),
nf4(20),
f8e4m3(21),
f8e5m2(22),
string(23),
f4e2m1(24),
f8e8m0(25);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why new type added as PR only fix compatibility issues after deprecation of undefined?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The added type has nothing to do with the fix of the problem. The problem comes from the usage of two Type_t entries using the same int value 0 (undefined and dynamic).

The fix was subtracting 1 from the values of ElementType.java

Take a look at the following example:

#include <iostream>


enum class OldType_t {
    undefined,  // 0
    dynamic,    // 1
    boolean,    // 2
    bf16,       // 3
    f16,        // 4
    f32,        // 5
    f64,        // 6
    // etc...
};

constexpr size_t idx(OldType_t e) noexcept {
    return static_cast<std::underlying_type_t<OldType_t>>(e);
}


enum class NewType_t {
    dynamic,              // 0   
    undefined = dynamic,  // 0
    boolean,              // 1  <-- value changed
    bf16,                 // 2  <-- value changed
    f16,                  // 3  <-- value changed
    f32,                  // 4  <-- value changed
    f64,                  // 5  <-- value changed
    // etc...
};

constexpr size_t idx(NewType_t e) noexcept {
    return static_cast<std::underlying_type_t<NewType_t>>(e);
}


int main()
{
    std::cout << "Old values:"
            <<" undefined="<< idx(OldType_t::undefined)
            <<" dynamic="  << idx(OldType_t::dynamic)
            <<" boolean="  << idx(OldType_t::boolean)
            <<" bf16="     << idx(OldType_t::bf16)
            <<" f16="      << idx(OldType_t::f16)
            <<" f32="      << idx(OldType_t::f32)
            <<" f64="      << idx(OldType_t::f64) << std::endl;


    std::cout << "New values:"
            <<" undefined="<< idx(NewType_t::undefined)
            <<" dynamic="  << idx(NewType_t::dynamic)
            <<" boolean="  << idx(NewType_t::boolean)
            <<" bf16="     << idx(NewType_t::bf16)
            <<" f16="      << idx(NewType_t::f16)
            <<" f32="      << idx(NewType_t::f32)
            <<" f64="      << idx(NewType_t::f64) << std::endl;

    return 0;
}
Old values: undefined=0 dynamic=1 boolean=2 bf16=3 f16=4 f32=5 f64=6
New values: undefined=0 dynamic=0 boolean=1 bf16=2 f16=3 f32=4 f64=5

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The added type has nothing to do with the fix of the problem, this was reason for question why is added if not related to the issue.

Fix for values of ElementType.java is OK.


private int value;
private static Map<Integer, ElementType> map = new HashMap<Integer, ElementType>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void testInputs() {
List<Output> inputs = model.inputs();

assertEquals("data", inputs.get(0).get_any_name());
assertEquals(ElementType.f16, inputs.get(0).get_element_type());
assertEquals(ElementType.f32, inputs.get(0).get_element_type());

int[] shape = new int[] {1, 3, 32, 32};
assertArrayEquals("Shape", shape, inputs.get(0).get_shape());
Expand All @@ -34,7 +34,7 @@ public void testOutputs() {
List<Output> outputs = model.outputs();

assertEquals("fc_out", outputs.get(0).get_any_name());
assertEquals(ElementType.f16, outputs.get(0).get_element_type());
assertEquals(ElementType.f32, outputs.get(0).get_element_type());

int[] shape = new int[] {1, 10};
assertArrayEquals("Shape", shape, outputs.get(0).get_shape());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void testOutputName() {
@Test
public void testOutputType() {
Output output = net.output();
assertEquals("Output element type", ElementType.f16, output.get_element_type());
assertEquals("Output element type", ElementType.f32, output.get_element_type());
}

@Test
Expand Down
Loading