Skip to content

Commit d680de8

Browse files
authored
Merge pull request #66 from DiamondLightSource/remove_paganin_savu
Remove paganin savu
2 parents a913636 + 24d0de6 commit d680de8

File tree

5 files changed

+4
-119
lines changed

5 files changed

+4
-119
lines changed

httomo_backends/methods_database/packages/backends/httomolibgpu/httomolibgpu.yaml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,6 @@ prep:
8787
memory_gpu:
8888
multiplier: None
8989
method: module
90-
paganin_filter_savu:
91-
pattern: projection
92-
output_dims_change: False
93-
implementation: gpu_cupy
94-
save_result_default: False
95-
padding: False
96-
memory_gpu:
97-
multiplier: None
98-
method: module
9990
alignment:
10091
distortion_correction_proj_discorpy:
10192
pattern: projection

httomo_backends/methods_database/packages/backends/httomolibgpu/supporting_funcs/prep/phase.py

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -27,70 +27,10 @@
2727
from httomo_backends.cufft import CufftType, cufft_estimate_2d
2828

2929
__all__ = [
30-
"_calc_memory_bytes_paganin_filter_savu",
3130
"_calc_memory_bytes_paganin_filter_tomopy",
3231
]
3332

3433

35-
def _calc_memory_bytes_paganin_filter_savu(
36-
non_slice_dims_shape: Tuple[int, int],
37-
dtype: np.dtype,
38-
**kwargs,
39-
) -> Tuple[int, int]:
40-
pad_x = kwargs["pad_x"]
41-
pad_y = kwargs["pad_y"]
42-
43-
# Input (unpadded)
44-
unpadded_in_slice_size = np.prod(non_slice_dims_shape) * dtype.itemsize
45-
46-
# Padded input
47-
padded_non_slice_dims_shape = (
48-
non_slice_dims_shape[0] + 2 * pad_y,
49-
non_slice_dims_shape[1] + 2 * pad_x,
50-
)
51-
padded_in_slice_size = (
52-
padded_non_slice_dims_shape[0] * padded_non_slice_dims_shape[1] * dtype.itemsize
53-
)
54-
55-
# Padded input cast to `complex64`
56-
complex_slice = padded_in_slice_size / dtype.itemsize * np.complex64().nbytes
57-
58-
# Plan size for 2D FFT
59-
fftplan_slice_size = cufft_estimate_2d(
60-
nx=padded_non_slice_dims_shape[1],
61-
ny=padded_non_slice_dims_shape[0],
62-
fft_type=CufftType.CUFFT_C2C,
63-
)
64-
65-
# Shape of 2D filter is the same as the padded `complex64` slice shape, so the size will be
66-
# the same
67-
filter_size = complex_slice
68-
69-
# Size of cropped/unpadded + cast to float32 result of 2D IFFT
70-
cropped_float32_res_slice = np.prod(non_slice_dims_shape) * np.float32().nbytes
71-
72-
# If the FFT plan size is negligible for some reason, this changes where the peak GPU
73-
# memory usage occurs. Hence, the if/else branching below for calculating the total bytes.
74-
NEGLIGIBLE_FFT_PLAN_SIZE = 16
75-
if fftplan_slice_size < NEGLIGIBLE_FFT_PLAN_SIZE:
76-
tot_memory_bytes = int(
77-
unpadded_in_slice_size + padded_in_slice_size + complex_slice
78-
)
79-
else:
80-
tot_memory_bytes = int(
81-
unpadded_in_slice_size
82-
+ padded_in_slice_size
83-
+ complex_slice
84-
# The padded float32 array is deallocated when a copy is made when casting to complex64
85-
# and the variable `padded_tomo` is reassigned to the complex64 version
86-
- padded_in_slice_size
87-
+ fftplan_slice_size
88-
+ cropped_float32_res_slice
89-
)
90-
91-
return (tot_memory_bytes, filter_size)
92-
93-
9434
def _calc_memory_bytes_paganin_filter_tomopy(
9535
non_slice_dims_shape: Tuple[int, int],
9636
dtype: np.dtype,

httomo_backends/methods_database/packages/backends/httomolibgpu/supporting_funcs/recon/algorithm.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ def add_to_memory_counters(amount, per_slice: bool):
354354

355355
return (tot_memory_bytes * 1.05, fixed_amount + 250 * 1024 * 1024)
356356

357+
357358
def _calc_memory_bytes_SIRT3d_tomobar(
358359
non_slice_dims_shape: Tuple[int, int],
359360
dtype: np.dtype,

httomo_backends/scripts/yaml_pipelines_generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def yaml_pipelines_generator(
235235
pipeline_full[i]["parameters"].yaml_add_eol_comment(
236236
key="detector_pad",
237237
comment="Horizontal detector padding to minimise circle/arc-type artifacts in the reconstruction",
238-
)
238+
)
239239
pipeline_full[i]["parameters"].yaml_add_eol_comment(
240240
key="recon_mask_radius",
241241
comment="Zero pixels outside the mask-circle radius.",

tests/test_httomolibgpu.py

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from httomolibgpu.misc.morph import data_resampler, sino_360_to_180
1717
from httomolibgpu.prep.normalize import normalize
18-
from httomolibgpu.prep.phase import paganin_filter_tomopy, paganin_filter_savu
18+
from httomolibgpu.prep.phase import paganin_filter_tomopy
1919
from httomolibgpu.prep.alignment import distortion_correction_proj_discorpy
2020
from httomolibgpu.prep.stripe import (
2121
remove_stripe_based_sorting,
@@ -257,48 +257,6 @@ def test_paganin_filter_tomopy_memoryhook(slices, dim_x, dim_y, ensure_clean_mem
257257
assert percents_relative_maxmem <= 20
258258

259259

260-
@pytest.mark.cupy
261-
@pytest.mark.parametrize("slices", [64, 128])
262-
@pytest.mark.parametrize("dim_x", [81, 260, 320])
263-
@pytest.mark.parametrize("dim_y", [340, 135, 96])
264-
def test_paganin_filter_savu_memoryhook(slices, dim_x, dim_y, ensure_clean_memory):
265-
data = cp.random.random_sample((slices, dim_x, dim_y), dtype=np.float32)
266-
kwargs = {}
267-
kwargs["ratio"] = 250.0
268-
kwargs["energy"] = 53.0
269-
kwargs["distance"] = 1.0
270-
kwargs["resolution"] = 1.28
271-
kwargs["pad_x"] = 20
272-
kwargs["pad_y"] = 20
273-
kwargs["pad_method"] = "edge"
274-
kwargs["increment"] = 0.0
275-
hook = MaxMemoryHook()
276-
with hook:
277-
data_filtered = paganin_filter_savu(data, **kwargs).get()
278-
279-
# The amount of bytes used by the method's processing according to the memory hook, plus
280-
# the amount of bytes needed to hold the method's input in GPU memory
281-
max_mem = hook.max_mem + data.nbytes
282-
283-
# now we estimate how much of the total memory required for this data
284-
(estimated_memory_bytes, subtract_bytes) = _calc_memory_bytes_paganin_filter_savu(
285-
(dim_x, dim_y), np.float32(), **kwargs
286-
)
287-
estimated_memory_mb = round(slices * estimated_memory_bytes / (1024**2), 2)
288-
max_mem -= subtract_bytes
289-
max_mem_mb = round(max_mem / (1024**2), 2)
290-
291-
# now we compare both memory estimations
292-
#
293-
# make sure estimator function is within range (80% min, 100% max)
294-
difference_mb = abs(estimated_memory_mb - max_mem_mb)
295-
percents_relative_maxmem = round((difference_mb / max_mem_mb) * 100)
296-
# the estimated_memory_mb should be LARGER or EQUAL to max_mem_mb
297-
# the resulting percent value should not deviate from max_mem on more than 20%
298-
assert estimated_memory_mb >= max_mem_mb
299-
assert percents_relative_maxmem <= 20
300-
301-
302260
@pytest.mark.cupy
303261
@pytest.mark.parametrize("slices", [128, 190, 256])
304262
def test_distortion_correction_memoryhook(
@@ -719,12 +677,7 @@ def __test_recon_LPRec3d_tomobar_memoryhook_common(
719677
# the estimated_memory_mb should be LARGER or EQUAL to max_mem_mb
720678
# the resulting percent value should not deviate from max_mem on more than 20%
721679
assert estimated_memory_mb >= max_mem_mb
722-
if slices <= 3:
723-
assert percents_relative_maxmem <= 75
724-
elif slices <= 5:
725-
assert percents_relative_maxmem <= 63
726-
else:
727-
assert percents_relative_maxmem <= 50
680+
assert percents_relative_maxmem <= 80
728681

729682

730683
@pytest.mark.cupy

0 commit comments

Comments
 (0)