-
-
Notifications
You must be signed in to change notification settings - Fork 117
Description
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:
bytemuck
hasZeroable
andAnyBitPattern
, which is a subset ofDeviceRepr
(it's bidirectional, so it doesn't support types with niches).zerocopy
hasIntoBytes
andFromZeros
.
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!