Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ members = [
"crates/cuda_std_macros",
"crates/cudnn",
"crates/cudnn-sys",
"crates/cufft",
"crates/cufft_raw",
"crates/cust",
"crates/cust_core",
"crates/cust_derive",
Expand Down Expand Up @@ -49,6 +51,7 @@ members = [
"examples/i128_demo/kernels",
"examples/sha2_crates_io",
"examples/sha2_crates_io/kernels",
"examples/fft",
"examples/vecadd",
"examples/vecadd/kernels",

Expand Down
11 changes: 11 additions & 0 deletions crates/cufft/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "cufft"
version = "0.1.0"
edition = "2024"
license = "MIT OR Apache-2.0"
repository = "https://github.com/Rust-GPU/rust-cuda"
readme = "../../README.md"

[dependencies]
cufft_raw = { version = "0.1.0", path = "../cufft_raw" }
cust = { version = "0.3.2", path = "../cust" }
81 changes: 81 additions & 0 deletions crates/cufft/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
use std::error::Error;
use std::fmt::Display;

/// Error type for cuFFT operations.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum CufftError {
/// The plan handle is invalid.
InvalidPlan,
/// Memory allocation failed.
AllocFailed,
/// The transform type is invalid.
InvalidType,
/// An invalid value was provided.
InvalidValue,
/// An internal cuFFT error occurred.
InternalError,
/// The transform failed to execute.
ExecFailed,
/// The library failed to initialize.
SetupFailed,
/// The transform size is invalid.
InvalidSize,
/// The device is invalid.
InvalidDevice,
/// No workspace has been provided.
NoWorkspace,
/// This feature is not implemented.
NotImplemented,
/// This feature is not supported.
NotSupported,
}

impl Display for CufftError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let msg = match self {
CufftError::InvalidPlan => "invalid plan handle",
CufftError::AllocFailed => "allocation failed",
CufftError::InvalidType => "invalid type",
CufftError::InvalidValue => "invalid value",
CufftError::InternalError => "internal error",
CufftError::ExecFailed => "exec failed",
CufftError::SetupFailed => "setup failed",
CufftError::InvalidSize => "invalid size",
CufftError::InvalidDevice => "invalid device",
CufftError::NoWorkspace => "no workspace",
CufftError::NotImplemented => "not implemented",
CufftError::NotSupported => "not supported",
};
f.write_str(msg)
}
}

impl Error for CufftError {}

pub trait IntoResult {
fn into_result(self) -> Result<(), CufftError>;
}

impl IntoResult for cufft_raw::cufftResult {
fn into_result(self) -> Result<(), CufftError> {
use cufft_raw::cufftResult::*;
Err(match self {
CUFFT_SUCCESS => return Ok(()),
CUFFT_INVALID_PLAN => CufftError::InvalidPlan,
CUFFT_ALLOC_FAILED => CufftError::AllocFailed,
CUFFT_INVALID_TYPE => CufftError::InvalidType,
CUFFT_INVALID_VALUE => CufftError::InvalidValue,
CUFFT_INTERNAL_ERROR => CufftError::InternalError,
CUFFT_EXEC_FAILED => CufftError::ExecFailed,
CUFFT_SETUP_FAILED => CufftError::SetupFailed,
CUFFT_INVALID_SIZE => CufftError::InvalidSize,
CUFFT_UNALIGNED_DATA => CufftError::InvalidValue,
CUFFT_INVALID_DEVICE => CufftError::InvalidDevice,
CUFFT_NO_WORKSPACE => CufftError::NoWorkspace,
CUFFT_NOT_IMPLEMENTED => CufftError::NotImplemented,
CUFFT_NOT_SUPPORTED => CufftError::NotSupported,
_ => CufftError::InternalError,
})
}
}
15 changes: 15 additions & 0 deletions crates/cufft/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//! Rust wrapper for the [cuFFT library](https://docs.nvidia.com/cuda/cufft/).
//!
//! Create a `FftPlan<T>` with one of the plan constructors,
//! where `T` implements the `FftType` trait (`C2C`, `R2C`, `C2R`, `Z2Z`, `D2Z`, `Z2D`).
//! Optionally attach a stream with `FftPlan::set_stream`.
//! Execute the plan with `FftPlan::exec`.
//! Plans are destroyed when dropped.
//!
//! Raw bindgen bindings are available in `cufft_raw`.
mod error;
mod plan;

pub use error::{CufftError, IntoResult};
pub use plan::{C2C, C2R, D2Z, Direction, FftPlan, FftType, R2C, Z2D, Z2Z};
Loading