Skip to content

Compilation error on DU case construction inside kernel #148

Open
@dpanfilyonok

Description

@dpanfilyonok

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

  • OS: Windows 11
  • Brahma.FSharp: 2.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions