mathnet / mathnet-numerics

Math.NET Numerics
http://numerics.mathdotnet.com
MIT License
3.47k stars 893 forks source link

How to use openblas native provider? #311

Open jaybert opened 9 years ago

jaybert commented 9 years ago

i am trying the 3.8.0 which says to include openblas support. I tried to give it a shot by using the Control.UseNativeOpenBLAS() command but it complained about not being able to find mathnet.numerics.openblas.dll. I looked through the packages on nuget and couldn't find this dll at all. I tried downloading the binary from openblas.net which had the file name lib openblas.dll. Renamed it to mathnet.numerics.openblas.dll just to see what happens and it complained about no entry point called query_capability (I think that was name but can get the exact name if that's useful) in the dll and exits.

Any ideas? Thanks!

-Jason

jaybert commented 9 years ago

Sorry I meant to say 3.7.0 not 3.8.0

cdrnet commented 9 years ago

Yes, our "official" builds of the native binaries for the new OpenBLAS and CUDA providers have not been published to NuGet yet. I should have mentioned this in the release notes.

I'll publish them after some more testing and clarifying the best approach in #312.

kjbartel commented 9 years ago

@jaybert If you want to try out the provider you can compile the project yourself.

For Windows:

1) Get a copy of OpenBLAS binaries from SourceForge (latest currently 0.2.14). Grab the Win64-int32, Win32, mingw32 and mingw64 archives. 2) Under the mathnet-numerics folder create a libs folder and an OpenBLAS folder under that. 3) Extract the OpenBLAS files into the folder so you have the following structure:

4) Open the MathNet.Numerics.NativeProviders.sln solution in Visual Studio and build the OpenBLAS project. You'll need to build both x64 and x86 if you want to support Any CPU. 5) The compiled files will be under the mathnet-numerics\out\OpenBLAS\Windows folder. Copy the x86 and x64 folders to your program's directory and the call to Control.UseNativeOpenBLAS() should now work.

jaybert commented 9 years ago

Thanks For the info.  I actually tried this earlier (and again today based on your instructions) but I was unable to get openblas to compile. 

The include statements in the cpp files didn't seem to be able To find the .h files I copied to that include directory. I just tried dropping the files into the main directory which solved that issue but then failed with a cannot link libopenblas.h.a error in vs 2013 (don't have screen in front of me). I'm guessing I need to set some sort of include directory but I wasn't really able to figure it out.  As you can tell I'm completely unfamiliar with c++ so can't figure out heads from tails.

Thanks for the help!

On Thu, Jul 2, 2015 at 5:59 AM, Kuan Bartel notifications@github.com wrote:

@jaybert If you want to try out the provider you can compile the project yourself. For Windows: 1) Get a copy of OpenBLAS binaries from SourceForge (latest currently 0.2.14). Grab the Win64-int32, Win32, mingw32 and mingw64 archives. 2) Under the mathnet-numerics folder create a libs folder and an OpenBLAS folder under that. 3) Extract the OpenBLAS files into the folder so you have the following structure:

  • \libs\OpenBLAS
    • \include
    • all .h files from either Win64-int32 or Win32 include folder
    • \x64
    • libopenblas.dll from Win64-int32 bin folder
    • libopenblas.dll.a from Win64-int32 lib folder
    • all dlls from mingw64 archive
    • \x86
    • libopenblas.dll from Win32 bin folder
    • libopenblas.dll.a from Win32 lib folder
    • all dlls from mingw32 archive
      4) Open the MathNet.Numerics.NativeProviders.sln solution in Visual Studio and build the OpenBLAS project. You'll need to build both x64 and x86 if you want to support Any CPU. 5) The compiled files will be under the mathnet-numerics\out\OpenBLAS\Windows folder. Copy the x86 and x64 folders to your program's directory and the call to Control.UseNativeOpenBLAS() should now work.

      Reply to this email directly or view it on GitHub: https://github.com/mathnet/mathnet-numerics/issues/311#issuecomment-117986780

MarcoROG commented 9 years ago

@cdrnet Have openBLAS and CUDA native programmers been added yet? I still can't use them using the NuGet MathNet release

kjbartel commented 9 years ago

@MarcoROG native providers are released separately to the main NuGet release, I think mainly due to the size of the native libraries. OpenBLAS and CUDA NuGet packages have not been published yet but the libraries can be manually built from the MathNet.Numerics.NativeProviders.sln or using FAKE. FAKE can also be used to build the NuGet packages. Both the OpenBLAS and CUDA projects have dependencies on the corresponding native libraries being installed / available on your computer. CUDA should just work after installing the SDK as it will set all of the required environment variables. OpenBLAS doesn't have an installer so the path to the required files isn't set with an environment variable. The project will look for files in \libs\OpenBLAS under the solution directory (as described above) or alternatively the path can be set in the OpenBLASWrapper.vcxproj project file by setting a value for OpenBLASPath. For example:

