Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.

Unable to run a mkl_malloc function from a package in Go

Aditya_Avinash_Atlur
722 Views

Hi, I am trying to use mkl_malloc() in Golang.

I have created a package which wraps mkl_malloc(). I called the wrapper from other Go file.

The problem comes when I am calling the wrapper. The package is build fine.

This is the error when I use the wrapper:

/tmp/go-build655247984/blasl1.a(blasl1.cgo2.o)(.text): MKL_malloc: not defined
MKL_malloc(0): not defined

The wrapper:

func Mal(x int,y int)unsafe.Pointer{
    return unsafe.Pointer(C.mkl_malloc(C.size_t(x),C.int(y)))
}

Using the wrapper:

x := blasl1.MKLMal(1024,64)

 

0 Kudos
4 Replies
Zhang_Z_Intel
Employee
722 Views

This is the first time I've seen MKL being used with Go. It is interesting! Maybe someone on this forum has had experience with Go can help?

Meanwhile, please share the command line and options you used to build the wrapper and link with MKL. Also, suppose you are on Linux, you can try 'ldd' on the binary to see if there's any broken dependence.

 

0 Kudos
mecej4
Honored Contributor III
722 Views

Aditya, I do not know about Go, but it seems to me that you may have overlooked the point that on Linux external symbols need to match as to upper/lower case. You probably need to avoid MKL_malloc, using instead the name mkl_malloc.

0 Kudos
Aditya_Avinash_Atlur
722 Views

Thank you Zhang. I took the compiler options from MKL-Linking-Advisor. The issue comes at linking.

Hi mecej4, I have changed the name of the Wrapper Go function. But, it is still showing the same error. Does it mean that Go mapped the name permanently to the file?

Can some one help me with the linking? Any blogs or whitepapers?

Also, my installation took place in /opt/intel/. There are 2 mkl/include and 2 mkl/lib folders.

The first one is /opt/intel/mkl/include

The second one is /opt/intel/composerxe*2013spe1*16.1/mkl/include

Which one should is use during compilation and linking?

0 Kudos
Zhang_Z_Intel
Employee
722 Views

Aditya Avinash Atluri wrote:

Also, my installation took place in /opt/intel/. There are 2 mkl/include and 2 mkl/lib folders.

The first one is /opt/intel/mkl/include

The second one is /opt/intel/composerxe*2013spe1*16.1/mkl/include

Which one should is use during compilation and linking?

Unless you installed two different versions of MKL side-by-side, there should only be one 'include' and one 'lib'. Can you check and see if one of the folders you mentioned is actually symbolic link to the other?

0 Kudos
Reply