Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run on macOS/Mono 5+ #81

Closed
sergey-tihon opened this issue Jul 3, 2017 · 5 comments
Closed

Run on macOS/Mono 5+ #81

sergey-tihon opened this issue Jul 3, 2017 · 5 comments
Assignees

Comments

@sergey-tihon
Copy link

Description

Is possible to use Brahma.FSharp on macOS / Mono 5+?

Repro steps

  1. Compile and execute sample from Home page

Actual behavior

The error that I see (this probably could be more informative)

Unhandled Exception:
System.TypeInitializationException: The type initializer for 'Brahma.Helpers.Timer`1' threw an exception. ---> System.EntryPointNotFoundException: QueryPerformanceFrequency
  at (wrapper managed-to-native) Brahma.Helpers.NativeMethods:QueryPerformanceFrequency (long&)
  at Brahma.Helpers.Timer`1[TMarker]..ctor () [0x0001c] in <40f78615313049f381a4f5be7149ca08>:0
  at Brahma.Helpers.Timer`1[TMarker]..cctor () [0x00000] in <40f78615313049f381a4f5be7149ca08>:0
   --- End of inner exception stack trace ---
  at BrahmaTest.main (System.String[] argv) [0x00030] in <595a5b72d4251104a7450383725b5a59>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: The type initializer for 'Brahma.Helpers.Timer`1' threw an exception. ---> System.EntryPointNotFoundException
: QueryPerformanceFrequency
  at (wrapper managed-to-native) Brahma.Helpers.NativeMethods:QueryPerformanceFrequency (long&)
  at Brahma.Helpers.Timer`1[TMarker]..ctor () [0x0001c] in <40f78615313049f381a4f5be7149ca08>:0
  at Brahma.Helpers.Timer`1[TMarker]..cctor () [0x00000] in <40f78615313049f381a4f5be7149ca08>:0
   --- End of inner exception stack trace ---
  at BrahmaTest.main (System.String[] argv) [0x00030] in <595a5b72d4251104a7450383725b5a59>:0

Additional info

I did try to print platform details before execution of Main method.

    let (platforms, error) = OpenCL.Net.Cl.GetPlatformIDs()
    for pl in platforms do
        printfn "%A" pl
    printfn "Error %A" (error)

I this case I see the following error

Unhandled Exception:
System.DllNotFoundException: opencl.dll
  at (wrapper managed-to-native) OpenCL.Net.Cl:clGetPlatformIDs (uint,OpenCL.Net.Platform[],uint&)
  at OpenCL.Net.Cl.GetPlatformIDs (System.UInt32 numEntries, OpenCL.Net.Platform[] platforms, System.UInt32& numPlatforms) [0x00000] in <77a3ef23da094c79ba35fe25271dc2a6>:0
  at OpenCL.Net.Cl.GetPlatformIDs (OpenCL.Net.ErrorCode& error) [0x00000] in <77a3ef23da094c79ba35fe25271dc2a6>:0
  at BrahmaTest.main (System.String[] argv) [0x00017] in <595a5eb7d4251104a7450383b75e5a59>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.DllNotFoundException: opencl.dll
  at (wrapper managed-to-native) OpenCL.Net.Cl:clGetPlatformIDs (uint,OpenCL.Net.Platform[],uint&)
  at OpenCL.Net.Cl.GetPlatformIDs (System.UInt32 numEntries, OpenCL.Net.Platform[] platforms, System.UInt32& numPlatforms) [0x00000] in <77a3ef23da094c79ba35fe25271dc2a6>:0
  at OpenCL.Net.Cl.GetPlatformIDs (OpenCL.Net.ErrorCode& error) [0x00000] in <77a3ef23da094c79ba35fe25271dc2a6>:0
  at BrahmaTest.main (System.String[] argv) [0x00017] in <595a5eb7d4251104a7450383b75e5a59>:0

Related information

  • Operating system - macOS Sierra 10.12.5
  • Branch - v1.1 from NuGet
  • Mono Version - 5.0.1.1
  • GPU - Radeon Pro 460 4096 MB & Intel HD Graphics 530 1536 MB
@sergey-tihon
Copy link
Author

sergey-tihon commented Jul 3, 2017

Tip 1

In order to fix System.DllNotFoundException: opencl.dll the OpenCL.Net.dll.config should exist near exe file with the following content, this actually allows map dll reference to macOS implementation.

<configuration>
  <dllmap os="osx" dll="opencl.dll" target="/System/Library/Frameworks/OpenCL.framework/OpenCL"/>
</configuration>

Tip 2

