Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
1,179 additions
and
548 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
_error = None | ||
|
||
from chainer.configuration import config | ||
|
||
|
||
try: | ||
import ideep # NOQA | ||
except ImportError as e: | ||
_error = e | ||
|
||
|
||
_SHOULD_USE_IDEEP = { | ||
'==always': {'always': True, 'auto': False, 'never': False}, | ||
'>=auto': {'always': True, 'auto': True, 'never': False}, | ||
} | ||
|
||
|
||
def is_available(): | ||
return _error is None | ||
|
||
|
||
def check_available(): | ||
"""Checks if iDeep is available. | ||
When iDeep is correctly set up, nothing happens. | ||
Otherwise it raises ``RuntimeError``. | ||
""" | ||
if _error is not None: | ||
raise RuntimeError( | ||
'iDeep is not available.\n' | ||
'Reason: {}'.format(type(_error).__name__, str(_error))) | ||
|
||
|
||
def should_use_ideep(level): | ||
"""Determines if we should use iDeep. | ||
This function checks ``chainer.config.use_ideep`` and availability | ||
of ``ideep`` package. | ||
Args: | ||
level (str): iDeep use level. It must be either ``'==always'`` or | ||
``'>=auto'``. ``'==always'`` indicates that the ``use_ideep`` | ||
config must be ``'always'`` to use iDeep. | ||
Returns: | ||
bool: ``True`` if the caller should use cuDNN. | ||
""" | ||
if not is_available(): | ||
return False | ||
|
||
if level not in _SHOULD_USE_IDEEP: | ||
raise ValueError('invalid iDeep use level: %s ' | ||
'(must be either of "==always" or ">=auto")' % | ||
repr(level)) | ||
|
||
flags = _SHOULD_USE_IDEEP[level] | ||
|
||
use_ideep = config.use_ideep | ||
if use_ideep not in flags: | ||
raise ValueError('invalid use_ideep configuration: %s ' | ||
'(must be either of "always", "auto", or "never")' % | ||
repr(use_ideep)) | ||
return flags[use_ideep] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.