DTolm / VkFFT

Vulkan/CUDA/HIP/OpenCL/Level Zero/Metal Fast Fourier Transform library
MIT License
1.48k stars 88 forks source link

Use enum for precision #167

Open DejvBayer opened 3 months ago

DejvBayer commented 3 months ago

Hi,

inspired by the cuFFT library, I was wandering if it would be a good idea to specify the transform precision by an enum class VkFFTPrecision defined as:

typedef enum
{
  VKFFT_PREC_UNDEF = 0,
  VKFFT_PREC_BF16,
  VKFFT_PREC_F16,
  VKFFT_PREC_F32,
  VKFFT_PREC_F64,
  VKFFT_PREC_F128
} VkFFTPrecision;

Then when configurating all of the old flags could be removed and replaced by

At least precision variable must be always specified.

typedef struct {
  // ...

  // pfUINT doublePrecision;
  // pfUINT quadDoubleDoublePrecision;
  // pfUINT quadDoubleDoublePrecisionDoubleMemory;
  // pfUINT halfPrecision;
  // pfUINT halfPrecisionMemoryOnly;
  // pfUINT doublePrecisionFloatMemory;

  VkFFTPrecision precision;         // must be specified
  VkFFTPrecision forwardPrecision;  // optional, if is VKFFT_PREC_UNDEF, then use `precision`
  VkFFTPrecision inversePrecision;  // optional, if is VKFFT_PREC_UNDEF, then use `precision`
  VkFFTPrecision inputPrecision;    // optional, if is VKFFT_PREC_UNDEF, then use `precision`
  VkFFTPrecision outputPrecision;   // optional, if is VKFFT_PREC_UNDEF, then use `precision`

  // ...
} VkFFTConfiguration;

I think that it would really make everything more clear.

Thanks.

David

DTolm commented 3 months ago

Hello,

This can be done, but to have backward compatibility, I would rather do something simple, like

define VKFFT_PREC_FP32 0

define VKFFT_PREC_FP64 1

As for the rework of inputPrecision and so on, it is better to wait until the callback functionality is formalized and added.

Best regards, Dmitrii

DejvBayer commented 3 months ago

Hi,

so as I understand it, you suggest that the structure of the VkFFTConfiguration structure could look like:

typedef struct {
  // ...

  pfUINT doublePrecision;
  pfUINT quadDoubleDoublePrecision;
  pfUINT quadDoubleDoublePrecisionDoubleMemory;
  pfUINT halfPrecision;
  pfUINT halfPrecisionMemoryOnly;
  pfUINT doublePrecisionFloatMemory;

  VkFFTPrecision precision;
  VkFFTPrecision execPrecision;

  // ...
} VkFFTConfiguration;

where

The behaviour then would be:

Do I get it right?

And I do not understand why it would be better to define the precision values as macros instead of an enum. What is the motivation?

Thank you.

Best regards David