-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathjax_finufft_cpu.h
144 lines (112 loc) · 3.28 KB
/
jax_finufft_cpu.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#ifndef _JAX_FINUFFT_H_
#define _JAX_FINUFFT_H_
#include <fftw3.h>
#include <complex>
#include "finufft.h"
namespace jax_finufft {
namespace cpu {
template <typename T>
struct plan_type;
template <>
struct plan_type<double> {
typedef finufft_plan type;
};
template <>
struct plan_type<float> {
typedef finufftf_plan type;
};
template <typename T>
void default_opts(finufft_opts* opts);
template <>
void default_opts<float>(finufft_opts* opts) {
finufftf_default_opts(opts);
}
template <>
void default_opts<double>(finufft_opts* opts) {
finufft_default_opts(opts);
}
template <typename T>
int makeplan(int type, int dim, int64_t* nmodes, int iflag, int ntr, T eps,
typename plan_type<T>::type* plan, finufft_opts* opts);
template <>
int makeplan<float>(int type, int dim, int64_t* nmodes, int iflag, int ntr, float eps,
typename plan_type<float>::type* plan, finufft_opts* opts) {
return finufftf_makeplan(type, dim, nmodes, iflag, ntr, eps, plan, opts);
}
template <>
int makeplan<double>(int type, int dim, int64_t* nmodes, int iflag, int ntr, double eps,
typename plan_type<double>::type* plan, finufft_opts* opts) {
return finufft_makeplan(type, dim, nmodes, iflag, ntr, eps, plan, opts);
}
template <typename T>
int setpts(typename plan_type<T>::type plan, int64_t M, T* x, T* y, T* z, int64_t N, T* s, T* t,
T* u);
template <>
int setpts<float>(typename plan_type<float>::type plan, int64_t M, float* x, float* y, float* z,
int64_t N, float* s, float* t, float* u) {
return finufftf_setpts(plan, M, x, y, z, N, s, t, u);
}
template <>
int setpts<double>(typename plan_type<double>::type plan, int64_t M, double* x, double* y,
double* z, int64_t N, double* s, double* t, double* u) {
return finufft_setpts(plan, M, x, y, z, N, s, t, u);
}
template <typename T>
int execute(typename plan_type<T>::type plan, std::complex<T>* c, std::complex<T>* f);
template <>
int execute<float>(typename plan_type<float>::type plan, std::complex<float>* c,
std::complex<float>* f) {
return finufftf_execute(plan, c, f);
}
template <>
int execute<double>(typename plan_type<double>::type plan, std::complex<double>* c,
std::complex<double>* f) {
return finufft_execute(plan, c, f);
}
template <typename T>
void destroy(typename plan_type<T>::type plan);
template <>
void destroy<float>(typename plan_type<float>::type plan) {
finufftf_destroy(plan);
}
template <>
void destroy<double>(typename plan_type<double>::type plan) {
finufft_destroy(plan);
}
template <int ndim, typename T>
T* y_index(T* y, int64_t index) {
return &(y[index]);
}
template <>
double* y_index<1, double>(double* y, int64_t index) {
return NULL;
}
template <>
float* y_index<1, float>(float* y, int64_t index) {
return NULL;
}
template <int ndim, typename T>
T* z_index(T* z, int64_t index) {
return NULL;
}
template <>
double* z_index<3, double>(double* z, int64_t index) {
return &(z[index]);
}
template <>
float* z_index<3, float>(float* z, int64_t index) {
return &(z[index]);
}
template <typename T>
struct descriptor {
T eps;
int iflag;
int64_t n_tot;
int n_transf;
int64_t n_j;
int64_t n_k[3];
finufft_opts opts;
};
} // namespace cpu
} // namespace jax_finufft
#endif