YaccConstructor / Brahma.FSharp

F# quotation to OpenCL translator and respective runtime to utilize GPGPUs in F# applications.
http://yaccconstructor.github.io/Brahma.FSharp
Eclipse Public License 1.0
74 stars 17 forks source link

Compilation error on DU case construction inside kernel #148

Open dpanfilyonok opened 1 year ago

dpanfilyonok commented 1 year ago

Describe the bug

Unhandled exception. System.Exception: Program compilation failed: BuildProgramFailure
   BUILD LOG:
 <kernel>:17:55: error: passing '__global float' to parameter of incompatible type 'du0' (aka 'struct du0')
 tuple1 matchValue = matchValueUnitFunc ((du0) { 0 }, leftValues [gid]) ;
                                                      ^~~~~~~~~~~~~~~~

   at Microsoft.FSharp.Core.PrintfModule.PrintFormatToStringThenFail@1433.Invoke(String message) in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\printf.fs:line 1433
   at Microsoft.FSharp.Core.PrintfModule.gprintf[a,TState,TResidue,TResult,TPrinter](FSharpFunc`2 envf, PrintfFormat`4 format) in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\printf.fs:line 1385
   at Brahma.FSharp.ClProgram`2..ctor(ClContext ctx, FSharpExpr`1 srcLambda)
   at Brahma.FSharp.ClContextExtensions.ClContext.Compile[TRange,a](ClContext this, FSharpExpr`1 srcLambda)

To Reproduce

let left (opAdd: Expr<'a option -> 'b option -> 'c option>) =
    <@
        fun (leftItem: 'a) ->
             (%opAdd) (Some leftItem) None
    @>

let preparePositionsGeneral (leftRead: Expr<'a -> 'c option>) =
    <@
        fun (ndRange: Range1D)
            (length: int)
            (leftValues: ClArray<'a>) ->

        let gid = ndRange.GlobalID0

        if gid < length  then
            let a = (%leftRead) leftValues.[gid]
            ()
    @>

let preparePositions opAdd =
    preparePositionsGeneral (left opAdd)

let ctx = ClContext(ClDevice.GetFirstAppropriateDevice())
ctx.Compile(preparePositions StandardOperations.float32Sum)
|> printfn "%A"

Workarounds To use following function instead

let left (opAdd: Expr<'a option -> 'b option -> 'c option>) =
    <@
        fun (leftItem: 'a) ->
            let tmp = Some leftItem
            (%opAdd) tmp None
    @>

Additional context