Skip to content

Commit bea179d

Browse files
committed
Utils and tests for remove_stripe_fw
1 parent 6b0bb54 commit bea179d

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,15 @@ prep:
107107
memory_gpu:
108108
multiplier: 1.17
109109
method: direct
110+
remove_stripe_fw:
111+
pattern: sinogram
112+
output_dims_change: False
113+
implementation: gpu_cupy
114+
save_result_default: False
115+
padding: False
116+
memory_gpu:
117+
multiplier: None
118+
method: iterative
110119
remove_stripe_ti:
111120
pattern: sinogram
112121
output_dims_change: False

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@
2525
import numpy as np
2626

2727
from httomo_backends.cufft import CufftType, cufft_estimate_1d
28+
from httomolibgpu.prep.stripe import DeviceMemStack, remove_stripe_fw
2829

2930

3031
__all__ = [
32+
"_calc_memory_bytes_for_slices_remove_stripe_fw",
3133
"_calc_memory_bytes_remove_stripe_ti",
3234
"_calc_memory_bytes_remove_all_stripe",
3335
"_calc_memory_bytes_raven_filter",
@@ -53,6 +55,16 @@ def _calc_memory_bytes_remove_stripe_ti(
5355
return (tot_memory_bytes, gamma_mem)
5456

5557

58+
def _calc_memory_bytes_for_slices_remove_stripe_fw(
59+
dims_shape: Tuple[int, int, int],
60+
dtype: np.dtype,
61+
**kwargs,
62+
) -> Tuple[int, int]:
63+
mem_stack = DeviceMemStack()
64+
remove_stripe_fw(dims_shape, mem_stack=mem_stack, **kwargs)
65+
return mem_stack.highwater, 0
66+
67+
5668
def _calc_memory_bytes_remove_all_stripe(
5769
non_slice_dims_shape: Tuple[int, int],
5870
dtype: np.dtype,

tests/test_httomolibgpu.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from httomolibgpu.prep.alignment import distortion_correction_proj_discorpy
2020
from httomolibgpu.prep.stripe import (
2121
remove_stripe_based_sorting,
22+
remove_stripe_fw,
2223
remove_stripe_ti,
2324
remove_all_stripe,
2425
raven_filter,
@@ -376,6 +377,36 @@ def test_remove_stripe_ti_memoryhook(slices, ensure_clean_memory):
376377
assert percents_relative_maxmem <= 20
377378

378379

380+
@pytest.mark.cupy
381+
@pytest.mark.parametrize("slices", [64, 129])
382+
def test_remove_stripe_fw_memoryhook(slices, ensure_clean_memory):
383+
dim_x = 156
384+
dim_y = 216
385+
data = cp.random.random_sample((slices, dim_x, dim_y), dtype=np.float32)
386+
hook = MaxMemoryHook()
387+
with hook:
388+
remove_stripe_fw(cp.copy(data)).get()
389+
max_mem = (
390+
hook.max_mem
391+
) # the amount of memory in bytes needed for the method according to memoryhook
392+
393+
# now we estimate how much of the total memory required for this data
394+
(estimated_memory_bytes, subtract_bytes) = _calc_memory_bytes_remove_stripe_fw(
395+
(slices, dim_x, dim_y), dtype=np.float32()
396+
)
397+
estimated_memory_mb = round(estimated_memory_bytes / (1024**2), 2)
398+
max_mem -= subtract_bytes
399+
max_mem_mb = round(max_mem / (1024**2), 2)
400+
401+
# now we compare both memory estimations
402+
difference_mb = abs(estimated_memory_mb - max_mem_mb)
403+
percents_relative_maxmem = round((difference_mb / max_mem_mb) * 100)
404+
# the estimated_memory_mb should be LARGER or EQUAL to max_mem_mb
405+
# the resulting percent value should not deviate from max_mem on more than 1%
406+
assert estimated_memory_mb >= max_mem_mb
407+
assert percents_relative_maxmem <= 1
408+
409+
379410
@pytest.mark.cupy
380411
@pytest.mark.parametrize("projections", [180, 360, 720, 1080, 1440])
381412
def test_raven_filter_memoryhook(projections, ensure_clean_memory):

0 commit comments

Comments
 (0)