33import pytest
44from cupy .cuda import nvtx
55import time
6+ from math import isclose
67
78from httomolibgpu .prep .normalize import normalize
89from httomolibgpu .recon .algorithm import (
910 FBP ,
1011 LPRec ,
1112)
13+ from httomolibgpu .misc .morph import sino_360_to_180
1214from numpy .testing import assert_allclose
1315import time
1416import pytest
1517from cupy .cuda import nvtx
18+ from conftest import force_clean_gpu_memory
1619
17- def test_reconstruct_FBP_i12_dataset1 (i12_dataset1 , ensure_clean_memory ):
1820
21+ def test_reconstruct_FBP_i12_dataset1 (i12_dataset1 ):
22+ force_clean_gpu_memory ()
1923 projdata = i12_dataset1 [0 ]
2024 angles = i12_dataset1 [1 ]
2125 flats = i12_dataset1 [2 ]
@@ -24,22 +28,64 @@ def test_reconstruct_FBP_i12_dataset1(i12_dataset1, ensure_clean_memory):
2428
2529 data_normalised = normalize (projdata , flats , darks , minus_log = True )
2630 del flats , darks , projdata
27- ensure_clean_memory
31+ force_clean_gpu_memory ()
2832
2933 recon_data = FBP (
3034 data_normalised ,
3135 np .deg2rad (angles ),
3236 center = 1253.75 ,
33- filter_freq_cutoff = 0.35 ,
37+ filter_freq_cutoff = 0.35 ,
3438 )
3539 assert recon_data .flags .c_contiguous
3640 recon_data = recon_data .get ()
3741 assert_allclose (np .sum (recon_data ), 46569.395 , rtol = 1e-07 , atol = 1e-6 )
3842 assert recon_data .dtype == np .float32
3943 assert recon_data .shape == (2560 , 50 , 2560 )
4044
45+
46+ def test_reconstruct_LP_REC_i13_dataset1 (i13_dataset1 ):
47+ force_clean_gpu_memory ()
48+ projdata = i13_dataset1 [0 ]
49+ angles = i13_dataset1 [1 ]
50+ flats = i13_dataset1 [2 ]
51+ darks = i13_dataset1 [3 ]
52+ del i13_dataset1
53+
54+ data_normalised = normalize (projdata , flats , darks , minus_log = True )
55+ del flats , darks , projdata
56+ force_clean_gpu_memory ()
57+
58+ stiched_data_180degrees = sino_360_to_180 (
59+ data_normalised [:, 2 :3 , :], overlap = 473.822265625 , rotation = "right"
60+ )
61+ del data_normalised
62+ force_clean_gpu_memory ()
63+
64+ # GPU archetictures older than 5.3 wont accept the data larger than
65+ # (4096, 4096, 4096), while the newer ones can accept (16384 x 16384 x 16384)
66+
67+ # recon_data = FBP(
68+ # stiched_data_180degrees,
69+ # np.deg2rad(angles[0:3000]),
70+ # center=2322,
71+ # filter_freq_cutoff=0.35,
72+ # )
73+ recon_data = LPRec (
74+ data = stiched_data_180degrees ,
75+ angles = np .deg2rad (angles [0 :3000 ]),
76+ center = 2322.08 ,
77+ )
78+
79+ assert recon_data .flags .c_contiguous
80+ recon_data = recon_data .get ()
81+ assert isclose (np .sum (recon_data ), 620.856 , abs_tol = 10 ** - 3 )
82+ assert recon_data .dtype == np .float32
83+ assert recon_data .shape == (4646 , 1 , 4646 )
84+
85+
4186@pytest .mark .perf
42- def test_FBP_performance_i13_dataset2 (i13_dataset2 , ensure_clean_memory ):
87+ def test_FBP_performance_i13_dataset2 (i13_dataset2 ):
88+ force_clean_gpu_memory ()
4389 dev = cp .cuda .Device ()
4490 projdata = i13_dataset2 [0 ]
4591 angles = i13_dataset2 [1 ]
@@ -49,25 +95,25 @@ def test_FBP_performance_i13_dataset2(i13_dataset2, ensure_clean_memory):
4995
5096 data_normalised = normalize (projdata , flats , darks , minus_log = True )
5197 del flats , darks , projdata
52- ensure_clean_memory
98+ force_clean_gpu_memory ()
5399
54100 # cold run first
55101 FBP (
56102 data_normalised ,
57103 np .deg2rad (angles ),
58104 center = 1253.75 ,
59105 filter_freq_cutoff = 0.35 ,
60- )
106+ )
61107 dev .synchronize ()
62108
63109 start = time .perf_counter_ns ()
64110 nvtx .RangePush ("Core" )
65111 for _ in range (10 ):
66112 FBP (
67- data_normalised ,
68- np .deg2rad (angles ),
69- center = 1286.25 ,
70- filter_freq_cutoff = 0.35 ,
113+ data_normalised ,
114+ np .deg2rad (angles ),
115+ center = 1286.25 ,
116+ filter_freq_cutoff = 0.35 ,
71117 )
72118 nvtx .RangePop ()
73119 dev .synchronize ()
@@ -76,8 +122,8 @@ def test_FBP_performance_i13_dataset2(i13_dataset2, ensure_clean_memory):
76122 assert "performance in ms" == duration_ms
77123
78124
79- def test_reconstruct_LPREC_i13_dataset2 (i13_dataset2 , ensure_clean_memory ):
80-
125+ def test_reconstruct_LPREC_i13_dataset2 (i13_dataset2 ):
126+ force_clean_gpu_memory ()
81127 projdata = i13_dataset2 [0 ]
82128 angles = i13_dataset2 [1 ]
83129 flats = i13_dataset2 [2 ]
@@ -86,8 +132,7 @@ def test_reconstruct_LPREC_i13_dataset2(i13_dataset2, ensure_clean_memory):
86132
87133 data_normalised = normalize (projdata , flats , darks , minus_log = True )
88134 del flats , darks , projdata
89- ensure_clean_memory
90-
135+ force_clean_gpu_memory ()
91136
92137 recon_data = LPRec (
93138 data = data_normalised ,
@@ -97,13 +142,13 @@ def test_reconstruct_LPREC_i13_dataset2(i13_dataset2, ensure_clean_memory):
97142 assert recon_data .flags .c_contiguous
98143 recon_data = recon_data .get ()
99144
100- assert_allclose (np .sum (recon_data ), 2044.9531 , rtol = 1e-07 , atol = 1e-6 )
145+ assert isclose (np .sum (recon_data ), 2044.953 , abs_tol = 10 ** - 3 )
101146 assert recon_data .dtype == np .float32
102147 assert recon_data .shape == (2560 , 10 , 2560 )
103148
104149
105150@pytest .mark .perf
106- def test_LPREC_performance_i13_dataset2 (i13_dataset2 , ensure_clean_memory ):
151+ def test_LPREC_performance_i13_dataset2 (i13_dataset2 ):
107152 dev = cp .cuda .Device ()
108153 projdata = i13_dataset2 [0 ]
109154 angles = i13_dataset2 [1 ]
@@ -113,7 +158,7 @@ def test_LPREC_performance_i13_dataset2(i13_dataset2, ensure_clean_memory):
113158
114159 data_normalised = normalize (projdata , flats , darks , minus_log = True )
115160 del flats , darks , projdata
116- ensure_clean_memory
161+ force_clean_gpu_memory ()
117162
118163 # cold run first
119164 LPRec (
@@ -127,12 +172,45 @@ def test_LPREC_performance_i13_dataset2(i13_dataset2, ensure_clean_memory):
127172 nvtx .RangePush ("Core" )
128173 for _ in range (10 ):
129174 LPRec (
130- data = data_normalised ,
131- angles = np .deg2rad (angles ),
132- center = 1286.25 ,
175+ data = data_normalised ,
176+ angles = np .deg2rad (angles ),
177+ center = 1286.25 ,
133178 )
134179 nvtx .RangePop ()
135180 dev .synchronize ()
136181 duration_ms = float (time .perf_counter_ns () - start ) * 1e-6 / 10
137182
138- assert "performance in ms" == duration_ms
183+ assert "performance in ms" == duration_ms
184+
185+
186+ def test_reconstruct_FBP_i13_dataset3 (i13_dataset3 ):
187+ force_clean_gpu_memory ()
188+ projdata = i13_dataset3 [0 ]
189+ angles = i13_dataset3 [1 ]
190+ flats = i13_dataset3 [2 ]
191+ darks = i13_dataset3 [3 ]
192+ del i13_dataset3
193+
194+ data_normalised = normalize (projdata , flats , darks , minus_log = True )
195+ del flats , darks , projdata
196+ force_clean_gpu_memory ()
197+
198+ stiched_data_180degrees = sino_360_to_180 (
199+ data_normalised , overlap = 438.173828 , rotation = "left"
200+ )
201+ force_clean_gpu_memory ()
202+
203+ # GPU archetictures older than 5.3 wont accept the data larger than
204+ # (4096, 4096, 4096), while the newer ones can accept (16384 x 16384 x 16384)
205+
206+ recon_data = FBP (
207+ stiched_data_180degrees ,
208+ np .deg2rad (angles [0 :3000 ]),
209+ center = 2341 ,
210+ filter_freq_cutoff = 0.35 ,
211+ )
212+
213+ assert recon_data .flags .c_contiguous
214+ recon_data = recon_data .get ()
215+ assert recon_data .dtype == np .float32
216+ assert recon_data .shape == (4682 , 3 , 4682 )
0 commit comments