GNU Octave 11.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
oct-sysinfo.cc
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 2018-2026 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if defined (HAVE_CONFIG_H)
27# include "config.h"
28#endif
29
30#include <sstream>
31#include <string>
32
33#include "f77-fcn.h"
34#include "oct-shlib.h"
35#include "oct-sysinfo.h"
36
37// Hack to stringize macro results.
38#define xSTRINGIZE(x) #x
39#define STRINGIZE(x) xSTRINGIZE(x)
40
43
44std::string blas_version ()
45{
46 dynamic_library dyn_libs ("");
47
48 if (! dyn_libs)
49 return "unknown BLAS";
50
51 std::string retval;
52
53 // Check for functions that are specific to certain BLAS implementations.
54
55 // FlexiBLAS
56 typedef void (*flexi_f_type) (int *, int *, int *);
57 flexi_f_type flexi_f_ptr = reinterpret_cast<flexi_f_type>
58 (dyn_libs.search ("flexiblas_get_version"));
59
60 if (flexi_f_ptr)
61 {
62 int v_major = 0;
63 int v_minor = 0;
64 int v_patch = 0;
65 flexi_f_ptr (&v_major, &v_minor, &v_patch);
66
67 std::ostringstream s;
68 s << "FlexiBLAS Version "
69 << v_major << "." << v_minor << "." << v_patch;
70
71 retval = s.str ();
72 }
73
74 // OpenBLAS
75 typedef char *(*open_fcn_type) ();
76 open_fcn_type open_f_ptr = reinterpret_cast<open_fcn_type>
77 (dyn_libs.search ("openblas_get_config"));
78
79 if (open_f_ptr)
80 {
81 if (! retval.empty ())
82 retval += "\n";
83
84 retval += "OpenBLAS (config: " + std::string (open_f_ptr ()) + ")";
85 }
86
87 // OpenBLAS with minimal extension functions included in the library
88 else if (dyn_libs.search ("openblas_get_num_threads"))
89 {
90 if (! retval.empty ())
91 retval += "\n";
92
93 retval += "OpenBLAS (config: unknown)";
94 }
95
96 // GotoBLAS(2)
97 if (dyn_libs.search ("gotoblas_profile_init"))
98 {
99 if (! retval.empty ())
100 retval += "\n";
101
102 retval += "GotoBLAS(2)";
103 }
104
105 // ATLAS
106 // FIXME: If we are really interested, we could use a pipe to
107 // redirect the output of "ATL_buildinfo".
108 if (dyn_libs.search ("ATL_buildinfo"))
109 {
110 if (! retval.empty ())
111 retval += "\n";
112
113 retval += "ATLAS";
114 }
115
116 // ACML
117 typedef void (*acml_f_type) (int *, int *, int *);
118 acml_f_type acml_f_ptr = reinterpret_cast<acml_f_type>
119 (dyn_libs.search ("acmlversion"));
120
121 if (acml_f_ptr)
122 {
123 int v_major = 0;
124 int v_minor = 0;
125 int v_patch = 0;
126 acml_f_ptr (&v_major, &v_minor, &v_patch);
127
128 std::ostringstream s;
129 s << "ACML BLAS Version "
130 << v_major << "." << v_minor << "." << v_patch;
131
132 if (! retval.empty ())
133 retval += "\n";
134
135 retval += s.str ();
136 }
137
138 // Intel MKL
139 typedef void (*mkl_f_type) (char *, int);
140 mkl_f_type mkl_f_ptr = reinterpret_cast<mkl_f_type>
141 (dyn_libs.search ("mkl_get_version_string"));
142
143 if (mkl_f_ptr)
144 {
145 char buf[198] = {};
146 // MKL overwrites buffer. Read (LENGTH-1) bytes to keep '\0' terminator.
147 mkl_f_ptr (buf, (198 - 1));
148
149 if (! retval.empty ())
150 retval += "\n";
151
152 retval += std::string (buf);
153 }
154
155 // Otherwise
156 if (retval.empty ())
157 retval = "unknown or reference BLAS";
158
159 return retval;
160}
161
162std::string
164{
165 std::string retval = "unknown LAPACK";
166
167 dynamic_library dyn_libs ("");
168
169 if (! dyn_libs)
170 return retval;
171
172 // query LAPACK version
173 typedef F77_RET_T
174 (*ilaver_fcn_type) (const F77_INT&, const F77_INT&, const F77_INT&);
175 ilaver_fcn_type f_ptr = reinterpret_cast<ilaver_fcn_type>
176 (dyn_libs.search (STRINGIZE (F77_FUNC (ilaver, ILAVER))));
177
178 if (f_ptr)
179 {
180 int v_major = 0;
181 int v_minor = 0;
182 int v_patch = 0;
183 f_ptr (v_major, v_minor, v_patch);
184
185 std::ostringstream s;
186 s << "Linear Algebra PACKage Version "
187 << v_major << "." << v_minor << "." << v_patch;
188
189 retval = s.str ();
190 }
191
192 return retval;
193}
194
195OCTAVE_END_NAMESPACE(sys)
196OCTAVE_END_NAMESPACE(octave)
void * search(const std::string &nm, const name_mangler &mangler=name_mangler()) const
Definition oct-shlib.h:181
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
octave_f77_int_type F77_INT
Definition f77-fcn.h:306
F77_RET_T(F77_CONST_CHAR_ARG_DECL, F77_CONST_CHAR_ARG_DECL, F77_CONST_CHAR_ARG_DECL, const F77_INT &, const F77_INT &, const F77_INT &, F77_INT &, F77_INT &, F77_DBLE *, const F77_INT &, F77_DBLE *, const F77_INT &, F77_DBLE *, F77_DBLE *, F77_DBLE *, const F77_INT &, F77_DBLE *, const F77_INT &, F77_DBLE *, const F77_INT &, F77_DBLE *, F77_INT *, F77_INT &F77_CHAR_ARG_LEN_DECL F77_CHAR_ARG_LEN_DECL F77_CHAR_ARG_LEN_DECL)
std::string lapack_version()
#define STRINGIZE(x)
std::string blas_version()
F77_RET_T F77_FUNC(xerbla, XERBLA)(F77_CONST_CHAR_ARG_DEF(s_arg