Skip to content

Commit

Permalink
Improve error message when convolution kernel too big
Browse files Browse the repository at this point in the history
  • Loading branch information
daurer committed Mar 8, 2024
1 parent aeec234 commit f2c2cb6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
6 changes: 5 additions & 1 deletion ptypy/accelerate/cuda_cupy/engines/ML_cupy.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,11 @@ def _get_smooth_gradient(self, data, sigma):
if self.p.smooth_gradient_method == "convolution":
if self.GSK.tmp is None:
self.GSK.tmp = cp.empty(data.shape, dtype=np.complex64)
self.GSK.convolution(data, [sigma, sigma], tmp=self.GSK.tmp)
try:
self.GSK.convolution(data, [sigma, sigma], tmp=self.GSK.tmp)
except MemoryError:
raise RuntimeError("Convolution kernel too large for direct convolution on GPU",
"Please reduce parameter smooth_gradient or set smooth_gradient_method='fft'.")
elif self.p.smooth_gradient_method == "fft":
self.FGSK.filter(data, sigma)
else:
Expand Down
2 changes: 1 addition & 1 deletion ptypy/accelerate/cuda_cupy/kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def apply_real_support(self, x):


class FFTFilterKernel:
def __init__(self, queue_thread=None, fft='cuda'):
def __init__(self, queue_thread=None, fft='cupy'):
# Current implementation recompiles every time there is a change in input shape.
self.queue = queue_thread
self._fft_type = fft
Expand Down
6 changes: 5 additions & 1 deletion ptypy/accelerate/cuda_pycuda/engines/ML_pycuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,11 @@ def _get_smooth_gradient(self, data, sigma):
if self.p.smooth_gradient_method == "convolution":
if self.GSK.tmp is None:
self.GSK.tmp = gpuarray.empty(data.shape, dtype=np.complex64)
self.GSK.convolution(data, [sigma, sigma], tmp=self.GSK.tmp)
try:
self.GSK.convolution(data, [sigma, sigma], tmp=self.GSK.tmp)
except MemoryError:
raise RuntimeError("Convolution kernel too large for direct convolution on GPU",
"Please reduce parameter smooth_gradient or set smooth_gradient_method='fft'.")
elif self.p.smooth_gradient_method == "fft":
self.FGSK.filter(data, sigma)
else:
Expand Down

0 comments on commit f2c2cb6

Please sign in to comment.