Skip to content
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

add complex.hlsl #592

Merged
merged 22 commits into from
Jun 13, 2024
Merged

add complex.hlsl #592

merged 22 commits into from
Jun 13, 2024

Conversation

nahiim
Copy link
Contributor

@nahiim nahiim commented Nov 3, 2023

Description

Start drafting complex.hlsl

@devshgraphicsprogrammingjenkins
Copy link
Contributor

[CI]: Can one of the admins verify this patch?

Comment on lines 17 to 19
// Fast Fourier Transform
template<typename T, uint32_t N>
void fft_radix2(complex::complex_t<T> data[N], bool is_inverse)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make the is_inverse a template parameter

assert(N<gl_SubgroupSize)

btw the data need not be data[N], each invocation comes with its own register value and you can cooperatively exchange via the use of subgroupShuffleXor (add it to https://github.com/Devsh-Graphics-Programming/Nabla/blob/master/include/nbl/builtin/hlsl/glsl_compat/subgroup_shuffle.hlsl please).

I mean the original GLSL code is here
https://github.com/Devsh-Graphics-Programming/Nabla/blob/master/include/nbl/builtin/glsl/subgroup/fft.glsl

@devshgraphicsprogramming
Copy link
Member

devshgraphicsprogramming commented May 14, 2024

I see a certain ladder of features, and each should have their own branch (so I can merge in order without having all comments addressed):

  1. having a complex_t struct to use
  2. subgroup::fft utilities for DIT and DIF
  3. workgroup::fft utilities for DIT and DIF
  4. a way to do multiple input items per-workgroup, i.e. do a 2048 sized FFT with a 512 workgroup while having the option of only using enough shared memory for 512 FFT + auxilary accessor
  5. optimizations for FFT real signals
  6. resurrect the nbl::ext and 1 or both of the old FFT examples to test with

They can branch off each other.

P.S. Let me know if you need "runtime" transcendental/special functions for complex_t then we can look into doing up our tgmath.hlsl

Missing compound operators and template specializations for integer
types. Arithmetic logic is off, different from the STL
// Cooley-Tukey
assign_mul_complex<T> mul_assign;
assign_div_complex<T> div_assign;
for (uint32_t stride = 2; stride <= N; stride *= 2)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd do a loop from stride=1 to stride=N/2 instead of 2->N because that's the actual stride between your butterfly elements, what you have right now is a width

{
namespace subgroup
{
// TODO: specialize subgorupShuffleXor to different Scalar types. As of right now this would only support 1-wide scalars (no vectors)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thats fine, lets do 1 channel at a time



template<typename Scalar, uint32_t SubgroupSize, bool inverse>
void FFT(NBL_REF_ARG(complex_t<Scalar>) lo, NBL_REF_ARG(complex_t<Scalar>) hi) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to document with comments what lo and hi are

const uint32_t doubleSubgroupSize = SubgroupSize << 1;
// special first iteration
if (! inverse)
fft::DIX<Scalar, inverse>::radix2(fft::twiddle<Scalar, inverse>(glsl::gl_SubgroupID(), doubleSubgroupSize), lo, hi);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using DIX<Scalar,inverse> when you're already inside an if (inverse) or if (!inverse) makes the code super unreadable, I'd use DIT or DIF directly

Comment on lines 38 to 42
FFT_loop<Scalar, inverse>(stride, lo, hi);
// Decimation in Frequency
else
for (uint32_t stride = SubgroupSize >> 1; stride > 0; stride >>= 1)
FFT_loop<Scalar, inverse>(stride, lo, hi);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also substitute inverse if you already know the value

@devshgraphicsprogramming devshgraphicsprogramming merged commit bff2c33 into master Jun 13, 2024
1 check failed
@devshgraphicsprogramming devshgraphicsprogramming deleted the nahim_complex branch June 13, 2024 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants