Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add dlpack support#1306

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
SunDoge wants to merge3 commits intorust-ndarray:master
base:master
Choose a base branch
Loading
fromSunDoge:feat-dlpack
Draft

Conversation

SunDoge
Copy link

@SunDogeSunDoge commentedJul 14, 2023
edited
Loading

DLPack is an open in-memory tensor structure for sharing tensors among frameworks. DLPack enables

  • Easier sharing of operators between deep learning frameworks.
  • Easier wrapping of vendor level operator implementations, allowing collaboration when introducing new devices/ops.
  • Quick swapping of backend implementations, like different version of BLAS
  • For final users, this could bring more operators, and possibility of mixing usage between frameworks.

Supportingdlpack will make it easier to share tensors withdfdx,tch-rs and evennumpy,torch in Python (withpyo3 feature).

weiji14 reacted with eyes emoji
@SunDogeSunDoge marked this pull request as draftJuly 14, 2023 06:26
@nilgoyette
Copy link
Collaborator

I don't know much about dlpack, but I'm quite sure this won't be merged if

  • it's not hidden behind a feature gate
  • it doesn't use a real crates.io version (not git)

@SunDoge
Copy link
Author

SunDoge commentedJul 17, 2023
edited
Loading

This is still a draft. The api of dlpark is still evolving and I'll release v0.3.0 this week. I want to utilize the ownership system to make sure dlpack can only be consumed once, otherwise there will be double free error. And thanks for your advice, I will add the feature gate.

@SunDogeSunDoge marked this pull request as ready for reviewJuly 18, 2023 09:27
@SunDogeSunDoge changed the titleDraft: add dlpack supportAdd dlpack supportJul 18, 2023
unsafe impl<A> Send for ManagedRepr<A> where A: Send {}

impl<A> FromDLPack for ManagedArray<A, IxDyn> {
fn from_dlpack(dlpack: NonNull<dlpark::ffi::DLManagedTensor>) -> Self {
Copy link
Member

@blussblussMar 9, 2024
edited
Loading

Choose a reason for hiding this comment

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

this function takes a raw pointer (wrapped in NonNull) and it must be an unsafe function, otherwise we can trivially violate memory safety unfortunately.

The only way to remove this requirement - the requirement of usingunsafe - would be if you have a "magical" function that can take an arbitrary pointer and say whether it's a valid, live, non-mutably aliased pointer to a tensor.

Here's how to create a dangling bad pointer:NonNull::new(1 as *mut u8 as *mut dlpark::ffi::DLManagedTensor) does this code crash if we run with this pointer? I think it would..

Copy link
Author

Choose a reason for hiding this comment

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

I agree with you.from_dlpack should be unsafe, and users should use it at their own risk.

Copy link
Member

@blussblussMar 10, 2024
edited
Loading

Choose a reason for hiding this comment

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

I would say, we normally don't commit to public dependencies that are not stable (yes, not a very fair policy since ndarray itself is not so stable.), and dlpark is a public dependency here because it becomes part of our API. It could mean it takes a long time between version bumps.

Copy link
Author

Choose a reason for hiding this comment

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

Maybe we don't need to includedlpark as a dependency. We can create anArrayView usingArrayView::from_shape_ptr andManagedTensor. I can implementToTensor forArrayD indlpark with a new featurendarray. I'll do some quick experiments.

@blussbluss marked this pull request as draftMarch 9, 2024 14:36

let strides: Vec<usize> = match (managed_tensor.strides(), managed_tensor.is_contiguous()) {
(Some(s), _) => s.into_iter().map(|&x| x as _).collect(),
(None, true) => managed_tensor
Copy link
Member

Choose a reason for hiding this comment

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

Later work, check compatibility of dlpack and ndarray strides, how they work, their domains etc.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@blussblussbluss left review comments

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@SunDoge@nilgoyette@bluss

[8]ページ先頭

©2009-2025 Movatter.jp