<PropertyGroup Label="Globals">
  <ProjectGuid>{CB4011B6-E9A7-480B-A7B1-8492039DAAD1}</ProjectGuid>
  <RootNamespace>OpenBLASWrapper</RootNamespace>
  <ProjectName>OpenBLAS</ProjectName>
  <OpenBLASPath>C:\Development\Libs\OpenBLAS\v0.2.14<OpenBLASPath>
</PropertyGroup>

Perhaps a readme of some sort should be added to explain this.

MarcoROG commented 9 years ago

@kjbartel thank you, i will try now with cuda. If i downloaded MathNet from NuGet, when can i find MathNet.Numerics.NativeProviders.sln ?

MarcoROG commented 9 years ago

@kjbartel nevermind, i found it, but when i build it i get Error 1 error LNK1104: cannot open file 'cublas.lib' C:\Users\Marco\Downloads\mathnet-numerics-master\mathnet-numerics-master\src\NativeProviders\Windows\CUDA\LINK CUDA

kjbartel commented 9 years ago

@MarcoROG Did you install the CUDA Toolkit?

MarcoROG commented 9 years ago

@kjbartel Yes i installed this : https://developer.nvidia.com/cuda-downloads I can see cublas.lib if i search in my system. Maybe i need to set some environment variable?

cdrnet commented 8 years ago

A first version of the OpenBLAS provider is now available on NuGet.

kjbartel commented 8 years ago

With the release of the OpenBLAS nuget package I think this can now be closed. Everything seems to be working correctly. @jaybert and @MarcoROG have you tried the new release yet?

MarcoROG commented 8 years ago

@kjbartel @cdrnet OPENBlas is working well for me! Any word about when CUDA will be released aswell?

cdrnet commented 8 years ago

Great, thanks!

Regarding CUDA, I'm currently blocked there since I cannot actually test anything (it seems we're not supporting my old Quadro 4000).

MarcoROG commented 8 years ago

@cdrnet Is it related to Compute Capabilities? I have a GTX 760, if it can be useful for some tests or something let me know please! I'd love to help!

atlemann commented 8 years ago

Is there any chance of a Signed Edition of the OpenBLAS native provider NuGet package? We are implementing a plug-in where the application we are plugging into requires all referenced assemblies to be signed...which is insanely annoying.

I'm getting the following error: "Additional information: Method not found: 'Boolean MathNet.Numerics.Control.TryUseNativeOpenBLAS()'."

cdrnet commented 8 years ago

The native provider NuGet packages do not actually contain any .Net assemblies, so to my understanding they cannot have a strong name (assuming you mean strong names, not certificate/authenticode code signing).

You get this exception at runtime only, but the compiler sees the method? Can you verify that you use exactly the same MathNet.Numerics.dll assembly at compilation and runtime?

atlemann commented 8 years ago

You're right. I thought it might be a .Net assembly, but saw after downloading the source code that is was native. The problem was that another project in my solution was referencing an ancient version of MathNet (v2.xx), which seemed to be the one invoked and missing the method. I changed all references to the newest 3.10 NuGet and now it works ok. Thanks for a great library!

cdrnet commented 8 years ago

Great, thanks for the update!

atlemann commented 8 years ago

Will there be an OpenBLAS native provider package for Linux? We are developing a cross platform F# application which would require this in addition to the windows one. Any hints on how to make one if there is none in the pipeline?

cdrnet commented 8 years ago

OpenBLAS supports Linux, so there should be nothing in the way of providing one. But we would have to build it ourselves, they only provide pre-built binaries for Windows.

See https://github.com/xianyi/OpenBLAS/blob/develop/GotoBLAS_02QuickInstall.txt

atlemann commented 8 years ago

Ok, so I could just build OpenBLAS for linux and somehow reference that binary and try to initialize the OpenBLAS provider in .NET?

cdrnet commented 8 years ago

Ah, no, you'd also need the native provider implementation itself (which links the OpenBLAS binaries) and we don't seem to have a build script for Linux (nor OSX) for that yet. So there is still some more work left to get this working.

atlemann commented 8 years ago

I see. Is there any roadmap for the OpenBLAS linux native provider implementation? Does it have to be implemented from scratch or is it more or less the same as the windows impl., but with different build and link routines?