raise deprecation warning
import contextlib
+import warnings
from cupy._environment import get_cuda_path, get_nvcc_path # NOQA
from cupy.cuda import compiler # NOQA
@@ -26,41 +27,57 @@ _available = None
class UnavailableModule():
available = False
-# All `*_enabled` flags are kept just for backward compatibility.
+ def __init__(self, name):
+ self.__name__ = name
-# cuSOLVER is always available in CUDA 8.0+.
-cusolver_enabled = True
# TODO(leofang): always import cub (but not enable it) when hipCUB is supported
if not runtime.is_hip:
from cupy.cuda import cub # NOQA
else:
- cub = UnavailableModule()
+ cub = UnavailableModule('cub')
try:
from cupy.cuda import nvtx # NOQA
- nvtx_enabled = True
except ImportError:
- nvtx = UnavailableModule()
- nvtx_enabled = False
+ nvtx = UnavailableModule('nvtx')
try:
from cupy.cuda import thrust # NOQA
except ImportError:
- thrust = UnavailableModule()
+ thrust = UnavailableModule('thrust')
try:
from cupy.cuda import nccl # NOQA
- nccl_enabled = True
except ImportError:
- nccl = UnavailableModule()
- nccl_enabled = False
+ nccl = UnavailableModule('nccl')
try:
from cupy_backends.cuda.libs import cutensor
except ImportError:
- cutensor = UnavailableModule()
+ cutensor = UnavailableModule('cutensor')
+
+# `*_enabled` flags are kept for backward compatibility.
+def __getattr__(key):
+ if key == 'cusolver_enabled':
+ # cuSOLVER is always available in CUDA 8.0+.
+ warnings.warn('''
+cupy.cuda.cusolver_enabled has been deprecated in CuPy v8 and will be removed in the future release.
+This flag always returns True as cuSOLVER is always available in CUDA 8.0 or later.
+ ''') # NOQA
+ return True
+
+ for mod in [nvtx, nccl, thrust, cub, cutensor]:
+ flag = '{}_enabled'.format(mod.__name__.split('.')[-1])
+ if key == flag:
+ warnings.warn('''
+cupy.cuda.{} has been deprecated in CuPy v8 and will be removed in the future release.
+Use {}.available instead.'''.format(flag, mod.__name__))
+ return not isinstance(mod, UnavailableModule)
+
+ raise AttributeError(
+ 'module \'{}\' has no attribute \'{}\''.format(__name__, key))
def is_available():
