Skip to content

Commit cd276f8

Browse files
committed
moving all gpu related imports under try
1 parent 3a4524d commit cd276f8

File tree

9 files changed

+63
-18
lines changed

9 files changed

+63
-18
lines changed

httomolibgpu/cupywrapper.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
try:
33
import cupy as cp
44
import nvtx
5-
import cupyx
65

76
try:
87
cp.cuda.Device(0).compute_capability
@@ -18,4 +17,3 @@
1817
import numpy as cp
1918

2019
nvtx = Mock()
21-
cupyx = Mock()

httomolibgpu/misc/corr.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@
3131
nvtx = cupywrapper.nvtx
3232

3333
from numpy import float32
34-
from httomolibgpu.cuda_kernels import load_cuda_module
34+
from unittest.mock import Mock
35+
36+
try:
37+
from httomolibgpu.cuda_kernels import load_cuda_module
38+
except ImportError as e:
39+
load_cuda_module = Mock()
40+
3541

3642
__all__ = [
3743
"median_filter",

httomolibgpu/misc/morph.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@
2525

2626
cp = cupywrapper.cp
2727
nvtx = cupywrapper.nvtx
28-
cupyx = cupywrapper.cupyx
2928

30-
from cupyx.scipy.interpolate import interpn
29+
from unittest.mock import Mock
30+
31+
try:
32+
from cupyx.scipy.interpolate import interpn
33+
except ImportError as e:
34+
interpn = Mock()
3135

3236
from typing import Literal
3337

httomolibgpu/prep/alignment.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@
2525

2626
cp = cupywrapper.cp
2727
nvtx = cupywrapper.nvtx
28-
cupyx = cupywrapper.cupyx
2928

30-
from cupyx.scipy.ndimage import map_coordinates
29+
from unittest.mock import Mock
30+
31+
try:
32+
from cupyx.scipy.ndimage import map_coordinates
33+
except ImportError as e:
34+
map_coordinates = Mock()
3135

3236
from typing import Dict, List
3337

httomolibgpu/prep/normalize.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@
2626
cp = cupywrapper.cp
2727
nvtx = cupywrapper.nvtx
2828

29-
from cupy import mean
29+
from unittest.mock import Mock
30+
31+
try:
32+
from cupy import mean
33+
except ImportError as e:
34+
mean = Mock()
3035

3136
from numpy import float32
3237
from typing import Tuple

httomolibgpu/prep/phase.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,15 @@
2626
cp = cupywrapper.cp
2727
nvtx = cupywrapper.nvtx
2828

29-
from httomolibgpu.cuda_kernels import load_cuda_module
30-
from cupyx.scipy.fft import fft2, ifft2, fftshift
29+
from unittest.mock import Mock
30+
try:
31+
from httomolibgpu.cuda_kernels import load_cuda_module
32+
from cupyx.scipy.fft import fft2, ifft2, fftshift
33+
except ImportError as e:
34+
load_cuda_module = Mock()
35+
fft2 = Mock()
36+
ifft2 = Mock()
37+
fftshift = Mock()
3138

3239
from numpy import float32
3340
from typing import Union

httomolibgpu/prep/stripe.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@
2626
cp = cupywrapper.cp
2727
nvtx = cupywrapper.nvtx
2828

29-
from cupyx.scipy.ndimage import median_filter, binary_dilation, uniform_filter1d
29+
from unittest.mock import Mock
30+
try:
31+
from cupyx.scipy.ndimage import median_filter, binary_dilation, uniform_filter1d
32+
except ImportError as e:
33+
median_filter = Mock()
34+
binary_dilation = Mock()
35+
uniform_filter1d = Mock()
3036

3137
from typing import Union
3238

httomolibgpu/recon/algorithm.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,13 @@
2626
cp = cupywrapper.cp
2727
nvtx = cupywrapper.nvtx
2828

29-
from tomobar.methodsDIR_CuPy import RecToolsDIRCuPy
30-
from tomobar.methodsIR_CuPy import RecToolsIRCuPy
29+
from unittest.mock import Mock
30+
try:
31+
from tomobar.methodsDIR_CuPy import RecToolsDIRCuPy
32+
from tomobar.methodsIR_CuPy import RecToolsIRCuPy
33+
except ImportError as e:
34+
RecToolsDIRCuPy = Mock()
35+
RecToolsIRCuPy = Mock()
3136

3237
from numpy import float32, complex64
3338
from typing import Optional, Type

httomolibgpu/recon/rotation.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,21 @@
2626
cp = cupywrapper.cp
2727
nvtx = cupywrapper.nvtx
2828

29-
from httomolibgpu.cuda_kernels import load_cuda_module
30-
from cupyx.scipy.ndimage import shift, gaussian_filter
31-
from skimage.registration import phase_cross_correlation
32-
from cupyx.scipy.fftpack import get_fft_plan
33-
from cupyx.scipy.fft import rfft2
29+
30+
from unittest.mock import Mock
31+
try:
32+
from httomolibgpu.cuda_kernels import load_cuda_module
33+
from cupyx.scipy.ndimage import shift, gaussian_filter
34+
from skimage.registration import phase_cross_correlation
35+
from cupyx.scipy.fftpack import get_fft_plan
36+
from cupyx.scipy.fft import rfft2
37+
except ImportError as e:
38+
load_cuda_module = Mock()
39+
shift = Mock()
40+
gaussian_filter = Mock()
41+
phase_cross_correlation = Mock()
42+
get_fft_plan = Mock()
43+
rfft2 = Mock()
3444

3545
import math
3646
from typing import List, Literal, Optional, Tuple, Union

0 commit comments

Comments
 (0)