Skip to content

Conversation

@abrown
Copy link
Contributor

@abrown abrown commented Oct 4, 2024

This uses #142 (not included here) to update the OpenVINO C headers to their latest version and generate Rust bindings for them. While doing this I discovered #143, which results in a breaking change to the bindings; since the ov_element_type_e variants now have different values, users get wrong byte sizes (and out-of-bounds access to tensor memory via Tensor::get_*) if using these bindings with an implementation of OpenVINO older than 2024.2.0.

Along the way, this fixes up how we generate C enums, now as Rust enums in order to see compile-time errors when new variants are introduced. The majority of the changes are due to propagating this change throughout the crates.

Closes #143, closes #20.

abrown added 8 commits October 7, 2024 18:04
This consists of using intel#142:

```
$ cargo xtask update 2024.4.0
$ cargo xtask codegen
$ cargo test
```

The follow-on commits resolve the errors introduced by this update.
This change is an effort avoid missing new enum variants if they are
added to OpenVINO's C headers. As it stands now, new variants could be
missed until runtime, when the enum code can't be parsed and the library
panics. Instead, this change generates a Rust `enum` for each C `enum`
so that missing variants become a compile time error; if we update the
bindings but don't handle these, we see a compile-time error.
The `openvino` crate depended on the previous constants generated by
`bindgen`. This change uses the new Rust `enum`s instead, creating
`From` and `Into` implementations to go between the Rust and C versions.

Why not just pass through the `openvino_sys` enum as-is? The only real
issue currently is documentation: the C headers start documentation with
`<!` which seems a bit weird. I've also fixed up a few grammar problems
in the documentation. But one day we may indeed be able to just reuse
these types.
It wasn't clear to me why the function and the struct were kept in
different places so I moved them together. I also added a
`Version::parts` function.
Any test using `ElementType::U8` will cause problems when run on older
versions of the library. This change manually ignores tests that depend
on this by detecting the library version. For `Tensor`'s doc test, I
chose to use a type not affected by the breaking change to keep things
consistent.
@abrown abrown marked this pull request as ready for review October 8, 2024 18:00
@abrown abrown requested a review from rahulchaphalkar October 8, 2024 18:00
Copy link
Contributor

@rahulchaphalkar rahulchaphalkar left a comment

Choose a reason for hiding this comment

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

Couple of Nits, and String related feedback.

@rahulchaphalkar rahulchaphalkar merged commit 100eabc into intel:main Oct 9, 2024
17 checks passed
let mut parts = version.parts();
let year: usize = parts.next().unwrap().parse().unwrap();
let minor: usize = parts.next().unwrap().parse().unwrap();
year <= 2024 || (year == 2024 && minor < 2)
Copy link
Contributor

Choose a reason for hiding this comment

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

@abrown Realized this half hour too late - this needs to be year < 2024 ||, was testing new version again and it skipped this test for 2024.4.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ugh, yeah, that's right. I'll fix it.

@abrown abrown deleted the v2024.4.0 branch October 9, 2024 20:43
abrown added a commit to abrown/openvino-rs that referenced this pull request Oct 9, 2024
@rahulchaphalkar pointed out that the first part of this check should
filter out pre-2024 releases; fixes an issue in intel#144.
rahulchaphalkar pushed a commit that referenced this pull request Oct 9, 2024
@rahulchaphalkar pointed out that the first part of this check should
filter out pre-2024 releases; fixes an issue in #144.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tensor::get_byte_size returns incorrect result with v2024.4.0 Auto-generate InferenceError?

2 participants