Skip to content

Commit 935cfeb

Browse files
committed
fluidfft-builder: few @cython.profile(True)
1 parent 4625f33 commit 935cfeb

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import pstats
2+
import cProfile
3+
4+
from fluidfft.fft3d import get_classes_seq
5+
6+
7+
N = 128
8+
9+
classes = get_classes_seq()
10+
print(classes)
11+
12+
13+
def init_oper(fft_class):
14+
return fft_class(N, N, N)
15+
16+
17+
def run(fft_cls):
18+
print(fft_cls)
19+
o = init_oper(fft_cls)
20+
o.run_tests()
21+
o.run_benchs()
22+
o.run_benchs()
23+
24+
25+
def main():
26+
27+
# no issue with profiling
28+
name = "fft3d.with_pyfftw"
29+
30+
# issue with profiling (before fluidfft-builder 0.0.3): fft functions do not appear
31+
name = "fft3d.with_fftw3d"
32+
cls = classes[name]
33+
run(cls)
34+
35+
36+
# main()
37+
38+
cProfile.runctx("main()", globals(), locals(), "profile.pstats")
39+
40+
s = pstats.Stats("profile.pstats")
41+
# s.strip_dirs().sort_stats('time').print_stats(16)
42+
s.sort_stats("time").print_stats(12)

plugins/fluidfft-builder/fluidfft_builder/templates/template2d.pyx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,20 @@ cdef class ${class_name}:
7575
"""Get the local size in the real space."""
7676
return self.thisptr.get_local_size_X()
7777

78+
@cython.profile(True)
7879
def run_tests(self):
7980
"""Run the c++ tests."""
8081
return self.thisptr.test()
8182

83+
@cython.profile(True)
8284
def run_benchs(self, nb_time_execute=10):
8385
"""Run the c++ benchmarcks"""
8486
cdef DTYPEf_t[:] arr = np.empty([2], DTYPEf)
8587
self.thisptr.bench(nb_time_execute, &arr[0])
8688
if rank == 0:
8789
return arr
8890

91+
@cython.profile(True)
8992
@cython.boundscheck(False)
9093
@cython.wraparound(False)
9194
# @cython.initializedcheck(False)
@@ -94,6 +97,7 @@ cdef class ${class_name}:
9497
"""Perform the fft and copy the result in the second argument."""
9598
self.thisptr.fft(&fieldX[0, 0], <mycomplex*> &fieldK[0, 0])
9699

100+
@cython.profile(True)
97101
@cython.boundscheck(False)
98102
@cython.wraparound(False)
99103
# @cython.initializedcheck(False)
@@ -102,6 +106,7 @@ cdef class ${class_name}:
102106
"""Perform the ifft and copy the result in the second argument."""
103107
self.thisptr.ifft(<mycomplex*> &fieldK[0, 0], &fieldX[0, 0])
104108

109+
@cython.profile(True)
105110
@cython.boundscheck(False)
106111
@cython.wraparound(False)
107112
# @cython.initializedcheck(False)
@@ -112,6 +117,7 @@ cdef class ${class_name}:
112117
self.thisptr.fft(&fieldX[0, 0], <mycomplex*> &fieldK[0, 0])
113118
return fieldK
114119

120+
@cython.profile(True)
115121
@cython.boundscheck(False)
116122
@cython.wraparound(False)
117123
# @cython.initializedcheck(False)
@@ -232,6 +238,7 @@ cdef class ${class_name}:
232238
"""Compute the sum over all wavenumbers."""
233239
return <float> self.thisptr.sum_wavenumbers(&fieldK[0, 0])
234240

241+
@cython.profile(True)
235242
def gather_Xspace(self, ff_loc, root=None):
236243
"""Gather an array in real space for a parallel run."""
237244
cdef np.ndarray[DTYPEf_t, ndim=2] ff_seq
@@ -256,6 +263,7 @@ cdef class ${class_name}:
256263
raise ValueError('root should be an int')
257264
return ff_seq
258265

266+
@cython.profile(True)
259267
def scatter_Xspace(self, ff_seq, root=None):
260268
"""Scatter an array in real space for a parallel run."""
261269
cdef np.ndarray[DTYPEf_t, ndim=2] ff_loc

plugins/fluidfft-builder/fluidfft_builder/templates/template3d.pyx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,20 @@ cdef class ${class_name}:
113113
"""Get the local size in real space."""
114114
return self.thisptr.get_local_size_X()
115115

