1+ import cupy as cp
2+ import numpy as np
3+ import pytest
4+ from cupy .cuda import nvtx
5+ import time
6+
7+ from httomolibgpu .prep .normalize import normalize
8+ from httomolibgpu .recon .algorithm import (
9+ FBP ,
10+ LPRec ,
11+ )
12+ from numpy .testing import assert_allclose
13+ import time
14+ import pytest
15+ from cupy .cuda import nvtx
16+
17+ def test_reconstruct_FBP_i12_dataset1 (i12_dataset1 , ensure_clean_memory ):
18+
19+ projdata = i12_dataset1 [0 ]
20+ angles = i12_dataset1 [1 ]
21+ flats = i12_dataset1 [2 ]
22+ darks = i12_dataset1 [3 ]
23+ del i12_dataset1
24+
25+ data_normalised = normalize (projdata , flats , darks , minus_log = True )
26+ del flats , darks , projdata
27+ ensure_clean_memory
28+
29+ recon_data = FBP (
30+ data_normalised ,
31+ np .deg2rad (angles ),
32+ center = 1253.75 ,
33+ filter_freq_cutoff = 0.35 ,
34+ )
35+ assert recon_data .flags .c_contiguous
36+ recon_data = recon_data .get ()
37+ assert_allclose (np .sum (recon_data ), 46569.395 , rtol = 1e-07 , atol = 1e-6 )
38+ assert recon_data .dtype == np .float32
39+ assert recon_data .shape == (2560 , 50 , 2560 )
40+
41+ @pytest .mark .perf
42+ def test_FBP_performance_i13_dataset2 (i13_dataset2 , ensure_clean_memory ):
43+ dev = cp .cuda .Device ()
44+ projdata = i13_dataset2 [0 ]
45+ angles = i13_dataset2 [1 ]
46+ flats = i13_dataset2 [2 ]
47+ darks = i13_dataset2 [3 ]
48+ del i13_dataset2
49+
50+ data_normalised = normalize (projdata , flats , darks , minus_log = True )
51+ del flats , darks , projdata
52+ ensure_clean_memory
53+
54+ # cold run first
55+ FBP (
56+ data_normalised ,
57+ np .deg2rad (angles ),
58+ center = 1253.75 ,
59+ filter_freq_cutoff = 0.35 ,
60+ )
61+ dev .synchronize ()
62+
63+ start = time .perf_counter_ns ()
64+ nvtx .RangePush ("Core" )
65+ for _ in range (10 ):
66+ FBP (
67+ data_normalised ,
68+ np .deg2rad (angles ),
69+ center = 1286.25 ,
70+ filter_freq_cutoff = 0.35 ,
71+ )
72+ nvtx .RangePop ()
73+ dev .synchronize ()
74+ duration_ms = float (time .perf_counter_ns () - start ) * 1e-6 / 10
75+
76+ assert "performance in ms" == duration_ms
77+
78+
79+ def test_reconstruct_LPREC_i13_dataset2 (i13_dataset2 , ensure_clean_memory ):
80+
81+ projdata = i13_dataset2 [0 ]
82+ angles = i13_dataset2 [1 ]
83+ flats = i13_dataset2 [2 ]
84+ darks = i13_dataset2 [3 ]
85+ del i13_dataset2
86+
87+ data_normalised = normalize (projdata , flats , darks , minus_log = True )
88+ del flats , darks , projdata
89+ ensure_clean_memory
90+
91+
92+ recon_data = LPRec (
93+ data = data_normalised ,
94+ angles = np .deg2rad (angles ),
95+ center = 1286.25 ,
96+ )
97+ assert recon_data .flags .c_contiguous
98+ recon_data = recon_data .get ()
99+
100+ assert_allclose (np .sum (recon_data ), 2044.9531 , rtol = 1e-07 , atol = 1e-6 )
101+ assert recon_data .dtype == np .float32
102+ assert recon_data .shape == (2560 , 10 , 2560 )
103+
104+
105+ @pytest .mark .perf
106+ def test_LPREC_performance_i13_dataset2 (i13_dataset2 , ensure_clean_memory ):
107+ dev = cp .cuda .Device ()
108+ projdata = i13_dataset2 [0 ]
109+ angles = i13_dataset2 [1 ]
110+ flats = i13_dataset2 [2 ]
111+ darks = i13_dataset2 [3 ]
112+ del i13_dataset2
113+
114+ data_normalised = normalize (projdata , flats , darks , minus_log = True )
115+ del flats , darks , projdata
116+ ensure_clean_memory
117+
118+ # cold run first
119+ LPRec (
120+ data = data_normalised ,
121+ angles = np .deg2rad (angles ),
122+ center = 1286.25 ,
123+ )
124+ dev .synchronize ()
125+
126+ start = time .perf_counter_ns ()
127+ nvtx .RangePush ("Core" )
128+ for _ in range (10 ):
129+ LPRec (
130+ data = data_normalised ,
131+ angles = np .deg2rad (angles ),
132+ center = 1286.25 ,
133+ )
134+ nvtx .RangePop ()
135+ dev .synchronize ()
136+ duration_ms = float (time .perf_counter_ns () - start ) * 1e-6 / 10
137+
138+ assert "performance in ms" == duration_ms
0 commit comments