Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,15 @@ prep:
memory_gpu:
multiplier: 1.17
method: direct
remove_stripe_fw:
pattern: sinogram
output_dims_change: False
implementation: gpu_cupy
save_result_default: False
padding: False
memory_gpu:
multiplier: None
method: iterative

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those strings describe how httomo calculates the memory, so far we have only direct and "else". For else we use the name module, which I explain in the comments bellow. But I think you need to make "module" here and make your function iterative bellow.

remove_stripe_ti:
pattern: sinogram
output_dims_change: False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
import numpy as np

from httomo_backends.cufft import CufftType, cufft_estimate_1d
from httomolibgpu.prep.stripe import remove_stripe_fw


__all__ = [
"_calc_memory_bytes_for_slices_remove_stripe_fw",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again httomo will look exactly into a certain name of the function. So your function needs to be:
_calc_memory_bytes_remove_stripe_fw

"_calc_memory_bytes_remove_stripe_ti",
"_calc_memory_bytes_remove_all_stripe",
"_calc_memory_bytes_raven_filter",
Expand All @@ -53,6 +55,14 @@ def _calc_memory_bytes_remove_stripe_ti(
return (tot_memory_bytes, gamma_mem)


def _calc_memory_bytes_for_slices_remove_stripe_fw(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and this should be _calc_memory_bytes_remove_stripe_fw

dims_shape: Tuple[int, int, int],

@dkazanc dkazanc Nov 19, 2025 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then here we have a bigger problem. Passing a 3 values in the tuple why only 2 are accepted. We call that non_slice_dims_shape, which are 2 dimensions of the data that we know. See this function. In the case of the sinogram pattern, these are known shapes: number of angles and detector dimension X. What we don't know is the size of detector Y or the number of slices with the size non_slice_dims_shape we can fit into a GPU.
So when you pass the slices value - this is unknown and needs to be estimated in this function.

dtype: np.dtype,
**kwargs,
) -> int:
return remove_stripe_fw(dims_shape, calc_peak_gpu_mem=True, **kwargs)


def _calc_memory_bytes_remove_all_stripe(
non_slice_dims_shape: Tuple[int, int],
dtype: np.dtype,
Expand Down
30 changes: 30 additions & 0 deletions tests/test_httomolibgpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from httomolibgpu.prep.alignment import distortion_correction_proj_discorpy
from httomolibgpu.prep.stripe import (
remove_stripe_based_sorting,
remove_stripe_fw,
remove_stripe_ti,
remove_all_stripe,
raven_filter,
Expand Down Expand Up @@ -445,6 +446,35 @@ def test_remove_stripe_ti_memoryhook(slices, ensure_clean_memory):
assert percents_relative_maxmem <= 20


@pytest.mark.cupy
@pytest.mark.parametrize("slices", [64, 129])
def test_remove_stripe_fw_memoryhook(slices, ensure_clean_memory):
dim_x = 156
dim_y = 216
data = cp.random.random_sample((slices, dim_x, dim_y), dtype=np.float32)
hook = MaxMemoryHook()
with hook:
remove_stripe_fw(cp.copy(data)).get()
max_mem = (
hook.max_mem
) # the amount of memory in bytes needed for the method according to memoryhook

# now we estimate how much of the total memory required for this data
estimated_memory_bytes = _calc_memory_bytes_for_slices_remove_stripe_fw(
(slices, dim_x, dim_y), dtype=np.float32()
)
estimated_memory_mb = round(estimated_memory_bytes / (1024**2), 2)
max_mem_mb = round(max_mem / (1024**2), 2)

# now we compare both memory estimations
difference_mb = abs(estimated_memory_mb - max_mem_mb)
percents_relative_maxmem = round((difference_mb / max_mem_mb) * 100)
# the estimated_memory_mb should be LARGER or EQUAL to max_mem_mb
# the resulting percent value should not deviate from max_mem on more than 1%
assert estimated_memory_mb >= max_mem_mb
assert percents_relative_maxmem <= 20


@pytest.mark.cupy
@pytest.mark.parametrize("projections", [180, 360, 720, 1080, 1440])
def test_raven_filter_memoryhook(projections, ensure_clean_memory):
Expand Down