116+
@cython.profile(True)
116117
def run_tests(self):
117118
"""Run simple tests from C++."""
118119
return self.thisptr.test()
119120

121+
@cython.profile(True)
120122
def run_benchs(self, nb_time_execute=10):
121123
"""Run the C++ benchmarcks."""
122124
cdef DTYPEf_t[:] arr = np.empty([2], DTYPEf)
123125
self.thisptr.bench(nb_time_execute, &arr[0])
124126
if rank == 0:
125127
return arr
126128

129+
@cython.profile(True)
127130
@cython.boundscheck(False)
128131
@cython.wraparound(False)
129132
# @cython.initializedcheck(False)
@@ -136,6 +139,7 @@ cdef class ${class_name}:
136139

137140
self.thisptr.fft(&fieldX[0, 0, 0], <mycomplex*> &fieldK[0, 0, 0])
138141

142+
@cython.profile(True)
139143
@cython.boundscheck(False)
140144
@cython.wraparound(False)
141145
# @cython.initializedcheck(False)
@@ -150,6 +154,7 @@ cdef class ${class_name}:
150154
"""
151155
self.thisptr.ifft(<mycomplex*> &fieldK[0, 0, 0], &fieldX[0, 0, 0])
152156

157+
@cython.profile(True)
153158
@cython.boundscheck(False)
154159
@cython.wraparound(False)
155160
# @cython.initializedcheck(False)
@@ -165,6 +170,7 @@ cdef class ${class_name}:
165170
self.thisptr.ifft_destroy(
166171
<mycomplex*> &fieldK[0, 0, 0], &fieldX[0, 0, 0])
167172

173+
@cython.profile(True)
168174
@cython.boundscheck(False)
169175
@cython.wraparound(False)
170176
# @cython.initializedcheck(False)
@@ -175,6 +181,7 @@ cdef class ${class_name}:
175181
self.thisptr.fft(&fieldX[0, 0, 0], <mycomplex*> &fieldK[0, 0, 0])
176182
return fieldK
177183

184+
@cython.profile(True)
178185
@cython.boundscheck(False)
179186
@cython.wraparound(False)
180187
# @cython.initializedcheck(False)
@@ -203,6 +210,7 @@ cdef class ${class_name}:
203210
self.thisptr.get_global_shape_X(&nX0, &nX1, &nX2)
204211
return nX0, nX1, nX2
205212

213+
@cython.profile(True)
206214
def gather_Xspace(self, ff_loc, root=0):
207215
"""Gather an array in real space for a parallel run.
208216
"""
@@ -268,6 +276,7 @@ cdef class ${class_name}:
268276
raise ValueError('root should be an int')
269277
return ff_seq
270278

279+
@cython.profile(True)
271280
def scatter_Xspace(self, ff_seq, root=0):
272281
"""Scatter an array in real space for a parallel run.
273282
@@ -319,6 +328,7 @@ cdef class ${class_name}:
319328
self.thisptr.get_global_shape_K(&nK0, &nK1, &nK2)
320329
return nK0, nK1, nK2
321330

331+
@cython.profile(True)
322332
def sum_wavenumbers(self, fieldK):
323333
"""Compute the sum over all wavenumbers."""
324334
if fieldK.dtype == np.float64:
@@ -392,6 +402,7 @@ cdef class ${class_name}:
392402

393403
return k0_adim_loc, k1_adim_loc, k2_adim_loc
394404

405+
@cython.profile(True)
395406
def build_invariant_arrayX_from_2d_indices12X(self, o2d, arr2d):
396407
"""Build an array in real space invariant in the third dim."""
397408
nX0, nX1, nX2 = self._shapeX_seq
@@ -418,6 +429,7 @@ cdef class ${class_name}:
418429

419430
return arr3d
420431

432+
@cython.profile(True)
421433
def build_invariant_arrayK_from_2d_indices12X(self, o2d, arr2d):
422434
"""Build an array in Fourier space invariant in the third dim."""
423435
nK0, nK1, nK2 = self._shapeK_seq

plugins/fluidfft-builder/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "flit_core.buildapi"
44

55
[project]
66
name = "fluidfft-builder"
7-
version = "0.0.2"
7+
version = "0.0.3"
88
description = "Fluidfft plugin dependencies"
99
authors = [{name = "Pierre Augier", email = "[email protected]"}]
1010
license = {file = "LICENSE"}

0 commit comments

Comments
 (0)