gonum / blas

A BLAS implementation for Go [DEPRECATED]
172 stars 16 forks source link

Please help - getting blas64 to work with OpenBLAS #190

Closed ColdFire87 closed 7 years ago

ColdFire87 commented 8 years ago

Hi,

I'm trying to use the gonum/blas library with the OpenBLAS library but I can't figure it out.

My project structure is:

OpenBLAS_gonum
    |-- bin
    |-- pkg
    |-- src
          |-- main.go <- my source file
          |-- lib
               |-- OpenBLAS
                     |-- bin
                          |-- libopenblas.dll
                     |-- include
                          |-- (...) multiple .h files
                     |-- lib
                          |-- cmake
                                |-- openblas
                                      |-- OpenBLASConfig.cmake
                                      |-- OpenBLASConfigVersion.cmake
                          |-- libopenblas.a
                          |-- libopenblas.dll.a
                     |-- readme.txt

The code I have is (main.go):

package main

import (
    "fmt"

    "github.com/gonum/blas/cgo"
    "github.com/gonum/blas/blas64"
)

func main() {
    blas64.Use(cgo.Implementation{})
    v := blas64.Vector{Inc: 1, Data: []float64{1, 1, 1}}
    fmt.Println("v has length:", blas64.Nrm2(len(v.Data), v))
}

I set the environment variable:

CGO_LDFLAGS="-L${SRCDIR}/lib/OpenBLAS/lib -lopenblas"

I've tried setting this to different paths such as -L${SRCDIR}/lib/OpenBLAS or even the full path but I had no success.

The build command is:

C:\Go\bin\go.exe build -o "C:\Projects\PLAYGROUND\GO\OpenBLAS_gonum\bin\run_main.exe" "C:\Projects\PLAYGROUND\GO\OpenBLAS_gonum\src\main.go"

The error I get is:

# github.com/gonum/blas/cgo
realgcc.exe: warning: '-x c' after last input file has no effect
realgcc.exe: fatal error: no input files
compilation terminated.

I've also tried adding this at the top (after package main)

// #cgo LDFLAGS: -L${SRCDIR}/lib/OpenBLAS/lib -lopenblas
import "C"

My OS is Windows 7 x64 and I've downloaded the binary package for OpenBLAS (so I don't have to compile it).

Please help!

Thanks!

btracey commented 8 years ago

Do you have a $GOPATH set? Is gonum/BLAS in there? Why are you using the build command you are rather than using the "go" command?

ColdFire87 commented 8 years ago

My GOPATH is set to C:\Projects\PLAYGROUND\GO\OpenBLAS_gonum\ gonum/BLAS is in C:\Go\src\src\github.com\gonum\blas

I don't think is anything to do with the GOPATH as other projects are working just fine. I seem to get into this problem when trying to write GO programs that call C functions. I've just started looking into the topic recently and so far I've not managed to get it running. I have a different project setup trying to use CUDA (I tried both a direct approach and this library -> https://github.com/barnex/cuda5) and I get the same error regarding realgcc.exe

I don't really understand what you are asking by using the "go" command. I am using the go command. I'm doing go build -o output.exe main.go. I can also do go build main.go but still no luck. I'm using WebStorm for the IDE and that was the command run by it.

I've run go tool cgo main.go and got some code output in OpenBLAS_gonum\src\_obj I've also tried go build -compiler=gccgo main.go and got the below output:

C:\Projects\PLAYGROUND\GO\OpenBLAS_gonum\src>go build -compiler=gccgo main.go
go build github.com/gonum/blas: : exec: "C:\\Go\\src\\src\\github.com\\gonum\\blas": file does not exist
go build github.com/gonum/blas/native/internal/math32: : exec: "C:\\Go\\src\\src\\github.com\\gonum\\blas\\native\\internal\\math32": file does not exist
go build github.com/gonum/internal/asm: : exec: "C:\\Go\\src\\src\\github.com\\gonum\\internal\\asm": file does not exist

Which command do you use when building a sample GO app using the C bindings for OpenBLAS ?

I've been looking through the GO docs & Googling this problem yesterday a lot. It's probably something simple I'm missing and I know it's not directly related to your library in particular but I'd appreciate the help in getting it running.

btracey commented 7 years ago

Sorry, I'm not sure how to help, maybe ask on golang-nuts if it's still relevant, or you can use the native Go code.