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

Support empty array in kernel #110

Open
artemgl opened this issue Mar 26, 2021 · 0 comments
Open

Support empty array in kernel #110

artemgl opened this issue Mar 26, 2021 · 0 comments

Comments

@artemgl
Copy link

artemgl commented Mar 26, 2021

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 [email protected](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 [email protected](OpenCLEvaluationContext env)
   at [email protected](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.

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

1 participant