Skip to content

Commit f73d053

Browse files
committed
modifications of the estimators for recon methods and tests updated
1 parent 480eb53 commit f73d053

File tree

2 files changed

+71
-27
lines changed

2 files changed

+71
-27
lines changed

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ def _calc_memory_bytes_LPRec3d_tomobar(
175175
detector_pad = 0
176176

177177
angles_tot = non_slice_dims_shape[0]
178+
DetectorsLengthH_prepad = non_slice_dims_shape[1]
178179
DetectorsLengthH = non_slice_dims_shape[1] + 2 * detector_pad
179180
SLICES = 200 # dummy multiplier+divisor to pass large batch size threshold
180181
_CENTER_SIZE_MIN = 192 # must be divisible by 8
@@ -264,7 +265,9 @@ def _calc_memory_bytes_LPRec3d_tomobar(
264265
center_size * center_size * (1 + angle_range_pi_count * 2) * np.int16().itemsize
265266
)
266267

267-
recon_output_size = DetectorsLengthH * DetectorsLengthH * np.float32().itemsize
268+
recon_output_size = (
269+
DetectorsLengthH_prepad * DetectorsLengthH_prepad * np.float32().itemsize
270+
)
268271
ifft2_plan_slice_size = (
269272
cufft_estimate_2d(
270273
nx=(2 * m + 2 * n), ny=(2 * m + 2 * n), fft_type=CufftType.CUFFT_C2C
@@ -349,7 +352,7 @@ def add_to_memory_counters(amount, per_slice: bool):
349352
add_to_memory_counters(circular_mask_size, False)
350353
add_to_memory_counters(after_recon_swapaxis_slice, True)
351354

352-
return (tot_memory_bytes * 1.05, fixed_amount + 250 * 1024 * 1024)
355+
return (int(tot_memory_bytes * 1.05), fixed_amount + 250 * 1024 * 1024)
353356
# return (tot_memory_bytes, fixed_amount)
354357

355358

@@ -373,7 +376,7 @@ def _calc_memory_bytes_SIRT3d_tomobar(
373376

374377
astra_projection = 2.5 * (in_data_size + out_data_size)
375378

376-
tot_memory_bytes = 2 * in_data_size + 2 * out_data_size + astra_projection
379+
tot_memory_bytes = int(2 * in_data_size + 2 * out_data_size + astra_projection)
377380
return (tot_memory_bytes, 0)
378381

379382

@@ -382,14 +385,20 @@ def _calc_memory_bytes_CGLS3d_tomobar(
382385
dtype: np.dtype,
383386
**kwargs,
384387
) -> Tuple[int, int]:
385-
DetectorsLengthH = non_slice_dims_shape[1]
388+
if "detector_pad" in kwargs:
389+
detector_pad = kwargs["detector_pad"]
390+
else:
391+
detector_pad = 0
392+
393+
anglesnum = non_slice_dims_shape[0]
394+
DetectorsLengthH = non_slice_dims_shape[1] + 2 * detector_pad
386395
# calculate the output shape
387396
output_dims = _calc_output_dim_CGLS3d_tomobar(non_slice_dims_shape, **kwargs)
388397

389-
in_data_size = np.prod(non_slice_dims_shape) * dtype.itemsize
398+
in_data_size = (anglesnum * DetectorsLengthH) * dtype.itemsize
390399
out_data_size = np.prod(output_dims) * dtype.itemsize
391400

392401
astra_projection = 2.5 * (in_data_size + out_data_size)
393402

394-
tot_memory_bytes = 2 * in_data_size + 2 * out_data_size + astra_projection
403+
tot_memory_bytes = int(2 * in_data_size + 2 * out_data_size + astra_projection)
395404
return (tot_memory_bytes, 0)

tests/test_httomolibgpu.py

Lines changed: 56 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -528,17 +528,24 @@ def test_data_sampler_memoryhook(slices, newshape, interpolation, ensure_clean_m
528528

529529

530530
@pytest.mark.cupy
531+
@pytest.mark.parametrize("padding_detx", [0, 10, 100, 200])
531532
@pytest.mark.parametrize("projections", [1801, 3601])
532533
@pytest.mark.parametrize("slices", [7, 11, 15])
533534
@pytest.mark.parametrize("detectorX", [1200, 2560])
534535
def test_recon_FBP3d_tomobar_memoryhook(
535-
slices, detectorX, projections, ensure_clean_memory, mocker: MockerFixture
536+
slices,
537+
detectorX,
538+
projections,
539+
padding_detx,
540+
ensure_clean_memory,
541+
mocker: MockerFixture,
536542
):
537543
data = cp.random.random_sample((projections, slices, detectorX), dtype=np.float32)
538544
kwargs = {}
539545
kwargs["angles"] = np.linspace(
540546
0.0 * np.pi / 180.0, 180.0 * np.pi / 180.0, data.shape[0]
541547
)
548+
kwargs["detector_pad"] = padding_detx
542549
kwargs["center"] = 500
543550
kwargs["recon_size"] = detectorX
544551
kwargs["recon_mask_radius"] = 0.8
@@ -579,61 +586,88 @@ def test_recon_FBP3d_tomobar_memoryhook(
579586

580587

581588
@pytest.mark.cupy
582-
# @pytest.mark.parametrize("projections", [1801])
583-
# @pytest.mark.parametrize("detX_size", [2560])
584-
# @pytest.mark.parametrize("slices", [15])
585-
# @pytest.mark.parametrize("projection_angle_range", [(0, np.pi)])
586-
587-
589+
@pytest.mark.parametrize("padding_detx", [0, 10, 50, 100])
588590
@pytest.mark.parametrize("projections", [1500, 1801, 2560])
589591
@pytest.mark.parametrize("detX_size", [2560])
590592
@pytest.mark.parametrize("slices", [3, 4, 5, 10, 15, 20])
591593
@pytest.mark.parametrize("projection_angle_range", [(0, np.pi)])
592-
593-
# @pytest.mark.parametrize("projections", [1500, 1801, 2560])
594-
# @pytest.mark.parametrize("detX_size", [2560])
595-
# @pytest.mark.parametrize("slices", [3, 4, 5, 10])
596-
# @pytest.mark.parametrize("projection_angle_range", [(0, np.pi)])
597594
def test_recon_LPRec3d_tomobar_0_pi_memoryhook(
598-
slices, detX_size, projections, projection_angle_range, ensure_clean_memory
595+
slices,
596+
detX_size,
597+
projections,
598+
projection_angle_range,
599+
padding_detx,
600+
ensure_clean_memory,
599601
):
600602
__test_recon_LPRec3d_tomobar_memoryhook_common(
601-
slices, detX_size, projections, projection_angle_range, ensure_clean_memory
603+
slices,
604+
detX_size,
605+
projections,
606+
projection_angle_range,
607+
padding_detx,
608+
ensure_clean_memory,
602609
)
603610

604611

605612
@pytest.mark.full
606613
@pytest.mark.cupy
614+
@pytest.mark.parametrize("padding_detx", [0, 10, 50, 100])
607615
@pytest.mark.parametrize("projections", [1500, 1801, 2560, 3601])
608616
@pytest.mark.parametrize("detX_size", [2560])
609617
@pytest.mark.parametrize("slices", [3, 4, 5, 10, 15, 20])
610618
@pytest.mark.parametrize("projection_angle_range", [(0, np.pi)])
611619
def test_recon_LPRec3d_tomobar_0_pi_memoryhook_full(
612-
slices, detX_size, projections, projection_angle_range, ensure_clean_memory
620+
slices,
621+
detX_size,
622+
projections,
623+
projection_angle_range,
624+
padding_detx,
625+
ensure_clean_memory,
613626
):
614627
__test_recon_LPRec3d_tomobar_memoryhook_common(
615-
slices, detX_size, projections, projection_angle_range, ensure_clean_memory
628+
slices,
629+
detX_size,
630+
projections,
631+
projection_angle_range,
632+
padding_detx,
633+
ensure_clean_memory,
616634
)
617635

618636

619637
@pytest.mark.full
620638
@pytest.mark.cupy
639+
@pytest.mark.parametrize("padding_detx", [0, 10, 50, 100])
621640
@pytest.mark.parametrize("projections", [1500, 1801, 2560, 3601])
622641
@pytest.mark.parametrize("detX_size", [2560])
623642
@pytest.mark.parametrize("slices", [3, 4, 5, 10, 15, 20])
624643
@pytest.mark.parametrize(
625644
"projection_angle_range", [(0, np.pi), (0, 2 * np.pi), (-np.pi / 2, np.pi / 2)]
626645
)
627646
def test_recon_LPRec3d_tomobar_memoryhook_full(
628-
slices, detX_size, projections, projection_angle_range, ensure_clean_memory
647+
slices,
648+
detX_size,
649+
projections,
650+
projection_angle_range,
651+
padding_detx,
652+
ensure_clean_memory,
629653
):
630654
__test_recon_LPRec3d_tomobar_memoryhook_common(
631-
slices, detX_size, projections, projection_angle_range, ensure_clean_memory
655+
slices,
656+
detX_size,
657+
projections,
658+
projection_angle_range,
659+
padding_detx,
660+
ensure_clean_memory,
632661
)
633662

634663

635664
def __test_recon_LPRec3d_tomobar_memoryhook_common(
636-
slices, detX_size, projections, projection_angle_range, ensure_clean_memory
665+
slices,
666+
detX_size,
667+
projections,
668+
projection_angle_range,
669+
padding_detx,
670+
ensure_clean_memory,
637671
):
638672
angles_number = projections
639673
data = cp.random.random_sample((angles_number, slices, detX_size), dtype=np.float32)
@@ -642,6 +676,7 @@ def __test_recon_LPRec3d_tomobar_memoryhook_common(
642676
projection_angle_range[0], projection_angle_range[1], data.shape[0]
643677
)
644678
kwargs["center"] = 1280
679+
kwargs["detector_pad"] = padding_detx
645680
kwargs["recon_size"] = detX_size
646681
kwargs["recon_mask_radius"] = 0.8
647682

@@ -687,9 +722,9 @@ def __test_recon_LPRec3d_tomobar_memoryhook_common(
687722
if slices <= 3:
688723
assert percents_relative_maxmem <= 75
689724
elif slices <= 5:
690-
assert percents_relative_maxmem <= 60
725+
assert percents_relative_maxmem <= 63
691726
else:
692-
assert percents_relative_maxmem <= 47
727+
assert percents_relative_maxmem <= 50
693728

694729

695730
@pytest.mark.cupy

0 commit comments

Comments
 (0)