Exemple #1
0
def is_mx_mkldnn():
    """
    Detects if MXNet is build with MKLDNN or oneDNN support.
    MXNET ≥ 2.0.0 uses oneDNN (renamed from MKLDNN) but still calls the feature 'MKLDNN'.
    """
    try:
        from mxnet import runtime
        features = runtime.Features()
        return features.is_enabled('MKLDNN')
    except Exception:
        msg = f'INFO: Cannot detect if MKLDNN / ONEDNN is enabled in MXNet. Please ' \
              f'set MXNET_USE_MKLDNN=1 if MKLDNN / MXNET_USE_ONEDNN=1 if ONEDNN is ' \
              f'enabled in your MXNet build.'
        if 'linux' not in sys.platform:
            # MKLDNN / oneDNN is only enabled by default in MXNet Linux build. Return
            # False by default for non-linux build but still allow users to
            # enable it by using MXNET_USE_MKLDNN / MXNET_USE_ONEDNN env variable.
            print(msg)
            return os.environ.get(f'MXNET_USE_MKLDNN', '0') == '1' or \
                   os.environ.get(f'MXNET_USE_ONEDNN', '0') == '1'
        else:
            try:
                import mxnet as mx
                mx_libs = mx.libinfo.find_lib_path()
                for mx_lib in mx_libs:
                    output = subprocess.check_output(['readelf', '-d', mx_lib])
                    if 'mkldnn' in str(output):
                        return True
                return False
            except Exception:
                print(msg)
            return os.environ.get(f'MXNET_USE_MKLDNN', '0') == '1' or \
                   os.environ.get(f'MXNET_USE_ONEDNN', '0') == '1'
Exemple #2
0
def is_mx_mkldnn():
    try:
        from mxnet import runtime
        features = runtime.Features()
        return features.is_enabled('MKLDNN')
    except Exception:
        msg = 'INFO: Cannot detect if MKLDNN is enabled in MXNet. Please \
            set MXNET_USE_MKLDNN=1 if MKLDNN is enabled in your MXNet build.'

        if 'linux' not in sys.platform:
            # MKLDNN is only enabled by default in MXNet Linux build. Return
            # False by default for non-linux build but still allow users to
            # enable it by using MXNET_USE_MKLDNN env variable.
            print(msg)
            return os.environ.get('MXNET_USE_MKLDNN', '0') == '1'
        else:
            try:
                import mxnet as mx
                mx_libs = mx.libinfo.find_lib_path()
                for mx_lib in mx_libs:
                    output = subprocess.check_output(['readelf', '-d', mx_lib])
                    if 'mkldnn' in str(output):
                        return True
                return False
            except Exception:
                print(msg)
                return os.environ.get('MXNET_USE_MKLDNN', '0') == '1'
Exemple #3
0
def is_mx_dnn(dnn_flavour: str):
    """
    Detects if MXNet is build with given DNN flavour (MKLDNN or oneDNN) support.
    MXNET ≥ 2.0.0 uses oneDNN (renamed from MKLDNN), < 2.0.0 MKLDNN.
    """
    dnn_flavour_lower = dnn_flavour.lower()
    dnn_flavour = dnn_flavour.upper()
    try:
        from mxnet import runtime
        features = runtime.Features()
        return features.is_enabled(dnn_flavour)
    except Exception:
        msg = f'INFO: Cannot detect if {dnn_flavour} is enabled in MXNet. Please ' \
              f'set MXNET_USE_{dnn_flavour}=1 if {dnn_flavour} is ' \
              f'enabled in your MXNet build.'
        if 'linux' not in sys.platform:
            # MKLDNN / oneDNN is only enabled by default in MXNet Linux build. Return
            # False by default for non-linux build but still allow users to
            # enable it by using MXNET_USE_MKLDNN / MXNET_USE_ONEDNN env variable.
            print(msg, file=sys.stderr)
            return os.environ.get(f'MXNET_USE_{dnn_flavour}', '0') == '1'
        else:
            try:
                import mxnet as mx
                mx_libs = mx.libinfo.find_lib_path()
                for mx_lib in mx_libs:
                    output = subprocess.check_output(['readelf', '-d', mx_lib])
                    if dnn_flavour_lower in str(output):
                        return True
                return False
            except Exception:
                print(msg, file=sys.stderr)
            return os.environ.get(f'MXNET_USE_{dnn_flavour}', '0') == '1'
Exemple #4
0
def get_current_runtime_features():
    """Get all current runtime time flags/configuration for MXNet.

    Returns
    -------
    Map of current runtime features such as compile flags used by MXNet.
        Example: {'runtime_features': {'OPENCV' : '✔ OPENCV', 'CUDA': '✖ CUDA'}}
    """
    features = runtime.Features()
    runtime_features = {}
    for feature, config in sorted(features.items(), key=itemgetter(0)):
        runtime_features[feature] = config

    return {'runtime_features': runtime_features}
Exemple #5
0
def is_mx_cuda():
    try:
        from mxnet import runtime
        features = runtime.Features()
        return features.is_enabled('CUDA')
    except Exception:
        if 'linux' in sys.platform:
            try:
                import mxnet as mx
                mx_libs = mx.libinfo.find_lib_path()
                for mx_lib in mx_libs:
                    output = subprocess.check_output(['readelf', '-d', mx_lib])
                    if 'cuda' in str(output):
                        return True
                return False
            except Exception:
                return False
    return False