rocrand/rocfft: use bindgen status/enum types, not hardcoded u32

C enums with only non-negative values are unsigned int (u32) under Linux
GCC/Clang but signed int (i32) under MSVC. bindgen follows the platform ABI,
so the generated status/enum types are u32 on Linux and i32 on Windows.
Hand-coding u32 at status/enum-handling sites mismatched the bindgen type on
Windows, producing E0308 'expected u32, found i32'.

Fix is uniform: stop hardcoding u32; use the module's bindgen type. No-op on
Linux (the alias is u32 there), correct on Windows.

rocrand/error.rs:
  from_status(status: bindings::rocrand_status)   // was u32
  Unknown(other as u32)                           // keep error variant u32-stable

rocfft/error.rs:
  impl From<bindings::rocfft_status_e> for Error   // was From<u32>
  check_error(status: bindings::rocfft_status_e)   // was u32
  check_compatible_types(transform_type: rocfft_transform_type,
                         in/out_array_type: rocfft_array_type)  // was u32
  Unknown(code as u32)                             // keep error variant u32-stable

rocfft/plan.rs + rocfft/description.rs:
  From<TransformType>  for rocfft_transform_type     // was for u32
  From<Precision>      for rocfft_precision          // (enum-typed FFI args:
  From<PlacementType>  for rocfft_result_placement   //  the .into() targets
  From<ArrayType>      for rocfft_array_type         //  rocfft_plan_create etc.
  From<CommType>       for rocfft_comm_type          //  expect the enum type)

rocsparse/rocarray/hip already used bindgen types (or genuine u32 flags/dims/
counts) and need no change. Verified: cargo check --no-default-features
--features macros reaches Finished on Linux (ROCm 7.13).
This commit is contained in:
2026-06-21 21:21:56 -07:00
parent 69577a9110
commit 490346c497
4 changed files with 14 additions and 14 deletions
+1 -1
View File
@@ -21,7 +21,7 @@ pub enum CommType {
MPI,
}
impl From<CommType> for u32 {
impl From<CommType> for bindings::rocfft_comm_type {
fn from(comm_type: CommType) -> Self {
match comm_type {
CommType::None => bindings::rocfft_comm_type_e_rocfft_comm_none,
+7 -7
View File
@@ -75,8 +75,8 @@ impl From<NulError> for Error {
}
}
impl From<u32> for Error {
fn from(status: u32) -> Self {
impl From<bindings::rocfft_status_e> for Error {
fn from(status: bindings::rocfft_status_e) -> Self {
match status {
bindings::rocfft_status_e_rocfft_status_success => {
panic!("Tried to convert successful status to error")
@@ -89,7 +89,7 @@ impl From<u32> for Error {
bindings::rocfft_status_e_rocfft_status_invalid_distance => Error::InvalidDistance,
bindings::rocfft_status_e_rocfft_status_invalid_offset => Error::InvalidOffset,
bindings::rocfft_status_e_rocfft_status_invalid_work_buffer => Error::InvalidWorkBuffer,
code => Error::Unknown(code),
code => Error::Unknown(code as u32),
}
}
}
@@ -115,7 +115,7 @@ impl From<&'static str> for Error {
pub type Result<T> = std::result::Result<T, Error>;
/// Check a rocFFT status code and convert to a Rust Result
pub(crate) fn check_error(status: u32) -> Result<()> {
pub(crate) fn check_error(status: bindings::rocfft_status_e) -> Result<()> {
match status {
bindings::rocfft_status_e_rocfft_status_success => Ok(()),
_ => Err(Error::from(status)),
@@ -155,9 +155,9 @@ pub(crate) fn check_dimensions(dimensions: usize) -> Result<()> {
/// Helper function to detect incompatible array types for a transform
#[inline]
pub(crate) fn check_compatible_types(
transform_type: u32,
in_array_type: u32,
out_array_type: u32,
transform_type: bindings::rocfft_transform_type,
in_array_type: bindings::rocfft_array_type,
out_array_type: bindings::rocfft_array_type,
) -> Result<()> {
match transform_type {
bindings::rocfft_transform_type_e_rocfft_transform_type_complex_forward
+4 -4
View File
@@ -24,7 +24,7 @@ pub enum TransformType {
RealInverse,
}
impl From<TransformType> for u32 {
impl From<TransformType> for bindings::rocfft_transform_type {
fn from(transform_type: TransformType) -> Self {
match transform_type {
TransformType::ComplexForward => {
@@ -54,7 +54,7 @@ pub enum Precision {
Half,
}
impl From<Precision> for u32 {
impl From<Precision> for bindings::rocfft_precision {
fn from(precision: Precision) -> Self {
match precision {
Precision::Single => bindings::rocfft_precision_e_rocfft_precision_single,
@@ -73,7 +73,7 @@ pub enum PlacementType {
NotInPlace,
}
impl From<PlacementType> for u32 {
impl From<PlacementType> for bindings::rocfft_result_placement {
fn from(placement: PlacementType) -> Self {
match placement {
PlacementType::InPlace => bindings::rocfft_result_placement_e_rocfft_placement_inplace,
@@ -101,7 +101,7 @@ pub enum ArrayType {
Unset,
}
impl From<ArrayType> for u32 {
impl From<ArrayType> for bindings::rocfft_array_type {
fn from(array_type: ArrayType) -> Self {
match array_type {
ArrayType::ComplexInterleaved => {
+2 -2
View File
@@ -34,7 +34,7 @@ pub type Result<T> = std::result::Result<T, Error>;
impl Error {
/// Convert a rocrand status code to a Result
pub(crate) fn from_status(status: u32) -> Result<()> {
pub(crate) fn from_status(status: bindings::rocrand_status) -> Result<()> {
match status {
bindings::rocrand_status_ROCRAND_STATUS_SUCCESS => Ok(()),
bindings::rocrand_status_ROCRAND_STATUS_VERSION_MISMATCH => Err(Error::VersionMismatch),
@@ -52,7 +52,7 @@ impl Error {
}
bindings::rocrand_status_ROCRAND_STATUS_LAUNCH_FAILURE => Err(Error::LaunchFailure),
bindings::rocrand_status_ROCRAND_STATUS_INTERNAL_ERROR => Err(Error::InternalError),
other => Err(Error::Unknown(other)),
other => Err(Error::Unknown(other as u32)),
}
}
}