# HG changeset patch # User Markus Mützel # Date 1518128113 18000 # Thu Feb 08 17:15:13 2018 -0500 # Node ID 7d26bf831d5d4d51915930c08c7144be0db3758b # Parent a979bb895b64d4e391e9d5266fae7f7bec150c9f Add "-blas" and "-lapack" options to "version" (bug #45659). * lo-sysinfo.h, lo-sysinfo.cc: New files. * liboctave/system/module.mk: Update. * sysdep.cc (F__blas_version__, F__lapack_version__): New functions. * version.m: Accept -blas and -lapack options. Make options case insensitive. diff --git a/libinterp/corefcn/sysdep.cc b/libinterp/corefcn/sysdep.cc --- a/libinterp/corefcn/sysdep.cc +++ b/libinterp/corefcn/sysdep.cc @@ -61,6 +61,7 @@ along with Octave; see the file COPYING. #include "cmd-edit.h" #include "file-ops.h" #include "lo-mappers.h" +#include "lo-sysinfo.h" #include "mach-info.h" #include "oct-env.h" #include "unistd-wrappers.h" @@ -1229,3 +1230,21 @@ equivalent to %! assert (get_home_directory (), getenv ("HOME")); %! endif */ + +DEFUN (__blas_version__, , , + doc: /* -*- texinfo -*- +@deftypefn {} {} __blas_version__ () +Undocumented internal function. +@end deftypefn */) +{ + return ovl (octave::sys::blas_version ()); +} + +DEFUN (__lapack_version__, , , + doc: /* -*- texinfo -*- +@deftypefn {} {} __lapack_version__ () +Undocumented internal function. +@end deftypefn */) +{ + return ovl (octave::sys::lapack_version ()); +} diff --git a/liboctave/system/lo-sysinfo.cc b/liboctave/system/lo-sysinfo.cc new file mode 100644 --- /dev/null +++ b/liboctave/system/lo-sysinfo.cc @@ -0,0 +1,186 @@ +/* + +Copyright (C) 2018 Markus Mützel + +This file is part of Octave. + +Octave is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Octave is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, see +. + +*/ + +#if defined (HAVE_CONFIG_H) +# include "config.h" +#endif + +#include +#include + +#include "f77-fcn.h" +#include "lo-sysinfo.h" +#include "oct-shlib.h" + +// Hack to stringize macro results. +#define xSTRINGIZE(x) #x +#define STRINGIZE(x) xSTRINGIZE(x) + +namespace octave +{ + namespace sys + { + std::string blas_version (void) + { + dynamic_library dyn_libs (""); + + if (! dyn_libs) + return "unknown BLAS"; + + std::string retval; + + // Check for functions that are specific to certain BLAS implementations. + + // FlexiBLAS + typedef void (*flexi_f_type) (int*, int*, int*); + flexi_f_type flexi_f_ptr = reinterpret_cast + (dyn_libs.search ("flexiblas_get_version")); + + if (flexi_f_ptr) + { + int v_major = 0; + int v_minor = 0; + int v_patch = 0; + flexi_f_ptr (&v_major, &v_minor, &v_patch); + + std::ostringstream s; + s << "FlexiBLAS Version " + << v_major << "." << v_minor << "." << v_patch; + + if (! retval.empty ()) + retval += "\n"; + + retval += s.str (); + } + + // OpenBLAS + typedef char * (*open_fcn_type) (void); + open_fcn_type open_f_ptr = reinterpret_cast + (dyn_libs.search ("openblas_get_config")); + + if (open_f_ptr) + { + if (! retval.empty ()) + retval += "\n"; + + retval += "OpenBLAS (config: " + std::string (open_f_ptr ()) + ")"; + } + + // GotoBLAS(2) + if (dyn_libs.search ("gotoblas_profile_init")) + { + if (! retval.empty ()) + retval += "\n"; + + retval += "GotoBLAS(2)"; + } + + // ATLAS + // FIXME: If we are really interested, we could use a pipe to + // redirect the output of "ATL_buildinfo". + if (dyn_libs.search ("ATL_buildinfo")) + { + if (! retval.empty ()) + retval += "\n"; + + retval += "ATLAS"; + } + + // ACML + typedef void (*acml_f_type) (int*, int*, int*); + acml_f_type acml_f_ptr = reinterpret_cast + (dyn_libs.search ("acmlversion")); + + if (acml_f_ptr) + { + int v_major = 0; + int v_minor = 0; + int v_patch = 0; + acml_f_ptr (&v_major, &v_minor, &v_patch); + + std::ostringstream s; + s << "ACML BLAS Version " + << v_major << "." << v_minor << "." << v_patch; + + if (! retval.empty ()) + retval += "\n"; + + retval += s.str (); + } + + // Intel MKL + typedef void (*mkl_f_type) (char*, int); + mkl_f_type mkl_f_ptr = reinterpret_cast + (dyn_libs.search ("mkl_get_version_string")); + + if (mkl_f_ptr) + { + char buf[198]; + int len = 198; + mkl_f_ptr (buf, len); + + if (! retval.empty ()) + retval += "\n"; + + retval += std::string (buf); + } + + // Otherwise + if (retval.empty ()) + retval = "unknown or reference BLAS"; + + return retval; + } + + std::string lapack_version (void) + { + std::string retval = "unknown LAPACK"; + + dynamic_library dyn_libs (""); + + if (! dyn_libs) + return retval; + + // query LAPACK version + typedef F77_RET_T + (*ilaver_fcn_type) (const F77_INT&, const F77_INT&, const F77_INT&); + ilaver_fcn_type f_ptr = reinterpret_cast + (dyn_libs.search (STRINGIZE (F77_FUNC (ilaver, ILAVER)))); + + if (f_ptr) + { + int v_major = 0; + int v_minor = 0; + int v_patch = 0; + f_ptr (v_major, v_minor, v_patch); + + std::ostringstream s; + s << "Linear Algebra PACKage Version " + << v_major << "." << v_minor << "." << v_patch; + + retval = s.str (); + } + + return retval; + } + } +} diff --git a/liboctave/system/lo-sysinfo.h b/liboctave/system/lo-sysinfo.h new file mode 100644 --- /dev/null +++ b/liboctave/system/lo-sysinfo.h @@ -0,0 +1,40 @@ +/* + +Copyright (C) 2018 Markus Mützel + +This file is part of Octave. + +Octave is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Octave is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, see +. + +*/ + +#if ! defined (octave_lo_sysinfo_h) +#define octave_lo_sysinfo_h 1 + +#include "octave-config.h" + +#include + +namespace octave +{ + namespace sys + { + extern std::string blas_version (void); + + extern std::string lapack_version (void); + } +} + +#endif diff --git a/liboctave/system/module.mk b/liboctave/system/module.mk --- a/liboctave/system/module.mk +++ b/liboctave/system/module.mk @@ -4,6 +4,7 @@ SYSTEM_INC = \ %reldir%/file-ops.h \ %reldir%/file-stat.h \ %reldir%/lo-sysdep.h \ + %reldir%/lo-sysinfo.h \ %reldir%/mach-info.h \ %reldir%/oct-env.h \ %reldir%/oct-group.h \ @@ -19,6 +20,7 @@ SYSTEM_SRC = \ %reldir%/file-ops.cc \ %reldir%/file-stat.cc \ %reldir%/lo-sysdep.cc \ + %reldir%/lo-sysinfo.cc \ %reldir%/mach-info.cc \ %reldir%/oct-env.cc \ %reldir%/oct-group.cc \ diff --git a/scripts/miscellaneous/version.m b/scripts/miscellaneous/version.m --- a/scripts/miscellaneous/version.m +++ b/scripts/miscellaneous/version.m @@ -45,10 +45,10 @@ ## for version information for the linked @sc{fftw}, ## ## @item @qcode{"-blas"} -## for version information for the linked @sc{blas} (not implemented), +## for version information for the linked @sc{blas}, ## ## @item @qcode{"-lapack"} -## for version information for the linked @sc{lapack} (not implemented). +## for version information for the linked @sc{lapack}. ## @end table ## ## The variant with no input and output argument is an alias for the function @@ -71,7 +71,7 @@ function [v, d] = version (feature) d = __octave_config_info__ ("release_date"); end else - switch (feature) + switch (lower (feature)) case "-date" v = __octave_config_info__ ("release_date"); case "-description" @@ -90,16 +90,14 @@ function [v, d] = version (feature) "java.vm.info"); v = ["Java " jversion " with " jvendor " " jname " " jjitmode]; catch - v = "no java available"; + v = "no Java available"; end_try_catch case "-fftw" v = __octave_config_info__ ("fftw_version"); case "-blas" - v = ""; - warning ("version: option '-blas' not implemented"); + v = __blas_version__ (); case "-lapack" - v = ""; - warning ("version: option '-lapack' not implemented"); + v = __lapack_version__ (); otherwise error ("version: invalid FEATURE"); endswitch @@ -119,11 +117,11 @@ endfunction %!assert (version ("-description"), "") %!assert (version ("-release"), "") +%!assert (ischar (version ("-blas"))) +%!assert (ischar (version ("-LAPACK"))) ## Test input validation %!error version ("-date", "-release") %!error [v, d] = version ("-date") %!error version (1) -%!warning