Skip to content

Commit 3b07f5e

Browse files
Merge pull request #731 from DiamondLightSource/peak-reslice-estimator
Add CPU estimation of largest reslice in pipeline
2 parents e8dbf55 + 7052305 commit 3b07f5e

2 files changed

Lines changed: 28 additions & 13 deletions

File tree

‎httomo/cli.py‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -562,17 +562,18 @@ def estimate_cpu_memory(in_data_file: Path, pipeline_file: Path, nprocs: int) ->
562562

563563
section_memory_peak = 0
564564
for idx in range(len(sections)):
565+
mem, previewed_shape = estimate_section_memory(
566+
nprocs,
567+
0,
568+
None,
569+
dtype,
570+
previewed_shape,
571+
sections,
572+
idx,
573+
)
565574
section_memory_peak = max(
566575
section_memory_peak,
567-
estimate_section_memory(
568-
nprocs,
569-
0,
570-
None,
571-
dtype,
572-
previewed_shape,
573-
sections,
574-
idx,
575-
),
576+
mem,
576577
)
577578

578579
return section_memory_peak

‎httomo/runner/dataset_store_backing.py‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def calculate_section_output_chunk_shape(
5252
for method in section.methods:
5353
if method.memory_gpu is None:
5454
continue
55-
output_non_slice_dims = method.calculate_output_dims(input_non_slice_dims)
55+
output_non_slice_dims = method.calculate_output_dims(output_non_slice_dims)
5656

5757
output_chunk_shape = list(output_non_slice_dims)
5858
output_chunk_shape.insert(slicing_dim, chunk_shape[slicing_dim])
@@ -74,7 +74,7 @@ def estimate_section_memory(
7474
sections: List[Section],
7575
section_idx: int,
7676
consider_pinned_memory_pool: bool = False,
77-
) -> int:
77+
) -> tuple[int, tuple[int, int, int]]:
7878
# Get chunk shape created by reader of section `n` (the current section) that will account
7979
# for padding. This chunk shape is based on the chunk shape written by the writer of
8080
# section `n - 1` (the previous section)
@@ -150,12 +150,26 @@ def estimate_section_memory(
150150
# See https://github.com/cupy/cupy/issues/9813
151151
cupy_transfer_overhead = total_mem
152152

153+
# Calculate the shape of the global data of the output of the section to pass back to the
154+
# caller.
155+
#
156+
# NOTE: The caller will only use this if performing CPU memory estimation of the entire
157+
# pipeline not at runtime of htttomo (ie, the `memory-check` CLI command). If performing
158+
# CPU memory estimation of a section during runtime of httomo, the caller won't use this
159+
# value.
160+
current_section_slicing_dim = _get_slicing_dim(sections[section_idx].pattern) - 1
161+
output_global_shape = list(output_chunk_shape)
162+
output_global_shape[current_section_slicing_dim] = (
163+
output_global_shape[current_section_slicing_dim] * nprocs
164+
)
165+
153166
return (
154167
padded_input_chunk_bytes
155168
+ output_chunk_bytes
156169
+ reslice_bytes
157170
+ cupy_pinned_cpu_pool_memory
158-
+ cupy_transfer_overhead
171+
+ cupy_transfer_overhead,
172+
output_global_shape,
159173
)
160174

161175

@@ -167,7 +181,7 @@ def determine_store_backing(
167181
global_shape: Tuple[int, int, int],
168182
section_idx: int,
169183
) -> DataSetStoreBacking:
170-
section_memory = estimate_section_memory(
184+
section_memory, _ = estimate_section_memory(
171185
comm.size,
172186
comm.rank,
173187
comm.allgather,

0 commit comments

Comments
 (0)