John Hubbard
2025-Nov-08 05:08 UTC
[PATCH v6 3/4] gpu: nova-core: make Architecture behave as a u8 type
On 11/7/25 9:03 PM, Timur Tabi wrote:> On Fri, 2025-11-07 at 20:39 -0800, John Hubbard wrote: >> ?/// Enum representation of the GPU generation. >> -#[derive(fmt::Debug)] >> +#[derive(fmt::Debug, Default, Copy, Clone)] >> +#[repr(u8)] >> ?pub(crate) enum Architecture { >> +??? #[default] >> ???? Turing = 0x16, >> ???? Ampere = 0x17, >> ???? Ada = 0x19, >> @@ -142,6 +144,13 @@ fn try_from(value: u8) -> Result<Self> { >> ???? } >> ?} > > Does it make sense to designate a default Architecture? Turing is not a fallback for Ampere --Definitely not! However, we do want to use Architecture in places (register! and bitfield! macros) that expect u8 or u32, and that also expect to use integer defaults. So that's why we have to supply it. thanks, -- John Hubbard
Alexandre Courbot
2025-Nov-08 11:45 UTC
[PATCH v6 3/4] gpu: nova-core: make Architecture behave as a u8 type
On Sat Nov 8, 2025 at 2:08 PM JST, John Hubbard wrote:> On 11/7/25 9:03 PM, Timur Tabi wrote: >> On Fri, 2025-11-07 at 20:39 -0800, John Hubbard wrote: >>> ?/// Enum representation of the GPU generation. >>> -#[derive(fmt::Debug)] >>> +#[derive(fmt::Debug, Default, Copy, Clone)] >>> +#[repr(u8)] >>> ?pub(crate) enum Architecture { >>> +??? #[default] >>> ???? Turing = 0x16, >>> ???? Ampere = 0x17, >>> ???? Ada = 0x19, >>> @@ -142,6 +144,13 @@ fn try_from(value: u8) -> Result<Self> { >>> ???? } >>> ?} >> >> Does it make sense to designate a default Architecture? Turing is not a fallback for Ampere -- > > Definitely not! However, we do want to use Architecture in places > (register! and bitfield! macros) that expect u8 or u32, and that also > expect to use integer defaults. > > So that's why we have to supply it.To be precise, we need to supply this because of a shortcoming in the `register`` macro: it doesn't support read-only registers yet, and write support requires a `Default` implementation for its fields. This is subject to be fixed in the future but for now we need this little workaround.