SpectralOps Usage

Hi there! I’m looking for some help related to SpectralOps.cpp.

I’m essentially trying to create a new CPU kernel—in UnaryKernels.cpp—and in this kernel I want to use the inverse FFT defined in the project, but I’m not being able to use in another .cpp file as there is no header file for these functions.

Let me share an example of a dummy CPU kernel:

static void function_test(TensorIteratorBase& iter, int64_t a, double b) {
  AT_DISPATCH_FLOATING_TYPES_AND(kBFloat16, iter.dtype(), "function_test_cpu", [&](){
    const int64_t c = a + b; // Just an example
    cpu_kernel(iter, [=](scalar_t a){
      // Lines could be added here
      return c * a;
    });
    
    // TODO: Use at::fft_ifft from SpectralOps.cpp
  });
}

Does anybody know how to include these functions? It seems they aren’t used in any part of the codebase, other than creating Python bindings.

Thanks!

I kept digging into the codebase and kernels are generally used to apply operations on Tensors in a point-wise fashion. So, I decided to use at::native::fft_ifft after calling the function_test_stub inside a .cpp file that defines the high-level functions.

For example the following dummy code—which you can assume it’s in a file named Dummy.cpp:

Tensor high_level_function() { 
  // options
  auto input = at::empty(100, options);
  auto iter = TensorIterator::unary_op(input, options);
  auto output = function_test_stub(input);
  output = at::native::fft_ifft(output, -1, -1, "backward");
  return output;
}

But in this dummy file, I had to import the FFT functions, and I decided to create a SpectralOps.h file, which does not exist at the time of this writing.

This is the example of SpectralOps.h:

#pragma once

#include <string>
#include <stdexcept>
#include <sstream>

namespace at { namespace native {

Tensor fft_ifft(const Tensor& self, c10::optional<int64_t> n, int64_t dim,
                c10::optional<c10::string_view> norm);

}} // at::native

If anybody knows another way to do this, that may be the standard of the project or whatever other option, please let me know!