Skip to content
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

Add Core functions for devices, properties, version #114

Merged
merged 7 commits into from
May 24, 2024

Conversation

rahulchaphalkar
Copy link
Contributor

Add functions to core related to devices and properties.

Copy link
Contributor

@abrown abrown left a comment

Choose a reason for hiding this comment

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

I think this change is good functionality-wise. I made some style comments to address but otherwise it is good to go.

/// Gets device plugins version information.
/// Device name can be complex and identify multiple devices at once like `HETERO:CPU,GPU`;
/// in this case, the returned map contains multiple entries, each per device.
pub fn versions(&self, device_name: impl AsRef<str>) -> Result<HashMap<DeviceType, Version>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's just return a Result<Vec<(DeviceType, Version)>>; if users really need a map there are conversion functions for that. And they might want some other collection besides a hash map so let's let give them the most simple data structure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


/// Gets properties related to this Core.
/// The method extracts information that can be set via the [set_property] method.
pub fn property(&self, key: PropertyKey) -> Result<Cow<str>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe get_property for consistency?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


/// Gets properties related to device behaviour.
/// The method extracts information that can be set via the [set_device_property] method.
pub fn device_property(
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
pub fn device_property(
pub fn get_device_property(

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

&self,
device_name: impl AsRef<str>,
key: PropertyKey,
) -> Result<Cow<str>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, I'm not sure about this Cow... You're trying to avoid a copy?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have removed the Cow from return. I was using to_string_lossy which returned Cow<str>, handling non-utf8 and utf-8 cases both, so returning Cow would save copy for valid utf8.
I changed that now to to_str.

/// Sets a property for a device.
pub fn set_device_property(
&mut self,
device_name: impl AsRef<str>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the AsRef here but not for value? Just a consistency nit, but it may be worthwhile to think through why we would use the trait versus the simpler &str. Either is fine though I try to bias towards simpler.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, I removed AsRefs

}

/// Sets properties for a device.
pub fn set_device_properties<'a>(
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the 'a still needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I get an error otherwise, anonymous lifetimes in impl Trait are unstable

@abrown abrown merged commit a3731ac into intel:main May 24, 2024
15 checks passed
@abrown abrown deleted the core-functions branch May 24, 2024 20:03
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.

2 participants