unofficial mirror of bug-guix@gnu.org 
 help / color / mirror / code / Atom feed
* bug#69737: GSL cannot find CBLAS symbols
@ 2024-03-11 22:06 Artyom Bologov
  2024-03-12 22:22 ` Artyom Bologov
  0 siblings, 1 reply; 4+ messages in thread
From: Artyom Bologov @ 2024-03-11 22:06 UTC (permalink / raw)
  To: 69737

[-- Attachment #1: Type: text/plain, Size: 316 bytes --]

Hi y'all,

I'm working on Guile bindings for GNU Scientific Library (GSL), and I
encountered a bug: GSL cannot find CBLAS functions when invoked directly
from Guile.

I'm attaching a script, gslcblas.scm, ran (given that you replace the
path to libgsl.so in it with a machine-specific one) with

guile gslcblas.scm


[-- Attachment #2: Scheme file with buggy GSL behavior --]
[-- Type: text/plain, Size: 1183 bytes --]

(use-modules (system foreign)
             (system foreign-library))

(define libgsl
  (load-foreign-library "/gnu/store/zfxs8xbh68nb8smvsdf9i6aj6hbzgix4-profile/lib/libgsl.so"))

(define gsl-vector-alloc
  (foreign-library-function libgsl
                            "gsl_vector_alloc"
                            #:return-type '*
                            #:arg-types (list size_t)))

(define gsl-vector-set
  (foreign-library-function libgsl
                            "gsl_vector_set"
                            #:return-type void
                            #:arg-types (list '* size_t double)))

(define gsl-vector-get
  (foreign-library-function libgsl
                            "gsl_vector_get"
                            #:return-type double
                            #:arg-types (list '* size_t)))

(define gsl-blas-dscal
  (foreign-library-function libgsl
                            "gsl_blas_dscal"
                            #:return-type void
                            #:arg-types (list double '*)))

(let* ((n 3)
       (x (gsl-vector-alloc n)))
  (for-each (lambda (i)
              (gsl-vector-set x i i))
            (iota n))
  (gsl-blas-dscal 10 x))

[-- Attachment #3: Type: text/plain, Size: 1022 bytes --]


It errors out with

guile: symbol lookup error: [...]/libgsl.so: undefined symbol: cblas_dscal

Loading libgslcblas.so into the Scheme image doesn't help, it errors out
the same. That's why I'm thinking it's not a Guile Scheme problem, but a
library one: GSL C code breaks with no knowledge of CBLAS.

The suggested fix is to link libgsl.so against libgslcblas.so (or any
other CBLAS library?), so that the functions from the latter are
available in the former. that seems to be what Arch package does
(https://archlinux.org/packages/extra/x86_64/gsl/), at least. Although I
admit this is a strange circular behavior, it makes sense too: CBLAS is
an implementation detail for BLAS support in GSL, and should be linked
as such.

I'm not knowledgeable enough in the ways of building GSL (or any complex
C software really), so I cannot come up with a proper patch. Hopefully
that's enough info for someone to act on.

Acknowledgements: Huge thanks to Arun Isaac who helped me debug this
problem!

Thanks,
--
Artyom Bologov.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#69737: GSL cannot find CBLAS symbols
  2024-03-11 22:06 bug#69737: GSL cannot find CBLAS symbols Artyom Bologov
@ 2024-03-12 22:22 ` Artyom Bologov
  2024-03-13  0:14   ` Richard Sent
  0 siblings, 1 reply; 4+ messages in thread
From: Artyom Bologov @ 2024-03-12 22:22 UTC (permalink / raw)
  To: 69737; +Cc: Arun Isaac

CC-ing Arun Isaac to keep him in the loop.
--
Artyom.




^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#69737: GSL cannot find CBLAS symbols
  2024-03-12 22:22 ` Artyom Bologov
@ 2024-03-13  0:14   ` Richard Sent
  2024-03-13 21:09     ` Artyom Bologov
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Sent @ 2024-03-13  0:14 UTC (permalink / raw)
  To: Artyom Bologov; +Cc: Arun Isaac, 69737

Hi Artyom,

I found your code ran when I added

--8<---------------cut here---------------start------------->8---
(define libcblas
  ;; Your store path may differ
  (load-foreign-library "/gnu/store/dzx94b3xv4h1ik1bfrbxaw7n84y9r8zz-gsl-2.7.1/lib/libgslcblas.so"
                        #:global? #t))
--8<---------------cut here---------------end--------------->8---

before (define libgsl ...)

> If global? is true, symbols defined by the loaded library will be
> available when other modules need to resolve symbols; the default is
> #f, which keeps symbols local.
https://www.gnu.org/software/guile/manual/html_node/Foreign-Libraries.html

I have not tested if the calculation is correct.

-- 
Take it easy,
Richard Sent
Making my computer weirder one commit at a time.




^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#69737: GSL cannot find CBLAS symbols
  2024-03-13  0:14   ` Richard Sent
@ 2024-03-13 21:09     ` Artyom Bologov
  0 siblings, 0 replies; 4+ messages in thread
From: Artyom Bologov @ 2024-03-13 21:09 UTC (permalink / raw)
  To: Richard Sent; +Cc: Arun Isaac, 69737, Artyom Bologov


Hi Richard!

Thanks a lot, that solved it! I guess no actionable things for this
issue anymore. Sorry for the false lead on GSL 😅

--
Artyom.




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-03-19  7:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-11 22:06 bug#69737: GSL cannot find CBLAS symbols Artyom Bologov
2024-03-12 22:22 ` Artyom Bologov
2024-03-13  0:14   ` Richard Sent
2024-03-13 21:09     ` Artyom Bologov

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).