Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using eigen tensor fft

I had a look at implementing a CPU fft for tensorflow using the eigen tensor fft module. Benoit Steiner offered some advice on how to use it here.

The eigen fft uses the templated type of the corresponding tensor to perform its computation. Unfortunately, the inputs extracted from the OpKernelContext are declared const because inputs are immutable. I thus end up with a bunch of compiler errors that const variables cannot be assigned to (because the TensorFFTOp reuses the templated typename internally).

What's the best way to get around this problem? Some thoughts:

  • use a mutable_input but that seems like bending the API just to get around a problem
  • modify the TensorFFTOp with std::remove_const such that non-const variables are used internally
  • explicitly instantiate the TensorFFTOp rather than using the template member functions defined in TensorBase.h

The last option seems to be the most straightforward but I am struggling with getting all the template arguments right. Any suggestions?

like image 785
Till Hoffmann Avatar asked May 13 '26 08:05

Till Hoffmann


1 Answers

With the help of a co worker, we managed to get the desired behaviour by simply casting the const input array to a non-const one.

typename TTypes<T, 2>::Tensor& casted_input = *reinterpret_cast<typename TTypes<T, 2>::Tensor*>(&input);
auto result = casted_input.template fft<Eigen::BothParts, Eigen::FFT_FORWARD>(dims);
like image 73
Till Hoffmann Avatar answered May 14 '26 22:05

Till Hoffmann