The current OpenCL platform name is Apple on macOS.
So, the following code

    let (platforms, error) = OpenCL.Net.Cl.GetPlatformIDs()
    for pl in platforms do
        let (_,paramSize) = OpenCL.Net.Cl.GetPlatformInfo(pl, PlatformInfo.Name, System.IntPtr.Zero, InfoBuffer.Empty)
        use buffer = new InfoBuffer(paramSize)
        Cl.GetPlatformInfo(pl, PlatformInfo.Name, paramSize, buffer) |> ignore
        printfn "Platform=%A" (buffer)

    let provider = ComputeProvider.Create()//("Apple", DeviceType.Default)
    for d in provider.Devices do
        let getInfo (pName:DeviceInfo)=
            let (_,paramSize) = Cl.GetDeviceInfo(d, pName, System.IntPtr.Zero, InfoBuffer.Empty)
            use buffer = new InfoBuffer(paramSize)
            Cl.GetDeviceInfo(d, pName, paramSize, buffer) |> ignore
            buffer.ToString()
        printfn "Device=[Name=%s;\tDriverVersion=%A]"
            (getInfo DeviceInfo.Name)
            ((getInfo DeviceInfo.DriverVersion))

prints

Platform=Apple
Device=[Name=Intel(R) HD Graphics 530; DriverVersion="1.2(Apr 22 2017 16:00:49)"]
Device=[Name=AMD Radeon Pro 460 Compute Engine; DriverVersion="1.2 (Apr 27 2017 22:10:57)"]

Tip 3

Static ctor of Brahma.Helpers.Timer<TMarker> do P/Invoke calls to Kernel32.dll, so this Timer cannot be used on macOS and lines (like below) should be commented

        Timer<string>.Global.Start()
        ...
        Timer<string>.Global.Lap("OpenCL")

@sergey-tihon
Copy link
Author

sergey-tihon commented Jul 3, 2017

When I commented all calls to Timer<string>.Global I see the different error:
(Brahma cannot compile command Expr to OpenCL kernel)

Multiplying two 200x200 matrices 10 times using .NET...
done.
Multiplying two 200x200 matrices 10 times using OpenCL and selected platform/device : [Platform: Apple, device type:Gpu]
[Platform: Apple, device type:Gpu]
 ...

Unhandled Exception:
System.Exception:

  at Brahma.FSharp.OpenCL.Core.ComputeProvider.CompileQuery[T] (Brahma.OpenCL.ComputeProvider this, Microsoft.FSharp.Quotations.FSharpExpr lambda, System.Collections.Generic.IEnume
rable`1[T] translatorOptions, Microsoft.FSharp.Collections.FSharpList`1[T] additionalSources) [0x00153] in <594a167316e8481da745038373164a59>:0
  at Brahma.FSharp.OpenCL.Core.ComputeProvider.Compile[TRange,a] (Brahma.OpenCL.ComputeProvider this, Microsoft.FSharp.Quotations.FSharpExpr`1[T] query, Microsoft.FSharp.Core.FShar
pOption`1[T] _options, Microsoft.FSharp.Core.FSharpOption`1[T] translatorOptions, Microsoft.FSharp.Core.FSharpOption`1[T] _outCode, Microsoft.FSharp.Core.FSharpOption`1[T] kernelNa
me, Microsoft.FSharp.Core.FSharpOption`1[T] _additionalSources) [0x0002d] in <594a167316e8481da745038373164a59>:0
  at BrahmaTest.Main (System.String platformName, System.Single[] m1, System.Single[] m2) [0x00219] in <595a6f50d4251104a7450383506f5a59>:0
  at BrahmaTest.main (System.String[] argv) [0x001d3] in <595a6f50d4251104a7450383506f5a59>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.Exception:

  at Brahma.FSharp.OpenCL.Core.ComputeProvider.CompileQuery[T] (Brahma.OpenCL.ComputeProvider this, Microsoft.FSharp.Quotations.FSharpExpr lambda, System.Collections.Generic.IEnume
rable`1[T] translatorOptions, Microsoft.FSharp.Collections.FSharpList`1[T] additionalSources) [0x00153] in <594a167316e8481da745038373164a59>:0
  at Brahma.FSharp.OpenCL.Core.ComputeProvider.Compile[TRange,a] (Brahma.OpenCL.ComputeProvider this, Microsoft.FSharp.Quotations.FSharpExpr`1[T] query, Microsoft.FSharp.Core.FShar
pOption`1[T] _options, Microsoft.FSharp.Core.FSharpOption`1[T] translatorOptions, Microsoft.FSharp.Core.FSharpOption`1[T] _outCode, Microsoft.FSharp.Core.FSharpOption`1[T] kernelNa
me, Microsoft.FSharp.Core.FSharpOption`1[T] _additionalSources) [0x0002d] in <594a167316e8481da745038373164a59>:0
  at BrahmaTest.Main (System.String platformName, System.Single[] m1, System.Single[] m2) [0x00219] in <595a6f50d4251104a7450383506f5a59>:0
  at BrahmaTest.main (System.String[] argv) [0x001d3] in <595a6f50d4251104a7450383506f5a59>:0

Note: This is strange that stack trace does not have line numbers (:0 all the time), this makes troubleshooting more complicated. I guess that it could be fixed if you ship pdb files together with dlls inside NuGet package.

