Skip to content

Commit

Permalink
Augment SVML detection with llvmlite SVML patch detection.
Browse files Browse the repository at this point in the history
This adds defensive behaviour to SVML detection following changes
to llvmlite that added a function to declare whether SVML was enabled,
via patching LLVM, at compile time. This is a critical patch that
corrects erroneous behaviour, for context see numba#3006.

Closes numba#3006
Fixes numba#2998
  • Loading branch information
stuartarchibald committed Jun 1, 2018
1 parent 0585329 commit 12fdf62
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion numba/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import platform
import re
import sys
import warnings

from . import config, errors, runtests, types

Expand Down Expand Up @@ -118,10 +119,36 @@ def _try_enable_svml():
llvmlite.binding.load_library_permanently("svml_dispmd")
else:
return False
# The SVML library is loaded, therefore SVML *could* be supported.
# Now see if LLVM has been compiled with the SVML support patch.
# If llvmlite has the checking function `has_svml` and it returns
# True, then LLVM was compiled with SVML support and the the setup
# for SVML can proceed. We err on the side of caution and if the
# checking function is missing, regardless of that being fine for
# most 0.23.{0,1} llvmlite instances (i.e. conda or pip installed),
# we assume that SVML was not compiled in. llvmlite 0.23.2 is a
# bugfix release with the checking function present that will always
# produce correct behaviour. For context see: #3006.
try:
if not getattr(llvmlite.binding.targets, "has_svml")():
# has detection function, but no svml compiled in, therefore
# disable SVML
return False
except AttributeError:
if platform.machine() == 'x86_64' and config.DEBUG:
msg = ("SVML was found but llvmlite >= 0.23.2 is "
"needed to support it.")
warnings.warn(msg)
# does not have detection function, cannot detect reliably,
# disable SVML.
return False

# All is well, detection function present and reports SVML is
# compiled in, set the vector library to SVML.
llvmlite.binding.set_option('SVML', '-vector-library=SVML')
return True
except:
if platform.machine == 'x86_64' and config.DEBUG:
if platform.machine() == 'x86_64' and config.DEBUG:
warnings.warn("SVML was not found/could not be loaded.")
return False

Expand Down

0 comments on commit 12fdf62

Please sign in to comment.