YaccConstructor/Brahma.FSharp

Support empty array in kernel

artemgl opened this issue · 0 comments

Empty array can't be given as an argument to kernel.

let mutable oclContext = OpenCLEvaluationContext()

let workGroupSize = 256
let workSize n = n - n % workGroupSize + workGroupSize

let len = 0

let command =
    <@
        fun (ndRange: _1D)
            (xs: int[]) ->

            let i = ndRange.GlobalID0
            if i < len then xs.[i] <- 42
    @>

let xs = Array.zeroCreate len

opencl {
    do! RunCommand command <| fun kernelPrepare -> kernelPrepare (_1D(workSize len, workGroupSize)) xs
}
|> oclContext.RunSync

For the code above this exception is thrown:

Unhandled exception. Brahma.OpenCL.CLException: InvalidBufferSize
   at Brahma.OpenCL.Commands.RunBase`1.ArrayToMem(Object data, Type t)
   at Brahma.OpenCL.Commands.RunBase`1.ToIMem(Object arg)
   at Brahma.OpenCL.Commands.RunBase`1.SetupArgument(Object sender, Int32 index, Object arg)
   at lambda_method(Closure , Run`1 , Int32 , Object )
   at Microsoft.FSharp.Collections.ArrayModule.IterateIndexed[T](FSharpFunc`2 action, T[] array) in F:\workspace\_work\1\s\src\fsharp\FSharp.Core\array.fs:line 332
   at lambda_method(Closure , FSharpFunc`2 , Object[] )
   at lambda_method(Closure , Unit , _1D , Int32[] )
   at Program.main@28-1.Invoke(FSharpFunc`2 kernelPrepare) in E:\Projects\GraphBLAS-sharp\src\app\Program.fs:line 28
   at Brahma.FSharp.OpenCL.WorkflowBuilder.Basic.RunCommand@33-1.Invoke(OpenCLEvaluationContext _arg1)
   at Brahma.FSharp.OpenCL.WorkflowBuilder.Evaluation.Bind@64.Invoke(OpenCLEvaluationContext env)
   at Brahma.FSharp.OpenCL.WorkflowBuilder.Evaluation.Bind@64.Invoke(OpenCLEvaluationContext env)
   at Brahma.FSharp.OpenCL.WorkflowBuilder.Basic.OpenCLEvaluationContext.RunSync[a](OpenCLEvaluationContext this, OpenCLEvaluation`1 _arg1)
   at Program.main(String[] argv) in E:\Projects\GraphBLAS-sharp\src\app\Program.fs:line 27

Thus array emptyness check is required which is inconvenient.