Coverage Report

Created: 2024-05-04 12:45

/proc/self/cwd/external/ducc/google/fft.cc
Line
Count
Source (jump to first uncovered line)
1
/* Copyright 2023 The TensorFlow Authors. All Rights Reserved.
2
3
Licensed under the Apache License, Version 2.0 (the "License");
4
you may not use this file except in compliance with the License.
5
You may obtain a copy of the License at
6
7
    http://www.apache.org/licenses/LICENSE-2.0
8
9
Unless required by applicable law or agreed to in writing, software
10
distributed under the License is distributed on an "AS IS" BASIS,
11
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
See the License for the specific language governing permissions and
13
limitations under the License.
14
==============================================================================*/
15
#include "ducc/google/fft.h"
16
17
#include <complex>
18
#include <cstddef>
19
#include <cstdlib>
20
#include <exception>
21
#include <iostream>
22
#include <ostream>
23
#include <vector>
24
25
#include "ducc/google/threading.h"
26
#include "ducc/src/ducc0/fft/fft.h"
27
#include "ducc/src/ducc0/fft/fft1d_impl.h"  // IWYU pragma: keep, DUCC definitions.
28
#include "ducc/src/ducc0/fft/fftnd_impl.h"  // IWYU pragma: keep, DUCC definitions.
29
#include "ducc/src/ducc0/infra/mav.h"
30
#include "ducc/src/ducc0/infra/threading.h"
31
#include "unsupported/Eigen/CXX11/ThreadPool"
32
33
namespace ducc0 {
34
35
// Wrappers around DUCC calls.
36
namespace google {
37
38
using Shape = std::vector<std::size_t>;
39
using Stride = std::vector<std::ptrdiff_t>;
40
41
template <typename RealScalar>
42
void c2c(const std::complex<RealScalar>* in, const Shape& in_shape,
43
         const Stride& in_stride, std::complex<RealScalar>* out,
44
         const Shape& out_shape, const Stride& out_stride, const Shape& axes,
45
         bool forward, RealScalar scale,
46
0
         Eigen::ThreadPoolInterface* thread_pool) {
47
0
  ducc0::cfmav<std::complex<RealScalar>> m_in(in, in_shape, in_stride);
48
0
  ducc0::vfmav<std::complex<RealScalar>> m_out(out, out_shape, out_stride);
49
50
0
  try {
51
0
    if (thread_pool == nullptr) {
52
      // Use a fake threadpool.
53
0
      ducc0::google::NoThreadPool no_thread_pool;
54
0
      ducc0::detail_threading::ScopedUseThreadPool thread_pool_guard(
55
0
          no_thread_pool);
56
0
      ducc0::c2c(m_in, m_out, axes, forward, scale, 1);
57
0
    } else {
58
0
      EigenThreadPool eigen_thread_pool(*thread_pool);
59
0
      ducc0::detail_threading::ScopedUseThreadPool thread_pool_guard(
60
0
          eigen_thread_pool);
61
0
      ducc0::c2c(m_in, m_out, axes, forward, scale,
62
0
                 eigen_thread_pool.nthreads());
63
0
    }
64
0
  } catch (const std::exception& ex) {
65
0
    std::cerr << "DUCC FFT c2c failed: " << ex.what() << std::endl;
66
0
    std::abort();
67
0
  }
68
0
}
Unexecuted instantiation: void ducc0::google::c2c<float>(std::__1::complex<float> const*, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, std::__1::vector<long, std::__1::allocator<long> > const&, std::__1::complex<float>*, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, std::__1::vector<long, std::__1::allocator<long> > const&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, bool, float, Eigen::ThreadPoolInterface*)
Unexecuted instantiation: void ducc0::google::c2c<double>(std::__1::complex<double> const*, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, std::__1::vector<long, std::__1::allocator<long> > const&, std::__1::complex<double>*, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, std::__1::vector<long, std::__1::allocator<long> > const&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, bool, double, Eigen::ThreadPoolInterface*)
69
70
template <typename RealScalar>
71
void r2c(const RealScalar* in, const Shape& in_shape, const Stride& in_stride,
72
         std::complex<RealScalar>* out, const Shape& out_shape,
73
         const Stride& out_stride, const Shape& axes, bool forward,
74
0
         RealScalar scale, Eigen::ThreadPoolInterface* thread_pool) {
75
0
  ducc0::cfmav<RealScalar> m_in(in, in_shape, in_stride);
76
0
  ducc0::vfmav<std::complex<RealScalar>> m_out(out, out_shape, out_stride);
77
78
0
  try {
79
0
    if (thread_pool == nullptr) {
80
      // Use a fake threadpool.
81
0
      ducc0::google::NoThreadPool no_thread_pool;
82
0
      ducc0::detail_threading::ScopedUseThreadPool thread_pool_guard(
83
0
          no_thread_pool);
84
0
      ducc0::r2c(m_in, m_out, axes, forward, scale, 1);
85
0
    } else {
86
0
      EigenThreadPool eigen_thread_pool(*thread_pool);
87
0
      ducc0::detail_threading::ScopedUseThreadPool thread_pool_guard(
88
0
          eigen_thread_pool);
89
0
      ducc0::r2c(m_in, m_out, axes, forward, scale,
90
0
                 eigen_thread_pool.nthreads());
91
0
    }
92
0
  } catch (const std::exception& ex) {
93
0
    std::cerr << "DUCC FFT r2c failed: " << ex.what() << std::endl;
94
0
    std::abort();
95
0
  }
96
0
}
Unexecuted instantiation: void ducc0::google::r2c<float>(float const*, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, std::__1::vector<long, std::__1::allocator<long> > const&, std::__1::complex<float>*, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, std::__1::vector<long, std::__1::allocator<long> > const&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, bool, float, Eigen::ThreadPoolInterface*)
Unexecuted instantiation: void ducc0::google::r2c<double>(double const*, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, std::__1::vector<long, std::__1::allocator<long> > const&, std::__1::complex<double>*, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, std::__1::vector<long, std::__1::allocator<long> > const&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, bool, double, Eigen::ThreadPoolInterface*)
97
98
template <typename RealScalar>
99
void c2r(const std::complex<RealScalar>* in, const Shape& in_shape,
100
         const Stride& in_stride, RealScalar* out, const Shape& out_shape,
101
         const Stride& out_stride, const Shape& axes, bool forward,
102
0
         RealScalar scale, Eigen::ThreadPoolInterface* thread_pool) {
103
0
  ducc0::cfmav<std::complex<RealScalar>> m_in(in, in_shape, in_stride);
104
0
  ducc0::vfmav<RealScalar> m_out(out, out_shape, out_stride);
105
106
0
  try {
107
0
    if (thread_pool == nullptr) {
108
      // Use a fake threadpool.
109
0
      ducc0::google::NoThreadPool no_thread_pool;
110
0
      ducc0::detail_threading::ScopedUseThreadPool thread_pool_guard(
111
0
          no_thread_pool);
112
0
      ducc0::c2r(m_in, m_out, axes, forward, scale, 1);
113
0
    } else {
114
0
      EigenThreadPool eigen_thread_pool(*thread_pool);
115
0
      ducc0::detail_threading::ScopedUseThreadPool thread_pool_guard(
116
0
          eigen_thread_pool);
117
0
      ducc0::c2r(m_in, m_out, axes, forward, scale,
118
0
                 eigen_thread_pool.nthreads());
119
0
    }
120
0
  } catch (const std::exception& ex) {
121
0
    std::cerr << "DUCC FFT c2r failed: " << ex.what() << std::endl;
122
0
    std::abort();
123
0
  }
124
0
}
Unexecuted instantiation: void ducc0::google::c2r<float>(std::__1::complex<float> const*, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, std::__1::vector<long, std::__1::allocator<long> > const&, float*, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, std::__1::vector<long, std::__1::allocator<long> > const&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, bool, float, Eigen::ThreadPoolInterface*)
Unexecuted instantiation: void ducc0::google::c2r<double>(std::__1::complex<double> const*, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, std::__1::vector<long, std::__1::allocator<long> > const&, double*, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, std::__1::vector<long, std::__1::allocator<long> > const&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, bool, double, Eigen::ThreadPoolInterface*)
125
126
#define FFT_DEFINITIONS(RealScalar)                                            \
127
  template void c2c<RealScalar>(                                               \
128
      const std::complex<RealScalar>* in, const Shape& in_shape,               \
129
      const Stride& in_stride, std::complex<RealScalar>* out,                  \
130
      const Shape& out_shape, const Stride& out_stride, const Shape& axes,     \
131
      bool forward, RealScalar scale,                                          \
132
      Eigen::ThreadPoolInterface* thread_pool);                                \
133
  template void r2c<RealScalar>(                                               \
134
      const RealScalar* in, const Shape& in_shape, const Stride& in_stride,    \
135
      std::complex<RealScalar>* out, const Shape& out_shape,                   \
136
      const Stride& out_stride, const Shape& axes, bool forward,               \
137
      RealScalar scale, Eigen::ThreadPoolInterface* thread_pool);              \
138
  template void c2r(const std::complex<RealScalar>* in, const Shape& in_shape, \
139
                    const Stride& in_stride, RealScalar* out,                  \
140
                    const Shape& out_shape, const Stride& out_stride,          \
141
                    const Shape& axes, bool forward, RealScalar scale,         \
142
                    Eigen::ThreadPoolInterface* thread_pool)
143
FFT_DEFINITIONS(float);
144
FFT_DEFINITIONS(double);
145
#undef FFT_DEFINITIONS
146
147
}  // namespace google
148
}  // namespace ducc0