-
Notifications
You must be signed in to change notification settings - Fork 231
Add FFT causal conv1d frontend bindings #437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
yeliu-oss
wants to merge
3
commits into
NVIDIA:develop
Choose a base branch
from
yeliu-oss:yeliu/fft-causal-conv1d
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| # FFT Causal Conv1d | ||
|
|
||
| The cuDNN Frontend Python API exposes FFT-based depthwise causal convolution | ||
| through: | ||
|
|
||
| ```python | ||
| y = cudnn.ops.fft_causal_conv1d(x, weight) | ||
| ``` | ||
|
|
||
| This API requires cuDNN 9.26.0 or newer. It supports FP16, BF16, FP32, and FP64 | ||
| CUDA tensors, `torch.autograd`, and `torch.compile`. | ||
|
|
||
| ## Operation | ||
|
|
||
| For `x` shaped `(batch, dim, seq_len)` and `weight` shaped | ||
| `(dim, kernel_size)`, the operation computes: | ||
|
|
||
| ```text | ||
| y[b, c, t] = sum(x[b, c, t - j] * weight[c, j], j=0..kernel_size-1) | ||
| ``` | ||
|
|
||
| Here, `x[b, c, t - j]` is zero when `t - j` is outside the input sequence. | ||
| This is FIR-order weight storage: | ||
| `weight[0]` multiplies the current sample. It is reversed relative to | ||
| `cudnn.ops.causal_conv1d`, whose first stored weight multiplies the oldest | ||
| sample in the causal window. | ||
|
|
||
| ## Path Selection | ||
|
|
||
| The convenience wrapper follows cuhyena's Python API: | ||
|
|
||
| - It rounds `kernel_size` up to a power of two, with a minimum of 128. | ||
| - It selects the medium FFT path when the filter fits that path's dtype and | ||
| device limit. | ||
| - It right-pads the input to a multiple of the medium filter length. | ||
| - Otherwise it right-pads input and filter to one common power-of-two length | ||
| and selects the long FFT path. | ||
| - It trims the output and autograd gradients back to the caller's shapes. | ||
|
|
||
| The medium path supports FP64 filters through 4096. Other dtypes support | ||
| filters through 8192 before SM90 and through 16384 on SM90 or newer. | ||
|
|
||
| The raw long backend path requires power-of-two `seq_len == kernel_size` in | ||
| `[4096, 16777216]`. FP64 supports lengths through 8388608; length 16777216 for | ||
| other dtypes requires SM90 or newer. | ||
|
|
||
| ## Long FFT Buffers | ||
|
|
||
| Long FFT forward queries and allocates two opaque byte buffers: | ||
|
|
||
| - Workspace is temporary scratch for the current forward or backward call. | ||
| - Reserve space stores transformed signal and filter state from forward and is | ||
| retained by the autograd context for the matching backward call. | ||
|
|
||
| Applications calling the C APIs directly must preserve this same reserve-space | ||
| lifetime. See | ||
| `samples/cpp/causal_conv1d/fft_causal_conv1d.cpp` for medium and long C API | ||
| examples. | ||
|
|
||
| ## Example | ||
|
|
||
| ```python | ||
| import cudnn | ||
| import torch | ||
|
|
||
| x = torch.randn(2, 16, 4096, device="cuda", requires_grad=True) | ||
| weight = torch.randn(16, 256, device="cuda", requires_grad=True) | ||
|
|
||
| y = cudnn.ops.fft_causal_conv1d(x, weight) | ||
| y.sum().backward() | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| from .causal_conv1d import causal_conv1d, causal_conv1d_nwh, b2b_causal_conv1d | ||
| from .fft_causal_conv1d import fft_causal_conv1d |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.