@gsvgit gsvgit self-assigned this Jul 4, 2017
@gsvgit gsvgit mentioned this issue Jul 5, 2017
5 tasks
@sergey-tihon
Copy link
Author

sergey-tihon commented Jul 16, 2017

Error message after executing new sample on macOS using Brahma.FSharp v1.1.2

Multiplying two 300x300 matrices 10 times using .NET...
done.
Multiplying two 300x300 matrices 10 times using OpenCL and selected platform/device : [Platform: Apple, device type:Gpu]
[Platform: Apple, device type:Gpu]
 ...

Unhandled Exception:
System.Exception:

Error code: InvalidBuildOptions
  at Brahma.FSharp.OpenCL.Core+getProgramProcessingError@42TT[a,b].Invoke (a errCode, OpenCL.Net.Program program) [0x000c4] in <595cbbd516e8481da7450383d5bb5c59>:0
  at Microsoft.FSharp.Core.FSharpFunc`2[T,TResult].InvokeFast[V] (Microsoft.FSharp.Core.FSharpFunc`2[T,TResult] func, T arg1, TResult arg2) [0x0000d] in <5939249c904cf4daa74503839c243959>:0
  at Brahma.FSharp.OpenCL.Core.ComputeProvider.CompileQuery[T] (Brahma.OpenCL.ComputeProvider this, Microsoft.FSharp.Quotations.FSharpExpr lambda, System.Collections.Generic.IEnumerable`1[T] translatorOptions, Microsoft.FSharp.Collections.FSharpList`1[T] additionalSources) [0x0010e] in <595cbbd516e8481da7450383d5bb5c59>:0
  at Brahma.FSharp.OpenCL.Core.ComputeProvider.Compile[TRange,a] (Brahma.OpenCL.ComputeProvider this, Microsoft.FSharp.Quotations.FSharpExpr`1[T] query, Microsoft.FSharp.Core.FSharpOption`1[T] _options, Microsoft.FSharp.Core.FSharpOption`1[T] translatorOptions, Microsoft.FSharp.Core.FSharpOption`1[T] _outCode, Microsoft.FSharp.Core.FSharpOption`1[T] kernelName, Microsoft.FSharp.Core.FSharpOption`1[T] _additionalSources) [0x0002d] in <595cbbd516e8481da7450383d5bb5c59>:0
  at BrahmaTest.Main (System.String platformName, System.Int32 mSize) [0x0022d] in <596b094ed4251104a74503834e096b59>:0
  at BrahmaTest.main (System.String[] argv) [0x0000d] in <596b094ed4251104a74503834e096b59>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.Exception:

Error code: InvalidBuildOptions
  at Brahma.FSharp.OpenCL.Core+getProgramProcessingError@42TT[a,b].Invoke (a errCode, OpenCL.Net.Program program) [0x000c4] in <595cbbd516e8481da7450383d5bb5c59>:0
  at Microsoft.FSharp.Core.FSharpFunc`2[T,TResult].InvokeFast[V] (Microsoft.FSharp.Core.FSharpFunc`2[T,TResult] func, T arg1, TResult arg2) [0x0000d] in <5939249c904cf4daa74503839c243959>:0
  at Brahma.FSharp.OpenCL.Core.ComputeProvider.CompileQuery[T] (Brahma.OpenCL.ComputeProvider this, Microsoft.FSharp.Quotations.FSharpExpr lambda, System.Collections.Generic.IEnumerable`1[T] translatorOptions, Microsoft.FSharp.Collections.FSharpList`1[T] additionalSources) [0x0010e] in <595cbbd516e8481da7450383d5bb5c59>:0
  at Brahma.FSharp.OpenCL.Core.ComputeProvider.Compile[TRange,a] (Brahma.OpenCL.ComputeProvider this, Microsoft.FSharp.Quotations.FSharpExpr`1[T] query, Microsoft.FSharp.Core.FSharpOption`1[T] _options, Microsoft.FSharp.Core.FSharpOption`1[T] translatorOptions, Microsoft.FSharp.Core.FSharpOption`1[T] _outCode, Microsoft.FSharp.Core.FSharpOption`1[T] kernelName, Microsoft.FSharp.Core.FSharpOption`1[T] _additionalSources) [0x0002d] in <595cbbd516e8481da7450383d5bb5c59>:0
  at BrahmaTest.Main (System.String platformName, System.Int32 mSize) [0x0022d] in <596b094ed4251104a74503834e096b59>:0
  at BrahmaTest.main (System.String[] argv) [0x0000d] in <596b094ed4251104a74503834e096b59>:0

@gsvgit
Copy link
Member

gsvgit commented Jul 16, 2017

@sergey-tihon Thanks for additional informatuion. Seems, that it was a problem with extra spaces in compiler options. Fixed in Brahma.FSharp v1.1.3.

@sergey-tihon
Copy link
Author

2017-07-16_1626

Woohoo !!! Thank you for help @gsvgit .

Brahma.FSharp works on macOS now!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants