Skip to content

Add _logger.debug statements to cmodule default blas ldflags #528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 29 additions & 11 deletions pytensor/link/c/cmodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -2718,6 +2718,7 @@ def check_required_file(paths, required_regexs):
found = True
break
if not found:
_logger.debug("Required file '%s' not found", req)
raise RuntimeError(f"Required file {req} not found")
return libs

Expand Down Expand Up @@ -2779,9 +2780,15 @@ def check_libs(
res = try_blas_flag(flags)
if res:
if any("mkl" in flag for flag in flags):
check_mkl_openmp()
try:
check_mkl_openmp()
except Exception as e:
_logger.debug(e)
_logger.debug("The following blas flags will be used: '%s'", res)
return res
else:
_logger.debug(f"Supplied flags {res} failed to compile")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_logger.debug(f"Supplied flags {res} failed to compile")
_logger.debug("Supplied flags '%s' failed to compile", res)

_logger.debug("Supplied flags '%s' failed to compile", res)
raise RuntimeError(f"Supplied flags {flags} failed to compile")

# If no compiler is available we default to empty ldflags
Expand All @@ -2802,6 +2809,11 @@ def check_libs(
# directory. We will include both in our searched library dirs
searched_library_dirs.append(os.path.join(sys.prefix, "Library", "bin"))
searched_library_dirs.append(os.path.join(sys.prefix, "Library", "lib"))
search_dirs = "\n".join(searched_library_dirs)
_logger.debug(
"Will search for BLAS libraries in the following directories:\n%s",
search_dirs,
)
all_libs = [
l
for path in [
Expand All @@ -2817,6 +2829,7 @@ def check_libs(
maybe_add_to_os_environ_pathlist("PATH", rpath)
try:
# 1. Try to use MKL with INTEL OpenMP threading
_logger.debug("Checking MKL flags with intel threading")
return check_libs(
all_libs,
required_libs=[
Expand All @@ -2829,40 +2842,44 @@ def check_libs(
extra_compile_flags=[f"-Wl,-rpath,{rpath}"] if rpath is not None else [],
cxx_library_dirs=cxx_library_dirs,
)
except Exception:
pass
except Exception as e:
_logger.debug(e)
try:
# 2. Try to use MKL with GNU OpenMP threading
_logger.debug("Checking MKL flags with GNU OpenMP threading")
return check_libs(
all_libs,
required_libs=["mkl_core", "mkl_rt", "mkl_gnu_thread", "gomp", "pthread"],
extra_compile_flags=[f"-Wl,-rpath,{rpath}"] if rpath is not None else [],
cxx_library_dirs=cxx_library_dirs,
)
except Exception:
pass
except Exception as e:
_logger.debug(e)
try:
_logger.debug("Checking Lapack + blas")
# 3. Try to use LAPACK + BLAS
return check_libs(
all_libs,
required_libs=["lapack", "blas", "cblas", "m"],
extra_compile_flags=[f"-Wl,-rpath,{rpath}"] if rpath is not None else [],
cxx_library_dirs=cxx_library_dirs,
)
except Exception:
pass
except Exception as e:
_logger.debug(e)
try:
# 4. Try to use BLAS alone
_logger.debug("Checking blas alone")
return check_libs(
all_libs,
required_libs=["blas", "cblas"],
extra_compile_flags=[f"-Wl,-rpath,{rpath}"] if rpath is not None else [],
cxx_library_dirs=cxx_library_dirs,
)
except Exception:
pass
except Exception as e:
_logger.debug(e)
try:
# 5. Try to use openblas
_logger.debug("Checking openblas")
return check_libs(
all_libs,
required_libs=["openblas", "gfortran", "gomp", "m"],
Expand All @@ -2871,8 +2888,9 @@ def check_libs(
else ["-fopenmp"],
cxx_library_dirs=cxx_library_dirs,
)
except Exception:
pass
except Exception as e:
_logger.debug(e)
_logger.debug("Failed to identify blas ldflags. Will leave them empty.")
return ""


Expand Down