+
Skip to content

A feature for blanket implementations of DeviceRepr and ValidAsZeroBits #410

@kaathewisegit

Description

@kaathewisegit

cudarc's safe driver API has two traits, DeviceRepr and ValidAsZeroBits, which mark types which can be reliably memcopied to the GPU and those which are valid as zeros. Because of the orphan rule they cannot be defined for third-party crates, though.

There are, however, two popular crates: bytemuck and zerocopy, which define similar traits:

And many third-party crates like uuid and half have options to enable implementation for those features. I think it'd be convenient if cudarc had a zerocopy and/or bytemuck features, which would add a blanket implementation of cudarc's traits, i.e.:

// SAFETY: upheld by `Zeroable`'s invariant
unsafe impl<T> ValidAsZeroBits for T where T: zerocopy::Zeroable {}

This would make it easier to interface with third-party crates without the need to resort to a newtype wrapper. The downside is that it adds dependencies and could cause implementation conflicts, but I think that keeping it behind an off by default feature would be fine.

P.S.
I've just discovered cudarc this week and it using it has been a delight, so I wanted to say thanks for it!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载