Skip to content

Commit ac5591f

Browse files
committed
Remove debug logs
Fix PeakMemoryLineProfilerHook's peak counter, memory allocations and frees do not happen at the same time
1 parent 0345566 commit ac5591f

File tree

2 files changed

+4
-46
lines changed

2 files changed

+4
-46
lines changed

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

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -172,103 +172,59 @@ def _calc_memory_bytes_LPRec(
172172
n = n - 1 # dealing with the odd horizontal detector size
173173
odd_horiz = True
174174

175-
def debug_print(line_number: int, var_name: str, size_in_bytes: int) -> str:
176-
# print(f"{line_number} - {var_name}: {size_in_bytes} B / {size_in_bytes / 1024} KB / {size_in_bytes / 1024 ** 2} MB")
177-
pass
178-
179175
eps = 1e-4 # accuracy of usfft
180176
mu = -np.log(eps) / (2 * n * n)
181177
m = int(np.ceil(2 * n * 1 / np.pi * np.sqrt(-mu * np.log(eps) + (mu * n) * (mu * n) / 4)))
182178

183179
center_size = 6144
184180
center_size = min(center_size, n * 2 + m * 2)
185-
print(f"m: {m}")
186-
print(f"center_size: {center_size}")
187181

188182
oversampling_level = 2 # at least 2 or larger required
189183
ne = oversampling_level * n
190184
padding_m = ne // 2 - n // 2
191-
print(f"padding_m: {padding_m}")
192185

193186
output_dims = __calc_output_dim_recon(non_slice_dims_shape, **kwargs)
194187
if odd_horiz:
195188
output_dims = tuple(x + 1 for x in output_dims)
196-
print(f"output_dims: {output_dims}")
197189

198190
in_slice_size = np.prod(non_slice_dims_shape) * dtype.itemsize
199-
debug_print(0, "in_slice_size", in_slice_size)
200191
padded_in_slice_size = np.prod(non_slice_dims_shape) * np.float32().itemsize
201-
debug_print(246, "padded_in_slice_size", padded_in_slice_size)
202192
theta_size = angles_tot * np.float32().itemsize
203-
debug_print(262, "theta_size", theta_size)
204193
recon_output_size = (n + 1) * (n + 1) * np.float32().itemsize if odd_horiz else n * n * np.float32().itemsize # 264
205-
debug_print(281, "recon_output_size", recon_output_size)
206194
linspace_size = n * np.float32().itemsize
207-
debug_print(285, "linspace_size", linspace_size)
208195
meshgrid_size = 2 * n * n * np.float32().itemsize
209-
debug_print(286, "meshgrid_size", meshgrid_size)
210196
phi_size = 6 * n * n * np.float32().itemsize
211-
debug_print(287, "phi_size", phi_size)
212197
angle_range_size = center_size * center_size * 3 * np.int32().itemsize
213-
debug_print(293, "angle_range_size", angle_range_size)
214198
c1dfftshift_size = n * np.int8().itemsize
215-
debug_print(296, "c1dfftshift_size", c1dfftshift_size)
216199
c2dfftshift_slice_size = 4 * n * n * np.int8().itemsize
217-
debug_print(299, "c2dfftshift_slice_size", c2dfftshift_slice_size)
218200
filter_size = (n // 2 + 1) * np.float32().itemsize
219-
debug_print(309, "filter_size", filter_size)
220201
rfftfreq_size = filter_size
221-
debug_print(312, "rfftfreq_size", rfftfreq_size)
222202
scaled_filter_size = filter_size
223-
debug_print(313, "scaled_filter_size", scaled_filter_size)
224203
tmp_p_input_slice = np.prod(non_slice_dims_shape) * np.float32().itemsize
225-
debug_print(316, "tmp_p_input_slice", tmp_p_input_slice)
226204
padded_tmp_p_input_slice = angles_tot * (n + padding_m * 2) * dtype.itemsize
227-
debug_print(326, "padded_tmp_p_input_slice", padded_tmp_p_input_slice)
228205
rfft_result_size = padded_tmp_p_input_slice
229-
debug_print(327, "rfft_result_size", rfft_result_size)
230206
filtered_rfft_result_size = rfft_result_size
231-
debug_print(327, "filtered_rfft_result_size", filtered_rfft_result_size)
232207
rfft_plan_slice_size = cufft_estimate_1d(nx=(n + padding_m * 2),fft_type=CufftType.CUFFT_R2C,batch=angles_tot * SLICES) / SLICES
233-
debug_print(327, "rfft_plan_slice_size", rfft_plan_slice_size)
234208
irfft_result_size = filtered_rfft_result_size
235-
debug_print(327, "irfft_result_size", irfft_result_size)
236209
irfft_scratch_memory_size = filtered_rfft_result_size
237-
debug_print(327, "irfft_scratch_memory_size", irfft_scratch_memory_size)
238210
irfft_plan_slice_size = cufft_estimate_1d(nx=(n + padding_m * 2),fft_type=CufftType.CUFFT_C2R,batch=angles_tot * SLICES) / SLICES
239-
debug_print(327, "irfft_plan_slice_size", irfft_plan_slice_size)
240211
conversion_to_complex_size = np.prod(non_slice_dims_shape) * np.complex64().itemsize / 2
241-
debug_print(333, "conversion_to_complex_size", conversion_to_complex_size)
242212
datac_size = np.prod(non_slice_dims_shape) * np.complex64().itemsize / 2
243-
debug_print(333, "datac_size", datac_size)
244213
fde_size = (2 * m + 2 * n) * (2 * m + 2 * n) * np.complex64().itemsize / 2
245-
debug_print(341, "fde_size", fde_size)
246214
shifted_datac_size = datac_size
247-
debug_print(344, "shifted_datac_size", shifted_datac_size)
248215
fft_result_size = datac_size
249-
debug_print(344, "fft_result_size", fft_result_size)
250216
backshifted_datac_size = datac_size
251-
debug_print(344, "backshifted_datac_size", backshifted_datac_size)
252217
scaled_backshifted_datac_size = datac_size
253-
debug_print(344, "scaled_backshifted_datac_size", scaled_backshifted_datac_size)
254218
fft_plan_slice_size = cufft_estimate_1d(nx=n,fft_type=CufftType.CUFFT_C2C,batch=angles_tot * SLICES) / SLICES
255-
debug_print(344, "fft_plan_slice_size", fft_plan_slice_size)
256219
fde_view_size = 4 * n * n * np.complex64().itemsize / 2
257220
shifted_fde_view_size = fde_view_size
258-
debug_print(474, "shifted_fde_view_size", shifted_fde_view_size)
259221
ifft2_scratch_memory_size = fde_view_size
260-
debug_print(474, "ifft2_scratch_memory_size", ifft2_scratch_memory_size)
261222
ifft2_plan_slice_size = cufft_estimate_2d(nx=(2 * n),ny=(2 * n),fft_type=CufftType.CUFFT_C2C) / 2
262-
debug_print(474, "ifft2_plan_slice_size", ifft2_plan_slice_size)
263223
fde2_size = n * n * np.complex64().itemsize / 2
264-
debug_print(479, "fde2_size", fde2_size)
265224
concatenate_size = fde2_size
266-
debug_print(485, "concatenate_size", concatenate_size)
267225
circular_mask_size = np.prod(output_dims) / 2 * np.int64().itemsize * 4
268-
debug_print(496, "circular_mask_size", circular_mask_size)
269226

270227
after_recon_swapaxis_slice = np.prod(non_slice_dims_shape) * np.float32().itemsize
271-
debug_print(0, "after_recon_swapaxis_slice", after_recon_swapaxis_slice)
272228

273229
tot_memory_bytes = int(
274230
max(

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,12 @@ def _print_frame(self, memory_frame, running_peak_bytes, running_used_bytes, dep
8383
humanized_running_peak_bytes = None
8484
humanized_running_used_bytes = None
8585
if path.basename(st.filename) in self.running_peak_root_file_names:
86-
running_used_bytes[0] = running_used_bytes[0] + memory_frame.used_bytes - memory_frame.freed_bytes
87-
humanized_running_used_bytes = MemoryFrame.humanized_size(running_used_bytes[0])
86+
running_used_bytes[0] += memory_frame.used_bytes
8887
running_peak_bytes[0] = max(running_peak_bytes[0], running_used_bytes[0])
88+
running_used_bytes[0] -= memory_frame.freed_bytes
89+
8990
humanized_running_peak_bytes = MemoryFrame.humanized_size(running_peak_bytes[0])
91+
humanized_running_used_bytes = MemoryFrame.humanized_size(running_used_bytes[0])
9092

9193
line = '%s%s:%s:%s (%s, %s, %s, %s, %s)\n' % (
9294
indent, st.filename, st.lineno, st.name,

0 commit comments

Comments
 (0)